Salome HOME
Processing instruction is defined now in getScenarioInfo using document types mappings.
authorrkv <rkv@opencascade.com>
Mon, 19 Nov 2012 06:46:44 +0000 (06:46 +0000)
committerrkv <rkv@opencascade.com>
Mon, 19 Nov 2012 06:46:44 +0000 (06:46 +0000)
Workspace/Siman-Common/src/org/splat/service/ScenarioServiceImpl.java
Workspace/Siman-Common/src/org/splat/service/dto/DocumentDTO.java
Workspace/Siman-Common/src/org/splat/service/dto/FileDTO.java
Workspace/Siman-Common/src/spring/businessServiceContext.xml
Workspace/Siman-Common/src/test/splat/service/TestScenarioService.java

index 77f04df5618f186e303f40178294cc3904681d99..705b534d17d9ec978a689894cac6c004bbd9137a 100644 (file)
@@ -37,6 +37,7 @@ 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.service.technical.ProjectSettingsService;
 import org.splat.som.Step;
 import org.splat.util.BeanHelper;
 import org.springframework.transaction.annotation.Transactional;
@@ -113,6 +114,11 @@ public class ScenarioServiceImpl implements ScenarioService {
         */
        private SimulationContextService _simulationContextService;
 
+       /**
+        * Injected project service.
+        */
+       private ProjectSettingsService _projectSettings;
+
        /**
         * Get the projectElementService.
         * 
@@ -180,14 +186,20 @@ public class ScenarioServiceImpl implements ScenarioService {
        @Transactional
        public List<StepDTO> getScenarioInfo(final long scenarioId) {
                List<StepDTO> res = new ArrayList<StepDTO>();
+               // Get the scenario from the database by id
                Scenario scen = getScenarioDAO().get(scenarioId);
                if (LOG.isDebugEnabled()) {
                        LOG.debug("Scenario[" + scenarioId + "]: Number of publications: "
                                        + scen.getDocums().size());
                }
+               // Get activities of the scenario
                Step[] steps = getProjectElementService().getSteps(scen);
                StepDTO stepDTO;
                DocumentDTO docDTO;
+               String docType, fileFormat;
+               String processing;
+               boolean doImport;
+               // For each activity create a step DTO and add it to the result list
                for (Step step : steps) {
                        stepDTO = BeanHelper.copyBean(step.getStep(), StepDTO.class);
                        res.add(stepDTO);
@@ -196,15 +208,38 @@ public class ScenarioServiceImpl implements ScenarioService {
                                                + "]: Number of documents: "
                                                + step.getDocuments().size());
                        }
+                       // For each publication of the activity create a document DTO.
+                       // Each file is considered as a source file.
                        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);
+                               docType = tag.value().getType().getName();
+                               // For each file of the document create a file DTO
+                               // Process source file of the document
+                               fileFormat = tag.value().getFile().getFormat();
+                               doImport = getProjectSettings().doImport(docType, fileFormat);
+                               if (doImport && (!tag.isOutdated())) {
+                                       processing = "file-import";
+                               } else {
+                                       processing = "file-download";
+                               }
+                               docDTO.addFile(tag.value().getFile().getRelativePath(), aState,
+                                               processing, false);
+                               // Process all exported files
                                for (Relation rel : tag.value().getRelations(
                                                ConvertsRelation.class)) {
                                        File aFile = ((ConvertsRelation) rel).getTo();
-                                       docDTO.addFile(aFile.getRelativePath(), aState);
+                                       fileFormat = aFile.getFormat();
+                                       doImport = getProjectSettings().doImport(docType,
+                                                       fileFormat);
+                                       if (doImport && (!tag.isOutdated())) {
+                                               processing = "file-import";
+                                       } else {
+                                               processing = "file-download";
+                                       }
+                                       docDTO.addFile(aFile.getRelativePath(), aState, processing,
+                                                       false);
                                }
                        }
                }
@@ -683,4 +718,24 @@ public class ScenarioServiceImpl implements ScenarioService {
                _simulationContextService = simulationContextService;
        }
 
+       /**
+        * Get project settings.
+        * 
+        * @return Project settings service
+        */
+       private ProjectSettingsService getProjectSettings() {
+               return _projectSettings;
+       }
+
+       /**
+        * Set project settings service.
+        * 
+        * @param projectSettingsService
+        *            project settings service
+        */
+       public void setProjectSettings(
+                       final ProjectSettingsService projectSettingsService) {
+               _projectSettings = projectSettingsService;
+       }
+
 }
