ItEr41S23CUImportarTraballoRealizadoPorSubcontrata: Added object to configure order element import and export.
* Some FIXME added in order to move and modify some methods when subcontractors service exists.
This commit is contained in:
parent
82cfb1d54b
commit
b1a202a3b2
4 changed files with 167 additions and 51 deletions
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* This file is part of ###PROJECT_NAME###
|
||||
*
|
||||
* Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
|
||||
* Desenvolvemento Tecnolóxico de Galicia
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.navalplanner.ws.orders.impl;
|
||||
|
||||
|
||||
/**
|
||||
* Configuration for methods of {@link OrderElementConverter}.
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
*/
|
||||
public class ConfigurationOrderElementConverter {
|
||||
|
||||
public static ConfigurationOrderElementConverter all() {
|
||||
return new ConfigurationOrderElementConverter(true, true, true, true);
|
||||
}
|
||||
|
||||
public static ConfigurationOrderElementConverter none() {
|
||||
return new ConfigurationOrderElementConverter(false, false, false,
|
||||
false);
|
||||
}
|
||||
|
||||
public static ConfigurationOrderElementConverter noAdvanceMeasurements() {
|
||||
return new ConfigurationOrderElementConverter(true, true, false, true);
|
||||
}
|
||||
|
||||
private boolean labels;
|
||||
private boolean materialAssignments;
|
||||
private boolean advanceMeasurements;
|
||||
private boolean hoursGroups;
|
||||
|
||||
private ConfigurationOrderElementConverter(boolean labels,
|
||||
boolean materialAssignments, boolean advanceMeasurements,
|
||||
boolean hoursGroups) {
|
||||
this.labels = labels;
|
||||
this.materialAssignments = materialAssignments;
|
||||
this.advanceMeasurements = advanceMeasurements;
|
||||
this.hoursGroups = hoursGroups;
|
||||
}
|
||||
|
||||
public boolean isLabels() {
|
||||
return labels;
|
||||
}
|
||||
|
||||
public boolean isMaterialAssignments() {
|
||||
return materialAssignments;
|
||||
}
|
||||
|
||||
public boolean isAdvanceMeasurements() {
|
||||
return advanceMeasurements;
|
||||
}
|
||||
|
||||
public boolean isHoursGroups() {
|
||||
return hoursGroups;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -73,7 +73,8 @@ public final class OrderElementConverter {
|
|||
private OrderElementConverter() {
|
||||
}
|
||||
|
||||
public final static OrderElementDTO toDTO(OrderElement orderElement) {
|
||||
public final static OrderElementDTO toDTO(OrderElement orderElement,
|
||||
ConfigurationOrderElementConverter configuration) {
|
||||
String name = orderElement.getName();
|
||||
String code = orderElement.getCode();
|
||||
Date initDate = orderElement.getInitDate();
|
||||
|
|
@ -81,24 +82,33 @@ public final class OrderElementConverter {
|
|||
String description = orderElement.getDescription();
|
||||
|
||||
Set<LabelDTO> labels = new HashSet<LabelDTO>();
|
||||
for (Label label : orderElement.getLabels()) {
|
||||
labels.add(toDTO(label));
|
||||
if (configuration.isLabels()) {
|
||||
for (Label label : orderElement.getLabels()) {
|
||||
labels.add(toDTO(label));
|
||||
}
|
||||
}
|
||||
|
||||
Set<MaterialAssignmentDTO> materialAssignments = new HashSet<MaterialAssignmentDTO>();
|
||||
for (MaterialAssignment materialAssignment : orderElement
|
||||
.getMaterialAssignments()) {
|
||||
materialAssignments.add(toDTO(materialAssignment));
|
||||
if (configuration.isMaterialAssignments()) {
|
||||
for (MaterialAssignment materialAssignment : orderElement
|
||||
.getMaterialAssignments()) {
|
||||
materialAssignments.add(toDTO(materialAssignment));
|
||||
}
|
||||
}
|
||||
|
||||
Set<AdvanceMeasurementDTO> advanceMeasurements = toDTO(orderElement
|
||||
.getReportGlobalAdvanceAssignment());
|
||||
Set<AdvanceMeasurementDTO> advanceMeasurements = new HashSet<AdvanceMeasurementDTO>();
|
||||
if (configuration.isAdvanceMeasurements()) {
|
||||
advanceMeasurements = toDTO(orderElement
|
||||
.getReportGlobalAdvanceAssignment());
|
||||
}
|
||||
|
||||
if (orderElement instanceof OrderLine) {
|
||||
Set<HoursGroupDTO> hoursGroups = new HashSet<HoursGroupDTO>();
|
||||
for (HoursGroup hoursGroup : ((OrderLine) orderElement)
|
||||
.getHoursGroups()) {
|
||||
hoursGroups.add(toDTO(hoursGroup));
|
||||
if (configuration.isHoursGroups()) {
|
||||
for (HoursGroup hoursGroup : ((OrderLine) orderElement)
|
||||
.getHoursGroups()) {
|
||||
hoursGroups.add(toDTO(hoursGroup));
|
||||
}
|
||||
}
|
||||
|
||||
return new OrderLineDTO(name, code, initDate, deadline,
|
||||
|
|
@ -107,7 +117,7 @@ public final class OrderElementConverter {
|
|||
} else { // orderElement instanceof OrderLineGroup
|
||||
List<OrderElementDTO> children = new ArrayList<OrderElementDTO>();
|
||||
for (OrderElement element : orderElement.getChildren()) {
|
||||
children.add(toDTO(element));
|
||||
children.add(toDTO(element, configuration));
|
||||
}
|
||||
|
||||
if (orderElement instanceof Order) {
|
||||
|
|
@ -180,20 +190,23 @@ public final class OrderElementConverter {
|
|||
.getWorkingHours());
|
||||
}
|
||||
|
||||
public final static OrderElement toEntity(OrderElementDTO orderElementDTO) {
|
||||
public final static OrderElement toEntity(OrderElementDTO orderElementDTO,
|
||||
ConfigurationOrderElementConverter configuration) {
|
||||
OrderElement orderElement;
|
||||
|
||||
if (orderElementDTO instanceof OrderLineDTO) {
|
||||
orderElement = OrderLine.create();
|
||||
|
||||
for (HoursGroupDTO hoursGroupDTO : ((OrderLineDTO) orderElementDTO).hoursGroups) {
|
||||
HoursGroup hoursGroup = toEntity(hoursGroupDTO);
|
||||
((OrderLine) orderElement).addHoursGroup(hoursGroup);
|
||||
if (configuration.isHoursGroups()) {
|
||||
for (HoursGroupDTO hoursGroupDTO : ((OrderLineDTO) orderElementDTO).hoursGroups) {
|
||||
HoursGroup hoursGroup = toEntity(hoursGroupDTO);
|
||||
((OrderLine) orderElement).addHoursGroup(hoursGroup);
|
||||
}
|
||||
}
|
||||
} else { // orderElementDTO instanceof OrderLineGroupDTO
|
||||
List<OrderElement> children = new ArrayList<OrderElement>();
|
||||
for (OrderElementDTO element : ((OrderLineGroupDTO) orderElementDTO).children) {
|
||||
children.add(toEntity(element));
|
||||
children.add(toEntity(element, configuration));
|
||||
}
|
||||
|
||||
if (orderElementDTO instanceof OrderDTO) {
|
||||
|
|
@ -227,15 +240,22 @@ public final class OrderElementConverter {
|
|||
orderElement.setDeadline(orderElementDTO.deadline);
|
||||
orderElement.setDescription(orderElementDTO.description);
|
||||
|
||||
for (LabelDTO labelDTO : orderElementDTO.labels) {
|
||||
orderElement.addLabel(toEntity(labelDTO));
|
||||
if (configuration.isLabels()) {
|
||||
for (LabelDTO labelDTO : orderElementDTO.labels) {
|
||||
orderElement.addLabel(toEntity(labelDTO));
|
||||
}
|
||||
}
|
||||
|
||||
for (MaterialAssignmentDTO materialAssignmentDTO : orderElementDTO.materialAssignments) {
|
||||
orderElement.addMaterialAssignment(toEntity(materialAssignmentDTO));
|
||||
if (configuration.isMaterialAssignments()) {
|
||||
for (MaterialAssignmentDTO materialAssignmentDTO : orderElementDTO.materialAssignments) {
|
||||
orderElement
|
||||
.addMaterialAssignment(toEntity(materialAssignmentDTO));
|
||||
}
|
||||
}
|
||||
|
||||
addAdvanceMeasurements(orderElement, orderElementDTO);
|
||||
if (configuration.isAdvanceMeasurements()) {
|
||||
addAdvanceMeasurements(orderElement, orderElementDTO);
|
||||
}
|
||||
|
||||
return orderElement;
|
||||
}
|
||||
|
|
@ -298,7 +318,9 @@ public final class OrderElementConverter {
|
|||
}
|
||||
|
||||
public final static void update(OrderElement orderElement,
|
||||
OrderElementDTO orderElementDTO) throws IncompatibleTypeException {
|
||||
OrderElementDTO orderElementDTO,
|
||||
ConfigurationOrderElementConverter configuration)
|
||||
throws IncompatibleTypeException {
|
||||
|
||||
if (orderElementDTO instanceof OrderLineDTO) {
|
||||
if (!(orderElement instanceof OrderLine)) {
|
||||
|
|
@ -306,14 +328,17 @@ public final class OrderElementConverter {
|
|||
OrderLine.class, orderElement.getClass());
|
||||
}
|
||||
|
||||
for (HoursGroupDTO hoursGroupDTO : ((OrderLineDTO) orderElementDTO).hoursGroups) {
|
||||
if (((OrderLine) orderElement)
|
||||
.containsHoursGroup(hoursGroupDTO.code)) {
|
||||
update(((OrderLine) orderElement)
|
||||
.getHoursGroup(hoursGroupDTO.code), hoursGroupDTO);
|
||||
} else {
|
||||
((OrderLine) orderElement)
|
||||
.addHoursGroup(toEntity(hoursGroupDTO));
|
||||
if (configuration.isHoursGroups()) {
|
||||
for (HoursGroupDTO hoursGroupDTO : ((OrderLineDTO) orderElementDTO).hoursGroups) {
|
||||
if (((OrderLine) orderElement)
|
||||
.containsHoursGroup(hoursGroupDTO.code)) {
|
||||
update(((OrderLine) orderElement)
|
||||
.getHoursGroup(hoursGroupDTO.code),
|
||||
hoursGroupDTO);
|
||||
} else {
|
||||
((OrderLine) orderElement)
|
||||
.addHoursGroup(toEntity(hoursGroupDTO));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else { // orderElementDTO instanceof OrderLineGroupDTO
|
||||
|
|
@ -353,34 +378,41 @@ public final class OrderElementConverter {
|
|||
for (OrderElementDTO childDTO : ((OrderLineGroupDTO) orderElementDTO).children) {
|
||||
if (orderElement.containsOrderElement(childDTO.code)) {
|
||||
update(orderElement.getOrderElement(childDTO.code),
|
||||
childDTO);
|
||||
childDTO, configuration);
|
||||
} else {
|
||||
((OrderLineGroup) orderElement).add(toEntity(childDTO));
|
||||
((OrderLineGroup) orderElement).add(toEntity(childDTO,
|
||||
configuration));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for (LabelDTO labelDTO : orderElementDTO.labels) {
|
||||
if (!orderElement.containsLabel(labelDTO.name, labelDTO.type)) {
|
||||
orderElement.addLabel(toEntity(labelDTO));
|
||||
if (configuration.isLabels()) {
|
||||
for (LabelDTO labelDTO : orderElementDTO.labels) {
|
||||
if (!orderElement.containsLabel(labelDTO.name, labelDTO.type)) {
|
||||
orderElement.addLabel(toEntity(labelDTO));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (MaterialAssignmentDTO materialAssignmentDTO : orderElementDTO.materialAssignments) {
|
||||
if (orderElement
|
||||
.containsMaterialAssignment(materialAssignmentDTO.materialCode)) {
|
||||
update(
|
||||
orderElement
|
||||
.getMaterialAssignment(materialAssignmentDTO.materialCode),
|
||||
materialAssignmentDTO);
|
||||
} else {
|
||||
orderElement
|
||||
.addMaterialAssignment(toEntity(materialAssignmentDTO));
|
||||
if (configuration.isMaterialAssignments()) {
|
||||
for (MaterialAssignmentDTO materialAssignmentDTO : orderElementDTO.materialAssignments) {
|
||||
if (orderElement
|
||||
.containsMaterialAssignment(materialAssignmentDTO.materialCode)) {
|
||||
update(
|
||||
orderElement
|
||||
.getMaterialAssignment(materialAssignmentDTO.materialCode),
|
||||
materialAssignmentDTO);
|
||||
} else {
|
||||
orderElement
|
||||
.addMaterialAssignment(toEntity(materialAssignmentDTO));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
addAdvanceMeasurements(orderElement, orderElementDTO);
|
||||
if (configuration.isAdvanceMeasurements()) {
|
||||
addAdvanceMeasurements(orderElement, orderElementDTO);
|
||||
}
|
||||
|
||||
if (orderElementDTO.name != null) {
|
||||
orderElement.setName(orderElementDTO.name);
|
||||
|
|
|
|||
|
|
@ -68,7 +68,8 @@ public class OrderElementServiceREST implements IOrderElementService {
|
|||
public OrderElementDTO getOrderElement(@PathParam("code") String code)
|
||||
throws InstanceNotFoundException {
|
||||
return OrderElementConverter.toDTO(orderElementDAO
|
||||
.findUniqueByCode(code));
|
||||
.findUniqueByCode(code), ConfigurationOrderElementConverter
|
||||
.noAdvanceMeasurements());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -81,8 +82,11 @@ public class OrderElementServiceREST implements IOrderElementService {
|
|||
|
||||
InstanceConstraintViolationsDTO instanceConstraintViolationsDTO = null;
|
||||
try {
|
||||
OrderElement orderElement = OrderElementConverter
|
||||
.toEntity(orderDTO);
|
||||
OrderElement orderElement = OrderElementConverter.toEntity(
|
||||
orderDTO, ConfigurationOrderElementConverter
|
||||
.all());
|
||||
// FIXME change all() for noAdvanceMeasurements() when
|
||||
// subcontractors service exists
|
||||
orderElement.validate();
|
||||
orderElementDAO.save(orderElement);
|
||||
} catch (ValidationException e) {
|
||||
|
|
@ -117,7 +121,10 @@ public class OrderElementServiceREST implements IOrderElementService {
|
|||
|
||||
InstanceConstraintViolationsDTO instanceConstraintViolationsDTO = null;
|
||||
try {
|
||||
OrderElementConverter.update((Order) orderElement, orderDTO);
|
||||
OrderElementConverter.update((Order) orderElement, orderDTO,
|
||||
ConfigurationOrderElementConverter.all());
|
||||
// FIXME change all() for noAdvanceMeasurements() when
|
||||
// subcontractors service exists
|
||||
orderElement.validate();
|
||||
orderElementDAO.save(orderElement);
|
||||
} catch (ValidationException e) {
|
||||
|
|
|
|||
|
|
@ -753,6 +753,7 @@ public class OrderElementServiceTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
// FIXME move to subcontractors service when it exists
|
||||
public void invalidOrderWithInvalidAdvanceMeasurements()
|
||||
throws InstanceNotFoundException {
|
||||
String code = "order-code";
|
||||
|
|
@ -794,6 +795,7 @@ public class OrderElementServiceTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
// FIXME move to subcontractors service when it exists
|
||||
public void validOrderWithAdvanceMeasurements()
|
||||
throws InstanceNotFoundException {
|
||||
String code = "order-code";
|
||||
|
|
@ -827,6 +829,7 @@ public class OrderElementServiceTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
// FIXME move to subcontractors service when it exists
|
||||
public void updateAdvanceMeasurements() throws InstanceNotFoundException,
|
||||
IncompatibleTypeException {
|
||||
String code = "order-code";
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue