ItEr39S17CUImportacionOrganizacionsTraballo: Added support to import/export labels associated with OrderElements.
This commit is contained in:
parent
632664a4b6
commit
e16fbc8da8
7 changed files with 132 additions and 11 deletions
|
|
@ -23,6 +23,8 @@ package org.navalplanner.business.common;
|
|||
import org.navalplanner.business.advance.daos.IAdvanceTypeDAO;
|
||||
import org.navalplanner.business.calendars.daos.IBaseCalendarDAO;
|
||||
import org.navalplanner.business.costcategories.daos.ITypeOfWorkHoursDAO;
|
||||
import org.navalplanner.business.labels.daos.ILabelDAO;
|
||||
import org.navalplanner.business.labels.daos.ILabelTypeDAO;
|
||||
import org.navalplanner.business.materials.daos.IMaterialCategoryDAO;
|
||||
import org.navalplanner.business.materials.daos.IMaterialDAO;
|
||||
import org.navalplanner.business.qualityforms.daos.IQualityFormDAO;
|
||||
|
|
@ -80,6 +82,12 @@ public class Registry {
|
|||
@Autowired
|
||||
private IBaseCalendarDAO baseCalendarDAO;
|
||||
|
||||
@Autowired
|
||||
private ILabelDAO labelDAO;
|
||||
|
||||
@Autowired
|
||||
private ILabelTypeDAO labelTypeDAO;
|
||||
|
||||
private Registry() {
|
||||
}
|
||||
|
||||
|
|
@ -127,4 +135,12 @@ public class Registry {
|
|||
return getInstance().baseCalendarDAO;
|
||||
}
|
||||
|
||||
}
|
||||
public static ILabelDAO getLabelDAO() {
|
||||
return getInstance().labelDAO;
|
||||
}
|
||||
|
||||
public static ILabelTypeDAO getLabelTypeDAO() {
|
||||
return getInstance().labelTypeDAO;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* 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 javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import org.navalplanner.business.labels.entities.Label;
|
||||
|
||||
/**
|
||||
* DTO for {@link Label} entity.
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
*/
|
||||
@XmlRootElement(name = "label")
|
||||
public class LabelDTO {
|
||||
|
||||
@XmlAttribute
|
||||
public String name;
|
||||
|
||||
@XmlAttribute
|
||||
public String type;
|
||||
|
||||
public LabelDTO() {
|
||||
}
|
||||
|
||||
public LabelDTO(String name, String type) {
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -22,6 +22,7 @@ package org.navalplanner.ws.orders.api;
|
|||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
|
@ -47,9 +48,10 @@ public class OrderDTO extends OrderLineGroupDTO {
|
|||
}
|
||||
|
||||
public OrderDTO(String name, String code, Date initDate, Date deadline,
|
||||
String description, List<OrderElementDTO> children,
|
||||
String description, Set<LabelDTO> labels,
|
||||
List<OrderElementDTO> children,
|
||||
Boolean dependenciesConstraintsHavePriority, String calendarName) {
|
||||
super(name, code, initDate, deadline, description, children);
|
||||
super(name, code, initDate, deadline, description, labels, children);
|
||||
this.dependenciesConstraintsHavePriority = dependenciesConstraintsHavePriority;
|
||||
this.calendarName = calendarName;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,8 +21,11 @@
|
|||
package org.navalplanner.ws.orders.api;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import org.navalplanner.business.orders.entities.OrderElement;
|
||||
|
|
@ -50,16 +53,21 @@ public class OrderElementDTO {
|
|||
@XmlAttribute
|
||||
public String description;
|
||||
|
||||
@XmlElementWrapper(name = "labels")
|
||||
@XmlElement(name = "label")
|
||||
public Set<LabelDTO> labels;
|
||||
|
||||
public OrderElementDTO() {
|
||||
}
|
||||
|
||||
public OrderElementDTO(String name, String code, Date initDate,
|
||||
Date deadline, String description) {
|
||||
Date deadline, String description, Set<LabelDTO> labels) {
|
||||
this.name = name;
|
||||
this.code = code;
|
||||
this.initDate = initDate;
|
||||
this.deadline = deadline;
|
||||
this.description = description;
|
||||
this.labels = labels;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,8 +46,9 @@ public class OrderLineDTO extends OrderElementDTO {
|
|||
}
|
||||
|
||||
public OrderLineDTO(String name, String code, Date initDate, Date deadline,
|
||||
String description, Set<HoursGroupDTO> hoursGroups) {
|
||||
super(name, code, initDate, deadline, description);
|
||||
String description, Set<LabelDTO> labels,
|
||||
Set<HoursGroupDTO> hoursGroups) {
|
||||
super(name, code, initDate, deadline, description, labels);
|
||||
this.hoursGroups = hoursGroups;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ package org.navalplanner.ws.orders.api;
|
|||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||
|
|
@ -50,8 +51,9 @@ public class OrderLineGroupDTO extends OrderElementDTO {
|
|||
}
|
||||
|
||||
public OrderLineGroupDTO(String name, String code, Date initDate,
|
||||
Date deadline, String description, List<OrderElementDTO> children) {
|
||||
super(name, code, initDate, deadline, description);
|
||||
Date deadline, String description, Set<LabelDTO> labels,
|
||||
List<OrderElementDTO> children) {
|
||||
super(name, code, initDate, deadline, description, labels);
|
||||
this.children = children;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,8 +26,12 @@ import java.util.HashSet;
|
|||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.NonUniqueResultException;
|
||||
import org.navalplanner.business.calendars.entities.BaseCalendar;
|
||||
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.orders.entities.HoursGroup;
|
||||
import org.navalplanner.business.orders.entities.Order;
|
||||
import org.navalplanner.business.orders.entities.OrderElement;
|
||||
|
|
@ -37,6 +41,7 @@ import org.navalplanner.business.resources.entities.ResourceEnum;
|
|||
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.OrderDTO;
|
||||
import org.navalplanner.ws.orders.api.OrderElementDTO;
|
||||
import org.navalplanner.ws.orders.api.OrderLineDTO;
|
||||
|
|
@ -59,6 +64,11 @@ public final class OrderElementConverter {
|
|||
Date deadline = orderElement.getDeadline();
|
||||
String description = orderElement.getDescription();
|
||||
|
||||
Set<LabelDTO> labels = new HashSet<LabelDTO>();
|
||||
for (Label label : orderElement.getLabels()) {
|
||||
labels.add(toDTO(label));
|
||||
}
|
||||
|
||||
if (orderElement instanceof OrderLine) {
|
||||
Set<HoursGroupDTO> hoursGroups = new HashSet<HoursGroupDTO>();
|
||||
for (HoursGroup hoursGroup : ((OrderLine) orderElement)
|
||||
|
|
@ -67,7 +77,7 @@ public final class OrderElementConverter {
|
|||
}
|
||||
|
||||
return new OrderLineDTO(name, code, initDate, deadline,
|
||||
description, hoursGroups);
|
||||
description, labels, hoursGroups);
|
||||
} else { // orderElement instanceof OrderLineGroup
|
||||
List<OrderElementDTO> children = new ArrayList<OrderElementDTO>();
|
||||
for (OrderElement element : orderElement.getChildren()) {
|
||||
|
|
@ -84,15 +94,19 @@ public final class OrderElementConverter {
|
|||
}
|
||||
|
||||
return new OrderDTO(name, code, initDate, deadline,
|
||||
description, children,
|
||||
description, labels, children,
|
||||
dependenciesConstraintsHavePriority, calendarName);
|
||||
} else { // orderElement instanceof OrderLineGroup
|
||||
return new OrderLineGroupDTO(name, code, initDate, deadline,
|
||||
description, children);
|
||||
description, labels, children);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final static LabelDTO toDTO(Label label) {
|
||||
return new LabelDTO(label.getName(), label.getType().getName());
|
||||
}
|
||||
|
||||
public final static HoursGroupDTO toDTO(HoursGroup hoursGroup) {
|
||||
ResourceEnumDTO resourceType = ResourceEnumConverter.toDTO(hoursGroup
|
||||
.getResourceType());
|
||||
|
|
@ -141,9 +155,37 @@ 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));
|
||||
}
|
||||
}
|
||||
|
||||
return orderElement;
|
||||
}
|
||||
|
||||
public final static Label toEntity(LabelDTO labelDTO) {
|
||||
LabelType labelType = null;
|
||||
try {
|
||||
labelType = Registry.getLabelTypeDAO().findUniqueByName(
|
||||
labelDTO.type);
|
||||
} catch (NonUniqueResultException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (InstanceNotFoundException e) {
|
||||
labelType = LabelType.create(labelDTO.type);
|
||||
Registry.getLabelTypeDAO().save(labelType);
|
||||
}
|
||||
|
||||
Label label = Registry.getLabelDAO().findByNameAndType(labelDTO.name,
|
||||
labelType);
|
||||
if (label == null) {
|
||||
label = Label.create(labelDTO.name);
|
||||
label.setType(labelType);
|
||||
}
|
||||
|
||||
return label;
|
||||
}
|
||||
|
||||
private static HoursGroup toEntity(HoursGroupDTO hoursGroupDTO) {
|
||||
ResourceEnum resourceType = ResourceEnumConverter
|
||||
.fromDTO(hoursGroupDTO.resourceType);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue