comparison src/main/java/de/mpiwg/itgroup/ismi/search/beans/CodexOwnershipQuery.java @ 1:2e911857a759

(none)
author jurzua
date Wed, 29 Oct 2014 14:00:28 +0000
parents
children
comparison
equal deleted inserted replaced
0:74df02964906 1:2e911857a759
1 package de.mpiwg.itgroup.ismi.search.beans;
2
3 import java.io.Serializable;
4 import java.util.ArrayList;
5 import java.util.List;
6
7 import org.apache.commons.lang.StringUtils;
8 import org.mpi.openmind.cache.WrapperService;
9 import org.mpi.openmind.repository.bo.Entity;
10 import org.mpi.openmind.repository.bo.Relation;
11 import org.mpi.openmind.search.utils.ResultEntry;
12 import org.mpi.openmind.search.utils.SAttributeMultipleName;
13 import org.mpi.openmind.search.utils.SEntity;
14 import org.mpi.openmind.search.utils.SRelation;
15
16 import de.mpiwg.itgroup.ismi.entry.beans.ApplicationBean;
17
18 public class CodexOwnershipQuery extends AbstractQuery{
19
20 private static final long serialVersionUID = 5481872257359678512L;
21
22 private String personName;
23 private String codexShelfMark;
24
25 public CodexOwnershipQuery(ApplicationBean appBean){
26 super(appBean);
27 this.exportUrlRoot = ApplicationBean.urlISMIExportServiceAuthors;
28 }
29
30 @Override
31 public void reset(){
32 super.reset();
33 this.rs = null;
34 this.personName = null;
35 this.codexShelfMark = null;
36 }
37
38 @Override
39 protected void search() throws Exception{
40
41 List<Relation> wasOwnerByList = appBean.getWrapper().getRelation("owned_by", "CODEX", "PERSON");
42 List<Long> personCandidates = null;
43 List<Long> codexCadidates = null;
44
45 if(StringUtils.isNotEmpty(personName)){
46 personCandidates = getPersonCadidates(personName);
47 }
48 if(StringUtils.isNotEmpty(codexShelfMark)){
49 codexCadidates = getCodexCadidates(codexShelfMark);
50 }
51
52 rs = this.loadResultSet(wasOwnerByList, personCandidates, codexCadidates);
53
54 /*
55 * TODO there is report for it???
56 List<Long> idLongList = new ArrayList<Long>();
57 for(Object e : rs){
58 Titles4PersonEntry entry = (Titles4PersonEntry)e;
59 if(!idLongList.contains(entry.getPersonId()))
60 idLongList.add(entry.getPersonId());
61 }
62 this.idList = ApplicationBean.generateIdList(idLongList);
63
64 this.exportDirkUrl = ApplicationBean.generateExportURL(exportUrlRoot, idList, "xml");
65 */
66 }
67
68 private List<CodexOwnershipEntry> loadResultSet(List<Relation> wasOwnerByList,
69 List<Long> personCandidates,
70 List<Long> codexCadidates){
71
72 List<CodexOwnershipEntry> list = new ArrayList<CodexOwnershipQuery.CodexOwnershipEntry>();
73
74 if(!wasOwnerByList.isEmpty()){
75 for(Relation rel : wasOwnerByList){
76 if((codexCadidates == null || codexCadidates.contains(rel.getSourceId())) &&
77 (personCandidates == null ||personCandidates.contains(rel.getTargetId()))){
78 list.add(new CodexOwnershipEntry(
79 appBean.getWrapper().getEntityById(rel.getSourceId()), appBean.getWrapper().getEntityById(rel.getTargetId()),
80 appBean.getWrapper()));
81 }
82 }
83 }
84
85 return list;
86 }
87
88
89 public String getPersonName() {
90 return personName;
91 }
92
93 public void setPersonName(String personName) {
94 this.personName = personName;
95 }
96
97 public String getCodexShelfMark() {
98 return codexShelfMark;
99 }
100
101 public void setCodexShelfMark(String codexShelfMark) {
102 this.codexShelfMark = codexShelfMark;
103 }
104
105 private List<Long> getPersonCadidates(String personName){
106 List<SEntity> entFilters = new ArrayList<SEntity>();
107
108 //TODO
109 //alias, "is_prime_alias_name_of", "PERSON"
110 //alias, "is_alias_name_of", "PERSON"
111 SEntity person = new SEntity(0, "PERSON");
112 if(StringUtils.isNotEmpty(personName)){
113 person.addAtt(new SAttributeMultipleName(personName, "name_translit", "name"));
114 }
115 entFilters.add(person);
116
117 List<Long> idList = new ArrayList<Long>();
118 for(ResultEntry entry : this.appBean.getSS().search(entFilters, new ArrayList<SRelation>())){
119 idList.add(entry.getEntMap().get(0));
120 }
121 return idList;
122 }
123
124 private List<Long> getCodexCadidates(String shelfMark){
125
126 List<SEntity> entFilters = new ArrayList<SEntity>();
127
128 SEntity codex = new SEntity(0, "CODEX");
129 if(StringUtils.isNotEmpty(shelfMark)){
130 codex.addAtt(new SAttributeMultipleName(shelfMark, "identifier"));
131 }
132 entFilters.add(codex);
133
134 List<Long> idList = new ArrayList<Long>();
135 for(ResultEntry entry : this.appBean.getSS().search(entFilters, new ArrayList<SRelation>())){
136 idList.add(entry.getEntMap().get(0));
137 }
138 return idList;
139 }
140
141 public class CodexOwnershipEntry implements Serializable{
142
143 private static final long serialVersionUID = -6118835259154299870L;
144
145 private Long personId;
146 private String personOv;
147 private Long codexId;
148 private String codexOv;
149 private String shelfMark;
150 private String collection;
151
152 public CodexOwnershipEntry(Entity codex, Entity person, WrapperService ws){
153 this.personId = person.getId();
154 this.personOv = person.getOwnValue();
155 this.codexId = codex.getId();
156 this.codexOv = codex.getOwnValue();
157 //this.shelfMark = (codex.getAttributeByName("identifier") != null) ? codex.getAttributeByName("identifier").getOwnValue() : null;
158 try{
159 String[] array = this.codexOv.split("_");
160 if(array.length > 0){
161 this.collection = array[0];
162 this.shelfMark = array[1];
163 }
164 }catch (Exception e) {
165 e.printStackTrace();
166 }
167 }
168
169 public Long getPersonId() {
170 return personId;
171 }
172
173 public void setPersonId(Long personId) {
174 this.personId = personId;
175 }
176
177 public String getPersonOv() {
178 return personOv;
179 }
180
181 public void setPersonOv(String personOv) {
182 this.personOv = personOv;
183 }
184
185 public Long getCodexId() {
186 return codexId;
187 }
188
189 public void setCodexId(Long codexId) {
190 this.codexId = codexId;
191 }
192
193 public String getCodexOv() {
194 return codexOv;
195 }
196
197 public void setCodexOv(String codexOv) {
198 this.codexOv = codexOv;
199 }
200
201 public String getShelfMark() {
202 return shelfMark;
203 }
204
205 public void setShelfMark(String shelfMark) {
206 this.shelfMark = shelfMark;
207 }
208
209 public String getCollection() {
210 return collection;
211 }
212
213 public void setCollection(String collection) {
214 this.collection = collection;
215 }
216 }
217
218
219 }