comparison src/main/java/de/mpiwg/itgroup/ismi/utils/templates/AuthorTemplate.java @ 1:2e911857a759

(none)
author jurzua
date Wed, 29 Oct 2014 14:00:28 +0000
parents
children 4ec8d4cfad26
comparison
equal deleted inserted replaced
0:74df02964906 1:2e911857a759
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.search.AbstractSearchService;
16 import org.mpiwg.itgroup.escidoc.ESciDocHandler;
17 import org.mpiwg.itgroup.escidoc.bo.Publication;
18
19 import de.mpiwg.itgroup.ismi.entry.beans.AbstractISMIBean;
20 import de.mpiwg.itgroup.ismi.util.guiComponents.Calendar;
21
22 public class AuthorTemplate extends AbstractTemplate{
23
24 private static Logger logger = Logger.getLogger(AuthorTemplate.class);
25
26 private static String birth_date = "birth_date";
27
28 private static String lived_in = "lived_in";
29 private static String has_role = "has_role";
30 private static String was_student_of = "was_student_of";
31
32 public String privacity;
33 public String name;
34 public String nameTranslit;
35 public String bornInPlace;
36 public String diedInPlace;
37 public String primeAlias;
38 public String notes;
39 public String url;
40 public List<String> aliasList;
41 public List<String> roleList;
42
43 public String birthDate;
44 public String deathDate;
45
46 public Map<String, String> livedInPlaceMap;
47
48 public AuthorTemplate(Entity entity, WrapperService om){
49
50 logger.info("Diplaying " + entity);
51
52 if (entity.isLightweight()) {
53 entity = om.getEntityContent(entity);
54 }
55 this.aliasList = new ArrayList<String>();
56 this.roleList = new ArrayList<String>();
57 this.livedInPlaceMap = new HashMap<String, String>();
58 this.privacity = entity.getPrivacity();
59
60 Attribute attName = entity.getAttributeByName("name");
61 Attribute attNameTranslit = entity.getAttributeByName("name_translit");
62 Attribute attNotes = entity.getAttributeByName("notes");
63 Attribute attUrl = entity.getAttributeByName("url");
64 this.name = (attName == null) ? null : attName.getValue();
65 this.nameTranslit = (attNameTranslit == null) ? null : attNameTranslit.getValue();
66 this.notes = (attNotes == null) ? null : attNotes.getValue();
67 this.url = (attUrl == null) ? null : attUrl.getValue();
68
69 Calendar calDeathDate = AbstractISMIBean.updateCalendar(entity.getAttributeByName("death_date"));
70 this.deathDate = calDeathDate.getCalendarAsHtml();
71
72 Calendar calBirthDate = AbstractISMIBean.updateCalendar(entity.getAttributeByName(birth_date));
73 this.birthDate = calBirthDate.getCalendarAsHtml();
74
75 //this.setCurrentId(entity.getId().toString());
76 //this.loadAttributes(entity);
77
78 for (Relation rel : entity.getSourceRelations()) {
79 if(StringUtils.isEmpty(rel.getOwnValue()) || StringUtils.isEmpty(rel.getTargetObjectClass())){
80 try {
81 throw new Exception("Relation has no ownValue and/or targetObjCls " + rel);
82 } catch (Exception e) {
83 logger.error(e.getMessage(), e);
84 }
85 }else{
86 Entity target = om.getEntityById(rel.getTargetId());
87 if (rel.getOwnValue().equals("was_born_in")) {
88 this.bornInPlace = (target == null) ? "" : target.getOwnValue();
89 } else if (rel.getOwnValue().equals(lived_in)) {
90 String date = (rel.getAttributeByName("date") != null) ?
91 new Calendar(rel.getAttributeByName("date").getOwnValue()).getCalendarAsHtml() :
92 "";
93 this.livedInPlaceMap.put(target.getOwnValue(), date);
94 } else if (rel.getOwnValue().equals(was_student_of)) {
95 //this.studentOfList.add(target);
96 } else if (rel.getOwnValue().equals(has_role)) {
97 this.roleList.add(target.getOwnValue());
98 } else if (rel.getOwnValue().equals("died_in")) {
99 this.diedInPlace = (target == null) ? "" : target.getOwnValue();
100 }
101 }
102 }
103
104 for (Relation rel : entity.getTargetRelations()) {
105
106 if(StringUtils.isEmpty(rel.getOwnValue()) || StringUtils.isEmpty(rel.getSourceObjectClass())){
107 try {
108 throw new Exception("Relation has no ownValue and/or sourceObjCls " + rel);
109 } catch (Exception e) {
110 logger.error(e.getMessage(), e);
111 }
112 }else{
113 if (rel.getOwnValue().equals("was_created_by") && rel.getSourceObjectClass().equals("TEXT")) {
114 Entity title = om.getEntityById(rel.getSourceId());
115 if(title != null && title.getObjectClass().equals("TEXT")){
116 //this.titles.add(title);
117 //I remove this line cause the list in this way would not be sorted.
118 //this.titleItems.add(new SelectItem(title.getId().toString(), title.getOwnValue() + " [" + title.getId() + "]"));
119 }
120 } else if (rel.getOwnValue().equals("is_alias_name_of")) {
121 Entity alias = om.getEntityById(rel.getSourceId());
122 this.aliasList.add(alias.getOwnValue());
123 } else if (rel.getOwnValue().equals("is_prime_alias_name_of")) {
124 Entity alias = om.getEntityByIdWithContent(rel.getSourceId());
125 this.primeAlias = alias.getAttributeByName("alias").getValue();
126 } else if (rel.getOwnValue().equals("is_reference_of")) {
127 Entity ref = om.getEntityByIdWithContent(rel.getSourceId());
128 this.refEntityList.add(ref);
129 }
130 }
131
132 }
133 this.loadRefernces();
134 }
135
136 public String getPrivacity() {
137 return privacity;
138 }
139 public String getName() {
140 return name;
141 }
142 public String getNameTranslit() {
143 return nameTranslit;
144 }
145 public String getBornInPlace() {
146 return bornInPlace;
147 }
148 public String getDiedInPlace() {
149 return diedInPlace;
150 }
151 public String getPrimeAlias() {
152 return primeAlias;
153 }
154 public String getNotes() {
155 return notes;
156 }
157 public String getUrl() {
158 return url;
159 }
160 public List<String> getAliasList() {
161 return aliasList;
162 }
163
164 public String getBirthDate() {
165 return birthDate;
166 }
167 public String getDeathDate() {
168 return deathDate;
169 }
170 public List<String> getRoleList() {
171 return roleList;
172 }
173
174 public Map<String, String> getLivedInPlaceMap() {
175 return livedInPlaceMap;
176 }
177
178 public Collection<String> getLivedInPlaceList(){
179 return livedInPlaceMap.keySet();
180 }
181 }