Salome HOME
Refactoring of Database, replacing SQL by DAOs calls. Methods for search by criteria...
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / admin / DatabaseIndexingAction.java
1 package org.splat.simer.admin;
2
3 import java.util.List;
4 import java.util.Map;
5
6 import org.hibernate.Session;
7 import org.hibernate.Transaction;
8 import org.splat.service.SearchService;
9 import org.splat.service.SearchServiceImpl;
10 import org.splat.service.StudyService;
11 import org.splat.simer.Action;
12 import org.splat.dal.dao.som.Database;
13 import org.splat.dal.bo.som.Study;
14
15
16 public class DatabaseIndexingAction extends Action {
17
18         /**
19          * Serial version ID.
20          */
21     private static final long serialVersionUID = 4194268823457749655L;
22
23     private List<ImportedStudy> newstudies;
24     private String              indices;
25         private SearchService _searchService;
26         private ImportedStudy _importedStudy;
27         private StudyService _studyService;
28
29 //  ==============================================================================================================================
30 //  Action methods
31 //  ==============================================================================================================================
32
33     public String doInitialize () {
34 //  -----------------------------
35       Session      connex  = Database.getSession();
36       Transaction  transax = connex.beginTransaction();
37
38       newstudies = getImportedStudy().selectAll();
39       indices    = "";
40
41       transax.commit();
42       return SUCCESS;
43     }
44
45     public String doIndexing () {
46 //  ---------------------------
47       Session             connex  = Database.getSession();
48       Transaction         transax = connex.beginTransaction();
49       String[]            ridlist = indices.split(",");
50       @SuppressWarnings("unchecked")
51       Map<String, Object> filter  = (Map<String, Object>)getSession().get("study.filter");
52
53       for (int i=0; i<ridlist.length; i++) {
54         int                 index = Integer.valueOf(ridlist[i].trim());
55         Study               study = getStudyService().selectStudy(index);
56         getSearchService().indexStudy(study);
57       }
58       filter.put("owner", "all");   // Just in case of 1st study search
59
60       transax.commit();
61       return SUCCESS;
62     }
63
64 //  ==============================================================================================================================
65 //  Getters and setters
66 //  ==============================================================================================================================
67
68     public List<ImportedStudy> getNewStudies () {
69 //  -------------------------------------------
70       return newstudies;
71     }
72     public String getIndices () {
73 //  ---------------------------
74       return indices;
75     }
76
77     public void setIndices (String indices) {
78 //  ---------------------------------------
79       this.indices = indices;
80     }
81
82         /**
83          * Get the searchService.
84          * @return the searchService
85          */
86         public SearchService getSearchService() {
87                 return _searchService;
88         }
89
90         /**
91          * Set the searchService.
92          * @param searchService the searchService to set
93          */
94         public void setSearchService(SearchService searchService) {
95                 _searchService = searchService;
96         }
97
98         /**
99          * Get the importedStudy.
100          * @return the importedStudy
101          */
102         public ImportedStudy getImportedStudy() {
103                 return _importedStudy;
104         }
105
106         /**
107          * Set the importedStudy.
108          * @param importedStudy the importedStudy to set
109          */
110         public void setImportedStudy(ImportedStudy importedStudy) {
111                 _importedStudy = importedStudy;
112         }
113
114         /**
115          * Get the studyService.
116          * 
117          * @return the studyService
118          */
119         public StudyService getStudyService() {
120                 return _studyService;
121         }
122
123         /**
124          * Set the studyService.
125          * 
126          * @param studyService
127          *            the studyService to set
128          */
129         public void setStudyService(StudyService studyService) {
130                 _studyService = studyService;
131         }
132 }