+
+ /**
+ * {@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.
+ * @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 repositoryService.
+ * @return the repositoryService
+ */
+ public RepositoryService getRepositoryService() {
+ return _repositoryService;
+ }
+
+ /**
+ * Set the repositoryService.
+ * @param repositoryService the repositoryService to set
+ */
+ public void setRepositoryService(final RepositoryService repositoryService) {
+ _repositoryService = repositoryService;
+ }
+
+ /**
+ * Get the documentDAO.
+ * @return the documentDAO
+ */
+ public DocumentDAO getDocumentDAO() {
+ return _documentDAO;
+ }
+
+ /**
+ * Set the documentDAO.
+ * @param documentDAO the documentDAO to set
+ */
+ public void setDocumentDAO(final DocumentDAO documentDAO) {
+ _documentDAO = documentDAO;
+ }
+
+ /**
+ * Get the descriptionAttributeDAO.
+ * @return the descriptionAttributeDAO
+ */
+ public DescriptionAttributeDAO getDescriptionAttributeDAO() {
+ return _descriptionAttributeDAO;
+ }
+
+ /**
+ * Set the descriptionAttributeDAO.
+ * @param descriptionAttributeDAO the descriptionAttributeDAO to set
+ */
+ public void setDescriptionAttributeDAO(
+ final DescriptionAttributeDAO descriptionAttributeDAO) {
+ _descriptionAttributeDAO = descriptionAttributeDAO;
+ }