Salome HOME
Fix:
authorrkv <rkv@opencascade.com>
Thu, 18 Apr 2013 06:49:06 +0000 (06:49 +0000)
committerrkv <rkv@opencascade.com>
Thu, 18 Apr 2013 06:49:06 +0000 (06:49 +0000)
1) Popup menu item "Remove" must become disabled after importing a document for all depending documents without manual study refreshing;
2) Comparison functionality now takes into account current user for studies visibility.

Workspace/Siman-Common/src/org/splat/service/StudyComparisonService.java [new file with mode: 0644]
Workspace/Siman-Common/src/org/splat/service/StudyComparisonServiceImpl.java [new file with mode: 0644]
Workspace/Siman-Common/src/org/splat/service/StudyService.java
Workspace/Siman-Common/src/org/splat/service/StudyServiceImpl.java
Workspace/Siman-Common/src/spring/businessServiceContext.xml
Workspace/Siman/src/org/splat/simer/CompareStudyAction.java
Workspace/Siman/src/org/splat/simer/ImportDocumentAction.java
Workspace/Siman/src/org/splat/simer/OpenStudy.java
Workspace/Siman/src/spring/applicationContext.xml

diff --git a/Workspace/Siman-Common/src/org/splat/service/StudyComparisonService.java b/Workspace/Siman-Common/src/org/splat/service/StudyComparisonService.java
new file mode 100644 (file)
index 0000000..b0a5221
--- /dev/null
@@ -0,0 +1,42 @@
+package org.splat.service; 
+
+import java.util.List;
+
+import org.splat.exception.IncompatibleDataException;
+import org.splat.kernel.MismatchException;
+import org.splat.service.dto.DocToCompareDTO;
+import org.splat.service.dto.DocumentDTO;
+import org.splat.service.dto.StudyFacadeDTO;
+import org.splat.service.dto.StudyFacadeDTO.ScenarioDTO;
+
+public interface StudyComparisonService {
+       
+       /**
+        * Compare the studies and generate the file that contains the result chart.
+        * 
+        * @param docsList
+        *            the list of dtos each contains information: StudyTitle, ScenarioTitle, PathToFile in vault.
+        * @param userName
+        *            the name of the user who compare the results.
+        * @throws IncompatibleDataException
+        *             if data is incompatible for "Compare the studies" functionality.
+        * 
+        * @return path to result file in the vault.
+        */
+       String compare(List<DocToCompareDTO> docsList, final String userName)
+                       throws IncompatibleDataException;
+
+       /**
+        * Get studies, scenarios and publications available for comparison. <br>
+        * <b> DocumentDto.id are actually filled in with Publication ids.</b>
+        * 
+        * @param userId
+        *            id of the user to to whom visible studies will be returned.
+        * @return list of {@link StudyFacadeDTO} containing lists of {@link ScenarioDTO} containing list of {@link DocumentDTO}, corresponding
+        *         to to the publications available for comparison, with ids and titles filled in.
+        * @throws MismatchException
+        *             if some configurations considering postprocessing step are invalid.
+        */
+       List<StudyFacadeDTO> getComparableStudies(final long userId)
+                       throws MismatchException;
+}
diff --git a/Workspace/Siman-Common/src/org/splat/service/StudyComparisonServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/StudyComparisonServiceImpl.java
new file mode 100644 (file)
index 0000000..714576a
--- /dev/null
@@ -0,0 +1,398 @@
+package org.splat.service; 
+
+import java.awt.Graphics2D;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Scanner;
+
+import org.hibernate.Hibernate;
+import org.hibernate.criterion.Restrictions;
+import org.hibernate.proxy.HibernateProxy;
+import org.jfree.chart.ChartFactory;
+import org.jfree.chart.JFreeChart;
+import org.jfree.chart.plot.PlotOrientation;
+import org.jfree.data.xy.XYSeries;
+import org.jfree.data.xy.XYSeriesCollection;
+import org.splat.common.properties.MessageKeyEnum;
+import org.splat.dal.bo.kernel.User;
+import org.splat.dal.bo.som.ProjectElement;
+import org.splat.dal.bo.som.Publication;
+import org.splat.dal.bo.som.Scenario;
+import org.splat.dal.bo.som.Study;
+import org.splat.dal.bo.som.Visibility;
+import org.splat.dal.dao.som.PublicationDAO;
+import org.splat.exception.IncompatibleDataException;
+import org.splat.kernel.MismatchException;
+import org.splat.log.AppLogger;
+import org.splat.service.dto.DocToCompareDTO;
+import org.splat.service.dto.DocumentDTO;
+import org.splat.service.dto.Proxy;
+import org.splat.service.dto.StudyFacadeDTO;
+import org.splat.service.dto.StudySearchFilterDTO;
+import org.splat.service.technical.ProjectSettingsService;
+import org.splat.service.technical.ProjectSettingsService.Step;
+import org.springframework.transaction.annotation.Transactional;
+
+import com.lowagie.text.Document;
+import com.lowagie.text.DocumentException;
+import com.lowagie.text.Rectangle;
+import com.lowagie.text.pdf.DefaultFontMapper;
+import com.lowagie.text.pdf.PdfContentByte;
+import com.lowagie.text.pdf.PdfTemplate;
+import com.lowagie.text.pdf.PdfWriter;
+
+public class StudyComparisonServiceImpl implements StudyComparisonService {
+
+       /**
+        * logger for the service.
+        */
+       public final static AppLogger LOG = AppLogger
+                       .getLogger(StudyServiceImpl.class);
+
+       /**
+        * Injected project service.
+        */
+       private ProjectSettingsService _projectSettings;
+
+       /**
+        * Injected publication DAO.
+        */
+       private PublicationDAO _publicationDAO;
+
+       /**
+        * Injected user service.
+        */
+       private UserService _userService;
+       
+       /**
+        * Injected search service.
+        */
+       private SearchService _searchService;
+       
+       
+       /** 
+        * {@inheritDoc}
+        * @see org.splat.service.StudyComparisonService#getComparableStudies(long)
+        */
+       @Transactional(readOnly = true)
+       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")) {
+                               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.");
+               }
+
+               List<Publication> publications = _publicationDAO.getFilteredList(
+                               "mydoc", Restrictions.eq("step", Integer.valueOf(theAnalyzeStep
+                                               .getNumber())));
+
+               // 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>>();
+
+               // Get visible studies
+               StudySearchFilterDTO filter = new StudySearchFilterDTO();
+               User user = (_userService.selectUser(userId));
+               if(user != null) {
+                       filter.setConnectedUserId(userId);
+               }
+               List<Proxy> vizibleStudies = _searchService.selectStudiesWhere(filter);
+               
+               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())) {
+                               continue;
+                       }
+*/
+                       Study study = publication.getOwnerStudy();
+                       ProjectElement scenario = publication.getOwner();
+                       
+                       // check the study visibility to the user
+                       boolean contains = false;
+                       for(Proxy aStudy : vizibleStudies) {
+                               if(aStudy.getIndex().longValue() == study.getIndex()) {
+                                       contains = true;
+                               }
+                       }                       
+                       if(!contains && !Visibility.PUBLIC.equals(publication.getOwnerStudy().getVisibility())) {
+                               continue;
+                       }
+                       
+                       Hibernate.initialize(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)) {
+                               studyMap.put(study, new ArrayList<ProjectElement>());
+                       }
+
+                       if (!studyMap.get(study).contains(scenario)) {
+                               studyMap.get(study).add(scenario);
+                       }
+
+                       if (!scenarioMap.containsKey(scenario)) {
+                               scenarioMap.put(scenario, new ArrayList<Publication>());
+                       }
+                       scenarioMap.get(scenario).add(publication);
+               }
+
+               // Create the result DTOs
+               List<StudyFacadeDTO> result = new ArrayList<StudyFacadeDTO>();
+               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)) {
+
+                               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)) {
+
+                                       DocumentDTO documentDTO = new DocumentDTO();
+                                       documentDTO.setId(publication.getIndex());
+                                       documentDTO.setTitle(publication.value().getTitle());
+
+                                       scenarioDTO.getDocs().add(documentDTO);
+                               }
+                       }
+               }
+               return result;
+       }
+
+       /** 
+        * {@inheritDoc}
+        * @see org.splat.service.StudyComparisonService#compare(java.util.List, java.lang.String)
+        */
+       @Override
+       public String compare(final List<DocToCompareDTO> docsList,
+                       final String userName) throws IncompatibleDataException {
+
+               String axis1Name = "";
+               String axis2Name = "";
+               String chartTitle = "";
+               String resultPath = "";
+
+               XYSeriesCollection dataset = new XYSeriesCollection();
+
+               Iterator<DocToCompareDTO> docListIter = docsList.iterator();
+
+               for (; docListIter.hasNext();) {
+
+                       DocToCompareDTO docDTO = docListIter.next();
+                       String pathToFile = docDTO.getPathToFile();
+                       File compDocFile = new File(pathToFile);
+
+                       resultPath = pathToFile.substring(0, pathToFile.indexOf("vault"))
+                                       + "downloads" + File.separator + userName + File.separator
+                                       + "ComparisonResult.pdf";
+
+                       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.
+                               if (input.hasNext()) {
+                                       chartTitle = input.nextLine();
+                               }
+
+                               // get the name of the axis.
+                               if (input.hasNext()) {
+                                       String[] tokens = input.nextLine().split(",");
+
+                                       if (tokens.length < 2) {
+                                               throw new IncompatibleDataException(
+                                                               MessageKeyEnum.IDT_000001.toString());
+                                       }
+
+                                       if ("".equals(axis1Name)) {
+                                               axis1Name = tokens[0];
+                                       } else if (!axis1Name.equals(tokens[0])) {
+                                               LOG.debug("Axis must be the same for all documents");
+                                               throw new IncompatibleDataException(
+                                                               MessageKeyEnum.IDT_000001.toString());
+                                       }
+
+                                       if ("".equals(axis2Name)) {
+                                               axis2Name = tokens[1];
+                                       } else if (!axis2Name.equals(tokens[1])) {
+                                               LOG.debug("Axis must be the same for all documents");
+                                               throw new IncompatibleDataException(
+                                                               MessageKeyEnum.IDT_000001.toString());
+                                       }
+                               }
+
+                               // Get the XY points series.
+                               while (input.hasNext()) {
+
+                                       String currentString = input.nextLine();
+
+                                       if (!("".equals(currentString))) {
+                                               String[] tokens = currentString.split(" ");
+                                               series.add(Double.valueOf(tokens[0]), Double
+                                                               .valueOf(tokens[1]));
+                                       }
+
+                               } // while
+
+                               dataset.addSeries(series);
+
+                       } catch (FileNotFoundException e) {
+                               LOG.error("Sorry, the file is not found.", e);
+                       }
+               } // for
+
+               JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, // Title
+                               axis1Name, // x-axis Label
+                               axis2Name, // y-axis Label
+                               dataset, // Dataset
+                               PlotOrientation.VERTICAL, // Plot Orientation
+                               true, // Show Legend
+                               true, // Use tooltips
+                               false // Configure chart to generate URLs?
+                               );
+
+               // export to PDF - file.
+               int x = 500;
+               int y = 300;
+               Rectangle pagesize = new Rectangle(x, y);
+               Document document = new Document(pagesize, 50, 50, 50, 50);
+               PdfWriter writer;
+               try {
+                       File resFile = new File(resultPath);
+                       File resFolder = new File(resultPath.substring(0, resultPath
+                                       .lastIndexOf(File.separator)));
+                       resFolder.mkdirs();
+                       writer = PdfWriter.getInstance(document, new FileOutputStream(
+                                       resFile));
+
+                       document.open();
+                       PdfContentByte cb = writer.getDirectContent();
+                       PdfTemplate tp = cb.createTemplate(x, y);
+                       Graphics2D g2 = tp.createGraphics(x, y, new DefaultFontMapper());
+                       chart.draw(g2, new java.awt.Rectangle(x, y));
+                       g2.dispose();
+                       cb.addTemplate(tp, 0, 0);
+                       document.close();
+
+               } catch (FileNotFoundException e) {
+                       LOG.error("Sorry, the file is not found.", e);
+               } catch (DocumentException e) {
+                       LOG.error("Sorry, the DocumentException is thrown.", e);
+               }
+
+               return resultPath;
+       }
+
+
+       /**
+        * Get the projectSettings.
+        * @return the projectSettings
+        */
+       public ProjectSettingsService getProjectSettings() {
+               return _projectSettings;
+       }
+
+
+       /**
+        * Set the projectSettings.
+        * @param projectSettings the projectSettings to set
+        */
+       public void setProjectSettings(final ProjectSettingsService projectSettings) {
+               _projectSettings = projectSettings;
+       }
+
+
+       /**
+        * Get the publicationDAO.
+        * @return the publicationDAO
+        */
+       public PublicationDAO getPublicationDAO() {
+               return _publicationDAO;
+       }
+
+
+       /**
+        * Set the publicationDAO.
+        * @param publicationDAO the publicationDAO to set
+        */
+       public void setPublicationDAO(final PublicationDAO publicationDAO) {
+               _publicationDAO = publicationDAO;
+       }
+
+
+       /**
+        * Get the userService.
+        * @return the userService
+        */
+       public UserService getUserService() {
+               return _userService;
+       }
+
+
+       /**
+        * Set the userService.
+        * @param userService the userService to set
+        */
+       public void setUserService(final UserService userService) {
+               _userService = userService;
+       }
+
+
+       /**
+        * Get the searchService.
+        * @return the searchService
+        */
+       public SearchService getSearchService() {
+               return _searchService;
+       }
+
+
+       /**
+        * Set the searchService.
+        * @param searchService the searchService to set
+        */
+       public void setSearchService(final SearchService searchService) {
+               _searchService = searchService;
+       }
+}
index 7185cef30fec027a98cec84eabe079459cda8652..7f8d1a5a955fa29cc69b69b7a9dc3de0df42885f 100644 (file)
@@ -17,17 +17,11 @@ import org.splat.dal.bo.som.SimulationContext;
 import org.splat.dal.bo.som.Study;
 import org.splat.dal.bo.som.ValidationCycle;
 import org.splat.dal.bo.som.Study.Properties;