index 8652cd96436b1773a1b8316e004c938fc9d335f8..c7fbda68aeedcd3b28c728e899d11f839e5ac6ff 100644 (file)
@@ -97,10 +97,15 @@ public class DocumentDTO {
         *            relative file path
         * @param state
         *            file state
+        * @param processing
+        *            processing instruction: file-download or file-import
+        * @param isResult
+        *            true if the file is result
         * @return the added file DTO
         */
-       public FileDTO addFile(final String relativePath, final char state) {
-               FileDTO fileDTO = new FileDTO(relativePath, state);
+       public FileDTO addFile(final String relativePath, final char state,
+                       final String processing, final boolean isResult) {
+               FileDTO fileDTO = new FileDTO(relativePath, state, processing, isResult);
                _files.add(fileDTO);
                return fileDTO;
        }
@@ -115,8 +120,8 @@ public class DocumentDTO {
                StringBuffer buf = new StringBuffer();
                String indent = "    ";
                buf.append(indent).append("Document: ").append(getTitle()).append('\n')
-                               .append(indent).append("    Document ID: ").append(getId())
-                               .append('\n');
+                               .append(indent).append("Document ID: ").append(getId()).append(
+                                               '\n');
                for (FileDTO file : getFiles()) {
                        buf.append(file);
                }
index 0dda6c5e2848eb1b4b70ae6768da666e4a7154c6..b7ba42f1487b6b5dc6c22a4e59c5b2cbaf3e7493 100644 (file)
@@ -39,10 +39,17 @@ public class FileDTO {
         *            relative file path
         * @param state
         *            file state
+        * @param processing
+        *            processing instruction: file-download or file-import
+        * @param isResult
+        *            true if the file is result
         */
-       public FileDTO(final String relativePath, final char state) {
+       public FileDTO(final String relativePath, final char state,
+                       final String processing, final boolean isResult) {
                _path = relativePath;
                _state = state;
+               _processing = processing;
+               _isResult = isResult;
        }
 
        /**
index e27afec311d9a4b878c3cd9f25e09a7e346402b0..8fb2dbb8063f461c1b8e49cdf9e26166c2bf3801 100644 (file)
@@ -76,6 +76,7 @@ http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
                <property name="indexService" ref="indexService" />
                <property name="projectElementService"
                        ref="projectElementService" />
+        <property name="projectSettings" ref="projectSettings" />
                <property name="publicationService" ref="publicationService" />
                <property name="stepService" ref="stepService" />
                <property name="studyService" ref="studyService" />
index a0557c6e92456a7483d30c944c755f89611e59b4..364e55f2511865c3f11be1fbb22ebbbac9adcf0e 100644 (file)
@@ -178,7 +178,6 @@ public class TestScenarioService extends BaseTest {
                                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,
@@ -194,11 +193,58 @@ public class TestScenarioService extends BaseTest {
                                                                        "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').");
+                                                       /*                                                      
+                                                   <mappings>
+                                                       <document type="geometry">
+                                                           <import format="brep"/>     <!-- Result Shape                             -->
+                                                       </document>
+                                                       <document type="model">
+                                                           <import format="med"/>      <!-- Result mesh without input parameters     -->
+                                                       </document>
+                                                       <document type="loads">
+                                                           <import format="c3m"/>      <!-- Input data created interactively         -->
+                                                       </document>
+                                                       <document type="results">
+                                                           <import format="med"/>      <!-- Calculation results source file          -->
+                                                       </document>
+                                               </mappings>
+                                                        */
+                                                       // Check state and processing instruction
+                                                       String fileFormat = file.getPath().substring(
+                                                                       file.getPath().lastIndexOf('.') + 1);
+/*                                                     if (_projectSettings.doImport(dtype.getName(),
+                                                                       fileFormat)) {
+                                                               Assert.assertTrue(file.isResult(),
+                                                                               "The file must be a result file.");
+                                                       } else {
+                                                               Assert.assertFalse(file.isResult(),
+                                                                               "The file must be a source file.");
+                                                       }
+*/                                                     if ((docIndex % 2) == 0) { // New
+                                                               Assert.assertEquals(file.getState(), 'Y',
+                                                                               "File state must be actual ('Y').");
+                                                               if (_projectSettings.doImport(dtype.getName(),
+                                                                               fileFormat)) {
+                                                                       Assert.assertEquals(file.getProcessing(),
+                                                                                       "file-import",
+                                                                                       "File must be imported.");
+                                                               } else {
+                                                                       Assert.assertEquals(file.getProcessing(),
+                                                                                       "file-download",
+                                                                                       "File must be downloaded.");
+                                                               }
+                                                       } else { // Outdated
+                                                               Assert.assertEquals(file.getState(), 'O',
+                                                                               "File state must be actual ('O').");
+                                                               Assert
+                                                                               .assertEquals(file.getProcessing(),
+                                                                                               "file-download",
+                                                                                               "Outdated document should not be imported but downloaded.");
+                                                       }
                                                }
                                        }
                                }
+                               docIndex++;
                        }
                }
 
@@ -282,8 +328,11 @@ public class TestScenarioService extends BaseTest {
                                        .selectTypesOf(step);
                        for (DocumentType dtype : dtypes) {
                                dprop.setName("document" + i++).setType(dtype).setFormat(
-                                               dtype.getName());
+                                               "brep");
                                // Create a document published in the scenario
+                               // document<i>: document type[0] - first type used on the step
+                               //      <source-file>.brep
+                               //      <attached-file>.med
                                Publication pub = _stepService.createDocument(aScStep, dprop);
                                Assert.assertNotNull(pub.getOwner(),
                                                "The publication must be attached to the scenario.");
@@ -297,6 +346,29 @@ public class TestScenarioService extends BaseTest {
                                // Attach a file
                                ht.saveOrUpdate(pub.value());
                                ht.saveOrUpdate(_publicationService.attach(pub, "med"));
+                               
+                               // Create a document with outdated publication
+                               dprop.setName("document" + i++).setType(dtype).setFormat(
+                               "brep");
+                               // Create a document published in the scenario
+                               // document<i>: document type[0] - first type used on the step
+                               //      <source-file>.brep
+                               //      <attached-file>.med
+                               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.");
+               
+                               pub.setIsnew('O');
+                               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);