From b0340bf8a163033ec84fd4ffd920b49cf086fccc Mon Sep 17 00:00:00 2001 From: Susana Montes Pedreira Date: Thu, 27 Oct 2011 11:18:27 +0200 Subject: [PATCH] Create the entity CustomerComunication, the dao CustomerComunicationDAO, the test CustomerComunicationDAOTest and add the changes of the database in a new file db.changelog-1.2.xml FEA: ItEr75S28CustomerIncommingCommunicationsLists --- .../daos/CustomerComunicationDAO.java | 56 +++++++ .../daos/ICustomerComunicationDAO.java | 41 +++++ .../entities/ComunicationType.java | 31 ++++ .../entities/CustomerComunication.java | 130 ++++++++++++++++ .../src/main/resources/db.changelog-1.2.xml | 21 +++ .../src/main/resources/db.changelog.xml | 2 +- .../entities/ExternalCompanies.hbm.xml | 22 +++ .../daos/CustomerComunicationDAOTest.java | 145 ++++++++++++++++++ 8 files changed, 447 insertions(+), 1 deletion(-) create mode 100644 libreplan-business/src/main/java/org/libreplan/business/externalcompanies/daos/CustomerComunicationDAO.java create mode 100644 libreplan-business/src/main/java/org/libreplan/business/externalcompanies/daos/ICustomerComunicationDAO.java create mode 100644 libreplan-business/src/main/java/org/libreplan/business/externalcompanies/entities/ComunicationType.java create mode 100644 libreplan-business/src/main/java/org/libreplan/business/externalcompanies/entities/CustomerComunication.java create mode 100644 libreplan-business/src/main/resources/db.changelog-1.2.xml create mode 100644 libreplan-business/src/test/java/org/libreplan/business/test/externalcompanies/daos/CustomerComunicationDAOTest.java diff --git a/libreplan-business/src/main/java/org/libreplan/business/externalcompanies/daos/CustomerComunicationDAO.java b/libreplan-business/src/main/java/org/libreplan/business/externalcompanies/daos/CustomerComunicationDAO.java new file mode 100644 index 000000000..52499a67b --- /dev/null +++ b/libreplan-business/src/main/java/org/libreplan/business/externalcompanies/daos/CustomerComunicationDAO.java @@ -0,0 +1,56 @@ +/* + * This file is part of NavalPlan + * + * Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e + * Desenvolvemento Tecnolóxico de Galicia + * Copyright (C) 2010-2011 Igalia, 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.daos; + +import java.util.List; + +import org.hibernate.Criteria; +import org.hibernate.criterion.Restrictions; +import org.libreplan.business.common.daos.GenericDAOHibernate; +import org.libreplan.business.externalcompanies.entities.CustomerComunication; +import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Repository; + +/** + * Hibernate DAO for {@link CustomerComunication} + * + * @author Susana Montes Pedreira + */ +@Repository +@Scope(BeanDefinition.SCOPE_SINGLETON) +public class CustomerComunicationDAO extends GenericDAOHibernate +implements ICustomerComunicationDAO { + + @Override + public List getAll(){ + return list(CustomerComunication.class); + } + + @Override + public List getAllNotReviewed(){ + Criteria c = getSession().createCriteria(CustomerComunication.class); + c.add(Restrictions.eq("reviewed", false)); + return c.list(); + } + +} diff --git a/libreplan-business/src/main/java/org/libreplan/business/externalcompanies/daos/ICustomerComunicationDAO.java b/libreplan-business/src/main/java/org/libreplan/business/externalcompanies/daos/ICustomerComunicationDAO.java new file mode 100644 index 000000000..5d6c1b270 --- /dev/null +++ b/libreplan-business/src/main/java/org/libreplan/business/externalcompanies/daos/ICustomerComunicationDAO.java @@ -0,0 +1,41 @@ +/* + * This file is part of NavalPlan + * + * Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e + * Desenvolvemento Tecnolóxico de Galicia + * Copyright (C) 2010-2011 Igalia, 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.daos; + +import java.util.List; + +import org.libreplan.business.common.daos.IGenericDAO; +import org.libreplan.business.externalcompanies.entities.CustomerComunication; + + +/** + * Interface of the DAO for {@link CustomerComunication} + * + * @author Susana Montes Pedreira + */ +public interface ICustomerComunicationDAO extends IGenericDAO { + + List getAll(); + + List getAllNotReviewed(); + +} \ No newline at end of file diff --git a/libreplan-business/src/main/java/org/libreplan/business/externalcompanies/entities/ComunicationType.java b/libreplan-business/src/main/java/org/libreplan/business/externalcompanies/entities/ComunicationType.java new file mode 100644 index 000000000..ff95d30e6 --- /dev/null +++ b/libreplan-business/src/main/java/org/libreplan/business/externalcompanies/entities/ComunicationType.java @@ -0,0 +1,31 @@ +/* + * This file is part of NavalPlan + * + * Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e + * Desenvolvemento Tecnolóxico de Galicia + * Copyright (C) 2010-2011 Igalia, 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; + +/** + * Enum for specified the type of {@link CustomerComunication} + * + * @author Susana Montes Pedreira + */ +public enum ComunicationType { + New_Project +} diff --git a/libreplan-business/src/main/java/org/libreplan/business/externalcompanies/entities/CustomerComunication.java b/libreplan-business/src/main/java/org/libreplan/business/externalcompanies/entities/CustomerComunication.java new file mode 100644 index 000000000..3f884dcf1 --- /dev/null +++ b/libreplan-business/src/main/java/org/libreplan/business/externalcompanies/entities/CustomerComunication.java @@ -0,0 +1,130 @@ +/* + * This file is part of NavalPlan + * + * Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e + * Desenvolvemento Tecnolóxico de Galicia + * Copyright (C) 2010-2011 Igalia, 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.hibernate.validator.NotEmpty; +import org.hibernate.validator.NotNull; +import org.libreplan.business.common.BaseEntity; +import org.libreplan.business.orders.entities.Order; + +/** + * Entity CustomerComunication + * + * @author Susana Montes Pedreira + */ +public class CustomerComunication extends BaseEntity{ + + private Date deadline; + + private ComunicationType comunicationType; + + private Date comunicationDate; + + private Boolean reviewed = false; + + private Order order; + + public CustomerComunication() { + this.setComunicationDate(new Date()); + } + + public static CustomerComunication create() { + return (CustomerComunication) create(new CustomerComunication()); + } + + public CustomerComunication(Date deadline) { + this.setDeadline(deadline); + this.setComunicationDate(new Date()); + } + + public static CustomerComunication createToday(Date deadline) { + return (CustomerComunication) create(new CustomerComunication(deadline)); + } + + public static CustomerComunication createTodayNewProject(Date deadline) { + return (CustomerComunication) create(new CustomerComunication(deadline, new Date(), ComunicationType.New_Project)); + } + + protected CustomerComunication(Date deadline, Date comunicationDate, ComunicationType comunicationType) { + this.setDeadline(deadline); + this.setComunicationDate(comunicationDate); + this.setComunicationType(comunicationType); + } + + protected CustomerComunication(Date deadline, Date comunicationDate, ComunicationType comunicationType, Order order) { + this.setDeadline(deadline); + this.setComunicationDate(comunicationDate); + this.setComunicationType(comunicationType); + this.setOrder(order); + } + + public static CustomerComunication create(Date deadline, Date comunicationDate, ComunicationType comunicationType) { + return (CustomerComunication) create(new CustomerComunication(deadline, comunicationDate, comunicationType)); + } + + public static CustomerComunication create(Date deadline, Date comunicationDate, ComunicationType comunicationType, Order order) { + return (CustomerComunication) create(new CustomerComunication(deadline, comunicationDate, comunicationType, order)); + } + + public void setDeadline(Date deadline) { + this.deadline = deadline; + } + + public Date getDeadline() { + return deadline; + } + + public void setComunicationType(ComunicationType comunicationType) { + this.comunicationType = comunicationType; + } + + public ComunicationType getComunicationType() { + return comunicationType; + } + + public void setComunicationDate(Date comunicationDate) { + this.comunicationDate = comunicationDate; + } + + public Date getComunicationDate() { + return comunicationDate; + } + + public void setReviewed(Boolean reviewed) { + this.reviewed = reviewed; + } + + public Boolean getReviewed() { + return reviewed; + } + + public void setOrder(Order order) { + this.order = order; + } + + @NotNull(message = "order not specified") + public Order getOrder() { + return order; + } +} diff --git a/libreplan-business/src/main/resources/db.changelog-1.2.xml b/libreplan-business/src/main/resources/db.changelog-1.2.xml new file mode 100644 index 000000000..ecb610e1b --- /dev/null +++ b/libreplan-business/src/main/resources/db.changelog-1.2.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/libreplan-business/src/main/resources/db.changelog.xml b/libreplan-business/src/main/resources/db.changelog.xml index d74b91d48..7cff8e9f7 100644 --- a/libreplan-business/src/main/resources/db.changelog.xml +++ b/libreplan-business/src/main/resources/db.changelog.xml @@ -9,5 +9,5 @@ - + 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 bf8cf5a86..cff1bd4fa 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 @@ -33,4 +33,26 @@ column="company_user" /> + + + + + 100 + + + + + + + + + org.libreplan.business.externalcompanies.entities.ComunicationType + + + + + + + + diff --git a/libreplan-business/src/test/java/org/libreplan/business/test/externalcompanies/daos/CustomerComunicationDAOTest.java b/libreplan-business/src/test/java/org/libreplan/business/test/externalcompanies/daos/CustomerComunicationDAOTest.java new file mode 100644 index 000000000..59237cdec --- /dev/null +++ b/libreplan-business/src/test/java/org/libreplan/business/test/externalcompanies/daos/CustomerComunicationDAOTest.java @@ -0,0 +1,145 @@ +/* + * This file is part of NavalPlan + * + * Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e + * Desenvolvemento Tecnolóxico de Galicia + * Copyright (C) 2010-2011 Igalia, 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.test.externalcompanies.daos; + +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertNotNull; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.fail; +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.List; +import java.util.UUID; + +import org.joda.time.LocalDate; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.libreplan.business.calendars.daos.IBaseCalendarDAO; +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.InstanceNotFoundException; +import org.libreplan.business.common.exceptions.ValidationException; +import org.libreplan.business.externalcompanies.daos.ICustomerComunicationDAO; +import org.libreplan.business.externalcompanies.entities.CustomerComunication; +import org.libreplan.business.externalcompanies.entities.ExternalCompany; +import org.libreplan.business.orders.daos.IOrderDAO; +import org.libreplan.business.orders.entities.Order; +import org.libreplan.business.scenarios.IScenarioManager; +import org.libreplan.business.test.calendars.entities.BaseCalendarTest; +import org.libreplan.business.workreports.entities.WorkReportLine; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.transaction.annotation.Transactional; +import static org.junit.Assert.assertTrue; + +/** + * Tests for {@link CustomerComunication} + * + * @author Susana Montes Pedreira + */ +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations = { BUSINESS_SPRING_CONFIG_FILE, + BUSINESS_SPRING_CONFIG_TEST_FILE }) +@Transactional +public class CustomerComunicationDAOTest { + + @Autowired + ICustomerComunicationDAO customerComunicationDAO; + + @Autowired + IOrderDAO orderDAO; + + @Autowired + private IBaseCalendarDAO calendarDAO; + + public Order createValidOrder(String name) { + Order order = Order.create(); + order.setName(name); + order.setCode(UUID.randomUUID().toString()); + order.setInitDate(new Date()); + BaseCalendar basicCalendar = BaseCalendarTest.createBasicCalendar(); + calendarDAO.save(basicCalendar); + order.setCalendar(basicCalendar); + orderDAO.save(order); + return order; + } + + private Date givenDeadLine(int months) { + LocalDate date = new LocalDate(); + date.plusMonths(months); + return date.toDateTimeAtStartOfDay().toDate(); + } + + public CustomerComunication createValidCustomerComunication() { + Order order = createValidOrder("Order A"); + CustomerComunication customerComunication = CustomerComunication + .createTodayNewProject(givenDeadLine(2)); + customerComunication.setOrder(order); + return customerComunication; + } + + @Test + public void testOrderDAOInSpringContainer() { + assertNotNull(orderDAO); + } + + @Test + public void testCustomerComunicationDAOInSpringContainer() { + assertNotNull(customerComunicationDAO); + } + + @Test + public void testSaveCustomerComunication() { + CustomerComunication customerComunication = createValidCustomerComunication(); + customerComunicationDAO.save(customerComunication); + assertTrue(customerComunication.getId() != null); + } + + @Test + public void testRemoveCustomerComunication() + throws InstanceNotFoundException { + CustomerComunication customerComunication = createValidCustomerComunication(); + customerComunicationDAO.save(customerComunication); + assertTrue(customerComunication.getId() != null); + customerComunicationDAO.remove(customerComunication.getId()); + assertFalse(customerComunicationDAO + .exists(customerComunication.getId())); + } + + @Test + public void testSaveCustomerComunicationWithoutOrder() + throws InstanceNotFoundException { + CustomerComunication customerComunication = createValidCustomerComunication(); + customerComunication.setOrder(null); + try { + customerComunicationDAO.save(customerComunication); + fail("It should throw an exception"); + } catch (ValidationException e) { + // Ok + } + } + +}