comparison src/main/java/de/mpiwg/itgroup/ismi/entry/beans/CurrentCollectionBean.java @ 1:2e911857a759

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