ItEr45S14CUActualizarTraballoExportadoPorSubcontrataItEr44S20: Created new service in order to manage advances reporting from supplier to customer.
This commit is contained in:
parent
a06f7f942e
commit
b59b77fd74
6 changed files with 312 additions and 0 deletions
|
|
@ -691,4 +691,13 @@ public final class OrderElementConverter {
|
|||
return directAdvanceAssignment;
|
||||
}
|
||||
|
||||
public static AdvanceMeasurement toEntity(
|
||||
AdvanceMeasurementDTO advanceMeasurementDTO) {
|
||||
AdvanceMeasurement advanceMeasurement = AdvanceMeasurement.create(
|
||||
LocalDate
|
||||
.fromDateFields(advanceMeasurementDTO.date),
|
||||
advanceMeasurementDTO.value);
|
||||
return advanceMeasurement;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* 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.subcontract.api;
|
||||
|
||||
import org.navalplanner.ws.common.api.InstanceConstraintViolationsListDTO;
|
||||
|
||||
/**
|
||||
* Service for managing advances reporting.
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
*/
|
||||
public interface IReportAdvancesService {
|
||||
|
||||
InstanceConstraintViolationsListDTO updateAdvances(
|
||||
OrderElementWithAdvanceMeasurementsListDTO orderElementWithAdvanceMeasurementsListDTO);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* 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.subcontract.api;
|
||||
|
||||
import java.util.HashSet;
|
||||
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;
|
||||
import org.navalplanner.ws.common.api.AdvanceMeasurementDTO;
|
||||
|
||||
/**
|
||||
* DTO for {@link OrderElement} just with information about advances.
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
*/
|
||||
@XmlRootElement(name = "order-element")
|
||||
public class OrderElementWithAdvanceMeasurementsDTO {
|
||||
|
||||
@XmlAttribute
|
||||
public String code;
|
||||
|
||||
@XmlElementWrapper(name = "advance-measurements")
|
||||
@XmlElement(name = "advance-measurement")
|
||||
public Set<AdvanceMeasurementDTO> advanceMeasurements = new HashSet<AdvanceMeasurementDTO>();
|
||||
|
||||
public OrderElementWithAdvanceMeasurementsDTO() {
|
||||
}
|
||||
|
||||
public OrderElementWithAdvanceMeasurementsDTO(String code,
|
||||
Set<AdvanceMeasurementDTO> advanceMeasurements) {
|
||||
this.code = code;
|
||||
this.advanceMeasurements = advanceMeasurements;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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.subcontract.api;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import org.navalplanner.business.orders.entities.OrderElement;
|
||||
|
||||
/**
|
||||
* DTO for {@link OrderElement} just with information about advances.
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
*/
|
||||
@XmlRootElement(name = "order-element-list")
|
||||
public class OrderElementWithAdvanceMeasurementsListDTO {
|
||||
|
||||
@XmlElement(name = "order-element")
|
||||
public List<OrderElementWithAdvanceMeasurementsDTO> orderElements = new ArrayList<OrderElementWithAdvanceMeasurementsDTO>();
|
||||
|
||||
public OrderElementWithAdvanceMeasurementsListDTO() {
|
||||
}
|
||||
|
||||
public OrderElementWithAdvanceMeasurementsListDTO(
|
||||
List<OrderElementWithAdvanceMeasurementsDTO> orderElements) {
|
||||
this.orderElements = orderElements;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,159 @@
|
|||
/*
|
||||
* 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.subcontract.impl;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
|
||||
import org.joda.time.LocalDate;
|
||||
import org.navalplanner.business.advance.bootstrap.PredefinedAdvancedTypes;
|
||||
import org.navalplanner.business.advance.entities.AdvanceMeasurement;
|
||||
import org.navalplanner.business.advance.entities.DirectAdvanceAssignment;
|
||||
import org.navalplanner.business.advance.exceptions.DuplicateAdvanceAssignmentForOrderElementException;
|
||||
import org.navalplanner.business.advance.exceptions.DuplicateValueTrueReportGlobalAdvanceException;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.common.exceptions.ValidationException;
|
||||
import org.navalplanner.business.orders.daos.IOrderElementDAO;
|
||||
import org.navalplanner.business.orders.entities.OrderElement;
|
||||
import org.navalplanner.ws.common.api.AdvanceMeasurementDTO;
|
||||
import org.navalplanner.ws.common.api.InstanceConstraintViolationsDTO;
|
||||
import org.navalplanner.ws.common.api.InstanceConstraintViolationsListDTO;
|
||||
import org.navalplanner.ws.common.impl.ConstraintViolationConverter;
|
||||
import org.navalplanner.ws.common.impl.OrderElementConverter;
|
||||
import org.navalplanner.ws.common.impl.Util;
|
||||
import org.navalplanner.ws.subcontract.api.IReportAdvancesService;
|
||||
import org.navalplanner.ws.subcontract.api.OrderElementWithAdvanceMeasurementsDTO;
|
||||
import org.navalplanner.ws.subcontract.api.OrderElementWithAdvanceMeasurementsListDTO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* REST-based implementation of {@link IReportAdvancesService}.
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
*/
|
||||
@Path("/reportadvances/")
|
||||
@Produces("application/xml")
|
||||
@Service("reportAdvancesServiceREST")
|
||||
public class ReportAdvancesServiceREST implements IReportAdvancesService {
|
||||
|
||||
@Autowired
|
||||
private IOrderElementDAO orderElementDAO;
|
||||
|
||||
private InstanceConstraintViolationsListDTO getErrorMessage(String code,
|
||||
String message) {
|
||||
// FIXME review errors returned
|
||||
return new InstanceConstraintViolationsListDTO(Arrays
|
||||
.asList(InstanceConstraintViolationsDTO.create(Util
|
||||
.generateInstanceId(1, code), message)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@POST
|
||||
@Consumes("application/xml")
|
||||
@Transactional
|
||||
public InstanceConstraintViolationsListDTO updateAdvances(OrderElementWithAdvanceMeasurementsListDTO orderElementWithAdvanceMeasurementsListDTO) {
|
||||
|
||||
List<InstanceConstraintViolationsDTO> instanceConstraintViolationsList = new ArrayList<InstanceConstraintViolationsDTO>();
|
||||
|
||||
InstanceConstraintViolationsDTO instanceConstraintViolationsDTO = null;
|
||||
|
||||
List<OrderElementWithAdvanceMeasurementsDTO> orderElements = orderElementWithAdvanceMeasurementsListDTO.orderElements;
|
||||
for (OrderElementWithAdvanceMeasurementsDTO orderElementWithAdvanceMeasurementsDTO : orderElements) {
|
||||
try {
|
||||
OrderElement orderElement = orderElementDAO
|
||||
.findUniqueByCode(orderElementWithAdvanceMeasurementsDTO.code);
|
||||
|
||||
DirectAdvanceAssignment advanceAssignmentSubcontractor = orderElement
|
||||
.getDirectAdvanceAssignmentSubcontractor();
|
||||
if (advanceAssignmentSubcontractor == null) {
|
||||
DirectAdvanceAssignment reportGlobal = orderElement
|
||||
.getReportGlobalAdvanceAssignment();
|
||||
|
||||
advanceAssignmentSubcontractor = DirectAdvanceAssignment
|
||||
.create((reportGlobal == null), new BigDecimal(100));
|
||||
advanceAssignmentSubcontractor
|
||||
.setAdvanceType(PredefinedAdvancedTypes.SUBCONTRACTOR
|
||||
.getType());
|
||||
advanceAssignmentSubcontractor
|
||||
.setOrderElement(orderElement);
|
||||
|
||||
try {
|
||||
orderElement
|
||||
.addAdvanceAssignment(advanceAssignmentSubcontractor);
|
||||
} catch (DuplicateValueTrueReportGlobalAdvanceException e) {
|
||||
// This shouldn't happen, because new advance is only
|
||||
// marked as report global if there is not other advance
|
||||
// as report global
|
||||
throw new RuntimeException(e);
|
||||
} catch (DuplicateAdvanceAssignmentForOrderElementException e) {
|
||||
return getErrorMessage(
|
||||
orderElementWithAdvanceMeasurementsDTO.code,
|
||||
"someone in the same branch has the same advance type");
|
||||
}
|
||||
}
|
||||
|
||||
for (AdvanceMeasurementDTO advanceMeasurementDTO : orderElementWithAdvanceMeasurementsDTO.advanceMeasurements) {
|
||||
AdvanceMeasurement advanceMeasurement = advanceAssignmentSubcontractor
|
||||
.getAdvanceMeasurement(LocalDate
|
||||
.fromDateFields(advanceMeasurementDTO.date));
|
||||
if (advanceMeasurement == null) {
|
||||
advanceAssignmentSubcontractor
|
||||
.addAdvanceMeasurements(OrderElementConverter
|
||||
.toEntity(advanceMeasurementDTO));
|
||||
} else {
|
||||
advanceMeasurement
|
||||
.setValue(advanceMeasurementDTO.value);
|
||||
}
|
||||
}
|
||||
|
||||
orderElement.validate();
|
||||
orderElementDAO.save(orderElement);
|
||||
} catch (ValidationException e) {
|
||||
instanceConstraintViolationsDTO = ConstraintViolationConverter
|
||||
.toDTO(Util.generateInstanceId(1,
|
||||
orderElementWithAdvanceMeasurementsDTO.code), e
|
||||
.getInvalidValues());
|
||||
} catch (InstanceNotFoundException e) {
|
||||
return getErrorMessage(
|
||||
orderElementWithAdvanceMeasurementsDTO.code,
|
||||
"instance not found");
|
||||
}
|
||||
}
|
||||
|
||||
if (instanceConstraintViolationsDTO != null) {
|
||||
instanceConstraintViolationsList
|
||||
.add(instanceConstraintViolationsDTO);
|
||||
}
|
||||
|
||||
return new InstanceConstraintViolationsListDTO(
|
||||
instanceConstraintViolationsList);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -51,6 +51,7 @@
|
|||
<ref bean="orderElementServiceREST"/>
|
||||
<ref bean="resourceServiceREST"/>
|
||||
<ref bean="subcontractServiceREST"/>
|
||||
<ref bean="reportAdvancesServiceREST"/>
|
||||
</jaxrs:serviceBeans>
|
||||
<jaxrs:providers>
|
||||
<ref bean="runtimeExceptionMapper" />
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue