1 package org.splat.simer;
4 import java.text.ParseException;
5 import java.text.SimpleDateFormat;
6 import java.util.ArrayList;
7 import java.util.Iterator;
9 import java.util.ResourceBundle;
12 import org.splat.dal.bo.kernel.User;
13 import org.splat.dal.bo.som.Document;
14 import org.splat.dal.bo.som.DocumentType;
15 import org.splat.dal.bo.som.ProgressState;
16 import org.splat.dal.bo.som.Publication;
17 import org.splat.manox.Reader;
18 import org.splat.service.PublicationService;
19 import org.splat.service.StepService;
20 import org.splat.service.StudyService;
21 import org.splat.service.technical.ProjectSettingsService;
22 import org.splat.som.Step;
23 import org.splat.wapp.Constants;
26 * Base action for adding a document into a study step.
28 public class BaseUploadDocumentAction extends AbstractUploadNextAction {
33 private static final long serialVersionUID = 7920982168638437486L;
35 * Version number extracted from the imported file, if exist.
37 private String _version = "";
39 * Date extracted from the imported file, if exist.
41 private String _documentDate = "";
43 * Injected project settings service.
45 private ProjectSettingsService _projectSettings;
47 * Injected publication service.
49 private PublicationService _publicationService;
51 * Injected step service.
53 private StepService _stepService;
55 * Injected study service.
57 private StudyService _studyService;
58 protected DocumentType _deftype = null;
59 protected List<Document> _defuses = null;
60 protected String _docname = null;
61 protected String _docuses = null;
62 protected OpenStudy _mystudy = null;
63 protected ProgressState _state = null;
66 * Common initialization of the action form.
69 * if the study editable or not
70 * @return downloaded file
72 protected File commonInitialize(final String editDisabled) {
74 if (Constants.TRUE.equals(getWriteAccess())) {
75 setToolProperty(Constants.STUDY_MENU);
77 setToolProperty(Constants.NONE);
79 initializationFullScreenContext(Constants.STUDY_MENU,
80 Constants.STUDY_MENU, editDisabled, getToolProperty(),
81 Constants.STUDY_MENU);
83 User user = getConnectedUser();
84 File updir = getRepositoryService().getDownloadDirectory(user);
85 File upfile = new File(updir.getPath() + "/" + _fileName);
87 _mystudy = getOpenStudy();
88 _defuses = new ArrayList<Document>();
93 * Extract document date.
97 * @return true if ok, false if error
99 protected boolean extractDate(final Reader tool) {
101 setDocumentDate(tool.extractProperty("date"));
102 if (getDocumentDate() == null) {
105 ResourceBundle locale = ResourceBundle.getBundle("som",
106 getApplicationSettings().getCurrentLocale());
107 SimpleDateFormat check = new SimpleDateFormat(locale
108 .getString("date.format"), getApplicationSettings()
109 .getCurrentLocale());
111 check.parse(getDocumentDate());
112 } catch (ParseException e) {
113 setErrorCode("message.error.format.date");
121 * Set error message and menus.
126 protected void setError(final String errorCode) {
127 setErrorCode(errorCode);
129 initializationFullScreenContext(Constants.STUDY_MENU,
130 Constants.STUDY_MENU, Constants.FALSE, Constants.NONE,
131 Constants.STUDY_MENU);
135 * Date extracted from the imported file, if exist.
137 * @return the file date
139 public String getDocumentDate() {
140 return _documentDate;
144 * Get version number extracted from the imported file, if exist.
146 * @return the document version
148 public String getVersion() {
153 * Set date extracted from the imported file.
158 public void setDocumentDate(final String date) {
159 this._documentDate = date;
163 * Set version number extracted from the imported file, if exist.
168 public void setVersion(final String value) {
169 this._version = value;
173 * Get project settings.
175 * @return Project settings service
177 protected ProjectSettingsService getProjectSettings() {
178 return _projectSettings;
182 * Set project settings service.
184 * @param projectSettingsService
185 * project settings service
187 public void setProjectSettings(
188 final ProjectSettingsService projectSettingsService) {
189 _projectSettings = projectSettingsService;
193 * Get the publicationService.
195 * @return the publicationService
197 public PublicationService getPublicationService() {
198 return _publicationService;
202 * Set the publicationService.
204 * @param publicationService
205 * the publicationService to set
207 public void setPublicationService(
208 final PublicationService publicationService) {
209 _publicationService = publicationService;
213 * Get the stepService.
215 * @return the stepService
217 public StepService getStepService() {
222 * Set the stepService.
225 * the stepService to set
227 public void setStepService(final StepService stepService) {
228 _stepService = stepService;
232 * Get the studyService.
234 * @return the studyService
236 public StudyService getStudyService() {
237 return _studyService;
241 * Set the studyService.
243 * @param studyService
244 * the studyService to set
246 public void setStudyService(final StudyService studyService) {
247 _studyService = studyService;
250 // ==============================================================================================================================
251 // Getters and setters
252 // ==============================================================================================================================
254 public DocumentType getDefaultDocumentType() {
258 public List<Document> getDefaultDocumentUses() {
262 public String getDocumentName() {
266 public String getDocumentState() {
267 return _state.toString();
270 protected Publication getPublication(final int index) {
271 List<Step> steps = _mystudy.getInvolvedSteps();
272 Publication found = null, pub;
273 for (Iterator<Step> i = steps.iterator(); i.hasNext();) {
274 List<Publication> published = i.next().getAllDocuments();
275 for (Iterator<Publication> j = published.iterator(); j.hasNext();) {
276 pub = j.next(); // In a given study step,
277 if (pub.value().getIndex() == index) {
278 found = pub; // there is only one publication of a given document
286 public void setDocumentState(final String state) {
287 this._state = ProgressState.valueOf(state);
290 // ==============================================================================================================================
291 // Protected services
292 // ==============================================================================================================================
294 protected void setupDefaultUses(final DocumentType type) {
295 Set<DocumentType> uses = type.getDefaultUses();
297 for (Iterator<DocumentType> i = uses.iterator(); i.hasNext();) {
298 DocumentType usetype = i.next();
299 List<Document> usedoc = _mystudy.collectInvolvedDocuments(usetype);
300 if (usedoc.isEmpty() && (!usetype.equals(type))) {
301 setupDefaultUses(usetype);
303 _defuses.addAll(usedoc);
308 public void setUses(final String list) {
309 this._docuses = list;
312 public String getWriteAccess() {
313 Boolean res = (_mystudy != null);
315 res = _mystudy.isOpenForWriting();
317 return res.toString();