From a5fec5b8b610813775bedda233d92f1f943bb0ac Mon Sep 17 00:00:00 2001 From: Susana Montes Pedreira Date: Mon, 2 Apr 2012 15:22:29 +0100 Subject: [PATCH] add to the Order class a list sorted of elements of the class EndDateCommunitationToCustomer. FEA: ItEr76S21UpdateEndDateToCustomer --- .../EndDateCommunicationToCustomer.java | 93 +++++++++++++++++++ ...DateCommunicationToCustomerComparator.java | 45 +++++++++ .../business/orders/entities/Order.java | 48 +++++++++- .../src/main/resources/db.changelog-1.2.xml | 15 +++ .../entities/ExternalCompanies.hbm.xml | 12 +++ .../business/orders/entities/Orders.hbm.xml | 5 + 6 files changed, 216 insertions(+), 2 deletions(-) create mode 100644 libreplan-business/src/main/java/org/libreplan/business/externalcompanies/entities/EndDateCommunicationToCustomer.java create mode 100644 libreplan-business/src/main/java/org/libreplan/business/externalcompanies/entities/EndDateCommunicationToCustomerComparator.java diff --git a/libreplan-business/src/main/java/org/libreplan/business/externalcompanies/entities/EndDateCommunicationToCustomer.java b/libreplan-business/src/main/java/org/libreplan/business/externalcompanies/entities/EndDateCommunicationToCustomer.java new file mode 100644 index 000000000..0931927bd --- /dev/null +++ b/libreplan-business/src/main/java/org/libreplan/business/externalcompanies/entities/EndDateCommunicationToCustomer.java @@ -0,0 +1,93 @@ +/* + * This file is part of LibrePlan + * + * Copyright (C) 2012 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 . + */ + +package org.libreplan.business.externalcompanies.entities; + +import java.util.Date; + +import org.libreplan.business.common.BaseEntity; + +/** + * Entity EndDateCommunicationToCustomer + * + * @author Susana Montes Pedreira + */ + +public class EndDateCommunicationToCustomer extends BaseEntity { + + private Date saveDate; + + private Date endDate; + + private Date communicationDate; + + protected EndDateCommunicationToCustomer() { + this.setSaveDate(new Date()); + } + + protected EndDateCommunicationToCustomer(Date endDate) { + this.setEndDate(endDate); + this.setSaveDate(new Date()); + } + + protected EndDateCommunicationToCustomer(Date saveDate, Date endDate, + Date communicationDate) { + this.setSaveDate(saveDate); + this.setEndDate(endDate); + this.setCommunicationDate(communicationDate); + } + + public static EndDateCommunicationToCustomer create() { + return create(new EndDateCommunicationToCustomer()); + } + + public static EndDateCommunicationToCustomer create(Date endDate) { + return create(new EndDateCommunicationToCustomer(endDate)); + } + + public static EndDateCommunicationToCustomer create(Date saveDate, Date endDate, + Date communicationDate) { + return create(new EndDateCommunicationToCustomer(saveDate, endDate, communicationDate)); + } + + public void setSaveDate(Date saveDate) { + this.saveDate = saveDate; + } + + public Date getSaveDate() { + return saveDate; + } + + public void setEndDate(Date endDate) { + this.endDate = endDate; + } + + public Date getEndDate() { + return endDate; + } + + public void setCommunicationDate(Date communicationDate2) { + this.communicationDate = communicationDate2; + } + + public Date getCommunicationDate() { + return communicationDate; + } + +} diff --git a/libreplan-business/src/main/java/org/libreplan/business/externalcompanies/entities/EndDateCommunicationToCustomerComparator.java b/libreplan-business/src/main/java/org/libreplan/business/externalcompanies/entities/EndDateCommunicationToCustomerComparator.java new file mode 100644 index 000000000..eadbee5c5 --- /dev/null +++ b/libreplan-business/src/main/java/org/libreplan/business/externalcompanies/entities/EndDateCommunicationToCustomerComparator.java @@ -0,0 +1,45 @@ +/* + * This file is part of LibrePlan + * + * Copyright (C) 2012 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 . + */ + +package org.libreplan.business.externalcompanies.entities; + +import java.util.Comparator; + + +public class EndDateCommunicationToCustomerComparator implements + Comparator { + + public EndDateCommunicationToCustomerComparator() { + } + + @Override + public int compare(EndDateCommunicationToCustomer arg0, EndDateCommunicationToCustomer arg1) { + if (arg0.getSaveDate() == arg1.getSaveDate()) { + return 0; + } + if (arg0.getSaveDate() == null) { + return -1; + } + if (arg1.getSaveDate() == null) { + return 1; + } + return arg1.getSaveDate().compareTo(arg0.getSaveDate()); + } + +} diff --git a/libreplan-business/src/main/java/org/libreplan/business/orders/entities/Order.java b/libreplan-business/src/main/java/org/libreplan/business/orders/entities/Order.java index 35f0a47ab..56f61028c 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/orders/entities/Order.java +++ b/libreplan-business/src/main/java/org/libreplan/business/orders/entities/Order.java @@ -24,6 +24,7 @@ package org.libreplan.business.orders.entities; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Collections; +import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -38,8 +39,6 @@ import org.hibernate.validator.AssertTrue; import org.hibernate.validator.NotNull; import org.hibernate.validator.Valid; import org.libreplan.business.advance.bootstrap.PredefinedAdvancedTypes; -import org.libreplan.business.advance.entities.AdvanceMeasurement; -import org.libreplan.business.advance.entities.AdvanceMeasurementComparator; import org.libreplan.business.advance.entities.AdvanceType; import org.libreplan.business.advance.entities.DirectAdvanceAssignment; import org.libreplan.business.calendars.entities.BaseCalendar; @@ -49,6 +48,8 @@ import org.libreplan.business.common.exceptions.InstanceNotFoundException; import org.libreplan.business.externalcompanies.entities.CustomerCommunication; import org.libreplan.business.externalcompanies.entities.DeadlineCommunication; import org.libreplan.business.externalcompanies.entities.DeliverDateComparator; +import org.libreplan.business.externalcompanies.entities.EndDateCommunicationToCustomer; +import org.libreplan.business.externalcompanies.entities.EndDateCommunicationToCustomerComparator; import org.libreplan.business.externalcompanies.entities.ExternalCompany; import org.libreplan.business.orders.daos.IOrderDAO; import org.libreplan.business.planner.entities.DayAssignment; @@ -119,6 +120,10 @@ public class Order extends OrderLineGroup implements Comparable { private SortedSet deliveringDates = new TreeSet( new DeliverDateComparator()); + @Valid + private SortedSet endDateCommunicationToCustomer = new TreeSet( + new EndDateCommunicationToCustomerComparator()); + public enum SchedulingMode { FORWARD, BACKWARDS; } @@ -597,4 +602,43 @@ public class Order extends OrderLineGroup implements Comparable { return deliveringDates; } + public void setEndDateCommunicationToCustomer( + SortedSet endDateCommunicationToCustomer) { + this.endDateCommunicationToCustomer.clear(); + this.endDateCommunicationToCustomer.addAll(endDateCommunicationToCustomer); + } + + public SortedSet getEndDateCommunicationToCustomer() { + return Collections.unmodifiableSortedSet(this.endDateCommunicationToCustomer); + } + + public void updateFirstAskedEndDate(Date communicationDate) { + if (this.endDateCommunicationToCustomer != null && !this.endDateCommunicationToCustomer.isEmpty()) { + this.endDateCommunicationToCustomer.first().setCommunicationDate(communicationDate); + } + } + + public Date getLastAskedEndDate() { + if (this.endDateCommunicationToCustomer != null + && !this.endDateCommunicationToCustomer.isEmpty()) { + return this.endDateCommunicationToCustomer.first().getEndDate(); + } + return null; + } + + public EndDateCommunicationToCustomer getLastEndDateCommunicationToCustomer() { + if (this.endDateCommunicationToCustomer != null + && !this.endDateCommunicationToCustomer.isEmpty()) { + return this.endDateCommunicationToCustomer.first(); + } + return null; + } + + public void removeAskedEndDate(EndDateCommunicationToCustomer endDate) { + this.endDateCommunicationToCustomer.remove(endDate); + } + + public void addAskedEndDate(EndDateCommunicationToCustomer endDate) { + this.endDateCommunicationToCustomer.add(endDate); + } } diff --git a/libreplan-business/src/main/resources/db.changelog-1.2.xml b/libreplan-business/src/main/resources/db.changelog-1.2.xml index a430f7049..fc6718d50 100644 --- a/libreplan-business/src/main/resources/db.changelog-1.2.xml +++ b/libreplan-business/src/main/resources/db.changelog-1.2.xml @@ -3,6 +3,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd"> + @@ -195,4 +196,18 @@ + + + + + + + + + + + + + + diff --git a/libreplan-business/src/main/resources/org/libreplan/business/externalcompanies/entities/ExternalCompanies.hbm.xml b/libreplan-business/src/main/resources/org/libreplan/business/externalcompanies/entities/ExternalCompanies.hbm.xml index c19795179..c9dce0aec 100644 --- a/libreplan-business/src/main/resources/org/libreplan/business/externalcompanies/entities/ExternalCompanies.hbm.xml +++ b/libreplan-business/src/main/resources/org/libreplan/business/externalcompanies/entities/ExternalCompanies.hbm.xml @@ -68,4 +68,16 @@ + + + + + 100 + + + + + + + diff --git a/libreplan-business/src/main/resources/org/libreplan/business/orders/entities/Orders.hbm.xml b/libreplan-business/src/main/resources/org/libreplan/business/orders/entities/Orders.hbm.xml index b59a58d45..e2023623f 100644 --- a/libreplan-business/src/main/resources/org/libreplan/business/orders/entities/Orders.hbm.xml +++ b/libreplan-business/src/main/resources/org/libreplan/business/orders/entities/Orders.hbm.xml @@ -157,6 +157,11 @@ + + + +