-import org.splat.exception.IncompatibleDataException;
 import org.splat.exception.InvalidParameterException;
 import org.splat.kernel.InvalidPropertyException;
-import org.splat.kernel.MismatchException;
 import org.splat.kernel.MissedPropertyException;
 import org.splat.kernel.MultiplyDefinedException;
-import org.splat.service.dto.DocToCompareDTO;
-import org.splat.service.dto.DocumentDTO;
-import org.splat.service.dto.StudyFacadeDTO;
 import org.splat.service.dto.UserDTO;
-import org.splat.service.dto.StudyFacadeDTO.ScenarioDTO;
 
 /**
  * This class defines all methods for creation, modification the study.
@@ -313,20 +307,6 @@ public interface StudyService {
         */
        void removeStudyAsReference(Study aStudy);
 
-       /**
-        * Get studies, scenarios and publications available for comparison. <br>
-        * <b> DocumentDto.id are actually filled in with Publication ids.</b>
-        * 
-        * @param userId
-        *            id of the user to to whom visible studies will be returned.
-        * @return list of {@link StudyFacadeDTO} containing lists of {@link ScenarioDTO} containing list of {@link DocumentDTO}, corresponding
-        *         to to the publications available for comparison, with ids and titles filled in.
-        * @throws MismatchException
-        *             if some configurations considering postprocessing step are invalid.
-        */
-       List<StudyFacadeDTO> getComparableStudies(final long userId)
-                       throws MismatchException;
-
        /**
         * Get the description attribute related to the study (there supposed to be the only one such attribute in the database).
         * 
@@ -363,21 +343,6 @@ public interface StudyService {
        boolean removeDescription(final Long studyId)
                        throws InvalidParameterException;
 
-       /**
-        * Compare the studies and generate the file that contains the result chart.
-        * 
-        * @param docsList
-        *            the list of dtos each contains information: StudyTitle, ScenarioTitle, PathToFile in vault.
-        * @param userName
-        *            the name of the user who compare the results.
-        * @throws IncompatibleDataException
-        *             if data is incompatible for "Compare the studies" functionality.
-        * 
-        * @return path to result file in the vault.
-        */
-       String compare(List<DocToCompareDTO> docsList, final String userName)
-                       throws IncompatibleDataException;
-
        /**
         * Get readers of a given study.
         * 
index 2e4079229c690686a26a58012ed64b4bbf722599..5657ba53c9d3aefd859f902a2283aec58a2e91eb 100644 (file)
@@ -9,10 +9,6 @@
 
 package org.splat.service;
 
-import java.awt.Graphics2D;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.text.DecimalFormat;
 import java.text.SimpleDateFormat;
@@ -20,28 +16,18 @@ import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Collections;
 import java.util.Date;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.Scanner;
 import java.util.Set;
 
 import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.store.FSDirectory;
 import org.hibernate.Criteria;
-import org.hibernate.Hibernate;
 import org.hibernate.criterion.DetachedCriteria;
 import org.hibernate.criterion.Order;
 import org.hibernate.criterion.Restrictions;
-import org.hibernate.proxy.HibernateProxy;
-import org.jfree.chart.ChartFactory;
-import org.jfree.chart.JFreeChart;
-import org.jfree.chart.plot.PlotOrientation;
-import org.jfree.data.xy.XYSeries;
-import org.jfree.data.xy.XYSeriesCollection;
-import org.splat.common.properties.MessageKeyEnum;
 import org.splat.dal.bo.kernel.Relation;
 import org.splat.dal.bo.kernel.User;
 import org.splat.dal.bo.som.ActorRelation;
@@ -51,7 +37,6 @@ import org.splat.dal.bo.som.DocumentType;
 import org.splat.dal.bo.som.IDBuilder;
 import org.splat.dal.bo.som.KnowledgeElement;
 import org.splat.dal.bo.som.ProgressState;
-import org.splat.dal.bo.som.ProjectElement;
 import org.splat.dal.bo.som.Publication;
 import org.splat.dal.bo.som.ReaderRelation;
 import org.splat.dal.bo.som.Scenario;
@@ -73,34 +58,20 @@ import org.splat.dal.dao.som.StudyDAO;
 import org.splat.dal.dao.som.UsedByRelationDAO;
 import org.splat.dal.dao.som.ValidationCycleDAO;
 import org.splat.exception.BusinessException;
-import org.splat.exception.IncompatibleDataException;
 import org.splat.exception.InvalidParameterException;
 import org.splat.kernel.InvalidPropertyException;
-import org.splat.kernel.MismatchException;
 import org.splat.kernel.MissedPropertyException;
 import org.splat.kernel.MultiplyDefinedException;
 import org.splat.log.AppLogger;
-import org.splat.service.dto.DocToCompareDTO;
-import org.splat.service.dto.DocumentDTO;
-import org.splat.service.dto.StudyFacadeDTO;
 import org.splat.service.dto.UserDTO;
 import org.splat.service.technical.IndexService;
 import org.splat.service.technical.ProjectSettingsService;
 import org.splat.service.technical.ProjectSettingsServiceImpl;
 import org.splat.service.technical.RepositoryService;
-import org.splat.service.technical.ProjectSettingsService.Step;
 import org.splat.som.Revision;
 import org.splat.util.BeanHelper;
 import org.springframework.transaction.annotation.Transactional;
 
-import com.lowagie.text.Document;
-import com.lowagie.text.DocumentException;
-import com.lowagie.text.Rectangle;
-import com.lowagie.text.pdf.DefaultFontMapper;
-import com.lowagie.text.pdf.PdfContentByte;
-import com.lowagie.text.pdf.PdfTemplate;
-import com.lowagie.text.pdf.PdfWriter;
-
 /**
  * This class defines all methods for creation, modification the study.
  * 
@@ -1219,136 +1190,6 @@ public class StudyServiceImpl implements StudyService {
                                .getAttribute(DescriptionAttribute.class));
        }
 
-       /**
-        * 
-        * {@inheritDoc}
-        * 
-        * @see org.splat.service.StudyService#compare(java.util.List)
-        */
-       @Override
-       public String compare(final List<DocToCompareDTO> docsList,
-                       final String userName) throws IncompatibleDataException {
-
-               String axis1Name = "";
-               String axis2Name = "";
-               String chartTitle = "";
-               String resultPath = "";
-
-               XYSeriesCollection dataset = new XYSeriesCollection();
-
-               Iterator<DocToCompareDTO> docListIter = docsList.iterator();
-
-               for (; docListIter.hasNext();) {
-
-                       DocToCompareDTO docDTO = docListIter.next();
-                       String pathToFile = docDTO.getPathToFile();
-                       File compDocFile = new File(pathToFile);
-
-                       resultPath = pathToFile.substring(0, pathToFile.indexOf("vault"))
-                                       + "downloads" + File.separator + userName + File.separator
-                                       + "ComparisonResult.pdf";
-
-                       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.
-                               if (input.hasNext()) {
-                                       chartTitle = input.nextLine();
-                               }
-
-                               // get the name of the axis.
-                               if (input.hasNext()) {
-                                       String[] tokens = input.nextLine().split(",");
-
-                                       if (tokens.length < 2) {
-                                               throw new IncompatibleDataException(
-                                                               MessageKeyEnum.IDT_000001.toString());
-                                       }
-
-                                       if ("".equals(axis1Name)) {
-                                               axis1Name = tokens[0];
-                                       } else if (!axis1Name.equals(tokens[0])) {
-                                               LOG.debug("Axis must be the same for all documents");
-                                               throw new IncompatibleDataException(
-                                                               MessageKeyEnum.IDT_000001.toString());
-                                       }
-
-                                       if ("".equals(axis2Name)) {
-                                               axis2Name = tokens[1];
-                                       } else if (!axis2Name.equals(tokens[1])) {
-                                               LOG.debug("Axis must be the same for all documents");
-                                               throw new IncompatibleDataException(
-                                                               MessageKeyEnum.IDT_000001.toString());
-                                       }
-                               }
-
-                               // Get the XY points series.
-                               while (input.hasNext()) {
-
-                                       String currentString = input.nextLine();
-
-                                       if (!("".equals(currentString))) {
-                                               String[] tokens = currentString.split(" ");
-                                               series.add(Double.valueOf(tokens[0]), Double
-                                                               .valueOf(tokens[1]));
-                                       }
-
-                               } // while
-
-                               dataset.addSeries(series);
-
-                       } catch (FileNotFoundException e) {
-                               LOG.error("Sorry, the file is not found.", e);
-                       }
-               } // for
-
-               JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, // Title
-                               axis1Name, // x-axis Label
-                               axis2Name, // y-axis Label
-                               dataset, // Dataset
-                               PlotOrientation.VERTICAL, // Plot Orientation
-                               true, // Show Legend
-                               true, // Use tooltips
-                               false // Configure chart to generate URLs?
-                               );
-
-               // export to PDF - file.
-               int x = 500;
-               int y = 300;
-               Rectangle pagesize = new Rectangle(x, y);
-               Document document = new Document(pagesize, 50, 50, 50, 50);
-               PdfWriter writer;
-               try {
-                       File resFile = new File(resultPath);
-                       File resFolder = new File(resultPath.substring(0, resultPath
-                                       .lastIndexOf(File.separator)));
-                       resFolder.mkdirs();
-                       writer = PdfWriter.getInstance(document, new FileOutputStream(
-                                       resFile));
-
-                       document.open();
-                       PdfContentByte cb = writer.getDirectContent();
-                       PdfTemplate tp = cb.createTemplate(x, y);
-                       Graphics2D g2 = tp.createGraphics(x, y, new DefaultFontMapper());
-                       chart.draw(g2, new java.awt.Rectangle(x, y));
-                       g2.dispose();
-                       cb.addTemplate(tp, 0, 0);
-                       document.close();
-
-               } catch (FileNotFoundException e) {
-                       LOG.error("Sorry, the file is not found.", e);
-               } catch (DocumentException e) {
-                       LOG.error("Sorry, the DocumentException is thrown.", e);
-               }
-
-               return resultPath;
-       }
-
        /**
         * {@inheritDoc}
         * 
@@ -1617,108 +1458,6 @@ public class StudyServiceImpl implements StudyService {
                _userService = userService;
        }
 
-       /**
-        * {@inheritDoc}
-        * 
-        * @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
-               List<Step> allSteps = _projectSettings.getAllSteps();
-               Step theAnalyzeStep = null;
-               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.");
-               }
-
-               List<Publication> publications = _publicationDAO.getFilteredList(
-                               "mydoc", Restrictions.eq("step", Integer.valueOf(theAnalyzeStep
-                                               .getNumber())));
-
-               // 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)
-                                       || !"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())) {
-                               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)) {
-                               throw new MismatchException(
-                                               "publications from postprocessing step are supposed to have owner scenario");
-                       }
-
-                       if (!studyMap.containsKey(study)) {
-                               studyMap.put(study, new ArrayList<ProjectElement>());
-                       }
-
-                       if (!studyMap.get(study).contains(scenario)) {
-                               studyMap.get(study).add(scenario);
-                       }
-
-                       if (!scenarioMap.containsKey(scenario)) {
-                               scenarioMap.put(scenario, new ArrayList<Publication>());
-                       }
-                       scenarioMap.get(scenario).add(publication);
-               }
-
-               // Create the result DTOs
-               List<StudyFacadeDTO> result = new ArrayList<StudyFacadeDTO>();
-               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)) {
-
-                               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)) {
-
-                                       DocumentDTO documentDTO = new DocumentDTO();
-                                       documentDTO.setId(publication.getIndex());
-                                       documentDTO.setTitle(publication.value().getTitle());
-
-                                       scenarioDTO.getDocs().add(documentDTO);
-                               }
-                       }
-               }
-               return result;
-       }
-
        /**
         * Get the publicationDAO.
         * 
index b27d984d7476772a08419bb728c9f116783d80fe..cb6622239785d841969ab56d9ae0f27d5f1a22b3 100644 (file)
@@ -168,6 +168,14 @@ http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
         <property name="repositoryService" ref="repositoryService" />
         <property name="publicationDAO" ref="publicationDAO" />
        </bean>
+       
+    <bean id="studyComparisonService"
+        class="org.splat.service.StudyComparisonServiceImpl">
+        <property name="projectSettings" ref="projectSettings" />
+        <property name="publicationDAO" ref="publicationDAO" />
+        <property name="userService" ref="userService" />
+        <property name="searchService" ref="searchService" />
+    </bean>
 
        <bean id="userRights" abstract="true" scope="session">
                <property name="studyService" ref="studyService" />
index 62934b3785fe8df11ab9b6ee7824d7d6570b1098..7dd91ecb77f4889efff2a7935184df5f001c014e 100644 (file)
@@ -20,6 +20,7 @@ import org.splat.exception.IncompatibleDataException;
 import org.splat.exception.InvalidParameterException;
 import org.splat.kernel.MismatchException;
 import org.splat.service.PublicationService;
+import org.splat.service.StudyComparisonService;
 import org.splat.service.dto.DocToCompareDTO;
 import org.splat.service.dto.StudyFacadeDTO;
 import org.splat.wapp.Constants;
@@ -66,6 +67,11 @@ public class CompareStudyAction extends DisplayStudyStepAction {
         */
        private PublicationService _publicationService;
 
