1 /*****************************************************************************
5 * Creation date Dec 11, 2012
8 *****************************************************************************/
10 package org.splat.simer;
13 import java.io.FileInputStream;
14 import java.io.FileNotFoundException;
15 import java.io.InputStream;
16 import java.util.ArrayList;
17 import java.util.List;
19 import org.splat.exception.IncompatibleDataException;
20 import org.splat.exception.InvalidParameterException;
21 import org.splat.kernel.MismatchException;
22 import org.splat.service.PublicationService;
23 import org.splat.service.dto.DocToCompareDTO;
24 import org.splat.service.dto.StudyFacadeDTO;
25 import org.splat.wapp.Constants;
28 * Performs comparison of studies.
32 public class CompareStudyAction extends DisplayStudyStepAction {
37 private static final long serialVersionUID = 6467920934724352021L;
40 * List of StudyDTO containing ScenarioDTO containing publications available for comparison.
42 private List<StudyFacadeDTO> _studyList;
45 * Ids of files to compare.
47 private List<Long> _documentsToCompareIds;
50 * Comparison result file name.
52 private String _resultName = null;
57 private String _resultUrl;
60 * The result Input Stream.
62 private InputStream _resultInputStream;
65 * Injected publication service.
67 private PublicationService _publicationService;
70 * If true, "incompatible data" message will be displayed..
72 private Boolean _errorMessage = false;
75 * Initialize comparison screen.
77 * @throws MismatchException if some configurations considering postprocessing step are invalid.
79 public String doInitComparison() throws MismatchException {
80 initializationScreenContext(Constants.STUDY_MENU, Constants.BACK);
81 getTitleBarSettings().setEditDisabledProperty(Constants.TRUE);
83 _studyList = getStudyService().getComparableStudies(getOpenStudy().getUser().getIndex());
89 * @throws InvalidParameterException if no publication with given id is found
90 * @throws FileNotFoundException if no file with retrieved filename is found
93 public String doCompare() throws InvalidParameterException, FileNotFoundException {
96 if(_documentsToCompareIds != null && _documentsToCompareIds.size()>0) {
98 List<DocToCompareDTO> docsList = new ArrayList<DocToCompareDTO>();
99 for(Long id : _documentsToCompareIds) {
100 docsList.add(_publicationService.getDocToCompareDTO(id.longValue()));
102 String resultPath = getStudyService().compare(docsList, getConnectedUser().getUsername());
103 File file = new File(resultPath);
104 _resultInputStream = new FileInputStream(file);
106 } catch(IncompatibleDataException e) {
107 LOG.debug("Error while trying to compare study results: " + e.getMessage());
115 * @return the studyList
117 public List<StudyFacadeDTO> getStudyList() {
123 * @param studyList the studyList to set
125 public void setStudyList(final List<StudyFacadeDTO> studyList) {
126 _studyList = studyList;
130 * Get the filesToCompareIds.
131 * @return the filesToCompareIds
133 public List<Long> getDocumentsToCompareIds() {
134 return _documentsToCompareIds;
138 * Set the filesToCompareIds.
139 * @param filesToCompareIds the filesToCompareIds to set
141 public void setDocumentsToCompareIds(final List<Long> filesToCompareIds) {
142 _documentsToCompareIds = filesToCompareIds;
146 * Get the resultName.
147 * @return the resultName
149 public String getResultName() {
154 * Set the resultName.
155 * @param resultName the resultName to set
157 public void setResultName(final String resultName) {
158 _resultName = resultName;
163 * @return the resultUrl
165 public String getResultUrl() {
171 * @param resultUrl the resultUrl to set
173 public void setResultUrl(final String resultUrl) {
174 _resultUrl = resultUrl;
178 * Get the publicationService.
179 * @return the publicationService
181 public PublicationService getPublicationService() {
182 return _publicationService;
186 * Set the publicationService.
187 * @param publicationService the publicationService to set
189 public void setPublicationService(PublicationService publicationService) {
190 _publicationService = publicationService;
194 * Get the resultInputStream.
195 * @return the resultInputStream
197 public InputStream getResultInputStream() {
198 return _resultInputStream;
202 * Set the resultInputStream.
203 * @param resultInputStream the resultInputStream to set
205 public void setResultInputStream(InputStream resultInputStream) {
206 _resultInputStream = resultInputStream;
210 * Get the errorMessage.
211 * @return the errorMessage
213 public Boolean getErrorMessage() {
214 return _errorMessage;
218 * Set the errorMessage.
219 * @param errorMessage the errorMessage to set
221 public void setErrorMessage(final Boolean errorMessage) {
222 _errorMessage = errorMessage;