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