+       /**
+        * Injected study comparison service.
+        */
+       private StudyComparisonService _studyComparisonService;
+
        /**
         * If true, "incompatible data" message will be displayed..
         */
@@ -80,7 +86,7 @@ public class CompareStudyAction extends DisplayStudyStepAction {
                initializationScreenContext(Constants.STUDY_MENU, Constants.BACK);
                getTitleBarSettings().setEditDisabledProperty(Constants.TRUE);
                String res = SUCCESS;
-               _studyList = getStudyService().getComparableStudies(getOpenStudy().getUser().getIndex());
+               _studyList = getStudyComparisonService().getComparableStudies(getOpenStudy().getUser().getIndex());
                return res;
        }
 
@@ -99,7 +105,7 @@ public class CompareStudyAction extends DisplayStudyStepAction {
                                for(Long id : _documentsToCompareIds) {
                                        docsList.add(_publicationService.getDocToCompareDTO(id.longValue()));
                                }
-                               String resultPath = getStudyService().compare(docsList, getConnectedUser().getUsername());
+                               String resultPath = getStudyComparisonService().compare(docsList, getConnectedUser().getUsername());
                                File file = new File(resultPath);
                                _resultInputStream = new FileInputStream(file);
                                res = SUCCESS;
@@ -221,4 +227,21 @@ public class CompareStudyAction extends DisplayStudyStepAction {
        public void setErrorMessage(final Boolean errorMessage) {
                _errorMessage = errorMessage;
        }
+
+       /**
+        * Get the studyComparisonService.
+        * @return the studyComparisonService
+        */
+       public StudyComparisonService getStudyComparisonService() {
+               return _studyComparisonService;
+       }
+
+       /**
+        * Set the studyComparisonService.
+        * @param studyComparisonService the studyComparisonService to set
+        */
+       public void setStudyComparisonService(
+                       final StudyComparisonService studyComparisonService) {
+               _studyComparisonService = studyComparisonService;
+       }
 }
index 697f2b7d3a40b7490a05beedc8fc9630f42481b2..748a0f7b7b4b155f45fb0455f1035f205f998ff2 100644 (file)
@@ -265,7 +265,15 @@ public class ImportDocumentAction extends BaseUploadDocumentAction {
                                //
                                // if (send != null) send.converts(addoc); // Asynchronous process
 
-                               _mystudy.add(addoc); // Updates the presentation
+                               if (uses.isEmpty()) {
+                                       _mystudy.add(addoc); // Updates the presentation
+                               } else {
+                                       // Re-opening (refreshing) the currently open study
+                                       String selection = _mystudy.getSelection();
+                                       _mystudy = open(getStudyService().selectStudy(
+                                                       _mystudy.getIndex())); // Updates the study
+                                       _mystudy.setSelection(selection);
+                               }
                                res = SUCCESS;
                        } catch (FileNotFoundException error) {
                                LOG.error("Reason:", error);
index e6190801bf1d92edd4f670094ac5fc78ea7cc00d..ed7628ad03204823ca31b14eda4cfc2a87d53587 100644 (file)
@@ -23,6 +23,7 @@ import org.splat.dal.bo.som.Publication;
 import org.splat.dal.bo.som.Scenario;
 import org.splat.dal.bo.som.SimulationContext;
 import org.splat.dal.bo.som.Study;
+import org.splat.dal.bo.som.UsesRelation;
 import org.splat.kernel.Do;
 import org.splat.log.AppLogger;
 import org.splat.manox.Toolbox;
@@ -63,9 +64,21 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices {
         * User rights on the selected step.
         */
        private transient StepRights _urightstep;
+       /**
+        * The study version.
+        */
        private transient String _version;
+       /**
+        * The study creation date.
+        */
        private transient String _credate;
+       /**
+        * The study modification date.
+        */
        private transient String _lasdate;
+       /**
+        * The selected document publication.
+        */
        private transient Publication _selecdoc;
        /**
         * Injected step service.
@@ -88,9 +101,9 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices {
         */
        private StudyService _studyService;
 
-       // ==============================================================================================================================
+       // =========================================================================
        // Constructor
-       // ==============================================================================================================================
+       // =========================================================================
 
        /**
         * Open the given study in the current http session.
@@ -181,73 +194,149 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices {
                return this;
        }
 
-       // ==============================================================================================================================
+       // =========================================================================
        // Getters
-       // ==============================================================================================================================
+       // =========================================================================
 
+       /**
+        * {@inheritDoc}
+        * 
+        * @see org.splat.service.dto.Proxy#getAuthorName()
+        */
        @Override
        public String getAuthorName() {
                return _mystudy.getAuthor().toString();
        }
 
+       /**
+        * {@inheritDoc}
+        * 
+        * @see org.splat.service.dto.Proxy#getIndex()
+        */
        @Override
        public Long getIndex() {
                return _mystudy.getIndex();
        }
 
+       /**
+        * Get creation date.
+        * 
+        * @return the date
+        */
        public String getDate() {
                return _credate;
        }
 
+       /**
+        * {@inheritDoc}
+        * 
+        * @see org.splat.simer.AbstractOpenObject#getMenu()
+        */
        @Override
        public StudyMenu getMenu() {
                return (StudyMenu) _menu;
        }
 
+       /**
+        * Set study menu.
+        * 
+        * @param aMenu
+        *            the study menu
+        */
        public void setMenu(final StudyMenu aMenu) {
                _menu = aMenu;
        }
 
+       /**
+        * {@inheritDoc}
+        * 
+        * @see org.splat.service.dto.Proxy#getProgressState()
+        */
        @Override
        public ProgressState getProgressState() {
                return _mystudy.getProgressState();
        }
 
+       /**
+        * Get last modification date.
+        * 
+        * @return the date
+        */
        public String getLastModificationDate() {
                return _lasdate;
        }
 
+       /**
+        * Get the toolbar with buttons of available modules.
+        * 
+        * @return the toolbar
+        */
        public ToolBar getModuleBar() {
                return getApplicationSettings().getModuleBar(getSelectedStep());
        }
 
+       /**
+        * {@inheritDoc}
+        * 
+        * @see org.splat.service.dto.Proxy#getReference()
+        */
        @Override
        public String getReference() {
                return _mystudy.getReference();
        }
 
+       /**
+        * {@inheritDoc}
+        * 
+        * @see org.splat.simer.OpenStudyServices#getSelectedDocument()
+        */
        @Override
        public Publication getSelectedDocument() {
                return _selecdoc;
        }
 
+       /**
+        * Get user rights for the selected step.
+        * 
+        * @return user step rights
+        */
        public StepRights getSelectedStepRights() {
                return _urightstep;
        }
 
+       /**
+        * Get user rights for the study.
+        * 
+        * @return user study rights
+        */
        public StudyRights getStudyRights() {
                return _urightstudy;
        }
 
+       /**
+        * Get the detached study object.
+        * 
+        * @return the detached study object
+        */
        public Study getStudyObject() {
                return _mystudy;
        }
 
+       /**
+        * {@inheritDoc}
+        * 
+        * @see org.splat.service.dto.Proxy#getTitle()
+        */
        @Override
        public String getTitle() {
                return _mystudy.getTitle();
        }
 
+       /**
+        * {@inheritDoc}
+        * 
+        * @see org.splat.service.dto.Proxy#getType()
+        */
        @Override
        public String getType() {
                /*
@@ -256,17 +345,27 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices {
                return Constants.STUDY_MENU;
        }
 
+       /**
+        * Get the study version.
+        * 
+        * @return the version string
+        */
        public String getVersion() {
                return _version;
        }
 
+       /**
+        * Check if the selected step is enabled for writing.
+        * 
+        * @return true if the selected step is enabled for writing
+        */
        public boolean isStepEnabled() {
                return _urightstep.isEnabled();
        }
 
-       // ==============================================================================================================================
+       // =========================================================================
        // Public services
-       // ==============================================================================================================================
+       // =========================================================================
 
        @Override
        public URL newTemplateBasedDocument(final String typename, final User author) {
@@ -352,6 +451,12 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices {
                }
        }
 
+       /**
+        * Select an activity (step).
+        * 
+        * @param step
+        *            the key of the step to select
+        */
        public void setSelection(final String step) {
                if (!step.equals(_selection)) {
                        _selection = step;
@@ -366,10 +471,16 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices {
                setupContents(); // The contents may have changed even if the selection is the same
        }
 
-       // ==============================================================================================================================
+       // =========================================================================
        // Protected services
-       // ==============================================================================================================================
+       // =========================================================================
 
+       /**
+        * Add a new document presentation facade.
+        * 
+        * @param doc
+        *            the document publication
+        */
        protected void add(final Publication doc) {
                DocumentFacade facade = new DocumentFacade(this, doc,
                                getProjectSettings(), getPublicationService(),
@@ -381,9 +492,18 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices {
                if (first) {
                        this.getMenu().refreshSelectedItem();
                }
-
+               // Refresh dependencies. They can not be removed until removing this document.
+               for (Publication pub : doc.getRelations(UsesRelation.class)) {
+                       update(pub);
+               }
        }
 
+       /**
+        * Add a simulation context presentation facade.
+        * 
+        * @param contex
+        *            the simulation context to add
+        */
        protected void add(final SimulationContext contex) {
                SimulationContextFacade facade = new SimulationContextFacade(contex,
                                getProjectSettings().getAllSteps(), getApplicationSettings());
@@ -391,6 +511,12 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices {
                _context.add(facade);
        }
 
+       /**
+        * Add a knowledge element presentation facade.
+        * 
+        * @param kelm
+        *            the knowledge element to add
+        */
        protected void add(final KnowledgeElement kelm) {
                KnowledgeElementFacade facade = new KnowledgeElementFacade(BeanHelper
                                .copyBean(kelm, KnowledgeElementDTO.class),
@@ -412,6 +538,12 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices {
                }
        }
 
+       /**
+        * Remove the document presentation facade.
+        * 
+        * @param doctag
+        *            the document publication to remove
+        */
        protected void remove(final Publication doctag) {
                for (Iterator<DocumentFacade> i = _contents.iterator(); i.hasNext();) {
                        DocumentFacade facade = i.next();
@@ -425,6 +557,12 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices {
                }
        }
 
+       /**
+        * Change the currently connected user and refresh user's rights.
+        * 
+        * @param user
+        *            the new connected user
+        */
        protected void changeUser(final User user) {
                _cuser = user;
                _popup = null;
@@ -442,18 +580,29 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices {
                _urightstep = new StepRights(_cuser, _ustep);
        }
 
+       /**
+        * Remove the simulation context presentation facade.
+        * 
+        * @param contex
+        *            the simulation context to remove
+        */
        protected void remove(final SimulationContext contex) {
                for (Iterator<SimulationContextFacade> i = _context.iterator(); i
                                .hasNext();) {
                        SimulationContextFacade facade = i.next();
-                       if (!facade.isFacadeOf(contex)) {
-                               continue;
+                       if (facade.isFacadeOf(contex)) {
+                               i.remove();
+                               break;
                        }
-                       i.remove();
-                       break;
                }
        }
 
+       /**
+        * Remove the knowledge element presentation facade.
+        * 
+        * @param kelm
+        *            the knowledge element to remove
+        */
        protected void remove(final KnowledgeElement kelm) {
                // RKV: KnowledgeIterator known = _knowledge.get((int) (kelm.getType()
                // RKV: .getIndex() - 2));
@@ -482,6 +631,12 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices {
                }
        }
 
+       /**
+        * Refresh the document presentation facade.
+        * 
+        * @param doc
+        *            the document publication
+        */
        protected void update(final Publication doc) {
                DocumentFacade facade = _docpres.get(doc.getIndex());
                if (facade != null) {
@@ -489,6 +644,12 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices {
                }
        }
 
+       /**
+        * Refresh the knowledge element presentation facade.
+        * 
+        * @param kelm
+        *            the knowledge element DTO
+        */
        protected void update(final KnowledgeElementDTO kelm) {
                KnowledgeElementFacade facade = _knowpres.get(kelm.getIndex());
                if (facade != null) {
@@ -496,6 +657,9 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices {
                }
        }
 
+       /**
+        * Refresh simulation contexts presentation facades.
+        */
        protected void updateSimulationContexts() {
                _context.clear();
                for (Iterator<Step> i = _involving.iterator(); i.hasNext();) {
@@ -508,9 +672,9 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices {
                }
        }
 
-       // ==============================================================================================================================
+       // =========================================================================
        // Private services
-       // ==============================================================================================================================
+       // =========================================================================
 
        private void setupPreviousToSelectedSteps() {
                String[] item = _selection.split("\\x2E");
@@ -640,10 +804,21 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices {
                _documentService = documentService;
        }
 
+       /**
+        * Get the detached study object.
+        * 
+        * @return the detached study object
+        */
        public Study getMystudy() {
                return _mystudy;
        }
 
+       /**
+        * Set the study to present.
+        * 
+        * @param mystudy
+        *            the selected study detached object
+        */
        public void setMystudy(final Study mystudy) {
                this._mystudy = mystudy;
        }
index 081dd9f771a89e81b649f64ac0b9ddbee0057872..c8d97c35f263ee32501b0e3fd48a8ec1d59ddb4d 100644 (file)
@@ -233,6 +233,7 @@ http://www.springframework.org/schema/context/spring-context-3.0.xsd">
                parent="displayStudyStepAction">
                <property name="publicationService" ref="publicationService" />
                <property name="simanContext" value="#Compare_Studies.htm"/>
+        <property name="studyComparisonService" ref="studyComparisonService" />
        </bean>
 
        <!-- End of Inherited from displayStudyStepAction -->