Mercurial > hg > ismi-richfaces
annotate src/main/java/de/mpiwg/itgroup/ismi/browse/EntityDetailsBean.java @ 124:28a0c2726466
changed saveEntity() to use new EditIntent. Set up EditIntent for TEXT, PERSON, REFERENCE.
author | casties |
---|---|
date | Mon, 30 Jan 2017 20:35:36 +0100 |
parents | 4aa8c425685d |
children | b40a84944716 |
rev | line source |
---|---|
1 | 1 package de.mpiwg.itgroup.ismi.browse; |
2 | |
3 import java.util.ArrayList; | |
4 import java.util.HashMap; | |
5 import java.util.List; | |
6 import java.util.Map; | |
7 | |
8 import javax.faces.event.ActionEvent; | |
9 | |
10 import org.apache.log4j.Logger; | |
11 import org.mpi.openmind.repository.bo.Attribute; | |
12 import org.mpi.openmind.repository.bo.Entity; | |
13 import org.mpi.openmind.repository.bo.Node; | |
14 import org.mpi.openmind.repository.bo.Relation; | |
15 | |
16 import de.mpiwg.itgroup.ismi.entry.beans.SessionBean; | |
17 import de.mpiwg.itgroup.ismi.event.beans.CopyEvent; | |
18 import de.mpiwg.itgroup.ismi.event.beans.StudyEvent; | |
19 import de.mpiwg.itgroup.ismi.event.beans.TransferEvent; | |
20 | |
99 | 21 public class EntityDetailsBean extends AbstractBrowse { |
1 | 22 |
23 private static final long serialVersionUID = 1374652791403248103L; | |
24 | |
25 private static Logger logger = Logger.getLogger(EntityDetailsBean.class); | |
26 | |
27 private Entity entity; | |
28 private String currentEntityId; | |
29 | |
30 private List<Attribute> attributeList = new ArrayList<Attribute>(); | |
31 private List<String> sourceRelationNames = new ArrayList<String>(); | |
32 private List<String> targetRelationNames = new ArrayList<String>(); | |
33 | |
34 private Map<String, Long> sourceRelationCount = new HashMap<String, Long>(); | |
35 private Map<String, Long> targetRelationCount = new HashMap<String, Long>(); | |
36 | |
37 private Map<String, List<Relation>> sourceRelations = new HashMap<String, List<Relation>>(); | |
38 private Map<String, List<Relation>> targetRelations = new HashMap<String, List<Relation>>(); | |
39 | |
40 private List<Entity> previousVersionsList = new ArrayList<Entity>(); | |
41 private Entity selectedPreviousVersion = null; | |
42 private boolean previousVersionDetailsVisible = false; | |
43 | |
44 | |
45 public EntityDetailsBean() { | |
46 } | |
47 | |
48 public void listenerHideDetailsPopup(ActionEvent event){ | |
49 setPreviousVersionDetailsVisible(false); | |
50 } | |
51 | |
52 public void listenerHidePreviousVersions(ActionEvent event){ | |
53 setPreviousVersionsList(new ArrayList<Entity>()); | |
54 setSelectedPreviousVersion(null); | |
55 } | |
56 | |
57 public void listenerUndoUntilThisVersion(ActionEvent event) throws Exception{ | |
58 this.selectedPreviousVersion = (Entity)getRequestBean("previousVersion"); | |
59 if(this.selectedPreviousVersion != null){ | |
60 | |
61 //checking whether the relation reference to existing entities, | |
62 //If the entity referenced does not exist more, the relation will not be considered. | |
63 | |
64 //Checking source's relation | |
65 List<Relation> relToDelete = new ArrayList<Relation>(); | |
66 for(Relation rel : selectedPreviousVersion.getSourceRelations()){ | |
67 if(getWrapper().getEntityById(rel.getTargetId()) == null){ | |
68 relToDelete.add(rel); | |
69 } | |
70 } | |
71 for(Relation rel : relToDelete){ | |
72 selectedPreviousVersion.getSourceRelations().remove(rel); | |
73 } | |
74 | |
75 //Checking target's relations | |
76 relToDelete = new ArrayList<Relation>(); | |
77 for(Relation rel : selectedPreviousVersion.getTargetRelations()){ | |
78 if(getWrapper().getEntityById(rel.getSourceId()) == null){ | |
79 relToDelete.add(rel); | |
80 } | |
81 } | |
82 for(Relation rel : relToDelete){ | |
83 selectedPreviousVersion.getTargetRelations().remove(rel); | |
84 } | |
85 | |
86 selectedPreviousVersion.setVersion(this.entity.getVersion()); | |
87 selectedPreviousVersion.setSystemStatus(Node.SYS_STATUS_CURRENT_VERSION); | |
88 | |
124
28a0c2726466
changed saveEntity() to use new EditIntent. Set up EditIntent for TEXT, PERSON, REFERENCE.
casties
parents:
119
diff
changeset
|
89 getWrapper().saveEntity(selectedPreviousVersion, getUserName(), null); |
1 | 90 |
91 } | |
92 } | |
93 | |
94 | |
95 | |
96 public void listenerGetPreviousVersions(ActionEvent event){ | |
97 this.previousVersionsList = getWrapper().getPreviousEntitiesById(getEntity().getId()); | |
98 if(previousVersionsList.size() == 0){ | |
99 addGeneralMsg("It had not been found previous versions for this entity."); | |
100 } | |
101 } | |
102 | |
103 public void listenerShowPreviousVersionDetails(ActionEvent event){ | |
104 this.selectedPreviousVersion = (Entity)getRequestBean("previousVersion"); | |
105 setPreviousVersionDetailsVisible(true); | |
119 | 106 //System.out.println(this.selectedPreviousVersion); |
1 | 107 } |
108 | |
109 | |
110 | |
111 public void listenerShowEntity(ActionEvent event) { | |
112 try { | |
113 Long.parseLong(currentEntityId); | |
114 redirect("/browse/entityDetails.xhtml", "?eid=" + currentEntityId); | |
115 | |
116 } catch (Exception e) { | |
117 addErrorMsg("ID is not valid: " + this.currentEntityId); | |
118 } | |
119 } | |
120 | |
121 public void setEntity(Entity entity) { | |
122 this.entity = entity; | |
123 if(entity != null){ | |
124 | |
125 this.currentEntityId = entity.getId().toString(); | |
126 | |
127 this.selectedPreviousVersion = null; | |
128 this.previousVersionsList = new ArrayList<Entity>(); | |
129 //this.definition = getWrapper().getDefinition(entity.getObjectClass()); | |
130 this.attributeList = getWrapper().getAttributeByEntId(entity.getId()); | |
131 this.sourceRelations = new HashMap<String, List<Relation>>(); | |
132 this.targetRelations = new HashMap<String, List<Relation>>(); | |
133 this.sourceRelationNames = new ArrayList<String>(); | |
134 this.targetRelationNames = new ArrayList<String>(); | |
135 this.sourceRelationCount = new HashMap<String, Long>(); | |
136 this.targetRelationCount = new HashMap<String, Long>(); | |
137 | |
138 | |
119 | 139 //System.out.println("****************"); |
1 | 140 List<Relation> srcRels = getWrapper().getDefSourceRelations(this.entity.getObjectClass()); |
141 for(Relation rel : srcRels){ | |
142 if(rel.getOwnValue().equals("has_autor_misattribution")){ | |
119 | 143 logger.debug("misattribution: src - " + rel.getOwnValue()); |
1 | 144 } |
145 if(!this.sourceRelationNames.contains(rel.getOwnValue())){ | |
146 this.sourceRelationNames.add(rel.getOwnValue()); | |
147 this.sourceRelationCount.put(rel.getOwnValue(), getWrapper().getSourceRelationsCount(entity, rel.getOwnValue(), null)); | |
148 } | |
149 } | |
150 List<Relation> tarRels = getWrapper().getDefTargetRelations(this.entity.getObjectClass()); | |
151 for(Relation rel : tarRels){ | |
152 if(!this.targetRelationNames.contains(rel.getOwnValue())){ | |
153 this.targetRelationNames.add(rel.getOwnValue()); | |
154 this.targetRelationCount.put(rel.getOwnValue(), getWrapper().getTargetRelationsCount(entity, rel.getOwnValue(), null)); | |
155 } | |
156 | |
157 } | |
158 } | |
159 } | |
160 | |
161 public void listenerShowTargetRelations(ActionEvent event){ | |
162 String tarName = (String) getRequestBean("tarName"); | |
163 this.targetRelations.put(tarName, getWrapper().getTargetRelations(this.entity, tarName, null, -1)); | |
164 } | |
165 | |
102
db3e1bbfde03
fix error when EntityRepositoryBean is not available when deleting an entity.
casties
parents:
99
diff
changeset
|
166 /** |
db3e1bbfde03
fix error when EntityRepositoryBean is not available when deleting an entity.
casties
parents:
99
diff
changeset
|
167 * Handler that deletes the current Entity. |
db3e1bbfde03
fix error when EntityRepositoryBean is not available when deleting an entity.
casties
parents:
99
diff
changeset
|
168 * @return |
db3e1bbfde03
fix error when EntityRepositoryBean is not available when deleting an entity.
casties
parents:
99
diff
changeset
|
169 */ |
1 | 170 public String listenerDeleteEntity(){ |
171 try { | |
102
db3e1bbfde03
fix error when EntityRepositoryBean is not available when deleting an entity.
casties
parents:
99
diff
changeset
|
172 // get user name from SessionBean |
db3e1bbfde03
fix error when EntityRepositoryBean is not available when deleting an entity.
casties
parents:
99
diff
changeset
|
173 SessionBean session = (SessionBean) getSessionBean("Session"); |
db3e1bbfde03
fix error when EntityRepositoryBean is not available when deleting an entity.
casties
parents:
99
diff
changeset
|
174 String user = ""; |
db3e1bbfde03
fix error when EntityRepositoryBean is not available when deleting an entity.
casties
parents:
99
diff
changeset
|
175 if (session != null) { |
db3e1bbfde03
fix error when EntityRepositoryBean is not available when deleting an entity.
casties
parents:
99
diff
changeset
|
176 user = session.getUsername(); |
db3e1bbfde03
fix error when EntityRepositoryBean is not available when deleting an entity.
casties
parents:
99
diff
changeset
|
177 } |
db3e1bbfde03
fix error when EntityRepositoryBean is not available when deleting an entity.
casties
parents:
99
diff
changeset
|
178 |
99 | 179 // delete entity |
180 getWrapper().removeCurrentVersionEntity(this.entity, user); | |
102
db3e1bbfde03
fix error when EntityRepositoryBean is not available when deleting an entity.
casties
parents:
99
diff
changeset
|
181 |
db3e1bbfde03
fix error when EntityRepositoryBean is not available when deleting an entity.
casties
parents:
99
diff
changeset
|
182 // reset EntityRepositoryBean |
db3e1bbfde03
fix error when EntityRepositoryBean is not available when deleting an entity.
casties
parents:
99
diff
changeset
|
183 EntityRepositoryBean bean = (EntityRepositoryBean) getSessionBean("EntityRepository"); |
1 | 184 if(bean != null){ |
185 bean.reset(); | |
186 } | |
187 addGeneralMsg("The entity has been removed."); | |
102
db3e1bbfde03
fix error when EntityRepositoryBean is not available when deleting an entity.
casties
parents:
99
diff
changeset
|
188 |
1 | 189 } catch (Exception e) { |
190 printInternalError(e); | |
191 logger.error(e.getMessage() + " Removing" + entity, e); | |
192 } | |
193 | |
194 return GOTO_ENTITY_REPOSITORY; | |
195 } | |
196 | |
197 public void listenerShowSourceRelations(ActionEvent event){ | |
198 try { | |
199 String srcName = (String) getRequestBean("srcName"); | |
200 this.sourceRelations.put(srcName, getWrapper().getSourceRelations(this.entity, srcName, null, -1)); | |
201 } catch (Exception e) { | |
202 printInternalError(e); | |
203 logger.error(e.getMessage(), e); | |
204 } | |
205 } | |
206 public Entity getEntity() { | |
207 return entity; | |
208 } | |
209 | |
210 | |
211 | |
212 /** | |
213 * This method calls the SessionBean and put in it the current entity to be | |
214 * modified. | |
215 * | |
216 * @return | |
217 */ | |
218 public String actionEdit() { | |
219 try { | |
220 // getting de.mpiwg.itgroup.ismi.entry.beans.SessionBean | |
221 getSessionBean().editEntity(this.entity); | |
222 | |
223 } catch (Exception e) { | |
224 e.printStackTrace(); | |
225 } | |
226 if(entity.getObjectClass().equals(StudyEvent.OC) || | |
227 entity.getObjectClass().equals(CopyEvent.OC) || | |
228 entity.getObjectClass().equals(TransferEvent.OC)){ | |
229 return SessionBean.PAGE_EVENT_FORM; | |
230 }else{ | |
231 return SessionBean.PAGE_ENTRY; | |
232 } | |
233 } | |
234 | |
235 /** | |
236 * <p> | |
237 * Show the details page for the current entity. | |
238 * </p> | |
239 */ | |
240 public String showTarget() { | |
241 Relation relation = (Relation) getRequestBean("srcRelation"); | |
242 setEntity(relation.getTarget()); | |
243 return GOTO_ENTITY_DETAILS; | |
244 } | |
245 | |
246 public String showSource() { | |
247 Relation relation = (Relation) getRequestBean("tarRelation"); | |
248 setEntity(relation.getSource()); | |
249 return GOTO_ENTITY_DETAILS; | |
250 } | |
251 | |
252 public Entity getEntityById(Long id) { | |
253 //juc return getOntology().getEntityById(id); | |
254 return getWrapper().getEntityById(id); | |
255 } | |
256 | |
257 public String getCurrentEntityId() { | |
258 return currentEntityId; | |
259 } | |
260 | |
261 public void setCurrentEntityId(String cid) { | |
262 this.currentEntityId = cid; | |
263 } | |
264 | |
265 public List<Attribute> getAttributeList() { | |
266 return attributeList; | |
267 } | |
268 | |
269 public void setAttributeList(List<Attribute> attributeList) { | |
270 this.attributeList = attributeList; | |
271 } | |
272 public List<String> getSourceRelationNames() { | |
273 return sourceRelationNames; | |
274 } | |
275 | |
276 public void setSourceRelationNames(List<String> sourceRelationNames) { | |
277 this.sourceRelationNames = sourceRelationNames; | |
278 } | |
279 | |
280 public List<String> getTargetRelationNames() { | |
281 return targetRelationNames; | |
282 } | |
283 | |
284 public void setTargetRelationNames(List<String> targetRelationNames) { | |
285 this.targetRelationNames = targetRelationNames; | |
286 } | |
287 | |
288 public Map<String, Long> getSourceRelationCount() { | |
289 return sourceRelationCount; | |
290 } | |
291 | |
292 public void setSourceRelationCount(Map<String, Long> sourceRelationCount) { | |
293 this.sourceRelationCount = sourceRelationCount; | |
294 } | |
295 | |
296 public Map<String, Long> getTargetRelationCount() { | |
297 return targetRelationCount; | |
298 } | |
299 | |
300 public void setTargetRelationCount(Map<String, Long> targetRelationCount) { | |
301 this.targetRelationCount = targetRelationCount; | |
302 } | |
303 | |
304 public Map<String, List<Relation>> getSourceRelations() { | |
305 return sourceRelations; | |
306 } | |
307 | |
308 public void setSourceRelations(Map<String, List<Relation>> sourceRelations) { | |
309 this.sourceRelations = sourceRelations; | |
310 } | |
311 | |
312 public Map<String, List<Relation>> getTargetRelations() { | |
313 return targetRelations; | |
314 } | |
315 | |
316 public void setTargetRelations(Map<String, List<Relation>> targetRelations) { | |
317 this.targetRelations = targetRelations; | |
318 } | |
319 | |
320 public List<Entity> getPreviousVersionsList() { | |
321 return previousVersionsList; | |
322 } | |
323 | |
324 public void setPreviousVersionsList(List<Entity> previousVersionsList) { | |
325 this.previousVersionsList = previousVersionsList; | |
326 } | |
327 | |
328 public Entity getSelectedPreviousVersion() { | |
329 return selectedPreviousVersion; | |
330 } | |
331 | |
332 public void setSelectedPreviousVersion(Entity selectedPreviousVersion) { | |
333 this.selectedPreviousVersion = selectedPreviousVersion; | |
334 } | |
335 public boolean isPreviousVersionDetailsVisible() { | |
336 return previousVersionDetailsVisible; | |
337 } | |
338 | |
339 public void setPreviousVersionDetailsVisible( | |
340 boolean previousVersionDetailsVisible) { | |
341 this.previousVersionDetailsVisible = previousVersionDetailsVisible; | |
342 } | |
343 } |