ItEr19S12CUIntroducionAvanceUnidadeTraballoItEr18S15:Creation of business entities and Infrastructure to control of the advance.
This commit is contained in:
parent
6e71e01e9e
commit
2925e6038e
24 changed files with 1028 additions and 20 deletions
|
|
@ -0,0 +1,18 @@
|
|||
package org.navalplanner.business.advance.daos;
|
||||
|
||||
import org.navalplanner.business.advance.entities.AdvanceAssigment;
|
||||
import org.navalplanner.business.common.daos.impl.GenericDaoHibernate;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* Dao for {@link AdvanceAssigment}
|
||||
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
|
||||
*/
|
||||
@Repository
|
||||
@Scope(BeanDefinition.SCOPE_SINGLETON)
|
||||
public class AdvanceAssigmentDAO extends
|
||||
GenericDaoHibernate<AdvanceAssigment, Long> implements
|
||||
IAdvanceAssigmentDAO {
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
package org.navalplanner.business.advance.daos;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* A registry of Advance DAOs. Classes in which dependency injection (DI) is
|
||||
* not directly supported by Spring (e.g. entities) must use this class to
|
||||
* access resource DAOs. For the rest of classes (e.g. services, tests, etc.),
|
||||
* Spring DI is a more convenient option.
|
||||
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
|
||||
*/
|
||||
|
||||
public class AdvanceDaoRegistry {
|
||||
|
||||
private static AdvanceDaoRegistry instance = new AdvanceDaoRegistry();
|
||||
|
||||
@Autowired
|
||||
private IAdvanceAssigmentDAO advanceAssigmentDao;
|
||||
|
||||
@Autowired
|
||||
private IAdvanceTypeDAO advanceTypeDao;
|
||||
|
||||
@Autowired
|
||||
private IAdvanceMeasurementDAO advanceMeasurementDao;
|
||||
|
||||
private AdvanceDaoRegistry() {
|
||||
}
|
||||
|
||||
public static AdvanceDaoRegistry getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static IAdvanceMeasurementDAO getAdvanceMeasurementDao() {
|
||||
return getInstance().advanceMeasurementDao;
|
||||
}
|
||||
|
||||
public static IAdvanceTypeDAO getAdvanceTypeDao() {
|
||||
return getInstance().advanceTypeDao;
|
||||
}
|
||||
|
||||
public static IAdvanceAssigmentDAO getAdvanceAssigmentDao() {
|
||||
return getInstance().advanceAssigmentDao;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package org.navalplanner.business.advance.daos;
|
||||
|
||||
import org.navalplanner.business.common.daos.impl.GenericDaoHibernate;
|
||||
import org.navalplanner.business.advance.entities.AdvanceMeasurement;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* Dao for {@link AdvanceMeasurement}
|
||||
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
|
||||
*/
|
||||
@Repository
|
||||
@Scope(BeanDefinition.SCOPE_SINGLETON)
|
||||
public class AdvanceMeasurementDAO extends GenericDaoHibernate<AdvanceMeasurement, Long> implements IAdvanceMeasurementDAO{
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package org.navalplanner.business.advance.daos;
|
||||
|
||||
import org.navalplanner.business.common.daos.impl.GenericDaoHibernate;
|
||||
import org.navalplanner.business.advance.entities.AdvanceType;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* Dao for {@link AdvanceType}
|
||||
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
|
||||
*/
|
||||
@Repository
|
||||
@Scope(BeanDefinition.SCOPE_SINGLETON)
|
||||
public class AdvanceTypeDAO extends GenericDaoHibernate<AdvanceType, Long> implements IAdvanceTypeDAO{
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
package org.navalplanner.business.advance.daos;
|
||||
|
||||
import java.util.List;
|
||||
import org.navalplanner.business.common.daos.IGenericDao;
|
||||
import org.navalplanner.business.orders.entities.OrderElement;
|
||||
import org.navalplanner.business.advance.entities.AdvanceAssigment;
|
||||
|
||||
/**
|
||||
* Contract for {@link AdvanceAssigmentDao}
|
||||
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
|
||||
*/
|
||||
|
||||
public interface IAdvanceAssigmentDAO extends IGenericDao<AdvanceAssigment, Long> {
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
package org.navalplanner.business.advance.daos;
|
||||
|
||||
import org.navalplanner.business.common.daos.IGenericDao;
|
||||
import org.navalplanner.business.advance.entities.AdvanceMeasurement;
|
||||
|
||||
/**
|
||||
* Contract for {@link AdvanceMeasurementDao}
|
||||
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
|
||||
*/
|
||||
|
||||
public interface IAdvanceMeasurementDAO extends IGenericDao<AdvanceMeasurement, Long> {
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
package org.navalplanner.business.advance.daos;
|
||||
|
||||
import org.navalplanner.business.common.daos.IGenericDao;
|
||||
import org.navalplanner.business.advance.entities.AdvanceType;
|
||||
|
||||
/**
|
||||
* Contract for {@link AdvanceTypeDao}
|
||||
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
|
||||
*/
|
||||
|
||||
public interface IAdvanceTypeDAO extends IGenericDao<AdvanceType, Long>{
|
||||
}
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
package org.navalplanner.business.advance.entities;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Set;
|
||||
|
||||
import org.navalplanner.business.orders.entities.OrderElement;
|
||||
import org.navalplanner.business.workreports.entities.WorkReportLine;
|
||||
|
||||
public class AdvanceAssigment{
|
||||
private Long id;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private long version;
|
||||
|
||||
private boolean reportGlobalAdvance;
|
||||
|
||||
private BigDecimal maxValue;
|
||||
|
||||
private OrderElement orderElement;
|
||||
|
||||
private AdvanceType advanceType;
|
||||
|
||||
Set<AdvanceMeasurement> advanceMeasurements;
|
||||
|
||||
public AdvanceAssigment(boolean reportGlobalAdvance, BigDecimal maxValue) {
|
||||
this.reportGlobalAdvance = reportGlobalAdvance;
|
||||
this.maxValue = maxValue;
|
||||
this.maxValue.setScale(2);
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public long getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setMaxValue(BigDecimal maxValue) {
|
||||
this.maxValue = maxValue;
|
||||
this.maxValue.setScale(2);
|
||||
}
|
||||
|
||||
public BigDecimal getMaxValue() {
|
||||
return this.maxValue;
|
||||
}
|
||||
|
||||
public void setReportGlobalAdvance(boolean reportGlobalAdvance) {
|
||||
this.reportGlobalAdvance = reportGlobalAdvance;
|
||||
}
|
||||
|
||||
public boolean getReportGlobalAdvance() {
|
||||
return this.reportGlobalAdvance;
|
||||
}
|
||||
|
||||
public void setOrderElement(OrderElement orderElement) {
|
||||
this.orderElement = orderElement;
|
||||
}
|
||||
|
||||
public OrderElement getOrderElement() {
|
||||
return this.orderElement;
|
||||
}
|
||||
|
||||
public void setAdvanceType(AdvanceType advanceType) {
|
||||
this.advanceType = advanceType;
|
||||
}
|
||||
|
||||
public AdvanceType getAdvanceType() {
|
||||
return this.advanceType;
|
||||
}
|
||||
|
||||
public void setAdvanceMeasurements(Set<AdvanceMeasurement> advanceMeasurements) {
|
||||
this.advanceMeasurements = advanceMeasurements;
|
||||
}
|
||||
|
||||
public Set<AdvanceMeasurement> getAdvanceMeasurements() {
|
||||
return this.advanceMeasurements;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
package org.navalplanner.business.advance.entities;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
public class AdvanceMeasurement {
|
||||
private Long id;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private long version;
|
||||
|
||||
private Date date;
|
||||
|
||||
private BigDecimal value;
|
||||
|
||||
private AdvanceAssigment advanceAssigment;
|
||||
|
||||
public AdvanceMeasurement(Date date, BigDecimal value) {
|
||||
this.date = date;
|
||||
this.value = value;
|
||||
this.value.setScale(2);
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public long getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setDate(Date date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public Date getDate() {
|
||||
return this.date;
|
||||
}
|
||||
|
||||
public void setValue(BigDecimal value) {
|
||||
this.value = value;
|
||||
this.value.setScale(2);
|
||||
}
|
||||
|
||||
public BigDecimal getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public void setAdvanceAssigment(AdvanceAssigment advanceAssigment) {
|
||||
this.advanceAssigment = advanceAssigment;
|
||||
}
|
||||
|
||||
public AdvanceAssigment getAdvanceAssigment() {
|
||||
return this.advanceAssigment;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
package org.navalplanner.business.advance.entities;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import org.navalplanner.business.orders.entities.OrderElement;
|
||||
|
||||
/**
|
||||
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
|
||||
*/
|
||||
|
||||
public class AdvanceType {
|
||||
private Long id;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private long version;
|
||||
|
||||
private String unitName;
|
||||
|
||||
private BigDecimal defaultMaxValue;
|
||||
|
||||
private boolean updatable;
|
||||
|
||||
public AdvanceType(String unitName, BigDecimal defaultMaxValue,boolean updatable) {
|
||||
this.unitName = unitName;
|
||||
this.defaultMaxValue = defaultMaxValue;
|
||||
this.defaultMaxValue.setScale(2);
|
||||
this.updatable = updatable;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public long getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setUnitName(String unitName) {
|
||||
this.unitName = unitName;
|
||||
}
|
||||
|
||||
public String getUnitName() {
|
||||
return this.unitName;
|
||||
}
|
||||
|
||||
public void setDefaultMaxValue(BigDecimal defaultMaxValue) {
|
||||
this.defaultMaxValue = defaultMaxValue;
|
||||
this.defaultMaxValue.setScale(2);
|
||||
}
|
||||
|
||||
public BigDecimal getDefaultMaxValue() {
|
||||
return this.defaultMaxValue;
|
||||
}
|
||||
|
||||
public void setUpdatable(boolean updatable) {
|
||||
this.updatable = updatable;
|
||||
}
|
||||
|
||||
public boolean getUpdatable() {
|
||||
return this.updatable;
|
||||
}
|
||||
|
||||
public void doPropagateAdvaceToParent(OrderElement orderElement) {
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
package org.navalplanner.business.advance.exceptions;
|
||||
|
||||
/**
|
||||
* An exception for modeling a problem with duplicated advance assigment of the
|
||||
* same type for an order element. It contains a message, the key of the
|
||||
* instance, and its class name.
|
||||
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class DuplicateAdvanceAssigmentForOrderElementException extends
|
||||
Exception {
|
||||
|
||||
private Object key;
|
||||
private String className;
|
||||
|
||||
public DuplicateAdvanceAssigmentForOrderElementException(
|
||||
String specificMessage, Object key, String className) {
|
||||
super(specificMessage + " (key = '" + key + "' - className = '"
|
||||
+ className + "')");
|
||||
this.key = key;
|
||||
this.className = className;
|
||||
}
|
||||
|
||||
public Object getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public String getClassName() {
|
||||
return className;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
package org.navalplanner.business.advance.exceptions;
|
||||
|
||||
/**
|
||||
* An exception for modeling a problem with duplicated values to true for the
|
||||
* property reportGlobalAdvance of the advanceAsigment class for an order
|
||||
* element. It contains a message, the key of the instance, and its class name.
|
||||
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class DuplicateValueTrueReportGlobalAdvanceException extends Exception {
|
||||
|
||||
private Object key;
|
||||
private String className;
|
||||
|
||||
public DuplicateValueTrueReportGlobalAdvanceException(
|
||||
String specificMessage, Object key, String className) {
|
||||
super(specificMessage + " (key = '" + key + "' - className = '"
|
||||
+ className + "')");
|
||||
this.key = key;
|
||||
this.className = className;
|
||||
}
|
||||
|
||||
public Object getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public String getClassName() {
|
||||
return className;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,14 +1,14 @@
|
|||
package org.navalplanner.business.orders.daos;
|
||||
import java.util.List;
|
||||
|
||||
import org.navalplanner.business.common.daos.IGenericDao;
|
||||
import org.navalplanner.business.orders.entities.OrderElement;
|
||||
import org.navalplanner.business.resources.entities.Worker;
|
||||
|
||||
/**
|
||||
* Contract for {@link OrderElementDao}
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
* @author Diego Pino García <dpino@igalia.com>
|
||||
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
|
||||
*/
|
||||
public interface IOrderElementDao extends IGenericDao<OrderElement, Long> {
|
||||
public OrderElement findByCode(String code);
|
||||
|
|
@ -21,4 +21,6 @@ public interface IOrderElementDao extends IGenericDao<OrderElement, Long> {
|
|||
* @return the {@link OrderElement} found
|
||||
*/
|
||||
public OrderElement findByCode(OrderElement parent, String code);
|
||||
public List<OrderElement> findParent(
|
||||
OrderElement orderElement);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package org.navalplanner.business.orders.daos;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
import org.navalplanner.business.common.daos.impl.GenericDaoHibernate;
|
||||
|
|
@ -10,10 +12,10 @@ import org.springframework.stereotype.Repository;
|
|||
|
||||
/**
|
||||
* Dao for {@link OrderElement}
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
* @author Diego Pino García <dpino@igalia.com>
|
||||
*/
|
||||
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
|
||||
**/
|
||||
@Repository
|
||||
@Scope(BeanDefinition.SCOPE_SINGLETON)
|
||||
public class OrderElementDao extends GenericDaoHibernate<OrderElement, Long>
|
||||
|
|
@ -31,4 +33,12 @@ public class OrderElementDao extends GenericDaoHibernate<OrderElement, Long>
|
|||
c.add(Restrictions.eq("parent", orderElement));
|
||||
return (OrderElement) c.uniqueResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OrderElement> findParent(OrderElement orderElement) {
|
||||
Criteria c = getSession().createCriteria(OrderElement.class)
|
||||
.createCriteria("children").add(
|
||||
Restrictions.idEq(orderElement.getId()));
|
||||
return ((List<OrderElement>) c.list());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ public class OrdersDaoRegistry {
|
|||
@Autowired
|
||||
private IOrderDao order;
|
||||
|
||||
@Autowired
|
||||
private IOrderElementDao orderElement;
|
||||
|
||||
private OrdersDaoRegistry() {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,10 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
|
||||
import org.hibernate.validator.NotEmpty;
|
||||
import org.navalplanner.business.advance.entities.AdvanceAssigment;
|
||||
import org.navalplanner.business.advance.exceptions.DuplicateAdvanceAssigmentForOrderElementException;
|
||||
import org.navalplanner.business.advance.exceptions.DuplicateValueTrueReportGlobalAdvanceException;
|
||||
import org.navalplanner.business.orders.daos.OrdersDaoRegistry;
|
||||
import org.navalplanner.business.planner.entities.TaskElement;
|
||||
|
||||
public abstract class OrderElement {
|
||||
|
|
@ -28,6 +32,8 @@ public abstract class OrderElement {
|
|||
|
||||
private String description;
|
||||
|
||||
private Set<AdvanceAssigment> advanceAssigments = new HashSet<AdvanceAssigment>();
|
||||
|
||||
@NotEmpty
|
||||
private String code;
|
||||
|
||||
|
|
@ -168,4 +174,67 @@ public abstract class OrderElement {
|
|||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
public void setAdvanceAssigments(Set<AdvanceAssigment> advanceAssigments) {
|
||||
this.advanceAssigments = advanceAssigments;
|
||||
}
|
||||
|
||||
public Set<AdvanceAssigment> getAdvanceAssigments() {
|
||||
return this.advanceAssigments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate if the advanceAssigment can be added to the order element.The
|
||||
* list of advanceAssigments must be attached.
|
||||
* @param advanceAssigment
|
||||
* must be attached
|
||||
*/
|
||||
public void addAvanceAssigment(AdvanceAssigment newAdvanceAssigment)
|
||||
throws Exception {
|
||||
if (!this.advanceAssigments.isEmpty()) {
|
||||
for (AdvanceAssigment advanceAssigment : getAdvanceAssigments()) {
|
||||
if (advanceAssigment.getAdvanceType().getId() == newAdvanceAssigment
|
||||
.getAdvanceType().getId()) {
|
||||
System.out.println("bien");
|
||||
throw new DuplicateAdvanceAssigmentForOrderElementException(
|
||||
"Duplicate Advance Assigment For Order Element",
|
||||
this,
|
||||
"org.navalplanner.business.orders.entities.OrderElement");
|
||||
}
|
||||
|
||||
if (advanceAssigment.getReportGlobalAdvance()
|
||||
&& newAdvanceAssigment.getReportGlobalAdvance())
|
||||
throw new DuplicateValueTrueReportGlobalAdvanceException(
|
||||
"Duplicate Value True ReportGlobalAdvance For Order Element",
|
||||
this,
|
||||
"org.navalplanner.business.orders.entities.OrderElement");
|
||||
}
|
||||
}
|
||||
existParentsWithSameAdvanceType(this, newAdvanceAssigment);
|
||||
this.advanceAssigments.add(newAdvanceAssigment);
|
||||
}
|
||||
|
||||
private void existParentsWithSameAdvanceType(OrderElement orderElement,
|
||||
AdvanceAssigment newAdvanceAssigment)
|
||||
throws DuplicateAdvanceAssigmentForOrderElementException {
|
||||
|
||||
List<OrderElement> parents = OrdersDaoRegistry.getOrderElementDao()
|
||||
.findParent(orderElement);
|
||||
for (OrderElement orderElementParent : parents) {
|
||||
for (AdvanceAssigment advanceAssigment : orderElementParent
|
||||
.getAdvanceAssigments()) {
|
||||
if (advanceAssigment.getAdvanceType().getId() == newAdvanceAssigment
|
||||
.getAdvanceType().getId()) {
|
||||
throw new DuplicateAdvanceAssigmentForOrderElementException(
|
||||
"Duplicate Advance Assigment For Order Element",
|
||||
this,
|
||||
"org.navalplanner.business.orders.entities.OrderElement");
|
||||
}
|
||||
}
|
||||
existParentsWithSameAdvanceType(orderElementParent,
|
||||
newAdvanceAssigment);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -14,12 +14,14 @@
|
|||
|
||||
<!-- Hibernate Session Factory. -->
|
||||
<bean id="sessionFactory"
|
||||
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
|
||||
p:dataSource-ref="dataSource"
|
||||
p:configLocation="classpath:/navalplanner-business-hibernate.cfg.xml">
|
||||
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
|
||||
p:dataSource-ref="dataSource" p:configLocation="classpath:/navalplanner-business-hibernate.cfg.xml">
|
||||
|
||||
<property name="mappingResources">
|
||||
<list>
|
||||
<value>
|
||||
org/navalplanner/business/advance/entities/Advance.hbm.xml
|
||||
</value>
|
||||
<value>
|
||||
org/navalplanner/business/resources/entities/Resources.hbm.xml
|
||||
</value>
|
||||
|
|
@ -35,7 +37,7 @@
|
|||
<value>
|
||||
org/navalplanner/business/workreports/entities/WorkReports.hbm.xml
|
||||
</value>
|
||||
</list>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
|
|
@ -45,8 +47,7 @@
|
|||
p:sessionFactory-ref="sessionFactory" />
|
||||
|
||||
<!--
|
||||
Enable configuration of transactional behavior based on
|
||||
annotations
|
||||
Enable configuration of transactional behavior based on annotations
|
||||
-->
|
||||
<tx:annotation-driven transaction-manager="transactionManager" />
|
||||
|
||||
|
|
@ -56,10 +57,12 @@
|
|||
-->
|
||||
<context:annotation-config />
|
||||
|
||||
<context:component-scan base-package="org.navalplanner.business"/>
|
||||
<context:component-scan base-package="org.navalplanner.business" />
|
||||
|
||||
<!-- DAO registries (to be used from non-Spring managed objects
|
||||
(e.g. entities) -->
|
||||
<!--
|
||||
DAO registries (to be used from non-Spring managed objects (e.g.
|
||||
entities)
|
||||
-->
|
||||
|
||||
<bean id="resourcesDaoRegistry"
|
||||
class="org.navalplanner.business.resources.daos.ResourcesDaoRegistry"
|
||||
|
|
@ -76,4 +79,9 @@
|
|||
<bean id="workReportsDaoRegistry"
|
||||
class="org.navalplanner.business.workreports.daos.WorkReportsDaoRegistry"
|
||||
factory-method="getInstance" />
|
||||
|
||||
<bean id="advanceDaoRegistry"
|
||||
class="org.navalplanner.business.advance.daos.AdvanceDaoRegistry"
|
||||
factory-method="getInstance" />
|
||||
|
||||
</beans>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,49 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
|
||||
<hibernate-mapping package="org.navalplanner.business.advance.entities" default-access="field">
|
||||
|
||||
<!-- AdvanceType -->
|
||||
<class name="AdvanceType" table="ADVANCE_TYPE">
|
||||
<id name="id" type="long">
|
||||
<generator class="native"/>
|
||||
</id>
|
||||
<version name="version" type="long"/>
|
||||
|
||||
<property name="unitName"/>
|
||||
<property name="defaultMaxValue"/>
|
||||
<property name="updatable"/>
|
||||
</class>
|
||||
|
||||
<!-- AdvanceAssigment -->
|
||||
<class name="AdvanceAssigment" table="ADVANCE_ASSIGMENT">
|
||||
<id name="id" type="long">
|
||||
<generator class="native"/>
|
||||
</id>
|
||||
<version name="version" type="long"/>
|
||||
|
||||
<property name="maxValue"/>
|
||||
<property name="reportGlobalAdvance"/>
|
||||
|
||||
<many-to-one name="advanceType" class="AdvanceType" column="ADVANCE_TYPE_ID"/>
|
||||
|
||||
<many-to-one name="orderElement" class="org.navalplanner.business.orders.entities.OrderElement" column="ORDER_ELEMENT_ID"/>
|
||||
|
||||
<set name="advanceMeasurements" cascade="all" inverse="true">
|
||||
<key column="ADVANCE_ASSIGMENT_ID"/>
|
||||
<one-to-many class="AdvanceMeasurement"/>
|
||||
</set>
|
||||
</class>
|
||||
|
||||
<!-- AdvanceMeasurement -->
|
||||
<class name="AdvanceMeasurement" table="ADVANCE_MEASUREMENT">
|
||||
<id name="id" type="long">
|
||||
<generator class="native"/>
|
||||
</id>
|
||||
<version name="version" type="long"/>
|
||||
|
||||
<property name="date"/>
|
||||
<property name="value"/>
|
||||
|
||||
<many-to-one name="advanceAssigment" class="AdvanceAssigment" column="ADVANCE_ASSIGMENT_ID" />
|
||||
</class>
|
||||
</hibernate-mapping>
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
<id access="field" type="long" name="id">
|
||||
<generator class="native" />
|
||||
</id>
|
||||
<version name="version" access="field" type="long" />
|
||||
<version name="version" access="field" type="long"/>
|
||||
<property name="initDate" access="field"></property>
|
||||
<property name="endDate" access="field"></property>
|
||||
<property name="name" access="field"></property>
|
||||
|
|
@ -15,7 +15,7 @@
|
|||
<list name="orderElements" access="field" cascade="all">
|
||||
<key column="orderId" not-null="false"></key>
|
||||
<index column="positionInOrder"></index>
|
||||
<one-to-many class="OrderElement" />
|
||||
<one-to-many class="OrderElement"/>
|
||||
</list>
|
||||
</class>
|
||||
|
||||
|
|
@ -31,11 +31,15 @@
|
|||
<property name="mandatoryInit" access="field" />
|
||||
<property name="mandatoryEnd" access="field" />
|
||||
<property name="description" access="field" />
|
||||
<property name="code" access="field"/>
|
||||
<property name="code" access="field" />
|
||||
<set name="taskElements" access="field" cascade="delete">
|
||||
<key column="ORDER_ELEMENT_ID"/>
|
||||
<key column="ORDER_ELEMENT_ID" />
|
||||
<one-to-many class="org.navalplanner.business.planner.entities.TaskElement"></one-to-many>
|
||||
</set>
|
||||
<set name="advanceAssigments" cascade="all" inverse="true">
|
||||
<key column="ORDER_ELEMENT_ID" />
|
||||
<one-to-many class="org.navalplanner.business.advance.entities.AdvanceAssigment"></one-to-many>
|
||||
</set>
|
||||
|
||||
<!-- Inverse navigation from OrderElement to OrderLineGroup -->
|
||||
<many-to-one name="parent" access="field"/>
|
||||
|
|
@ -77,8 +81,8 @@
|
|||
</set>
|
||||
|
||||
<many-to-one name="parentOrderLine" column="PARENT_ORDER_LINE"
|
||||
not-null="true"/>
|
||||
not-null="true" />
|
||||
|
||||
</class>
|
||||
</class>
|
||||
|
||||
</hibernate-mapping>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
package org.navalplanner.business.test.advance.entities;
|
||||
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class AdvanceAssigmentTest {
|
||||
@Test
|
||||
public void testAdvanceAssigmentTest() {
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package org.navalplanner.business.test.advance.entities;
|
||||
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class AdvanceMeasurementTest {
|
||||
@Test
|
||||
public void testAdvanceMeasurementTest() {
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package org.navalplanner.business.test.advance.entities;
|
||||
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class AdvanceTypeTest {
|
||||
|
||||
@Test
|
||||
public void testAdvanceTypeTest() {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,431 @@
|
|||
package org.navalplanner.business.test.orders.entities;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.navalplanner.business.BusinessGlobalNames.BUSINESS_SPRING_CONFIG_FILE;
|
||||
import static org.navalplanner.business.test.BusinessGlobalNames.BUSINESS_SPRING_CONFIG_TEST_FILE;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.navalplanner.business.advance.daos.IAdvanceAssigmentDAO;
|
||||
import org.navalplanner.business.advance.daos.IAdvanceTypeDAO;
|
||||
import org.navalplanner.business.advance.entities.AdvanceAssigment;
|
||||
import org.navalplanner.business.advance.entities.AdvanceType;
|
||||
import org.navalplanner.business.advance.exceptions.DuplicateAdvanceAssigmentForOrderElementException;
|
||||
import org.navalplanner.business.advance.exceptions.DuplicateValueTrueReportGlobalAdvanceException;
|
||||
import org.navalplanner.business.orders.daos.IOrderDao;
|
||||
import org.navalplanner.business.orders.daos.IOrderElementDao;
|
||||
import org.navalplanner.business.orders.entities.HoursGroup;
|
||||
import org.navalplanner.business.orders.entities.Order;
|
||||
import org.navalplanner.business.orders.entities.OrderElement;
|
||||
import org.navalplanner.business.orders.entities.OrderLine;
|
||||
import org.navalplanner.business.orders.entities.OrderLineGroup;
|
||||
import org.navalplanner.business.test.resources.daos.CriterionSatisfactionDAOTest;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* Tests for {@link AdvanceAssigment of OrderElement}. <br />
|
||||
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { BUSINESS_SPRING_CONFIG_FILE,
|
||||
BUSINESS_SPRING_CONFIG_TEST_FILE })
|
||||
@Transactional
|
||||
public class AddAdvanceAssigmentsToOrderElementTest {
|
||||
|
||||
@Autowired
|
||||
private SessionFactory sessionFactory;
|
||||
|
||||
@Autowired
|
||||
private IOrderElementDao orderElementDao;
|
||||
|
||||
@Autowired
|
||||
private IOrderDao orderDao;
|
||||
|
||||
@Autowired
|
||||
private IAdvanceAssigmentDAO advanceAssigmentDao;
|
||||
|
||||
@Autowired
|
||||
private IAdvanceTypeDAO advanceTypeDao;
|
||||
|
||||
private Session getSession() {
|
||||
return sessionFactory.getCurrentSession();
|
||||
}
|
||||
|
||||
private static Order createValidOrder() {
|
||||
Order order = new Order();
|
||||
order.setDescription("description");
|
||||
order.setCustomer("blabla");
|
||||
order.setInitDate(CriterionSatisfactionDAOTest.year(2000));
|
||||
order.setName("name");
|
||||
order.setResponsible("responsible");
|
||||
return order;
|
||||
}
|
||||
|
||||
private OrderLine createValidLeaf(String name, String code) {
|
||||
OrderLine result = new OrderLine();
|
||||
result.setName(name);
|
||||
result.setCode(code);
|
||||
HoursGroup hoursGroup = new HoursGroup(result);
|
||||
hoursGroup.setWorkingHours(0);
|
||||
result.addHoursGroup(hoursGroup);
|
||||
return result;
|
||||
}
|
||||
|
||||
private AdvanceType createValidAdvanceType(String name) {
|
||||
BigDecimal value = new BigDecimal(120).setScale(2);
|
||||
AdvanceType advanceType = new AdvanceType(name, value, true);
|
||||
return advanceType;
|
||||
}
|
||||
|
||||
private AdvanceAssigment createValidAdvanceAssigment(
|
||||
boolean reportGlobalAdvance) {
|
||||
BigDecimal value = new BigDecimal(120).setScale(2);
|
||||
AdvanceAssigment advanceAssigment = new AdvanceAssigment(
|
||||
reportGlobalAdvance, value);
|
||||
return advanceAssigment;
|
||||
}
|
||||
|
||||
/**
|
||||
* An empty {@link OrderElement} without any {@link AdvanceAssigment}.
|
||||
* Trying to add a new {@link AdvanceAssigment} to {@link OrderElement} .
|
||||
* Expected: Add new {@link AdvanceAssigment} to the list of
|
||||
* advanceAssigment of {@link OrderElement}.
|
||||
*/
|
||||
@Test
|
||||
public void testSetAdvanceAssigmentEmptyOrderElement() {
|
||||
Order order = createValidOrder();
|
||||
OrderElement orderLine = createValidLeaf("OrderLineA", "1k1k1k1k");
|
||||
|
||||
AdvanceType advanceType = createValidAdvanceType("tipoA");
|
||||
advanceTypeDao.save(advanceType);
|
||||
assertTrue(advanceTypeDao.exists(advanceType.getId()));
|
||||
|
||||
AdvanceAssigment advanceAssigment = createValidAdvanceAssigment(true);
|
||||
assertTrue(orderLine.getAdvanceAssigments().isEmpty());
|
||||
advanceAssigment.setAdvanceType(advanceType);
|
||||
|
||||
order.add(orderLine);
|
||||
orderDao.save(order);
|
||||
|
||||
try {
|
||||
orderLine.addAvanceAssigment(advanceAssigment);
|
||||
} catch (DuplicateAdvanceAssigmentForOrderElementException e) {
|
||||
fail("Duplicate Exception");
|
||||
} catch (Exception e) {
|
||||
fail("It should not throw an exception ");
|
||||
}
|
||||
|
||||
order.add(orderLine);
|
||||
orderDao.save(order);
|
||||
this.sessionFactory.getCurrentSession().flush();
|
||||
assertTrue(orderDao.exists(order.getId()));
|
||||
assertTrue(orderElementDao.exists(orderLine.getId()));
|
||||
|
||||
assertFalse(orderLine.getAdvanceAssigments().isEmpty());
|
||||
assertTrue(advanceAssigmentDao.exists(advanceAssigment.getId()));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* An {@link OrderElement} with an {@link AdvanceAssigment}. Trying to add a
|
||||
* new {@link AdvanceAssigment} to {@link OrderElement} . Expected: Add to
|
||||
* the list a new {@link AdvanceAssigment} of diferent type.
|
||||
*/
|
||||
@Test
|
||||
public void testSetOtherAdvanceAssigmentOrderElement() {
|
||||
Order order = createValidOrder();
|
||||
OrderLine orderLine = createValidLeaf("OrderLineA", "1111111");
|
||||
|
||||
AdvanceType advanceTypeA = createValidAdvanceType("tipoA");
|
||||
advanceTypeDao.save(advanceTypeA);
|
||||
AdvanceType advanceTypeB = createValidAdvanceType("tipoB");
|
||||
advanceTypeDao.save(advanceTypeB);
|
||||
|
||||
AdvanceAssigment advanceAssigmentA = createValidAdvanceAssigment(true);
|
||||
advanceAssigmentA.setAdvanceType(advanceTypeA);
|
||||
|
||||
order.add(orderLine);
|
||||
orderDao.save(order);
|
||||
|
||||
try {
|
||||
orderLine.addAvanceAssigment(advanceAssigmentA);
|
||||
} catch (Exception e) {
|
||||
fail("It should not throw an exception ");
|
||||
}
|
||||
|
||||
AdvanceAssigment advanceAssigmentB = createValidAdvanceAssigment(false);
|
||||
advanceAssigmentB.setAdvanceType(advanceTypeB);
|
||||
try {
|
||||
orderLine.addAvanceAssigment(advanceAssigmentB);
|
||||
} catch (Exception e) {
|
||||
fail("It should not throw an exception ");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An {@link OrderElement} with an {@link AdvanceAssigment}. Trying to add a
|
||||
* new {@link AdvanceAssigment} of the same type.to {@link OrderElement}
|
||||
* Expected: It must throw a
|
||||
* DuplicateAdvanceAssigmentForOrderElementException Exception.
|
||||
*/
|
||||
@Test
|
||||
public void testSetOtherAdvanceAssigmentOrderElementIllegal() {
|
||||
Order order = createValidOrder();
|
||||
OrderLine orderLine = createValidLeaf("OrderLineA", "22222222");
|
||||
|
||||
AdvanceType advanceTypeA = createValidAdvanceType("tipoA");
|
||||
advanceTypeDao.save(advanceTypeA);
|
||||
|
||||
AdvanceAssigment advanceAssigmentA = createValidAdvanceAssigment(true);
|
||||
advanceAssigmentA.setAdvanceType(advanceTypeA);
|
||||
|
||||
order.add(orderLine);
|
||||
orderDao.save(order);
|
||||
|
||||
try {
|
||||
orderLine.addAvanceAssigment(advanceAssigmentA);
|
||||
} catch (Exception e) {
|
||||
fail("It should not throw an exception ");
|
||||
}
|
||||
|
||||
AdvanceAssigment advanceAssigmentB = createValidAdvanceAssigment(false);
|
||||
advanceAssigmentB.setAdvanceType(advanceTypeA);
|
||||
try {
|
||||
orderLine.addAvanceAssigment(advanceAssigmentB);
|
||||
fail("It should throw an exception");
|
||||
} catch (Exception e) {
|
||||
// Ok } }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An {@link OrderElement} with an {@link AdvanceAssigment}. Trying to add a
|
||||
* new {@link AdvanceAssigment} with the ReportGloblalAdvance value true to
|
||||
* {@link OrderElement} Expected: It must throw a
|
||||
* DuplicateValueTrueReportGlobalAdvanceException Exception.
|
||||
*/
|
||||
@Test
|
||||
public void testSetWithSameReportGloblalAdvance() {
|
||||
Order order = createValidOrder();
|
||||
OrderLine orderLine = createValidLeaf("OrderLineA", "101010101");
|
||||
|
||||
AdvanceType advanceTypeA = createValidAdvanceType("tipoA");
|
||||
advanceTypeDao.save(advanceTypeA);
|
||||
AdvanceType advanceTypeB = createValidAdvanceType("tipoB");
|
||||
advanceTypeDao.save(advanceTypeB);
|
||||
|
||||
AdvanceAssigment advanceAssigmentA = createValidAdvanceAssigment(true);
|
||||
advanceAssigmentA.setAdvanceType(advanceTypeA);
|
||||
|
||||
order.add(orderLine);
|
||||
orderDao.save(order);
|
||||
|
||||
try {
|
||||
orderLine.addAvanceAssigment(advanceAssigmentA);
|
||||
} catch (Exception e) {
|
||||
fail("It should not throw an exception ");
|
||||
}
|
||||
|
||||
AdvanceAssigment advanceAssigmentB = createValidAdvanceAssigment(true);
|
||||
advanceAssigmentB.setAdvanceType(advanceTypeB);
|
||||
try {
|
||||
orderLine.addAvanceAssigment(advanceAssigmentB);
|
||||
fail("It should throw an exception ");
|
||||
} catch (DuplicateValueTrueReportGlobalAdvanceException e) {
|
||||
// Ok
|
||||
} catch (Exception e) {
|
||||
fail("It should not throw an exception");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Trying define an AdvanceAssigment object when any father of OrderElement
|
||||
* with an AdvanceAssigment object that has the other AdvanceType. It must
|
||||
* not throw any exception.
|
||||
**/
|
||||
@Test
|
||||
public void testSetAdvanceAssigmentOrdeElementSon() {
|
||||
final Order order = createValidOrder();
|
||||
final OrderElement[] containers = new OrderLineGroup[2];
|
||||
for (int i = 0; i < containers.length; i++) {
|
||||
containers[i] = new OrderLineGroup();
|
||||
containers[i].setName("bla");
|
||||
containers[i].setCode("000000000");
|
||||
order.add(containers[i]);
|
||||
}
|
||||
OrderLineGroup container = (OrderLineGroup) containers[0];
|
||||
final OrderElement[] orderElements = new OrderElement[4];
|
||||
for (int i = 0; i < orderElements.length; i++) {
|
||||
OrderLine leaf = createValidLeaf("bla", "787887");
|
||||
orderElements[i] = leaf;
|
||||
container.add(leaf);
|
||||
}
|
||||
|
||||
for (int i = 1; i < containers.length; i++) {
|
||||
OrderLineGroup orderLineGroup = (OrderLineGroup) containers[i];
|
||||
OrderLine leaf = createValidLeaf("foo", "156325");
|
||||
orderLineGroup.add(leaf);
|
||||
}
|
||||
|
||||
AdvanceType advanceTypeA = createValidAdvanceType("tipoA");
|
||||
advanceTypeDao.save(advanceTypeA);
|
||||
AdvanceType advanceTypeB = createValidAdvanceType("tipoB");
|
||||
advanceTypeDao.save(advanceTypeB);
|
||||
|
||||
AdvanceAssigment advanceAssigmentA = createValidAdvanceAssigment(true);
|
||||
advanceAssigmentA.setAdvanceType(advanceTypeA);
|
||||
AdvanceAssigment advanceAssigmentB = createValidAdvanceAssigment(true);
|
||||
advanceAssigmentB.setAdvanceType(advanceTypeB);
|
||||
|
||||
orderDao.save(order);
|
||||
|
||||
try {
|
||||
container.addAvanceAssigment(advanceAssigmentA);
|
||||
} catch (Exception e) {
|
||||
fail("It should not throw an exception ");
|
||||
}
|
||||
|
||||
assertThat(container.getAdvanceAssigments().size(), equalTo(1));
|
||||
assertThat(
|
||||
container.getChildren().get(0).getAdvanceAssigments().size(),
|
||||
equalTo(0));
|
||||
try {
|
||||
((OrderElement) container.getChildren().get(0))
|
||||
.addAvanceAssigment(advanceAssigmentB);
|
||||
} catch (Exception e) {
|
||||
fail("It should not throw an exception ");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Trying define an AdvanceAssigment object when any father of OrderElement
|
||||
* with an AdvanceAssigment object that has the same AdvanceType Expected:
|
||||
* It must throw DuplicateAdvanceAssigmentForOrderElementException
|
||||
* Exception.
|
||||
**/
|
||||
@Test
|
||||
public void testSetAdvanceAssigmentOrdeElementSonIllegal() {
|
||||
final Order order = createValidOrder();
|
||||
final OrderElement[] containers = new OrderLineGroup[2];
|
||||
for (int i = 0; i < containers.length; i++) {
|
||||
containers[i] = new OrderLineGroup();
|
||||
containers[i].setName("bla");
|
||||
containers[i].setCode("000000000");
|
||||
order.add(containers[i]);
|
||||
}
|
||||
OrderLineGroup container = (OrderLineGroup) containers[0];
|
||||
|
||||
final OrderElement[] orderElements = new OrderElement[4];
|
||||
for (int i = 0; i < orderElements.length; i++) {
|
||||
OrderLine leaf = createValidLeaf("bla", "97979");
|
||||
orderElements[i] = leaf;
|
||||
container.add(leaf);
|
||||
}
|
||||
|
||||
for (int i = 1; i < containers.length; i++) {
|
||||
OrderLineGroup orderLineGroup = (OrderLineGroup) containers[i];
|
||||
OrderLine leaf = createValidLeaf("foo", "797900");
|
||||
orderLineGroup.add(leaf);
|
||||
}
|
||||
|
||||
AdvanceType advanceTypeA = createValidAdvanceType("tipoA");
|
||||
advanceTypeDao.save(advanceTypeA);
|
||||
|
||||
AdvanceAssigment advanceAssigmentA = createValidAdvanceAssigment(true);
|
||||
advanceAssigmentA.setAdvanceType(advanceTypeA);
|
||||
AdvanceAssigment advanceAssigmentB = createValidAdvanceAssigment(true);
|
||||
advanceAssigmentB.setAdvanceType(advanceTypeA);
|
||||
|
||||
orderDao.save(order);
|
||||
|
||||
try {
|
||||
container.addAvanceAssigment(advanceAssigmentA);
|
||||
} catch (Exception e) {
|
||||
fail("It should not throw an exception ");
|
||||
}
|
||||
|
||||
assertThat(container.getAdvanceAssigments().size(), equalTo(1));
|
||||
assertThat(
|
||||
container.getChildren().get(0).getAdvanceAssigments().size(),
|
||||
equalTo(0));
|
||||
try {
|
||||
((OrderElement) container.getChildren().get(0))
|
||||
.addAvanceAssigment(advanceAssigmentB);
|
||||
fail("It should throw an exception ");
|
||||
} catch (Exception e) {
|
||||
// Ok
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Trying define an AdvanceAssigment object when any grandfather of
|
||||
* OrderElement with an AdvanceAssigment object that has the same
|
||||
* AdvanceType Expected: It must throw
|
||||
* DuplicateAdvanceAssigmentForOrderElementException Exception.
|
||||
**/
|
||||
@Test
|
||||
public void testSetAdvanceAssigmentOrdeElementGrandSonIllegal() {
|
||||
final Order order = createValidOrder();
|
||||
final OrderElement[] containers = new OrderLineGroup[2];
|
||||
for (int i = 0; i < containers.length; i++) {
|
||||
containers[i] = new OrderLineGroup();
|
||||
containers[i].setName("bla_" + i);
|
||||
containers[i].setCode("000000000");
|
||||
order.add(containers[i]);
|
||||
}
|
||||
OrderLineGroup container = (OrderLineGroup) containers[0];
|
||||
OrderLineGroup containerSon = (OrderLineGroup) new OrderLineGroup();
|
||||
containerSon.setName("Son");
|
||||
containerSon.setCode("11111111");
|
||||
container.add(containerSon);
|
||||
OrderLine orderLineGranSon = createValidLeaf("GranSon", "75757");
|
||||
containerSon.add(orderLineGranSon);
|
||||
final OrderElement[] orderElements = new OrderElement[2];
|
||||
for (int i = 1; i < orderElements.length; i++) {
|
||||
OrderLine leaf = createValidLeaf("bla", "979879");
|
||||
orderElements[i] = leaf;
|
||||
container.add(leaf);
|
||||
}
|
||||
for (int i = 1; i < containers.length; i++) {
|
||||
OrderLineGroup orderLineGroup = (OrderLineGroup) containers[i];
|
||||
OrderLine leaf = createValidLeaf("foo", "79799");
|
||||
orderLineGroup.add(leaf);
|
||||
}
|
||||
AdvanceType advanceTypeA = createValidAdvanceType("tipoA");
|
||||
advanceTypeDao.save(advanceTypeA);
|
||||
|
||||
AdvanceAssigment advanceAssigmentA = createValidAdvanceAssigment(true);
|
||||
advanceAssigmentA.setAdvanceType(advanceTypeA);
|
||||
AdvanceAssigment advanceAssigmentB = createValidAdvanceAssigment(true);
|
||||
advanceAssigmentB.setAdvanceType(advanceTypeA);
|
||||
|
||||
orderDao.save(order);
|
||||
|
||||
try {
|
||||
container.addAvanceAssigment(advanceAssigmentA);
|
||||
} catch (Exception e) {
|
||||
fail("It should not throw an exception ");
|
||||
}
|
||||
|
||||
assertThat(container.getAdvanceAssigments().size(), equalTo(1));
|
||||
|
||||
try {
|
||||
orderLineGranSon.addAvanceAssigment(advanceAssigmentB);
|
||||
fail("It should throw an exception ");
|
||||
} catch (Exception e) {
|
||||
// Ok
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -31,6 +31,9 @@
|
|||
-->
|
||||
<property name="mappingResources">
|
||||
<list>
|
||||
<value>
|
||||
org/navalplanner/business/advance/entities/Advance.hbm.xml
|
||||
</value>
|
||||
<value>
|
||||
org/navalplanner/business/resources/entities/Resources.hbm.xml
|
||||
</value>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue