Mercurial > hg > ismi-richfaces
annotate src/main/java/de/mpiwg/itgroup/ismi/entry/beans/CurrentCodexBean.java @ 121:6f0e9a333c15
misidentification of witness mostly works now.
author | casties |
---|---|
date | Mon, 09 Jan 2017 20:37:29 +0100 |
parents | 22a18bfc66b0 |
children | 28a0c2726466 |
rev | line source |
---|---|
1 | 1 package de.mpiwg.itgroup.ismi.entry.beans; |
2 | |
3 import java.io.Serializable; | |
4 | |
5 import java.util.ArrayList; | |
6 import java.util.List; | |
7 | |
8 import javax.faces.event.ActionEvent; | |
9 import javax.faces.model.SelectItem; | |
10 | |
11 import org.apache.commons.lang.StringUtils; | |
12 import org.apache.log4j.Logger; | |
13 import org.mpi.openmind.repository.bo.Attribute; | |
14 import org.mpi.openmind.repository.bo.Entity; | |
15 import org.mpi.openmind.repository.bo.Node; | |
16 import org.mpi.openmind.repository.bo.Relation; | |
17 | |
18 import de.mpiwg.itgroup.ismi.util.guiComponents.Calendar; | |
19 import de.mpiwg.itgroup.ismi.util.guiComponents.EntityList; | |
20 | |
21 /** | |
22 * @author jurzua | |
23 * | |
24 */ | |
25 public class CurrentCodexBean extends CodexEditorTemplate implements Serializable{ | |
26 private static final long serialVersionUID = -4242977362183330958L; | |
27 | |
28 private static Logger logger = Logger.getLogger(CurrentCodexBean.class); | |
29 | |
30 //private Entity codex; | |
31 | |
32 private List<Entity> witnessInCurrentCodex; | |
33 private boolean showWitnessInCurrentCodex; | |
34 | |
35 private EntityList ownedByPeople; | |
36 private EntityList readByPeople; | |
37 | |
38 private List<SelectItem> suggestedBindingList = new ArrayList<SelectItem>(); | |
39 | |
40 private CodexEditorTemplate referencedCodexTemplate; | |
41 private Boolean isAlias; | |
42 | |
43 | |
44 public CurrentCodexBean() { | |
45 this.entity = new Entity(Node.TYPE_ABOX, CODEX, false); | |
46 setDefObjectClass(CODEX); | |
47 registerChecker(getCityLo(), "city is not valid"); | |
48 registerChecker(getCountryLo(), "country is not valid"); | |
49 registerChecker(getRepositoryLo(), "repository is not valid"); | |
50 registerChecker(getCollectionLo(), "collection is not valid"); | |
51 | |
52 this.refreshBindingList(); | |
53 } | |
54 | |
55 @Override | |
56 public void reset(){ | |
57 super.reset(); | |
58 this.entity = new Entity(Node.TYPE_ABOX, CODEX, false); | |
59 | |
60 this.ownedByPeople = new EntityList(PERSON, "name_translit", true); | |
61 this.readByPeople = new EntityList(PERSON, "name_translit", true); | |
62 | |
63 this.witnessInCurrentCodex = new ArrayList<Entity>(); | |
64 this.showWitnessInCurrentCodex = false; | |
65 this.isAlias = false; | |
66 this.referencedCodexTemplate = new CodexEditorTemplate(); | |
67 this.refreshBindingList(); | |
68 } | |
69 | |
70 public void listenerRefreshBindingList(ActionEvent event){ | |
71 this.refreshBindingList(); | |
72 } | |
73 | |
74 public void listenerEditCalendarOwnedBy(ActionEvent event){ | |
75 Entity entity = (Entity)getRequestBean("item"); | |
76 if(entity != null){ | |
77 Calendar cal = this.ownedByPeople.getCalendar(entity.getId()); | |
78 getSessionBean().editCalendar(cal, ownedByPeople, entity.getId()); | |
79 } | |
80 } | |
81 | |
82 public void listenerEditCalendarReadBy(ActionEvent event){ | |
83 Entity entity = (Entity)getRequestBean("item"); | |
84 if(entity != null){ | |
85 Calendar cal = this.readByPeople.getCalendar(entity.getId()); | |
86 getSessionBean().editCalendar(cal, readByPeople, entity.getId()); | |
87 } | |
88 } | |
89 | |
90 private void refreshBindingList(){ | |
91 this.suggestedBindingList = new ArrayList<SelectItem>(); | |
92 suggestedBindingList.add(new SelectItem("", "--choose--")); | |
93 Attribute binding = getWrapper().getDefAttributeByOwnValue(this.entity.getObjectClass(), "binding"); | |
94 if(binding != null){ | |
95 for(String s : binding.getPossibleValuesList()){ | |
96 this.suggestedBindingList.add(new SelectItem(s)); | |
97 } | |
98 } | |
99 } | |
100 | |
101 public String createCollectionAction() { | |
102 getSessionBean().setSelectedTab(SessionBean.COLLECTION_TAB); | |
103 return "edit"; | |
104 } | |
105 | |
106 @Override | |
107 public void setEntity(Entity codex) { | |
108 this.reset(); | |
109 this.entity = codex; | |
110 logger.info("Set Codex " + this.entity); | |
111 try { | |
112 if(this.entity != null && this.entity.isPersistent()){ | |
113 if(this.entity.isLightweight()){ | |
114 this.entity = getWrapper().getEntityContent(this.entity); | |
115 } | |
116 | |
117 this.loadAttributes(this.entity); | |
118 | |
119 Attribute isAliasAtt = getWrapper().getAttributeByName(this.entity.getId(), "is_alias"); | |
120 if(isAlias != null){ | |
121 try{ | |
122 this.isAlias = new Boolean(isAliasAtt.getOwnValue()); | |
123 }catch(Exception ex){ | |
124 this.isAlias = false; | |
125 } | |
126 }else{ | |
127 this.isAlias = false; | |
128 } | |
129 | |
130 for(Relation rel : getWrapper().getSourceRelations(codex, owned_by, PERSON, -1)) { | |
131 this.ownedByPeople.add(getWrapper().getEntityById(rel.getTargetId()), rel.getAttributeByName("date")); | |
132 } | |
133 | |
134 for(Relation rel : getWrapper().getSourceRelations(codex, "read_by", PERSON, -1)) { | |
135 this.readByPeople.add(getWrapper().getEntityById(rel.getTargetId()), rel.getAttributeByName("date")); | |
136 } | |
137 | |
138 for (Entity target : getWrapper() | |
139 .getTargetsForSourceRelation(codex, is_part_of, COLLECTION, 1)) { | |
140 String ct = target.getObjectClass(); | |
141 | |
142 if (ct.equals(COLLECTION)) { | |
143 this.setCollection(target); | |
144 } | |
145 } | |
146 | |
147 List<Entity> list = getWrapper().getTargetsForSourceRelation(codex, "is_alias_of", CODEX, 1); | |
148 if(!list.isEmpty()){ | |
149 this.setReferencedCodex(list.get(0)); | |
150 //this.referencedCodexTemplate.setCodexLo(codexLo); | |
151 //this.referencedCodexLO.setEntityAndAttribute(list.get(0), "identifier"); | |
152 } | |
153 | |
154 | |
155 //this.loadReferences(this.entity); | |
156 this.loadEndNoteRefs(); | |
157 | |
158 this.setCurrentId(this.entity.getId().toString()); | |
159 this.checkConsistencyFromCountryToCodex(); | |
160 } | |
161 } catch (Exception e) { | |
162 logger.info(e.getMessage(), e); | |
163 printInternalError(e); | |
164 } | |
165 } | |
166 | |
167 public void setReferencedCodex(Entity codex){ | |
111
22a18bfc66b0
new completion that uses ALIASes: AbstractListenerObject. was_copied_in in WITNESS form can use PLACE aliases now. some cleanup.
casties
parents:
91
diff
changeset
|
168 this.referencedCodexTemplate.getCodexLo().setEntityAndAttributeName(codex, "identifier"); |
1 | 169 |
170 if(this.referencedCodexTemplate.getCodexLo().entity != null && | |
171 this.referencedCodexTemplate.getCodexLo().entity.isPersistent()){ | |
172 | |
173 List<Entity> list = getWrapper().getTargetsForSourceRelation(codex, is_part_of, COLLECTION, 1); | |
174 if(list.size() > 0){ | |
175 this.referencedCodexTemplate.setCollection(list.get(0)); | |
176 } | |
177 } | |
178 } | |
179 | |
180 @Override | |
181 public String save() { | |
182 super.save(); | |
183 try { | |
184 CheckResults cr = getCheckResults(); | |
185 if (cr.hasErrors) { | |
186 getSessionBean().setErrorMessages(cr); | |
187 getSessionBean().setDisplayError(true); | |
188 this.setSelectedSaveAsNew(false); | |
189 return PAGE_EDITOR; | |
190 } | |
191 | |
192 if (this.entity == null) { | |
193 this.entity = new Entity(); | |
194 this.entity.setObjectClass("CODEX"); | |
195 } | |
196 | |
197 this.entity = this.updateEntityAttributes(this.entity); | |
198 | |
199 if(this.entity.getAttributeByName("is_alias") != null){ | |
200 this.entity.getAttributeByName("is_alias").setOwnValue(this.isAlias.toString()); | |
201 }else{ | |
202 this.entity.addAttribute(new Attribute("is_alias", "boolean", this.isAlias.toString())); | |
203 } | |
204 | |
205 if(this.isAlias){ | |
206 if(referencedCodexTemplate.getCodexLo().entity != null){ | |
207 // CODEX -> is_part_of -> CODEX | |
208 this.entity.replaceSourceRelation(referencedCodexTemplate.getCodexLo().entity, CODEX, "is_alias_of"); | |
209 }else{ | |
210 this.entity.removeAllSourceRelations("is_alias_of", CODEX); | |
211 } | |
212 } | |
213 | |
214 //checking is the identifier is unique for the selected collecion | |
215 String identifier = (this.entity.getAttributeByName("identifier") != null) ? this.entity.getAttributeByName("identifier").getValue() : ""; | |
216 if(StringUtils.isNotEmpty(identifier)){ | |
217 if(!checkUnityCodex(identifier, (isSelectedSaveAsNew()) ? null : this.entity.getId(), this.getCollectionLo().entity)){ | |
218 this.renderUnityCheckerDialog(); | |
219 this.setSelectedSaveAsNew(false); | |
220 return PAGE_EDITOR; | |
221 } | |
222 }else{ | |
223 this.addErrorMsg("This entity has not been saved, because its identifier was empty."); | |
224 this.addErrorMsg("You must enter an identifier."); | |
225 return PAGE_EDITOR; | |
226 } | |
227 | |
228 if(!isCodexConsistentBeforeSave()){ | |
229 return PAGE_EDITOR; | |
230 } | |
231 | |
232 this.entity.replaceSourceRelation(this.getCollectionLo().entity, COLLECTION, is_part_of); | |
233 | |
234 // CODEX -> owner_by (manyToMany) -> PERSON | |
235 this.entity.removeAllSourceRelationsByName(owned_by); | |
236 | |
237 // CODEX -> read_by (manyToMany) -> PERSON | |
238 this.entity.removeAllSourceRelationsByName("read_by"); | |
239 | |
240 //REFERENCE -> is_reference_of -> THIS | |
241 //this.entity = this.prepareReferencesToSave(this.entity); | |
242 this.prepareEndNoteRefs2Save(); | |
243 | |
244 if (this.isSelectedSaveAsNew()) { | |
245 this.entity = getWrapper().saveEntityAsNew(this.entity,getSessionUser().getEmail()); | |
246 this.setSelectedSaveAsNew(false); | |
247 } else { | |
248 for(Entity owner : this.ownedByPeople.getEntities()){ | |
249 if(owner.isLightweight()){ | |
250 owner = getWrapper().getEntityByIdWithContent(owner.getId()); | |
251 } | |
252 Relation ownerBy = new Relation(this.entity, owner, owned_by); | |
253 Calendar cal = ownedByPeople.getCalendar(owner.getId()); | |
254 if(cal != null){ | |
255 ownerBy.addAttribute(new Attribute("date", "date", cal.toJSONString())); | |
256 } | |
257 } | |
258 for(Entity reader : this.readByPeople.getEntities()){ | |
259 Relation readBy = new Relation(this.entity, reader, "read_by"); | |
260 Calendar cal = readByPeople.getCalendar(reader.getId()); | |
261 if(cal != null){ | |
262 readBy.addAttribute(new Attribute("date", "date", cal.toJSONString())); | |
263 } | |
264 } | |
265 | |
266 this.entity = getWrapper().saveEntity(this.entity, getSessionUser().getEmail()); | |
267 } | |
268 | |
91 | 269 this.updateRelatedOW(this.entity, getSessionUser().getEmail()); |
1 | 270 getSessionBean().setEditFormCurrentEntId(this.entity.getId()); |
271 | |
272 logger.info("Entity saved - Time = " + (System.currentTimeMillis() - start) + ", " + entity); | |
273 this.printSuccessSavingEntity(); | |
274 | |
275 this.setSelectedSaveAsNew(false); | |
276 | |
277 } catch (Exception e) { | |
278 logger.error(e.getMessage(), e); | |
279 e.printStackTrace(); | |
280 this.printInternalError(e); | |
281 } | |
282 | |
283 saveEnd(); | |
284 return PAGE_EDITOR; | |
285 } | |
286 | |
287 public String saveAsNewEntity() { | |
288 this.setSelectedSaveAsNew(true); | |
289 return save(); | |
290 } | |
291 | |
292 public void setLWCodex(Entity codex) { | |
293 this.entity = codex; | |
294 } | |
295 | |
296 public void actionShowWitnessDialog(ActionEvent event){ | |
297 if(this.witnessInCurrentCodex.size() == 0 && this.entity.isPersistent()){ | |
298 this.witnessInCurrentCodex = | |
299 getWrapper().getSourcesForTargetRelation(this.entity, "is_part_of", "WITNESS", 50); | |
300 } | |
301 this.setShowWitnessInCurrentCodex(true); | |
302 } | |
303 | |
304 public void actionCloseWitnessDialog(ActionEvent event){ | |
305 this.setShowWitnessInCurrentCodex(false); | |
306 } | |
307 | |
308 public void actionEditThisWitness(ActionEvent event){ | |
309 this.setShowWitnessInCurrentCodex(false); | |
310 Entity currentWitness = (Entity)getRequestBean("witness"); | |
311 if(currentWitness != null && currentWitness.isPersistent()){ | |
312 getSessionBean().editEntity(currentWitness); | |
313 } | |
314 } | |
315 | |
316 public List<Entity> getWitnessInCurrentCodex() { | |
317 return witnessInCurrentCodex; | |
318 } | |
319 | |
320 public void setWitnessInCurrentCodex(List<Entity> witnessInCurrentCodex) { | |
321 this.witnessInCurrentCodex = witnessInCurrentCodex; | |
322 } | |
323 | |
324 public boolean isShowWitnessInCurrentCodex() { | |
325 if(this.entity == null || !this.entity.isPersistent()){ | |
326 return false; | |
327 } | |
328 return showWitnessInCurrentCodex; | |
329 } | |
330 | |
331 public void setShowWitnessInCurrentCodex(boolean showWitnessInCurrentCodex) { | |
332 this.showWitnessInCurrentCodex = showWitnessInCurrentCodex; | |
333 } | |
334 | |
335 public void actionEditThisCollection(ActionEvent event){ | |
336 if(this.getCollectionLo().entity != null && getCollectionLo().entity.isPersistent()){ | |
337 getSessionBean().editEntity(this.getCollectionLo().entity); | |
338 } | |
339 } | |
340 | |
341 public EntityList getOwnedByPeople() { | |
342 return ownedByPeople; | |
343 } | |
344 | |
345 public void setOwnedByPeople(EntityList ownedByPeople) { | |
346 this.ownedByPeople = ownedByPeople; | |
347 } | |
348 | |
349 public List<SelectItem> getSuggestedBindingList() { | |
350 return suggestedBindingList; | |
351 } | |
352 | |
353 public void setSuggestedBindingList(List<SelectItem> suggestedBindingList) { | |
354 this.suggestedBindingList = suggestedBindingList; | |
355 } | |
356 | |
357 public CodexEditorTemplate getReferencedCodexTemplate() { | |
358 return referencedCodexTemplate; | |
359 } | |
360 | |
361 public void setReferencedCodexTemplate( | |
362 CodexEditorTemplate referencedCodexTemplate) { | |
363 this.referencedCodexTemplate = referencedCodexTemplate; | |
364 } | |
365 | |
366 public Boolean getIsAlias() { | |
367 return isAlias; | |
368 } | |
369 | |
370 public void setIsAlias(Boolean isAlias) { | |
371 this.isAlias = isAlias; | |
372 } | |
373 | |
374 public EntityList getReadByPeople() { | |
375 return readByPeople; | |
376 } | |
377 | |
378 public void setReadByPeople(EntityList readByPeople) { | |
379 this.readByPeople = readByPeople; | |
380 } | |
381 | |
382 } |