Mercurial > hg > ismi-richfaces
comparison src/main/java/de/mpiwg/itgroup/ismi/search/beans/SampleSearch07.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 import java.util.Map; | |
7 | |
8 import javax.faces.event.ActionEvent; | |
9 import javax.faces.model.SelectItem; | |
10 | |
11 import org.apache.commons.lang.StringUtils; | |
12 import org.mpi.openmind.repository.bo.Entity; | |
13 import org.mpi.openmind.search.utils.ResultEntry; | |
14 import org.mpi.openmind.search.utils.SAttributeMultipleName; | |
15 import org.mpi.openmind.search.utils.SAttributeUniqueName; | |
16 import org.mpi.openmind.search.utils.SEntity; | |
17 import org.mpi.openmind.search.utils.SRelation; | |
18 import org.mpi.openmind.search.utils.SRelationMultipleName; | |
19 import org.mpi.openmind.search.utils.SRelationUniqueName; | |
20 | |
21 import de.mpiwg.itgroup.ismi.entry.beans.ApplicationBean; | |
22 | |
23 /** | |
24 * 7) Bring up people associated with a particular witness | |
25 * (not just one huge list of people, but be able to distinguish owner, say, from commentator) | |
26 * @author jurzua | |
27 * | |
28 */ | |
29 public class SampleSearch07 extends AbstractQuery implements Serializable{ | |
30 private static final long serialVersionUID = 55883896148547918L; | |
31 | |
32 private String personName; | |
33 private String roleName = "Author"; | |
34 private static List<SelectItem> roleList; | |
35 private List<ResultEntry07> rs; | |
36 | |
37 //"Author", "Annotator", "Copyist", "Corrector", "Dedicatee", "Illuminator", "Illustrator", "Owner", "Patron", "inspector" | |
38 static{ | |
39 roleList = new ArrayList<SelectItem>(); | |
40 roleList.add(new SelectItem("Author")); | |
41 roleList.add(new SelectItem("Annotator")); | |
42 roleList.add(new SelectItem("Copyist")); | |
43 roleList.add(new SelectItem("Corrector")); | |
44 roleList.add(new SelectItem("Dedicatee")); | |
45 roleList.add(new SelectItem("Illuminator")); | |
46 roleList.add(new SelectItem("Illustrator")); | |
47 roleList.add(new SelectItem("Owner")); | |
48 roleList.add(new SelectItem("Patron")); | |
49 roleList.add(new SelectItem("Inspector")); | |
50 } | |
51 | |
52 | |
53 public SampleSearch07(ApplicationBean appBean){ | |
54 super(appBean); | |
55 } | |
56 | |
57 @Override | |
58 public void reset(){ | |
59 super.reset(); | |
60 this.personName = null; | |
61 this.roleName = "Author"; | |
62 this.rs = null; | |
63 } | |
64 | |
65 @Override | |
66 protected void search(){ | |
67 List<ResultEntry> rs0 = this.execute(personName, roleName); | |
68 //this.printRs(rs, this.appBean.getWrapper()); | |
69 | |
70 this.rs = new ArrayList<SampleSearch07.ResultEntry07>(); | |
71 | |
72 int count = 0; | |
73 for(ResultEntry re : rs0){ | |
74 Entity person = getOm().getEntityById(re.getEntMap().get(1)); | |
75 Entity witness = getOm().getEntityById(re.getEntMap().get(2)); | |
76 String witness2Person = re.getRel(2, 1); | |
77 rs.add(new ResultEntry07( | |
78 person.getId(), person.getOwnValue(), | |
79 witness.getId(), witness.getOwnValue(), | |
80 this.roleName, witness2Person)); | |
81 count++; | |
82 if(count >= MAX_RS){ | |
83 break; | |
84 } | |
85 } | |
86 } | |
87 | |
88 private List<ResultEntry> execute(String personName, String roleName){ | |
89 | |
90 List<SEntity> entFilters = new ArrayList<SEntity>(); | |
91 List<SRelation> relFilters = new ArrayList<SRelation>(); | |
92 | |
93 //The user can select between: | |
94 //"Author", "Annotator", "Copyist", "Corrector", "Dedicatee", "Illuminator", "Illustrator", "Owner", "Patron", "inspector" | |
95 SEntity role = new SEntity(0, "ROLE"); | |
96 role.addAtt(new SAttributeUniqueName("name", roleName)); | |
97 entFilters.add(role); | |
98 | |
99 //alias, "is_prime_alias_name_of", "PERSON" | |
100 //alias, "is_alias_name_of", "PERSON" | |
101 SEntity person = new SEntity(1, "PERSON"); | |
102 if(StringUtils.isNotEmpty(personName)){ | |
103 person.addAtt(new SAttributeMultipleName(personName, "name_translit", "name")); | |
104 } | |
105 entFilters.add(person); | |
106 | |
107 SEntity witness = new SEntity(2, "WITNESS"); | |
108 entFilters.add(witness); | |
109 | |
110 | |
111 SRelationUniqueName has_role = new SRelationUniqueName(person, role, "has_role"); | |
112 SRelationMultipleName witness_to_person = new SRelationMultipleName(witness, person, "had_patron", "was_copied_by", "was_created_by", "was_studied_by"); | |
113 relFilters.add(witness_to_person); | |
114 relFilters.add(has_role); | |
115 | |
116 return this.appBean.getSS().search(entFilters, relFilters); | |
117 } | |
118 | |
119 public String getPersonName() { | |
120 return personName; | |
121 } | |
122 | |
123 public void setPersonName(String personName) { | |
124 this.personName = personName; | |
125 } | |
126 | |
127 public String getRoleName() { | |
128 return roleName; | |
129 } | |
130 | |
131 public void setRoleName(String roleName) { | |
132 this.roleName = roleName; | |
133 } | |
134 | |
135 public List<SelectItem> getRoleList() { | |
136 return roleList; | |
137 } | |
138 | |
139 public List<ResultEntry07> getRs() { | |
140 return rs; | |
141 } | |
142 | |
143 @Override | |
144 public Integer getRsSize(){ | |
145 if(rs != null){ | |
146 return rs.size(); | |
147 } | |
148 return 0; | |
149 } | |
150 | |
151 public class ResultEntry07 implements Serializable{ | |
152 private static final long serialVersionUID = -3582904838999322869L; | |
153 | |
154 private Long personId; | |
155 private String personOv; | |
156 private Long witnessId; | |
157 private String witnessOv; | |
158 private String role; | |
159 private String witness2Person; | |
160 | |
161 public ResultEntry07( | |
162 Long personId, String personOv, | |
163 Long witnessId, String witnessOv, | |
164 String role, String witness2Person){ | |
165 | |
166 this.personId = personId; | |
167 this.personOv = personOv; | |
168 this.witnessId = witnessId; | |
169 this.witnessOv = witnessOv; | |
170 this.role = role; | |
171 this.witness2Person = witness2Person; | |
172 } | |
173 | |
174 public Long getPersonId() { | |
175 return personId; | |
176 } | |
177 | |
178 public void setPersonId(Long personId) { | |
179 this.personId = personId; | |
180 } | |
181 | |
182 public String getPersonOv() { | |
183 return personOv; | |
184 } | |
185 | |
186 public void setPersonOv(String personOv) { | |
187 this.personOv = personOv; | |
188 } | |
189 | |
190 public Long getWitnessId() { | |
191 return witnessId; | |
192 } | |
193 | |
194 public void setWitnessId(Long witnessId) { | |
195 this.witnessId = witnessId; | |
196 } | |
197 | |
198 public String getWitnessOv() { | |
199 return witnessOv; | |
200 } | |
201 | |
202 public void setWitnessOv(String witnessOv) { | |
203 this.witnessOv = witnessOv; | |
204 } | |
205 | |
206 public String getRole() { | |
207 return role; | |
208 } | |
209 | |
210 public void setRole(String role) { | |
211 this.role = role; | |
212 } | |
213 | |
214 public String getWitness2Person() { | |
215 return witness2Person; | |
216 } | |
217 | |
218 public void setWitness2Person(String witness2Person) { | |
219 this.witness2Person = witness2Person; | |
220 } | |
221 | |
222 | |
223 } | |
224 } |