1
|
1 package de.mpiwg.itgroup.ismi.utils.templates;
|
|
2
|
|
3 import java.util.ArrayList;
|
|
4 import java.util.Collection;
|
|
5 import java.util.HashMap;
|
|
6 import java.util.List;
|
|
7 import java.util.Map;
|
|
8
|
|
9 import org.apache.commons.lang.StringUtils;
|
|
10 import org.apache.log4j.Logger;
|
|
11 import org.mpi.openmind.cache.WrapperService;
|
|
12 import org.mpi.openmind.repository.bo.Attribute;
|
|
13 import org.mpi.openmind.repository.bo.Entity;
|
|
14 import org.mpi.openmind.repository.bo.Relation;
|
|
15 import org.mpi.openmind.repository.services.PersistenceService;
|
|
16 import org.mpi.openmind.repository.utils.RomanizationLoC;
|
|
17
|
|
18 import de.mpiwg.itgroup.ismi.entry.beans.AbstractISMIBean;
|
|
19 import de.mpiwg.itgroup.ismi.entry.beans.ApplicationBean;
|
|
20 import de.mpiwg.itgroup.ismi.util.guiComponents.Calendar;
|
|
21 import de.mpiwg.itgroup.ismi.utils.NaturalOrderComparator;
|
|
22
|
|
23 public class WitnessTemplate extends AbstractTemplate implements
|
|
24 Comparable<WitnessTemplate> {
|
|
25
|
|
26 private static final long serialVersionUID = -8829977715724255324L;
|
|
27
|
|
28 private static Logger logger = Logger.getLogger(WitnessTemplate.class);
|
|
29
|
|
30 public String privacity;
|
|
31 public Long id;
|
|
32 public String ov;
|
|
33 public String title;
|
|
34 public Long titleId;
|
|
35 public String startPage;
|
|
36 public String endPage;
|
|
37 public String status;
|
|
38 public String tableOfContents;
|
|
39 public String notesOnTitleAuthor;
|
|
40 public String notesOnCollationAndCorrections;
|
|
41 public String notesOnOwnership;
|
|
42 public String notes;
|
|
43 public String codex;
|
|
44 public String collection;
|
|
45 public String repository;
|
|
46 public String city;
|
|
47 public String country;
|
|
48 public String folios;
|
|
49 public String ahlwardtNo;
|
|
50 public String colophon;
|
|
51
|
|
52 public String incipit;
|
|
53 public String explicit;
|
|
54 public String subject;
|
|
55
|
|
56 // public List<String> referenceList;
|
|
57 public Map<String, String> ownedByMap;
|
|
58 public Map<String, String> readByMap;
|
|
59
|
|
60 //extras fields used by the json interface
|
|
61 public String titleAsWrittenInWitness;
|
|
62 public String authorAsWrittenInWitness;
|
|
63 public String copyist;
|
|
64 public String placeOfCopying;
|
|
65
|
|
66 public String page_dimensions;
|
|
67 public String written_area_dimensions;
|
|
68 public String lines_per_page;
|
|
69 public String page_layout;
|
|
70 public String script;
|
|
71 public String writing_surface;
|
|
72 public List<String> wasStudiedByList;
|
|
73 public String fullTitle;
|
|
74 public String fullTitleTranslit;
|
|
75 public String authorName;
|
|
76 public String authorNameTranslit;
|
|
77 public String creationDate;
|
|
78
|
|
79 public boolean useRomanization = false;
|
|
80
|
|
81 public boolean isUnknown() {
|
|
82 return StringUtils.equals("UNKNOWN", this.title);
|
|
83 }
|
|
84
|
|
85 public WitnessTemplate(Entity witness, WrapperService om, boolean useRomanization) {
|
|
86 this.init(witness, om, false, useRomanization);
|
|
87 }
|
|
88
|
|
89 public WitnessTemplate(Entity witness, WrapperService om, boolean extended, boolean useRomanization) {
|
|
90 this.init(witness, om, extended, useRomanization);
|
|
91 }
|
|
92
|
|
93 private void init(Entity witness, WrapperService om, boolean extended, boolean useRomanization) {
|
|
94 // this.referenceList = new ArrayList<String>();
|
|
95 this.ownedByMap = new HashMap<String, String>();
|
|
96 this.readByMap = new HashMap<String, String>();
|
|
97 this.wasStudiedByList = new ArrayList<String>();
|
|
98
|
|
99 this.useRomanization = useRomanization;
|
|
100
|
|
101 try {
|
|
102 if (witness != null) {
|
|
103 this.privacity = witness.getPrivacity();
|
|
104
|
|
105 this.id = witness.getId();
|
|
106 this.ov = (useRomanization) ? RomanizationLoC.convert(witness.getOwnValue()) : witness.getOwnValue();
|
|
107
|
|
108 if (StringUtils.isEmpty(witness.getStatus())) {
|
|
109 this.status = ApplicationBean.STATUS_NOT_CHECKED;
|
|
110 } else {
|
|
111 this.status = witness.getStatus();
|
|
112 }
|
|
113
|
|
114 Attribute att0 = om.getAttributeByName(witness.getId(), "start_page");
|
|
115 this.startPage = (att0 != null) ? att0.getValue() : null;
|
|
116
|
|
117 att0 = om.getAttributeByName(witness.getId(),
|
|
118 "end_page");
|
|
119 this.endPage = (att0 != null) ? att0.getValue() : null;
|
|
120
|
|
121 att0 = om.getAttributeByName(witness.getId(),
|
|
122 "folios");
|
|
123 this.folios = (att0 != null) ? att0.getValue() : null;
|
|
124
|
|
125 att0 = om.getAttributeByName(witness.getId(),
|
|
126 "ahlwardt_no");
|
|
127 this.ahlwardtNo = (att0 != null) ? att0.getValue() : null;
|
|
128
|
|
129 att0 = om.getAttributeByName(witness.getId(), "colophon");
|
|
130 this.colophon = (att0 != null) ? att0.getValue() : null;
|
|
131
|
|
132 att0 = om.getAttributeByName(witness.getId(), "page_dimensions");
|
|
133 this.page_dimensions = (att0 != null) ? att0.getValue() : null;
|
|
134
|
|
135 att0 = om.getAttributeByName(witness.getId(), "written_area_dimensions");
|
|
136 this.written_area_dimensions = (att0 != null) ? att0.getValue() : null;
|
|
137
|
|
138 att0 = om.getAttributeByName(witness.getId(), "lines_per_page");
|
|
139 this.lines_per_page = (att0 != null) ? att0.getValue() : null;
|
|
140
|
|
141 att0 = om.getAttributeByName(witness.getId(), "page_layout");
|
|
142 this.page_layout = (att0 != null) ? att0.getValue() : null;
|
|
143
|
|
144 att0 = om.getAttributeByName(witness.getId(), "script");
|
|
145 this.script = (att0 != null) ? att0.getValue() : null;
|
|
146
|
|
147 att0 = om.getAttributeByName(witness.getId(), "writing_surface");
|
|
148 this.writing_surface = (att0 != null) ? att0.getValue() : null;
|
|
149
|
|
150 att0 = om.getAttributeByName(witness.getId(), "creation_date");
|
|
151 Calendar creationDate0 = AbstractISMIBean.updateCalendar(att0);
|
|
152 this.creationDate = creationDate0.getCalendarAsHtml();
|
|
153
|
|
154 if(extended){
|
|
155 Attribute incipit = om.getAttributeByName(witness.getId(),
|
|
156 "incipit");
|
|
157 this.incipit = (incipit != null) ? incipit.getValue() : null;
|
|
158
|
|
159 Attribute explicit = om.getAttributeByName(witness.getId(),
|
|
160 "explicit");
|
|
161 this.explicit = (explicit != null) ? explicit.getValue() : null;
|
|
162 }
|
|
163
|
|
164 Attribute table_of_contents = om.getAttributeByName(
|
|
165 witness.getId(), "table_of_contents");
|
|
166 this.tableOfContents = (table_of_contents != null) ? table_of_contents
|
|
167 .getValue() : null;
|
|
168
|
|
169 Attribute notes_on_title_author = om.getAttributeByName(
|
|
170 witness.getId(), "notes_on_title_author");
|
|
171 if (notes_on_title_author != null) {
|
|
172 this.notesOnTitleAuthor = notes_on_title_author.getValue();
|
|
173 }
|
|
174
|
|
175 Attribute notes_on_collation_and_corrections = om
|
|
176 .getAttributeByName(witness.getId(),
|
|
177 "notes_on_collation_and_corrections");
|
|
178 if (notes_on_collation_and_corrections != null) {
|
|
179 this.notesOnCollationAndCorrections = notes_on_collation_and_corrections
|
|
180 .getValue();
|
|
181 }
|
|
182
|
|
183 Attribute notes_on_ownership = om.getAttributeByName(
|
|
184 witness.getId(), "notes_on_ownership");
|
|
185 if (notes_on_ownership != null) {
|
|
186 this.notesOnOwnership = notes_on_ownership.getValue();
|
|
187 }
|
|
188
|
|
189 att0 = om.getAttributeByName(witness.getId(), "notes");
|
|
190 this.notes = (att0 != null) ? att0.getValue() : null;
|
|
191
|
|
192 List<Entity> list0 = om.getTargetsForSourceRelation(witness.getId(), "is_exemplar_of", "TEXT", 1);
|
|
193 if (list0.size() > 0) {
|
|
194 this.title = (useRomanization) ? RomanizationLoC.convert(list0.get(0).getOwnValue()) : list0.get(0).getOwnValue();
|
|
195 this.titleId = list0.get(0).getId();
|
|
196 att0 = om.getAttributeByName(titleId, "full_title");
|
|
197 this.fullTitle = (att0 != null) ? att0.getOwnValue() : null;
|
|
198 this.fullTitle = (useRomanization) ? RomanizationLoC.convert(fullTitle) : fullTitle;
|
|
199
|
|
200 att0 = om.getAttributeByName(titleId, "full_title_translit");
|
|
201 if(att0 != null){
|
|
202 this.fullTitleTranslit = (useRomanization) ? RomanizationLoC.convert(att0.getOwnValue()) : att0.getOwnValue();
|
|
203 }
|
|
204
|
|
205 List<Entity> list1 = om.getTargetsForSourceRelation(this.titleId, "was_created_by", "PERSON", 1);
|
|
206 if(list1.size() > 0){
|
|
207 Entity author = list1.get(0);
|
|
208 att0 = om.getAttributeByName(author.getId(), "name");
|
|
209 this.authorName = (att0 == null) ? null : att0.getValue();
|
|
210 this.authorName = (useRomanization) ? RomanizationLoC.convert(authorName) : authorName;
|
|
211 att0 = om.getAttributeByName(author.getId(), "name_translit");
|
|
212 if(att0 != null){
|
|
213 this.authorNameTranslit = (useRomanization) ? RomanizationLoC.convert(att0.getValue()) : att0.getValue();
|
|
214 }
|
|
215 }
|
|
216
|
|
217 if(extended){
|
|
218 //Attribute subject = om.getAttributeByName(witness.getId(), "subject");
|
|
219 list0 = om.getTargetsForSourceRelation(this.titleId, "has_subject", "SUBJECT", 1);
|
|
220 this.subject = (!list0.isEmpty()) ? list0.get(0).getOwnValue() : null;
|
|
221
|
|
222 }
|
|
223 }
|
|
224
|
|
225 list0 = om.getTargetsForSourceRelation(witness, "has_author_written_as", "ALIAS", 1);
|
|
226 if(list0.size() > 0){
|
|
227 this.authorAsWrittenInWitness = (useRomanization) ? RomanizationLoC.convert(list0.get(0).getOwnValue()) : list0.get(0).getOwnValue();
|
|
228 }
|
|
229
|
|
230 list0 = om.getTargetsForSourceRelation(witness, "has_title_written_as", "ALIAS", 1);
|
|
231 if(list0.size() > 0){
|
|
232 this.titleAsWrittenInWitness = (useRomanization) ? RomanizationLoC.convert(list0.get(0).getOwnValue()) : list0.get(0).getOwnValue();
|
|
233 }
|
|
234
|
|
235 list0 = om.getTargetsForSourceRelation(witness, "was_copied_by", "PERSON", 1);
|
|
236 if(list0.size() > 0){
|
|
237 this.copyist = (useRomanization) ? RomanizationLoC.convert(list0.get(0).getOwnValue()) : list0.get(0).getOwnValue();
|
|
238 }
|
|
239
|
|
240 list0 = om.getTargetsForSourceRelation(witness, "was_copied_in", "PLACE", 1);
|
|
241 this.placeOfCopying = (list0.size() > 0) ? list0.get(0).getOwnValue() : null;
|
|
242
|
|
243
|
|
244 list0 = om.getTargetsForSourceRelation(witness, "was_studied_by", "PERSON", 1);
|
|
245 for(Entity ent : list0){
|
|
246 this.wasStudiedByList.add((useRomanization) ? RomanizationLoC.convert(ent.getOwnValue()) : ent.getOwnValue());
|
|
247 }
|
|
248
|
|
249 List<Entity> list = om.getTargetsForSourceRelation(
|
|
250 witness.getId(), "is_part_of", "CODEX", 1);
|
|
251 if (list.size() > 0) {
|
|
252 Entity codex = list.get(0);
|
|
253
|
|
254 Attribute att = om.getAttributeByName(codex.getId(),
|
|
255 "identifier");
|
|
256 if (att != null && StringUtils.isNotEmpty(att.getValue())) {
|
|
257 this.codex = att.getValue();
|
|
258 }
|
|
259
|
|
260 for (Relation rel : om.getSourceRelations(codex,
|
|
261 "owned_by", "PERSON", -1)) {
|
|
262 String date = (rel.getAttributeByName("date") != null) ? new Calendar(
|
|
263 rel.getAttributeByName("date").getOwnValue())
|
|
264 .getCalendarAsHtml() : "";
|
|
265 String ov = om.getEntityById(rel.getTargetId()).getOwnValue();
|
|
266 String ownedLabel = (useRomanization) ? RomanizationLoC.convert(ov) : ov;
|
|
267 this.ownedByMap.put(ownedLabel, date);
|
|
268 }
|
|
269
|
|
270 for (Relation rel : om.getSourceRelations(codex, "read_by",
|
|
271 "PERSON", -1)) {
|
|
272 String date = (rel.getAttributeByName("date") != null) ? new Calendar(
|
|
273 rel.getAttributeByName("date").getOwnValue())
|
|
274 .getCalendarAsHtml() : "";
|
|
275 String ov = om.getEntityById(rel.getTargetId()).getOwnValue();
|
|
276 String readerLabel = (useRomanization) ? RomanizationLoC.convert(ov) : ov;
|
|
277 this.readByMap.put(readerLabel, date);
|
|
278 }
|
|
279
|
|
280 list = om.getTargetsForSourceRelation(codex.getId(),
|
|
281 "is_part_of", "COLLECTION", 1);
|
|
282 if (list.size() > 0) {
|
|
283 Entity collection = list.get(0);
|
|
284 this.collection = collection.getOwnValue();
|
|
285
|
|
286 list = om.getTargetsForSourceRelation(
|
|
287 collection.getId(), "is_part_of", "REPOSITORY",
|
|
288 1);
|
|
289
|
|
290 if (list.size() > 0) {
|
|
291 Entity repository = list.get(0);
|
|
292 this.repository = repository.getOwnValue();
|
|
293
|
|
294 list = om.getTargetsForSourceRelation(
|
|
295 repository.getId(), "is_in", "PLACE", 1);
|
|
296
|
|
297 if (list.size() > 0) {
|
|
298 Entity city = list.get(0);
|
|
299 this.city = city.getOwnValue();
|
|
300
|
|
301 list = om.getTargetsForSourceRelation(
|
|
302 city.getId(), "is_part_of", "PLACE", 1);
|
|
303 if (list.size() > 0) {
|
|
304 Entity country = list.get(0);
|
|
305 this.country = country.getOwnValue();
|
|
306 }
|
|
307 }
|
|
308 }
|
|
309 }
|
|
310 }
|
|
311
|
|
312 list0 = om.getSourcesForTargetRelation(witness,
|
|
313 "is_reference_of", "REFERENCE", -1);
|
|
314 for (Entity ref : list0) {
|
|
315 System.out.println("### REF= " + ref.getId());
|
|
316 this.refEntityList.add(om.getEntityContent(ref));
|
|
317 }
|
|
318 }
|
|
319
|
|
320 this.loadRefernces();
|
|
321 } catch (Exception e) {
|
|
322 logger.error(e.getMessage(), e);
|
|
323 }
|
|
324 }
|
|
325
|
|
326 public String getPrivacity() {
|
|
327 return privacity;
|
|
328 }
|
|
329
|
|
330 public String getStatus() {
|
|
331 return status;
|
|
332 }
|
|
333
|
|
334 public String getTableOfContents() {
|
|
335 return tableOfContents;
|
|
336 }
|
|
337
|
|
338 public String getNotesOnTitleAuthor() {
|
|
339 return notesOnTitleAuthor;
|
|
340 }
|
|
341
|
|
342 public String getNotesOnCollationAndCorrections() {
|
|
343 return notesOnCollationAndCorrections;
|
|
344 }
|
|
345
|
|
346 public String getNotesOnOwnership() {
|
|
347 return notesOnOwnership;
|
|
348 }
|
|
349
|
|
350 public String getNotes() {
|
|
351 return notes;
|
|
352 }
|
|
353
|
|
354 public String getCodex() {
|
|
355 return codex;
|
|
356 }
|
|
357
|
|
358 public String getCollection() {
|
|
359 return collection;
|
|
360 }
|
|
361
|
|
362 public String getRepository() {
|
|
363 return repository;
|
|
364 }
|
|
365
|
|
366 public String getCity() {
|
|
367 return city;
|
|
368 }
|
|
369
|
|
370 public String getCountry() {
|
|
371 return country;
|
|
372 }
|
|
373
|
|
374 /*
|
|
375 * public List<String> getReferenceList() { return referenceList; }
|
|
376 */
|
|
377
|
|
378 public Map<String, String> getOwnedByMap() {
|
|
379 return ownedByMap;
|
|
380 }
|
|
381
|
|
382 public Map<String, String> getReadByMap() {
|
|
383 return readByMap;
|
|
384 }
|
|
385
|
|
386 public Collection<String> getOwnedByList() {
|
|
387 return ownedByMap.keySet();
|
|
388 }
|
|
389
|
|
390 public Collection<String> getReadByList() {
|
|
391 return readByMap.keySet();
|
|
392 }
|
|
393
|
|
394 public static Logger getLogger() {
|
|
395 return logger;
|
|
396 }
|
|
397
|
|
398 public String getStartPage() {
|
|
399 return startPage;
|
|
400 }
|
|
401
|
|
402 public String getEndPage() {
|
|
403 return endPage;
|
|
404 }
|
|
405
|
|
406 public Long getId() {
|
|
407 return id;
|
|
408 }
|
|
409
|
|
410 public String getOv() {
|
|
411 return ov;
|
|
412 }
|
|
413
|
|
414 public String getTitle() {
|
|
415 return this.title;
|
|
416 }
|
|
417
|
|
418 public Long getTitleId() {
|
|
419 return this.titleId;
|
|
420 }
|
|
421
|
|
422 public String getFolios() {
|
|
423 return this.folios;
|
|
424 }
|
|
425
|
|
426 public boolean hasTitle(){
|
|
427 return this.titleId != null;
|
|
428 }
|
|
429
|
|
430 // 40b-49b
|
|
431 // 104b-111b
|
|
432 public int compareTo(WitnessTemplate other) {
|
|
433 // return this.empId - o.empId ;
|
|
434
|
|
435 if (other == null)
|
|
436 return -1;
|
|
437 if (StringUtils.isEmpty(this.folios)
|
|
438 && StringUtils.isEmpty(other.folios))
|
|
439 return this.title.compareTo(other.title);
|
|
440 if (StringUtils.isEmpty(this.folios))
|
|
441 return 1;
|
|
442 if (StringUtils.isEmpty(other.folios))
|
|
443 return -1;
|
|
444
|
|
445 try {
|
|
446 return NaturalOrderComparator.compare(this.folios, other.folios);
|
|
447 } catch (Exception e) {
|
|
448 logger.error(e.getMessage(), e);
|
|
449 }
|
|
450
|
|
451 return 0;
|
|
452 }
|
|
453
|
|
454 }
|