LCK-000003=Lock reference protected and can be only deleted or updated by user {0}.
LCK-000004=Lock reference is timeout and could have been modified by user {0}.
STD-000001=Unable to re-index the study #{0}, reason: {1}
+STD-000002=The study #{0} is not found
SCN-000001=Scenario doesn't contain the step number #{0}
SCN-000002=Scenario doesn't contain the document #{0}
SCN-000003=The existing file {0} has been deleted when check-in the scenario #{0}
USR-000001=User {0} is not found in the database
KNT-000001=Knowledge element type "{0}" already exists
SCT-000001=Simulation context type "{0}" already exists
+SCT-000002=Simulation context type name could not be blank
DCT-000001=Document type "{0}" already exists
DCT-000002=Can not delete the document "{0}" because it is used by other documents.
DCT-000003=Can not save a document in {0} state. Check the validation cycle.
LCK-000003=Lock reference protected and can be only deleted or updated by user {0}.
LCK-000004=Lock reference is timeout and could have been modified by user {0}.
STD-000001=Unable to re-index the study #{0}, reason: {1}
+STD-000002=The study #{0} is not found
SCN-000001=Scenario doesn't contain the step number #{0}
SCN-000002=Scenario doesn't contain the document #{0}
SCN-000003=The existing file {0} has been deleted when check-in the scenario #{0}
USR-000001=User {0} is not found in the database
KNT-000001=Knowledge element type "{0}" already exists
SCT-000001=Simulation context type "{0}" already exists
+SCT-000002=Simulation context type name could not be blank
DCT-000001=Document type "{0}" already exists
DCT-000002=Can not delete the document "{0}" because it is used by other documents.
DCT-000003=Can not save a document in {0} state. Check the validation cycle.
* Unable to re-index the study #{0}, reason: {1}.
*/
STD_000001("STD-000001"),
+ /**
+ * The study #{0} is not found.
+ */
+ STD_000002("STD-000002"),
/**
* Scenario doesn't contain the step number #{0}.
*/
*/
KNT_000001("KNT-000001"),
/**
- * Knowledge element type "{0}" already exists.
+ * Simulation context type "{0}" already exists.
*/
SCT_000001("SCT-000001"),
+ /**
+ * Simulation context type name could not be blank.
+ */
+ SCT_000002("SCT-000002"),
/**
* Document type "{0}" already exists.
*/
*/
List<StepDTO> getScenarioInfo(long scenarioId);
+ /**
+ * Assign context to the study.
+ *
+ * @param studyId
+ * study id
+ * @param ctxType
+ * context type name
+ * @param ctxValue
+ * context value
+ * @throws InvalidPropertyException
+ * if an invalid value is passed to a property
+ * @throws MissedPropertyException
+ * if a mandatory property is missed
+ * @throws MultiplyDefinedException
+ * if some property is defined several times
+ */
+ public void assignStudyContext(final Long studyId, final String ctxType,
+ final String ctxValue) throws MissedPropertyException,
+ InvalidPropertyException, MultiplyDefinedException;
+
/**
* Create a new study.
*
*/
long createStudy(final String username, final String title,
final String productName, final String description)
- throws InvalidPropertyException, MissedPropertyException, MultiplyDefinedException;
+ throws InvalidPropertyException, MissedPropertyException,
+ MultiplyDefinedException;
/**
* Create a new study with one scenario and "product" simulation context.
* @return true if removal succeeded
*/
boolean removeKnowledgeElement(Scenario scenario, KnowledgeElement kelm);
-
+
/**
* Rename the scenario.
- * @param scenario - the scenario with a new title.
+ *
+ * @param scenario -
+ * the scenario with a new title.
*/
void renameScenario(final Scenario scenario);
}
*/
private SimulationContextService _simulationContextService;
+ /**
+ * Injected simulation context type service.
+ */
+ private SimulationContextTypeService _simulationContextTypeService;
+
/**
* Injected project service.
*/
return study;
}
+ /**
+ * {@inheritDoc}
+ * @see org.splat.service.ScenarioService#assignStudyContext(java.lang.Long, java.lang.String, java.lang.String)
+ */
@Transactional
- public void assignContext() throws MissedPropertyException,
+ public void assignStudyContext(final Long studyId, final String ctxType,
+ final String ctxValue) throws MissedPropertyException,
InvalidPropertyException, MultiplyDefinedException {
- //TODO: complete the method
- SimulationContext.Properties cprop = new SimulationContext.Properties();
- Long id = 0L;
- Study study = getStudyDAO().get(id);
- if (cprop.getIndex() == 0) { // Input of new project context
- cprop.setType(getSimulationContextService().selectType("product"))
- .setValue(cprop.getValue());
+ // Find the study by the given id
+ Study study = getStudyDAO().get(studyId);
+ if (study == null) {
+ throw new InvalidPropertyException(MessageKeyEnum.STD_000002
+ .toString(), studyId);
+ }
+ // Find the context type by its name
+ SimulationContextType celt = getSimulationContextService().selectType(
+ ctxType);
+ if (celt == null) {
+ // Creation of a new context type
+ celt = getSimulationContextTypeService().createType(ctxType,
+ getProjectElementService().getFirstStep(study).getStep());
+ }
+ // Find the given context value of the given type
+ SimulationContext context = getSimulationContextService()
+ .selectSimulationContext(celt, ctxValue);
+ if (context == null) { // Input of a new project context
+ SimulationContext.Properties cprop = new SimulationContext.Properties();
+ cprop.setType(celt).setValue(ctxValue);
getStudyService().addProjectContext(study, cprop);
} else { // Selection of existing project context
- SimulationContext context = getSimulationContextService()
- .selectSimulationContext(cprop.getIndex());
getStudyService().addProjectContext(study, context);
}
}
_roleDAO = roleDAO;
}
+ /**
+ * Get the simulationContextTypeService.
+ *
+ * @return the simulationContextTypeService
+ */
+ public SimulationContextTypeService getSimulationContextTypeService() {
+ return _simulationContextTypeService;
+ }
+
+ /**
+ * Set the simulationContextTypeService.
+ *
+ * @param simulationContextTypeService
+ * the simulationContextTypeService to set
+ */
+ public void setSimulationContextTypeService(
+ final SimulationContextTypeService simulationContextTypeService) {
+ _simulationContextTypeService = simulationContextTypeService;
+ }
+
}
* @copyright OPEN CASCADE 2012
*****************************************************************************/
-package org.splat.service;
+package org.splat.service;
+import org.apache.commons.lang3.StringUtils;
import org.hibernate.criterion.Restrictions;
import org.splat.common.properties.MessageKeyEnum;
import org.splat.dal.bo.som.ProgressState;
/**
* Simulation context type service implementation.
- *
+ *
* @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
*/
public class SimulationContextTypeServiceImpl implements
*/
@Transactional
public SimulationContextType createType(final String name,
- final ProjectSettingsService.Step step) throws InvalidPropertyException {
- SimulationContextType type = getSimulationContextTypeDAO().findByCriteria(Restrictions.eq("name", name));
+ final ProjectSettingsService.Step step)
+ throws InvalidPropertyException {
+ if (StringUtils.isBlank(name)) {
+ // Simulation context type name could not be blank
+ throw new InvalidPropertyException(MessageKeyEnum.SCT_000002
+ .toString());
+ }
+ SimulationContextType type = getSimulationContextTypeDAO()
+ .findByCriteria(Restrictions.eq("name", name));
if (type == null) {
type = new SimulationContextType(name, step);
getSimulationContextTypeDAO().create(type);
} else {
+ // Simulation context type already exists
LOG.info(MessageKeyEnum.SCT_000001.toString(), name);
}
<property name="roleDAO" ref="roleDAO" />
<property name="knowledgeElementTypeDAO"
ref="knowledgeElementTypeDAO" />
- <property name="simulationContextService"
- ref="simulationContextService" />
+ <property name="simulationContextService"
+ ref="simulationContextService" />
+ <property name="simulationContextTypeService"
+ ref="simulationContextTypeService" />
</bean>
<bean id="searchService"
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
"Simulation context type 'product' must be created in the database.");
String productName = "New Test Product " + new Date().toString();
-
+
ht.flush();
ht.clear();
long studyId1 = _scenarioService.createStudy("goodUser",
// Check that the simulation context is the same
Study study1 = _studyService.selectStudy(studyId1);
Study study3 = _studyService.selectStudy(studyId3);
- Assert.assertEquals(study1.SimulationContextIterator().next(),
- study3.SimulationContextIterator().next());
-
+ Assert.assertEquals(study1.SimulationContextIterator().next(), study3
+ .SimulationContextIterator().next());
+
// Check the title of the created scenario
String scTitle = study1.getScenarii()[0].getTitle();
- Assert.assertEquals(scTitle, I18nUtils.getMessageLocaleDefault("label.scenario") + " 1");
+ Assert.assertEquals(scTitle, I18nUtils
+ .getMessageLocaleDefault("label.scenario")
+ + " 1");
Assert.assertFalse(scTitle.equals("label.scenario 1"));
-
+
rollbackNestedTransaction();
LOG.debug(">>>>> END testCreateStudyFromPython()");
}
+
+ /**
+ * Test assigning a simulation context to a study.<BR>
+ * <B>Description :</B> <BR>
+ * <i>Create a study and assign a simulation context to it.</i><BR>
+ * <B>Action : </B><BR>
+ * <i>1. call the method for not existing study id.</i><BR>
+ * <i>2. call the method for not existing context type and context value.</i><BR>
+ * <i>3. call the method for existing context type and context value.</i><BR>
+ * <i>4. call the method for existing context type and not existing context value.</i><BR>
+ * <i>5. call the method for empty context type.</i><BR>
+ * <i>6. call the method for empty context value.</i><BR>
+ * <B>Test data : </B><BR>
+ * <i>no input parameters</i><BR>
+ *
+ * <B>Outcome results:</B><BR>
+ * <i>
+ * <ul>
+ * <li>1: Exception must be thrown.</li>
+ * <li>2: The new context type and value must be created. The new context must be assigned to the study first step.</li>
+ * <li>3: The existing context must be assigned to the study first step.</li>
+ * <li>4: The new context value must be created. The new context must be assigned to the study first step.</li>
+ * <li>5: Exception must be thrown.</li>
+ * <li>6: Exception must be thrown.</li>
+ * </ul>
+ * </i>
+ *
+ * @throws IOException
+ * if application configuration loading is failed
+ * @throws SQLException
+ * if application configuration loading is failed
+ * @throws BusinessException
+ * if test data creation is failed
+ */
+ @Test(groups = { "study", "sevice", "functional", "business" })
+ public void testAssignStudyContextFromPython() throws IOException,
+ SQLException, BusinessException {
+ LOG.debug(">>>>> BEGIN testAssignStudyContextFromPython()");
+ startNestedTransaction();
+
+ HibernateTemplate ht = getHibernateTemplate();
+
+ Database.getInstance().reset();
+ _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
+ _projectSettings.configure("classpath:test/som.xml");
+
+ // Create a test user
+ User goodUser = TestEntitiesGenerator.getTestUser("goodUser");
+ _userDAO.create(goodUser);
+ SimulationContextType prodtype = _simulationContextService
+ .selectType("product");
+ Assert
+ .assertNotNull(prodtype,
+ "Simulation context type 'product' must be created in the database.");
+
+ String productName = "New Test Product " + new Date().toString();
+
+ ht.flush();
+ ht.clear();
+ long studyId1 = _scenarioService.createStudy("goodUser",
+ "Test Study 1", productName, "Test description");
+ Assert.assertTrue(studyId1 > 0);
+
+ ht.flush();
+ ht.clear();
+
+ // //////// START OF TESTS
+ // 1. call the method for not existing study id.</i><BR>
+ try {
+ _scenarioService.assignStudyContext(-1L, "new context type",
+ "new context value");
+ Assert.fail("Not existing study must not be found.");
+ } catch (InvalidPropertyException ipe) {
+ LOG.debug("Expected exception: " + ipe.getMessage());
+ }
+
+ // 2. call the method for not existing context type and context value.</i><BR>
+ _scenarioService.assignStudyContext(studyId1, "new context type",
+ "new context value");
+
+ ht.flush();
+ ht.clear();
+
+ // Check the assigned simulation context
+ checkCtx(studyId1, "new context type", "new context value");
+
+ // 3. call the method for existing context type and context value.</i><BR>
+ _scenarioService.assignStudyContext(studyId1, "new context type",
+ "new context value");
+
+ ht.flush();
+ ht.clear();
+
+ // Check the assigned simulation context
+ checkCtx(studyId1, "new context type", "new context value");
+
+ // 4. call the method for existing context type and not existing context value.</i><BR>
+ _scenarioService.assignStudyContext(studyId1, "new context type",
+ "new context value1");
+
+ ht.flush();
+ ht.clear();
+
+ // Check the assigned simulation context
+ checkCtx(studyId1, "new context type", "new context value1");
+
+ // 5. call the method for empty context type.</i><BR>
+ try {
+ _scenarioService.assignStudyContext(studyId1, "",
+ "new context value");
+ Assert.fail("Empty context type name must be forbidden.");
+ } catch (InvalidPropertyException ipe) {
+ LOG.debug("Expected exception: " + ipe.getMessage());
+ }
+ // 6. call the method for empty context value.</i><BR>
+ try {
+ _scenarioService.assignStudyContext(studyId1, "new context type",
+ "");
+ Assert.fail("Empty context value must be forbidden.");
+ } catch (InvalidPropertyException ipe) {
+ LOG.debug("Expected exception: " + ipe.getMessage());
+ }
+
+ rollbackNestedTransaction();
+ LOG.debug(">>>>> END testAssignStudyContextFromPython()");
+ }
+
+ /**
+ * Check if the context is assigned to the study.
+ *
+ * @param studyId1
+ * the study id
+ * @param ctxType
+ * the context type name
+ * @param ctxValue
+ * the context value
+ */
+ private void checkCtx(final long studyId1, final String ctxType,
+ final String ctxValue) {
+ // Check the assigned simulation context
+ Study study1 = _studyService.selectStudy(studyId1);
+ Iterator<SimulationContext> it = study1.SimulationContextIterator();
+ SimulationContext ctx;
+ boolean isFound = false;
+ while ((!isFound) && it.hasNext()) {
+ ctx = it.next();
+ isFound = ctx.getType().getName().equals(ctxType)
+ && ctx.getValue().equals(ctxValue);
+ }
+ Assert.assertTrue(isFound, "Context must be assigned to the study.");
+ }
}