creates a new field in the Order entity to store the delivering dates communications.

FEA: ItEr75S32AnA15S04UpdateDeliveringDateInSubcontracting
This commit is contained in:
Susana Montes Pedreira 2011-12-12 11:28:04 +01:00
parent 31e899353e
commit 69fc902751
5 changed files with 139 additions and 0 deletions

View file

@ -0,0 +1,49 @@
/*
* 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.business.externalcompanies.entities;
import java.util.Comparator;
import org.libreplan.business.externalcompanies.entities.DeadlineCommunication;
/**
* Comparator to {@link DeadlineCommunication}
*
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
*/
public class DeadlineCommunicationComparator implements Comparator<DeadlineCommunication> {
public DeadlineCommunicationComparator(){
}
@Override
public int compare(DeadlineCommunication arg0, DeadlineCommunication 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

@ -29,12 +29,17 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.Validate;
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;
@ -42,6 +47,8 @@ import org.libreplan.business.common.Registry;
import org.libreplan.business.common.entities.EntitySequence;
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.DeadlineCommunicationComparator;
import org.libreplan.business.externalcompanies.entities.ExternalCompany;
import org.libreplan.business.orders.daos.IOrderDAO;
import org.libreplan.business.planner.entities.DayAssignment;
@ -107,6 +114,10 @@ public class Order extends OrderLineGroup implements Comparable {
private Set<CustomerCommunication> customerCommunications = new HashSet<CustomerCommunication>();
@Valid
private SortedSet<DeadlineCommunication> deliveringDates = new TreeSet<DeadlineCommunication>(
new DeadlineCommunicationComparator());
public enum SchedulingMode {
FORWARD, BACKWARDS;
}
@ -576,4 +587,12 @@ public class Order extends OrderLineGroup implements Comparable {
return customerCommunications;
}
public void setDeliveringDates(SortedSet<DeadlineCommunication> deliveringDates) {
this.deliveringDates = deliveringDates;
}
public SortedSet<DeadlineCommunication> getDeliveringDates() {
return deliveringDates;
}
}

View file

@ -103,4 +103,11 @@
</createTable>
</changeSet>
<changeSet id="add-delivering-date-column-to-order-entity" author="smontes">
<comment>Add new delivering date column to order</comment>
<addColumn tableName="deadline_communication">
<column name="order_id" type="BIGINT"/>
</addColumn>
</changeSet>
</databaseChangeLog>

View file

@ -150,6 +150,14 @@
<key column="order_id" />
<one-to-many class="org.libreplan.business.externalcompanies.entities.CustomerCommunication" />
</set>
<set name="deliveringDates" cascade="all,delete-orphan"
inverse="true" access="field"
sort="org.libreplan.business.externalcompanies.entities.DeadlineCommunicationComparator">
<key column="order_id" />
<one-to-many class="org.libreplan.business.externalcompanies.entities.DeadlineCommunication" />
</set>
</joined-subclass>
</joined-subclass>

View file

@ -20,12 +20,17 @@
package org.libreplan.business.test.orders.daos;
import static junit.framework.Assert.assertNotNull;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.libreplan.business.BusinessGlobalNames.BUSINESS_SPRING_CONFIG_FILE;
import static org.libreplan.business.test.BusinessGlobalNames.BUSINESS_SPRING_CONFIG_TEST_FILE;
import java.util.Date;
import java.util.UUID;
import org.joda.time.LocalDate;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -34,6 +39,7 @@ import org.libreplan.business.calendars.entities.BaseCalendar;
import org.libreplan.business.common.IAdHocTransactionService;
import org.libreplan.business.common.IOnTransaction;
import org.libreplan.business.common.exceptions.ValidationException;
import org.libreplan.business.externalcompanies.entities.DeadlineCommunication;
import org.libreplan.business.orders.daos.IOrderDAO;
import org.libreplan.business.orders.entities.Order;
import org.libreplan.business.scenarios.IScenarioManager;
@ -102,6 +108,56 @@ public class OrderDAOTest {
return order;
}
private Order createValidOrderWithDeadlineCommunications(String name) {
Order order = createValidOrder(name);
//create two deadline communications
Date date1 = (new Date());
Date date2 = (new LocalDate(date1).plusDays(3)).toDateTimeAtStartOfDay().toDate();
DeadlineCommunication deadlineCommunication1 = DeadlineCommunication.create(date1, null);
DeadlineCommunication deadlineCommunication2 = DeadlineCommunication.create(date2, null);
order.getDeliveringDates().add(deadlineCommunication1);
order.getDeliveringDates().add(deadlineCommunication2);
return order;
}
@Test
public void testSaveOrdersWithDeliveringDates() {
Order order = createValidOrderWithDeadlineCommunications("test");
orderDAO.save(order);
orderDAO.flush();
assertThat(order.getDeliveringDates().size(), equalTo(2));
DeadlineCommunication dcFirst = order.getDeliveringDates().first();
DeadlineCommunication dcLast = order.getDeliveringDates().last();
assertTrue(dcFirst.getSaveDate().after(dcLast.getSaveDate()));
//A new DeadlineCommunication is placed between the existing communications.
Date date = (new LocalDate(dcLast.getSaveDate()).plusDays(2)).toDateTimeAtStartOfDay().toDate();
DeadlineCommunication deadlineCommunication = DeadlineCommunication.create(date, null);
order.getDeliveringDates().add(deadlineCommunication);
orderDAO.save(order);
orderDAO.flush();
assertThat(order.getDeliveringDates().size(), equalTo(3));
dcFirst = order.getDeliveringDates().first();
dcLast = order.getDeliveringDates().last();
DeadlineCommunication new_dc = (DeadlineCommunication) order.getDeliveringDates().toArray()[1];
assertTrue(dcFirst.getSaveDate().after(dcLast.getSaveDate()));
assertTrue(dcFirst.getSaveDate().after(new_dc.getSaveDate()));
assertFalse(dcLast.equals(new_dc));
assertTrue(dcLast.getSaveDate().before(new_dc.getSaveDate()));
}
@Test
public void testSaveTwoOrdersWithDifferentNames() {
transactionService.runOnAnotherTransaction(new IOnTransaction<Void>() {