add to the Order class a list sorted of elements of the

class EndDateCommunitationToCustomer.

FEA: ItEr76S21UpdateEndDateToCustomer
This commit is contained in:
Susana Montes Pedreira 2012-04-02 15:22:29 +01:00
parent 3a54b63419
commit a5fec5b8b6
6 changed files with 216 additions and 2 deletions

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
package org.libreplan.business.externalcompanies.entities;
import java.util.Date;
import org.libreplan.business.common.BaseEntity;
/**
* Entity EndDateCommunicationToCustomer
*
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
*/
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;
}
}

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
package org.libreplan.business.externalcompanies.entities;
import java.util.Comparator;
public class EndDateCommunicationToCustomerComparator implements
Comparator<EndDateCommunicationToCustomer> {
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());
}
}

View file

@ -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<DeadlineCommunication> deliveringDates = new TreeSet<DeadlineCommunication>(
new DeliverDateComparator());
@Valid
private SortedSet<EndDateCommunicationToCustomer> endDateCommunicationToCustomer = new TreeSet<EndDateCommunicationToCustomer>(
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> endDateCommunicationToCustomer) {
this.endDateCommunicationToCustomer.clear();
this.endDateCommunicationToCustomer.addAll(endDateCommunicationToCustomer);
}
public SortedSet<EndDateCommunicationToCustomer> 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);
}
}

View file

@ -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">
<changeSet author="smontes" id="initial-database-creation-customer-comunication">
<createTable tableName="customer_comunication">
<column name="id" type="BIGINT">
@ -195,4 +196,18 @@
<modifyDataType tableName="order_element_template" columnName="description" newDataType="TEXT" />
</changeSet>
<changeSet author="smontes" id="database-creation-table-end-date-communication-to-customer">
<createTable tableName="end_date_communication_to_customer">
<column name="id" type="BIGINT">
<constraints nullable="false" primaryKey="true" primaryKeyName="end_date_communication_to_customer_pkey"/>
</column>
<column name="version" type="BIGINT">
<constraints nullable="false"/>
</column>
<column name="save_date" type="DATETIME"/>
<column name="end_date" type="DATETIME"/>
<column name="communication_date" type="DATETIME"/>
<column name="order_id" type="BIGINT"/>
</createTable>
</changeSet>
</databaseChangeLog>

View file

@ -68,4 +68,16 @@
<property name="deliverDate" access="field" column="deliver_date" />
</class>
<!-- EndDateCommunicationToCustomer -->
<class name="EndDateCommunicationToCustomer" table="end_date_communication_to_customer">
<id name="id" type="long" access="property">
<generator class="hilo">
<param name="max_lo">100</param>
</generator>
</id>
<version name="version" access="property" type="long" />
<property name="endDate" access="field" column="end_date"/>
<property name="saveDate" access="field" column="save_date"/>
<property name="communicationDate" access="field" column="communication_date" />
</class>
</hibernate-mapping>

View file

@ -157,6 +157,11 @@
<one-to-many class="org.libreplan.business.externalcompanies.entities.DeadlineCommunication" />
</set>
<set name="endDateCommunicationToCustomer" inverse="false" cascade="all,delete-orphan" access="field"
sort="org.libreplan.business.externalcompanies.entities.EndDateCommunicationToCustomerComparator">
<key column="order_id" />
<one-to-many class="org.libreplan.business.externalcompanies.entities.EndDateCommunicationToCustomer" />
</set>
</joined-subclass>
</joined-subclass>