1
|
1 package de.mpiwg.itgroup.ismi.entry.beans;
|
|
2
|
|
3 import java.util.ArrayList;
|
|
4 import java.util.Collection;
|
|
5 import java.util.Collections;
|
|
6 import java.util.HashMap;
|
|
7 import java.util.List;
|
|
8 import java.util.Map;
|
|
9
|
|
10 import org.mpi.openmind.cache.WrapperService;
|
|
11 import org.mpi.openmind.repository.bo.Attribute;
|
|
12 import org.mpi.openmind.repository.bo.Entity;
|
|
13 import org.mpi.openmind.repository.bo.utils.EntitySortByNormalizedOwnValue;
|
|
14
|
|
15 public class BiographyBean extends AbstractBean{
|
|
16
|
|
17 private boolean dirty = true;
|
|
18
|
|
19 private Map<String, List<Biography>> biographyMap;
|
|
20 private List<String> indexList = null;
|
|
21
|
|
22 public BiographyBean(){
|
|
23 }
|
|
24
|
|
25 private void load(){
|
|
26 this.dirty = false;
|
|
27 this.biographyMap = new HashMap<String, List<Biography>>();
|
|
28
|
|
29
|
|
30
|
|
31 List<Entity> rs = getAppBean().getWrapper().getEntitiesByAtt("PERSON", "url", "http://islamsci.mcgill.ca/RASI/BEA", -1, true);
|
|
32
|
|
33 for(Entity ent : rs){
|
|
34 String normalizedOv = ent.getNormalizedOwnValue();
|
|
35 String index = new String(normalizedOv.charAt(0) + "");
|
|
36 index = index.toUpperCase();
|
|
37
|
|
38 if(!this.biographyMap.containsKey(index)){
|
|
39 this.biographyMap.put(index, new ArrayList<BiographyBean.Biography>());
|
|
40 }
|
|
41 this.biographyMap.get(index).add(new Biography(ent, getAppBean().getWrapper()));
|
|
42 }
|
|
43
|
|
44 for(String index : this.biographyMap.keySet()){
|
|
45 Collections.sort(this.biographyMap.get(index));
|
|
46 }
|
|
47
|
|
48 this.indexList = new ArrayList<String>(this.biographyMap.keySet());
|
|
49 Collections.sort(indexList);
|
|
50 }
|
|
51
|
|
52 public List<String> getIndexList(){
|
|
53 if(dirty)
|
|
54 this.load();
|
|
55 return this.indexList;
|
|
56 }
|
|
57
|
|
58 public Map<String, List<Biography>> getBiographyMap(){
|
|
59 if(dirty)
|
|
60 this.load();
|
|
61 return this.biographyMap;
|
|
62 }
|
|
63
|
|
64 public void makeDirty(){
|
|
65 this.dirty = true;
|
|
66 }
|
|
67
|
|
68 public class Biography implements Comparable<Biography>{
|
|
69 private Long personId;
|
|
70 private String biographyUrl;
|
|
71 private String label;
|
|
72 private String normalizedLabel;
|
|
73
|
|
74 public Biography(Entity person, WrapperService wrapper){
|
|
75 Attribute att = wrapper.getAttributeByName(person.getId(), "url");
|
|
76
|
|
77 this.label = person.getOwnValue();
|
|
78 this.personId = person.getId();
|
|
79 this.biographyUrl = att.getOwnValue();
|
|
80 this.normalizedLabel = person.getNormalizedOwnValue();
|
|
81 }
|
|
82
|
|
83 public Long getPersonId() {
|
|
84 return personId;
|
|
85 }
|
|
86 public String getBiographyUrl() {
|
|
87 return biographyUrl;
|
|
88 }
|
|
89 public String getLabel() {
|
|
90 return label;
|
|
91 }
|
|
92
|
|
93 public int compareTo(Biography o) {
|
|
94 return this.normalizedLabel.compareTo(o.normalizedLabel);
|
|
95
|
|
96 }
|
|
97
|
|
98 @Override
|
|
99 public String toString(){
|
|
100 return "[" + this.personId + "] " + this.label + " - " + this.biographyUrl;
|
|
101 }
|
|
102 }
|
|
103
|
|
104 }
|