Salome HOME
b3b00415ab399722e2d42658c726a29833e4defb
[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     private List<ImportedStudy> newstudies;
19     private String              indices;
20         private SearchService _searchService;
21         private ImportedStudy _importedStudy;
22         private StudyService _studyService;
23
24     private static final long serialVersionUID = 4194268823457749655L;
25
26 //  ==============================================================================================================================
27 //  Action methods
28 //  ==============================================================================================================================
29
30     public String doInitialize () {
31 //  -----------------------------
32       Session      connex  = Database.getSession();
33       Transaction  transax = connex.beginTransaction();
34
35       newstudies = getImportedStudy().selectAll();
36       indices    = "";
37
38       transax.commit();
39       return SUCCESS;
40     }
41
42     public String doIndexing () {
43 //  ---------------------------
44       Session             connex  = Database.getSession();
45       Transaction         transax = connex.beginTransaction();
46       String[]            ridlist = indices.split(",");
47       @SuppressWarnings("unchecked")
48       Map<String, Object> filter  = (Map<String, Object>)getSession().get("study.filter");
49
50       for (int i=0; i<ridlist.length; i++) {
51         int                 index = Integer.valueOf(ridlist[i].trim());
52         Study               study = getStudyService().selectStudy(index);
53         getSearchService().indexStudy(study);
54       }
55       filter.put("owner", "all");   // Just in case of 1st study search
56
57       transax.commit();
58       return SUCCESS;
59     }
60
61 //  ==============================================================================================================================
62 //  Getters and setters
63 //  ==============================================================================================================================
64
65     public List<ImportedStudy> getNewStudies () {
66 //  -------------------------------------------
67       return newstudies;
68     }
69     public String getIndices () {
70 //  ---------------------------
71       return indices;
72     }
73
74     public void setIndices (String indices) {
75 //  ---------------------------------------
76       this.indices = indices;
77     }
78
79         /**
80          * Get the searchService.
81          * @return the searchService
82          */
83         public SearchService getSearchService() {
84                 return _searchService;
85         }
86
87         /**
88          * Set the searchService.
89          * @param searchService the searchService to set
90          */
91         public void setSearchService(SearchService searchService) {
92                 _searchService = searchService;
93         }
94
95         /**
96          * Get the importedStudy.
97          * @return the importedStudy
98          */
99         public ImportedStudy getImportedStudy() {
100                 return _importedStudy;
101         }
102
103         /**
104          * Set the importedStudy.
105          * @param importedStudy the importedStudy to set
106          */
107         public void setImportedStudy(ImportedStudy importedStudy) {
108                 _importedStudy = importedStudy;
109         }
110
111         /**
112          * Get the studyService.
113          * 
114          * @return the studyService
115          */
116         public StudyService getStudyService() {
117                 return _studyService;
118         }
119
120         /**
121          * Set the studyService.
122          * 
123          * @param studyService
124          *            the studyService to set
125          */
126         public void setStudyService(StudyService studyService) {
127                 _studyService = studyService;
128         }
129 }