Salome HOME
Processing instruction is defined now in getScenarioInfo using document types mappings.
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / service / ScenarioServiceImpl.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;
+       }
+
 }