*/
List<StepDTO> getScenarioInfo(long scenarioId);
+ /**
+ * Create a new study.
+ *
+ * @param username
+ * user login
+ * @param title
+ * study title
+ * @param productName
+ * study product simulation context value
+ * @param description
+ * study summary
+ * @return the created study id
+ * @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
+ */
+ long createStudy(final String username, final String title,
+ final String productName, final String description)
+ throws InvalidPropertyException, MissedPropertyException, MultiplyDefinedException;
+
/**
* Create a new study with one scenario and "product" simulation context.
*
* @throws MissedPropertyException
* if a mandatory property is missed
* @throws InvalidPropertyException
- * if some property doesn't exist
+ * if an invalid value is passed to a property
* @throws MultiplyDefinedException
* if some property occurs several times
*/
* @throws MissedPropertyException
* if a mandatory property is missed
* @throws InvalidPropertyException
- * if some property doesn't exist
+ * if an invalid value is passed to a property
* @throws MultiplyDefinedException
* if some property is defined several times
*/
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;
}
import org.splat.dal.bo.som.Publication;
import org.splat.dal.bo.som.SimulationContext;
import org.splat.dal.bo.som.Study;
-import org.splat.dal.bo.som.Study.Properties;
import org.splat.dal.bo.som.ValidationCycle;
+import org.splat.dal.bo.som.Study.Properties;
import org.splat.exception.IncompatibleDataException;
import org.splat.exception.InvalidParameterException;
import org.splat.kernel.InvalidPropertyException;
* @throws MissedPropertyException
* if a mandatory property is missed
* @throws InvalidPropertyException
- * if some property doesn't exist
+ * if an invalid value is passed to a property
* @throws MultiplyDefinedException
* if some property is defined several times
*/
- Study createStudy(Study.Properties sprop)
- throws MissedPropertyException, InvalidPropertyException,
- MultiplyDefinedException;
+ Study createStudy(Study.Properties sprop) throws MissedPropertyException,
+ InvalidPropertyException, MultiplyDefinedException;
/**
* Add a simulation context to the first step of the study. If the context doesn't yet saved it is created in the database.
* @throws MissedPropertyException
* if a mandatory property is missed
* @throws InvalidPropertyException
- * if some property doesn't exist
+ * if an invalid value is passed to a property
* @throws MultiplyDefinedException
* if some property occurs several times
*/
* the simulation context to add
* @return the added simulation context
*/
- SimulationContext addProjectContext(Study aStudy,
- SimulationContext context);
+ SimulationContext addProjectContext(Study aStudy, SimulationContext context);
/**
* Remove a simulation context from a study.
* @see #isPublic()
*/
boolean moveToPublic(Study aStudy);
-
+
/**
* Moves this study from the Public to the Private area of the repository.
*
* new properties of the study
* @return true if the study has been updated successfully
* @throws InvalidPropertyException
- * if some property doesn't exist
+ * if an invalid value is passed to a property
*/
boolean update(Study aStudy, Properties sprop)
throws InvalidPropertyException;
* @return the unmodifiable not null transient list of contributors of this study
*/
List<User> getContributors(Study aStudy);
-
+
/**
* Mark study as reference.
*
- * @param aStudy - the Study
+ * @param aStudy -
+ * the Study
*/
void markStudyAsReference(Study aStudy);
-
+
/**
- * Remove study as reference.
- * This operation is inverse one to Mark as reference.
+ * Remove study as reference. This operation is inverse one to Mark as reference.
*
- * @param aStudy - the Study
+ * @param aStudy -
+ * the Study
*/
void removeStudyAsReference(Study aStudy);
-
+
/**
- * Get the description attribute related to the study
- * (there supposed to be the only one such attribute in the database).
- * @param studyId the study id
+ * Get the description attribute related to the study (there supposed to be the only one such attribute in the database).
+ *
+ * @param studyId
+ * the study id
* @return the description attribute value (null if does not exist)
- * @throws InvalidParameterException if a study with such id does not exist in the database.
+ * @throws InvalidParameterException
+ * if a study with such id does not exist in the database.
*/
String getDescription(Long studyId) throws InvalidParameterException;
-
+
/**
* Set the description attribute related to the study.
- * @param studyId the study id
- * @param descriptionText the description text
- * @throws InvalidParameterException if some parameters are invalid.
+ *
+ * @param studyId
+ * the study id
+ * @param descriptionText
+ * the description text
+ * @throws InvalidParameterException
+ * if some parameters are invalid.
*/
- void setDescription(Long studyId, String descriptionText) throws InvalidParameterException;
+ void setDescription(Long studyId, String descriptionText)
+ throws InvalidParameterException;
/**
* Remove a description attached to a study.
*
- * @param studyId the study id
+ * @param studyId
+ * the study id
* @throws InvalidParameterException
- * if no study with such Id has been found in the database.
+ * if no study with such Id has been found in the database.
* @return true if succeeded, false if study doesn't have a description.
*/
- boolean removeDescription(final Long studyId) throws InvalidParameterException;
-
+ boolean removeDescription(final Long studyId)
+ throws InvalidParameterException;
+
/**
* Compare the studies and generate the file that contains the result chart.
- * @param docsList the list of dtos each contains information:
- * StudyTitle, ScenarioTitle, PathToFile in vault.
- * @param userName the name of the user who compare the results.
+ *
+ * @param docsList
+ * the list of dtos each contains information: StudyTitle, ScenarioTitle, PathToFile in vault.
+ * @param userName
+ * the name of the user who compare the results.
* @throws IncompatibleDataException
- * if data is incompatible for "Compare the studies" functionality.
+ * if data is incompatible for "Compare the studies" functionality.
*
* @return path to result file in the vault.
*/
- String compare (List<DocToCompareDTO> docsList, final String userName) throws IncompatibleDataException;
+ String compare(List<DocToCompareDTO> docsList, final String userName)
+ throws IncompatibleDataException;
}