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.
--- /dev/null
+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;
+}
--- /dev/null
+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;
+ }
+}
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.
*/
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).
*
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.
*
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;
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;
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;
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.
*
.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}
*
_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.
*
<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" />
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;
*/
private PublicationService _publicationService;
+ /**
+ * Injected study comparison service.
+ */
+ private StudyComparisonService _studyComparisonService;
+
/**
* If true, "incompatible data" message will be displayed..
*/
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;
}
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;
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;
+ }
}
//
// 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);
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;
* 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.
*/
private StudyService _studyService;
- // ==============================================================================================================================
+ // =========================================================================
// Constructor
- // ==============================================================================================================================
+ // =========================================================================
/**
* Open the given study in the current http session.
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() {
/*
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) {
}
}
+ /**
+ * 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;
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(),
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());
_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),
}
}
+ /**
+ * 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();
}
}
+ /**
+ * 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;
_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));
}
}
+ /**
+ * 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) {
}
}
+ /**
+ * 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) {
}
}
+ /**
+ * Refresh simulation contexts presentation facades.
+ */
protected void updateSimulationContexts() {
_context.clear();
for (Iterator<Step> i = _involving.iterator(); i.hasNext();) {
}
}
- // ==============================================================================================================================
+ // =========================================================================
// Private services
- // ==============================================================================================================================
+ // =========================================================================
private void setupPreviousToSelectedSteps() {
String[] item = _selection.split("\\x2E");
_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;
}
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 -->