1
|
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
|
106
|
7 /**
|
|
8 * Class to check uniqueness of Entities.
|
|
9 *
|
|
10 * @author jurzua
|
|
11 *
|
|
12 */
|
1
|
13 public class UnityChecker extends AbstractISMIBean{
|
|
14
|
|
15 private static final long serialVersionUID = -5727416233789954800L;
|
|
16 private Entity cloneEntity;
|
|
17 private String unityCheckerMsg;
|
|
18 private boolean renderUnityCheckerDialog;
|
|
19
|
|
20 @Override
|
|
21 public void reset(){
|
|
22 super.reset();
|
|
23 this.renderUnityCheckerDialog = false;
|
|
24 }
|
|
25
|
106
|
26 /**
|
|
27 * Return if the name for an entity is unique.
|
|
28 *
|
|
29 * @param unityName
|
|
30 * @param id
|
|
31 * @param objectClass
|
|
32 * @param target
|
|
33 * @param relationName
|
|
34 * @param attName
|
|
35 * @return
|
|
36 */
|
1
|
37 private boolean checkUnity(String unityName, Long id, String objectClass, Entity target, String relationName, String attName){
|
|
38 this.cloneEntity = null;
|
|
39 unityName = unityName.toLowerCase();
|
|
40
|
|
41 if(target != null && target.isPersistent()){
|
|
42 for (Entity src : getWrapper().getSourcesForTargetRelation(target, relationName, objectClass, -1)) {
|
|
43 if(id == null || id.longValue() != src.getId().longValue()){
|
|
44 if(StringUtils.isEmpty(attName)){
|
|
45 if(unityName.equals(src.getOwnValue().toLowerCase())){
|
|
46 this.cloneEntity = src;
|
|
47 return false;
|
|
48 }
|
|
49 }else{
|
|
50 Attribute att = getWrapper().getAttributeByName(src.getId(), attName);
|
|
51 if(att != null && unityName.equals(att.getValue().toLowerCase())){
|
|
52 this.cloneEntity = src;
|
|
53 return false;
|
|
54 }
|
|
55 }
|
|
56 }
|
|
57 }
|
|
58 }
|
|
59
|
|
60 return true;
|
|
61 }
|
|
62
|
|
63 public String hideUnityCheckerDialog(){
|
|
64 this.renderUnityCheckerDialog = false;
|
|
65 return PAGE_EDITOR;
|
|
66 }
|
|
67
|
|
68 public void renderUnityCheckerDialog(){
|
|
69 if(cloneEntity != null && cloneEntity.isPersistent()){
|
|
70 if(cloneEntity.getObjectClass().equals(CODEX)){
|
|
71 this.unityCheckerMsg = "There is already an object with the same identifier. ";
|
|
72 }else{
|
|
73 this.unityCheckerMsg = "There is already an object with the same name. ";
|
|
74 }
|
|
75
|
|
76 this.unityCheckerMsg += "The ID of the " + cloneEntity.getObjectClass().toLowerCase() +
|
|
77 " found is " + cloneEntity.getId() + ".";
|
|
78
|
|
79 this.unityCheckerMsg +=
|
|
80 "\nDo you want to load the existing "
|
|
81 + cloneEntity.getObjectClass().toLowerCase() + "?";
|
|
82 this.renderUnityCheckerDialog = true;
|
|
83 }
|
|
84 }
|
|
85
|
|
86 public String loadCloneEntity(){
|
|
87 if(cloneEntity != null && cloneEntity.isPersistent()){
|
|
88 getSessionBean().editEntity(cloneEntity);
|
|
89 }
|
|
90 return PAGE_EDITOR;
|
|
91 }
|
|
92
|
|
93 public boolean checkUnityCollection(String collectionName, Long id, Entity repository){
|
|
94 return this.checkUnity(collectionName, id, COLLECTION, repository, is_part_of, null);
|
|
95 }
|
|
96
|
|
97 public boolean checkUnityRepository(String repositoryName, Long id, Entity city){
|
|
98 return this.checkUnity(repositoryName, id, REPOSITORY, city, is_in, null);
|
|
99 }
|
|
100
|
|
101 public boolean checkUnityCity(String cityName, Long id, Entity country){
|
|
102 return this.checkUnity(cityName, id, PLACE, country, is_part_of, null);
|
|
103 }
|
|
104
|
|
105 public boolean checkUnityCodex(String identifier, Long id, Entity collection){
|
|
106 return this.checkUnity(identifier, id, CODEX, collection, is_part_of, "identifier");
|
|
107 }
|
|
108
|
|
109 public Entity getCloneEntity() {
|
|
110 return cloneEntity;
|
|
111 }
|
|
112
|
|
113 public void setCloneEntity(Entity cloneEntity) {
|
|
114 this.cloneEntity = cloneEntity;
|
|
115 }
|
|
116 public String getUnityCheckerMsg() {
|
|
117 return unityCheckerMsg;
|
|
118 }
|
|
119
|
|
120 public void setUnityCheckerMsg(String unityCheckerMsg) {
|
|
121 this.unityCheckerMsg = unityCheckerMsg;
|
|
122 }
|
|
123 public boolean isRenderUnityCheckerDialog() {
|
|
124 return renderUnityCheckerDialog;
|
|
125 }
|
|
126
|
|
127 public void setRenderUnityCheckerDialog(boolean renderUnityCheckerDialog) {
|
|
128 this.renderUnityCheckerDialog = renderUnityCheckerDialog;
|
|
129 }
|
|
130 }
|