ItEr45S23CUImportacionTiposEtiquetasEEtiquetas: Replaced LabelDTO for LabelReferenceDTO, because of labels are going to be referenced just by its code for the current services implemented.
This commit is contained in:
parent
68ca6ad686
commit
8c8a7ba1d7
15 changed files with 167 additions and 200 deletions
|
|
@ -803,7 +803,7 @@ public abstract class OrderElement extends BaseEntity implements
|
|||
|
||||
private boolean checkAncestorsNoOtherLabelRepeated(Label newLabel) {
|
||||
for (Label label : labels) {
|
||||
if (label.equals(newLabel)) {
|
||||
if (label.isEqualTo(newLabel)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -877,10 +877,9 @@ public abstract class OrderElement extends BaseEntity implements
|
|||
return null;
|
||||
}
|
||||
|
||||
public boolean containsLabel(String name, String type) {
|
||||
public boolean containsLabel(String code) {
|
||||
for (Label label : getLabels()) {
|
||||
if (label.getName().equals(name)
|
||||
&& label.getType().getName().equals(type)) {
|
||||
if (label.getCode().equals(code)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,25 +26,21 @@ import javax.xml.bind.annotation.XmlRootElement;
|
|||
import org.navalplanner.business.labels.entities.Label;
|
||||
|
||||
/**
|
||||
* DTO for {@link Label} entity.
|
||||
* DTO for references to {@link Label} entities.
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
*/
|
||||
@XmlRootElement(name = "label")
|
||||
public class LabelDTO {
|
||||
public class LabelReferenceDTO {
|
||||
|
||||
@XmlAttribute
|
||||
public String name;
|
||||
public String code;
|
||||
|
||||
@XmlAttribute
|
||||
public String type;
|
||||
|
||||
public LabelDTO() {
|
||||
public LabelReferenceDTO() {
|
||||
}
|
||||
|
||||
public LabelDTO(String name, String type) {
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
public LabelReferenceDTO(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -48,7 +48,7 @@ public class OrderDTO extends OrderLineGroupDTO {
|
|||
}
|
||||
|
||||
public OrderDTO(String name, String code, Date initDate, Date deadline,
|
||||
String description, Set<LabelDTO> labels,
|
||||
String description, Set<LabelReferenceDTO> labels,
|
||||
Set<MaterialAssignmentDTO> materialAssignments,
|
||||
Set<AdvanceMeasurementDTO> advanceMeasurements,
|
||||
Set<CriterionRequirementDTO> criterionRequirements,
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ public class OrderElementDTO {
|
|||
|
||||
@XmlElementWrapper(name = "labels")
|
||||
@XmlElement(name = "label")
|
||||
public Set<LabelDTO> labels = new HashSet<LabelDTO>();
|
||||
public Set<LabelReferenceDTO> labels = new HashSet<LabelReferenceDTO>();
|
||||
|
||||
@XmlElementWrapper(name = "material-assignments")
|
||||
@XmlElement(name = "material-assignment")
|
||||
|
|
@ -77,7 +77,7 @@ public class OrderElementDTO {
|
|||
}
|
||||
|
||||
public OrderElementDTO(String name, String code, Date initDate,
|
||||
Date deadline, String description, Set<LabelDTO> labels,
|
||||
Date deadline, String description, Set<LabelReferenceDTO> labels,
|
||||
Set<MaterialAssignmentDTO> materialAssignments,
|
||||
Set<AdvanceMeasurementDTO> advanceMeasurements,
|
||||
Set<CriterionRequirementDTO> criterionRequirements) {
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ public class OrderLineDTO extends OrderElementDTO {
|
|||
}
|
||||
|
||||
public OrderLineDTO(String name, String code, Date initDate, Date deadline,
|
||||
String description, Set<LabelDTO> labels,
|
||||
String description, Set<LabelReferenceDTO> labels,
|
||||
Set<MaterialAssignmentDTO> materialAssignments,
|
||||
Set<AdvanceMeasurementDTO> advanceMeasurements,
|
||||
Set<CriterionRequirementDTO> criterionRequirements,
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ public class OrderLineGroupDTO extends OrderElementDTO {
|
|||
}
|
||||
|
||||
public OrderLineGroupDTO(String name, String code, Date initDate,
|
||||
Date deadline, String description, Set<LabelDTO> labels,
|
||||
Date deadline, String description, Set<LabelReferenceDTO> labels,
|
||||
Set<MaterialAssignmentDTO> materialAssignments,
|
||||
Set<AdvanceMeasurementDTO> advanceMeasurements,
|
||||
Set<CriterionRequirementDTO> criterionRequirements,
|
||||
|
|
|
|||
|
|
@ -1,103 +0,0 @@
|
|||
/*
|
||||
* 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.common.impl;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.NonUniqueResultException;
|
||||
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.ws.common.api.LabelDTO;
|
||||
|
||||
/**
|
||||
* Converter from/to {@link Label} entities to/from DTOs.
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
*/
|
||||
public final class LabelConverter {
|
||||
|
||||
private LabelConverter() {
|
||||
}
|
||||
|
||||
public final static LabelDTO toDTO(Label label) {
|
||||
return new LabelDTO(label.getName(), label.getType().getName());
|
||||
}
|
||||
|
||||
public final static Label forceToEntity(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);
|
||||
/*
|
||||
* "validate" method avoids that "labelType" goes to the Hibernate's
|
||||
* session if "labelType" is not valid.
|
||||
*/
|
||||
labelType.validate();
|
||||
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;
|
||||
}
|
||||
|
||||
public static Set<Label> toEntity(Set<LabelDTO> labels)
|
||||
throws InstanceNotFoundException {
|
||||
Set<Label> result = new HashSet<Label>();
|
||||
for (LabelDTO labelDTO : labels) {
|
||||
result.add(toEntity(labelDTO));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public final static Label toEntity(LabelDTO labelDTO)
|
||||
throws InstanceNotFoundException {
|
||||
LabelType labelType = null;
|
||||
try {
|
||||
labelType = Registry.getLabelTypeDAO().findUniqueByName(
|
||||
labelDTO.type);
|
||||
} catch (NonUniqueResultException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
Label label = Registry.getLabelDAO().findByNameAndType(labelDTO.name,
|
||||
labelType);
|
||||
if (label == null) {
|
||||
throw new InstanceNotFoundException(labelDTO.name, Label.class
|
||||
.getName());
|
||||
}
|
||||
|
||||
return label;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* 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.common.impl;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.navalplanner.business.common.Registry;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.labels.entities.Label;
|
||||
import org.navalplanner.ws.common.api.LabelReferenceDTO;
|
||||
|
||||
/**
|
||||
* Converter from/to {@link Label} entities to/from reference DTOs.
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
*/
|
||||
public final class LabelReferenceConverter {
|
||||
|
||||
private LabelReferenceConverter() {
|
||||
}
|
||||
|
||||
public final static LabelReferenceDTO toDTO(Label label) {
|
||||
return new LabelReferenceDTO(label.getCode());
|
||||
}
|
||||
|
||||
public static Set<Label> toEntity(Set<LabelReferenceDTO> labels)
|
||||
throws InstanceNotFoundException {
|
||||
Set<Label> result = new HashSet<Label>();
|
||||
for (LabelReferenceDTO labelReferenceDTO : labels) {
|
||||
result.add(toEntity(labelReferenceDTO));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public final static Label toEntity(LabelReferenceDTO labelReferenceDTO)
|
||||
throws InstanceNotFoundException {
|
||||
// FIXME review if this check could be moved to findByCode at
|
||||
// IntegrationEntityDAO
|
||||
if (labelReferenceDTO.code == null) {
|
||||
throw new InstanceNotFoundException(null, Label.class.getName());
|
||||
}
|
||||
|
||||
return Registry.getLabelDAO().findByCode(labelReferenceDTO.code);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -60,7 +60,7 @@ import org.navalplanner.ws.common.api.DirectCriterionRequirementDTO;
|
|||
import org.navalplanner.ws.common.api.HoursGroupDTO;
|
||||
import org.navalplanner.ws.common.api.IncompatibleTypeException;
|
||||
import org.navalplanner.ws.common.api.IndirectCriterionRequirementDTO;
|
||||
import org.navalplanner.ws.common.api.LabelDTO;
|
||||
import org.navalplanner.ws.common.api.LabelReferenceDTO;
|
||||
import org.navalplanner.ws.common.api.MaterialAssignmentDTO;
|
||||
import org.navalplanner.ws.common.api.OrderDTO;
|
||||
import org.navalplanner.ws.common.api.OrderElementDTO;
|
||||
|
|
@ -86,10 +86,10 @@ public final class OrderElementConverter {
|
|||
Date deadline = orderElement.getDeadline();
|
||||
String description = orderElement.getDescription();
|
||||
|
||||
Set<LabelDTO> labels = new HashSet<LabelDTO>();
|
||||
Set<LabelReferenceDTO> labels = new HashSet<LabelReferenceDTO>();
|
||||
if (configuration.isLabels()) {
|
||||
for (Label label : orderElement.getLabels()) {
|
||||
labels.add(LabelConverter.toDTO(label));
|
||||
labels.add(LabelReferenceConverter.toDTO(label));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -224,7 +224,8 @@ public final class OrderElementConverter {
|
|||
}
|
||||
|
||||
public final static OrderElement toEntity(OrderElementDTO orderElementDTO,
|
||||
ConfigurationOrderElementConverter configuration) {
|
||||
ConfigurationOrderElementConverter configuration)
|
||||
throws InstanceNotFoundException {
|
||||
OrderElement orderElement = toEntityExceptCriterionRequirements(
|
||||
orderElementDTO, configuration);
|
||||
if (configuration.isCriterionRequirements()) {
|
||||
|
|
@ -314,7 +315,8 @@ public final class OrderElementConverter {
|
|||
|
||||
private final static OrderElement toEntityExceptCriterionRequirements(
|
||||
OrderElementDTO orderElementDTO,
|
||||
ConfigurationOrderElementConverter configuration) {
|
||||
ConfigurationOrderElementConverter configuration)
|
||||
throws InstanceNotFoundException {
|
||||
OrderElement orderElement;
|
||||
|
||||
if (orderElementDTO instanceof OrderLineDTO) {
|
||||
|
|
@ -369,8 +371,8 @@ public final class OrderElementConverter {
|
|||
orderElement.setDescription(orderElementDTO.description);
|
||||
|
||||
if (configuration.isLabels()) {
|
||||
for (LabelDTO labelDTO : orderElementDTO.labels) {
|
||||
orderElement.addLabel(LabelConverter.forceToEntity(labelDTO));
|
||||
for (LabelReferenceDTO labelDTO : orderElementDTO.labels) {
|
||||
orderElement.addLabel(LabelReferenceConverter.toEntity(labelDTO));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -454,7 +456,7 @@ public final class OrderElementConverter {
|
|||
public final static void update(OrderElement orderElement,
|
||||
OrderElementDTO orderElementDTO,
|
||||
ConfigurationOrderElementConverter configuration)
|
||||
throws IncompatibleTypeException {
|
||||
throws IncompatibleTypeException, InstanceNotFoundException {
|
||||
updateExceptCriterionRequirements(orderElement, orderElementDTO,
|
||||
configuration);
|
||||
if (configuration.isCriterionRequirements()) {
|
||||
|
|
@ -465,7 +467,7 @@ public final class OrderElementConverter {
|
|||
private final static void updateExceptCriterionRequirements(
|
||||
OrderElement orderElement, OrderElementDTO orderElementDTO,
|
||||
ConfigurationOrderElementConverter configuration)
|
||||
throws IncompatibleTypeException {
|
||||
throws IncompatibleTypeException, InstanceNotFoundException {
|
||||
|
||||
if (orderElementDTO instanceof OrderLineDTO) {
|
||||
if (!(orderElement instanceof OrderLine)) {
|
||||
|
|
@ -534,9 +536,9 @@ public final class OrderElementConverter {
|
|||
}
|
||||
|
||||
if (configuration.isLabels()) {
|
||||
for (LabelDTO labelDTO : orderElementDTO.labels) {
|
||||
if (!orderElement.containsLabel(labelDTO.name, labelDTO.type)) {
|
||||
orderElement.addLabel(LabelConverter.forceToEntity(labelDTO));
|
||||
for (LabelReferenceDTO labelDTO : orderElementDTO.labels) {
|
||||
if (!orderElement.containsLabel(labelDTO.code)) {
|
||||
orderElement.addLabel(LabelReferenceConverter.toEntity(labelDTO));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -94,6 +94,10 @@ public class OrderElementServiceREST implements IOrderElementService {
|
|||
instanceConstraintViolationsDTO = ConstraintViolationConverter
|
||||
.toDTO(Util.generateInstanceId(1, orderDTO.code), e
|
||||
.getInvalidValues());
|
||||
} catch (InstanceNotFoundException e) {
|
||||
instanceConstraintViolationsDTO = InstanceConstraintViolationsDTO
|
||||
.create(Util.generateInstanceId(1, orderDTO.code), e
|
||||
.getMessage());
|
||||
}
|
||||
|
||||
if (instanceConstraintViolationsDTO != null) {
|
||||
|
|
|
|||
|
|
@ -153,6 +153,10 @@ public class SubcontractServiceREST implements ISubcontractService {
|
|||
instanceConstraintViolationsDTO = ConstraintViolationConverter
|
||||
.toDTO(Util.generateInstanceId(1, orderElementDTO.code), e
|
||||
.getInvalidValues());
|
||||
} catch (InstanceNotFoundException e) {
|
||||
instanceConstraintViolationsDTO = InstanceConstraintViolationsDTO
|
||||
.create(Util.generateInstanceId(1, orderElementDTO.code), e
|
||||
.getMessage());
|
||||
}
|
||||
|
||||
if (instanceConstraintViolationsDTO != null) {
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ import javax.xml.bind.annotation.XmlRootElement;
|
|||
|
||||
import org.navalplanner.business.workreports.entities.WorkReport;
|
||||
import org.navalplanner.ws.common.api.IntegrationEntityDTO;
|
||||
import org.navalplanner.ws.common.api.LabelDTO;
|
||||
import org.navalplanner.ws.common.api.LabelReferenceDTO;
|
||||
|
||||
/**
|
||||
* DTO for {@link WorkReport} entity.
|
||||
|
|
@ -57,7 +57,7 @@ public class WorkReportDTO extends IntegrationEntityDTO {
|
|||
|
||||
@XmlElementWrapper(name = "label-list")
|
||||
@XmlElement(name = "label")
|
||||
public Set<LabelDTO> labels = new HashSet<LabelDTO>();
|
||||
public Set<LabelReferenceDTO> labels = new HashSet<LabelReferenceDTO>();
|
||||
|
||||
@XmlElementWrapper(name = "text-field-list")
|
||||
@XmlElement(name = "text-field")
|
||||
|
|
@ -71,7 +71,7 @@ public class WorkReportDTO extends IntegrationEntityDTO {
|
|||
}
|
||||
|
||||
public WorkReportDTO(String code, String workReportType, Date date,
|
||||
String resource, String orderElement, Set<LabelDTO> labels,
|
||||
String resource, String orderElement, Set<LabelReferenceDTO> labels,
|
||||
Set<DescriptionValueDTO> descriptionValues,
|
||||
Set<WorkReportLineDTO> workReportLines) {
|
||||
super(code);
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ import javax.xml.bind.annotation.XmlRootElement;
|
|||
|
||||
import org.navalplanner.business.workreports.entities.WorkReportLine;
|
||||
import org.navalplanner.ws.common.api.IntegrationEntityDTO;
|
||||
import org.navalplanner.ws.common.api.LabelDTO;
|
||||
import org.navalplanner.ws.common.api.LabelReferenceDTO;
|
||||
|
||||
/**
|
||||
* DTO for {@link WorkReportLine} entity.
|
||||
|
|
@ -66,7 +66,7 @@ public class WorkReportLineDTO extends IntegrationEntityDTO {
|
|||
|
||||
@XmlElementWrapper(name = "label-list")
|
||||
@XmlElement(name = "label")
|
||||
public Set<LabelDTO> labels = new HashSet<LabelDTO>();
|
||||
public Set<LabelReferenceDTO> labels = new HashSet<LabelReferenceDTO>();
|
||||
|
||||
@XmlElementWrapper(name = "text-field-list")
|
||||
@XmlElement(name = "text-field")
|
||||
|
|
@ -77,7 +77,7 @@ public class WorkReportLineDTO extends IntegrationEntityDTO {
|
|||
|
||||
public WorkReportLineDTO(String code, Date date, String resource,
|
||||
String orderElement, String typeOfWorkHours, Date clockStart,
|
||||
Date clockFinish, Integer numHours, Set<LabelDTO> labels,
|
||||
Date clockFinish, Integer numHours, Set<LabelReferenceDTO> labels,
|
||||
Set<DescriptionValueDTO> descriptionValues) {
|
||||
super(code);
|
||||
this.date = date;
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ import org.navalplanner.business.workreports.entities.WorkReport;
|
|||
import org.navalplanner.business.workreports.entities.WorkReportLine;
|
||||
import org.navalplanner.business.workreports.entities.WorkReportType;
|
||||
import org.navalplanner.business.workreports.valueobjects.DescriptionValue;
|
||||
import org.navalplanner.ws.common.impl.LabelConverter;
|
||||
import org.navalplanner.ws.common.impl.LabelReferenceConverter;
|
||||
import org.navalplanner.ws.workreports.api.DescriptionValueDTO;
|
||||
import org.navalplanner.ws.workreports.api.WorkReportDTO;
|
||||
import org.navalplanner.ws.workreports.api.WorkReportLineDTO;
|
||||
|
|
@ -77,7 +77,7 @@ public final class WorkReportConverter {
|
|||
}
|
||||
|
||||
if (workReportDTO.labels != null) {
|
||||
workReport.setLabels(LabelConverter.toEntity(workReportDTO.labels));
|
||||
workReport.setLabels(LabelReferenceConverter.toEntity(workReportDTO.labels));
|
||||
}
|
||||
|
||||
if (workReportDTO.descriptionValues != null) {
|
||||
|
|
@ -124,7 +124,7 @@ public final class WorkReportConverter {
|
|||
}
|
||||
|
||||
if (workReportLineDTO.labels != null) {
|
||||
workReportLine.setLabels(LabelConverter
|
||||
workReportLine.setLabels(LabelReferenceConverter
|
||||
.toEntity(workReportLineDTO.labels));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ import static org.hamcrest.CoreMatchers.equalTo;
|
|||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
|
@ -40,12 +39,14 @@ import java.util.HashSet;
|
|||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.hamcrest.BaseMatcher;
|
||||
import org.hamcrest.Description;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
|
@ -54,11 +55,14 @@ import org.navalplanner.business.IDataBootstrap;
|
|||
import org.navalplanner.business.advance.entities.AdvanceMeasurement;
|
||||
import org.navalplanner.business.advance.entities.DirectAdvanceAssignment;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.labels.daos.ILabelTypeDAO;
|
||||
import org.navalplanner.business.labels.entities.Label;
|
||||
import org.navalplanner.business.labels.entities.LabelType;
|
||||
import org.navalplanner.business.materials.entities.MaterialAssignment;
|
||||
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.requirements.entities.CriterionRequirement;
|
||||
|
|
@ -74,7 +78,7 @@ import org.navalplanner.ws.common.api.HoursGroupDTO;
|
|||
import org.navalplanner.ws.common.api.IncompatibleTypeException;
|
||||
import org.navalplanner.ws.common.api.IndirectCriterionRequirementDTO;
|
||||
import org.navalplanner.ws.common.api.InstanceConstraintViolationsDTO;
|
||||
import org.navalplanner.ws.common.api.LabelDTO;
|
||||
import org.navalplanner.ws.common.api.LabelReferenceDTO;
|
||||
import org.navalplanner.ws.common.api.MaterialAssignmentDTO;
|
||||
import org.navalplanner.ws.common.api.OrderDTO;
|
||||
import org.navalplanner.ws.common.api.OrderLineDTO;
|
||||
|
|
@ -127,6 +131,30 @@ public class OrderElementServiceTest {
|
|||
@Autowired
|
||||
private IOrderElementDAO orderElementDAO;
|
||||
|
||||
@Autowired
|
||||
private ILabelTypeDAO labelTypeDAO;
|
||||
|
||||
@Autowired
|
||||
private SessionFactory sessionFactory;
|
||||
|
||||
private Label givenLabelStored() {
|
||||
Label label = Label.create("label-name-" + UUID.randomUUID());
|
||||
|
||||
LabelType labelType = LabelType.create("label-type-"
|
||||
+ UUID.randomUUID());
|
||||
labelType.addLabel(label);
|
||||
|
||||
labelTypeDAO.save(labelType);
|
||||
labelTypeDAO.flush();
|
||||
sessionFactory.getCurrentSession().evict(labelType);
|
||||
sessionFactory.getCurrentSession().evict(label);
|
||||
|
||||
labelType.dontPoseAsTransientObjectAnymore();
|
||||
label.dontPoseAsTransientObjectAnymore();
|
||||
|
||||
return label;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invalidOrderWithoutAttributes() {
|
||||
int previous = orderDAO.getOrders().size();
|
||||
|
|
@ -483,8 +511,8 @@ public class OrderElementServiceTest {
|
|||
orderDTO.code = "order-code";
|
||||
orderDTO.initDate = new Date();
|
||||
|
||||
LabelDTO labelDTO = new LabelDTO();
|
||||
orderDTO.labels.add(labelDTO);
|
||||
LabelReferenceDTO labelReferenceDTO = new LabelReferenceDTO();
|
||||
orderDTO.labels.add(labelReferenceDTO);
|
||||
|
||||
List<InstanceConstraintViolationsDTO> instanceConstraintViolationsList = orderElementService
|
||||
.addOrder(orderDTO).instanceConstraintViolationsList;
|
||||
|
|
@ -492,36 +520,7 @@ public class OrderElementServiceTest {
|
|||
|
||||
List<ConstraintViolationDTO> constraintViolations = instanceConstraintViolationsList
|
||||
.get(0).constraintViolations;
|
||||
// Mandatory fields: material, units, unitPrice
|
||||
assertThat(constraintViolations.size(), equalTo(1));
|
||||
assertThat(constraintViolations.get(0).fieldName,
|
||||
equalTo("LabelType::name"));
|
||||
|
||||
assertThat(orderDAO.getOrders().size(), equalTo(previous));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void orderWithInvalidLabelWithoutName() {
|
||||
int previous = orderDAO.getOrders().size();
|
||||
|
||||
OrderDTO orderDTO = new OrderDTO();
|
||||
orderDTO.name = "Order name";
|
||||
orderDTO.code = "order-code";
|
||||
orderDTO.initDate = new Date();
|
||||
|
||||
LabelDTO labelDTO = new LabelDTO();
|
||||
labelDTO.type = "Label type";
|
||||
orderDTO.labels.add(labelDTO);
|
||||
|
||||
List<InstanceConstraintViolationsDTO> instanceConstraintViolationsList = orderElementService
|
||||
.addOrder(orderDTO).instanceConstraintViolationsList;
|
||||
assertThat(instanceConstraintViolationsList.size(), equalTo(1));
|
||||
|
||||
List<ConstraintViolationDTO> constraintViolations = instanceConstraintViolationsList
|
||||
.get(0).constraintViolations;
|
||||
// Mandatory fields: material, units, unitPrice
|
||||
assertThat(constraintViolations.size(), equalTo(1));
|
||||
assertThat(constraintViolations.get(0).fieldName, mustEnd("name"));
|
||||
|
||||
assertThat(orderDAO.getOrders().size(), equalTo(previous));
|
||||
}
|
||||
|
|
@ -536,10 +535,9 @@ public class OrderElementServiceTest {
|
|||
orderDTO.code = code;
|
||||
orderDTO.initDate = new Date();
|
||||
|
||||
LabelDTO labelDTO = new LabelDTO();
|
||||
labelDTO.name = "Label name";
|
||||
labelDTO.type = "Label type";
|
||||
orderDTO.labels.add(labelDTO);
|
||||
LabelReferenceDTO labelReferenceDTO = new LabelReferenceDTO();
|
||||
labelReferenceDTO.code = givenLabelStored().getCode();
|
||||
orderDTO.labels.add(labelReferenceDTO);
|
||||
|
||||
List<InstanceConstraintViolationsDTO> instanceConstraintViolationsList = orderElementService
|
||||
.addOrder(orderDTO).instanceConstraintViolationsList;
|
||||
|
|
@ -550,7 +548,7 @@ public class OrderElementServiceTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void orderWithLabelRepeatedInTheSameBranch() {
|
||||
public void orderWithLabelRepeatedInTheSameBranchIsNotAddedTwice() {
|
||||
int previous = orderDAO.getOrders().size();
|
||||
|
||||
OrderDTO orderDTO = new OrderDTO();
|
||||
|
|
@ -558,10 +556,9 @@ public class OrderElementServiceTest {
|
|||
orderDTO.code = "order-code";
|
||||
orderDTO.initDate = new Date();
|
||||
|
||||
LabelDTO labelDTO = new LabelDTO();
|
||||
labelDTO.name = "Label name";
|
||||
labelDTO.type = "Label type";
|
||||
orderDTO.labels.add(labelDTO);
|
||||
LabelReferenceDTO labelReferenceDTO = new LabelReferenceDTO();
|
||||
labelReferenceDTO.code = givenLabelStored().getCode();
|
||||
orderDTO.labels.add(labelReferenceDTO);
|
||||
|
||||
OrderLineDTO orderLineDTO = new OrderLineDTO();
|
||||
orderLineDTO.name = "Order line";
|
||||
|
|
@ -570,20 +567,22 @@ public class OrderElementServiceTest {
|
|||
ResourceEnumDTO.WORKER, 1000,
|
||||
new HashSet<CriterionRequirementDTO>());
|
||||
orderLineDTO.hoursGroups.add(hoursGroupDTO);
|
||||
orderLineDTO.labels.add(labelDTO);
|
||||
orderLineDTO.labels.add(labelReferenceDTO);
|
||||
orderDTO.children.add(orderLineDTO);
|
||||
|
||||
List<InstanceConstraintViolationsDTO> instanceConstraintViolationsList = orderElementService
|
||||
.addOrder(orderDTO).instanceConstraintViolationsList;
|
||||
assertThat(instanceConstraintViolationsList.size(), equalTo(1));
|
||||
assertThat(instanceConstraintViolationsList.size(), equalTo(0));
|
||||
|
||||
List<ConstraintViolationDTO> constraintViolations = instanceConstraintViolationsList
|
||||
.get(0).constraintViolations;
|
||||
// Mandatory fields: checkConstraintLabelNotRepeatedInTheSameBranch
|
||||
assertThat(constraintViolations.size(), equalTo(1));
|
||||
assertNull(constraintViolations.get(0).fieldName);
|
||||
assertThat(orderDAO.getOrders().size(), equalTo(previous + 1));
|
||||
|
||||
assertThat(orderDAO.getOrders().size(), equalTo(previous));
|
||||
Order order = orderDAO.getOrders().get(previous);
|
||||
assertThat(order.getLabels().size(), equalTo(1));
|
||||
assertThat(order.getLabels().iterator().next().getCode(),
|
||||
equalTo(labelReferenceDTO.code));
|
||||
|
||||
OrderElement orderElement = order.getChildren().get(0);
|
||||
assertThat(orderElement.getLabels().size(), equalTo(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -602,8 +601,9 @@ public class OrderElementServiceTest {
|
|||
orderDTO.code = code;
|
||||
orderDTO.initDate = new Date();
|
||||
|
||||
LabelDTO labelDTO = new LabelDTO("Label name", "Label type");
|
||||
orderDTO.labels.add(labelDTO);
|
||||
LabelReferenceDTO labelReferenceDTO = new LabelReferenceDTO(givenLabelStored()
|
||||
.getCode());
|
||||
orderDTO.labels.add(labelReferenceDTO);
|
||||
|
||||
List<InstanceConstraintViolationsDTO> instanceConstraintViolationsList = orderElementService
|
||||
.addOrder(orderDTO).instanceConstraintViolationsList;
|
||||
|
|
@ -613,8 +613,9 @@ public class OrderElementServiceTest {
|
|||
assertNotNull(orderElement);
|
||||
assertThat(orderElement.getLabels().size(), equalTo(1));
|
||||
|
||||
LabelDTO labelDTO2 = new LabelDTO("Label name2", "Label type");
|
||||
orderDTO.labels.add(labelDTO2);
|
||||
LabelReferenceDTO labelReferenceDTO2 = new LabelReferenceDTO(givenLabelStored()
|
||||
.getCode());
|
||||
orderDTO.labels.add(labelReferenceDTO2);
|
||||
instanceConstraintViolationsList = orderElementService
|
||||
.updateOrder(orderDTO).instanceConstraintViolationsList;
|
||||
assertThat(instanceConstraintViolationsList.size(), equalTo(0));
|
||||
|
|
@ -622,9 +623,8 @@ public class OrderElementServiceTest {
|
|||
orderElement = orderElementDAO.findUniqueByCode(code);
|
||||
assertThat(orderElement.getLabels().size(), equalTo(2));
|
||||
for (Label label : orderElement.getLabels()) {
|
||||
assertThat(label.getName(), anyOf(equalTo("Label name"),
|
||||
equalTo("Label name2")));
|
||||
assertThat(label.getType().getName(), equalTo("Label type"));
|
||||
assertThat(label.getCode(), anyOf(equalTo(labelReferenceDTO.code),
|
||||
equalTo(labelReferenceDTO2.code)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue