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.StudyComparisonService;
24 import org.splat.service.dto.DocToCompareDTO;
25 import org.splat.service.dto.StudyFacadeDTO;
26 import org.splat.wapp.Constants;
29 * Performs comparison of studies.
33 public class CompareStudyAction extends DisplayStudyStepAction {
38 private static final long serialVersionUID = 6467920934724352021L;
41 * List of StudyDTO containing ScenarioDTO containing publications available for comparison.
43 private List<StudyFacadeDTO> _studyList;
46 * Ids of files to compare.
48 private List<Long> _documentsToCompareIds;
51 * Comparison result file name.
53 private String _resultName = null;
58 private String _resultUrl;
61 * The result Input Stream.
63 private InputStream _resultInputStream;
66 * Injected publication service.
68 private PublicationService _publicationService;
71 * Injected study comparison service.
73 private StudyComparisonService _studyComparisonService;
76 * If true, "incompatible data" message will be displayed..
78 private Boolean _errorMessage = false;
81 * Initialize comparison screen.
83 * @throws MismatchException if some configurations considering postprocessing step are invalid.
85 public String doInitComparison() throws MismatchException {
86 initializationScreenContext(Constants.STUDY_MENU, Constants.BACK);
87 getTitleBarSettings().setEditDisabledProperty(Constants.TRUE);
89 _studyList = getStudyComparisonService().getComparableStudies(getOpenStudy().getUser().getIndex());
95 * @throws InvalidParameterException if no publication with given id is found
96 * @throws FileNotFoundException if no file with retrieved filename is found
99 public String doCompare() throws InvalidParameterException, FileNotFoundException {
102 if(_documentsToCompareIds != null && _documentsToCompareIds.size()>0) {
104 List<DocToCompareDTO> docsList = new ArrayList<DocToCompareDTO>();
105 for(Long id : _documentsToCompareIds) {
106 docsList.add(_publicationService.getDocToCompareDTO(id.longValue()));
108 String resultPath = getStudyComparisonService().compare(docsList, getConnectedUser().getUsername());
109 File file = new File(resultPath);
110 _resultInputStream = new FileInputStream(file);
112 } catch(IncompatibleDataException e) {
113 LOG.debug("Error while trying to compare study results: " + e.getMessage());
121 * @return the studyList
123 public List<StudyFacadeDTO> getStudyList() {
129 * @param studyList the studyList to set
131 public void setStudyList(final List<StudyFacadeDTO> studyList) {
132 _studyList = studyList;
136 * Get the filesToCompareIds.
137 * @return the filesToCompareIds
139 public List<Long> getDocumentsToCompareIds() {
140 return _documentsToCompareIds;
144 * Set the filesToCompareIds.
145 * @param filesToCompareIds the filesToCompareIds to set
147 public void setDocumentsToCompareIds(final List<Long> filesToCompareIds) {
148 _documentsToCompareIds = filesToCompareIds;
152 * Get the resultName.
153 * @return the resultName
155 public String getResultName() {
160 * Set the resultName.
161 * @param resultName the resultName to set
163 public void setResultName(final String resultName) {
164 _resultName = resultName;
169 * @return the resultUrl
171 public String getResultUrl() {
177 * @param resultUrl the resultUrl to set
179 public void setResultUrl(final String resultUrl) {
180 _resultUrl = resultUrl;
184 * Get the publicationService.
185 * @return the publicationService
187 public PublicationService getPublicationService() {
188 return _publicationService;
192 * Set the publicationService.
193 * @param publicationService the publicationService to set
195 public void setPublicationService(PublicationService publicationService) {
196 _publicationService = publicationService;
200 * Get the resultInputStream.
201 * @return the resultInputStream
203 public InputStream getResultInputStream() {
204 return _resultInputStream;
208 * Set the resultInputStream.
209 * @param resultInputStream the resultInputStream to set
211 public void setResultInputStream(InputStream resultInputStream) {
212 _resultInputStream = resultInputStream;
216 * Get the errorMessage.
217 * @return the errorMessage
219 public Boolean getErrorMessage() {
220 return _errorMessage;
224 * Set the errorMessage.
225 * @param errorMessage the errorMessage to set
227 public void setErrorMessage(final Boolean errorMessage) {
228 _errorMessage = errorMessage;
232 * Get the studyComparisonService.
233 * @return the studyComparisonService
235 public StudyComparisonService getStudyComparisonService() {
236 return _studyComparisonService;
240 * Set the studyComparisonService.
241 * @param studyComparisonService the studyComparisonService to set
243 public void setStudyComparisonService(
244 final StudyComparisonService studyComparisonService) {
245 _studyComparisonService = studyComparisonService;