ItEr39S17CUImportacionOrganizacionsTraballo: Added support to import/export MaterialAssignments associated with OrderElements.
This commit is contained in:
parent
9ee01d4c41
commit
9548884477
6 changed files with 125 additions and 13 deletions
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* 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.api;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
|
||||
import org.navalplanner.business.materials.entities.MaterialAssignment;
|
||||
|
||||
/**
|
||||
* DTO for {@link MaterialAssignment} entity.
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
*/
|
||||
public class MaterialAssignmentDTO {
|
||||
|
||||
@XmlAttribute(name = "material-code")
|
||||
public String materialCode;
|
||||
|
||||
@XmlAttribute
|
||||
public Double units;
|
||||
|
||||
@XmlAttribute(name = "unit-price")
|
||||
public BigDecimal unitPrice;
|
||||
|
||||
public MaterialAssignmentDTO() {
|
||||
}
|
||||
|
||||
public MaterialAssignmentDTO(String materialCode, Double units,
|
||||
BigDecimal unitPrice) {
|
||||
this.materialCode = materialCode;
|
||||
this.units = units;
|
||||
this.unitPrice = unitPrice;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -49,9 +49,11 @@ public class OrderDTO extends OrderLineGroupDTO {
|
|||
|
||||
public OrderDTO(String name, String code, Date initDate, Date deadline,
|
||||
String description, Set<LabelDTO> labels,
|
||||
Set<MaterialAssignmentDTO> materialAssignments,
|
||||
List<OrderElementDTO> children,
|
||||
Boolean dependenciesConstraintsHavePriority, String calendarName) {
|
||||
super(name, code, initDate, deadline, description, labels, children);
|
||||
super(name, code, initDate, deadline, description, labels,
|
||||
materialAssignments, children);
|
||||
this.dependenciesConstraintsHavePriority = dependenciesConstraintsHavePriority;
|
||||
this.calendarName = calendarName;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
package org.navalplanner.ws.orders.api;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
|
|
@ -55,19 +56,25 @@ public class OrderElementDTO {
|
|||
|
||||
@XmlElementWrapper(name = "labels")
|
||||
@XmlElement(name = "label")
|
||||
public Set<LabelDTO> labels;
|
||||
public Set<LabelDTO> labels = new HashSet<LabelDTO>();
|
||||
|
||||
@XmlElementWrapper(name = "material-assignments")
|
||||
@XmlElement(name = "material-assignment")
|
||||
public Set<MaterialAssignmentDTO> materialAssignments = new HashSet<MaterialAssignmentDTO>();
|
||||
|
||||
public OrderElementDTO() {
|
||||
}
|
||||
|
||||
public OrderElementDTO(String name, String code, Date initDate,
|
||||
Date deadline, String description, Set<LabelDTO> labels) {
|
||||
Date deadline, String description, Set<LabelDTO> labels,
|
||||
Set<MaterialAssignmentDTO> materialAssignments) {
|
||||
this.name = name;
|
||||
this.code = code;
|
||||
this.initDate = initDate;
|
||||
this.deadline = deadline;
|
||||
this.description = description;
|
||||
this.labels = labels;
|
||||
this.materialAssignments = materialAssignments;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -47,8 +47,9 @@ public class OrderLineDTO extends OrderElementDTO {
|
|||
|
||||
public OrderLineDTO(String name, String code, Date initDate, Date deadline,
|
||||
String description, Set<LabelDTO> labels,
|
||||
Set<MaterialAssignmentDTO> materialAssignments,
|
||||
Set<HoursGroupDTO> hoursGroups) {
|
||||
super(name, code, initDate, deadline, description, labels);
|
||||
super(name, code, initDate, deadline, description, labels, materialAssignments);
|
||||
this.hoursGroups = hoursGroups;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -52,8 +52,10 @@ public class OrderLineGroupDTO extends OrderElementDTO {
|
|||
|
||||
public OrderLineGroupDTO(String name, String code, Date initDate,
|
||||
Date deadline, String description, Set<LabelDTO> labels,
|
||||
Set<MaterialAssignmentDTO> materialAssignments,
|
||||
List<OrderElementDTO> children) {
|
||||
super(name, code, initDate, deadline, description, labels);
|
||||
super(name, code, initDate, deadline, description, labels,
|
||||
materialAssignments);
|
||||
this.children = children;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,6 +32,10 @@ import org.navalplanner.business.common.Registry;
|
|||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.labels.entities.Label;
|
||||
import org.navalplanner.business.labels.entities.LabelType;
|
||||
import org.navalplanner.business.materials.entities.Material;
|
||||
import org.navalplanner.business.materials.entities.MaterialAssignment;
|
||||
import org.navalplanner.business.materials.entities.MaterialCategory;
|
||||
import org.navalplanner.business.materials.entities.PredefinedMaterialCategories;
|
||||
import org.navalplanner.business.orders.entities.HoursGroup;
|
||||
import org.navalplanner.business.orders.entities.Order;
|
||||
import org.navalplanner.business.orders.entities.OrderElement;
|
||||
|
|
@ -42,6 +46,7 @@ import org.navalplanner.ws.common.api.ResourceEnumDTO;
|
|||
import org.navalplanner.ws.common.impl.ResourceEnumConverter;
|
||||
import org.navalplanner.ws.orders.api.HoursGroupDTO;
|
||||
import org.navalplanner.ws.orders.api.LabelDTO;
|
||||
import org.navalplanner.ws.orders.api.MaterialAssignmentDTO;
|
||||
import org.navalplanner.ws.orders.api.OrderDTO;
|
||||
import org.navalplanner.ws.orders.api.OrderElementDTO;
|
||||
import org.navalplanner.ws.orders.api.OrderLineDTO;
|
||||
|
|
@ -69,6 +74,12 @@ public final class OrderElementConverter {
|
|||
labels.add(toDTO(label));
|
||||
}
|
||||
|
||||
Set<MaterialAssignmentDTO> materialAssignments = new HashSet<MaterialAssignmentDTO>();
|
||||
for (MaterialAssignment materialAssignment : orderElement
|
||||
.getMaterialAssignments()) {
|
||||
materialAssignments.add(toDTO(materialAssignment));
|
||||
}
|
||||
|
||||
if (orderElement instanceof OrderLine) {
|
||||
Set<HoursGroupDTO> hoursGroups = new HashSet<HoursGroupDTO>();
|
||||
for (HoursGroup hoursGroup : ((OrderLine) orderElement)
|
||||
|
|
@ -77,7 +88,7 @@ public final class OrderElementConverter {
|
|||
}
|
||||
|
||||
return new OrderLineDTO(name, code, initDate, deadline,
|
||||
description, labels, hoursGroups);
|
||||
description, labels, materialAssignments, hoursGroups);
|
||||
} else { // orderElement instanceof OrderLineGroup
|
||||
List<OrderElementDTO> children = new ArrayList<OrderElementDTO>();
|
||||
for (OrderElement element : orderElement.getChildren()) {
|
||||
|
|
@ -94,15 +105,22 @@ public final class OrderElementConverter {
|
|||
}
|
||||
|
||||
return new OrderDTO(name, code, initDate, deadline,
|
||||
description, labels, children,
|
||||
description, labels, materialAssignments, children,
|
||||
dependenciesConstraintsHavePriority, calendarName);
|
||||
} else { // orderElement instanceof OrderLineGroup
|
||||
return new OrderLineGroupDTO(name, code, initDate, deadline,
|
||||
description, labels, children);
|
||||
description, labels, materialAssignments, children);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final static MaterialAssignmentDTO toDTO(
|
||||
MaterialAssignment materialAssignment) {
|
||||
return new MaterialAssignmentDTO(materialAssignment.getMaterial()
|
||||
.getCode(), materialAssignment.getUnits(), materialAssignment
|
||||
.getUnitPrice());
|
||||
}
|
||||
|
||||
public final static LabelDTO toDTO(Label label) {
|
||||
return new LabelDTO(label.getName(), label.getType().getName());
|
||||
}
|
||||
|
|
@ -155,15 +173,42 @@ public final class OrderElementConverter {
|
|||
orderElement.setDeadline(orderElementDTO.deadline);
|
||||
orderElement.setDescription(orderElementDTO.description);
|
||||
|
||||
if (orderElementDTO.labels != null) {
|
||||
for (LabelDTO labelDTO : orderElementDTO.labels) {
|
||||
orderElement.addLabel(toEntity(labelDTO));
|
||||
}
|
||||
for (LabelDTO labelDTO : orderElementDTO.labels) {
|
||||
orderElement.addLabel(toEntity(labelDTO));
|
||||
}
|
||||
|
||||
for (MaterialAssignmentDTO materialAssignmentDTO : orderElementDTO.materialAssignments) {
|
||||
orderElement.addMaterialAssignment(toEntity(materialAssignmentDTO));
|
||||
}
|
||||
|
||||
return orderElement;
|
||||
}
|
||||
|
||||
public final static MaterialAssignment toEntity(
|
||||
MaterialAssignmentDTO materialAssignmentDTO) {
|
||||
Material material = null;
|
||||
|
||||
try {
|
||||
material = Registry.getMaterialDAO()
|
||||
.findUniqueByCodeInAnotherTransaction(
|
||||
materialAssignmentDTO.materialCode);
|
||||
} catch (InstanceNotFoundException e) {
|
||||
material = Material.create(materialAssignmentDTO.materialCode);
|
||||
|
||||
MaterialCategory defaultMaterialCategory = PredefinedMaterialCategories.IMPORTED_MATERIALS_WITHOUT_CATEGORY
|
||||
.getMaterialCategory();
|
||||
material.setCategory(defaultMaterialCategory);
|
||||
|
||||
Registry.getMaterialDAO().save(material);
|
||||
}
|
||||
|
||||
MaterialAssignment materialAssignment = MaterialAssignment
|
||||
.create(material);
|
||||
materialAssignment.setUnits(materialAssignmentDTO.units);
|
||||
materialAssignment.setUnitPrice(materialAssignmentDTO.unitPrice);
|
||||
return materialAssignment;
|
||||
}
|
||||
|
||||
public final static Label toEntity(LabelDTO labelDTO) {
|
||||
LabelType labelType = null;
|
||||
try {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue