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