tim-connector: added attribute key and connectorId and removed code and label attributes
- attributes key and connectorId added - modified findBys with this new change - modified other files affected by this change
This commit is contained in:
parent
604368f822
commit
4aae86335e
7 changed files with 80 additions and 53 deletions
|
|
@ -34,24 +34,29 @@ public interface IOrderSyncInfoDAO extends IGenericDAO<OrderSyncInfo, Long> {
|
|||
|
||||
/**
|
||||
* Search last synchronized info for the specified
|
||||
* <code>{@link Order}</code>
|
||||
* <code>{@link Order}</code> and <code>connectorId</code>
|
||||
*
|
||||
* @param order
|
||||
* the order to search for
|
||||
* @param connectorId
|
||||
* the connector-id
|
||||
*
|
||||
* @return Last synchronized info
|
||||
*/
|
||||
OrderSyncInfo findByOrderLastSynchronizedInfo(Order order);
|
||||
OrderSyncInfo findLastSynchronizedInfoByOrderAndConnectorId(Order order,
|
||||
String connectorId);
|
||||
|
||||
/**
|
||||
* Search last synchronized infos for the specified
|
||||
* <code>{@link Order}</code>
|
||||
* <code>{@link Order}</code> and <code>connectorId</code>
|
||||
*
|
||||
* @param order
|
||||
* the order to search for
|
||||
*
|
||||
* @param connectorId
|
||||
* the connector-id
|
||||
* @return list of last synchronized infos
|
||||
*/
|
||||
List<OrderSyncInfo> findByOrderLastSynchronizedInfos(Order order);
|
||||
List<OrderSyncInfo> findLastSynchronizedInfosByOrderAndConnectorId(
|
||||
Order order, String connectorId);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,9 +22,6 @@ package org.libreplan.business.orders.daos;
|
|||
import java.util.List;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.criterion.DetachedCriteria;
|
||||
import org.hibernate.criterion.Projections;
|
||||
import org.hibernate.criterion.Property;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
import org.libreplan.business.common.daos.GenericDAOHibernate;
|
||||
import org.libreplan.business.orders.entities.Order;
|
||||
|
|
@ -44,26 +41,23 @@ public class OrderSyncInfoDAO extends GenericDAOHibernate<OrderSyncInfo, Long>
|
|||
implements IOrderSyncInfoDAO {
|
||||
|
||||
@Override
|
||||
public OrderSyncInfo findByOrderLastSynchronizedInfo(Order order) {
|
||||
DetachedCriteria mostRecentDate = DetachedCriteria
|
||||
.forClass(OrderSyncInfo.class)
|
||||
.setProjection(Projections.max("lastSyncDate"))
|
||||
.add(Restrictions.isNotNull("code"));
|
||||
|
||||
Criteria criteria = getSession().createCriteria(OrderSyncInfo.class);
|
||||
|
||||
criteria.add(Restrictions.eq("order", order));
|
||||
criteria.add(Property.forName("lastSyncDate").eq(mostRecentDate));
|
||||
|
||||
return (OrderSyncInfo) criteria.uniqueResult();
|
||||
public OrderSyncInfo findLastSynchronizedInfoByOrderAndConnectorId(
|
||||
Order order, String connectorId) {
|
||||
List<OrderSyncInfo> orderSyncInfoList = findLastSynchronizedInfosByOrderAndConnectorId(
|
||||
order, connectorId);
|
||||
if (orderSyncInfoList == null || orderSyncInfoList.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return orderSyncInfoList.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<OrderSyncInfo> findByOrderLastSynchronizedInfos(Order order) {
|
||||
public List<OrderSyncInfo> findLastSynchronizedInfosByOrderAndConnectorId(
|
||||
Order order, String connectorId) {
|
||||
Criteria criteria = getSession().createCriteria(OrderSyncInfo.class);
|
||||
criteria.add(Restrictions.eq("order", order));
|
||||
criteria.add(Restrictions.isNotNull("code"));
|
||||
criteria.add(Restrictions.eq("connectorId", connectorId));
|
||||
criteria.addOrder(org.hibernate.criterion.Order.desc("lastSyncDate"));
|
||||
return criteria.list();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,23 +22,37 @@ package org.libreplan.business.orders.entities;
|
|||
import java.util.Date;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.hibernate.validator.NotNull;
|
||||
import org.libreplan.business.common.BaseEntity;
|
||||
|
||||
/**
|
||||
* OrderSyncInfo entity
|
||||
* OrderSyncInfo entity. This entity holds order synchronization info. Each time
|
||||
* that order synchronization is successfully completed, an instance of this
|
||||
* entity is created and saved to DB to hold the synchronized info. This info is
|
||||
* then displayed in UI.
|
||||
*
|
||||
* This entity contains the following fields:
|
||||
* <ul>
|
||||
* <li>lastSyncDate: last date where synchronization took place</li>
|
||||
* <li>key: an identifier, which connector's key is last synchronized</li>
|
||||
* <li>connectorId: an identifier to distinguish which connector has running the
|
||||
* synchronization</li>
|
||||
* <li>order: order that is synchronized</li>
|
||||
* </ul>
|
||||
*
|
||||
* @author Miciele Ghiorghis <m.ghiorghis@antoniusziekenhuis.nl>
|
||||
*/
|
||||
public class OrderSyncInfo extends BaseEntity {
|
||||
|
||||
private Date lastSyncDate;
|
||||
private String label;
|
||||
private String code;
|
||||
private String key;
|
||||
private String connectorId;
|
||||
private Order order;
|
||||
|
||||
public static OrderSyncInfo create(Order order) {
|
||||
public static OrderSyncInfo create(Order order, String connectorId) {
|
||||
Validate.notNull(order);
|
||||
return create(new OrderSyncInfo(order));
|
||||
Validate.notEmpty(connectorId);
|
||||
return create(new OrderSyncInfo(order, connectorId));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -47,11 +61,13 @@ public class OrderSyncInfo extends BaseEntity {
|
|||
protected OrderSyncInfo() {
|
||||
}
|
||||
|
||||
private OrderSyncInfo(Order order) {
|
||||
private OrderSyncInfo(Order order, String connectorId) {
|
||||
this.lastSyncDate = new Date();
|
||||
this.order = order;
|
||||
this.connectorId = connectorId;
|
||||
}
|
||||
|
||||
@NotNull(message = "last synchronized date not specified")
|
||||
public Date getLastSyncDate() {
|
||||
return lastSyncDate;
|
||||
}
|
||||
|
|
@ -60,20 +76,22 @@ public class OrderSyncInfo extends BaseEntity {
|
|||
this.lastSyncDate = lastSyncDate;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
@NotNull(message = "key not specified")
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
@NotNull(message = "connector id not specified")
|
||||
public String getConnectorId() {
|
||||
return connectorId;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
public void setConnectorId(String connectorId) {
|
||||
this.connectorId = connectorId;
|
||||
}
|
||||
|
||||
public Order getOrder() {
|
||||
|
|
@ -83,5 +101,4 @@ public class OrderSyncInfo extends BaseEntity {
|
|||
public void setOrder(Order order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -309,7 +309,6 @@
|
|||
<comment>Change column jira_labels in configuration to TEXT in MySQL</comment>
|
||||
<sql>ALTER TABLE configuration MODIFY jira_labels TEXT</sql>
|
||||
</changeSet>
|
||||
|
||||
<!-- order sync info -->
|
||||
<changeSet author="miciele" id="create-table-order-sync-info">
|
||||
<comment>Create new table order_sync_info</comment>
|
||||
|
|
@ -320,9 +319,15 @@
|
|||
<column name="version" type="BIGINT">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="last_sync_date" type="DATETIME" />
|
||||
<column name="label" type="VARCHAR(255)" />
|
||||
<column name="code" type="VARCHAR(255)" />
|
||||
<column name="last_sync_date" type="DATETIME" >
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="key" type="VARCHAR(255)" >
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="connector_id" type="VARCHAR(255)" >
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="order_element_id" type="BIGINT" />
|
||||
</createTable>
|
||||
<addForeignKeyConstraint constraintName="order_sync_info_order_table_fkey"
|
||||
|
|
|
|||
|
|
@ -307,9 +307,9 @@
|
|||
</generator>
|
||||
</id>
|
||||
<version name="version" access="property" type="long" />
|
||||
<property name="lastSyncDate" column="last_sync_date" access="field" />
|
||||
<property name="label" access="field" />
|
||||
<property name="code" access="field" />
|
||||
<property name="lastSyncDate" column="last_sync_date" access="field" not-null="true"/>
|
||||
<property name="key" access="field" not-null="true"/>
|
||||
<property name="connectorId" column="connector_id" access="field" not-null="true"/>
|
||||
|
||||
<many-to-one name="order" class="Order">
|
||||
<column name="order_element_id" not-null="true"/>
|
||||
|
|
|
|||
|
|
@ -88,19 +88,23 @@ public class ExportTimesheetsToTim implements IExportTimesheetsToTim {
|
|||
@Autowired
|
||||
private IOrderDAO orderDAO;
|
||||
|
||||
private static final String CONNECTOR_MAJOR_ID = "Tim";
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public void exportTimesheets() {
|
||||
Map<String, String> prop = appPropertiesDAO.findByMajorId("Tim");
|
||||
Map<String, String> prop = appPropertiesDAO
|
||||
.findByMajorId(CONNECTOR_MAJOR_ID);
|
||||
List<Order> orders = orderDAO.getOrders();
|
||||
for (Order order : orders) {
|
||||
OrderSyncInfo orderSyncInfo = orderSyncInfoDAO
|
||||
.findByOrderLastSynchronizedInfo(order);
|
||||
.findLastSynchronizedInfoByOrderAndConnectorId(order,
|
||||
CONNECTOR_MAJOR_ID);
|
||||
if (orderSyncInfo == null) {
|
||||
LOG.warn("Order '" + order.getName()
|
||||
+ "' is not yet synchronized");
|
||||
} else {
|
||||
boolean result = exportTimesheets(orderSyncInfo.getCode(),
|
||||
boolean result = exportTimesheets(orderSyncInfo.getKey(),
|
||||
orderSyncInfo.getOrder(), prop);
|
||||
LOG.info("Export successful: " + result);
|
||||
}
|
||||
|
|
@ -117,7 +121,8 @@ public class ExportTimesheetsToTim implements IExportTimesheetsToTim {
|
|||
throw new RuntimeException("Order should not be empty");
|
||||
}
|
||||
|
||||
Map<String, String> prop = appPropertiesDAO.findByMajorId("Tim");
|
||||
Map<String, String> prop = appPropertiesDAO
|
||||
.findByMajorId(CONNECTOR_MAJOR_ID);
|
||||
return exportTimesheets(productCode, order, prop);
|
||||
|
||||
}
|
||||
|
|
@ -213,9 +218,9 @@ public class ExportTimesheetsToTim implements IExportTimesheetsToTim {
|
|||
.runOnAnotherTransaction(new IOnTransaction<Void>() {
|
||||
@Override
|
||||
public Void execute() {
|
||||
OrderSyncInfo orderSyncInfo = OrderSyncInfo
|
||||
.create(order);
|
||||
orderSyncInfo.setCode(productCode);
|
||||
OrderSyncInfo orderSyncInfo = OrderSyncInfo.create(
|
||||
order, CONNECTOR_MAJOR_ID);
|
||||
orderSyncInfo.setKey(productCode);
|
||||
orderSyncInfoDAO.save(orderSyncInfo);
|
||||
return null;
|
||||
}
|
||||
|
|
@ -270,7 +275,8 @@ public class ExportTimesheetsToTim implements IExportTimesheetsToTim {
|
|||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public OrderSyncInfo getOrderLastSyncInfo(Order order) {
|
||||
return orderSyncInfoDAO.findByOrderLastSynchronizedInfo(order);
|
||||
return orderSyncInfoDAO.findLastSynchronizedInfoByOrderAndConnectorId(
|
||||
order, CONNECTOR_MAJOR_ID);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ public class TimSynchronizationController extends GenericForwardComposer {
|
|||
.getLastSyncDate()));
|
||||
}
|
||||
if (labelProductCode != null) {
|
||||
labelProductCode.setValue("(" + orderSyncInfo.getCode() + ")");
|
||||
labelProductCode.setValue("(" + orderSyncInfo.getKey() + ")");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue