<level value="DEBUG" />
</logger>
+ <logger name="org.splat.service.technical">
+ <level value="DEBUG" />
+ </logger>
+
+ <logger name="org.splat.service">
+ <level value="DEBUG" />
+ </logger>
+
+ <logger name="org.splat.dal.dao.som">
+ <level value="DEBUG" />
+ </logger>
+
<logger name="test">
<level value="DEBUG" />
</logger>
- <logger name="org.splat.util">
+<!-- <logger name="org.splat.util">
<level value="DEBUG" />
</logger>
-
<logger name="net.sf.beanlib.spi">
<level value="DEBUG" />
</logger>
+ -->
<logger name="log4j.logger.org.hibernate">
<level value="DEBUG" />
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
+import java.sql.Statement;
import java.util.Properties;
import org.apache.log4j.Logger;
public class Database extends org.splat.dal.dao.kernel.AbstractDatabase {
- public final static Logger LOG = org.splat.dal.dao.som.Database.LOG;
+ public final static Logger LOG = Logger.getLogger(org.splat.dal.dao.som.Database.class);
private transient int _uplevel = 0; // Level of database upgrade
private RepositoryService _repositoryService;
DatabaseMetaData dbmdata = connex.getMetaData();
String dbname = connex.getCatalog();
ResultSet table = null;
+ Statement st = connex.createStatement();
+ _uplevel = -1; // Database not initialized
try {
table = dbmdata.getTables(dbname, null, "study", null);
if (table.next()) {
- return;
+ table = dbmdata.getTables(dbname, null, "doctype", null);
+ if (table.next()) {
+ if (st.execute("SELECT name FROM doctype") &&
+ st.getResultSet().next() ) {
+ _uplevel = 0;
+ }
+ }
}
} catch (SQLException e) {
LOG.debug("Can't check the database version: ", e);
if (table != null) {
table.close();
}
+ if (st != null) {
+ st.close();
+ }
}
- _uplevel = -1; // Database not initialized
}
}
// ==============================================================================================================================
public boolean isInitialized() {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("The database is initialized: " + (_uplevel >= 0));
+ }
return (_uplevel >= 0);
}
* @param publicationService
* the publicationService to set
*/
- public void setPublicationService(final PublicationService publicationService) {
+ public void setPublicationService(
+ final PublicationService publicationService) {
_publicationService = publicationService;
}
_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);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Scenario[" + scenarioId + "]: Number of publications: "
+ + scen.getDocums().size());
+ }
Step[] steps = getProjectElementService().getSteps(scen);
StepDTO stepDTO;
DocumentDTO docDTO;
- for (Step step: steps) {
+ 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());
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Step[" + stepDTO.getNumber()
+ + "]: Number of documents: "
+ + step.getDocuments().size());
+ }
+ 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();
+ 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.
*
* if some property occurs several times
*/
@Transactional
- public Study createStudy(final Study.Properties sprop, final Scenario.Properties oprop,
- final SimulationContext.Properties cprop) throws MissedPropertyException,
- InvalidPropertyException, MultiplyDefinedException {
+ public Study createStudy(final Study.Properties sprop,
+ final Scenario.Properties oprop,
+ final SimulationContext.Properties cprop)
+ throws MissedPropertyException, InvalidPropertyException,
+ MultiplyDefinedException {
Study study = getStudyService().createStudy(sprop);
addScenario(study, oprop);
if (cprop.getIndex() == 0) { // Input of new project context
*/
@Transactional
public KnowledgeElement addKnowledgeElement(final Scenario aScenarioDTO,
- final KnowledgeElement.Properties kprop) throws MissedPropertyException,
- InvalidPropertyException, MultiplyDefinedException {
+ final KnowledgeElement.Properties kprop)
+ throws MissedPropertyException, InvalidPropertyException,
+ MultiplyDefinedException {
KnowledgeElement kelm = null;
try {
long aScenarioId = aScenarioDTO.getIndex();
} 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
+
+ // 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()) {
* @see org.splat.service.StudyService#addScenario(org.splat.dal.bo.som.Study, org.splat.dal.bo.som.Scenario.Properties)
*/
@Transactional
- public Scenario addScenario(final Study aStudy, final Scenario.Properties sprop)
- throws MissedPropertyException, InvalidPropertyException,
- MultiplyDefinedException {
+ public Scenario addScenario(final Study aStudy,
+ final Scenario.Properties sprop) throws MissedPropertyException,
+ InvalidPropertyException, MultiplyDefinedException {
if (sprop.getManager() == null) {
sprop.setManager(aStudy.getAuthor());
}
* @param knowledgeElementDAO
* the knowledgeElementDAO to set
*/
- public void setKnowledgeElementDAO(final KnowledgeElementDAO knowledgeElementDAO) {
+ public void setKnowledgeElementDAO(
+ final KnowledgeElementDAO knowledgeElementDAO) {
_knowledgeElementDAO = knowledgeElementDAO;
}
* Create in the database document types defined in the custom configuration.
*/
private void createDocumentTypes() {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Creating documents types...");
+ }
DocumentType.Properties tprop = new DocumentType.Properties();
Map<String, List<ProjectSettingsService.Step>> mapsteps = new HashMap<String, List<ProjectSettingsService.Step>>();
Map<String, ProjectSettingsService.Step> mapresult = new HashMap<String, ProjectSettingsService.Step>();
for (Iterator<String> i = tset.iterator(); i.hasNext();) {
type = i.next();
slist = mapsteps.get(type);
- uses = _mapuse.get(type);
- step = mapresult.get(type);
-
- tprop.clear();
- tprop.setName(type).setStep(
- slist.toArray(new ProjectSettingsService.Step[slist
- .size()]));
- if (uses != null) {
- tdoc = maptype.get(uses);
- if (tdoc == null) {
- LOG.warn("Undefined \"" + uses + "\" document type.");
- } else {
- tprop.setUses(tdoc);
+ if (slist != null) {
+ uses = _mapuse.get(type);
+ step = mapresult.get(type);
+
+ tprop.clear();
+ tprop.setName(type).setStep(
+ slist.toArray(new ProjectSettingsService.Step[slist
+ .size()]));
+ if (uses != null) {
+ tdoc = maptype.get(uses);
+ if (tdoc == null) {
+ LOG.warn("Undefined \"" + uses + "\" document type.");
+ } else {
+ tprop.setUses(tdoc);
+ }
}
+ if (step != null) {
+ tprop.setResult(step);
+ }
+
+ tprop.disableCheck();
+ tdoc = getDocumentTypeService().createType(tprop); // Creation of Document Types
+ getDocumentTypeService().approve(tdoc);
+ maptype.put(type, tdoc);
}
- if (step != null) {
- tprop.setResult(step);
- }
-
- tprop.disableCheck();
- tdoc = getDocumentTypeService().createType(tprop); // Creation of Document Types
- getDocumentTypeService().approve(tdoc);
- maptype.put(type, tdoc);
}
} catch (Exception error) {
LOG.warn("Error creating document types, reason:", error); // Should not happen
}
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Documents types are created: " + maptype.size());
+ }
}
/**
wapp.version = D-0.5
wapp.root = D:/users/rkv/SIMAN/SIMAN_SRC/Workspace/Siman/WebContent/
wapp.login = conf/login.conf
-wapp.configuration = conf/som.xml
+wapp.configuration = som.xml
wapp.customization = conf/my.xml
wapp.website = http://www.salome-platform.org
wapp.onlinehelp = http://docs.salome-platform.org/salome_6_3_1/gui/GUI_index.html
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+
+<project-structure>
+
+
+<!-- 1. Database physical location
+ -->
+ <database>
+ <repository disk="D:/users/rkv/SALOME_SIMER/rep" />
+ </database>
+
+
+<!-- 2. Formats
+ -->
+ <formats>
+
+<!-- 2.1 Project elements identification scheme
+ Studies, Knowledges and Documents are identified by unique user references. The structure of these references is customizable.
+ You customize references through patterns.
+ A reference's pattern is a character string including format directives. These format directives allow you to insert
+ some information into the reference. The following directives are available:
+ - %yy or %yyyy for inserting the entity creation year on 2 or 4 digits
+ - %0000 for inserting a unique index, the number of digits being defined by the number of 0
+ The above index is unique in the scope of cycle defined by the first format directive (year). In other words, this index
+ restarts every new year. As such, for making references unique on this application server, both format directives (cycle
+ and index) must be present in the pattern.
+ Other characters are simply inserted as is in generated references. They can be used for extending the reference uniqueness
+ beyond application servers, by adding a prefix specific to a given server (for example, a company department name).
+ Given that these references may be used as directory or file names of the repository vault, the pattern must not include
+ illicit characters such as '/', '?', '<' etc.
+ -->
+ <references study="DER%yy%0000"/>
+
+<!-- 2.2 Physical files naming scheme
+ The physical data files stored into the repository vault can be named as follows:
+ - By the user-defined title of corresponding documents ("title" name attribute below)
+ - Encoded by a built-in scheme ("encoded" name attribute)
+ - As is, that is, by keeping the name of the imported file ("asis" name attribute - not yet supported)
+ Remarks:
+ - When using the title scheme, as file names may include accent characters, client browsers must be configured for
+ NOT encoding URLs as UTF-8.
+ - Whatever is the naming scheme used, in order to avoid name clashes, file names are anyway suffixed by an index
+ unique in the scope of the owner study.
+ -->
+ <files name="encoded"/>
+
+<!-- 2.3 Document versions format
+ -->
+ <versions pattern="%M.%m[-%s]"/>
+ </formats>
+
+
+<!-- 3. Document types
+
+ Warning: Articles must be ordered in a way that used document types (uses attribute values) must previously be defined.
+ Example: "requirements" type must be defined before "specification" because "specification" uses "requirements".
+ Remarks:
+ - "knowledge" is a reserved word qualifying Knowledge Elements. So, it must not be used as a document type name.
+ - "default" and "built-in" are also reserved words used for defining validation cycles.
+ - In this version, the "uses" attribute is limited to 1 document type only.
+ -->
+ <documents>
+ <article type="requirements"/>
+ <article type="specification" uses="requirements"/>
+ <article type="design" uses="specification"/>
+ <article type="geometry" uses="design"/>
+ <article type="model" uses="geometry"/>
+ <article type="loads" uses="model"/>
+ <article type="script" uses="loads"/>
+ <article type="log" uses="script"/>
+ <article type="results" uses="script"/>
+ <article type="report" uses="results"/>
+ <article type="memorandum"/>
+ <article type="minutes"/>
+ </documents>
+
+
+<!-- 4. Simulation Context types
+
+ Warning: The Simulation Context type "product" is mandatory as it is used by at least one application.
+ -->
+ <contexts>
+
+ <!-- General information -->
+ <article type="customer"/>
+ <article type="product"/>
+ <article type="phase"/> <!-- Phase of the product -->
+ <article type="need"/> <!-- Customer needs -->
+ <article type="purpose"/> <!-- Objective of the study -->
+ <article type="physic"/> <!-- Structure analysis, Thermal-hydraulics, Neutronic... -->
+
+ <!-- Geometry characteristics Examples: -->
+ <article type="object"/> <!-- Car, Plane, Equipment... -->
+ <article type="part"/> <!-- Crankcase, Outer layer... -->
+ <artivle type="geometry"/> <!-- Surface, Volume -->
+
+ <!-- Model characteristics Examples: -->
+ <article type="model"/> <!-- CSG, FEM... -->
+ <article type="element"/> <!-- Bar, Surface, Volume -->
+ <article type="shape"/> <!-- (Surface) Triangle, Quadrangle... (Volume) Tetrahedron, Hexahedron... -->
+ <article type="order"/> <!-- First-order, Second-order... -->
+
+ <!-- Analysis type Examples: -->
+ <article type="analysis"/> <!-- Static, Dynamic... -->
+
+ <!-- Software tools used -->
+ <article type="platform"/>
+ <article type="module"/>
+ <article type="component"/>
+ </contexts>
+
+
+<!-- 5. Knowledge Elements types
+
+ Warning: The Knowledge Elements type "usecase" is reserved for internal use.
+ -->
+ <knowledges>
+ <article type="bestpractice"/>
+ <article type="limitation"/>
+ <article type="inconsistency"/>
+ <article type="metrics"/>
+ <article type="improvement"/>
+ </knowledges>
+
+
+<!-- 6. User activities
+
+ Remarks:
+ - Step names must naturally be unique.
+ - Simulation Contexts must be attached to one classification step only.
+ - Result document types must be results of one step only and be part of contents of the corresponding step.
+ -->
+ <activities>
+ <step name="specification">
+ <classification context="customer,product,phase,need,purpose,physic"/>
+ <flow contents="requirements,specification,minutes" result="specification"/>
+ <storage path="1.Study"/>
+ </step>
+ <scenario>
+ <step name="design">
+ <flow contents="design,memorandum,minutes" result="design"/>
+ <storage path="1.Study"/>
+ </step>
+ <step name="modeling">
+ <classification context="object,part,geometry"/>
+ <flow contents="geometry,memorandum,minutes" result="geometry"/>
+ <storage path="2.Geometry"/>
+ <module name="GEOM"/>
+ </step>
+ <step name="meshing">
+ <classification context="model,element,shape,order"/>
+ <flow contents="model,memorandum,minutes" result="model"/>
+ <storage path="3.Mesh"/>
+ <module name="SMESH"/>
+ </step>
+ <step name="solving">
+ <classification context="loads,script,platform,module,component"/>
+ <flow contents="log,results,minutes" result="results"/>
+ <storage path="5.Result"/>
+ <module name="CASTEM"/>
+ </step>
+ <step name="postprocessing">
+ <flow contents="memorandum,minutes"/>
+ <storage path="6.Report"/>
+ </step>
+ <step name="capitalization">
+ <flow contents="knowledge"/>
+ <storage path="6.Report"/>
+ </step>
+ </scenario>
+ <step name="reporting">
+ <flow contents="report,minutes" result="report"/>
+ <storage path="1.Study"/>
+ </step>
+ </activities>
+
+
+<!-- 6. Document validation cycles
+ Validation cycles define the actors involved in the validation steps of documents. These steps can be
+ "review", "approval" and "acceptance".
+ Remarks:
+ - Each validation cycle is defined by a tag corresponding to the type of an activity result document.
+ - The actors of validation steps can be
+ "manager", referring the responsible of study,
+ "Nx1", referring the manager of the department (see User definition for more information),
+ "Nx2", referring the boss of the department manager,
+ "customer" (most likely involved in the acceptance step).
+ -->
+ <validations>
+ <specification review="Nx1" approval="Nx2"/>
+ <report review="Nx1" approval="Nx2"/>
+ <default review="manager" />
+ </validations>
+
+<!-- 3. Check-in check-out information
+ Defines the way documents involved in the check-in check-out operations must be processed.
+ -->
+ <mappings>
+ <document type="geometry">
+ <source format="step" process="file-download"/> <!-- Geometry created from STEP import -->
+ <source format="py" process="file-download"/> <!-- Geometry created from Python execution -->
+ <source format="xml" process="ocaf-import"/> <!-- Geometry created interactively -->
+ <export format="brep"/> <!-- Result Shape -->
+ </document>
+ <document type="model">
+ <source format="py" process="file-download"/> <!-- Mesh created from Python execution -->
+ <source format="xml" process="ocaf-import"/> <!-- Mesh including input parameters -->
+ <export format="med"/> <!-- Result mesh without input parameters -->
+ </document>
+ <document type="loads">
+ <source format="py" process="file-download"/> <!-- Input data created from Python execution -->
+ <source format="c3m" process="c3m-import"/> <!-- Input data created interactively -->
+ </document>
+ <document type="results">
+ <source format="med" process="med-import"/> <!-- Calculation results source file -->
+ </document>
+ </mappings>
+</project-structure>
\ No newline at end of file
*/
@Autowired
@Test(enabled = false)
- public void setSessionFactory(@Qualifier("simanSessionFactory") SessionFactory aSessionFactory) {
+ public void setSessionFactory(@Qualifier("simanSessionFactory")
+ final SessionFactory aSessionFactory) {
_hibernateTemplate = new HibernateTemplate(aSessionFactory);
}
*****************************************************************************/
package test.splat.service;
+import java.io.FileNotFoundException;
import java.io.IOException;
+import java.sql.SQLException;
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.service.PublicationService;
import org.splat.service.ScenarioService;
import org.splat.service.StepService;
+import org.splat.service.dto.DocumentDTO;
+import org.splat.service.dto.FileDTO;
import org.splat.service.dto.StepDTO;
-import org.splat.som.Step;
+import org.splat.service.technical.ProjectSettingsService;
+import org.splat.service.technical.ProjectSettingsService.Step;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.orm.hibernate3.HibernateTemplate;
* @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
*
*/
+@Test(sequential = true, groups = { "service", "functional", "business" })
public class TestScenarioService extends BaseTest {
/**
@Qualifier("projectElementService")
private transient ProjectElementService _projectElementService;
+ /**
+ * The ProjectSettingsService. Later injected by Spring.
+ */
+ @Autowired
+ @Qualifier("projectSettings")
+ private transient ProjectSettingsService _projectSettings;
+
/**
* The DocumentTypeService. Later injected by Spring.
*/
* if a mandatory property is not defined for an object to be created
* @throws IOException
* if scenario creation is failed
- *
+ * @throws SQLException
+ * if scenario creation is failed
*/
@Test
public void testGetScenarioInfo() throws InvalidPropertyException,
- MissedPropertyException, MultiplyDefinedException, IOException {
+ MissedPropertyException, MultiplyDefinedException, IOException,
+ SQLException {
LOG.debug(">>>>> BEGIN testGetScenarioInfo()");
long scenarioId = createScenario();
// Call DAO's create method for a good transient knowledge element.
Assert.assertNotNull(steps, "List of steps must not be null.");
Assert.assertTrue(steps.size() > 0, "No steps are read.");
+ List<Step> projSteps = _projectSettings.getStepsOf(Scenario.class);
+ Assert.assertEquals(steps.size(), projSteps.size(),
+ "Not all steps are listed.");
+ int docIndex = 0;
+ for (StepDTO step : steps) {
+ LOG.debug("check the step " + step.getNumber() + ":\n" + step);
+ Assert.assertNotNull(step, "Step DTO must not be null.");
+ Assert.assertNotNull(step.getKey(), "Step name must not be null.");
+ Assert.assertFalse(step.getKey().isEmpty(),
+ "Step name must not empty.");
+ Assert.assertTrue(step.getNumber() > 0,
+ "Step number must be positive integer.");
+ Assert.assertNotNull(step.getDocs(),
+ "Step documents list must not be null.");
+
+ Step aProjStep = null;
+ for (Step projStep : projSteps) {
+ if (projStep.getNumber() == step.getNumber()) {
+ aProjStep = projStep;
+ break;
+ }
+ }
+
+ List<DocumentType> dtypes = _documentTypeService
+ .selectTypesOf(aProjStep);
+ for (DocumentType dtype : dtypes) {
+ Assert.assertTrue(step.getDocs().size() > 0,
+ "Step documents list must not be empty.");
+ String docName = "document" + docIndex;
+ docIndex++;
+ for (DocumentDTO doc : step.getDocs()) {
+ if (docName.equals(doc.getTitle())) {
+ Assert.assertTrue(doc.getId() > 0,
+ "Document id must be positive integer.");
+ Assert.assertEquals(doc.getTitle(), docName);
+ Assert.assertNotNull(doc.getFiles(),
+ "Document files list must not be null.");
+ Assert.assertTrue(doc.getFiles().size() > 1,
+ "Document must have more then 1 attached file.");
+
+ for (FileDTO file : doc.getFiles()) {
+ Assert.assertNotNull(file.getPath(),
+ "File path must not be null.");
+ Assert.assertFalse(file.getPath().isEmpty(),
+ "File path must not be empty.");
+ Assert.assertEquals(file.getState(), 'Y',
+ "File state must be actual ('Y').");
+ }
+ }
+ }
+ }
+ }
+
// Call DAO's get method for a not existing id.
try {
steps = _scenarioService.getScenarioInfo(-1L);
* if a mandatory property is not defined for an object to be created
* @throws IOException
* if document creation is failed
+ * @throws SQLException
+ * if project settings loading is failed
*/
private long createScenario() throws InvalidPropertyException,
- MissedPropertyException, MultiplyDefinedException, IOException {
+ MissedPropertyException, MultiplyDefinedException, IOException,
+ SQLException {
// Create a scenario for tests
HibernateTemplate ht = getHibernateTemplate();
+ // Load workflow customization
+ try {
+ _projectSettings.configure("src/test/som.xml");
+ } catch (FileNotFoundException e) {
+ Assert.fail("Can't find som.xml: ", e);
+ }
+ List<Step> steps = _projectSettings.getStepsOf(Scenario.class);
+ Assert.assertTrue(steps.size() > 0, "No steps are created.");
+
// Create a test user
User.Properties uprop = new User.Properties();
uprop.setUsername("TST_Username").setName("TST_SimanUnitTestsUser")
"noreply@salome-platform.org");
uprop.disableCheck();
User anAuthor = new User(uprop);
- ht.update(anAuthor);
+ ht.save(anAuthor);
// Create a test study
Study.Properties stprops = new Study.Properties().setReference(
Scenario aScenario = new Scenario(sprops);
aStudy.getScenariiList().add(aScenario);
ht.saveOrUpdate(anAuthor);
- ht.update(aStudy);
+ ht.saveOrUpdate(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.");
+ // Create documents
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
+ LOG.debug("Create scenario step: " + i);
+
+ org.splat.som.Step aScStep = new org.splat.som.Step(step, aScenario);
+ List<DocumentType> dtypes = _documentTypeService
+ .selectTypesOf(step);
+ for (DocumentType dtype : dtypes) {
+ dprop.setName("document" + i++).setType(dtype).setFormat(
+ dtype.getName());
+ // Create a document published in the scenario
+ Publication pub = _stepService.createDocument(aScStep, dprop);
+ Assert.assertNotNull(pub.getOwner(),
+ "The publication must be attached to the scenario.");
+ Assert.assertEquals(pub.getOwner().getIndex(), aScenario
+ .getIndex(),
+ "The publication was not attached to the scenario.");
+
+ aScenario.add(pub);
+ ht.saveOrUpdate(pub);
+
+ // Attach a file
+ ht.saveOrUpdate(pub.value());
+ ht.saveOrUpdate(_publicationService.attach(pub, "med"));
+ }
+ if (dtypes.size() <= 0) {
+ LOG.debug("No document types are found for scenario step " + i);
+ }
}
- return aScenario.getIndex();
- }
+ Assert.assertNotNull(ht.find("from Document"),
+ "No documents in the database.");
+ Assert.assertTrue(ht.find("from Document").size() > 0,
+ "No documents in the database.");
- /**
- * 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.");
+ Assert.assertNotNull(ht.find("from Publication where owner="
+ + aScenario.getIndex()), "No publications in the database.");
+ Assert.assertTrue(
+ ht.find("from Publication where owner=" + aScenario.getIndex())
+ .size() > 0, "No publications in the database.");
+
+ for (Publication p : (List<Publication>) ht
+ .find("from Publication where owner=" + aScenario.getIndex())) {
+ LOG.debug("Publication found: [id=" + p.getIndex() + ", owner="
+ + p.getOwner().getIndex() + ", doc=" + p.value().getIndex()
+ + "]");
+ Assert.assertEquals(p.getOwner().getIndex(), aScenario.getIndex(),
+ "The publication was not attached to the scenario.");
+ }
+
+ ht.evict(aScenario);
+ Scenario aScen = ht.load(Scenario.class, aScenario.getIndex());
+ Assert.assertNotNull(aScen, "Scenario was not saved in the database.");
+ Assert.assertTrue(aScen.getDocums().size() > 0,
+ "No publications in the scenario.");
+
+ Assert.assertTrue(i > 0,
+ "More then one document must be in the database");
+
+ return aScenario.getIndex();
}
}