Salome HOME
Copyrights update 2015.
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / service / SimulationContextTypeServiceImpl.java
1 /*****************************************************************************
2  * Company         OPEN CASCADE
3  * Application     SIMAN
4  * File            $Id$ 
5  * Creation date   22.10.2012
6  * @author         $Author$
7  * @version        $Revision$
8  * @copyright      OPEN CASCADE 2012-2015
9  *****************************************************************************/
10
11 package org.splat.service;
12
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;
23
24 /**
25  * Simulation context type service implementation.
26  * 
27  * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
28  */
29 public class SimulationContextTypeServiceImpl implements
30                 SimulationContextTypeService {
31
32         /**
33          * The logger for the service.
34          */
35         public final static AppLogger LOG = AppLogger
36                         .getLogger(SimulationContextTypeServiceImpl.class);
37
38         /**
39          * Injected simulation context type DAO.
40          */
41         private SimulationContextTypeDAO _simulationContextTypeDAO;
42
43         /**
44          * {@inheritDoc}
45          * 
46          * @see org.splat.service.SimulationContextService#createType(java.lang.String, org.splat.service.technical.ProjectSettingsService.Step)
47          */
48         @Transactional
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
55                                         .toString());
56                 }
57                 SimulationContextType type = getSimulationContextTypeDAO()
58                                 .findByCriteria(Restrictions.eq("name", name));
59                 if (type == null) {
60                         type = new SimulationContextType(name, step);
61                         getSimulationContextTypeDAO().create(type);
62                 } else {
63                         // Simulation context type already exists
64                         LOG.info(MessageKeyEnum.SCT_000001.toString(), name);
65                 }
66
67                 return type;
68         }
69
70         /**
71          * Approve the simulation context type.
72          * 
73          * @param simCtxType
74          *            the type to approve
75          * @return true if approval succeeded
76          */
77         public boolean approve(final SimulationContextType simCtxType) {
78                 if (simCtxType.getState() != ProgressState.inCHECK) {
79                         return false;
80                 }
81                 simCtxType.setState(ProgressState.APPROVED); // The type name is supposed being localized
82                 getSimulationContextTypeDAO().update(simCtxType);
83                 return true;
84         }
85
86         /**
87          * Get the simulationContextTypeDAO.
88          * 
89          * @return the simulationContextTypeDAO
90          */
91         public SimulationContextTypeDAO getSimulationContextTypeDAO() {
92                 return _simulationContextTypeDAO;
93         }
94
95         /**
96          * Set the simulationContextTypeDAO.
97          * 
98          * @param simulationContextTypeDAO
99          *            the simulationContextTypeDAO to set
100          */
101         public void setSimulationContextTypeDAO(
102                         final SimulationContextTypeDAO simulationContextTypeDAO) {
103                 _simulationContextTypeDAO = simulationContextTypeDAO;
104         }
105
106 }