package org.splat.service;
+import java.util.List;
+
import org.splat.dal.bo.kernel.User;
import org.splat.dal.bo.som.KnowledgeElement;
import org.splat.dal.bo.som.Scenario;
import org.splat.kernel.InvalidPropertyException;
import org.splat.kernel.MissedPropertyException;
import org.splat.kernel.MultiplyDefinedException;
+import org.splat.service.dto.StepDTO;
import org.splat.som.Step;
/**
*/
public interface ScenarioService {
+ /**
+ * Get lists of scenario steps, documents and files for building siman-salome.conf file.
+ *
+ * @param scenarioId
+ * scenario id
+ * @return list of step DTOs
+ */
+ List<StepDTO> getScenarioInfo(long scenarioId);
+
/**
* Create a new study with one scenario and "product" simulation context.
*
* the knowledge element to remove
* @return true if removal succeeded
*/
- boolean removeKnowledgeElement(Scenario scenario,
- KnowledgeElement kelm);
+ boolean removeKnowledgeElement(Scenario scenario, KnowledgeElement kelm);
}
package org.splat.service;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.Calendar;
import java.util.Iterator;
import java.util.List;
import org.apache.log4j.Logger;
+import org.splat.dal.bo.kernel.Relation;
import org.splat.dal.bo.kernel.User;
+import org.splat.dal.bo.som.ConvertsRelation;
+import org.splat.dal.bo.som.File;
import org.splat.dal.bo.som.KnowledgeElement;
import org.splat.dal.bo.som.KnowledgeElementType;
import org.splat.dal.bo.som.Publication;
import org.splat.kernel.InvalidPropertyException;
import org.splat.kernel.MissedPropertyException;
import org.splat.kernel.MultiplyDefinedException;
+import org.splat.service.dto.DocumentDTO;
+import org.splat.service.dto.StepDTO;
import org.splat.service.technical.IndexService;
import org.splat.som.Step;
+import org.splat.util.BeanHelper;
import org.springframework.transaction.annotation.Transactional;
/**
_stepService = stepService;
}
+ /**
+ * {@inheritDoc}
+ * @see org.splat.service.ScenarioService#getScenarioInfo(long)
+ */
+ @Transactional
+ public List<StepDTO> getScenarioInfo(final long scenarioId) {
+ List<StepDTO> res = new ArrayList<StepDTO>();
+ Scenario scen = getScenarioDAO().get(scenarioId);
+ Step[] steps = getProjectElementService().getSteps(scen);
+ StepDTO stepDTO;
+ DocumentDTO docDTO;
+ for (Step step: steps) {
+ stepDTO = BeanHelper.copyBean(step.getStep(), StepDTO.class);
+ res.add(stepDTO);
+ for (Publication tag: step.getDocuments()) {
+ docDTO = stepDTO.addDoc(tag.value().getIndex(), tag.value().getTitle());
+ char aState = tag.getIsnew();
+ docDTO.addFile(tag.value().getFile().getRelativePath(), aState);
+ for(Relation rel: tag.value().getRelations(ConvertsRelation.class)) {
+ File aFile = ((ConvertsRelation)rel).getTo();
+ docDTO.addFile(aFile.getRelativePath(), aState);
+ }
+ }
+ }
+ return res;
+ }
+
/**
* Create a new study with one scenario and "product" simulation context.
*
--- /dev/null
+/*****************************************************************************
+ * Company OPEN CASCADE
+ * Application SIMAN
+ * File $Id$
+ * Creation date 14.11.2012
+ * @author $Author$
+ * @version $Revision$
+ * @copyright OPEN CASCADE 2012
+ *****************************************************************************/
+
+package org.splat.service.dto;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Document DTO. This is a container of document files.
+ */
+public class DocumentDTO {
+ /**
+ * Document persistent id.
+ */
+ private Long _id;
+ /**
+ * Document title.
+ */
+ private String _title;
+ /**
+ * List of document files.
+ */
+ private final List<FileDTO> _files = new ArrayList<FileDTO>(); // RKV: NOPMD: Access to the collection via getter
+
+ /**
+ * Constructor with initialization.
+ *
+ * @param index
+ * the document persistent id
+ * @param title
+ * the document title
+ */
+ public DocumentDTO(final long index, final String title) {
+ _id = index;
+ _title = title;
+ }
+
+ /**
+ * Get the files.
+ *
+ * @return the files
+ */
+ public List<FileDTO> getFiles() {
+ return _files;
+ }
+
+ /**
+ * Get the id.
+ *
+ * @return the id
+ */
+ public Long getId() {
+ return _id;
+ }
+
+ /**
+ * Set the id.
+ *
+ * @param id
+ * the id to set
+ */
+ public void setId(final Long id) {
+ _id = id;
+ }
+
+ /**
+ * Get the title.
+ *
+ * @return the title
+ */
+ public String getTitle() {
+ return _title;
+ }
+
+ /**
+ * Set the title.
+ *
+ * @param title
+ * the title to set
+ */
+ public void setTitle(final String title) {
+ _title = title;
+ }
+
+ /**
+ * Add a new file DTO.
+ *
+ * @param relativePath
+ * relative file path
+ * @param state
+ * file state
+ * @return the added file DTO
+ */
+ public FileDTO addFile(final String relativePath, final char state) {
+ FileDTO fileDTO = new FileDTO(relativePath, state);
+ _files.add(fileDTO);
+ return fileDTO;
+ }
+}
--- /dev/null
+/*****************************************************************************
+ * Company OPEN CASCADE
+ * Application SIMAN
+ * File $Id$
+ * Creation date 14.11.2012
+ * @author $Author$
+ * @version $Revision$
+ * @copyright OPEN CASCADE 2012
+ *****************************************************************************/
+
+package org.splat.service.dto;
+
+/**
+ * Document's file DTO.
+ */
+public class FileDTO {
+
+ /**
+ * True if the file is a result file for a document.
+ */
+ private boolean _isResult; // RKV: NOPMD: isResult method is used as getter
+ /**
+ * File state: "Y" - actual, "O" - outdated, "N" - taken from other study.
+ */
+ private char _state;
+ /**
+ * Automatic processing instruction: "file-import", "file-download", etc.
+ */
+ private String _processing;
+ /**
+ * File path from the repository root.
+ */
+ private String _path;
+
+ /**
+ * Constructor with initialization.
+ *
+ * @param relativePath
+ * relative file path
+ * @param state
+ * file state
+ */
+ public FileDTO(final String relativePath, final char state) {
+ _path = relativePath;
+ _state = state;
+ }
+
+ /**
+ * Get the isResult.
+ *
+ * @return the isResult
+ */
+ public boolean isResult() {
+ return _isResult;
+ }
+
+ /**
+ * Set the isResult.
+ *
+ * @param isResult
+ * the isResult to set
+ */
+ public void setResult(final boolean isResult) {
+ _isResult = isResult;
+ }
+
+ /**
+ * Get the state.
+ *
+ * @return the state
+ */
+ public char getState() {
+ return _state;
+ }
+
+ /**
+ * Set the state.
+ *
+ * @param state
+ * the state to set
+ */
+ public void setState(final char state) {
+ _state = state;
+ }
+
+ /**
+ * Get the processing.
+ *
+ * @return the processing
+ */
+ public String getProcessing() {
+ return _processing;
+ }
+
+ /**
+ * Set the processing.
+ *
+ * @param processing
+ * the processing to set
+ */
+ public void setProcessing(final String processing) {
+ _processing = processing;
+ }
+
+ /**
+ * Get the path.
+ *
+ * @return the path
+ */
+ public String getPath() {
+ return _path;
+ }
+
+ /**
+ * Set the path.
+ *
+ * @param path
+ * the path to set
+ */
+ public void setPath(final String path) {
+ _path = path;
+ }
+}
--- /dev/null
+/*****************************************************************************
+ * Company OPEN CASCADE
+ * Application SIMAN
+ * File $Id$
+ * Creation date 14.11.2012
+ * @author $Author$
+ * @version $Revision$
+ * @copyright OPEN CASCADE 2012
+ *****************************************************************************/
+
+package org.splat.service.dto;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Study activity (step) DTO. This is a container of step documents.
+ */
+public class StepDTO {
+ /**
+ * The step's key name.
+ */
+ private String _key;
+ /**
+ * The sequential number of the step.
+ */
+ private int _number;
+ /**
+ * Executable module for this step.
+ */
+ private String _module;
+ /**
+ * Documents of the step.
+ */
+ private List<DocumentDTO> _docs = new ArrayList<DocumentDTO>();
+
+ /**
+ * Get the docs.
+ *
+ * @return the docs
+ */
+ public List<DocumentDTO> getDocs() {
+ return _docs;
+ }
+
+ /**
+ * Set the docs.
+ *
+ * @param docs
+ * the docs to set
+ */
+ public void setDocs(final List<DocumentDTO> docs) {
+ _docs = docs;
+ }
+
+ /**
+ * Add a document DTO to the step DTO.
+ *
+ * @param index
+ * the document persistent id
+ * @param title
+ * the document title
+ * @return the added document DTO
+ */
+ public DocumentDTO addDoc(final long index, final String title) {
+ DocumentDTO doc = new DocumentDTO(index, title);
+ _docs.add(doc);
+ return doc;
+ }
+
+ /**
+ * Get the key.
+ * @return the key
+ */
+ public String getKey() {
+ return _key;
+ }
+
+ /**
+ * Set the key.
+ * @param key the key to set
+ */
+ public void setKey(final String key) {
+ _key = key;
+ }
+
+ /**
+ * Get the number.
+ * @return the number
+ */
+ public int getNumber() {
+ return _number;
+ }
+
+ /**
+ * Set the number.
+ * @param number the number to set
+ */
+ public void setNumber(final int number) {
+ _number = number;
+ }
+
+ /**
+ * Get the module.
+ * @return the module
+ */
+ public String getModule() {
+ return _module;
+ }
+
+ /**
+ * Set the module.
+ * @param module the module to set
+ */
+ public void setModule(final String module) {
+ _module = module;
+ }
+}
* The sequential number of the step.
*/
private int _number;
+ /**
+ * The step's key name.
+ */
+ private String _key;
/**
* The owner of the step: study or scenario.
public void setModule(final String module) {
_module = module;
}
+
+ /**
+ * Get the key.
+ * @return the key
+ */
+ public String getKey() {
+ return _key;
+ }
+
+ /**
+ * Set the key.
+ * @param key the key to set
+ */
+ public void setKey(final String key) {
+ _key = key;
+ }
}
/**
final List<String> resultype) {
int res = snum;
if ("step".equals(node.getNodeName())) {
+
+ String name = ((Element)node).getAttribute("name");
HashMap<String, Node> tags = XDOM.getNamedChildNodes(node);
NamedNodeMap natr = tags.get("storage").getAttributes();
ProjectSettingsService.Step step = new ProjectSettingsService.Step(
- snum, ownerClass, natr.getNamedItem("path")
- .getNodeValue());
+ snum, ownerClass, natr.getNamedItem("path").getNodeValue());
+ step.setKey(name);
// Keeping flow and classification information for eventual later use
natr = tags.get("flow").getAttributes();
if (natr.getNamedItem("contents").getNodeValue()
.equals("knowledge")) {
if (Study.class.equals(ownerClass)) {
- LOG.error("Error: knowledges must be attached to scenarios.");
+ LOG
+ .error("Error: knowledges must be attached to scenarios.");
} else {
// TODO In a given scenario, only one step must contain knowledges
step._contents.add(KnowledgeElement.class);
} else {
step._contents.add(Document.class);
}
-
- Element module = (Element)tags.get("module");
+
+ Element module = (Element) tags.get("module");
if (module != null) {
step.setModule(module.getAttribute("name"));
}
int snum = 0;
for (Iterator<NamedNodeMap> i = _sclass.iterator(); i.hasNext(); snum++) {
NamedNodeMap clatr = i.next();
- if (clatr == null) {
- continue;
- }
-
- String[] clist = clatr.getNamedItem("context").getNodeValue()
- .split(",");
- for (int j = 0; j < clist.length; j++) {
- mapstep.put(clist[j], _steps.get(snum));
+ if (clatr != null) {
+ String[] clist = clatr.getNamedItem("context").getNodeValue()
+ .split(",");
+ for (int j = 0; j < clist.length; j++) {
+ mapstep.put(clist[j], _steps.get(snum));
+ }
}
}
try {
SimulationContextType tctex = null;
for (Iterator<String> i = _context.iterator(); i.hasNext();) {
String type = i.next();
- if (!mapstep.containsKey(type)) {
+ if (mapstep.containsKey(type)) {
+ tctex = getSimulationContextTypeService().createType(type,
+ mapstep.get(type)); // Creation of Simulation Context Types
+ getSimulationContextTypeService().approve(tctex);
+ } else {
LOG
.warn("Could not find \""
+ type
+ "\" classification. Simulation Context type ignored.");
- continue;
}
- tctex = getSimulationContextTypeService().createType(type,
- mapstep.get(type)); // Creation of Simulation Context Types
- getSimulationContextTypeService().approve(tctex);
}
} catch (Exception error) {
LOG.warn("Error creating context types, reason:", error); // Should not happen
--- /dev/null
+/*****************************************************************************
+ * Company OPEN CASCADE
+ * Application SIMAN
+ * File $Id$
+ * Creation date 12 Oct 2012
+ * @author $Author$
+ * @version $Revision$
+ *****************************************************************************/
+package test.splat.service;
+
+import java.io.IOException;
+import java.util.Date;
+import java.util.List;
+
+import org.splat.dal.bo.kernel.User;
+import org.splat.dal.bo.som.Document;
+import org.splat.dal.bo.som.DocumentType;
+import org.splat.dal.bo.som.KnowledgeElement;
+import org.splat.dal.bo.som.Publication;
+import org.splat.dal.bo.som.Scenario;
+import org.splat.dal.bo.som.Study;
+import org.splat.kernel.InvalidPropertyException;
+import org.splat.kernel.MissedPropertyException;
+import org.splat.kernel.MultiplyDefinedException;
+import org.splat.log.AppLogger;
+import org.splat.service.DocumentService;
+import org.splat.service.DocumentTypeService;
+import org.splat.service.ProjectElementService;
+import org.splat.service.PublicationService;
+import org.splat.service.ScenarioService;
+import org.splat.service.StepService;
+import org.splat.service.dto.StepDTO;
+import org.splat.som.Step;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.orm.hibernate3.HibernateTemplate;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import test.splat.common.BaseTest;
+
+/**
+ * Test class for KnowledgeElementDAO.
+ *
+ * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
+ *
+ */
+public class TestScenarioService extends BaseTest {
+
+ /**
+ * Logger for the class.
+ */
+ private static final AppLogger LOG = AppLogger
+ .getLogger(TestScenarioService.class);
+
+ /**
+ * The tested ScenarioService. Later injected by Spring.
+ */
+ @Autowired
+ @Qualifier("scenarioService")
+ private transient ScenarioService _scenarioService;
+
+ /**
+ * The DocumentService. Later injected by Spring.
+ */
+ @Autowired
+ @Qualifier("documentService")
+ private transient DocumentService _documentService;
+
+ /**
+ * The PublicationService. Later injected by Spring.
+ */
+ @Autowired
+ @Qualifier("publicationService")
+ private transient PublicationService _publicationService;
+
+ /**
+ * The StepService. Later injected by Spring.
+ */
+ @Autowired
+ @Qualifier("stepService")
+ private transient StepService _stepService;
+
+ /**
+ * The ProjectElementService. Later injected by Spring.
+ */
+ @Autowired
+ @Qualifier("projectElementService")
+ private transient ProjectElementService _projectElementService;
+
+ /**
+ * The DocumentTypeService. Later injected by Spring.
+ */
+ @Autowired
+ @Qualifier("documentTypeService")
+ private transient DocumentTypeService _documentTypeService;
+
+ /**
+ * Test of getting a scenario content for building siman-salome.conf.<BR>
+ * <B>Description :</B> <BR>
+ * <i>Create a scenario try to get an info for it.</i><BR>
+ * <B>Action : </B><BR>
+ * <i>1. call the method for an existing scenario id.</i><BR>
+ * <i>2. call the method for a not existing scenario id.</i><BR>
+ * <B>Test data : </B><BR>
+ * <i>no input parameters</i><BR>
+ * <i>no input parameters</i><BR>
+ *
+ * <B>Outcome results:</B><BR>
+ * <i>
+ * <ul>
+ * <li>result DTO must contain list of all documents and files<BR>
+ * </li>
+ * <li>Exception is thrown<BR>
+ * </li>
+ * </ul>
+ * </i>
+ *
+ * @throws InvalidPropertyException
+ * if an invalid property is used when creating objects
+ * @throws MultiplyDefinedException
+ * when trying to create an object with already existing id
+ * @throws MissedPropertyException
+ * if a mandatory property is not defined for an object to be created
+ * @throws IOException
+ * if scenario creation is failed
+ *
+ */
+ @Test
+ public void testGetScenarioInfo() throws InvalidPropertyException,
+ MissedPropertyException, MultiplyDefinedException, IOException {
+ LOG.debug(">>>>> BEGIN testGetScenarioInfo()");
+ long scenarioId = createScenario();
+ // Call DAO's create method for a good transient knowledge element.
+ List<StepDTO> steps = _scenarioService.getScenarioInfo(scenarioId);
+ Assert.assertNotNull(steps, "List of steps must not be null.");
+ Assert.assertTrue(steps.size() > 0, "No steps are read.");
+
+ // Call DAO's get method for a not existing id.
+ try {
+ steps = _scenarioService.getScenarioInfo(-1L);
+ // getHibernateTemplate().flush();
+ Assert
+ .fail("Getting an object with not existing id must be failed.");
+ } catch (Exception e) {
+ LOG.debug("Expected exception is thrown: "
+ + e.getClass().getSimpleName() + ": " + e.getMessage());
+ }
+ LOG.debug(">>>>> END testGetScenarioInfo()");
+ }
+
+ /**
+ * Create a transient KnowledgeElement for tests.
+ *
+ * @return a transient KnowledgeElement
+ * @throws InvalidPropertyException
+ * if an invalid property is used when creating objects
+ * @throws MultiplyDefinedException
+ * when trying to create an object with already existing id
+ * @throws MissedPropertyException
+ * if a mandatory property is not defined for an object to be created
+ * @throws IOException
+ * if document creation is failed
+ */
+ private long createScenario() throws InvalidPropertyException,
+ MissedPropertyException, MultiplyDefinedException, IOException {
+ // Create a scenario for tests
+ HibernateTemplate ht = getHibernateTemplate();
+
+ // Create a test user
+ User.Properties uprop = new User.Properties();
+ uprop.setUsername("TST_Username").setName("TST_SimanUnitTestsUser")
+ .setFirstName("TST_FirstName").setDisplayName("TST_test.user")
+ .addRole("TST_user").setMailAddress(
+ "noreply@salome-platform.org");
+ uprop.disableCheck();
+ User anAuthor = new User(uprop);
+ ht.update(anAuthor);
+
+ // Create a test study
+ Study.Properties stprops = new Study.Properties().setReference(
+ "TST_SID_01").setTitle("TST_Study").setManager(anAuthor);
+ Study aStudy = new Study(stprops);
+ ht.saveOrUpdate(aStudy);
+
+ // Create a test scenario
+ Scenario.Properties sprops = new Scenario.Properties().setTitle(
+ "TST_Study").setManager(anAuthor).setOwnerStudy(aStudy);
+ Scenario aScenario = new Scenario(sprops);
+ aStudy.getScenariiList().add(aScenario);
+ ht.saveOrUpdate(anAuthor);
+ ht.update(aStudy);
+ ht.saveOrUpdate(aScenario);
+
+ Document.Properties dprop = new Document.Properties().setAuthor(
+ anAuthor).setDate(new Date());
+ Step[] steps = _projectElementService.getSteps(aScenario);
+ Assert.assertTrue(steps.length > 0, "No steps are created.");
+ int i = 0;
+ for (Step step : steps) {
+ List<DocumentType> dtypes = _documentTypeService.selectTypesOf(step
+ .getStep());
+ dprop.setName("document" + i++).setType(dtypes.get(0));
+ // Create a document published in the scenario
+ Publication pub = _stepService.createDocument(step, dprop);
+ // Attach a file
+ _publicationService.attach(pub, "brep"); // TODO: test for different formats
+ }
+
+ return aScenario.getIndex();
+ }
+
+ /**
+ * Check that given objects are equal.
+ *
+ * @param anActual
+ * the object to check
+ * @param anExpected
+ * the expected object
+ */
+ private void compareObjects(final KnowledgeElement anActual,
+ final KnowledgeElement anExpected) {
+ Assert.assertNotNull(anActual,
+ "Created object is not found in the database.");
+ Assert.assertEquals(anActual.getAuthor(), anExpected.getAuthor(),
+ "Knowledge Element author is not saved.");
+ Assert.assertEquals(anActual.getDate(), anExpected.getDate(),
+ "Knowledge Element date is not saved.");
+ Assert
+ .assertEquals(anActual.getOwnerScenario(), anExpected
+ .getOwnerScenario(),
+ "Knowledge Element scenario is not saved.");
+ Assert.assertEquals(anActual.getProgressState(), anExpected
+ .getProgressState(), "Knowledge Element state is not saved.");
+ Assert.assertEquals(anActual.getTitle(), anExpected.getTitle(),
+ "Knowledge Element title is not saved.");
+ Assert.assertEquals(anActual.getType(), anExpected.getType(),
+ "Knowledge Element type is not saved.");
+ Assert.assertEquals(anActual.getValue(), anExpected.getValue(),
+ "Knowledge Element value is not saved.");
+ Assert.assertEquals(anActual.getIndex(), anExpected.getIndex(),
+ "Knowledge Element index is not saved.");
+ }
+}