ItEr19S10CUIntroducionPartesTraballoManualmenteItEr18S11 [Fix bug] Show distinguished code for OrderElement

This commit is contained in:
Diego Pino Garcia 2009-07-30 13:34:27 +02:00 committed by Javier Moran Rua
parent 1978d7a52b
commit f5316e0882
6 changed files with 82 additions and 3 deletions

View file

@ -2,6 +2,7 @@ package org.navalplanner.business.orders.daos;
import java.util.List;
import org.navalplanner.business.common.daos.IGenericDao;
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
import org.navalplanner.business.orders.entities.OrderElement;
/**
@ -21,6 +22,17 @@ 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);
/**
* Returns the unique code that distinguishes an OrderElement (unique path
* from root to OrderElement)
*
* @param orderElement must be attached
* @return
*/
public String getDistinguishedCode(OrderElement orderElement)
throws InstanceNotFoundException;
}

View file

@ -5,6 +5,7 @@ import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.navalplanner.business.common.daos.impl.GenericDaoHibernate;
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
import org.navalplanner.business.orders.entities.OrderElement;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
@ -41,4 +42,16 @@ public class OrderElementDao extends GenericDaoHibernate<OrderElement, Long>
Restrictions.idEq(orderElement.getId()));
return ((List<OrderElement>) c.list());
}
public String getDistinguishedCode(OrderElement orderElement)
throws InstanceNotFoundException {
String code = orderElement.getCode();
while (orderElement.getParent() != null) {
OrderElement parent = find(orderElement.getParent().getId());
code = parent.getCode() + "-" + code;
orderElement = parent;
}
return code;
}
}

View file

@ -9,7 +9,9 @@ import java.util.UUID;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
import org.navalplanner.business.orders.daos.IOrderElementDao;
import org.navalplanner.business.orders.entities.OrderElement;
import org.navalplanner.business.orders.entities.OrderLine;
import org.navalplanner.business.orders.entities.OrderLineGroup;
import org.springframework.beans.factory.annotation.Autowired;
@ -96,4 +98,34 @@ public class OrderElementDAOTest {
orderLineGroup, orderLine.getCode());
assertTrue(found != null && found.getCode().equals(orderLine.getCode()));
}
@Test
public void testFindDistinguishedCode() {
// Create OrderLineGroupLine
OrderLineGroup orderLineGroup = createValidOrderLineGroup();
orderElementDAO.save(orderLineGroup);
orderLineGroup.setCode(((Long) orderLineGroup.getId()).toString());
orderElementDAO.save(orderLineGroup);
// Create OrderLineGroup
OrderLine orderLine = createValidOrderLine();
orderElementDAO.save(orderLine);
orderLine.setCode(((Long) orderLine.getId()).toString());
orderLine.setParent(orderLineGroup);
orderElementDAO.save(orderLine);
try {
String distinguishedCode = orderElementDAO
.getDistinguishedCode(orderLine);
String code = orderLine.getCode();
OrderElement orderElement = orderLine;
while (orderElement.getParent() != null) {
code = orderLine.getParent().getCode() + "-" + code;
orderElement = orderElement.getParent();
}
assertTrue(distinguishedCode.equals(code));
} catch (InstanceNotFoundException e) {
}
}
}

View file

@ -85,4 +85,13 @@ public interface IWorkReportModel {
*/
boolean isEditing();
/**
* Returns distinguished code for {@link OrderElement}
*
* @param orderElement
* @return
*/
String getDistinguishedCode(OrderElement orderElement)
throws InstanceNotFoundException;
}

View file

@ -398,9 +398,15 @@ public class WorkReportCRUDController extends GenericForwardComposer implements
@Override
public String get() {
return (workReportLine.getOrderElement() != null) ? workReportLine
.getOrderElement().getCode()
: "";
if (workReportLine.getOrderElement() != null) {
try {
return workReportModel
.getDistinguishedCode(workReportLine
.getOrderElement());
} catch (InstanceNotFoundException e) {
}
}
return "";
}
}, new Util.Setter<String>() {

View file

@ -184,4 +184,11 @@ public class WorkReportModel implements IWorkReportModel {
public boolean isEditing() {
return editing;
}
@Override
@Transactional(readOnly = true)
public String getDistinguishedCode(OrderElement orderElement) throws InstanceNotFoundException {
orderElementDAO.save(orderElement);
return orderElementDAO.getDistinguishedCode(orderElement);
}
}