]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman/src/org/splat/simer/CompareStudyAction.java
Salome HOME
Fix:
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / CompareStudyAction.java
1 /*****************************************************************************
2  * Company         EURIWARE
3  * Application     SIMAN
4  * File            $Id$ 
5  * Creation date   Dec 11, 2012
6  * @author         $Author$
7  * @version        $Revision$
8  *****************************************************************************/
9
10 package org.splat.simer; 
11
12 import java.io.File;
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;
18
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;
27
28 /**
29  * Performs comparison of studies.
30  * @author isr
31  *
32  */
33 public class CompareStudyAction extends DisplayStudyStepAction {
34
35         /**
36          * Serial version ID.
37          */
38         private static final long serialVersionUID = 6467920934724352021L;
39         
40         /**
41          * List of StudyDTO containing ScenarioDTO containing publications available for comparison.
42          */
43         private List<StudyFacadeDTO> _studyList;
44         
45         /**
46          * Ids of files to compare.
47          */
48         private List<Long> _documentsToCompareIds;
49         
50         /**
51          * Comparison result file name.
52          */
53         private String _resultName = null;
54         
55         /**
56          * The result URL.
57          */
58         private String _resultUrl;
59         
60         /**
61          * The result Input Stream.
62          */
63         private InputStream _resultInputStream;
64
65         /**
66          * Injected publication service.
67          */
68         private PublicationService _publicationService;
69
70         /**
71          * Injected study comparison service.
72          */
73         private StudyComparisonService _studyComparisonService;
74
75         /**
76          * If true, "incompatible data" message will be displayed..
77          */
78         private Boolean _errorMessage = false;
79
80         /**
81          * Initialize comparison screen.
82          * @return result
83          * @throws MismatchException if some configurations considering postprocessing step are invalid.
84          */
85         public String doInitComparison() throws MismatchException {
86                 initializationScreenContext(Constants.STUDY_MENU, Constants.BACK);
87                 getTitleBarSettings().setEditDisabledProperty(Constants.TRUE);
88                 String res = SUCCESS;
89                 _studyList = getStudyComparisonService().getComparableStudies(getOpenStudy().getUser().getIndex());
90                 return res;
91         }
92
93         /**
94          * Compare studies.
95          * @throws InvalidParameterException if no publication with given id is found
96          * @throws FileNotFoundException if no file with retrieved filename is found
97          * @return result
98          */
99         public String doCompare() throws InvalidParameterException, FileNotFoundException {
100                 String res = ERROR;
101                 
102                 if(_documentsToCompareIds != null && _documentsToCompareIds.size()>0) {
103                         try {
104                                 List<DocToCompareDTO> docsList = new ArrayList<DocToCompareDTO>();
105                                 for(Long id : _documentsToCompareIds) {
106                                         docsList.add(_publicationService.getDocToCompareDTO(id.longValue()));
107                                 }
108                                 String resultPath = getStudyComparisonService().compare(docsList, getConnectedUser().getUsername());
109                                 File file = new File(resultPath);
110                                 _resultInputStream = new FileInputStream(file);
111                                 res = SUCCESS;
112                         } catch(IncompatibleDataException e) {
113                                 LOG.debug("Error while trying to compare study results: " + e.getMessage());
114                         }
115                 }
116                 return res;
117         }
118
119         /**
120          * Get the studyList.
121          * @return the studyList
122          */
123         public List<StudyFacadeDTO> getStudyList() {
124                 return _studyList;
125         }
126
127         /**
128          * Set the studyList.
129          * @param studyList the studyList to set
130          */
131         public void setStudyList(final List<StudyFacadeDTO> studyList) {
132                 _studyList = studyList;
133         }
134
135         /**
136          * Get the filesToCompareIds.
137          * @return the filesToCompareIds
138          */
139         public List<Long> getDocumentsToCompareIds() {
140                 return _documentsToCompareIds;
141         }
142
143         /**
144          * Set the filesToCompareIds.
145          * @param filesToCompareIds the filesToCompareIds to set
146          */
147         public void setDocumentsToCompareIds(final List<Long> filesToCompareIds) {
148                 _documentsToCompareIds = filesToCompareIds;
149         }
150
151         /**
152          * Get the resultName.
153          * @return the resultName
154          */
155         public String getResultName() {
156                 return _resultName;
157         }
158
159         /**
160          * Set the resultName.
161          * @param resultName the resultName to set
162          */
163         public void setResultName(final String resultName) {
164                 _resultName = resultName;
165         }
166
167         /**
168          * Get the resultUrl.
169          * @return the resultUrl
170          */
171         public String getResultUrl() {
172                 return _resultUrl;
173         }
174
175         /**
176          * Set the resultUrl.
177          * @param resultUrl the resultUrl to set
178          */
179         public void setResultUrl(final String resultUrl) {
180                 _resultUrl = resultUrl;
181         }
182
183         /**
184          * Get the publicationService.
185          * @return the publicationService
186          */
187         public PublicationService getPublicationService() {
188                 return _publicationService;
189         }
190
191         /**
192          * Set the publicationService.
193          * @param publicationService the publicationService to set
194          */
195         public void setPublicationService(PublicationService publicationService) {
196                 _publicationService = publicationService;
197         }
198
199         /**
200          * Get the resultInputStream.
201          * @return the resultInputStream
202          */
203         public InputStream getResultInputStream() {
204                 return _resultInputStream;
205         }
206
207         /**
208          * Set the resultInputStream.
209          * @param resultInputStream the resultInputStream to set
210          */
211         public void setResultInputStream(InputStream resultInputStream) {
212                 _resultInputStream = resultInputStream;
213         }
214
215         /**
216          * Get the errorMessage.
217          * @return the errorMessage
218          */
219         public Boolean getErrorMessage() {
220                 return _errorMessage;
221         }
222
223         /**
224          * Set the errorMessage.
225          * @param errorMessage the errorMessage to set
226          */
227         public void setErrorMessage(final Boolean errorMessage) {
228                 _errorMessage = errorMessage;
229         }
230
231         /**
232          * Get the studyComparisonService.
233          * @return the studyComparisonService
234          */
235         public StudyComparisonService getStudyComparisonService() {
236                 return _studyComparisonService;
237         }
238
239         /**
240          * Set the studyComparisonService.
241          * @param studyComparisonService the studyComparisonService to set
242          */
243         public void setStudyComparisonService(
244                         final StudyComparisonService studyComparisonService) {
245                 _studyComparisonService = studyComparisonService;
246         }
247 }