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