ItEr51S11RFInfraestucturaEscenariosItEr50S14: Basic entities for scenarios.
Creates a predefined Scenario called "master". All current orders will be associated with this Scenario.
This commit is contained in:
parent
2ce50f4713
commit
2bbfdc2d12
15 changed files with 760 additions and 0 deletions
|
|
@ -43,6 +43,7 @@ import org.navalplanner.business.resources.daos.ICriterionTypeDAO;
|
|||
import org.navalplanner.business.resources.daos.IMachineDAO;
|
||||
import org.navalplanner.business.resources.daos.IResourceDAO;
|
||||
import org.navalplanner.business.resources.daos.IWorkerDAO;
|
||||
import org.navalplanner.business.scenarios.daos.IScenarioDAO;
|
||||
import org.navalplanner.business.templates.daos.IOrderElementTemplateDAO;
|
||||
import org.navalplanner.business.users.daos.IProfileDAO;
|
||||
import org.navalplanner.business.users.daos.IUserDAO;
|
||||
|
|
@ -157,6 +158,9 @@ public class Registry {
|
|||
@Autowired
|
||||
private ICalendarExceptionTypeDAO calendarExceptionTypeDAO;
|
||||
|
||||
@Autowired
|
||||
private IScenarioDAO scenarioDAO;
|
||||
|
||||
private Registry() {
|
||||
}
|
||||
|
||||
|
|
@ -282,4 +286,8 @@ public class Registry {
|
|||
return getInstance().calendarExceptionTypeDAO;
|
||||
}
|
||||
|
||||
public static IScenarioDAO getScenarioDAO() {
|
||||
return getInstance().scenarioDAO;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* This file is part of NavalPlan
|
||||
*
|
||||
* Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
|
||||
* Desenvolvemento Tecnolóxico de Galicia
|
||||
*
|
||||
* 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.navalplanner.business.scenarios.bootstrap;
|
||||
|
||||
import org.navalplanner.business.IDataBootstrap;
|
||||
|
||||
/**
|
||||
* Contratct for {@link ScenariosBootstrap}.
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
*/
|
||||
public interface IScenariosBootstrap extends IDataBootstrap {
|
||||
|
||||
void loadRequiredData();
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* This file is part of NavalPlan
|
||||
*
|
||||
* Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
|
||||
* Desenvolvemento Tecnolóxico de Galicia
|
||||
*
|
||||
* 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.navalplanner.business.scenarios.bootstrap;
|
||||
|
||||
import org.navalplanner.business.common.Registry;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.scenarios.entities.Scenario;
|
||||
|
||||
/**
|
||||
* Defines the default {@link Scenario}.
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
*/
|
||||
public enum PredefinedScenarios {
|
||||
|
||||
MASTER("master");
|
||||
|
||||
private final String name;
|
||||
|
||||
private PredefinedScenarios(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Scenario createScenario() {
|
||||
return Scenario.create(name);
|
||||
}
|
||||
|
||||
public Scenario getScenario() {
|
||||
try {
|
||||
return Registry.getScenarioDAO().findByName(name);
|
||||
} catch (InstanceNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* This file is part of NavalPlan
|
||||
*
|
||||
* Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
|
||||
* Desenvolvemento Tecnolóxico de Galicia
|
||||
*
|
||||
* 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.navalplanner.business.scenarios.bootstrap;
|
||||
|
||||
import org.navalplanner.business.orders.daos.IOrderDAO;
|
||||
import org.navalplanner.business.orders.entities.Order;
|
||||
import org.navalplanner.business.scenarios.daos.IScenarioDAO;
|
||||
import org.navalplanner.business.scenarios.entities.Scenario;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* Creates the default {@link Scenario}.
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
*/
|
||||
@Component
|
||||
@Scope("singleton")
|
||||
public class ScenariosBootstrap implements IScenariosBootstrap {
|
||||
|
||||
@Autowired
|
||||
private IScenarioDAO scenarioDAO;
|
||||
|
||||
@Autowired
|
||||
private IOrderDAO orderDAO;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void loadRequiredData() {
|
||||
for (PredefinedScenarios predefinedScenario : PredefinedScenarios
|
||||
.values()) {
|
||||
if (!scenarioDAO.existsByNameAnotherTransaction(predefinedScenario
|
||||
.getName())) {
|
||||
createAtDB(predefinedScenario);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void createAtDB(PredefinedScenarios predefinedScenario) {
|
||||
Scenario scenario = predefinedScenario.createScenario();
|
||||
for (Order each : orderDAO.getOrders()) {
|
||||
scenario.addOrder(each);
|
||||
}
|
||||
scenarioDAO.save(scenario);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* This file is part of NavalPlan
|
||||
*
|
||||
* Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
|
||||
* Desenvolvemento Tecnolóxico de Galicia
|
||||
*
|
||||
* 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.navalplanner.business.scenarios.daos;
|
||||
|
||||
import org.navalplanner.business.common.daos.IGenericDAO;
|
||||
import org.navalplanner.business.scenarios.entities.OrderVersion;
|
||||
|
||||
/**
|
||||
* Contract for {@link OrderVersionDAO}.
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
*/
|
||||
public interface IOrderVersionDAO extends IGenericDAO<OrderVersion, Long> {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* This file is part of NavalPlan
|
||||
*
|
||||
* Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
|
||||
* Desenvolvemento Tecnolóxico de Galicia
|
||||
*
|
||||
* 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.navalplanner.business.scenarios.daos;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.navalplanner.business.common.daos.IGenericDAO;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.scenarios.entities.Scenario;
|
||||
|
||||
/**
|
||||
* Contract for {@link ScenarioDAO}.
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
*/
|
||||
public interface IScenarioDAO extends IGenericDAO<Scenario, Long> {
|
||||
|
||||
Scenario findByName(String name) throws InstanceNotFoundException;
|
||||
|
||||
boolean existsByName(String name);
|
||||
|
||||
boolean existsByNameAnotherTransaction(String name);
|
||||
|
||||
List<Scenario> getAll();
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* This file is part of NavalPlan
|
||||
*
|
||||
* Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
|
||||
* Desenvolvemento Tecnolóxico de Galicia
|
||||
*
|
||||
* 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.navalplanner.business.scenarios.daos;
|
||||
|
||||
import org.navalplanner.business.common.daos.GenericDAOHibernate;
|
||||
import org.navalplanner.business.scenarios.entities.OrderVersion;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* DAO implementation for {@link OrderVersion}.
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
*/
|
||||
@Repository
|
||||
@Scope(BeanDefinition.SCOPE_SINGLETON)
|
||||
public class OrderVersionDAO extends GenericDAOHibernate<OrderVersion, Long>
|
||||
implements IOrderVersionDAO {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,118 @@
|
|||
/*
|
||||
* This file is part of NavalPlan
|
||||
*
|
||||
* Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
|
||||
* Desenvolvemento Tecnolóxico de Galicia
|
||||
*
|
||||
* 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.navalplanner.business.scenarios.daos;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
import org.navalplanner.business.common.daos.GenericDAOHibernate;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.common.exceptions.ValidationException;
|
||||
import org.navalplanner.business.scenarios.entities.OrderVersion;
|
||||
import org.navalplanner.business.scenarios.entities.Scenario;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* DAO implementation for {@link Scenario}.
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
*/
|
||||
@Repository
|
||||
@Scope(BeanDefinition.SCOPE_SINGLETON)
|
||||
public class ScenarioDAO extends GenericDAOHibernate<Scenario, Long> implements
|
||||
IScenarioDAO {
|
||||
|
||||
@Autowired
|
||||
private IOrderVersionDAO orderVersionDAO;
|
||||
|
||||
@Override
|
||||
public void save(Scenario scenario) throws ValidationException {
|
||||
saveNewlyAddedOrderVersionsFor(scenario);
|
||||
super.save(scenario);
|
||||
}
|
||||
|
||||
private void saveNewlyAddedOrderVersionsFor(Scenario scenario) {
|
||||
List<OrderVersion> newOrders = getNewOrders(scenario);
|
||||
for (OrderVersion each : newOrders) {
|
||||
orderVersionDAO.save(each);
|
||||
}
|
||||
}
|
||||
|
||||
private List<OrderVersion> getNewOrders(Scenario scenario) {
|
||||
Collection<OrderVersion> values = scenario.getOrders().values();
|
||||
List<OrderVersion> newOrders = new ArrayList<OrderVersion>();
|
||||
for (OrderVersion each : values) {
|
||||
if (each.isNewObject()) {
|
||||
newOrders.add(each);
|
||||
}
|
||||
}
|
||||
return newOrders;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Scenario findByName(String name) throws InstanceNotFoundException {
|
||||
if (StringUtils.isBlank(name)) {
|
||||
throw new InstanceNotFoundException(null, Scenario.class.getName());
|
||||
}
|
||||
|
||||
Scenario scenario = (Scenario) getSession().createCriteria(
|
||||
Scenario.class).add(
|
||||
Restrictions.eq("name", name.trim()).ignoreCase())
|
||||
.uniqueResult();
|
||||
|
||||
if (scenario == null) {
|
||||
throw new InstanceNotFoundException(name, Scenario.class.getName());
|
||||
} else {
|
||||
return scenario;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean existsByName(String name) {
|
||||
try {
|
||||
findByName(name);
|
||||
return true;
|
||||
} catch (InstanceNotFoundException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true, propagation = Propagation.REQUIRES_NEW)
|
||||
public boolean existsByNameAnotherTransaction(String name) {
|
||||
return existsByName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Scenario> getAll() {
|
||||
return list(Scenario.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* This file is part of NavalPlan
|
||||
*
|
||||
* Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
|
||||
* Desenvolvemento Tecnolóxico de Galicia
|
||||
*
|
||||
* 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.navalplanner.business.scenarios.entities;
|
||||
|
||||
import org.navalplanner.business.common.BaseEntity;
|
||||
import org.navalplanner.business.orders.entities.Order;
|
||||
|
||||
/**
|
||||
* Version of an {@link Order} used in some {@link Scenario}.
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
*/
|
||||
public class OrderVersion extends BaseEntity {
|
||||
|
||||
public static OrderVersion createInitialVersion() {
|
||||
return create(new OrderVersion());
|
||||
}
|
||||
|
||||
// Default constructor, needed by Hibernate
|
||||
protected OrderVersion() {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,118 @@
|
|||
/*
|
||||
* This file is part of NavalPlan
|
||||
*
|
||||
* Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
|
||||
* Desenvolvemento Tecnolóxico de Galicia
|
||||
*
|
||||
* 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.navalplanner.business.scenarios.entities;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.hibernate.validator.AssertTrue;
|
||||
import org.hibernate.validator.NotEmpty;
|
||||
import org.navalplanner.business.common.BaseEntity;
|
||||
import org.navalplanner.business.common.Registry;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.orders.entities.Order;
|
||||
import org.navalplanner.business.scenarios.daos.IScenarioDAO;
|
||||
|
||||
/**
|
||||
* Represents a scenario in the application.
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
*/
|
||||
public class Scenario extends BaseEntity {
|
||||
|
||||
private String name;
|
||||
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* For each order tracked by this Scenario exists an OrderVersion that will
|
||||
* have specific data for that order
|
||||
*/
|
||||
private Map<Order, OrderVersion> orders = new HashMap<Order, OrderVersion>();
|
||||
|
||||
public static Scenario create(String name) {
|
||||
return create(new Scenario(name));
|
||||
}
|
||||
|
||||
// Default constructor, needed by Hibernate
|
||||
protected Scenario() {
|
||||
}
|
||||
|
||||
public Map<Order, OrderVersion> getOrders() {
|
||||
return Collections.unmodifiableMap(orders);
|
||||
}
|
||||
|
||||
private Scenario(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void addOrder(Order order) {
|
||||
if (!orders.values().contains(order)) {
|
||||
orders.put(order, OrderVersion.createInitialVersion());
|
||||
}
|
||||
}
|
||||
|
||||
public Set<Order> getTrackedOrders() {
|
||||
return Collections.unmodifiableSet(orders.keySet());
|
||||
}
|
||||
|
||||
@NotEmpty(message = "name not specified")
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@AssertTrue(message = "name is already used")
|
||||
public boolean checkConstraintUniqueName() {
|
||||
if (StringUtils.isBlank(name)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
IScenarioDAO scenarioDAO = Registry.getScenarioDAO();
|
||||
|
||||
if (isNewObject()) {
|
||||
return !scenarioDAO.existsByNameAnotherTransaction(
|
||||
name);
|
||||
} else {
|
||||
try {
|
||||
Scenario scenario = scenarioDAO.findByName(name);
|
||||
return scenario.getId().equals(getId());
|
||||
} catch (InstanceNotFoundException e) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -76,6 +76,9 @@
|
|||
<value>
|
||||
org/navalplanner/business/externalcompanies/entities/ExternalCompanies.hbm.xml
|
||||
</value>
|
||||
<value>
|
||||
org/navalplanner/business/scenarios/entities/Scenarios.hbm.xml
|
||||
</value>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,36 @@
|
|||
<?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.navalplanner.business.scenarios.entities"
|
||||
default-access="field">
|
||||
|
||||
<!-- Scenario -->
|
||||
<class name="Scenario">
|
||||
<id name="id" access="property" type="long">
|
||||
<generator class="hilo">
|
||||
<param name="max_lo">100</param>
|
||||
</generator>
|
||||
</id>
|
||||
<version name="version" access="property" type="long" />
|
||||
|
||||
<property name="name" />
|
||||
<property name="description" />
|
||||
<map name="orders" table="SCENARIO_ORDERS">
|
||||
<key column="SCENARIO_ID" />
|
||||
<map-key-many-to-many column="ORDER_ID"
|
||||
class="org.navalplanner.business.orders.entities.Order" />
|
||||
<many-to-many column="ORDER_VERSION_ID" class="OrderVersion"/>
|
||||
</map>
|
||||
|
||||
</class>
|
||||
|
||||
<!-- OrderVersion -->
|
||||
<class name="OrderVersion">
|
||||
<id name="id" access="property" type="long">
|
||||
<generator class="hilo">
|
||||
<param name="max_lo">100</param>
|
||||
</generator>
|
||||
</id>
|
||||
<version name="version" access="property" type="long" />
|
||||
</class>
|
||||
|
||||
</hibernate-mapping>
|
||||
|
|
@ -0,0 +1,156 @@
|
|||
/*
|
||||
* This file is part of NavalPlan
|
||||
*
|
||||
* Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
|
||||
* Desenvolvemento Tecnolóxico de Galicia
|
||||
*
|
||||
* 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.navalplanner.business.test.scenarios.bootstrap;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.navalplanner.business.BusinessGlobalNames.BUSINESS_SPRING_CONFIG_FILE;
|
||||
import static org.navalplanner.business.test.BusinessGlobalNames.BUSINESS_SPRING_CONFIG_TEST_FILE;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.navalplanner.business.IDataBootstrap;
|
||||
import org.navalplanner.business.common.IAdHocTransactionService;
|
||||
import org.navalplanner.business.common.IOnTransaction;
|
||||
import org.navalplanner.business.common.daos.IConfigurationDAO;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.orders.daos.IOrderDAO;
|
||||
import org.navalplanner.business.orders.entities.Order;
|
||||
import org.navalplanner.business.scenarios.bootstrap.IScenariosBootstrap;
|
||||
import org.navalplanner.business.scenarios.bootstrap.PredefinedScenarios;
|
||||
import org.navalplanner.business.scenarios.daos.IScenarioDAO;
|
||||
import org.navalplanner.business.scenarios.entities.Scenario;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.annotation.NotTransactional;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { BUSINESS_SPRING_CONFIG_FILE,
|
||||
BUSINESS_SPRING_CONFIG_TEST_FILE })
|
||||
@Transactional
|
||||
public class ScenariosBootstrapTest {
|
||||
|
||||
@Autowired
|
||||
private IScenariosBootstrap scenariosBootstrap;
|
||||
|
||||
@Autowired
|
||||
private IScenarioDAO scenarioDAO;
|
||||
|
||||
@Autowired
|
||||
private IOrderDAO orderDAO;
|
||||
|
||||
@Autowired
|
||||
private IAdHocTransactionService transactionService;
|
||||
|
||||
@Autowired
|
||||
private IConfigurationDAO configurationDAO;
|
||||
|
||||
@Resource
|
||||
private IDataBootstrap defaultAdvanceTypesBootstrapListener;
|
||||
|
||||
@Resource
|
||||
private IDataBootstrap configurationBootstrap;
|
||||
|
||||
@Before
|
||||
public void loadRequiredaData() {
|
||||
defaultAdvanceTypesBootstrapListener.loadRequiredData();
|
||||
configurationBootstrap.loadRequiredData();
|
||||
}
|
||||
|
||||
private void removeCurrentScenarios() {
|
||||
for (Scenario scenario : scenarioDAO.getAll()) {
|
||||
try {
|
||||
scenarioDAO.remove(scenario.getId());
|
||||
} catch (InstanceNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Order givenOrderStored() {
|
||||
Order order = Order.create();
|
||||
order.setInitDate(new Date());
|
||||
order.setName("name-" + UUID.randomUUID().toString());
|
||||
order.setCode("code-" + UUID.randomUUID().toString());
|
||||
order.setCalendar(configurationDAO.getConfiguration()
|
||||
.getDefaultCalendar());
|
||||
orderDAO.save(order);
|
||||
return order;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadBasicData() throws InstanceNotFoundException {
|
||||
removeCurrentScenarios();
|
||||
scenariosBootstrap.loadRequiredData();
|
||||
|
||||
assertFalse(scenarioDAO.getAll().isEmpty());
|
||||
assertNotNull(scenarioDAO.findByName(PredefinedScenarios.MASTER
|
||||
.getName()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@NotTransactional
|
||||
public void loadBasicDataAssociatedWithCurrentOrders()
|
||||
throws InstanceNotFoundException {
|
||||
final Order orderAssociated = transactionService
|
||||
.runOnAnotherTransaction(new IOnTransaction<Order>() {
|
||||
|
||||
@Override
|
||||
public Order execute() {
|
||||
removeCurrentScenarios();
|
||||
Order order = givenOrderStored();
|
||||
scenariosBootstrap.loadRequiredData();
|
||||
return order;
|
||||
}
|
||||
});
|
||||
transactionService.runOnAnotherTransaction(new IOnTransaction<Void>() {
|
||||
|
||||
@Override
|
||||
public Void execute() {
|
||||
assertFalse(scenarioDAO.getAll().isEmpty());
|
||||
Scenario scenario = PredefinedScenarios.MASTER.getScenario();
|
||||
assertNotNull(scenario);
|
||||
assertTrue(isAt(orderAssociated, scenario.getTrackedOrders()));
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean isAt(Order orderAssociated, Set<Order> trackedOrders) {
|
||||
for (Order each : trackedOrders) {
|
||||
if (each.getId().equals(orderAssociated.getId())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -84,6 +84,9 @@
|
|||
<value>
|
||||
org/navalplanner/business/externalcompanies/entities/ExternalCompanies.hbm.xml
|
||||
</value>
|
||||
<value>
|
||||
org/navalplanner/business/scenarios/entities/Scenarios.hbm.xml
|
||||
</value>
|
||||
</list>
|
||||
</property>
|
||||
|
||||
|
|
|
|||
|
|
@ -81,6 +81,9 @@
|
|||
<value>
|
||||
org/navalplanner/business/externalcompanies/entities/ExternalCompanies.hbm.xml
|
||||
</value>
|
||||
<value>
|
||||
org/navalplanner/business/scenarios/entities/Scenarios.hbm.xml
|
||||
</value>
|
||||
</list>
|
||||
</property>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue