tim-connector: Refactor majorId attribute of Connector entity to name
FEA: ItEr77S16JiraAndTimConnectorContributionIntegration
This commit is contained in:
parent
ef1328eee1
commit
21c788316a
14 changed files with 53 additions and 54 deletions
|
|
@ -49,27 +49,27 @@ public class ConnectorDAO extends GenericDAOHibernate<Connector, Long>
|
|||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public Connector findUniqueByMajorId(String majorId) {
|
||||
public Connector findUniqueByName(String name) {
|
||||
Criteria c = getSession().createCriteria(Connector.class).add(
|
||||
Restrictions.eq("majorId", majorId));
|
||||
Restrictions.eq("name", name));
|
||||
return (Connector) c.uniqueResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true, propagation = Propagation.REQUIRES_NEW)
|
||||
public boolean existsByNameAnotherTransaction(Connector connector) {
|
||||
return existsOtherConnectorByMajorId(connector);
|
||||
return existsOtherConnectorByName(connector);
|
||||
}
|
||||
|
||||
private boolean existsOtherConnectorByMajorId(Connector connector) {
|
||||
Connector found = findUniqueByMajorId(connector.getMajorId());
|
||||
private boolean existsOtherConnectorByName(Connector connector) {
|
||||
Connector found = findUniqueByName(connector.getName());
|
||||
return found != null && found != connector;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true, propagation = Propagation.REQUIRES_NEW)
|
||||
public Connector findUniqueByMajorIdAnotherTransaction(String majorId) {
|
||||
return findUniqueByMajorId(majorId);
|
||||
public Connector findUniqueByNameAnotherTransaction(String name) {
|
||||
return findUniqueByName(name);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,10 +33,10 @@ public interface IConnectorDAO extends IGenericDAO<Connector, Long> {
|
|||
|
||||
List<Connector> getAll();
|
||||
|
||||
Connector findUniqueByMajorId(String majorId);
|
||||
Connector findUniqueByName(String name);
|
||||
|
||||
boolean existsByNameAnotherTransaction(Connector connector);
|
||||
|
||||
Connector findUniqueByMajorIdAnotherTransaction(String majorId);
|
||||
Connector findUniqueByNameAnotherTransaction(String name);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,9 +37,8 @@ import org.libreplan.business.common.daos.IConnectorDAO;
|
|||
* Connector entity, represents a connector in order that LibrePlan interchange
|
||||
* some data with other application.
|
||||
*
|
||||
* A connector is identified by a string called <code>majorId</code> and it has
|
||||
* a list of pairs key-value in order to store the configuration parameters of
|
||||
* the connector.
|
||||
* A connector is identified by a <code>name</code> and it has a list of pairs
|
||||
* key-value in order to store the configuration parameters of the connector.
|
||||
*
|
||||
* This entity should be used to create new connectors in LibrePlan.
|
||||
*
|
||||
|
|
@ -48,11 +47,11 @@ import org.libreplan.business.common.daos.IConnectorDAO;
|
|||
*/
|
||||
public class Connector extends BaseEntity {
|
||||
|
||||
public static Connector create(String majorId) {
|
||||
return create(new Connector(majorId));
|
||||
public static Connector create(String name) {
|
||||
return create(new Connector(name));
|
||||
}
|
||||
|
||||
private String majorId;
|
||||
private String name;
|
||||
|
||||
private List<ConnectorProperty> properties = new ArrayList<ConnectorProperty>();
|
||||
|
||||
|
|
@ -62,17 +61,17 @@ public class Connector extends BaseEntity {
|
|||
protected Connector() {
|
||||
}
|
||||
|
||||
private Connector(String majorId) {
|
||||
this.majorId = majorId;
|
||||
private Connector(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@NotEmpty(message = "major id not specified")
|
||||
public String getMajorId() {
|
||||
return majorId;
|
||||
@NotEmpty(message = "name not specified")
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setMajorId(String majorId) {
|
||||
this.majorId = majorId;
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Valid
|
||||
|
|
@ -96,9 +95,9 @@ public class Connector extends BaseEntity {
|
|||
return map;
|
||||
}
|
||||
|
||||
@AssertTrue(message = "connector major id is already being used")
|
||||
public boolean checkConstraintUniqueConnectorMajorId() {
|
||||
if (StringUtils.isBlank(majorId)) {
|
||||
@AssertTrue(message = "connector name is already being used")
|
||||
public boolean checkConstraintUniqueConnectorName() {
|
||||
if (StringUtils.isBlank(name)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -107,7 +106,7 @@ public class Connector extends BaseEntity {
|
|||
return !connectorDAO.existsByNameAnotherTransaction(this);
|
||||
} else {
|
||||
Connector found = connectorDAO
|
||||
.findUniqueByMajorIdAnotherTransaction(majorId);
|
||||
.findUniqueByNameAnotherTransaction(name);
|
||||
return found == null || found.getId().equals(getId());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -43,11 +43,11 @@ public class ConnectorBootstrap implements IConnectorBootstrap {
|
|||
public void loadRequiredData() {
|
||||
for (PredefinedConnectors predefinedConnector : PredefinedConnectors
|
||||
.values()) {
|
||||
String majorId = predefinedConnector.getMajorId();
|
||||
String name = predefinedConnector.getName();
|
||||
|
||||
Connector connector = connectorDAO.findUniqueByMajorId(majorId);
|
||||
Connector connector = connectorDAO.findUniqueByName(name);
|
||||
if (connector == null) {
|
||||
connector = Connector.create(majorId);
|
||||
connector = Connector.create(name);
|
||||
connector.setProperties(predefinedConnector.getProperties());
|
||||
connectorDAO.save(connector);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,17 +42,17 @@ public enum PredefinedConnectors {
|
|||
ConnectorProperty.create(PredefinedConnectorProperties.TIM_DEPARTAMENTS_IMPORT_ROSTER, "0")
|
||||
);
|
||||
|
||||
private String majorId;
|
||||
private String name;
|
||||
private List<ConnectorProperty> properties;
|
||||
|
||||
private PredefinedConnectors(String majorId,
|
||||
private PredefinedConnectors(String name,
|
||||
ConnectorProperty... properties) {
|
||||
this.majorId = majorId;
|
||||
this.name = name;
|
||||
this.properties = Arrays.asList(properties);
|
||||
}
|
||||
|
||||
public String getMajorId() {
|
||||
return majorId;
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public List<ConnectorProperty> getProperties() {
|
||||
|
|
|
|||
|
|
@ -345,7 +345,7 @@
|
|||
<column name="version" type="BIGINT">
|
||||
<constraints nullable="false" />
|
||||
</column>
|
||||
<column name="major_id" type="VARCHAR(255)" >
|
||||
<column name="name" type="VARCHAR(255)" >
|
||||
<constraints nullable="false" />
|
||||
</column>
|
||||
</createTable>
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
<version name="version" access="property" type="long" />
|
||||
|
||||
<property name="majorId" column="major_id" not-null="true" />
|
||||
<property name="name" column="name" not-null="true" />
|
||||
|
||||
<list name="properties" table="connector_property">
|
||||
<key column="connector_id" />
|
||||
|
|
|
|||
|
|
@ -94,8 +94,8 @@ public class ExportTimesheetsToTim implements IExportTimesheetsToTim {
|
|||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public void exportTimesheets() {
|
||||
String majorId = PredefinedConnectors.TIM.getMajorId();
|
||||
Connector connector = connectorDAO.findUniqueByMajorId(majorId);
|
||||
String name = PredefinedConnectors.TIM.getName();
|
||||
Connector connector = connectorDAO.findUniqueByName(name);
|
||||
if (connector == null) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -104,7 +104,7 @@ public class ExportTimesheetsToTim implements IExportTimesheetsToTim {
|
|||
for (Order order : orders) {
|
||||
OrderSyncInfo orderSyncInfo = orderSyncInfoDAO
|
||||
.findLastSynchronizedInfoByOrderAndConnectorId(order,
|
||||
majorId);
|
||||
name);
|
||||
if (orderSyncInfo == null) {
|
||||
LOG.warn("Order '" + order.getName()
|
||||
+ "' is not yet synchronized");
|
||||
|
|
@ -126,7 +126,7 @@ public class ExportTimesheetsToTim implements IExportTimesheetsToTim {
|
|||
throw new RuntimeException("Order should not be empty");
|
||||
}
|
||||
Connector connector = connectorDAO
|
||||
.findUniqueByMajorId(PredefinedConnectors.TIM.getMajorId());
|
||||
.findUniqueByName(PredefinedConnectors.TIM.getName());
|
||||
if (connector == null) {
|
||||
throw new RuntimeException("Tim connector not found");
|
||||
}
|
||||
|
|
@ -229,7 +229,7 @@ public class ExportTimesheetsToTim implements IExportTimesheetsToTim {
|
|||
@Override
|
||||
public Void execute() {
|
||||
OrderSyncInfo orderSyncInfo = OrderSyncInfo.create(
|
||||
order, PredefinedConnectors.TIM.getMajorId());
|
||||
order, PredefinedConnectors.TIM.getName());
|
||||
orderSyncInfo.setKey(productCode);
|
||||
orderSyncInfoDAO.save(orderSyncInfo);
|
||||
return null;
|
||||
|
|
@ -286,7 +286,7 @@ public class ExportTimesheetsToTim implements IExportTimesheetsToTim {
|
|||
@Transactional(readOnly = true)
|
||||
public OrderSyncInfo getOrderLastSyncInfo(Order order) {
|
||||
return orderSyncInfoDAO.findLastSynchronizedInfoByOrderAndConnectorId(
|
||||
order, PredefinedConnectors.TIM.getMajorId());
|
||||
order, PredefinedConnectors.TIM.getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -126,8 +126,8 @@ public class ImportRosterFromTim implements IImportRosterFromTim {
|
|||
@Transactional
|
||||
public void importRosters() {
|
||||
Connector connector = connectorDAO
|
||||
.findUniqueByMajorId(
|
||||
PredefinedConnectors.TIM.getMajorId());
|
||||
.findUniqueByName(
|
||||
PredefinedConnectors.TIM.getName());
|
||||
if (connector == null) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -335,8 +335,8 @@ public class ConfigurationController extends GenericForwardComposer {
|
|||
String password = properties
|
||||
.get(PredefinedConnectorProperties.PASSWORD);
|
||||
|
||||
if (selectedConnector.getMajorId().equals(
|
||||
PredefinedConnectors.TIM.getMajorId())) {
|
||||
if (selectedConnector.getName().equals(
|
||||
PredefinedConnectors.TIM.getName())) {
|
||||
testTimConnection(url, username, password);
|
||||
} else {
|
||||
throw new RuntimeException("Unknown connector");
|
||||
|
|
@ -407,8 +407,8 @@ public class ConfigurationController extends GenericForwardComposer {
|
|||
|
||||
private void reloadConnectors() {
|
||||
selectedConnector = configurationModel
|
||||
.getConnectorByMajorId(selectedConnector != null ? selectedConnector
|
||||
.getMajorId() : null);
|
||||
.getConnectorByName(selectedConnector != null ? selectedConnector
|
||||
.getName() : null);
|
||||
Util.reloadBindings(connectorCombo);
|
||||
Util.reloadBindings(connectorPropertriesGrid);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -735,13 +735,13 @@ public class ConfigurationModel implements IConfigurationModel {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Connector getConnectorByMajorId(String majorId) {
|
||||
if (majorId == null || connectors == null) {
|
||||
public Connector getConnectorByName(String name) {
|
||||
if (name == null || connectors == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (Connector connector : connectors) {
|
||||
if (connector.getMajorId().equals(majorId)) {
|
||||
if (connector.getName().equals(name)) {
|
||||
return connector;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -197,6 +197,6 @@ public interface IConfigurationModel {
|
|||
|
||||
List<Connector> getConnectors();
|
||||
|
||||
Connector getConnectorByMajorId(String majorId);
|
||||
Connector getConnectorByName(String name);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ public class TimSynchronizationController extends GenericForwardComposer {
|
|||
|
||||
public boolean isTimActivated() {
|
||||
Connector connector = connectorDAO
|
||||
.findUniqueByMajorId(PredefinedConnectors.TIM.getMajorId());
|
||||
.findUniqueByName(PredefinedConnectors.TIM.getName());
|
||||
if (connector == null) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -466,7 +466,7 @@
|
|||
selectedItem="@{configurationController.selectedConnector}">
|
||||
<comboitem
|
||||
self="@{each=connectors}"
|
||||
label="@{connectors.majorId}"
|
||||
label="@{connectors.name}"
|
||||
value="@{connectors}" />
|
||||
</combobox>
|
||||
</hbox>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue