import org.splat.dal.bo.som.Publication;
import org.splat.dal.bo.som.Scenario;
import org.splat.dal.bo.som.SimulationContext;
+import org.splat.dal.bo.som.SimulationContextType;
import org.splat.dal.bo.som.Study;
import org.splat.dal.bo.som.UsedByRelation;
import org.splat.dal.bo.som.UsesRelation;
import org.splat.dal.dao.som.KnowledgeElementTypeDAO;
import org.splat.dal.dao.som.ScenarioDAO;
import org.splat.dal.dao.som.StudyDAO;
+import org.splat.i18n.I18nUtils;
import org.splat.kernel.InvalidPropertyException;
import org.splat.kernel.MismatchException;
import org.splat.kernel.MissedPropertyException;
return res;
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.splat.service.ScenarioService#createStudy(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public long createStudy(final String username, final String title,
+ final String productName, final String description)
+ throws InvalidPropertyException, MissedPropertyException,
+ MultiplyDefinedException {
+ long id = 0;
+
+ // Find the author
+ User author = getUserService().selectUser(username);
+ if (author == null) {
+ // User is not found
+ throw new InvalidPropertyException(MessageKeyEnum.USR_000001
+ .toString(), username);
+ }
+
+ // Set the study properties
+ Study.Properties sprop = new Study.Properties();
+ sprop.setTitle(title).setManager(author);
+ sprop.setDescription(description);
+
+ // Find the product simulation context
+ SimulationContextType productContextType = getSimulationContextService()
+ .selectType("product");
+ SimulationContext.Properties cprop = new SimulationContext.Properties();
+ cprop.setType(productContextType).setValue(productName);
+ SimulationContext productCtx = getSimulationContextService()
+ .selectSimulationContext(productContextType, productName);
+ if (productCtx != null) {
+ cprop.setIndex(productCtx.getIndex());
+ }
+
+ // Set a first scenario properties
+ Scenario.Properties oprop = new Scenario.Properties();
+ oprop.setTitle(I18nUtils.getMessageLocaleDefault("label.scenario")
+ + " 1");
+
+ Study study = createStudy(sprop, oprop, cprop);
+ id = study.getIndex();
+
+ return id;
+ }
+
/**
* Create a new study with one scenario and "product" simulation context.
*
throws MissedPropertyException, InvalidPropertyException,
MultiplyDefinedException {
KnowledgeElement kelm = null;
-// try {
- long aScenarioId = aScenarioDTO.getIndex();
- if (LOG.isDebugEnabled()) {
- LOG.debug("Add a knowledge element to the scenario #"
- + aScenarioId);
- }
- // Get the persistent scenario.
- Scenario aScenario = getScenarioDAO().get(aScenarioId);
- // Get persistent objects for creating a new knowledge.
- // TODO: Actions must use DTO instead of persistent objects.
- getUserDAO().merge(kprop.getAuthor());
- getKnowledgeElementTypeDAO().merge(kprop.getType());
- // Create a transient knowledge element related to the given scenario.
- kelm = new KnowledgeElement(kprop.setOwnerScenario(aScenario));
- // Save the new knowledge in the database.
- getKnowledgeElementDAO().create(kelm);
- // Update scenario transient data.
- if (kelm.getType().equals("usecase")) {
- aScenarioDTO.setUcase(kelm);
- } else if (aScenarioDTO.getKnowledgeElementsList() != null) { // If null, knowl will be initialized when needed
- aScenarioDTO.getKnowledgeElementsList().add(kelm);
- }
+ // try {
+ long aScenarioId = aScenarioDTO.getIndex();
+ if (LOG.isDebugEnabled()) {
+ LOG
+ .debug("Add a knowledge element to the scenario #"
+ + aScenarioId);
+ }
+ // Get the persistent scenario.
+ Scenario aScenario = getScenarioDAO().get(aScenarioId);
+ // Get persistent objects for creating a new knowledge.
+ // TODO: Actions must use DTO instead of persistent objects.
+ getUserDAO().merge(kprop.getAuthor());
+ getKnowledgeElementTypeDAO().merge(kprop.getType());
+ // Create a transient knowledge element related to the given scenario.
+ kelm = new KnowledgeElement(kprop.setOwnerScenario(aScenario));
+ // Save the new knowledge in the database.
+ getKnowledgeElementDAO().create(kelm);
+ // Update scenario transient data.
+ if (kelm.getType().equals("usecase")) {
+ aScenarioDTO.setUcase(kelm);
+ } else if (aScenarioDTO.getKnowledgeElementsList() != null) { // If null, knowl will be initialized when needed
+ aScenarioDTO.getKnowledgeElementsList().add(kelm);
+ }
- // Load the workflow for the parent study to take into account
- // all study actors durng reindexing.
- getStudyService().loadWorkflow(aScenario.getOwnerStudy());
+ // Load the workflow for the parent study to take into account
+ // all study actors durng reindexing.
+ getStudyService().loadWorkflow(aScenario.getOwnerStudy());
-// // Update the lucene index of knowledge elements.
-// getIndexService().add(kelm);
- if (LOG.isDebugEnabled()) {
- LOG.debug("A knowledge element #" + kelm.getIndex()
- + " is added to the scenario #" + aScenario.getIndex());
- }
-// } catch (IOException error) {
-// LOG.error("Unable to index the knowedge element '"
-// + kelm.getIndex() + "', reason:", error);
-// kelm = null;
-// }
+ // // Update the lucene index of knowledge elements.
+ // getIndexService().add(kelm);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("A knowledge element #" + kelm.getIndex()
+ + " is added to the scenario #" + aScenario.getIndex());
+ }
+ // } catch (IOException error) {
+ // LOG.error("Unable to index the knowedge element '"
+ // + kelm.getIndex() + "', reason:", error);
+ // kelm = null;
+ // }
return kelm;
}