1
|
1 package de.mpiwg.itgroup.ismi.entry.beans;
|
|
2
|
|
3 import java.io.Serializable;
|
|
4 import java.util.ArrayList;
|
|
5 import java.util.List;
|
|
6
|
89
|
7 import javax.faces.event.ActionEvent;
|
1
|
8 import javax.faces.model.SelectItem;
|
|
9
|
|
10 import org.apache.commons.lang.StringUtils;
|
|
11 import org.apache.log4j.Logger;
|
89
|
12 import org.mpi.openmind.repository.bo.Attribute;
|
1
|
13 import org.mpi.openmind.repository.bo.Entity;
|
|
14 import org.mpi.openmind.repository.bo.Node;
|
|
15 import org.mpi.openmind.repository.bo.Relation;
|
125
|
16 import org.mpi.openmind.repository.services.utils.EditIntent;
|
1
|
17
|
89
|
18 import de.mpiwg.itgroup.ismi.auxObjects.ListenerObject;
|
107
|
19 import de.mpiwg.itgroup.ismi.util.guiComponents.EntityList;
|
1
|
20 import de.mpiwg.itgroup.ismi.utils.SelectableObject;
|
|
21
|
|
22
|
89
|
23 public class CurrentCityBean extends CodexEditorTemplate implements Serializable {
|
1
|
24 private static final long serialVersionUID = -8609055286714729597L;
|
|
25
|
|
26 private static Logger logger = Logger.getLogger(CurrentCityBean.class);
|
|
27
|
|
28 private List<SelectItem> suggestedTypes;
|
|
29
|
|
30 private List<SelectableObject<Entity>> placesPartOfThis;
|
107
|
31 //private List<SelectableObject<Entity>> peopleLivedIn;
|
|
32 private EntityList aliasList;
|
|
33
|
125
|
34 /** intent to edit all attributes and relations in the form */
|
|
35 public static EditIntent editPlaceIntent = new EditIntent(
|
|
36 AbstractISMIBean.PLACE,
|
|
37 // attributes
|
|
38 new String[]{"name", "type"},
|
|
39 // source relations
|
|
40 new String[]{"is_part_of"},
|
|
41 // target relations
|
|
42 new String[]{"is_part_of", "is_alias_name_of"});
|
|
43
|
1
|
44 public CurrentCityBean() {
|
|
45 this.reset();
|
|
46 }
|
|
47
|
|
48 @Override
|
|
49 public void reset(){
|
|
50 super.reset();
|
|
51 this.entity = new Entity(Node.TYPE_ABOX, PLACE, false);
|
|
52 this.suggestedTypes = new ArrayList<SelectItem>();
|
|
53
|
|
54 this.placesPartOfThis = new ArrayList<SelectableObject<Entity>>();
|
107
|
55 //this.peopleLivedIn = new ArrayList<SelectableObject<Entity>>();
|
|
56 this.aliasList = new EntityList(ALIAS, "alias", getWrapper(), getUserName());
|
1
|
57
|
|
58 //setDefinition(getDefinition(PLACE));
|
|
59 setDefObjectClass(PLACE);
|
89
|
60 // old types
|
1
|
61 String[] types = new String[]{"city","institution", "city_part", "region"};
|
89
|
62 // get new types from definition
|
|
63 Attribute typeAtt = getWrapper().getDefAttributeByOwnValue(PLACE, "type");
|
|
64 if (typeAtt != null) {
|
|
65 types = typeAtt.getPossibleValuesList().toArray(types);
|
|
66 }
|
1
|
67 fillList(suggestedTypes, types);
|
|
68
|
|
69 registerChecker(getCountryLo(), "Country not valid!");
|
|
70 }
|
|
71
|
|
72 @Override
|
105
|
73 public void setEntity(Entity city) {
|
|
74 this.reset();
|
|
75 this.entity = city;
|
|
76
|
|
77 if (this.entity.isPersistent()) {
|
|
78 // load attributes and relations of Entity
|
|
79 if (city.isLightweight()) {
|
|
80 this.entity = getWrapper().getEntityContent(this.entity);
|
|
81 }
|
|
82 // load entity attributes into bean
|
|
83 this.loadAttributes(this.entity);
|
|
84
|
|
85 /*
|
|
86 * create list of places this place is part_of
|
|
87 */
|
|
88 List<Entity> list = getWrapper().getTargetsForSourceRelation(city, is_part_of, PLACE, -1);
|
|
89 if (list.size() > 0) {
|
|
90 this.setCountry(list.get(0));
|
|
91 // part_of more than one place
|
|
92 if (list.size() > 1) {
|
106
|
93 addErrorMsg("Inconsistency: this place 'is part of' " + list.size() + " other places!");
|
105
|
94 addErrorMsg("List:");
|
|
95 for (Entity place : list) {
|
|
96 addErrorMsg(place.getOwnValue() + " [" + place.getId() + "]");
|
|
97 }
|
|
98 }
|
|
99 }
|
|
100
|
|
101 /*
|
|
102 * create list of places that are part of this place
|
|
103 */
|
|
104 for (Entity place : getWrapper().getSourcesForTargetRelation(city, is_part_of, PLACE, -1)) {
|
|
105 String label = place.getOwnValue() + " [" + place.getId() + "]";
|
|
106 this.placesPartOfThis.add(new SelectableObject<Entity>(place, label));
|
|
107 }
|
|
108
|
107
|
109 /*
|
|
110 * create list of alias names of this place
|
|
111 */
|
|
112 for (Entity alias : getWrapper().getSourcesForTargetRelation(city, is_alias_name_of, ALIAS, -1)) {
|
|
113 this.aliasList.add(alias);
|
|
114 }
|
|
115
|
105
|
116 // load references
|
|
117 this.loadEndNoteRefs();
|
|
118
|
|
119 this.setCurrentId(this.entity.getId().toString());
|
|
120 // check consistency and set checkmark(s)
|
|
121 this.checkConsistencyFromCountryToCodex();
|
|
122 }
|
|
123 }
|
1
|
124
|
106
|
125 /* (non-Javadoc)
|
|
126 * @see de.mpiwg.itgroup.ismi.entry.beans.AbstractISMIBean#save()
|
|
127 */
|
1
|
128 @Override
|
|
129 public String save(){
|
|
130 super.save();
|
|
131 try {
|
|
132
|
|
133 CheckResults cr = getCheckResults();
|
|
134 if (cr.hasErrors){
|
|
135 getSessionBean().setErrorMessages(cr);
|
|
136 getSessionBean().setDisplayError(true);
|
|
137 this.setSelectedSaveAsNew(false);
|
|
138 return "SAVE_ERROR";
|
|
139 }
|
|
140
|
|
141 this.entity = this.updateEntityAttributes(this.entity);
|
|
142
|
|
143 String cityName = (this.entity.getAttributeByName(name) != null) ? this.entity.getAttributeByName(name).getValue() : "";
|
|
144 if(StringUtils.isNotEmpty(cityName)){
|
107
|
145 // check if name is unique
|
1
|
146 if(!checkUnityCity(cityName, (isSelectedSaveAsNew()) ? null : this.entity.getId(), this.getCountryLo().entity)){
|
|
147 this.renderUnityCheckerDialog();
|
|
148 this.setSelectedSaveAsNew(false);
|
|
149 return "SAVE_ERROR";
|
|
150 }
|
|
151 }else{
|
105
|
152 this.addErrorMsg("This place has not been saved, because its name was empty.");
|
106
|
153 this.addErrorMsg("Please enter a name.");
|
1
|
154 return "SAVE_ERROR";
|
|
155 }
|
|
156
|
|
157 this.entity.replaceSourceRelation(this.getCountryLo().entity, PLACE, is_part_of);
|
|
158
|
|
159 this.entity.removeAllTargetRelationsByName(is_part_of);
|
|
160 for(SelectableObject<Entity> so : this.placesPartOfThis){
|
|
161 Entity place = getWrapper().getEntityByIdWithContent(so.getObj().getId());
|
105
|
162 new Relation(place, this.entity, is_part_of);
|
1
|
163 }
|
|
164
|
89
|
165 /*
|
1
|
166 this.entity.removeAllTargetRelationsByName(lived_in);
|
|
167 for(SelectableObject<Entity> so : this.peopleLivedIn){
|
|
168 Entity person = getWrapper().getEntityByIdWithContent(so.getObj().getId());
|
|
169 Relation livedIn = new Relation(person, this.entity, lived_in);
|
|
170 }
|
89
|
171 */
|
1
|
172
|
107
|
173 //ALIAS -> is_alias_name_of -> PERSON
|
|
174 this.entity.removeAllTargetRelationsByName(is_alias_name_of);
|
|
175 for(Entity alias : this.aliasList.getEntities()){
|
|
176 Entity alias0 = getWrapper().getEntityByIdWithContent(alias.getId());
|
|
177 new Relation(alias0, this.entity, is_alias_name_of);
|
|
178 }
|
|
179
|
1
|
180 //REFERENCE -> is_reference_of -> THIS
|
|
181 this.prepareEndNoteRefs2Save();
|
|
182
|
125
|
183 if (this.isSelectedSaveAsNew()) {
|
1
|
184 this.setSelectedSaveAsNew(false);
|
125
|
185 } else {
|
|
186 this.entity = getWrapper().saveEntity(this.entity, getSessionUser().getEmail(), editPlaceIntent);
|
1
|
187 }
|
91
|
188 this.updateRelatedOW(this.entity, getSessionUser().getEmail());
|
1
|
189 this.setCurrentId(this.entity.getId().toString());
|
|
190
|
105
|
191 logger.debug("Place saved - Time = " + (System.currentTimeMillis() - start) + ", " + entity);
|
1
|
192 this.printSuccessSavingEntity();
|
|
193
|
|
194 this.setSelectedSaveAsNew(false);
|
|
195
|
|
196 } catch (Exception e) {
|
|
197 logger.error(e.getMessage(), e);
|
|
198 this.printInternalError(e);
|
|
199 }
|
|
200 saveEnd();
|
|
201
|
|
202 return PAGE_EDITOR;
|
|
203 }
|
|
204
|
|
205 public void listenerRemovePlacesPartOfThis(){
|
|
206 for(SelectableObject<Entity> so : new ArrayList<SelectableObject<Entity>>(this.placesPartOfThis)){
|
|
207 if(so.isSelected()){
|
|
208 this.placesPartOfThis.remove(so);
|
|
209 }
|
|
210 }
|
|
211 }
|
|
212
|
107
|
213 /* public void listenerRemovePeopleLivedIn(){
|
1
|
214 for(SelectableObject<Entity> so : new ArrayList<SelectableObject<Entity>>(this.peopleLivedIn)){
|
|
215 if(so.isSelected()){
|
|
216 this.peopleLivedIn.remove(so);
|
|
217 }
|
|
218 }
|
107
|
219 } */
|
1
|
220
|
89
|
221 public void removeThisCountryAction(ActionEvent event) {
|
|
222 if (this.getCountryLo().entity != null) {
|
|
223 this.setCountryLo(new ListenerObject());
|
|
224 }
|
|
225 }
|
|
226
|
|
227
|
|
228
|
1
|
229 public String saveAsNewEntity(){
|
|
230 this.setSelectedSaveAsNew(true);
|
|
231 return save();
|
|
232 }
|
|
233 public List<SelectItem> getSuggestedTypes() {
|
|
234 return suggestedTypes;
|
|
235 }
|
|
236 public void setSuggestedTypes(List<SelectItem> suggestedTypes) {
|
|
237 this.suggestedTypes = suggestedTypes;
|
|
238 }
|
|
239
|
|
240 public List<SelectableObject<Entity>> getPlacesPartOfThis() {
|
|
241 return placesPartOfThis;
|
|
242 }
|
|
243
|
|
244 public void setPlacesPartOfThis(List<SelectableObject<Entity>> placesPartOfThis) {
|
|
245 this.placesPartOfThis = placesPartOfThis;
|
|
246 }
|
|
247
|
107
|
248 /* public List<SelectableObject<Entity>> getPeopleLivedIn() {
|
1
|
249 return peopleLivedIn;
|
|
250 }
|
|
251
|
|
252 public void setPeopleLivedIn(List<SelectableObject<Entity>> peopleLivedIn) {
|
|
253 this.peopleLivedIn = peopleLivedIn;
|
107
|
254 } */
|
|
255
|
|
256 /**
|
|
257 * @return the aliasList
|
|
258 */
|
|
259 public EntityList getAliasList() {
|
|
260 return aliasList;
|
|
261 }
|
|
262
|
|
263 /**
|
|
264 * @param aliasList the aliasList to set
|
|
265 */
|
|
266 public void setAliasList(EntityList aliasList) {
|
|
267 this.aliasList = aliasList;
|
|
268 }
|
1
|
269 }
|