Mercurial > hg > ismi-richfaces
annotate src/main/java/de/mpiwg/itgroup/ismi/entry/beans/CodexEditorTemplate.java @ 125:eee2e0ca4032
updated entry beans to use EditIntents.
author | casties |
---|---|
date | Tue, 31 Jan 2017 18:09:54 +0100 |
parents | 22a18bfc66b0 |
children |
rev | line source |
---|---|
1 | 1 package de.mpiwg.itgroup.ismi.entry.beans; |
2 | |
3 import java.util.ArrayList; | |
4 import java.util.Collections; | |
5 import java.util.List; | |
6 | |
7 import javax.faces.event.ActionEvent; | |
8 import javax.faces.event.ValueChangeEvent; | |
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.Relation; | |
16 | |
17 import de.mpiwg.itgroup.ismi.auxObjects.ListenerObject; | |
18 import de.mpiwg.itgroup.ismi.auxObjects.lo.WitnessCityLO; | |
19 import de.mpiwg.itgroup.ismi.auxObjects.lo.WitnessCollectionLO; | |
20 import de.mpiwg.itgroup.ismi.auxObjects.lo.WitnessCountryLO; | |
21 import de.mpiwg.itgroup.ismi.auxObjects.lo.WitnessRepositoryLO; | |
22 import de.mpiwg.itgroup.ismi.util.guiComponents.StatusImage; | |
23 import de.mpiwg.itgroup.ismi.utils.SelectItemSort; | |
24 | |
25 | |
26 /** | |
27 * CODEX -> is_part_of -> COLLECTION | |
28 * COLLECTION -> is_part_of -> REPOSITORY | |
29 * REPOSITORY -> is_in -> PLACE[city] | |
30 * PLACE[city] -> is_part_of -> PLACE[country] | |
31 * @author jurzua | |
32 * | |
33 */ | |
34 public class CodexEditorTemplate extends UnityChecker { | |
35 | |
36 private static final long serialVersionUID = 7580021280544772497L; | |
37 private static Logger logger = Logger.getLogger(CodexEditorTemplate.class); | |
38 public static int MAX_CODICES = 1000; | |
39 public static int MAX_REPOSITORIES = 100; | |
40 public static int MAX_COLLECTIONS = 100; | |
41 public static int MAX_PLACES = 100; | |
42 | |
43 private ListenerObject countryLo; | |
44 private ListenerObject cityLo; | |
45 private ListenerObject repositoryLo; | |
46 private ListenerObject collectionLo; | |
47 private ListenerObject codexLo; | |
48 | |
49 private List<SelectItem> citiesInCurrentCountry; | |
50 private List<SelectItem> repositoriesInCurrentCity; | |
51 private List<SelectItem> collectionsInCurrentRepository; | |
52 private List<SelectItem> shelfMarksInCurrentCollection; | |
53 | |
54 private boolean thereExistMoreCodices = false; | |
55 | |
56 public CodexEditorTemplate(){ | |
57 logger.debug("Init: " + this.getClass().getName()); | |
58 this.reset(); | |
59 } | |
60 | |
61 @Override | |
62 public void reset(){ | |
63 super.reset(); | |
64 this.countryLo = new WitnessCountryLO(PLACE, "name", this); | |
65 this.cityLo = new WitnessCityLO(PLACE, "name", this); | |
66 this.repositoryLo = new WitnessRepositoryLO(REPOSITORY, "name", this); | |
67 this.collectionLo = new WitnessCollectionLO(COLLECTION, "name", this); | |
68 this.codexLo = new ListenerObject(CODEX, "identifier"); | |
69 | |
70 this.citiesInCurrentCountry = new ArrayList<SelectItem>(); | |
71 this.repositoriesInCurrentCity = new ArrayList<SelectItem>(); | |
72 this.collectionsInCurrentRepository = new ArrayList<SelectItem>(); | |
73 this.shelfMarksInCurrentCollection = new ArrayList<SelectItem>(); | |
74 | |
75 this.thereExistMoreCodices = false; | |
76 } | |
77 | |
105 | 78 /** |
79 * Set this.countryLo and restrict by country type(?). | |
80 * @param country | |
81 */ | |
1 | 82 public void setCountry(Entity country){ |
111
22a18bfc66b0
new completion that uses ALIASes: AbstractListenerObject. was_copied_in in WITNESS form can use PLACE aliases now. some cleanup.
casties
parents:
106
diff
changeset
|
83 this.getCountryLo().setEntityAndAttribute(country); |
1 | 84 this.restrictByCountry(country); |
85 } | |
86 | |
87 public void setCity(Entity city) { | |
111
22a18bfc66b0
new completion that uses ALIASes: AbstractListenerObject. was_copied_in in WITNESS form can use PLACE aliases now. some cleanup.
casties
parents:
106
diff
changeset
|
88 this.getCityLo().setEntityAndAttribute(city); |
1 | 89 this.restrictByCity(city); |
90 | |
91 List<Entity> list = getWrapper().getTargetsForSourceRelation(city, is_part_of, PLACE, 1); | |
92 | |
93 if(list.size() > 0){ | |
94 this.setCountry(list.get(0)); | |
95 } | |
96 } | |
97 | |
98 public void setRepository(Entity repository) { | |
111
22a18bfc66b0
new completion that uses ALIASes: AbstractListenerObject. was_copied_in in WITNESS form can use PLACE aliases now. some cleanup.
casties
parents:
106
diff
changeset
|
99 this.getRepositoryLo().setEntityAndAttribute(repository); |
1 | 100 this.restrictByRepository(repository); |
101 | |
102 List<Entity> list = getWrapper().getTargetsForSourceRelation(repository, is_in, PLACE, 5); | |
103 | |
104 if(list.size() > 0){ | |
105 this.setCity(list.get(0)); | |
106 } | |
107 } | |
108 | |
109 public void setCollection(Entity collection) { | |
111
22a18bfc66b0
new completion that uses ALIASes: AbstractListenerObject. was_copied_in in WITNESS form can use PLACE aliases now. some cleanup.
casties
parents:
106
diff
changeset
|
110 this.getCollectionLo().setEntityAndAttribute(collection); |
1 | 111 this.restrictByCollection(collection); |
112 | |
113 List<Entity> repoList = getWrapper().getTargetsForSourceRelation(collection, is_part_of, REPOSITORY, 1); | |
114 | |
115 if(repoList.size() > 0){ | |
116 this.setRepository(repoList.get(0)); | |
117 } | |
118 } | |
119 | |
120 /** | |
121 * Listen to a change of the country where the codex is located. Restrict | |
122 * possible collections/repositories/codices to object in this city. | |
123 * | |
124 * @param event | |
125 */ | |
126 /* rich | |
127 public void countryChangeListener(ValueChangeEvent event) { | |
128 | |
129 this.setCitiesInCurrentCountry(new ArrayList<SelectItem>()); | |
130 | |
131 this.setCountryLo(changeListener(event, getCountryLo(), PLACE, "name","type","region")); | |
132 if (getCountryLo().entity!=null && getCountryLo().entity.isPersistent()){ | |
133 this.setCountry(getCountryLo().entity); | |
134 } | |
135 this.checkConsistencyFromCountryToCodex(); | |
136 }*/ | |
137 | |
138 /** | |
139 * Listen to a change of the city where the codex is located. Restrict | |
140 * possible collections/repositories/codices to object in this city. | |
141 * | |
142 * @param event | |
143 */ | |
144 /* rich | |
145 public void cityChangeListener(ValueChangeEvent event) { | |
146 | |
147 this.setRepositoriesInCurrentCity(new ArrayList<SelectItem>()); | |
148 | |
149 this.setCityLo(changeListener(event, getCityLo(), PLACE, "name", "type", "city")); | |
150 | |
151 if (this.getCityLo().entity!=null && this.getCityLo().entity.isPersistent()){ | |
152 this.setCity(this.getCityLo().entity); | |
153 } | |
154 this.checkConsistencyFromCountryToCodex(); | |
155 | |
156 } | |
157 */ | |
158 /* | |
159 public void repositoryChangeListener(ValueChangeEvent event) { | |
160 | |
161 this.setCollectionsInCurrentRepository(new ArrayList<SelectItem>()); | |
162 this.setShelfMarksInCurrentCollection(new ArrayList<SelectItem>()); | |
163 | |
164 this.setRepositoryLo(changeListener(event, this.getRepositoryLo(), REPOSITORY, "name")); | |
165 | |
166 if (this.getRepositoryLo().entity!= null && this.getRepositoryLo().entity.isPersistent()){ | |
167 this.setRepository(this.getRepositoryLo().entity); | |
168 } | |
169 this.checkConsistencyFromCountryToCodex(); | |
170 | |
171 }*/ | |
172 | |
173 | |
174 /** | |
175 * <p>When the collection is changed by the user this method will be called.</p> | |
176 * <p>This modification means that the COLLECTION of the relation CODEX-> | |
177 * is_part_of-> COLLECTION is replaced.</p> | |
178 * @param newEvent | |
179 */ | |
180 /* rich | |
181 public void collectionChangeListener(ValueChangeEvent event) { | |
182 | |
183 this.setShelfMarksInCurrentCollection(new ArrayList<SelectItem>()); | |
184 | |
185 this.setCollectionLo(this.changeListener(event, this.getCollectionLo(), COLLECTION, "name")); | |
186 | |
187 Entity currentCollection = this.getCollectionLo().entity; | |
188 if(currentCollection != null && currentCollection.isPersistent()){ | |
189 this.setCollection(currentCollection); | |
190 } | |
191 | |
192 this.checkConsistencyFromCountryToCodex(); | |
193 | |
194 }*/ | |
195 | |
196 public void inCurrentCountryListener(ValueChangeEvent event) { | |
197 inCurrentListener(getCitiesInCurrentCountry(), event); | |
198 } | |
199 | |
200 public void inCurrentCityListener(ValueChangeEvent event) { | |
201 inCurrentListener(getRepositoriesInCurrentCity(), event); | |
202 } | |
203 | |
204 public void inCurrentRepositoryListener(ValueChangeEvent event) { | |
205 inCurrentListener(getCollectionsInCurrentRepository(), event); | |
206 } | |
207 | |
208 public void inCurrentListener(List<SelectItem> items, ValueChangeEvent event) { | |
209 if (event.getNewValue() == null) { | |
210 return; | |
211 } | |
212 if (event.getNewValue().equals(event.getOldValue())) { | |
213 return; | |
214 } | |
215 String newValue = (String) event.getNewValue(); | |
216 for (SelectItem item : items) { | |
217 if (item.getValue().equals(newValue)) { | |
218 //System.out.println(item.getValue()); | |
219 Entity ent = | |
220 getWrapper().getEntityById(Long.valueOf((String) item.getValue())); | |
221 | |
222 if(ent != null){ | |
223 String ct = ent.getObjectClass(); | |
224 if (ct.equals(CODEX)) { | |
111
22a18bfc66b0
new completion that uses ALIASes: AbstractListenerObject. was_copied_in in WITNESS form can use PLACE aliases now. some cleanup.
casties
parents:
106
diff
changeset
|
225 this.getCodexLo().setEntityAndAttribute(ent); |
1 | 226 Attribute identifier = getWrapper().getAttributeByName(ent.getId(), "identifier"); |
227 | |
228 if(identifier != null){ | |
229 this.getCodexLo().statusImage.setStatus(StatusImage.STATUS_OK); | |
230 } | |
231 //changeValueAttCodex(this.getCodexLo().getAttribute().getOwnValue()); | |
232 break; | |
233 | |
234 } else if (ct.equals(REPOSITORY)) { | |
235 this.setRepository(ent); | |
236 break; | |
237 } else if (ct.equals(PLACE)) { | |
238 this.setCity(ent); | |
239 break; | |
240 | |
241 } else if (ct.equals(COLLECTION)) { | |
242 setCollection(ent); | |
243 break; | |
244 } else { | |
245 break; | |
246 } | |
247 } | |
248 }else{ | |
249 logger.error("Entity no found " + item.getValue() + ", however it should exist."); | |
250 } | |
251 } | |
252 this.checkConsistencyFromCountryToCodex(); | |
253 } | |
254 | |
255 public void checkConsistencyFromCountryToCodex(ActionEvent event){ | |
256 this.checkConsistencyFromCountryToCodex(); | |
257 } | |
258 | |
259 public CodexForList getCodexData(Entity entity) { | |
260 Entity currentRepository = null; | |
261 | |
262 CodexForList entForList = new CodexForList(); | |
263 entForList.id = entity.getId(); | |
264 if (entity.isLightweight()){ | |
265 entity = getWrapper().getEntityContent(entity); | |
266 } | |
267 Attribute identAttr = entity.getAttributeByName("identifier"); | |
268 if (identAttr != null) | |
269 entForList.ident = identAttr.getValue(); | |
270 List<Relation> rels = null; | |
271 try { | |
272 if (entity.isLightweight()){ | |
273 entity = getWrapper().getEntityContent(entity); | |
274 } | |
275 | |
276 rels = entity.getSourceRelations(); | |
277 } catch (Exception e) { | |
278 e.printStackTrace(); | |
279 rels = null; | |
280 } | |
281 if (rels != null) { | |
282 for (Relation rel : rels) { | |
283 | |
284 Entity coll = getWrapper().getEntityById(rel.getTargetId()); | |
285 coll = getWrapper().getEntityContent(coll); | |
286 | |
287 if (rel.getOwnValue().equals(is_part_of) | |
288 && coll.getObjectClass().equals(COLLECTION)) { | |
289 Attribute name = coll.getAttributeByName("name"); | |
290 if (name != null) | |
291 entForList.collection = name.getValue(); | |
292 try { | |
293 Relation rel2 = coll | |
294 .getSourceRelationByOwnValue(is_part_of); | |
295 if (rel2 != null) { | |
296 currentRepository = getWrapper().getEntityById(rel2.getTargetId()); | |
297 Attribute nameRep = currentRepository | |
298 .getAttributeByName("name"); | |
299 if (nameRep != null) | |
300 entForList.repository = nameRep.getValue(); | |
301 | |
302 } | |
303 } catch (Exception e) { | |
304 e.printStackTrace(); | |
305 } | |
306 | |
307 } else if (rel.getOwnValue().equals(is_part_of) | |
308 && coll.getObjectClass().equals(REPOSITORY)) { | |
309 Attribute name = coll.getAttributeByName("name"); | |
310 if (name != null) | |
311 entForList.repository = name.getValue(); | |
312 currentRepository = coll; | |
313 } else if (rel.getOwnValue().equals(is_in) | |
314 && coll.getObjectClass().equals(PLACE)) { | |
315 Attribute name = coll.getAttributeByName("name"); | |
316 // TODO: ersetze �ber all den String f�r das Attribute | |
317 // zur | |
318 // Anzeige durch eine Konstante bzw. durch | |
319 // getAttRepository.getName, dann kann es leichter | |
320 // geaendert | |
321 // werden, bzw. ducrch eine dynamischen getOwnValue. | |
322 if (name != null) | |
323 entForList.place = name.getValue(); | |
324 } | |
325 | |
326 } | |
327 } | |
328 | |
329 if (currentRepository != null) { | |
330 Relation rel = null; | |
331 try { | |
332 if (currentRepository.isLightweight()) | |
333 entity = getWrapper().getEntityContent(currentRepository); | |
334 | |
335 rel = currentRepository.getSourceRelationByOwnValue(is_in); | |
336 } catch (Exception e) { | |
337 e.printStackTrace(); | |
338 rel = null; | |
339 } | |
340 if (rel != null) { | |
341 Entity coll = getWrapper().getEntityById(rel.getSourceId()); | |
342 if (coll.getObjectClass().equals(PLACE)) { | |
343 Attribute name = coll.getAttributeByName("name"); | |
344 // TODO: ersetze ueber all den String fuer das Attribute | |
345 // zur | |
346 // Anzeige durch eine Konstante bzw. durch | |
347 // getAttRepository.getName, dann kann es leichter | |
348 // geaendert | |
349 // werden, bzw. ducrch eine dynamischen getOwnValue. | |
350 if (name != null) | |
351 entForList.place = name.getValue(); | |
352 } | |
353 | |
354 } | |
355 } | |
356 return entForList; | |
357 } | |
358 | |
359 /** | |
106 | 360 * Set the list of cities for the select menu, by the given country. |
105 | 361 * |
1 | 362 * @param country |
363 */ | |
106 | 364 protected void restrictByCountry(Entity country) { |
365 | |
366 this.setCitiesInCurrentCountry(new ArrayList<SelectItem>()); | |
367 | |
368 for (Entity src : getWrapper().getSourcesForTargetRelation(country, is_part_of, PLACE, MAX_PLACES)) { | |
369 getCitiesInCurrentCountry().add(new SelectItem(String.valueOf(src.getId()), src.getOwnValue())); | |
370 } | |
371 } | |
1 | 372 |
373 /** | |
106 | 374 * Set the list of repositories for the select menu, by the given city. |
1 | 375 * |
376 * @param place | |
377 */ | |
378 protected void restrictByCity(Entity place) { | |
379 | |
380 this.setRepositoriesInCurrentCity(new ArrayList<SelectItem>()); | |
381 | |
106 | 382 for (Entity src : getWrapper().getSourcesForTargetRelation(place, is_in, "REPOSITORY", MAX_REPOSITORIES)) { |
383 this.getRepositoriesInCurrentCity().add(new SelectItem(String.valueOf(src.getId()), src.getOwnValue())); | |
384 } | |
1 | 385 } |
386 | |
387 /** | |
106 | 388 * Set the list of collections for the select menu, by the given repository. |
1 | 389 * |
390 * @param repository | |
391 */ | |
106 | 392 public void restrictByRepository(Entity repository) { |
393 | |
394 this.setCollectionsInCurrentRepository(new ArrayList<SelectItem>()); | |
395 for (Entity src : getWrapper().getSourcesForTargetRelation(repository, is_part_of, COLLECTION, | |
396 MAX_COLLECTIONS)) { | |
397 this.getCollectionsInCurrentRepository() | |
398 .add(new SelectItem(String.valueOf(src.getId()), src.getOwnValue())); | |
399 } | |
1 | 400 } |
401 | |
106 | 402 /** |
403 * Set the list of shelf marks for the select menu, by the given collection. | |
404 * | |
405 * @param collection | |
406 */ | |
1 | 407 protected void restrictByCollection(Entity collection) { |
408 this.setShelfMarksInCurrentCollection(restrictShelfMarks(collection)); | |
409 } | |
410 | |
411 protected List<SelectItem> restrictShelfMarks(Entity collection) { | |
412 List<SelectItem> items = new ArrayList<SelectItem>(); | |
413 int countCodex = 0; | |
414 for (Entity src : getWrapper().getSourcesForTargetRelation(collection, is_part_of, CODEX, MAX_CODICES)) { | |
415 countCodex++; | |
416 items.add(new SelectItem(String.valueOf(src.getId()), src | |
417 .getOwnValue() | |
418 + "(" + src.getObjectClass() + ")")); | |
419 } | |
420 Collections.sort(items, new SelectItemSort()); | |
421 this.thereExistMoreCodices = (countCodex == MAX_CODICES) ? true : false; | |
422 return items; | |
423 } | |
424 | |
425 /* | |
426 * ######################## | |
427 * Country -> Codex | |
428 * ######################## | |
429 */ | |
430 | |
105 | 431 /** |
432 * Returns if country (this.countryLo) has a proper name and continues checking | |
433 * city, repository, collection and codex. | |
434 */ | |
435 public void checkConsistencyFromCountryToCodex() { | |
436 boolean consistent = false; | |
437 | |
438 Entity country = this.getCountryLo().entity; | |
439 if (country != null && country.isPersistent() && getCountryLo().getAttribute() != null | |
440 && StringUtils.isNotEmpty(getCountryLo().getAttribute().getValue())) { | |
441 | |
442 Attribute att = getWrapper().getAttributeByName(country.getId(), "name"); | |
443 | |
444 if (att != null && getCountryLo().getAttribute().getValue().equals(att.getValue())) { | |
445 this.getCountryLo().statusImage.setStatus(StatusImage.STATUS_OK); | |
446 consistent = true; | |
447 } else { | |
448 this.getCountryLo().statusImage.setStatus(StatusImage.STATUS_FALSE); | |
449 } | |
450 } else { | |
451 this.getCountryLo().statusImage.setStatus(StatusImage.STATUS_UNSET); | |
452 } | |
453 | |
454 if (consistent) { | |
455 this.checkConsistencyFromCityToCodex(country); | |
456 } else { | |
457 this.labelStatesAsFalseOrUnset(true, true, true, true, false); | |
458 } | |
459 } | |
1 | 460 |
461 private void checkConsistencyFromCityToCodex(Entity country){ | |
462 boolean consistent = false; | |
463 | |
464 Entity city = this.getCityLo().entity; | |
82
c000b4b386bc
better "internal error" message. fix NPE when codex has no identifier.
casties
parents:
1
diff
changeset
|
465 if(city != null && city.isPersistent() && getCityLo().getAttribute() != null &&StringUtils.isNotEmpty(getCityLo().getAttribute().getValue())){ |
1 | 466 |
467 List<Entity> list = getWrapper().getTargetsForSourceRelation(city, is_part_of, PLACE, 1); | |
468 | |
469 if(list.size() > 0 && list.get(0).getId().longValue() == country.getId().longValue()){ | |
470 this.getCityLo().statusImage.setStatus(StatusImage.STATUS_OK); | |
471 consistent = true; | |
472 }else{ | |
473 this.getCityLo().statusImage.setStatus(StatusImage.STATUS_FALSE); | |
474 } | |
475 }else{ | |
476 this.getCityLo().statusImage.setStatus(StatusImage.STATUS_UNSET); | |
477 } | |
478 | |
479 if(consistent){ | |
480 this.checkConsistencyFromRepositoryToCodex(city); | |
481 }else{ | |
482 this.labelStatesAsFalseOrUnset(true, true, true, false, false); | |
483 } | |
484 } | |
485 | |
486 private void checkConsistencyFromRepositoryToCodex(Entity city){ | |
487 boolean consistent = false; | |
488 | |
489 Entity repository = this.getRepositoryLo().entity; | |
82
c000b4b386bc
better "internal error" message. fix NPE when codex has no identifier.
casties
parents:
1
diff
changeset
|
490 if(repository != null && repository.isPersistent() && getCollectionLo().getAttribute() != null && StringUtils.isNotEmpty(getRepositoryLo().getAttribute().getValue())){ |
1 | 491 //juc List<Entity> list = getSearchServ().getTargetsForSourceRelation(repository, is_in, PLACE, 1); |
492 List<Entity> list = getWrapper().getTargetsForSourceRelation(repository, is_in, PLACE, 1); | |
493 | |
494 if(list.size() > 0 && list.get(0).getId().longValue() == city.getId().longValue()){ | |
495 this.getRepositoryLo().statusImage.setStatus(StatusImage.STATUS_OK); | |
496 consistent = true; | |
497 }else{ | |
498 this.getRepositoryLo().statusImage.setStatus(StatusImage.STATUS_FALSE); | |
499 } | |
500 }else{ | |
501 this.getRepositoryLo().statusImage.setStatus(StatusImage.STATUS_UNSET); | |
502 } | |
503 | |
504 if(consistent){ | |
505 this.checkConsistencyFromCollectionToCodex(repository); | |
506 }else{ | |
507 this.labelStatesAsFalseOrUnset(true, true, false, false, false); | |
508 } | |
509 } | |
510 | |
511 private void checkConsistencyFromCollectionToCodex(Entity repository){ | |
512 boolean consistent = false; | |
513 | |
514 Entity collection = this.getCollectionLo().entity; | |
82
c000b4b386bc
better "internal error" message. fix NPE when codex has no identifier.
casties
parents:
1
diff
changeset
|
515 if(collection != null && collection.isPersistent() && getCollectionLo().getAttribute() != null && StringUtils.isNotEmpty(getCollectionLo().getAttribute().getValue())){ |
1 | 516 |
517 List<Entity> list = getWrapper().getTargetsForSourceRelation(collection, is_part_of, REPOSITORY, 1); | |
518 | |
519 if(list.size() > 0 && list.get(0).getId().longValue() == repository.getId().longValue()){ | |
520 this.getCollectionLo().statusImage.setStatus(StatusImage.STATUS_OK); | |
521 consistent = true; | |
522 }else{ | |
523 this.getCollectionLo().statusImage.setStatus(StatusImage.STATUS_FALSE); | |
524 } | |
525 }else{ | |
526 this.getCollectionLo().statusImage.setStatus(StatusImage.STATUS_UNSET); | |
527 } | |
528 | |
529 if(consistent){ | |
530 this.checkConsistencyOfCodex(collection); | |
531 }else{ | |
532 this.labelStatesAsFalseOrUnset(true, false, false, false, false); | |
533 } | |
534 } | |
535 | |
536 private void checkConsistencyOfCodex(Entity collection){ | |
537 | |
538 Entity codex = this.getCodexLo().entity; | |
82
c000b4b386bc
better "internal error" message. fix NPE when codex has no identifier.
casties
parents:
1
diff
changeset
|
539 if(codex != null && codex.isPersistent() && getCodexLo().getAttribute() != null && StringUtils.isNotEmpty(getCodexLo().getAttribute().getValue())){ |
1 | 540 |
541 Attribute identifier = getWrapper().getAttributeByName(codex.getId(), "identifier"); | |
542 | |
543 List<Entity> list = getWrapper().getTargetsForSourceRelation(codex, is_part_of, COLLECTION, 1); | |
544 | |
545 if(list.size() > 0 && list.get(0).getId().longValue() == collection.getId().longValue() && | |
546 identifier != null && this.getCodexLo().getAttribute().getValue().equals(identifier.getValue())){ | |
547 this.getCodexLo().setStatus(StatusImage.STATUS_OK); | |
548 }else{ | |
549 this.getCodexLo().setStatus(StatusImage.STATUS_FALSE); | |
550 } | |
551 }else{ | |
552 this.getCodexLo().setStatus(StatusImage.STATUS_UNSET); | |
553 } | |
554 } | |
555 | |
556 /** | |
557 * If a previous method detects that some elements (a subset of {CODEX,...,COUNTRY}) | |
558 * of the cycle can not be 'OK' (see: StatusImage states), | |
559 * this method will label the mentioned elements as either 'FALSE' or 'UNSET' | |
560 * | |
561 * @param bCodex true if you are sure that it can not be 'ok'. | |
562 * @param bCollection true if you are sure that it can not be 'ok'. | |
563 * @param bRepository true if you are sure that it can not be 'ok'. | |
564 * @param bCity true if you are sure that it can not be 'ok'. | |
565 * @param bCountry true if you are sure that it can not be 'ok'. | |
566 */ | |
567 public void labelStatesAsFalseOrUnset(boolean bCodex, boolean bCollection, boolean bRepository, boolean bCity, boolean bCountry){ | |
568 | |
569 if(bCodex){ | |
570 Entity codex = this.getCodexLo().entity; | |
82
c000b4b386bc
better "internal error" message. fix NPE when codex has no identifier.
casties
parents:
1
diff
changeset
|
571 if(codex != null && codex.isPersistent() && getCodexLo().getAttribute() != null && StringUtils.isNotEmpty(getCodexLo().getAttribute().getValue())) |
1 | 572 this.getCodexLo().statusImage.setStatus(StatusImage.STATUS_FALSE); |
573 else | |
574 this.getCodexLo().statusImage.setStatus(StatusImage.STATUS_UNSET); | |
575 } | |
576 | |
577 if(bCollection){ | |
578 Entity collection = this.getCollectionLo().entity; | |
82
c000b4b386bc
better "internal error" message. fix NPE when codex has no identifier.
casties
parents:
1
diff
changeset
|
579 if(collection != null && collection.isPersistent() && this.getCollectionLo().getAttribute() != null && StringUtils.isNotEmpty(this.getCollectionLo().getAttribute().getValue())) |
1 | 580 this.getCollectionLo().statusImage.setStatus(StatusImage.STATUS_FALSE); |
581 else | |
582 this.getCollectionLo().statusImage.setStatus(StatusImage.STATUS_UNSET); | |
583 } | |
584 | |
585 if(bRepository){ | |
586 Entity repository = this.getRepositoryLo().entity; | |
82
c000b4b386bc
better "internal error" message. fix NPE when codex has no identifier.
casties
parents:
1
diff
changeset
|
587 if(repository != null && repository.isPersistent() && this.getRepositoryLo().getAttribute() != null && StringUtils.isNotEmpty(this.getRepositoryLo().getAttribute().getValue())) |
1 | 588 this.getRepositoryLo().statusImage.setStatus(StatusImage.STATUS_FALSE); |
589 else | |
590 this.getRepositoryLo().statusImage.setStatus(StatusImage.STATUS_UNSET); | |
591 } | |
592 | |
593 if(bCity){ | |
594 Entity city = this.getCityLo().entity; | |
82
c000b4b386bc
better "internal error" message. fix NPE when codex has no identifier.
casties
parents:
1
diff
changeset
|
595 if(city != null && city.isPersistent() && this.getCityLo().getAttribute() != null && StringUtils.isNotEmpty(this.getCityLo().getAttribute().getValue())) |
1 | 596 this.getCityLo().statusImage.setStatus(StatusImage.STATUS_FALSE); |
597 else | |
598 this.getCityLo().statusImage.setStatus(StatusImage.STATUS_UNSET); | |
599 } | |
600 | |
601 if(bCountry){ | |
602 Entity country = this.getCountryLo().entity; | |
82
c000b4b386bc
better "internal error" message. fix NPE when codex has no identifier.
casties
parents:
1
diff
changeset
|
603 if(country != null && country.isPersistent() && this.getCountryLo().getAttribute() != null && StringUtils.isNotEmpty(this.getCountryLo().getAttribute().getValue())) |
1 | 604 this.getCountryLo().statusImage.setStatus(StatusImage.STATUS_FALSE); |
605 else | |
606 this.getCountryLo().statusImage.setStatus(StatusImage.STATUS_UNSET); | |
607 } | |
608 | |
609 } | |
610 | |
611 public ListenerObject getCountryLo() { | |
612 return countryLo; | |
613 } | |
614 public void setCountryLo(ListenerObject countryLo) { | |
615 this.countryLo = countryLo; | |
616 } | |
617 public ListenerObject getCityLo() { | |
618 return cityLo; | |
619 } | |
620 public void setCityLo(ListenerObject cityLo) { | |
621 this.cityLo = cityLo; | |
622 } | |
623 public ListenerObject getRepositoryLo() { | |
624 return repositoryLo; | |
625 } | |
626 public void setRepositoryLo(ListenerObject repositoryLo) { | |
627 this.repositoryLo = repositoryLo; | |
628 } | |
629 public ListenerObject getCollectionLo() { | |
630 return collectionLo; | |
631 } | |
632 public void setCollectionLo(ListenerObject collectionLo) { | |
633 this.collectionLo = collectionLo; | |
634 } | |
635 public ListenerObject getCodexLo() { | |
636 return codexLo; | |
637 } | |
638 public void setCodexLo(ListenerObject codexLo) { | |
639 this.codexLo = codexLo; | |
640 } | |
641 | |
642 public void setCitiesInCurrentCountry(List<SelectItem> citiesInCurrentCountry) { | |
643 this.citiesInCurrentCountry = citiesInCurrentCountry; | |
644 } | |
645 | |
646 public void setRepositoriesInCurrentCity( | |
647 List<SelectItem> repositoriesInCurrentCity) { | |
648 this.repositoriesInCurrentCity = repositoriesInCurrentCity; | |
649 } | |
650 | |
651 public void setCollectionsInCurrentRepository( | |
652 List<SelectItem> collectionsInCurrentRepository) { | |
653 this.collectionsInCurrentRepository = collectionsInCurrentRepository; | |
654 } | |
655 | |
656 public void setShelfMarksInCurrentCollection( | |
657 List<SelectItem> shelfMarksInCurrentCollection) { | |
658 this.shelfMarksInCurrentCollection = shelfMarksInCurrentCollection; | |
659 } | |
660 | |
661 public boolean isThereExistMoreCodices() { | |
662 return thereExistMoreCodices; | |
663 } | |
664 | |
665 public void setThereExistMoreCodices(boolean thereExistMoreCodices) { | |
666 this.thereExistMoreCodices = thereExistMoreCodices; | |
667 } | |
668 | |
669 public List<SelectItem> getCitiesInCurrentCountry() { | |
670 if(this.citiesInCurrentCountry != null && | |
671 this.citiesInCurrentCountry.size() > 0 && | |
672 (this.citiesInCurrentCountry.get(0).getLabel() == null || | |
673 !this.citiesInCurrentCountry.get(0).getLabel().equals("-- choose --"))){ | |
674 SelectItem chooser = new SelectItem("", "-- choose --"); | |
675 this.citiesInCurrentCountry.add(0, chooser); | |
676 } | |
677 return citiesInCurrentCountry; | |
678 } | |
679 | |
680 public List<SelectItem> getRepositoriesInCurrentCity() { | |
681 if(this.repositoriesInCurrentCity != null && | |
682 this.repositoriesInCurrentCity.size() > 0 && | |
683 (this.repositoriesInCurrentCity.get(0).getLabel() == null || | |
684 !this.repositoriesInCurrentCity.get(0).getLabel().equals("-- choose --"))){ | |
685 SelectItem chooser = new SelectItem("", "-- choose --"); | |
686 this.repositoriesInCurrentCity.add(0, chooser); | |
687 } | |
688 return repositoriesInCurrentCity; | |
689 } | |
690 | |
691 public List<SelectItem> getCollectionsInCurrentRepository() { | |
692 if(this.collectionsInCurrentRepository != null && | |
693 this.collectionsInCurrentRepository.size() > 0 && | |
694 (this.collectionsInCurrentRepository.get(0).getLabel() == null || | |
695 !this.collectionsInCurrentRepository.get(0).getLabel().equals("-- choose --"))){ | |
696 SelectItem chooser = new SelectItem("", "-- choose --"); | |
697 this.collectionsInCurrentRepository.add(0, chooser); | |
698 } | |
699 return collectionsInCurrentRepository; | |
700 } | |
701 | |
702 public List<SelectItem> getShelfMarksInCurrentCollection() { | |
703 if(shelfMarksInCurrentCollection != null && | |
704 this.shelfMarksInCurrentCollection.size() > 0 && | |
705 (this.shelfMarksInCurrentCollection.get(0).getLabel() == null || | |
706 !this.shelfMarksInCurrentCollection.get(0).getLabel().equals("-- choose --"))){ | |
707 SelectItem chooser = new SelectItem("", "-- choose --"); | |
708 this.shelfMarksInCurrentCollection.add(0, chooser); | |
709 } | |
710 return shelfMarksInCurrentCollection; | |
711 } | |
712 public class CodexForList { | |
713 | |
714 public String ident; | |
715 public String repository; | |
716 public String collection; | |
717 public String place; | |
718 public String city; | |
719 public Long id; | |
720 | |
721 public String getIdent() { | |
722 return ident; | |
723 } | |
724 | |
725 public void setIdent(String ident) { | |
726 this.ident = ident; | |
727 } | |
728 | |
729 public String getRepository() { | |
730 return repository; | |
731 } | |
732 | |
733 public void setRepository(String repository) { | |
734 this.repository = repository; | |
735 } | |
736 | |
737 public String getCollection() { | |
738 return collection; | |
739 } | |
740 | |
741 public void setCollection(String collection) { | |
742 this.collection = collection; | |
743 } | |
744 | |
745 public String getPlace() { | |
746 return place; | |
747 } | |
748 | |
749 public void setPlace(String place) { | |
750 this.place = place; | |
751 } | |
752 | |
753 public Long getId() { | |
754 return id; | |
755 } | |
756 | |
757 public void setId(Long id) { | |
758 this.id = id; | |
759 } | |
760 | |
761 public String toString() { | |
762 String str = ""; | |
763 if (ident != null && !ident.equals("")) | |
764 str += ident; | |
765 | |
766 if (collection != null && !collection.equals("")) | |
767 str += "_" + collection; | |
768 if (repository != null && !repository.equals("")) | |
769 str += "_" + repository; | |
770 if (city != null && !city.equals("")) | |
771 str += city; | |
772 | |
773 return str; | |
774 | |
775 } | |
776 } | |
777 | |
778 | |
779 protected boolean isRepositoryConsistentBeforeSave(){ | |
780 this.checkConsistencyFromCountryToCodex(); | |
781 | |
782 if(!getCountryLo().getStatus().equals(StatusImage.STATUS_OK)){ | |
783 this.addErrorMsg("The country is marked as: " + getCountryLo().getStatus() + ". The entity could not be saved."); | |
784 return false; | |
785 } | |
786 | |
787 if(!getCityLo().getStatus().equals(StatusImage.STATUS_OK)){ | |
788 this.addErrorMsg("The city is marked as: " + getCityLo().getStatus() + ". The entity could not be saved."); | |
789 return false; | |
790 } | |
791 | |
792 return true; | |
793 } | |
794 | |
795 protected boolean isCollectionConsistentBeforeSave(){ | |
796 | |
797 if(!isRepositoryConsistentBeforeSave()){ | |
798 return false; | |
799 } | |
800 | |
801 if(!getRepositoryLo().getStatus().equals(StatusImage.STATUS_OK)){ | |
802 this.addErrorMsg("The repository is marked as: " + getRepositoryLo().getStatus() + ". The entity could not be saved."); | |
803 return false; | |
804 } | |
805 | |
806 return true; | |
807 } | |
808 | |
809 protected boolean isCodexConsistentBeforeSave(){ | |
810 | |
811 if(!isCollectionConsistentBeforeSave()){ | |
812 return false; | |
813 } | |
814 | |
815 if(!getCollectionLo().getStatus().equals(StatusImage.STATUS_OK)){ | |
816 this.addErrorMsg("The collection is marked as: " + getCollectionLo().getStatus() + ". The entity could not be saved."); | |
817 return false; | |
818 } | |
819 | |
820 return true; | |
821 } | |
822 | |
823 protected boolean isWitnessConsistentBeforeSave(){ | |
824 | |
825 if(!isCodexConsistentBeforeSave()){ | |
826 return false; | |
827 } | |
828 | |
829 if(!getCodexLo().getStatus().equals(StatusImage.STATUS_OK)){ | |
830 this.addErrorMsg("The codex is marked as: " + getCodexLo().getStatus() + ". The entity could not be saved."); | |
831 return false; | |
832 } | |
833 | |
834 return true; | |
835 } | |
836 | |
837 | |
838 public void editThisCountryAction(ActionEvent event){ | |
839 if(this.getCountryLo().entity != null && this.getCountryLo().entity.isPersistent()){ | |
840 getSessionBean().editEntity(this.getCountryLo().entity); | |
841 } | |
842 } | |
843 | |
844 public void editThisCityAction(ActionEvent event){ | |
845 if(this.getCityLo().entity != null && this.getCityLo().entity.isPersistent()){ | |
846 getSessionBean().editEntity(this.getCityLo().entity); | |
847 } | |
848 } | |
849 | |
850 public void editThisRepositoryAction(ActionEvent event){ | |
851 if(this.getRepositoryLo().entity != null && this.getRepositoryLo().entity.isPersistent()){ | |
852 getSessionBean().editEntity(this.getRepositoryLo().entity); | |
853 } | |
854 } | |
855 | |
856 public void editThisCollectionAction(ActionEvent event){ | |
857 if(this.getCollectionLo().entity != null && this.getCollectionLo().entity.isPersistent()){ | |
858 getSessionBean().editEntity(this.getCollectionLo().entity); | |
859 } | |
860 } | |
861 | |
862 public void editThisCodexAction(ActionEvent event){ | |
863 if(this.getCodexLo().entity != null && this.getCodexLo().entity.isPersistent()){ | |
864 getSessionBean().editEntity(this.getCodexLo().entity); | |
865 } | |
866 } | |
867 | |
868 public void identifierChangedListener(ValueChangeEvent event) { | |
869 if(event.getNewValue() != null){ | |
870 inCurrentListener(getShelfMarksInCurrentCollection(), event); | |
871 }else{ | |
872 getCodexLo().setEntity(null); | |
873 getCodexLo().setAttribute(new Attribute("identifier", TEXT, "")); | |
874 } | |
875 } | |
876 } |