Create new subcontractor state for sending updates of the delivering

date, while it is created a new customer communication.

FEA: ItEr75S32AnA15S04UpdateDeliveringDateInSubcontracting
This commit is contained in:
Susana Montes Pedreira 2011-12-19 20:10:02 +01:00
parent a8ca548493
commit 8b50f2ebba
12 changed files with 427 additions and 20 deletions

View file

@ -27,6 +27,7 @@ import java.util.Set;
import org.libreplan.business.common.daos.IIntegrationEntityDAO;
import org.libreplan.business.common.exceptions.InstanceNotFoundException;
import org.libreplan.business.orders.entities.Order;
import org.libreplan.business.orders.entities.OrderElement;
import org.libreplan.business.templates.entities.OrderElementTemplate;
import org.libreplan.business.workingday.EffortDuration;
@ -133,4 +134,6 @@ public interface IOrderElementDAO extends IIntegrationEntityDAO<OrderElement> {
*/
OrderElement findRepeatedOrderCodeInDB(OrderElement order);
OrderElement findByExternalCode(String code) throws InstanceNotFoundException;
}

View file

@ -41,6 +41,7 @@ import org.libreplan.business.common.IAdHocTransactionService;
import org.libreplan.business.common.IOnTransaction;
import org.libreplan.business.common.daos.IntegrationEntityDAO;
import org.libreplan.business.common.exceptions.InstanceNotFoundException;
import org.libreplan.business.orders.entities.Order;
import org.libreplan.business.orders.entities.OrderElement;
import org.libreplan.business.orders.entities.SchedulingDataForVersion;
import org.libreplan.business.orders.entities.TaskSource;
@ -275,6 +276,29 @@ public class OrderElementDAO extends IntegrationEntityDAO<OrderElement>
return c.list();
}
@SuppressWarnings("unchecked")
@Override
public OrderElement findByExternalCode(String code) throws InstanceNotFoundException {
if (StringUtils.isBlank(code)) {
throw new InstanceNotFoundException(null, getEntityClass()
.getName());
}
Criteria c = getSession().createCriteria(OrderElement.class);
c.add(Restrictions.eq("externalCode", code.trim()).ignoreCase());
OrderElement entity = (OrderElement) c.uniqueResult();
if (entity == null) {
throw new InstanceNotFoundException(code, getEntityClass()
.getName());
} else {
return entity;
}
}
/**
* Methods to calculate estatistics with the estimated hours and worked
* hours of a set of order elements.

View file

@ -29,7 +29,9 @@ import static org.libreplan.business.i18n.I18nHelper._;
* @author Manuel Rego Casasnovas <mrego@igalia.com>
*/
public enum SubcontractState {
PENDING(_("Pending"), true), FAILED_SENT(_("Failed sent"), true), SUCCESS_SENT(
PENDING_INITIAL_SEND(_("Pending initial send"), true), PENDING_UPDATE_DELIVERING_DATE(
_("Pending update delivering date"), true), FAILED_SENT(
_("Failed sent"), true), FAILED_UPDATE(_("Failed update"), true), SUCCESS_SENT(
_("Success sent"), false);
private String name;

View file

@ -94,7 +94,7 @@ public class SubcontractedTaskData extends BaseEntity {
private Boolean materialAssignmentsExported;
private Boolean hoursGroupsExported;
private SubcontractState state = SubcontractState.PENDING;
private SubcontractState state = SubcontractState.PENDING_INITIAL_SEND;
private final SortedSet<SubcontractorDeliverDate> requiredDeliveringDates = new TreeSet<SubcontractorDeliverDate>(
new DeliverDateComparator());
@ -280,4 +280,10 @@ public class SubcontractedTaskData extends BaseEntity {
SubcontractorDeliverDate subcontractorDeliverDate) {
this.requiredDeliveringDates.remove(subcontractorDeliverDate);
}
public void updateFirstRequiredDeliverDate(Date subcontractCommunicationDate){
if(this.requiredDeliveringDates != null && !this.requiredDeliveringDates.isEmpty()){
this.requiredDeliveringDates.first().setCommunicationDate(subcontractCommunicationDate);
}
}
}

View file

@ -909,7 +909,7 @@ public class Task extends TaskElement implements ITaskPositionConstrained {
public boolean isSubcontractedAndWasAlreadySent() {
return (subcontractedTaskData != null)
&& (!subcontractedTaskData.getState()
.equals(SubcontractState.PENDING));
.equals(SubcontractState.PENDING_INITIAL_SEND));
}
public boolean hasSomeSatisfiedAllocation() {

View file

@ -206,6 +206,9 @@ public class SubcontractModel implements ISubcontractModel {
//update the end date of the task
updateEndDateWithDeliverDate();
//update the state of the subcontracted task data
updateStateToPendingUpdateDeliveringDate();
}
}
@ -215,6 +218,15 @@ public class SubcontractModel implements ISubcontractModel {
task.setEndDate(lastDeliverDate.getSubcontractorDeliverDate());
}
private void updateStateToPendingUpdateDeliveringDate(){
if ((subcontractedTaskData.getState() != null)
&& (subcontractedTaskData.getState()
.equals(SubcontractState.SUCCESS_SENT))) {
subcontractedTaskData
.setState(SubcontractState.PENDING_UPDATE_DELIVERING_DATE);
}
}
@Override
public boolean alreadyExistsRepeatedDeliverDate(Date newDeliverDate){
for(SubcontractorDeliverDate subDeliverDate : this
@ -234,6 +246,19 @@ public class SubcontractModel implements ISubcontractModel {
SubcontractorDeliverDate subcontractorDeliverDate) {
if(subcontractedTaskData != null){
subcontractedTaskData.removeRequiredDeliveringDates(subcontractorDeliverDate);
updateStateFromPendingDeliveringDateToSuccessSent();
}
}
private void updateStateFromPendingDeliveringDateToSuccessSent(){
if (subcontractedTaskData.getState() != null) {
switch (subcontractedTaskData.getState()) {
case PENDING_UPDATE_DELIVERING_DATE:
case FAILED_UPDATE:
subcontractedTaskData
.setState(SubcontractState.SUCCESS_SENT);
break;
}
}
}

View file

@ -23,12 +23,15 @@ package org.libreplan.web.subcontract;
import static org.libreplan.web.I18nHelper._;
import java.io.StringWriter;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import javax.ws.rs.WebApplicationException;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.datatype.XMLGregorianCalendar;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -95,7 +98,7 @@ public class SubcontractedTasksModel implements ISubcontractedTasksModel {
for (SubcontractedTaskData subcontractedTaskData : result) {
forceLoadExternalCompany(subcontractedTaskData);
}
return result;
return sortByState(result);
}
private void forceLoadExternalCompany(
@ -103,6 +106,37 @@ public class SubcontractedTasksModel implements ISubcontractedTasksModel {
subcontractedTaskData.getExternalCompany().getName();
}
private List<SubcontractedTaskData> sortByState(List<SubcontractedTaskData> tasks){
Collections.sort(tasks, new Comparator<SubcontractedTaskData>(){
@Override
public int compare(SubcontractedTaskData arg0, SubcontractedTaskData arg1) {
if((arg0 == null) || (arg0.getState() == null)){
return -1;
}
if((arg1 == null) || (arg1.getState() == null)){
return 1;
}
if(arg0.getState().equals(arg1.getState())){
return 0;
}
if (arg0.getState().equals(
SubcontractState.PENDING_INITIAL_SEND)) {
return 1;
}
if (arg1.getState().equals(
SubcontractState.PENDING_INITIAL_SEND)) {
return -1;
}
if( arg0.getState().equals(SubcontractState.PENDING_UPDATE_DELIVERING_DATE)) {
return 1;
}
return -1;
}
});
return tasks;
}
@Override
@Transactional(readOnly = true)
public String getOrderCode(SubcontractedTaskData subcontractedTaskData) {
@ -119,7 +153,14 @@ public class SubcontractedTasksModel implements ISubcontractedTasksModel {
UnrecoverableErrorServiceException {
subcontractedTaskDataDAO.save(subcontractedTaskData);
subcontractedTaskData.setState(SubcontractState.FAILED_SENT);
SubcontractState currentState = subcontractedTaskData.getState();
if (currentState.equals(SubcontractState.PENDING_INITIAL_SEND)) {
subcontractedTaskData.setState(SubcontractState.FAILED_SENT);
} else if (currentState
.equals(SubcontractState.PENDING_UPDATE_DELIVERING_DATE)) {
subcontractedTaskData.setState(SubcontractState.FAILED_UPDATE);
}
if (!subcontractedTaskData.isSendable()) {
throw new RuntimeException("Subcontracted task already sent");
@ -131,13 +172,81 @@ public class SubcontractedTasksModel implements ISubcontractedTasksModel {
"External company has not interaction fields filled");
}
makeSubcontractRequestRequest(subcontractedTaskData);
makeSubcontractRequestRequest(subcontractedTaskData,currentState);
Date today = new Date();
if (currentState.equals(SubcontractState.PENDING_INITIAL_SEND)) {
subcontractedTaskData.setSubcontractCommunicationDate(today);
}
//update the first required deliver date
subcontractedTaskData.updateFirstRequiredDeliverDate(today);
subcontractedTaskData.setSubcontractCommunicationDate(new Date());
subcontractedTaskData.setState(SubcontractState.SUCCESS_SENT);
}
private void makeSubcontractRequestRequest(
SubcontractedTaskData subcontractedTaskData,
SubcontractState currentState) throws ConnectionProblemsException,
UnrecoverableErrorServiceException {
if (subcontractedTaskData.getState() != null) {
if ((currentState.equals(SubcontractState.PENDING_INITIAL_SEND) || (currentState
.equals(SubcontractState.FAILED_SENT)))) {
makeSubcontractRequestRequest_InitialSent(subcontractedTaskData);
} else if ((currentState
.equals(SubcontractState.PENDING_UPDATE_DELIVERING_DATE) || currentState
.equals(SubcontractState.FAILED_UPDATE))) {
makeSubcontractRequestRequest_UpdateDeliverDate(subcontractedTaskData);
}
}
}
private void makeSubcontractRequestRequest_UpdateDeliverDate(SubcontractedTaskData subcontractedTaskData)
throws ConnectionProblemsException, UnrecoverableErrorServiceException {
UpdateDeliveringDateDTO updateDeliveringDateDTO = SubcontractedTaskDataConverter
.toUpdateDeliveringDateDTO(subcontractedTaskData);
ExternalCompany externalCompany = subcontractedTaskData
.getExternalCompany();
NaiveTrustProvider.setAlwaysTrust(true);
try {
WebClient client = WebClient.create(externalCompany.getAppURI());
client.path("ws/rest/subcontract/update");
Util.addAuthorizationHeader(client,
externalCompany.getOurCompanyLogin(),
externalCompany.getOurCompanyPassword());
InstanceConstraintViolationsListDTO instanceConstraintViolationsListDTO = client
.post(updateDeliveringDateDTO,
InstanceConstraintViolationsListDTO.class);
List<InstanceConstraintViolationsDTO> instanceConstraintViolationsList = instanceConstraintViolationsListDTO.instanceConstraintViolationsList;
if ((instanceConstraintViolationsList != null)
&& (!instanceConstraintViolationsList.isEmpty())) {
String message = "";
for (ConstraintViolationDTO constraintViolationDTO : instanceConstraintViolationsList
.get(0).constraintViolations) {
message += constraintViolationDTO.toString() + "\n";
}
throw new UnrecoverableErrorServiceException(message);
}
} catch (WebApplicationException e) {
LOG.error("Problems connecting with subcontractor web service", e);
String message = _("Problems connecting with subcontractor web service");
if (e.getMessage() != null) {
message += ". " + _("Error: {0}", e.getMessage());
}
throw new ConnectionProblemsException(message, e);
}
}
private void makeSubcontractRequestRequest_InitialSent(
SubcontractedTaskData subcontractedTaskData)
throws ConnectionProblemsException, UnrecoverableErrorServiceException {
SubcontractedTaskDataDTO subcontractedTaskDataDTO = getSubcontractedTaskData(subcontractedTaskData);
@ -150,7 +259,7 @@ public class SubcontractedTasksModel implements ISubcontractedTasksModel {
try {
WebClient client = WebClient.create(externalCompany.getAppURI());
client.path("ws/rest/subcontract");
client.path("ws/rest/subcontract/create");
Util.addAuthorizationHeader(client, externalCompany
.getOurCompanyLogin(), externalCompany
@ -239,6 +348,16 @@ public class SubcontractedTasksModel implements ISubcontractedTasksModel {
@Override
@Transactional(readOnly = true)
public String exportXML(SubcontractedTaskData subcontractedTaskData) {
SubcontractState currentState = subcontractedTaskData.getState();
if ((currentState.equals(SubcontractState.PENDING_INITIAL_SEND) || (currentState
.equals(SubcontractState.FAILED_SENT)))) {
return exportXML_CreateSubcontractor(subcontractedTaskData);
} else {
return exportXML_UpdateSubcontractor(subcontractedTaskData);
}
}
public String exportXML_CreateSubcontractor(SubcontractedTaskData subcontractedTaskData){
SubcontractedTaskDataDTO subcontractedTaskDataDTO = getSubcontractedTaskData(subcontractedTaskData);
StringWriter xml = new StringWriter();
@ -254,4 +373,21 @@ public class SubcontractedTasksModel implements ISubcontractedTasksModel {
return xml.toString();
}
public String exportXML_UpdateSubcontractor(SubcontractedTaskData subcontractedTaskData){
subcontractedTaskDataDAO.reattachUnmodifiedEntity(subcontractedTaskData);
UpdateDeliveringDateDTO updateDeliveringDateDTO = SubcontractedTaskDataConverter
.toUpdateDeliveringDateDTO(subcontractedTaskData);
StringWriter xml = new StringWriter();
try {
JAXBContext jaxbContext = JAXBContext
.newInstance(UpdateDeliveringDateDTO.class);
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.marshal(updateDeliveringDateDTO, xml);
} catch (Exception e) {
throw new RuntimeException(e);
}
return xml.toString();
}
}

View file

@ -0,0 +1,61 @@
/*
* This file is part of LibrePlan
*
* Copyright (C) 2011 WirelessGalicia, S.L.
*
* 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.libreplan.web.subcontract;
import java.util.Date;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.datatype.XMLGregorianCalendar;
import org.libreplan.business.planner.entities.SubcontractedTaskData;
import org.libreplan.ws.common.impl.DateConverter;
/**
* DTO UpdateDeliveringDate
*
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
*/
@XmlRootElement(name = "update-delivering-date")
public class UpdateDeliveringDateDTO {
@XmlAttribute(name = "customer-reference")
public String customerReference;
@XmlAttribute(name = "external-code")
public String externalCode;
@XmlAttribute(name = "external-company-nif")
public String companyNif;
@XmlAttribute(name = "deliver-date")
public XMLGregorianCalendar deliverDate;
public UpdateDeliveringDateDTO(){
}
public UpdateDeliveringDateDTO(String customerReference,
String externalCode, String companyNif, XMLGregorianCalendar deliverDate) {
this.customerReference = customerReference;
this.deliverDate = deliverDate;
this.companyNif = companyNif;
this.externalCode = externalCode;
}
}

View file

@ -21,6 +21,7 @@
package org.libreplan.ws.subcontract.api;
import org.libreplan.web.subcontract.UpdateDeliveringDateDTO;
import org.libreplan.ws.common.api.InstanceConstraintViolationsListDTO;
@ -34,4 +35,8 @@ public interface ISubcontractService {
InstanceConstraintViolationsListDTO subcontract(
SubcontractedTaskDataDTO subcontractedTaskDataDTO);
InstanceConstraintViolationsListDTO updateDeliveringDates(
UpdateDeliveringDateDTO updateDeliveringDateDTO);
}

View file

@ -27,6 +27,7 @@ import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElements;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.datatype.XMLGregorianCalendar;
import org.libreplan.business.planner.entities.SubcontractedTaskData;
import org.libreplan.ws.common.api.OrderDTO;
@ -54,6 +55,9 @@ public class SubcontractedTaskDataDTO {
@XmlAttribute(name = "subcontracted-code")
public String subcontractedCode;
@XmlAttribute(name = "deliver-date")
public XMLGregorianCalendar deliverDate;
@XmlElements( {
@XmlElement(name = "order-line", type = OrderLineDTO.class),
@XmlElement(name = "order-line-group", type = OrderLineGroupDTO.class),
@ -65,12 +69,14 @@ public class SubcontractedTaskDataDTO {
public SubcontractedTaskDataDTO(String externalCompanyNif,
String workDescription, BigDecimal subcontractPrice,
String subcontractedCode, OrderElementDTO orderElementDTO) {
String subcontractedCode, OrderElementDTO orderElementDTO,
XMLGregorianCalendar deliverDate) {
this.externalCompanyNif = externalCompanyNif;
this.workDescription = workDescription;
this.subcontractPrice = subcontractPrice;
this.subcontractedCode = subcontractedCode;
this.orderElementDTO = orderElementDTO;
this.deliverDate = deliverDate;
}
}

View file

@ -51,6 +51,7 @@ import org.libreplan.business.externalcompanies.daos.ICustomerCommunicationDAO;
import org.libreplan.business.externalcompanies.daos.IExternalCompanyDAO;
import org.libreplan.business.externalcompanies.entities.CommunicationType;
import org.libreplan.business.externalcompanies.entities.CustomerCommunication;
import org.libreplan.business.externalcompanies.entities.DeadlineCommunication;
import org.libreplan.business.externalcompanies.entities.ExternalCompany;
import org.libreplan.business.orders.daos.IOrderElementDAO;
import org.libreplan.business.orders.entities.Order;
@ -63,6 +64,7 @@ import org.libreplan.business.planner.daos.ITaskSourceDAO;
import org.libreplan.business.scenarios.daos.IScenarioDAO;
import org.libreplan.business.scenarios.entities.OrderVersion;
import org.libreplan.business.scenarios.entities.Scenario;
import org.libreplan.web.subcontract.UpdateDeliveringDateDTO;
import org.libreplan.ws.common.api.InstanceConstraintViolationsDTO;
import org.libreplan.ws.common.api.InstanceConstraintViolationsDTOId;
import org.libreplan.ws.common.api.InstanceConstraintViolationsListDTO;
@ -70,6 +72,7 @@ import org.libreplan.ws.common.api.OrderDTO;
import org.libreplan.ws.common.api.OrderElementDTO;
import org.libreplan.ws.common.impl.ConfigurationOrderElementConverter;
import org.libreplan.ws.common.impl.ConstraintViolationConverter;
import org.libreplan.ws.common.impl.DateConverter;
import org.libreplan.ws.common.impl.OrderElementConverter;
import org.libreplan.ws.common.impl.Util;
import org.libreplan.ws.subcontract.api.ISubcontractService;
@ -135,6 +138,94 @@ public class SubcontractServiceREST implements ISubcontractService {
@Override
@POST
@Path("update/")
@Consumes("application/xml")
public InstanceConstraintViolationsListDTO updateDeliveringDates(
final UpdateDeliveringDateDTO updateDeliveringDateDTO) {
try {
updateSubcontract(updateDeliveringDateDTO);
} catch (ViolationError e) {
return e.toViolationList();
}
return new InstanceConstraintViolationsListDTO();
}
private void updateSubcontract(
final UpdateDeliveringDateDTO updateDeliveringDateDTO) {
if (StringUtils.isEmpty(updateDeliveringDateDTO.companyNif)) {
throw new ViolationError(updateDeliveringDateDTO.companyNif,
"external company Nif not specified");
}
if (StringUtils.isEmpty(updateDeliveringDateDTO.externalCode)) {
throw new ViolationError(updateDeliveringDateDTO.externalCode,
"external order code not specified");
}
if ((updateDeliveringDateDTO.deliverDate) == null) {
throw new ViolationError(updateDeliveringDateDTO.deliverDate.toString(),
"deliver date not specified");
}
final ExternalCompany externalCompany = adHocTransactionService
.runOnTransaction(new IOnTransaction<ExternalCompany>() {
@Override
public ExternalCompany execute() {
return findExternalCompanyFor(updateDeliveringDateDTO.companyNif);
}
});
if (!externalCompany.isClient()) {
throw new ViolationError(updateDeliveringDateDTO.companyNif,
"external company is not registered as client");
}
try {
adHocTransactionService
.runOnTransaction(new IOnTransaction<Void>() {
@Override
public Void execute() {
updateDeliveringDateInOrder(updateDeliveringDateDTO);
return null;
}
});
} catch (ValidationException e) {
InstanceConstraintViolationsDTO violation = ConstraintViolationConverter
.toDTO(new InstanceConstraintViolationsDTOId(Long.valueOf(1),
updateDeliveringDateDTO.companyNif, OrderDTO.ENTITY_TYPE), e);
throw new ViolationError(violation);
}
}
private void updateDeliveringDateInOrder(UpdateDeliveringDateDTO updateDeliveringDateDTO){
try {
OrderElement orderElement = orderElementDAO
.findByExternalCode(updateDeliveringDateDTO.externalCode);
if((orderElement != null) && (orderElement instanceof Order)) {
Order order = (Order)orderElement;
DeadlineCommunication deadlineCommunication = DeadlineCommunication
.create(new Date(), DateConverter.toDate(updateDeliveringDateDTO.deliverDate));
order.getDeliveringDates().add(deadlineCommunication);
createCustomerCommunication(order, CommunicationType.UPDATE_DELIVERING_DATE);
orderElementDAO.save(order);
} else {
throw new ViolationError(
updateDeliveringDateDTO.customerReference,
"It do not exist any order with this reference");
}
} catch (InstanceNotFoundException e) {
throw new ViolationError(updateDeliveringDateDTO.customerReference,
"It do not exist any order with this reference");
}
}
@Override
@POST
@Path("create/")
@Consumes("application/xml")
public InstanceConstraintViolationsListDTO subcontract(
final SubcontractedTaskDataDTO subcontractedTaskDataDTO) {
@ -236,6 +327,13 @@ public class SubcontractServiceREST implements ISubcontractService {
TaskSource.persistTaskSources(taskSourceDAO));
order.writeSchedulingDataChanges();
if (subcontractedTaskDataDTO.deliverDate != null) {
DeadlineCommunication deadlineCommunication = DeadlineCommunication
.create(new Date(), DateConverter
.toDate(subcontractedTaskDataDTO.deliverDate));
order.getDeliveringDates().add(deadlineCommunication);
}
order.validate();
orderElementDAO.save(order);
@ -243,7 +341,7 @@ public class SubcontractServiceREST implements ISubcontractService {
* create the customer communication to a new subcontrating project.
*/
if(!StringUtils.isBlank(order.getExternalCode())){
createCustomerCommunication(order);
createCustomerCommunication(order, CommunicationType.NEW_PROJECT);
}
}
@ -306,13 +404,18 @@ public class SubcontractServiceREST implements ISubcontractService {
}
private ExternalCompany findExternalCompanyFor(
final SubcontractedTaskDataDTO subcontractedTask)
final SubcontractedTaskDataDTO subcontractedTask){
return findExternalCompanyFor(subcontractedTask.externalCompanyNif);
}
private ExternalCompany findExternalCompanyFor(
final String externalCompanyNif)
throws ViolationError {
try {
return externalCompanyDAO
.findUniqueByNif(subcontractedTask.externalCompanyNif);
.findUniqueByNif(externalCompanyNif);
} catch (InstanceNotFoundException e) {
throw new ViolationError(subcontractedTask.externalCompanyNif,
throw new ViolationError(externalCompanyNif,
"external company not found");
}
}
@ -323,12 +426,17 @@ public class SubcontractServiceREST implements ISubcontractService {
Util.generateInstanceId(1, code), message);
}
private void createCustomerCommunication(Order order){
Date deadline = order.getDeadline();
private void createCustomerCommunication(Order order, CommunicationType type){
Date communicationDate = new Date();
Date deadline = null;
if(type.equals(CommunicationType.NEW_PROJECT)){
deadline = order.getDeadline();
}else{
deadline = order.getDeliveringDates().first().getDeliverDate();
}
CustomerCommunication customerCommunication = CustomerCommunication
.create(deadline, communicationDate,
CommunicationType.NEW_PROJECT, order);
type, order);
customerCommunicationDAO.save(customerCommunication);
}
}

View file

@ -21,8 +21,14 @@
package org.libreplan.ws.subcontract.impl;
import java.util.Date;
import javax.xml.datatype.XMLGregorianCalendar;
import org.libreplan.business.planner.entities.SubcontractedTaskData;
import org.libreplan.web.subcontract.UpdateDeliveringDateDTO;
import org.libreplan.ws.common.api.OrderElementDTO;
import org.libreplan.ws.common.impl.DateConverter;
import org.libreplan.ws.subcontract.api.SubcontractedTaskDataDTO;
/**
@ -38,10 +44,35 @@ public final class SubcontractedTaskDataConverter {
public final static SubcontractedTaskDataDTO toDTO(String companyCode,
SubcontractedTaskData subcontractedTaskData,
OrderElementDTO orderElementDTO) {
return new SubcontractedTaskDataDTO(companyCode, subcontractedTaskData
.getWorkDescription(), subcontractedTaskData
.getSubcontractPrice(), subcontractedTaskData
.getSubcontractedCode(), orderElementDTO);
return new SubcontractedTaskDataDTO(companyCode,
subcontractedTaskData.getWorkDescription(),
subcontractedTaskData.getSubcontractPrice(),
subcontractedTaskData.getSubcontractedCode(), orderElementDTO,
toXmlDate(getDeliverDate(subcontractedTaskData)));
}
public final static UpdateDeliveringDateDTO toUpdateDeliveringDateDTO(SubcontractedTaskData subTaskData){
String customerReference = subTaskData.getSubcontractedCode();
XMLGregorianCalendar deliverDate = toXmlDate(getDeliverDate(subTaskData));
if(!subTaskData.getRequiredDeliveringDates().isEmpty()){
deliverDate = toXmlDate(subTaskData.getRequiredDeliveringDates().first().getSubcontractorDeliverDate());
}
String companyNif = subTaskData.getExternalCompany().getNif();
String externalCode = subTaskData.getTask().getOrderElement().getCode();
return new UpdateDeliveringDateDTO(customerReference, externalCode, companyNif,deliverDate);
}
private final static XMLGregorianCalendar toXmlDate(Date date) {
XMLGregorianCalendar xmlDate = (date != null) ? DateConverter
.toXMLGregorianCalendar(date) : null;
return xmlDate;
}
private final static Date getDeliverDate(SubcontractedTaskData subcontractedTaskData){
Date deliverDate = null;
if((subcontractedTaskData != null) && (!subcontractedTaskData.getRequiredDeliveringDates().isEmpty())){
deliverDate = subcontractedTaskData.getRequiredDeliveringDates().first().getSubcontractorDeliverDate();
}
return deliverDate;
}
}