1
|
1 package de.mpiwg.itgroup.ismi.search.beans;
|
|
2
|
|
3 import java.io.Serializable;
|
|
4 import java.util.ArrayList;
|
|
5 import java.util.Collection;
|
|
6 import java.util.Collections;
|
|
7 import java.util.List;
|
|
8
|
|
9 import javax.faces.event.ValueChangeEvent;
|
|
10 import javax.faces.model.SelectItem;
|
|
11
|
|
12 import org.apache.commons.lang.StringUtils;
|
|
13 import org.mpi.openmind.repository.bo.Entity;
|
|
14 import org.mpi.openmind.repository.utils.NormalizerUtils;
|
|
15 import org.mpi.openmind.repository.utils.TransliterationUtil;
|
|
16 import org.mpi.openmind.search.utils.ResultEntry;
|
|
17 import org.mpi.openmind.search.utils.SAttributeMultipleName;
|
|
18 import org.mpi.openmind.search.utils.SAttributeUniqueName;
|
|
19 import org.mpi.openmind.search.utils.SEntity;
|
|
20 import org.mpi.openmind.search.utils.SRelLongKey;
|
|
21 import org.mpi.openmind.search.utils.SRelation;
|
|
22 import org.mpi.openmind.search.utils.SRelationMultipleName;
|
|
23 import org.mpi.openmind.search.utils.SRelationUniqueName;
|
|
24
|
|
25 import de.mpiwg.itgroup.ismi.entry.beans.ApplicationBean;
|
|
26
|
|
27 /**
|
|
28 * 7) Bring up people associated with a particular witness
|
|
29 * (not just one huge list of people, but be able to distinguish owner, say, from commentator)
|
|
30 * @author jurzua
|
|
31 *
|
|
32 */
|
|
33 public class SampleSearch06 extends AbstractQuery implements Serializable{
|
|
34
|
|
35 private static final long serialVersionUID = 3749889381908517654L;
|
|
36 private String personName;
|
|
37 private String roleName = "Author";
|
|
38 private static List<SelectItem> roleList;
|
|
39
|
|
40
|
|
41 //"Author", "Annotator", "Copyist", "Corrector", "Dedicatee", "Illuminator", "Illustrator", "Owner", "Patron", "inspector"
|
|
42 static{
|
|
43 roleList = new ArrayList<SelectItem>();
|
|
44 roleList.add(new SelectItem("Author"));
|
|
45 roleList.add(new SelectItem("Annotator"));
|
|
46 roleList.add(new SelectItem("Copyist"));
|
|
47 roleList.add(new SelectItem("Corrector"));
|
|
48 roleList.add(new SelectItem("Dedicatee"));
|
|
49 roleList.add(new SelectItem("Illuminator"));
|
|
50 roleList.add(new SelectItem("Illustrator"));
|
|
51 roleList.add(new SelectItem("Owner"));
|
|
52 roleList.add(new SelectItem("Patron"));
|
|
53 roleList.add(new SelectItem("Inspector"));
|
|
54 }
|
|
55
|
|
56
|
|
57 public SampleSearch06(ApplicationBean appBean){
|
|
58 super(appBean);
|
|
59 this.exportUrlRoot = ApplicationBean.urlISMIExportServiceAuthors;
|
|
60 }
|
|
61
|
|
62 @Override
|
|
63 public void reset(){
|
|
64 super.reset();
|
|
65 this.personName = null;
|
|
66 this.roleName = "Author";
|
|
67 this.rs = null;
|
|
68 this.personTitleKeyList = null;
|
|
69 }
|
|
70
|
|
71 @Override
|
|
72 protected void search(){
|
|
73
|
|
74 List<ResultEntry> rs0 = this.execute01(personName, roleName);
|
|
75 List<ResultEntry> rs1 = null;
|
|
76 if(StringUtils.isNotEmpty(personName)){
|
|
77 rs1 = this.execute02(personName, roleName);
|
|
78 }
|
|
79 rs = loadResultSet(rs0, rs1);
|
|
80
|
|
81 List<Long> idLongList = new ArrayList<Long>();
|
|
82 for(Object e : rs){
|
|
83 ResultEntry06 entry = (ResultEntry06)e;
|
|
84 if(!idLongList.contains(entry.getPersonId()))
|
|
85 idLongList.add(entry.getPersonId());
|
|
86 }
|
|
87 this.idList = ApplicationBean.generateIdList(idLongList);
|
|
88
|
|
89 this.exportDirkUrl = ApplicationBean.generateExportURL(exportUrlRoot, idList, "xml");
|
|
90 }
|
|
91
|
|
92 private List<ResultEntry06> loadResultSet(List<ResultEntry> rs0, List<ResultEntry> rs1){
|
|
93 List<ResultEntry06> currentRs = new ArrayList<SampleSearch06.ResultEntry06>();
|
|
94 personTitleKeyList = new ArrayList<SRelLongKey>();
|
|
95
|
|
96 for(ResultEntry re : rs0){
|
|
97
|
|
98 Entity person = getOm().getEntityById(re.getEntMap().get(1));
|
|
99 Entity title = getOm().getEntityById(re.getEntMap().get(2));
|
|
100
|
|
101 String alias = null;
|
|
102 String alias2Person = null;
|
|
103 String role = this.roleName;
|
|
104 String title2Person = re.getRel(2, 1);
|
|
105 List<Entity> subjectList = getOm().getTargetsForSourceRelation(title.getId(), "has_subject", "SUBJECT", 1);
|
|
106 String subject = (subjectList.size() == 0) ? null : subjectList.get(0).getOwnValue();
|
|
107
|
|
108 currentRs.add(new ResultEntry06(person, title, alias, alias2Person, role, title2Person, subject));
|
|
109 putPersonTitleKey(person.getId(), title.getId());
|
|
110 }
|
|
111 if(rs1 != null){
|
|
112 for(ResultEntry re : rs1){
|
|
113 Entity person = getOm().getEntityById(re.getEntMap().get(1));
|
|
114 Entity title = getOm().getEntityById(re.getEntMap().get(3));
|
|
115 if(!containsPersonTitleKey(person.getId(), title.getId())){
|
|
116
|
|
117 String alias = getOm().getEntityById(re.getEntMap().get(2)).getOwnValue();
|
|
118 String alias2Person = re.getRel(2, 1);
|
|
119 String role = this.roleName;
|
|
120 String title2Person = re.getRel(3, 1);
|
|
121 List<Entity> subjectList = getOm().getTargetsForSourceRelation(title.getId(), "has_subject", "SUBJECT", 1);
|
|
122 String subject = (subjectList.size() == 0) ? null : subjectList.get(0).getOwnValue();
|
|
123
|
|
124 currentRs.add(new ResultEntry06(person, title, alias, alias2Person, role, title2Person, subject));
|
|
125 putPersonTitleKey(person.getId(), title.getId());
|
|
126 }
|
|
127 }
|
|
128 }
|
|
129
|
|
130 Collections.sort(currentRs);
|
|
131
|
|
132 return currentRs;
|
|
133 }
|
|
134
|
|
135 private List<SRelLongKey> personTitleKeyList;
|
|
136 private boolean containsPersonTitleKey(Long personId, Long titleId){
|
|
137 return personTitleKeyList.contains(new SRelLongKey(personId, titleId));
|
|
138 }
|
|
139 private void putPersonTitleKey(Long personId, Long titleId){
|
|
140 personTitleKeyList.add(new SRelLongKey(personId, titleId));
|
|
141 }
|
|
142
|
|
143
|
|
144
|
|
145 private List<ResultEntry> execute01(String personName, String roleName){
|
|
146
|
|
147 List<SEntity> entFilters = new ArrayList<SEntity>();
|
|
148 List<SRelation> relFilters = new ArrayList<SRelation>();
|
|
149
|
|
150 //The user can select between:
|
|
151 //"Author", "Annotator", "Copyist", "Corrector", "Dedicatee", "Illuminator", "Illustrator", "Owner", "Patron", "inspector"
|
|
152 SEntity role = new SEntity(0, "ROLE");
|
|
153 role.addAtt(new SAttributeUniqueName("name", roleName));
|
|
154 entFilters.add(role);
|
|
155
|
|
156 //alias, "is_prime_alias_name_of", "PERSON"
|
|
157 //alias, "is_alias_name_of", "PERSON"
|
|
158 SEntity person = new SEntity(1, "PERSON");
|
|
159 if(StringUtils.isNotEmpty(personName)){
|
|
160 person.addAtt(new SAttributeMultipleName(personName, "name_translit", "name"));
|
|
161 }
|
|
162 entFilters.add(person);
|
|
163
|
|
164 SEntity text = new SEntity(2, "TEXT");
|
|
165 entFilters.add(text);
|
|
166
|
|
167
|
|
168 SRelationUniqueName has_role = new SRelationUniqueName(person, role, "has_role");
|
|
169 SRelationMultipleName text_to_person = new SRelationMultipleName(text, person, "was_created_by", "had_patron", "was_dedicated_to");
|
|
170 relFilters.add(text_to_person);
|
|
171 relFilters.add(has_role);
|
|
172
|
|
173 return this.appBean.getSS().search(entFilters, relFilters);
|
|
174 }
|
|
175
|
|
176 private List<ResultEntry> execute02(String personName, String roleName){
|
|
177
|
|
178 List<SEntity> entFilters = new ArrayList<SEntity>();
|
|
179 List<SRelation> relFilters = new ArrayList<SRelation>();
|
|
180
|
|
181 //The user can select between:
|
|
182 //"Author", "Annotator", "Copyist", "Corrector", "Dedicatee", "Illuminator", "Illustrator", "Owner", "Patron", "inspector"
|
|
183 SEntity role = new SEntity(0, "ROLE");
|
|
184 role.addAtt(new SAttributeUniqueName("name", roleName));
|
|
185 entFilters.add(role);
|
|
186
|
|
187 //alias, "is_prime_alias_name_of", "PERSON"
|
|
188 //alias, "is_alias_name_of", "PERSON"
|
|
189 SEntity person = new SEntity(1, "PERSON");
|
|
190 entFilters.add(person);
|
|
191
|
|
192 SEntity alias = new SEntity(2, "ALIAS");
|
|
193 alias.addAtt(new SAttributeUniqueName("alias", personName));
|
|
194 entFilters.add(alias);
|
|
195
|
|
196 SEntity text = new SEntity(3, "TEXT");
|
|
197 entFilters.add(text);
|
|
198
|
|
199
|
|
200 SRelationMultipleName is_alias = new SRelationMultipleName(alias, person, "is_alias_name_of", "is_prime_alias_name_of");
|
|
201 SRelationUniqueName has_role = new SRelationUniqueName(person, role, "has_role");
|
|
202 SRelationMultipleName text_to_person = new SRelationMultipleName(text, person, "was_created_by", "had_patron", "was_dedicated_to");
|
|
203 relFilters.add(text_to_person);
|
|
204 relFilters.add(has_role);
|
|
205 relFilters.add(is_alias);
|
|
206
|
|
207 return this.appBean.getSS().search(entFilters, relFilters);
|
|
208 }
|
|
209
|
|
210
|
|
211 public String getPersonName() {
|
|
212 return personName;
|
|
213 }
|
|
214
|
|
215 public void setPersonName(String personName) {
|
|
216 this.personName = personName;
|
|
217 }
|
|
218
|
|
219 public String getRoleName() {
|
|
220 return roleName;
|
|
221 }
|
|
222
|
|
223 public void setRoleName(String roleName) {
|
|
224 this.roleName = roleName;
|
|
225 }
|
|
226
|
|
227 public List<SelectItem> getRoleList() {
|
|
228 return roleList;
|
|
229 }
|
|
230
|
|
231 public class ResultEntry06 implements Comparable<ResultEntry06>, Serializable{
|
|
232 private static final long serialVersionUID = 3814421582310240565L;
|
|
233
|
|
234 private Long personId;
|
|
235 private String personOv;
|
|
236 private String personNOv;
|
|
237 private String alias;
|
|
238 private String alias2Person;
|
|
239 private Long titleId;
|
|
240 private String titleOv;
|
|
241 private String titleNOv;
|
|
242 private String role;
|
|
243 private String title2Person;
|
|
244 private String subject;
|
|
245
|
|
246 public ResultEntry06(
|
|
247 Entity person,
|
|
248 Entity title,
|
|
249 String alias,
|
|
250 String alias2Person,
|
|
251 String role,
|
|
252 String title2Person,
|
|
253 String subject
|
|
254 ){
|
|
255
|
|
256 set(person, title);
|
|
257 this.alias = alias;
|
|
258 this.alias2Person = alias2Person;
|
|
259 this.role = role;
|
|
260 this.title2Person = title2Person;
|
|
261 this.subject = subject;
|
|
262 }
|
|
263
|
|
264 private void set(Entity person, Entity title){
|
|
265 this.personId = person.getId();
|
|
266 this.personOv = person.getOwnValue();
|
|
267 this.personNOv = person.getNormalizedOwnValue();
|
|
268
|
|
269 this.titleId = title.getId();
|
|
270 this.titleOv = title.getOwnValue();
|
|
271 this.titleNOv = title.getNormalizedOwnValue();
|
|
272 }
|
|
273
|
|
274 public Long getPersonId() {
|
|
275 return personId;
|
|
276 }
|
|
277
|
|
278 public String getPersonOv() {
|
|
279 return personOv;
|
|
280 }
|
|
281
|
|
282 public String getPersonNOv() {
|
|
283 return personNOv;
|
|
284 }
|
|
285
|
|
286 public String getAlias() {
|
|
287 return alias;
|
|
288 }
|
|
289
|
|
290 public String getAlias2Person() {
|
|
291 return alias2Person;
|
|
292 }
|
|
293
|
|
294 public Long getTitleId() {
|
|
295 return titleId;
|
|
296 }
|
|
297
|
|
298 public String getTitleOv() {
|
|
299 return titleOv;
|
|
300 }
|
|
301
|
|
302 public String getTitleNOv() {
|
|
303 return titleNOv;
|
|
304 }
|
|
305
|
|
306 public String getRole() {
|
|
307 return role;
|
|
308 }
|
|
309
|
|
310 public String getTitle2Person() {
|
|
311 return title2Person;
|
|
312 }
|
|
313
|
|
314 public String getSubject() {
|
|
315 return subject;
|
|
316 }
|
|
317
|
|
318 @Override
|
|
319 public int compareTo(ResultEntry06 o) {
|
|
320 if(!this.personId.equals(o.personId)){
|
|
321
|
|
322 int comparisonPerson = NormalizerUtils.normalizedToCompare(personNOv).compareTo(
|
|
323 NormalizerUtils.normalizedToCompare(o.personNOv));
|
|
324 if(comparisonPerson != 0){
|
|
325 return comparisonPerson;
|
|
326 }else{
|
|
327 if(StringUtils.isNotEmpty(role) && StringUtils.isNotEmpty(o.role)){
|
|
328 int comparisonRole = this.role.compareTo(o.role);
|
|
329 if(comparisonRole != 0){
|
|
330 return comparisonRole;
|
|
331 }
|
|
332 }else{
|
|
333 if(StringUtils.isNotEmpty(role)){
|
|
334 return -1;
|
|
335 }else if(StringUtils.isNotEmpty(o.role)){
|
|
336 return 1;
|
|
337 }
|
|
338 }
|
|
339 }
|
|
340 }else{
|
|
341 if(!this.titleId.equals(o.titleId)){
|
|
342 //comparing subject
|
|
343 if(StringUtils.isNotEmpty(subject) && StringUtils.isNotEmpty(o.subject)){
|
|
344 int comparisonSubject = this.subject.compareTo(o.subject);
|
|
345 if(comparisonSubject != 0){
|
|
346 return comparisonSubject;
|
|
347 }
|
|
348 }else{
|
|
349 if(StringUtils.isNotEmpty(subject)){
|
|
350 return -1;
|
|
351 }else if(StringUtils.isNotEmpty(o.subject)){
|
|
352 return 1;
|
|
353 }
|
|
354 }
|
|
355 //comparing title
|
|
356 int comparisonTitle = NormalizerUtils.normalizedToCompare(titleNOv).compareTo(
|
|
357 NormalizerUtils.normalizedToCompare(o.titleNOv));
|
|
358 return comparisonTitle;
|
|
359 }
|
|
360 }
|
|
361 return 0;
|
|
362 }
|
|
363 }
|
|
364 }
|