From 674a43e57cc119ec231258b1011593886a490cb8 Mon Sep 17 00:00:00 2001 From: rkv Date: Thu, 18 Apr 2013 06:49:06 +0000 Subject: [PATCH] Fix: 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. --- .../splat/service/StudyComparisonService.java | 42 ++ .../service/StudyComparisonServiceImpl.java | 398 ++++++++++++++++++ .../src/org/splat/service/StudyService.java | 35 -- .../org/splat/service/StudyServiceImpl.java | 261 ------------ .../src/spring/businessServiceContext.xml | 8 + .../org/splat/simer/CompareStudyAction.java | 27 +- .../org/splat/simer/ImportDocumentAction.java | 10 +- .../Siman/src/org/splat/simer/OpenStudy.java | 205 ++++++++- .../Siman/src/spring/applicationContext.xml | 1 + 9 files changed, 673 insertions(+), 314 deletions(-) create mode 100644 Workspace/Siman-Common/src/org/splat/service/StudyComparisonService.java create mode 100644 Workspace/Siman-Common/src/org/splat/service/StudyComparisonServiceImpl.java 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 index 0000000..b0a5221 --- /dev/null +++ b/Workspace/Siman-Common/src/org/splat/service/StudyComparisonService.java @@ -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 docsList, final String userName) + throws IncompatibleDataException; + + /** + * Get studies, scenarios and publications available for comparison.
+ * DocumentDto.id are actually filled in with Publication ids. + * + * @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 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 index 0000000..714576a --- /dev/null +++ b/Workspace/Siman-Common/src/org/splat/service/StudyComparisonServiceImpl.java @@ -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 getComparableStudies(final long userId) + throws MismatchException { + // retrieve the number of the "Analyze the results" step + List 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 publications = _publicationDAO.getFilteredList( + "mydoc", Restrictions.eq("step", Integer.valueOf(theAnalyzeStep + .getNumber()))); + + // split retrieved publications into groups by studies and scenarios + Map> studyMap = new HashMap>(); + Map> scenarioMap = new HashMap>(); + + // Get visible studies + StudySearchFilterDTO filter = new StudySearchFilterDTO(); + User user = (_userService.selectUser(userId)); + if(user != null) { + filter.setConnectedUserId(userId); + } + List 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()); + } + + if (!studyMap.get(study).contains(scenario)) { + studyMap.get(study).add(scenario); + } + + if (!scenarioMap.containsKey(scenario)) { + scenarioMap.put(scenario, new ArrayList()); + } + scenarioMap.get(scenario).add(publication); + } + + // Create the result DTOs + List result = new ArrayList(); + for (Study study : studyMap.keySet()) { + + StudyFacadeDTO studyDTO = new StudyFacadeDTO(); + studyDTO.setName(study.getTitle()); + studyDTO.setScenarios(new ArrayList()); + result.add(studyDTO); + + for (ProjectElement scenario : studyMap.get(study)) { + + StudyFacadeDTO.ScenarioDTO scenarioDTO = new StudyFacadeDTO.ScenarioDTO(); + scenarioDTO.setName(scenario.getTitle()); + scenarioDTO.setDocs(new ArrayList()); + 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 docsList, + final String userName) throws IncompatibleDataException { + + String axis1Name = ""; + String axis2Name = ""; + String chartTitle = ""; + String resultPath = ""; + + XYSeriesCollection dataset = new XYSeriesCollection(); + + Iterator 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; + } +} diff --git a/Workspace/Siman-Common/src/org/splat/service/StudyService.java b/Workspace/Siman-Common/src/org/splat/service/StudyService.java index 7185cef..7f8d1a5 100644 --- a/Workspace/Siman-Common/src/org/splat/service/StudyService.java +++ b/Workspace/Siman-Common/src/org/splat/service/StudyService.java @@ -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.
- * DocumentDto.id are actually filled in with Publication ids. - * - * @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 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 docsList, final String userName) - throws IncompatibleDataException; - /** * Get readers of a given study. * diff --git a/Workspace/Siman-Common/src/org/splat/service/StudyServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/StudyServiceImpl.java index 2e40792..5657ba5 100644 --- a/Workspace/Siman-Common/src/org/splat/service/StudyServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/StudyServiceImpl.java @@ -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 docsList, - final String userName) throws IncompatibleDataException { - - String axis1Name = ""; - String axis2Name = ""; - String chartTitle = ""; - String resultPath = ""; - - XYSeriesCollection dataset = new XYSeriesCollection(); - - Iterator 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 getComparableStudies(final long userId) - throws MismatchException { - // retrieve the number of the "Analyze the results" step - List 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 publications = _publicationDAO.getFilteredList( - "mydoc", Restrictions.eq("step", Integer.valueOf(theAnalyzeStep - .getNumber()))); - - // split retrieved publications into groups by studies and scenarios - Map> studyMap = new HashMap>(); - Map> scenarioMap = new HashMap>(); - - 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()); - } - - if (!studyMap.get(study).contains(scenario)) { - studyMap.get(study).add(scenario); - } - - if (!scenarioMap.containsKey(scenario)) { - scenarioMap.put(scenario, new ArrayList()); - } - scenarioMap.get(scenario).add(publication); - } - - // Create the result DTOs - List result = new ArrayList(); - for (Study study : studyMap.keySet()) { - - StudyFacadeDTO studyDTO = new StudyFacadeDTO(); - studyDTO.setName(study.getTitle()); - studyDTO.setScenarios(new ArrayList()); - result.add(studyDTO); - - for (ProjectElement scenario : studyMap.get(study)) { - - StudyFacadeDTO.ScenarioDTO scenarioDTO = new StudyFacadeDTO.ScenarioDTO(); - scenarioDTO.setName(scenario.getTitle()); - scenarioDTO.setDocs(new ArrayList()); - 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. * diff --git a/Workspace/Siman-Common/src/spring/businessServiceContext.xml b/Workspace/Siman-Common/src/spring/businessServiceContext.xml index b27d984..cb66222 100644 --- a/Workspace/Siman-Common/src/spring/businessServiceContext.xml +++ b/Workspace/Siman-Common/src/spring/businessServiceContext.xml @@ -168,6 +168,14 @@ http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> + + + + + + + diff --git a/Workspace/Siman/src/org/splat/simer/CompareStudyAction.java b/Workspace/Siman/src/org/splat/simer/CompareStudyAction.java index 62934b3..7dd91ec 100644 --- a/Workspace/Siman/src/org/splat/simer/CompareStudyAction.java +++ b/Workspace/Siman/src/org/splat/simer/CompareStudyAction.java @@ -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; + } } diff --git a/Workspace/Siman/src/org/splat/simer/ImportDocumentAction.java b/Workspace/Siman/src/org/splat/simer/ImportDocumentAction.java index 697f2b7..748a0f7 100644 --- a/Workspace/Siman/src/org/splat/simer/ImportDocumentAction.java +++ b/Workspace/Siman/src/org/splat/simer/ImportDocumentAction.java @@ -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); diff --git a/Workspace/Siman/src/org/splat/simer/OpenStudy.java b/Workspace/Siman/src/org/splat/simer/OpenStudy.java index e619080..ed7628a 100644 --- a/Workspace/Siman/src/org/splat/simer/OpenStudy.java +++ b/Workspace/Siman/src/org/splat/simer/OpenStudy.java @@ -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 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 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 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; } diff --git a/Workspace/Siman/src/spring/applicationContext.xml b/Workspace/Siman/src/spring/applicationContext.xml index 081dd9f..c8d97c3 100644 --- a/Workspace/Siman/src/spring/applicationContext.xml +++ b/Workspace/Siman/src/spring/applicationContext.xml @@ -233,6 +233,7 @@ http://www.springframework.org/schema/context/spring-context-3.0.xsd"> parent="displayStudyStepAction"> + -- 2.39.2