Create the entity SubcontractorComunication, the dao SubcontractorComunicationDAO,
the test SubcontractorComunicationDAOTest and add the changes of the database in a new file db.changelog-1.2.xml FEA: ItEr75S30SubcontractorIncommingCommunicationsLists
This commit is contained in:
parent
c0a3ec1392
commit
d9d482bdeb
10 changed files with 651 additions and 0 deletions
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* This file is part of LibrePlan
|
||||
*
|
||||
* 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.planner.daos;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.libreplan.business.common.daos.IGenericDAO;
|
||||
import org.libreplan.business.planner.entities.SubcontractorComunication;
|
||||
|
||||
public interface ISubcontractorComunicationDAO extends IGenericDAO<SubcontractorComunication, Long> {
|
||||
|
||||
List<SubcontractorComunication> getAll();
|
||||
|
||||
List<SubcontractorComunication> getAllNotReviewed();
|
||||
}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* This file is part of LibrePlan
|
||||
*
|
||||
* 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.planner.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.planner.entities.SubcontractorComunication;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* DAO for {@link SubcontractorComunication}
|
||||
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
|
||||
*/
|
||||
|
||||
@Repository
|
||||
@Scope(BeanDefinition.SCOPE_SINGLETON)
|
||||
public class SubcontractorComunicationDAO extends GenericDAOHibernate<SubcontractorComunication, Long>
|
||||
implements ISubcontractorComunicationDAO {
|
||||
|
||||
@Override
|
||||
public List<SubcontractorComunication> getAll() {
|
||||
return list(SubcontractorComunication.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SubcontractorComunication> getAllNotReviewed(){
|
||||
Criteria c = getSession().createCriteria(SubcontractorComunication.class);
|
||||
c.add(Restrictions.eq("reviewed", false));
|
||||
return c.list();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,127 @@
|
|||
/*
|
||||
* This file is part of LibrePlan
|
||||
*
|
||||
* 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.planner.entities;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.validator.NotNull;
|
||||
import org.libreplan.business.common.BaseEntity;
|
||||
import org.libreplan.business.externalcompanies.entities.ComunicationType;
|
||||
import org.libreplan.business.qualityforms.entities.QualityFormItem;
|
||||
|
||||
/**
|
||||
* Entity {@link SubcontractorComunication}.
|
||||
*
|
||||
* @author Susana Montes Pedreira <smontes@wirelessgalicia>
|
||||
*/
|
||||
public class SubcontractorComunication extends BaseEntity {
|
||||
|
||||
private SubcontractedTaskData subcontractedTaskData;
|
||||
|
||||
private ComunicationType comunicationType;
|
||||
|
||||
private Date comunicationDate;
|
||||
|
||||
private Boolean reviewed = false;
|
||||
|
||||
private List<SubcontractorComunicationValue> subcontratorComunicationValues = new ArrayList<SubcontractorComunicationValue>();
|
||||
|
||||
// Default constructor, needed by Hibernate
|
||||
protected SubcontractorComunication() {
|
||||
|
||||
}
|
||||
|
||||
private SubcontractorComunication ( SubcontractedTaskData subcontractedTaskData, ComunicationType comunicationType, Date comunicationDate, Boolean reviewed){
|
||||
this.setSubcontractedTaskData(subcontractedTaskData);
|
||||
this.setComunicationType(comunicationType);
|
||||
this.setComunicationDate(comunicationDate);
|
||||
this.setReviewed(reviewed);
|
||||
}
|
||||
|
||||
public static SubcontractorComunication create(
|
||||
SubcontractedTaskData subcontractedTaskData,
|
||||
ComunicationType comunicationType, Date comunicationDate,
|
||||
Boolean reviewed) {
|
||||
return new SubcontractorComunication(subcontractedTaskData,
|
||||
comunicationType, comunicationDate, reviewed);
|
||||
}
|
||||
|
||||
public static SubcontractorComunication create() {
|
||||
return new SubcontractorComunication();
|
||||
}
|
||||
|
||||
public void setSubcontractedTaskData(SubcontractedTaskData subcontractedTaskData) {
|
||||
this.subcontractedTaskData = subcontractedTaskData;
|
||||
}
|
||||
|
||||
@NotNull(message="subcontrated task data not specified")
|
||||
public SubcontractedTaskData getSubcontractedTaskData() {
|
||||
return subcontractedTaskData;
|
||||
}
|
||||
|
||||
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 setSubcontratorComunicationValues(
|
||||
List<SubcontractorComunicationValue> subcontratorComunicationValues) {
|
||||
this.subcontratorComunicationValues = subcontratorComunicationValues;
|
||||
}
|
||||
|
||||
public List<SubcontractorComunicationValue> getSubcontratorComunicationValues() {
|
||||
return subcontratorComunicationValues;
|
||||
}
|
||||
|
||||
public SubcontractorComunicationValue getLastSubcontratorComunicationValues(){
|
||||
if (subcontratorComunicationValues.isEmpty()){
|
||||
return null;
|
||||
}
|
||||
return subcontratorComunicationValues.get(subcontratorComunicationValues.size()-1);
|
||||
}
|
||||
|
||||
public Date getLastSubcontratorComunicationValueDate(){
|
||||
SubcontractorComunicationValue value = getLastSubcontratorComunicationValues();
|
||||
return (value == null) ? null : value.getDate();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
* 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.planner.entities;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import org.hibernate.validator.AssertTrue;
|
||||
import org.libreplan.business.INewObject;
|
||||
|
||||
/**
|
||||
* Entity to represent each {@SubcontractorComunicationValue}.
|
||||
*
|
||||
* @author Susana Montes Pedreira <smontes@wirelessgalicia>
|
||||
*/
|
||||
public class SubcontractorComunicationValue implements INewObject {
|
||||
|
||||
public final static String propertyDate = "date";
|
||||
|
||||
public final static String propertyProgress = "progress";
|
||||
|
||||
public static SubcontractorComunicationValue create() {
|
||||
SubcontractorComunicationValue subcontractorComunicationValue = new SubcontractorComunicationValue();
|
||||
subcontractorComunicationValue.setNewObject(true);
|
||||
return subcontractorComunicationValue;
|
||||
}
|
||||
|
||||
public static SubcontractorComunicationValue create(Date date,
|
||||
BigDecimal progress) {
|
||||
SubcontractorComunicationValue subcontractorComunicationValue = new SubcontractorComunicationValue(
|
||||
date, progress);
|
||||
subcontractorComunicationValue.setNewObject(true);
|
||||
return subcontractorComunicationValue;
|
||||
}
|
||||
|
||||
public SubcontractorComunicationValue() {
|
||||
|
||||
}
|
||||
|
||||
public SubcontractorComunicationValue(Date date, BigDecimal progress) {
|
||||
this.setDate(date);
|
||||
this.setProgress(progress);
|
||||
}
|
||||
|
||||
private boolean newObject = false;
|
||||
|
||||
private Date date;
|
||||
|
||||
private BigDecimal progress;
|
||||
|
||||
public boolean isNewObject() {
|
||||
return newObject;
|
||||
}
|
||||
|
||||
private void setNewObject(boolean newObject) {
|
||||
this.newObject = newObject;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@AssertTrue(message = "progress should be greater than 0% and less than 100%")
|
||||
public boolean checkConstraintQualityFormItemPercentage() {
|
||||
if (getProgress() == null) {
|
||||
return true;
|
||||
}
|
||||
return ((getProgress().compareTo(new BigDecimal(100).setScale(2)) <= 0) && (getProgress()
|
||||
.compareTo(new BigDecimal(0).setScale(2)) > 0));
|
||||
}
|
||||
|
||||
public void setDate(Date date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public Date getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setProgress(BigDecimal progress) {
|
||||
this.progress = progress;
|
||||
}
|
||||
|
||||
public BigDecimal getProgress() {
|
||||
return progress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String datetime = (date == null) ? "" : new SimpleDateFormat(
|
||||
"dd/MM/yyyy HH:mm").format(date);
|
||||
return progress.toString() + " - " + datetime;
|
||||
}
|
||||
}
|
||||
|
|
@ -18,4 +18,31 @@
|
|||
<column name="order_id" type="BIGINT"/>
|
||||
</createTable>
|
||||
</changeSet>
|
||||
<changeSet author="smontes" id="initial-database-creation-subcontractor-comunication">
|
||||
<createTable tableName="subcontractor_comunication">
|
||||
<column name="id" type="BIGINT">
|
||||
<constraints nullable="false" primaryKey="true" primaryKeyName="subcontractor_comunication_pkey"/>
|
||||
</column>
|
||||
<column name="version" type="BIGINT">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="comunication_type" type="INTEGER"/>
|
||||
<column name="comunication_date" type="DATETIME"/>
|
||||
<column name="reviewed" type="BOOLEAN"/>
|
||||
<column name="subcontracted_task_data" type="BIGINT"/>
|
||||
</createTable>
|
||||
</changeSet>
|
||||
<changeSet author="smontes" id="initial-database-creation-subcontractor-comunication-value">
|
||||
<createTable tableName="subcontrator_comunication_values">
|
||||
<column name="subcontractor_comunication_id" type="BIGINT">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="date" type="DATETIME"/>
|
||||
<column name="progress" type="DECIMAL(19,2)"/>
|
||||
<column name="idx" type="INTEGER">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
</createTable>
|
||||
</changeSet>
|
||||
|
||||
</databaseChangeLog>
|
||||
|
|
@ -81,6 +81,9 @@
|
|||
<value>
|
||||
org/libreplan/business/planner/entities/AdvanceConsolidations.hbm.xml
|
||||
</value>
|
||||
<value>
|
||||
org/libreplan/business/planner/entities/SubcontractorComunication.hbm.xml
|
||||
</value>
|
||||
<value>
|
||||
org/libreplan/business/scenarios/entities/Scenarios.hbm.xml
|
||||
</value>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,34 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
|
||||
<hibernate-mapping package="org.libreplan.business.planner.entities" default-access="field">
|
||||
|
||||
<!-- SubcontractorComunication -->
|
||||
<class name="SubcontractorComunication" table="subcontractor_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="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="subcontractedTaskData" class="org.libreplan.business.planner.entities.SubcontractedTaskData" column="Subcontracted_task_data" />
|
||||
|
||||
<list name="subcontratorComunicationValues" table="subcontrator_comunication_values">
|
||||
<key column="subcontractor_comunication_id"/>
|
||||
<index column="idx"/>
|
||||
<composite-element class="org.libreplan.business.planner.entities.SubcontractorComunicationValue">
|
||||
<property name="date" access="field"/>
|
||||
<property name="progress" access="field"/>
|
||||
</composite-element>
|
||||
</list>
|
||||
</class>
|
||||
|
||||
</hibernate-mapping>
|
||||
|
|
@ -0,0 +1,254 @@
|
|||
/*
|
||||
* 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.planner.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.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.junit.Before;
|
||||
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.daos.IConfigurationDAO;
|
||||
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.daos.IExternalCompanyDAO;
|
||||
import org.libreplan.business.externalcompanies.entities.ComunicationType;
|
||||
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.HoursGroup;
|
||||
import org.libreplan.business.orders.entities.Order;
|
||||
import org.libreplan.business.orders.entities.OrderLine;
|
||||
import org.libreplan.business.orders.entities.SchedulingDataForVersion;
|
||||
import org.libreplan.business.orders.entities.TaskSource;
|
||||
import org.libreplan.business.orders.entities.TaskSource.TaskSourceSynchronization;
|
||||
import org.libreplan.business.planner.daos.ISubcontractedTaskDataDAO;
|
||||
import org.libreplan.business.planner.daos.ISubcontractorComunicationDAO;
|
||||
import org.libreplan.business.planner.daos.ITaskElementDAO;
|
||||
import org.libreplan.business.planner.daos.ITaskSourceDAO;
|
||||
import org.libreplan.business.planner.entities.SubcontractedTaskData;
|
||||
import org.libreplan.business.planner.entities.SubcontractorComunication;
|
||||
import org.libreplan.business.planner.entities.Task;
|
||||
import org.libreplan.business.scenarios.IScenarioManager;
|
||||
import org.libreplan.business.scenarios.bootstrap.IScenariosBootstrap;
|
||||
import org.libreplan.business.scenarios.entities.OrderVersion;
|
||||
import org.libreplan.business.test.calendars.entities.BaseCalendarTest;
|
||||
import org.libreplan.business.test.externalcompanies.daos.ExternalCompanyDAOTest;
|
||||
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 SubcontractorComunication}
|
||||
*
|
||||
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { BUSINESS_SPRING_CONFIG_FILE,
|
||||
BUSINESS_SPRING_CONFIG_TEST_FILE })
|
||||
@Transactional
|
||||
public class SubcontractorComunicationDAOTest {
|
||||
|
||||
@Autowired
|
||||
ISubcontractorComunicationDAO subcontractorComunicationDAO;
|
||||
|
||||
@Autowired
|
||||
ISubcontractedTaskDataDAO subcontractedTaskDataDAO;
|
||||
|
||||
@Autowired
|
||||
IExternalCompanyDAO externalCompanyDAO;
|
||||
|
||||
@Autowired
|
||||
private ITaskElementDAO taskElementDAO;
|
||||
|
||||
@Autowired
|
||||
private IOrderDAO orderDAO;
|
||||
|
||||
@Autowired
|
||||
private ITaskSourceDAO taskSourceDAO;
|
||||
|
||||
@Autowired
|
||||
private SessionFactory sessionFactory;
|
||||
|
||||
@Autowired
|
||||
private IConfigurationDAO configurationDAO;
|
||||
|
||||
@Autowired
|
||||
private IScenarioManager scenarioManager;
|
||||
|
||||
@Autowired
|
||||
private IBaseCalendarDAO calendarDAO;
|
||||
|
||||
@Autowired
|
||||
private IScenariosBootstrap scenariosBootstrap;
|
||||
|
||||
@Before
|
||||
public void loadRequiredData() {
|
||||
scenariosBootstrap.loadRequiredData();
|
||||
}
|
||||
|
||||
private HoursGroup associatedHoursGroup;
|
||||
|
||||
private ExternalCompany getSubcontractorExternalCompanySaved() {
|
||||
ExternalCompany externalCompany = ExternalCompanyDAOTest
|
||||
.createValidExternalCompany();
|
||||
externalCompany.setSubcontractor(true);
|
||||
|
||||
externalCompanyDAO.save(externalCompany);
|
||||
externalCompanyDAO.flush();
|
||||
sessionFactory.getCurrentSession().evict(externalCompany);
|
||||
|
||||
externalCompany.dontPoseAsTransientObjectAnymore();
|
||||
|
||||
return externalCompany;
|
||||
}
|
||||
|
||||
private OrderLine createOrderLine() {
|
||||
OrderLine orderLine = OrderLine.create();
|
||||
orderLine.setName("bla");
|
||||
orderLine.setCode("code-" + UUID.randomUUID());
|
||||
HoursGroup hoursGroup = new HoursGroup();
|
||||
hoursGroup.setCode("hours-group-code-" + UUID.randomUUID());
|
||||
orderLine.addHoursGroup(hoursGroup);
|
||||
Order order = Order.create();
|
||||
OrderVersion orderVersion = ResourceAllocationDAOTest
|
||||
.setupVersionUsing(scenarioManager, order);
|
||||
order.setName("bla-" + UUID.randomUUID());
|
||||
order.setInitDate(new Date());
|
||||
order.setCode("code-" + UUID.randomUUID());
|
||||
order.useSchedulingDataFor(orderVersion);
|
||||
order.add(orderLine);
|
||||
|
||||
//add a basic calendar
|
||||
BaseCalendar basicCalendar = BaseCalendarTest.createBasicCalendar();
|
||||
calendarDAO.save(basicCalendar);
|
||||
order.setCalendar(basicCalendar);
|
||||
|
||||
try {
|
||||
orderDAO.save(order);
|
||||
sessionFactory.getCurrentSession().flush();
|
||||
} catch (ValidationException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return orderLine;
|
||||
}
|
||||
|
||||
private Task createValidTask() {
|
||||
associatedHoursGroup = new HoursGroup();
|
||||
associatedHoursGroup.setCode("hours-group-code-" + UUID.randomUUID());
|
||||
OrderLine orderLine = createOrderLine();
|
||||
orderLine.addHoursGroup(associatedHoursGroup);
|
||||
OrderVersion orderVersion = ResourceAllocationDAOTest
|
||||
.setupVersionUsing(scenarioManager,
|
||||
orderLine.getOrder());
|
||||
orderLine.useSchedulingDataFor(orderVersion);
|
||||
SchedulingDataForVersion schedulingDataForVersion = orderLine
|
||||
.getCurrentSchedulingDataForVersion();
|
||||
TaskSource taskSource = TaskSource.create(schedulingDataForVersion,
|
||||
Arrays.asList(associatedHoursGroup));
|
||||
TaskSourceSynchronization mustAdd = TaskSource.mustAdd(taskSource);
|
||||
mustAdd.apply(TaskSource.persistTaskSources(taskSourceDAO));
|
||||
Task task = (Task) taskSource.getTask();
|
||||
return task;
|
||||
}
|
||||
|
||||
public SubcontractedTaskData createValidSubcontractedTaskData(String name) {
|
||||
Task task = createValidTask();
|
||||
SubcontractedTaskData subcontractedTaskData = SubcontractedTaskData
|
||||
.create(task);
|
||||
subcontractedTaskData.setExternalCompany(getSubcontractorExternalCompanySaved());
|
||||
|
||||
task.setSubcontractedTaskData(subcontractedTaskData);
|
||||
taskElementDAO.save(task);
|
||||
taskElementDAO.flush();
|
||||
sessionFactory.getCurrentSession().evict(task);
|
||||
sessionFactory.getCurrentSession().evict(subcontractedTaskData);
|
||||
|
||||
subcontractedTaskDataDAO.save(subcontractedTaskData);
|
||||
return subcontractedTaskData;
|
||||
}
|
||||
|
||||
public SubcontractorComunication createValidSubcontractorComunication(){
|
||||
SubcontractedTaskData subcontractedTaskData = createValidSubcontractedTaskData("Task A");
|
||||
Date comunicationDate = new Date();
|
||||
SubcontractorComunication subcontractorComunication = SubcontractorComunication
|
||||
.create(subcontractedTaskData, ComunicationType.NEW_PROJECT,
|
||||
comunicationDate, false);
|
||||
return subcontractorComunication;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSubcontractorComunicationDAOInSpringContainer() {
|
||||
assertNotNull(subcontractorComunicationDAO);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveCustomerComunication() {
|
||||
SubcontractorComunication subcontractorComunication = createValidSubcontractorComunication();
|
||||
subcontractorComunicationDAO.save(subcontractorComunication);
|
||||
assertTrue(subcontractorComunication.getId() != null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveCustomerComunication()
|
||||
throws InstanceNotFoundException {
|
||||
SubcontractorComunication customerComunication = createValidSubcontractorComunication();
|
||||
subcontractorComunicationDAO.save(customerComunication);
|
||||
assertTrue(customerComunication.getId() != null);
|
||||
subcontractorComunicationDAO.remove(customerComunication.getId());
|
||||
assertFalse(subcontractorComunicationDAO
|
||||
.exists(customerComunication.getId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveCustomerComunicationWithoutSubcontratedTaskData()
|
||||
throws InstanceNotFoundException {
|
||||
SubcontractorComunication subcontractorComunication = createValidSubcontractorComunication();
|
||||
subcontractorComunication.setSubcontractedTaskData(null);
|
||||
try {
|
||||
subcontractorComunicationDAO.save(subcontractorComunication);
|
||||
fail("It should throw an exception");
|
||||
} catch (ValidationException e) {
|
||||
// Ok
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -87,6 +87,9 @@
|
|||
<value>
|
||||
org/libreplan/business/planner/entities/AdvanceConsolidations.hbm.xml
|
||||
</value>
|
||||
<value>
|
||||
org/libreplan/business/planner/entities/SubcontractorComunication.hbm.xml
|
||||
</value>
|
||||
<value>
|
||||
org/libreplan/business/scenarios/entities/Scenarios.hbm.xml
|
||||
</value>
|
||||
|
|
|
|||
|
|
@ -84,6 +84,9 @@
|
|||
<value>
|
||||
org/libreplan/business/planner/entities/AdvanceConsolidations.hbm.xml
|
||||
</value>
|
||||
<value>
|
||||
org/libreplan/business/planner/entities/SubcontractorComunication.hbm.xml
|
||||
</value>
|
||||
<value>
|
||||
org/libreplan/business/scenarios/entities/Scenarios.hbm.xml
|
||||
</value>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue