Salome HOME
Creation of a new study from an existing one is implemented.
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / service / StudyServiceImpl.java
index d6bf598962b848b99a8c3eabad3be6d38c9481c9..40f106cc693b870862e5d6e894f6c03bc39c9534 100644 (file)
@@ -196,7 +196,9 @@ public class StudyServiceImpl implements StudyService {
        @Transactional
        public Study selectStudy(final long index) {
                Study result = getStudyDAO().get(index);
-               loadWorkflow(result);
+               if (result != null) {
+                       loadWorkflow(result);
+               }
                return result;
        }
 
@@ -241,14 +243,16 @@ public class StudyServiceImpl implements StudyService {
 
                        // Remove all relations of study documents
                        for (org.splat.dal.bo.som.Document doc : docums) {
-                               LOG.debug("Found doc: " + doc.getTitle() + " [" + doc.getReference() + "]" + " [" + doc.getRid() + "]");
+                               LOG.debug("Found doc: " + doc.getTitle() + " ["
+                                               + doc.getReference() + "]" + " [" + doc.getRid() + "]");
                                doc.getAllRelations().clear();
                        }
                        getDocumentDAO().flush();
 
                        // Remove all documents of the study
                        for (org.splat.dal.bo.som.Document doc : docums) {
-                               LOG.debug("Remove doc: " + doc.getTitle() + " [" + doc.getReference() + "]" + " [" + doc.getRid() + "]");
+                               LOG.debug("Remove doc: " + doc.getTitle() + " ["
+                                               + doc.getReference() + "]" + " [" + doc.getRid() + "]");
                                getDocumentDAO().delete(doc);
                        }
                }
@@ -400,17 +404,9 @@ public class StudyServiceImpl implements StudyService {
         *            the document
         * @return true if the document is published in the study
         */
-/*     private boolean publishes(final Study aStudy, final Document doc) {
-               if (!aStudy.publishes(doc)) {
-                       Scenario[] scene = aStudy.getScenarii();
-                       for (int i = 0; i < scene.length; i++) {
-                               if (scene[i].publishes(doc)) {
-                                       return true;
-                               }
-                       }
-               }
-               return false;
-       }
+       /*
+        * private boolean publishes(final Study aStudy, final Document doc) { if (!aStudy.publishes(doc)) { Scenario[] scene =
+        * aStudy.getScenarii(); for (int i = 0; i < scene.length; i++) { if (scene[i].publishes(doc)) { return true; } } } return false; }
         */
        /**
         * {@inheritDoc}
@@ -488,8 +484,7 @@ public class StudyServiceImpl implements StudyService {
 
                                validactor.put(cname, link.getTo()); // Replaces the cycle if exists as default,
                        } catch (BusinessException error) {
-                               LOG.error("Unable to create validation cycle, reason:",
-                                               error);
+                               LOG.error("Unable to create validation cycle, reason:", error);
                                return;
                        }
                }
@@ -1177,7 +1172,8 @@ public class StudyServiceImpl implements StudyService {
                }
                Study study = _studyDAO.get(studyId);
                if (study == null) {
-                       throw new InvalidParameterException(PARAM_STUDY_ID, studyId.toString());
+                       throw new InvalidParameterException(PARAM_STUDY_ID, studyId
+                                       .toString());
                }
                return study.getDescription();
        }
@@ -1196,7 +1192,8 @@ public class StudyServiceImpl implements StudyService {
                }
                Study study = _studyDAO.get(studyId);
                if (study == null) {
-                       throw new InvalidParameterException(PARAM_STUDY_ID, studyId.toString());
+                       throw new InvalidParameterException(PARAM_STUDY_ID, studyId
+                                       .toString());
                }
                study.setAttribute(new DescriptionAttribute(study, descriptionText));
        }
@@ -1252,17 +1249,19 @@ public class StudyServiceImpl implements StudyService {
                                        + "downloads" + File.separator + userName + File.separator
                                        + "ComparisonResult.pdf";
 
-                       XYSeries series = new XYSeries("Study: " + docDTO.getStudyTitle() + " Scenario: " + docDTO.getScenarioTitle() + " Document: " + docDTO.getDocumentTitle());
+                       XYSeries series = new XYSeries("Study: " + docDTO.getStudyTitle()
+                                       + " Scenario: " + docDTO.getScenarioTitle() + " Document: "
+                                       + docDTO.getDocumentTitle());
 
                        // read the file and get points information.
                        try {
                                Scanner input = new Scanner(compDocFile);
 
-                               //get the title of the chart.
+                               // get the title of the chart.
                                if (input.hasNext()) {
                                        chartTitle = input.nextLine();
                                }
-                               
+
                                // get the name of the axis.
                                if (input.hasNext()) {
                                        String[] tokens = input.nextLine().split(",");
@@ -1309,8 +1308,7 @@ public class StudyServiceImpl implements StudyService {
                        }
                } // for
 
-               JFreeChart chart = ChartFactory.createXYLineChart(
-                               chartTitle, // Title
+               JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, // Title
                                axis1Name, // x-axis Label
                                axis2Name, // y-axis Label
                                dataset, // Dataset
@@ -1552,98 +1550,102 @@ public class StudyServiceImpl implements StudyService {
         * @see org.splat.service.StudyService#getComparableStudies()
         */
        @Transactional(readOnly = true)
-       public List<StudyFacadeDTO> getComparableStudies(final long userId) throws MismatchException {
-               //retrieve the number of the "Analyze the results" step 
+       public List<StudyFacadeDTO> getComparableStudies(final long userId)
+                       throws MismatchException {
+               // retrieve the number of the "Analyze the results" step
                List<Step> allSteps = _projectSettings.getAllSteps();
                Step theAnalyzeStep = null;
-               for(Step step : allSteps) {
-                       if(step.getKey().equals("postprocessing")) {
+               for (Step step : allSteps) {
+                       if (step.getKey().equals("postprocessing")) {
                                theAnalyzeStep = step;
                        }
                }
-               if(theAnalyzeStep == null) {    //TODO: throw some other exception
-                       throw new MismatchException("no step with key 'postprocessing' found." +
-                                       "Probably, customization settings have been changed.");
+               if (theAnalyzeStep == null) { // TODO: throw some other exception
+                       throw new MismatchException(
+                                       "no step with key 'postprocessing' found."
+                                                       + "Probably, customization settings have been changed.");
                }
 
-               List<Publication> publications = _publicationDAO.getFilteredList("mydoc",
-                               Restrictions.eq("step", Integer.valueOf(theAnalyzeStep.getNumber())));
+               List<Publication> publications = _publicationDAO.getFilteredList(
+                               "mydoc", Restrictions.eq("step", Integer.valueOf(theAnalyzeStep
+                                               .getNumber())));
 
-               //split retrieved publications into groups by studies and scenarios
+               // split retrieved publications into groups by studies and scenarios
                Map<Study, List<ProjectElement>> studyMap = new HashMap<Study, List<ProjectElement>>();
-               Map<ProjectElement, List<Publication>> scenarioMap = 
-                               new HashMap<ProjectElement, List<Publication>>();
-               
-               for(Publication publication : publications) {                   
-                       //filter out publications corresponding to a document of given step which is not a _result_ document
-                       if(!publication.value().getType().isResultOf(theAnalyzeStep)
+               Map<ProjectElement, List<Publication>> scenarioMap = new HashMap<ProjectElement, List<Publication>>();
+
+               for (Publication publication : publications) {
+                       // filter out publications corresponding to a document of given step which is not a _result_ document
+                       if (!publication.value().getType().isResultOf(theAnalyzeStep)
                                        || !"srd".equals(publication.getSourceFile().getFormat())) {
                                continue;
                        }
-                       
-                       //check the study visibility to the user
-                       if(!isStaffedBy(publication.getOwnerStudy(), _userService.selectUser(userId))
-                                       && Visibility.PUBLIC.equals(publication.getOwnerStudy().getVisibility())) {
+
+                       // check the study visibility to the user
+                       if (!isStaffedBy(publication.getOwnerStudy(), _userService
+                                       .selectUser(userId))
+                                       && Visibility.PUBLIC.equals(publication.getOwnerStudy()
+                                                       .getVisibility())) {
                                continue;
                        }
-       
+
                        Study study = publication.getOwnerStudy();
                        ProjectElement scenario = publication.getOwner();
-                       
+
                        Hibernate.initialize(scenario);
-                   if (scenario instanceof HibernateProxy) {
-                       scenario = (ProjectElement) ((HibernateProxy) scenario).getHibernateLazyInitializer()
-                               .getImplementation();
-                   }
-                       
-                       if(!(scenario instanceof Scenario)) {
+                       if (scenario instanceof HibernateProxy) {
+                               scenario = (ProjectElement) ((HibernateProxy) scenario)
+                                               .getHibernateLazyInitializer().getImplementation();
+                       }
+
+                       if (!(scenario instanceof Scenario)) {
                                throw new MismatchException(
                                                "publications from postprocessing step are supposed to have owner scenario");
                        }
 
-                       if(!studyMap.containsKey(study)) {
+                       if (!studyMap.containsKey(study)) {
                                studyMap.put(study, new ArrayList<ProjectElement>());
                        }
-                       
-                       if(!studyMap.get(study).contains(scenario)) {
+
+                       if (!studyMap.get(study).contains(scenario)) {
                                studyMap.get(study).add(scenario);
                        }
 
-                       if(!scenarioMap.containsKey(scenario)) {
+                       if (!scenarioMap.containsKey(scenario)) {
                                scenarioMap.put(scenario, new ArrayList<Publication>());
                        }
                        scenarioMap.get(scenario).add(publication);
                }
-               
-               //Create the result DTOs
+
+               // Create the result DTOs
                List<StudyFacadeDTO> result = new ArrayList<StudyFacadeDTO>();
-               for(Study study : studyMap.keySet()) {
-                       
+               for (Study study : studyMap.keySet()) {
+
                        StudyFacadeDTO studyDTO = new StudyFacadeDTO();
                        studyDTO.setName(study.getTitle());
                        studyDTO.setScenarios(new ArrayList<StudyFacadeDTO.ScenarioDTO>());
                        result.add(studyDTO);
-                       
-                       for(ProjectElement scenario : studyMap.get(study)) {
-                               
+
+                       for (ProjectElement scenario : studyMap.get(study)) {
+
                                StudyFacadeDTO.ScenarioDTO scenarioDTO = new StudyFacadeDTO.ScenarioDTO();
                                scenarioDTO.setName(scenario.getTitle());
                                scenarioDTO.setDocs(new ArrayList<DocumentDTO>());
                                studyDTO.getScenarios().add(scenarioDTO);
 
-                               for(Publication publication : scenarioMap.get(scenario)) {
+                               for (Publication publication : scenarioMap.get(scenario)) {
 
                                        DocumentDTO documentDTO = new DocumentDTO();
                                        documentDTO.setId(publication.getIndex());
                                        documentDTO.setTitle(publication.value().getTitle());
-                                       
+
                                        scenarioDTO.getDocs().add(documentDTO);
                                }
                        }
-               }               
+               }
                return result;
        }
-       
+
        /**
         * Get the publicationDAO.
         *