Salome HOME
Modifications done to respect PMD rules. Versioning a document is fixed. Validation...
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / UploadAction.java
1 package org.splat.simer;
2
3 import java.io.File;
4
5 import org.splat.kernel.Do;
6 import org.splat.service.technical.RepositoryService;
7 import org.splat.dal.dao.som.Database;
8
9
10 public class UploadAction extends Action {
11
12         private File    upload         = null;
13         private String  uploadMimeType = null;
14     private String  uploadFileName = null;
15
16     private ToDo    action;                  // Action to do
17     private String  next           = null;   // Action to which the uploaded file is passed
18         private String  index          = null;   // Depending on the next action, document index to which the action applies
19         /**
20          * Injected repository service.
21          */
22         private RepositoryService _repositoryService;
23         
24         /**
25          * Value of the menu property. 
26          * It can be: none, create, open, study, knowledge, sysadmin, help.
27          */
28         private String _menuProperty;
29         
30         /**
31          * Value of the title bar property. 
32          * It can be: study, knowledge.
33          */
34         private String _titleProperty;
35         
36         /**
37          * Value of the tool bar property. 
38          * It can be: none, standard, study, back.
39          */
40         private String _toolProperty;
41         
42         /**
43          * Value of the left menu property. 
44          * It can be: open, study, knowledge, scenario.
45          */
46         private String _leftMenuProperty;
47         
48         /**
49          * Property that indicates whether the current open study is editable or not.
50          * On the screen it looks like pen on the status icon, pop-up menu also can be called.
51          * It is necessary for correct building the title bar.
52          */
53         private String _editDisabledProperty = "false";
54
55         private static final long serialVersionUID = 6003880772275115923L;
56
57     private enum ToDo { cancel, upload };
58
59 //  ==============================================================================================================================
60 //  Action methods
61 //  ==============================================================================================================================
62
63     public String doInitialize () {
64 //  -----------------------------
65         setMenuProperty("study");
66         setToolProperty("none");
67         setLeftMenuProperty("open");
68                 initializationFullScreenContext(_menuProperty, _toolProperty, _leftMenuProperty);
69                 
70       return SUCCESS;
71     }
72
73     public String doUpload () {
74 //  -------------------------
75       setMenuProperty("study");
76       setTitleProperty("study");
77       setEditDisabledProperty("true");
78       initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty);
79       
80       if (action == ToDo.cancel) return "cancel";
81       try {
82         File    udir = getRepositoryService().getDownloadDirectory(getConnectedUser());
83         String  path = udir.getPath() + "/" + uploadFileName;
84         File    file = new File(path);
85
86         if (!udir.exists()) udir.mkdir();
87         if (file.exists())  file.delete();
88         Do.copy(upload, file);
89         logger.info("Uploading \"" + uploadFileName + "\" " + uploadMimeType + " file.");
90         /*if (next == null || next.isEmpty()) {
91                 next = "import";
92         }*/
93         
94         return next;
95       }
96       catch (OutOfMemoryError error) {
97           
98         setMenuProperty("none");
99         setTitleProperty("study");
100         setEditDisabledProperty("true");
101         setToolProperty("none");
102         setLeftMenuProperty("study");
103         initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty);
104                 
105         return "outofmemory";
106       }
107       catch (Exception error) {
108         logger.error("Reason: ", error);
109         return ERROR;
110       }
111     }
112 //  ==============================================================================================================================
113 //  Getters and setters
114 //  ==============================================================================================================================
115
116     public String getIndex () {
117 //  -------------------------
118       return index;
119     }
120     public String getFileName () {
121 //  ----------------------------
122       return uploadFileName;
123     }
124     public String getNextAction () {
125 //  ------------------------------
126       return next;
127     }
128
129     public void setCancel (boolean back) {
130 //  ------------------------------------
131       this.action = ToDo.cancel;
132     }
133     public void setDoIt (boolean upload) {
134 //  --------------------------------
135       this.action = ToDo.upload;
136     }
137     public void setIndex (String index) {
138 //  -----------------------------------
139       this.index = index;
140     }
141     public void setNextAction (String next) {
142 //  ---------------------------------------
143       this.next = next;
144     }
145     public void setUpload (File upload) {
146 //  -----------------------------------
147       this.upload = upload;
148     }
149     public void setUploadFileName (String name) {
150 //  -------------------------------------------
151       this.uploadFileName = name;
152     }
153     public void setUploadContentType (String mime) {
154 //  ----------------------------------------------
155       this.uploadMimeType = mime;
156     }
157
158         /**
159          * Get the repositoryService.
160          * @return the repositoryService
161          */
162         public RepositoryService getRepositoryService() {
163                 return _repositoryService;
164         }
165
166         /**
167          * Set the repositoryService.
168          * @param repositoryService the repositoryService to set
169          */
170         public void setRepositoryService(RepositoryService repositoryService) {
171                 _repositoryService = repositoryService;
172         }
173         
174         /**
175          * Get the menuProperty.
176          * @return the menuProperty
177          */
178         public String getMenuProperty() {
179                 return _menuProperty;
180         }
181
182         /**
183          * Set the menuProperty.
184          * @param menuProperty the menuProperty to set
185          */
186         public void setMenuProperty(String menuProperty) {
187                 this._menuProperty = menuProperty;
188         }
189         
190         /**
191          * Get the _titleProperty.
192          * @return the _titleProperty
193          */
194         public String getTitleProperty() {
195                 return _titleProperty;
196         }
197
198         /**
199          * Set the _titleProperty.
200          * @param _titleProperty the titleProperty to set
201          */
202         public void setTitleProperty(String titleProperty) {
203                 _titleProperty = titleProperty;
204         }
205
206         /**
207          * Get the _editDisabledProperty.
208          * @return the _editDisabledProperty
209          */
210         public String getEditDisabledProperty() {
211                 return _editDisabledProperty;
212         }
213
214         /**
215          * Set the _editDisabledProperty.
216          * @param _editDisabledProperty the _editDisabledProperty to set
217          */
218         public void setEditDisabledProperty(String _editDisabledProperty) {
219                 this._editDisabledProperty = _editDisabledProperty;
220         }
221
222         /**
223          * Get the toolProperty.
224          * @return the toolProperty
225          */
226         public String getToolProperty() {
227                 return _toolProperty;
228         }
229
230         /**
231          * Set the toolProperty.
232          * @param toolProperty the toolProperty to set
233          */
234         public void setToolProperty(final String toolProperty) {
235                 _toolProperty = toolProperty;
236         }
237         
238         /**
239          * Get the leftMenuProperty.
240          * @return the leftMenuProperty
241          */
242         public String getLeftMenuProperty() {
243                 return _leftMenuProperty;
244         }
245
246         /**
247          * Set the leftMenuProperty.
248          * @param leftMenuProperty the leftMenuProperty to set
249          */
250         public void setLeftMenuProperty(final String leftMenuProperty) {
251                 _leftMenuProperty = leftMenuProperty;
252         }
253 }