1 /*****************************************************************************
5 * Creation date 22.10.2012
8 * @copyright OPEN CASCADE 2012-2015
9 *****************************************************************************/
11 package org.splat.service;
13 import org.apache.commons.lang3.StringUtils;
14 import org.hibernate.criterion.Restrictions;
15 import org.splat.common.properties.MessageKeyEnum;
16 import org.splat.dal.bo.som.ProgressState;
17 import org.splat.dal.bo.som.SimulationContextType;
18 import org.splat.dal.dao.som.SimulationContextTypeDAO;
19 import org.splat.kernel.InvalidPropertyException;
20 import org.splat.log.AppLogger;
21 import org.splat.service.technical.ProjectSettingsService;
22 import org.springframework.transaction.annotation.Transactional;
25 * Simulation context type service implementation.
27 * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
29 public class SimulationContextTypeServiceImpl implements
30 SimulationContextTypeService {
33 * The logger for the service.
35 public final static AppLogger LOG = AppLogger
36 .getLogger(SimulationContextTypeServiceImpl.class);
39 * Injected simulation context type DAO.
41 private SimulationContextTypeDAO _simulationContextTypeDAO;
46 * @see org.splat.service.SimulationContextService#createType(java.lang.String, org.splat.service.technical.ProjectSettingsService.Step)
49 public SimulationContextType createType(final String name,
50 final ProjectSettingsService.Step step)
51 throws InvalidPropertyException {
52 if (StringUtils.isBlank(name)) {
53 // Simulation context type name could not be blank
54 throw new InvalidPropertyException(MessageKeyEnum.SCT_000002
57 SimulationContextType type = getSimulationContextTypeDAO()
58 .findByCriteria(Restrictions.eq("name", name));
60 type = new SimulationContextType(name, step);
61 getSimulationContextTypeDAO().create(type);
63 // Simulation context type already exists
64 LOG.info(MessageKeyEnum.SCT_000001.toString(), name);
71 * Approve the simulation context type.
75 * @return true if approval succeeded
77 public boolean approve(final SimulationContextType simCtxType) {
78 if (simCtxType.getState() != ProgressState.inCHECK) {
81 simCtxType.setState(ProgressState.APPROVED); // The type name is supposed being localized
82 getSimulationContextTypeDAO().update(simCtxType);
87 * Get the simulationContextTypeDAO.
89 * @return the simulationContextTypeDAO
91 public SimulationContextTypeDAO getSimulationContextTypeDAO() {
92 return _simulationContextTypeDAO;
96 * Set the simulationContextTypeDAO.
98 * @param simulationContextTypeDAO
99 * the simulationContextTypeDAO to set
101 public void setSimulationContextTypeDAO(
102 final SimulationContextTypeDAO simulationContextTypeDAO) {
103 _simulationContextTypeDAO = simulationContextTypeDAO;