Salome HOME
Siman codebase is refactored. Spring beans are introduced in the context.
[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.simer.Action;
11 import org.splat.dal.dao.som.Database;
12 import org.splat.dal.bo.som.Study;
13
14
15 public class DatabaseIndexingAction extends Action {
16
17     private List<ImportedStudy> newstudies;
18     private String              indices;
19         private SearchService _searchService;
20         private ImportedStudy _importedStudy;
21
22     private static final long serialVersionUID = 4194268823457749655L;
23
24 //  ==============================================================================================================================
25 //  Action methods
26 //  ==============================================================================================================================
27
28     public String doInitialize () {
29 //  -----------------------------
30       Session      connex  = Database.getSession();
31       Transaction  transax = connex.beginTransaction();
32
33       newstudies = getImportedStudy().selectAll();
34       indices    = "";
35
36       transax.commit();
37       return SUCCESS;
38     }
39
40     public String doIndexing () {
41 //  ---------------------------
42       Session             connex  = Database.getSession();
43       Transaction         transax = connex.beginTransaction();
44       String[]            ridlist = indices.split(",");
45       @SuppressWarnings("unchecked")
46       Map<String, Object> filter  = (Map<String, Object>)getSession().get("study.filter");
47
48       for (int i=0; i<ridlist.length; i++) {
49         int                 index = Integer.valueOf(ridlist[i].trim());
50         Study               study = Database.selectStudy(index);
51         getSearchService().indexStudy(study);
52       }
53       filter.put("owner", "all");   // Just in case of 1st study search
54
55       transax.commit();
56       return SUCCESS;
57     }
58
59 //  ==============================================================================================================================
60 //  Getters and setters
61 //  ==============================================================================================================================
62
63     public List<ImportedStudy> getNewStudies () {
64 //  -------------------------------------------
65       return newstudies;
66     }
67     public String getIndices () {
68 //  ---------------------------
69       return indices;
70     }
71
72     public void setIndices (String indices) {
73 //  ---------------------------------------
74       this.indices = indices;
75     }
76
77         /**
78          * Get the searchService.
79          * @return the searchService
80          */
81         public SearchService getSearchService() {
82                 return _searchService;
83         }
84
85         /**
86          * Set the searchService.
87          * @param searchService the searchService to set
88          */
89         public void setSearchService(SearchService searchService) {
90                 _searchService = searchService;
91         }
92
93         /**
94          * Get the importedStudy.
95          * @return the importedStudy
96          */
97         public ImportedStudy getImportedStudy() {
98                 return _importedStudy;
99         }
100
101         /**
102          * Set the importedStudy.
103          * @param importedStudy the importedStudy to set
104          */
105         public void setImportedStudy(ImportedStudy importedStudy) {
106                 _importedStudy = importedStudy;
107         }
108 }