Mercurial > hg > ismi-richfaces
annotate src/main/java/de/mpiwg/itgroup/ismi/entry/beans/CurrentCollectionBean.java @ 134:25bfcc9d757c
effort to re-use more relations when saving entities.
new replaceMultipleSourceRelations() and changes to use it.
changes for renamed replaceUniqueSourceRelation().
author | casties |
---|---|
date | Fri, 24 Feb 2017 20:25:33 +0100 |
parents | eee2e0ca4032 |
children | 502ae5b1a07d |
rev | line source |
---|---|
1 | 1 package de.mpiwg.itgroup.ismi.entry.beans; |
2 | |
3 import java.io.Serializable; | |
4 | |
5 import org.apache.commons.lang.StringUtils; | |
6 import org.apache.log4j.Logger; | |
7 import org.mpi.openmind.repository.bo.Attribute; | |
8 import org.mpi.openmind.repository.bo.Entity; | |
9 import org.mpi.openmind.repository.bo.Node; | |
125 | 10 import org.mpi.openmind.repository.services.utils.EditIntent; |
1 | 11 |
12 public class CurrentCollectionBean extends CodexEditorTemplate implements | |
13 Serializable { | |
14 private static final long serialVersionUID = 5723693904746973203L; | |
15 | |
16 public static int MAX_PLACES = 100; | |
17 public static int MAX_REPOSITORIES = 100; | |
18 private static Logger logger = Logger | |
19 .getLogger(CurrentCollectionBean.class); | |
20 | |
21 protected Boolean restrictCities = true; | |
22 private Boolean restrictRepositories = true; | |
23 | |
125 | 24 /** intent to edit all attributes and relations in the form */ |
25 public static EditIntent editCollectionIntent = new EditIntent( | |
26 AbstractISMIBean.COLLECTION, | |
27 // attributes | |
28 new String[]{"name"}, | |
29 // source relations | |
30 new String[]{"is_part_of"}, | |
31 // target relations | |
32 new String[]{"is_reference_of"}); | |
33 | |
1 | 34 |
35 @Override | |
36 public void reset() { | |
37 super.reset(); | |
38 this.entity = new Entity(Node.TYPE_ABOX, COLLECTION, false); | |
39 | |
40 this.restrictCities = true; | |
41 this.restrictRepositories = true; | |
42 | |
43 this.entity = new Entity(Node.TYPE_ABOX, COLLECTION, false); | |
44 } | |
45 | |
46 public CurrentCollectionBean() { | |
47 this.reset(); | |
48 // setDefinition(getDefinition("COLLECTION")); | |
49 setDefObjectClass(COLLECTION); | |
50 registerChecker(getCityLo(), "City is not valid!"); | |
51 registerChecker(getCountryLo(), "Country is not valid!"); | |
52 registerChecker(getRepositoryLo(), "Repository is not valid!"); | |
53 } | |
54 | |
55 public Boolean getRestrictCities() { | |
56 return restrictCities; | |
57 } | |
58 | |
59 public void setRestrictCities(Boolean restrictCities) { | |
60 this.restrictCities = restrictCities; | |
61 } | |
62 | |
63 public Boolean getRestrictRepositories() { | |
64 return restrictRepositories; | |
65 } | |
66 | |
67 public void setRestrictRepositories(Boolean restrictRepositories) { | |
68 this.restrictRepositories = restrictRepositories; | |
69 } | |
70 | |
71 public void setEntity(Entity collection) { | |
72 this.reset(); | |
73 this.entity = collection; | |
74 | |
75 if (this.entity != null && this.entity.isPersistent()) { | |
76 if (this.entity.isLightweight()) { | |
77 this.entity = getWrapper().getEntityContent(this.entity); | |
78 } | |
79 | |
80 this.loadAttributes(this.entity); | |
81 | |
82 for (Entity target : getWrapper().getTargetsForSourceRelation( | |
83 collection, "is_part_of", REPOSITORY, 1)) { | |
84 setRepository(target); | |
85 } | |
86 | |
87 // this.loadReferences(this.entity); | |
88 this.loadEndNoteRefs(); | |
89 | |
90 this.setCurrentId(this.entity.getId().toString()); | |
91 this.checkConsistencyFromCountryToCodex(); | |
92 } | |
93 } | |
94 | |
95 public String saveAsNewEntity() { | |
96 this.setSelectedSaveAsNew(true); | |
97 return save(); | |
98 } | |
99 | |
100 @Override | |
101 public String save() { | |
102 super.save(); | |
103 try { | |
104 | |
105 CheckResults cr = getCheckResults(); | |
106 if (cr.hasErrors) { | |
107 getSessionBean().setErrorMessages(cr); | |
108 getSessionBean().setDisplayError(true); | |
109 this.setSelectedSaveAsNew(false); | |
110 return ""; | |
111 } | |
112 | |
113 this.entity = this.updateEntityAttributes(this.entity); | |
114 // checking is the identifier is unique for the selected collecion | |
115 Attribute attName = this.entity.getAttributeByName("name"); | |
134
25bfcc9d757c
effort to re-use more relations when saving entities.
casties
parents:
125
diff
changeset
|
116 String collectionName = (attName == null) ? null : attName.getValue(); |
1 | 117 if (StringUtils.isNotEmpty(collectionName)) { |
134
25bfcc9d757c
effort to re-use more relations when saving entities.
casties
parents:
125
diff
changeset
|
118 if (!checkUnityCollection(collectionName, (isSelectedSaveAsNew()) ? null : this.entity.getId(), |
1 | 119 this.getRepositoryLo().entity)) { |
120 this.renderUnityCheckerDialog(); | |
121 this.setSelectedSaveAsNew(false); | |
122 return ""; | |
123 } | |
124 } else { | |
125 this.addErrorMsg("Ths entity has not been saved, because its name was empty."); | |
126 this.addErrorMsg("You must enter a name."); | |
127 return ""; | |
128 } | |
129 | |
130 if (!isCollectionConsistentBeforeSave()) { | |
131 return ""; | |
132 } | |
133 | |
134
25bfcc9d757c
effort to re-use more relations when saving entities.
casties
parents:
125
diff
changeset
|
134 if (this.getRepositoryLo().entity != null && this.getRepositoryLo().entity.isLightweight()) { |
1 | 135 this.getRepositoryLo().entity = getWrapper() |
134
25bfcc9d757c
effort to re-use more relations when saving entities.
casties
parents:
125
diff
changeset
|
136 .getEntityByIdWithContent(this.getRepositoryLo().entity.getId()); |
1 | 137 } |
134
25bfcc9d757c
effort to re-use more relations when saving entities.
casties
parents:
125
diff
changeset
|
138 this.entity.replaceUniqueSourceRelation(this.getRepositoryLo().entity, REPOSITORY, is_part_of); |
1 | 139 |
140 // REFERENCE -> is_reference_of -> THIS | |
141 this.prepareEndNoteRefs2Save(); | |
142 | |
143 if (isSelectedSaveAsNew()) { | |
134
25bfcc9d757c
effort to re-use more relations when saving entities.
casties
parents:
125
diff
changeset
|
144 // this.entity.removeAllTargetRelations(is_part_of, CODEX); |
25bfcc9d757c
effort to re-use more relations when saving entities.
casties
parents:
125
diff
changeset
|
145 // this.entity = getWrapper().saveEntityAsNew(this.entity, |
25bfcc9d757c
effort to re-use more relations when saving entities.
casties
parents:
125
diff
changeset
|
146 // getSessionUser().getEmail()); |
1 | 147 } else { |
125 | 148 this.entity = getWrapper().saveEntity(this.entity, getSessionUser().getEmail(), editCollectionIntent); |
1 | 149 } |
150 | |
91 | 151 this.updateRelatedOW(this.entity, getSessionUser().getEmail()); |
1 | 152 this.setCurrentId(this.entity.getId().toString()); |
153 | |
134
25bfcc9d757c
effort to re-use more relations when saving entities.
casties
parents:
125
diff
changeset
|
154 logger.info("Entity saved - Time = " + (System.currentTimeMillis() - start) + ", " + entity); |
1 | 155 this.printSuccessSavingEntity(); |
156 | |
157 this.setSelectedSaveAsNew(false); | |
158 | |
159 } catch (Exception e) { | |
160 logger.error(e.getMessage(), e); | |
161 e.printStackTrace(); | |
162 this.printInternalError(e); | |
163 } | |
164 saveEnd(); | |
165 | |
166 return PAGE_EDITOR; | |
167 } | |
168 | |
169 /** | |
170 * <p> | |
171 * This method saves the collection without the loading of its contain when | |
172 * it is not necessary. LW means that the collection keeps light weight or | |
173 * without attributes and relation. | |
174 * </p> | |
175 * <p> | |
176 * It is normally used by classes (like: CurrentCodex, CurrentWitness) which | |
177 * inherit of this class. | |
178 * </p> | |
179 * | |
180 * @param collection | |
181 */ | |
182 public void setLWCollection(Entity collection) { | |
183 this.entity = collection; | |
184 } | |
185 } |