comparison src/main/java/de/mpiwg/itgroup/ismi/entry/beans/CurrentRepositoryBean.java @ 1:2e911857a759

(none)
author jurzua
date Wed, 29 Oct 2014 14:00:28 +0000
parents
children d172201d24ad
comparison
equal deleted inserted replaced
0:74df02964906 1:2e911857a759
1 package de.mpiwg.itgroup.ismi.entry.beans;
2
3 import java.io.Serializable;
4
5 import org.apache.commons.lang.StringUtils;
6 import org.apache.log4j.Logger;
7 import org.mpi.openmind.repository.bo.Attribute;
8 import org.mpi.openmind.repository.bo.Entity;
9 import org.mpi.openmind.repository.bo.Node;
10
11 public class CurrentRepositoryBean extends CodexEditorTemplate implements Serializable{
12 private static final long serialVersionUID = 2926289436446091260L;
13
14 private static Logger logger = Logger.getLogger(CurrentRepositoryBean.class);
15
16 public static int MAX_PLACES = 100;
17 //private Entity repository;
18
19 @Override
20 public void reset(){
21 super.reset();
22 this.entity = new Entity(Node.TYPE_ABOX, REPOSITORY, false);
23 }
24
25 public CurrentRepositoryBean(){
26 this.reset();
27 setDefObjectClass(REPOSITORY);
28 registerChecker(getCityLo().statusImage, "City not valid!");
29 registerChecker(getCountryLo().statusImage, "Country is not valid!");
30 }
31
32
33 @Override
34 public void setEntity(Entity repository) {
35 this.reset();
36 this.entity = repository;
37
38 if(this.entity != null && this.entity.isPersistent()){
39 if(this.entity.isLightweight()){
40 this.entity = getWrapper().getEntityContent(this.entity);
41 }
42
43 this.setCurrentId(this.entity.getId().toString());
44 this.loadAttributes(this.entity);//, getDefinition(this.entity));
45
46 //this.loadReferences(this.entity);
47 this.loadEndNoteRefs();
48
49 for(Entity city : getWrapper().getTargetsForSourceRelation(this.entity, "is_in", PLACE, 1)){
50 this.setCity(city);
51 }
52 }
53 }
54
55 public String saveAsNewEntity(){
56 this.setSelectedSaveAsNew(true);
57 return save();
58 }
59
60
61 @Override
62 public String save(){
63 super.save();
64 try {
65 CheckResults cr = getCheckResults();
66 if (cr.hasErrors){
67 getSessionBean().setErrorMessages(cr);
68 getSessionBean().setDisplayError(true);
69 this.setSelectedSaveAsNew(false);
70 return PAGE_EDITOR;
71 }
72
73 this.entity = this.updateEntityAttributes(this.entity);
74
75
76 Attribute attName = this.entity.getAttributeByName("name");
77 String repositoryName = (attName == null) ? null : attName.getValue();
78 if(StringUtils.isNotEmpty(repositoryName)){
79 if(!checkUnityRepository(repositoryName, (isSelectedSaveAsNew()) ? null : this.entity.getId(), this.getCityLo().entity)){
80 this.renderUnityCheckerDialog();
81 this.setSelectedSaveAsNew(false);
82 return PAGE_EDITOR;
83 }
84 }else{
85 this.addErrorMsg("Ths entity has not been saved, because its name was empty.");
86 this.addErrorMsg("You must enter a name.");
87 return PAGE_EDITOR;
88 }
89
90 if(!isRepositoryConsistentBeforeSave()){
91 return PAGE_EDITOR;
92 }
93
94 this.entity.replaceSourceRelation(this.getCityLo().getEntity(), PLACE, is_in);
95
96 //REFERENCE -> is_reference_of -> THIS
97 //this.entity = this.prepareReferencesToSave(this.entity);
98 this.prepareEndNoteRefs2Save();
99
100 if(isSelectedSaveAsNew()){
101 this.entity.removeAllTargetRelations(is_part_of, COLLECTION);
102 this.entity = getWrapper().saveEntityAsNew(this.entity, getSessionUser().getEmail());
103 }else{
104 this.entity = getWrapper().saveEntity(this.entity, getSessionUser().getEmail());
105 }
106
107 this.generateSecundaryOW(this.entity, getSessionUser().getEmail());
108 getSessionBean().setEditFormCurrentEntId(this.entity.getId());
109
110 logger.info("Entity saved - Time = " + (System.currentTimeMillis() - start) + ", " + entity);
111 this.printSuccessSavingEntity();
112
113 this.setSelectedSaveAsNew(false);
114 } catch (Exception e) {
115 logger.error(e.getMessage(), e);
116 e.printStackTrace();
117 this.printInternalError(e);
118 }
119 saveEnd();
120 return PAGE_EDITOR;
121 }
122 }