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
This commit is contained in:
parent
e4a49d8fed
commit
b0340bf8a1
8 changed files with 447 additions and 1 deletions
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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 <smontes@wirelessgalicia.com>
|
||||
*/
|
||||
@Repository
|
||||
@Scope(BeanDefinition.SCOPE_SINGLETON)
|
||||
public class CustomerComunicationDAO extends GenericDAOHibernate<CustomerComunication, Long>
|
||||
implements ICustomerComunicationDAO {
|
||||
|
||||
@Override
|
||||
public List<CustomerComunication> getAll(){
|
||||
return list(CustomerComunication.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CustomerComunication> getAllNotReviewed(){
|
||||
Criteria c = getSession().createCriteria(CustomerComunication.class);
|
||||
c.add(Restrictions.eq("reviewed", false));
|
||||
return c.list();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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 <smontes@wirelessgalicia.com>
|
||||
*/
|
||||
public interface ICustomerComunicationDAO extends IGenericDAO<CustomerComunication, Long> {
|
||||
|
||||
List<CustomerComunication> getAll();
|
||||
|
||||
List<CustomerComunication> getAllNotReviewed();
|
||||
|
||||
}
|
||||
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.libreplan.business.externalcompanies.entities;
|
||||
|
||||
/**
|
||||
* Enum for specified the type of {@link CustomerComunication}
|
||||
*
|
||||
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
|
||||
*/
|
||||
public enum ComunicationType {
|
||||
New_Project
|
||||
}
|
||||
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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 <smontes@wirelessgalicia.com>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
21
libreplan-business/src/main/resources/db.changelog-1.2.xml
Normal file
21
libreplan-business/src/main/resources/db.changelog-1.2.xml
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
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">
|
||||
<constraints nullable="false" primaryKey="true" primaryKeyName="customer_comunication_pkey"/>
|
||||
</column>
|
||||
<column name="version" type="BIGINT">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="deadline" type="DATETIME"/>
|
||||
<column name="comunication_type" type="INTEGER"/>
|
||||
<column name="comunication_date" type="DATETIME"/>
|
||||
<column name="reviewed" type="BOOLEAN"/>
|
||||
<column name="order_id" type="BIGINT"/>
|
||||
</createTable>
|
||||
</changeSet>
|
||||
</databaseChangeLog>
|
||||
|
|
@ -9,5 +9,5 @@
|
|||
<include file="src/main/resources/db.changelog-initial.xml"/>
|
||||
<include file="src/main/resources/db.changelog-1.0.xml"/>
|
||||
<include file="src/main/resources/db.changelog-1.1.xml"/>
|
||||
|
||||
<include file="src/main/resources/db.changelog-1.2.xml"/>
|
||||
</databaseChangeLog>
|
||||
|
|
|
|||
|
|
@ -33,4 +33,26 @@
|
|||
column="company_user" />
|
||||
</class>
|
||||
|
||||
<!-- CustomerComunication -->
|
||||
<class name="CustomerComunication" table="customer_comunication">
|
||||
<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="deadline" access="field"/>
|
||||
<property name="comunicationType" access="field" column="comunication_type">
|
||||
<type name="org.hibernate.type.EnumType">
|
||||
<param name="enumClass">
|
||||
org.libreplan.business.externalcompanies.entities.ComunicationType
|
||||
</param>
|
||||
</type>
|
||||
</property>
|
||||
<property name="comunicationDate" access="field" column="comunication_date" />
|
||||
<property name="reviewed" access="field" column="reviewed" />
|
||||
<many-to-one name="order" class="org.libreplan.business.orders.entities.Order" column="order_id" />
|
||||
</class>
|
||||
|
||||
</hibernate-mapping>
|
||||
|
|
|
|||
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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 <smontes@wirelessgalicia.com>
|
||||
*/
|
||||
@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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue