comparison src/main/java/de/mpiwg/itgroup/ismi/browse/EntityDetailsBean.java @ 1:2e911857a759

(none)
author jurzua
date Wed, 29 Oct 2014 14:00:28 +0000
parents
children d0fb989bf53a
comparison
equal deleted inserted replaced
0:74df02964906 1:2e911857a759
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
21 public class EntityDetailsBean extends AbstractBrowse{
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
89 getWrapper().saveEntity(selectedPreviousVersion, getUserName());
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);
106 System.out.println(this.selectedPreviousVersion);
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
139 System.out.println("****************");
140 List<Relation> srcRels = getWrapper().getDefSourceRelations(this.entity.getObjectClass());
141 for(Relation rel : srcRels){
142 if(rel.getOwnValue().equals("has_autor_misattribution")){
143 System.out.println("src - " + rel.getOwnValue());
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
166 public String listenerDeleteEntity(){
167 try {
168 getWrapper().removeCurrentVersionEntity(this.entity);
169 EntityRepositoryBean bean = (EntityRepositoryBean)getSessionBean("EntityRepository");
170 if(bean != null){
171 bean.reset();
172 }
173 addGeneralMsg("The entity has been removed.");
174 } catch (Exception e) {
175 printInternalError(e);
176 logger.error(e.getMessage() + " Removing" + entity, e);
177 e.printStackTrace();
178 }
179
180 return GOTO_ENTITY_REPOSITORY;
181 }
182
183 public void listenerShowSourceRelations(ActionEvent event){
184 try {
185 String srcName = (String) getRequestBean("srcName");
186 this.sourceRelations.put(srcName, getWrapper().getSourceRelations(this.entity, srcName, null, -1));
187 } catch (Exception e) {
188 printInternalError(e);
189 logger.error(e.getMessage(), e);
190 }
191 }
192 public Entity getEntity() {
193 return entity;
194 }
195
196
197
198 /**
199 * This method calls the SessionBean and put in it the current entity to be
200 * modified.
201 *
202 * @return
203 */
204 public String actionEdit() {
205 try {
206 // getting de.mpiwg.itgroup.ismi.entry.beans.SessionBean
207 getSessionBean().editEntity(this.entity);
208
209 } catch (Exception e) {
210 e.printStackTrace();
211 }
212 if(entity.getObjectClass().equals(StudyEvent.OC) ||
213 entity.getObjectClass().equals(CopyEvent.OC) ||
214 entity.getObjectClass().equals(TransferEvent.OC)){
215 return SessionBean.PAGE_EVENT_FORM;
216 }else{
217 return SessionBean.PAGE_ENTRY;
218 }
219 }
220
221 /**
222 * <p>
223 * Show the details page for the current entity.
224 * </p>
225 */
226 public String showTarget() {
227 Relation relation = (Relation) getRequestBean("srcRelation");
228 setEntity(relation.getTarget());
229 return GOTO_ENTITY_DETAILS;
230 }
231
232 public String showSource() {
233 Relation relation = (Relation) getRequestBean("tarRelation");
234 setEntity(relation.getSource());
235 return GOTO_ENTITY_DETAILS;
236 }
237
238 public Entity getEntityById(Long id) {
239 //juc return getOntology().getEntityById(id);
240 return getWrapper().getEntityById(id);
241 }
242
243 public String getCurrentEntityId() {
244 return currentEntityId;
245 }
246
247 public void setCurrentEntityId(String cid) {
248 this.currentEntityId = cid;
249 }
250
251 public List<Attribute> getAttributeList() {
252 return attributeList;
253 }
254
255 public void setAttributeList(List<Attribute> attributeList) {
256 this.attributeList = attributeList;
257 }
258 public List<String> getSourceRelationNames() {
259 return sourceRelationNames;
260 }
261
262 public void setSourceRelationNames(List<String> sourceRelationNames) {
263 this.sourceRelationNames = sourceRelationNames;
264 }
265
266 public List<String> getTargetRelationNames() {
267 return targetRelationNames;
268 }
269
270 public void setTargetRelationNames(List<String> targetRelationNames) {
271 this.targetRelationNames = targetRelationNames;
272 }
273
274 public Map<String, Long> getSourceRelationCount() {
275 return sourceRelationCount;
276 }
277
278 public void setSourceRelationCount(Map<String, Long> sourceRelationCount) {
279 this.sourceRelationCount = sourceRelationCount;
280 }
281
282 public Map<String, Long> getTargetRelationCount() {
283 return targetRelationCount;
284 }
285
286 public void setTargetRelationCount(Map<String, Long> targetRelationCount) {
287 this.targetRelationCount = targetRelationCount;
288 }
289
290 public Map<String, List<Relation>> getSourceRelations() {
291 return sourceRelations;
292 }
293
294 public void setSourceRelations(Map<String, List<Relation>> sourceRelations) {
295 this.sourceRelations = sourceRelations;
296 }
297
298 public Map<String, List<Relation>> getTargetRelations() {
299 return targetRelations;
300 }
301
302 public void setTargetRelations(Map<String, List<Relation>> targetRelations) {
303 this.targetRelations = targetRelations;
304 }
305
306 public List<Entity> getPreviousVersionsList() {
307 return previousVersionsList;
308 }
309
310 public void setPreviousVersionsList(List<Entity> previousVersionsList) {
311 this.previousVersionsList = previousVersionsList;
312 }
313
314 public Entity getSelectedPreviousVersion() {
315 return selectedPreviousVersion;
316 }
317
318 public void setSelectedPreviousVersion(Entity selectedPreviousVersion) {
319 this.selectedPreviousVersion = selectedPreviousVersion;
320 }
321 public boolean isPreviousVersionDetailsVisible() {
322 return previousVersionDetailsVisible;
323 }
324
325 public void setPreviousVersionDetailsVisible(
326 boolean previousVersionDetailsVisible) {
327 this.previousVersionDetailsVisible = previousVersionDetailsVisible;
328 }
329 }