Mercurial > hg > ismi-richfaces
comparison src/main/java/de/mpiwg/itgroup/ismi/entry/beans/UnityChecker.java @ 1:2e911857a759
(none)
author | jurzua |
---|---|
date | Wed, 29 Oct 2014 14:00:28 +0000 |
parents | |
children | 71efad4fe975 |
comparison
equal
deleted
inserted
replaced
0:74df02964906 | 1:2e911857a759 |
---|---|
1 package de.mpiwg.itgroup.ismi.entry.beans; | |
2 | |
3 import org.apache.commons.lang.StringUtils; | |
4 import org.mpi.openmind.repository.bo.Attribute; | |
5 import org.mpi.openmind.repository.bo.Entity; | |
6 | |
7 public class UnityChecker extends AbstractISMIBean{ | |
8 | |
9 /** | |
10 * | |
11 */ | |
12 private static final long serialVersionUID = -5727416233789954800L; | |
13 private Entity cloneEntity; | |
14 private String unityCheckerMsg; | |
15 private boolean renderUnityCheckerDialog; | |
16 | |
17 @Override | |
18 public void reset(){ | |
19 super.reset(); | |
20 this.renderUnityCheckerDialog = false; | |
21 } | |
22 | |
23 private boolean checkUnity(String unityName, Long id, String objectClass, Entity target, String relationName, String attName){ | |
24 this.cloneEntity = null; | |
25 unityName = unityName.toLowerCase(); | |
26 | |
27 if(target != null && target.isPersistent()){ | |
28 for (Entity src : getWrapper().getSourcesForTargetRelation(target, relationName, objectClass, -1)) { | |
29 if(id == null || id.longValue() != src.getId().longValue()){ | |
30 if(StringUtils.isEmpty(attName)){ | |
31 if(unityName.equals(src.getOwnValue().toLowerCase())){ | |
32 this.cloneEntity = src; | |
33 return false; | |
34 } | |
35 }else{ | |
36 Attribute att = getWrapper().getAttributeByName(src.getId(), attName); | |
37 if(att != null && unityName.equals(att.getValue().toLowerCase())){ | |
38 this.cloneEntity = src; | |
39 return false; | |
40 } | |
41 } | |
42 } | |
43 } | |
44 } | |
45 | |
46 return true; | |
47 } | |
48 | |
49 public String hideUnityCheckerDialog(){ | |
50 this.renderUnityCheckerDialog = false; | |
51 return PAGE_EDITOR; | |
52 } | |
53 | |
54 public void renderUnityCheckerDialog(){ | |
55 if(cloneEntity != null && cloneEntity.isPersistent()){ | |
56 if(cloneEntity.getObjectClass().equals(CODEX)){ | |
57 this.unityCheckerMsg = "There is already an object with the same identifier. "; | |
58 }else{ | |
59 this.unityCheckerMsg = "There is already an object with the same name. "; | |
60 } | |
61 | |
62 this.unityCheckerMsg += "The ID of the " + cloneEntity.getObjectClass().toLowerCase() + | |
63 " found is " + cloneEntity.getId() + "."; | |
64 | |
65 this.unityCheckerMsg += | |
66 "\nDo you want to load the existing " | |
67 + cloneEntity.getObjectClass().toLowerCase() + "?"; | |
68 this.renderUnityCheckerDialog = true; | |
69 } | |
70 } | |
71 | |
72 public String loadCloneEntity(){ | |
73 if(cloneEntity != null && cloneEntity.isPersistent()){ | |
74 getSessionBean().editEntity(cloneEntity); | |
75 } | |
76 return PAGE_EDITOR; | |
77 } | |
78 | |
79 public boolean checkUnityCollection(String collectionName, Long id, Entity repository){ | |
80 return this.checkUnity(collectionName, id, COLLECTION, repository, is_part_of, null); | |
81 } | |
82 | |
83 public boolean checkUnityRepository(String repositoryName, Long id, Entity city){ | |
84 return this.checkUnity(repositoryName, id, REPOSITORY, city, is_in, null); | |
85 } | |
86 | |
87 public boolean checkUnityCity(String cityName, Long id, Entity country){ | |
88 return this.checkUnity(cityName, id, PLACE, country, is_part_of, null); | |
89 } | |
90 | |
91 public boolean checkUnityCodex(String identifier, Long id, Entity collection){ | |
92 return this.checkUnity(identifier, id, CODEX, collection, is_part_of, "identifier"); | |
93 } | |
94 | |
95 public Entity getCloneEntity() { | |
96 return cloneEntity; | |
97 } | |
98 | |
99 public void setCloneEntity(Entity cloneEntity) { | |
100 this.cloneEntity = cloneEntity; | |
101 } | |
102 public String getUnityCheckerMsg() { | |
103 return unityCheckerMsg; | |
104 } | |
105 | |
106 public void setUnityCheckerMsg(String unityCheckerMsg) { | |
107 this.unityCheckerMsg = unityCheckerMsg; | |
108 } | |
109 public boolean isRenderUnityCheckerDialog() { | |
110 return renderUnityCheckerDialog; | |
111 } | |
112 | |
113 public void setRenderUnityCheckerDialog(boolean renderUnityCheckerDialog) { | |
114 this.renderUnityCheckerDialog = renderUnityCheckerDialog; | |
115 } | |
116 } |