]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman/src/org/splat/simer/UploadBaseNextAction.java
Salome HOME
Refactoring of Database, replacing SQL by DAOs calls. Methods for search by criteria...
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / UploadBaseNextAction.java
1 package org.splat.simer;
2
3 import java.util.Iterator;
4 import java.util.List;
5 import java.util.Set;
6
7 import org.splat.dal.bo.som.Document;
8 import org.splat.dal.bo.som.DocumentType;
9 import org.splat.dal.bo.som.ProgressState;
10 import org.splat.dal.bo.som.Publication;
11 import org.splat.som.Step;
12
13
14 public abstract class UploadBaseNextAction extends Action {
15
16     protected OpenStudy      mystudy  = null;
17     protected String         filename = null;   // Uploaded file name
18     protected DocumentType   deftype  = null;
19     protected List<Document> defuses  = null;
20     protected String         docname  = null;
21     protected ProgressState  state    = null;
22     protected String         docuses  = null;
23     protected ToDo           action   = null;
24
25         /**
26          * Serial version ID.
27          */
28     private static final long serialVersionUID = -6925961099244461039L;
29
30     protected enum  ToDo { cancel, save };
31
32 //  ==============================================================================================================================
33 //  Getters and setters
34 //  ==============================================================================================================================
35
36     public DocumentType getDefaultDocumentType () {
37 //  ---------------------------------------------
38       return deftype;
39     }
40     public List<Document> getDefaultDocumentUses () {
41 //  -----------------------------------------------
42       return defuses;
43     }
44     public String getDocumentName () {
45 //  --------------------------------
46       return docname;
47     }
48     public String getDocumentState () {
49 //  ---------------------------------
50       return state.toString();
51     }
52     public String getFileName () {
53 //  ----------------------------
54       return filename;
55     }
56
57     public void setCancel (boolean cancel) {
58 //  --------------------------------------
59       this.action = ToDo.cancel;
60     }
61     public void setDocumentState (String state) {
62 //  -------------------------------------------
63       this.state = ProgressState.valueOf(state);
64     }
65     public void setFileName (String path) {
66 //  -------------------------------------
67       this.filename = path;
68     }
69     public void setUses (String list) {
70 //  ---------------------------------
71       this.docuses = list;
72     }
73     public void setSave (boolean save) {
74 //  ----------------------------------
75       this.action = ToDo.save;
76     }
77 //  ==============================================================================================================================
78 //  Protected services
79 //  ==============================================================================================================================
80
81     protected void setupDefaultUses (DocumentType type) {
82 //  -------------------------------------------------
83       Set<DocumentType> uses = type.getDefaultUses();
84       
85       for (Iterator<DocumentType> i=uses.iterator(); i.hasNext();) {
86         DocumentType   usetype = i.next();
87         List<Document> usedoc  = mystudy.collectInvolvedDocuments(usetype);
88         if (usedoc.isEmpty()) setupDefaultUses(usetype);
89         else                  defuses.addAll(usedoc);
90       }
91     }
92
93     protected Publication getPublication (int index) {
94 //  ------------------------------------------------
95       List<Step> steps = mystudy.getInvolvedSteps();
96       
97       for (Iterator<Step> i=steps.iterator(); i.hasNext(); ) {
98         List<Publication> published = i.next().getAllDocuments();
99         for (Iterator<Publication> j=published.iterator(); j.hasNext();) {
100           Publication found = j.next();                          // In a given study step,
101           if (found.value().getIndex() == index) return found;   // there is only one publication of a given document
102         }
103       }
104       return null;
105     }
106 }