1
|
1 package de.mpiwg.itgroup.ismi.event.beans;
|
|
2
|
|
3 import java.io.Serializable;
|
|
4 import java.util.ArrayList;
|
|
5
|
|
6 import javax.faces.event.ActionEvent;
|
|
7 import javax.faces.event.ValueChangeEvent;
|
|
8 import javax.faces.model.SelectItem;
|
|
9
|
|
10 import org.mpi.openmind.repository.bo.Entity;
|
|
11 import org.mpi.openmind.repository.bo.Node;
|
|
12 import org.mpi.openmind.repository.bo.Relation;
|
|
13
|
|
14 import de.mpiwg.itgroup.ismi.auxObjects.ListenerObject;
|
|
15 import de.mpiwg.itgroup.ismi.auxObjects.lo.EventTextLO;
|
|
16 import de.mpiwg.itgroup.ismi.util.guiComponents.Calendar;
|
|
17
|
|
18 public class CopyEvent extends AbstractEvent implements Serializable{
|
|
19
|
|
20 /**
|
|
21 *
|
|
22 */
|
|
23 private static final long serialVersionUID = 1545705063133894571L;
|
|
24
|
|
25 public static String OC = "COPY_EVENT";
|
|
26
|
|
27 private ListenerObject personCopiedForLo = new ListenerObject(PERSON, name_translit);
|
|
28 private ListenerObject personCopyingTextLo = new ListenerObject(PERSON, name_translit);
|
|
29 private ListenerObject repositoryLo = new ListenerObject(REPOSITORY, name);
|
|
30
|
|
31 private Calendar date;
|
|
32
|
|
33 @Override
|
|
34 public void setEvent(Entity ev){
|
|
35 reset();
|
|
36 event = ev;
|
|
37 if(event != null && event.isPersistent()){
|
|
38 if(event.isLightweight()){
|
|
39 event = getWrapper().getEntityContent(event);
|
|
40 }
|
|
41
|
|
42 this.loadAttributes(this.event);
|
|
43 this.date = updateCalendar(this.event.getAttributeByName("date"));
|
|
44
|
|
45 for (Relation rel : event.getSourceRelations()) {
|
|
46 Entity target = null;
|
|
47 if (rel.getOwnValue().equals(was_copied_for)) {
|
95
|
48 //EVENT was_copied_for PERSON
|
1
|
49 target = getTargetRelation(rel);
|
|
50 personCopiedForLo.setEntityAndAttribute0(target);
|
|
51 }else if (rel.getOwnValue().equals(has_person_copying_text)) {
|
95
|
52 //EVENT has_person_copying_text PERSON
|
1
|
53 target = getTargetRelation(rel);
|
|
54 personCopyingTextLo.setEntityAndAttribute0(target);
|
|
55
|
|
56 } else if (rel.getOwnValue().equals(was_copied_in)) {
|
|
57 target = getTargetRelation(rel);
|
|
58 if(target.getObjectClass().equals(PLACE)){
|
95
|
59 //EVENT was_copied_in PLACE
|
1
|
60 placeLo.setEntityAndAttribute0(target);
|
|
61 }else if(target.getObjectClass().equals(REPOSITORY)){
|
95
|
62 //EVENT was_copied_in REPOSITORY
|
1
|
63 repositoryLo.setEntityAndAttribute0(target);
|
|
64 }
|
|
65 } else if (rel.getOwnValue().equals(is_a_copy_of)) {
|
95
|
66 //EVENT is_a_copy_of WITNESS
|
1
|
67 //WITNESS is_exemplar_of TEXT
|
|
68 this.witness = getTargetRelation(rel);
|
|
69 if(witness != null && witness.isPersistent()){
|
|
70 witnessId = witness.getId();
|
|
71 this.textLo.setEntityAndAttribute0( getTextOfWitness(witness));
|
|
72 refreshWitnesses(textLo.entity);
|
|
73 }
|
|
74 }
|
|
75 }
|
|
76 }
|
|
77 }
|
|
78
|
|
79 @Override
|
|
80 public void reset(){
|
|
81 super.reset();
|
|
82 this.defObjectClass = OC;
|
|
83
|
|
84 if(textLo != null){
|
|
85 textLo.reset();
|
|
86 }else{
|
|
87 textLo = new EventTextLO(TEXT, full_title_translit, this);
|
|
88 }
|
|
89
|
|
90 if(personCopiedForLo != null){
|
|
91 personCopiedForLo.reset();
|
|
92 }else{
|
|
93 personCopiedForLo = new ListenerObject(PERSON, name_translit);
|
|
94 }
|
|
95
|
|
96 if(personCopyingTextLo != null){
|
|
97 personCopyingTextLo.reset();
|
|
98 }else{
|
|
99 personCopyingTextLo = new ListenerObject(PERSON, name_translit);
|
|
100 }
|
|
101
|
|
102 if(placeLo != null){
|
|
103 placeLo.reset();
|
|
104 }else{
|
|
105 placeLo = new ListenerObject(PLACE, name);
|
|
106 }
|
|
107
|
|
108
|
|
109 if(repositoryLo != null){
|
|
110 repositoryLo.reset();
|
|
111 }else{
|
|
112 repositoryLo = new ListenerObject(REPOSITORY, name);
|
|
113 }
|
|
114
|
|
115
|
|
116
|
|
117 this.date = new Calendar();
|
|
118 this.witnessList = new ArrayList<SelectItem>();
|
|
119 }
|
|
120
|
|
121 /*
|
|
122 public void listenerChangePersonCopyingText(ValueChangeEvent event) {
|
|
123 this.personCopyingText = changeListener(event, personCopyingText, PERSON, name_translit);
|
|
124 }
|
|
125
|
|
126 public void listenerChangePersonCopiedFor(ValueChangeEvent event) {
|
|
127 this.personCopiedFor = changeListener(event, personCopiedFor, PERSON, name_translit);
|
|
128 }
|
|
129
|
|
130 public void listenerChangePlace(ValueChangeEvent event) {
|
|
131 this.place = changeListener(event, place, PLACE, name);
|
|
132 }
|
|
133
|
|
134 public void listenerChangeRepository(ValueChangeEvent event) {
|
|
135 this.repository = changeListener(event, repository, REPOSITORY, name);
|
|
136 }*/
|
|
137
|
|
138 public void listenerSave(ActionEvent event) {
|
|
139 this.save();
|
|
140 }
|
|
141
|
|
142 @Override
|
|
143 public String save(){
|
|
144 super.save();
|
|
145 if(!checkConsistency()){
|
|
146 addGeneralMsg("Either the Witness, the Person or the Place is empty.");
|
|
147 addGeneralMsg("The event could not be saved.");
|
|
148 return null;
|
|
149 }
|
|
150
|
|
151 try{
|
|
152 getAttributes().put("date", this.date.toJSONString());
|
|
153 event = updateEntityAttributes(event);
|
|
154
|
|
155 // EVENT -> was_copied_for -> PERSON
|
|
156 event.replaceSourceRelation(personCopiedForLo.entity, PERSON, was_copied_for);
|
|
157
|
|
158 // EVENT -> has_person_copying_text -> PERSON
|
|
159 event.replaceSourceRelation(personCopyingTextLo.entity, PERSON, has_person_copying_text);
|
|
160
|
|
161 // EVENT -> was_copied_in -> REPOSITORY
|
|
162 event.replaceSourceRelation(repositoryLo.entity, REPOSITORY, was_copied_in);
|
|
163
|
|
164 // EVENT -> was_copied_in -> PLACE
|
|
165 event.replaceSourceRelation(placeLo.entity, PLACE, was_copied_in);
|
|
166
|
|
167 // EVENT -> is_a_copy_of -> WITNESS
|
|
168 if(witness.isLightweight()){
|
|
169 this.witness = getWrapper().getEntityByIdWithContent(witness.getId());
|
|
170 }
|
|
171 event.replaceSourceRelation(witness, WITNESS, is_a_copy_of);
|
|
172
|
|
173 getWrapper().saveEntity(event, getSessionUserName());
|
|
174
|
|
175 printSuccessSavingEntity();
|
|
176
|
|
177 }catch (Exception e) {
|
|
178 addGeneralMsg(e.getMessage());
|
|
179 logger.error(e.getMessage(), e);
|
|
180 }
|
|
181 saveEnd();
|
|
182 return null;
|
|
183 }
|
|
184
|
|
185 public boolean checkConsistency(){
|
|
186 if(this.witness == null ||
|
|
187 this.textLo.entity == null ||
|
|
188 this.repositoryLo.entity == null ||
|
|
189 this.personCopiedForLo.entity == null ||
|
|
190 this.personCopyingTextLo.entity == null){
|
|
191 return false;
|
|
192 }
|
|
193 return true;
|
|
194 }
|
|
195
|
|
196 public CopyEvent(Entity event) {
|
|
197 super(event);
|
|
198 }
|
|
199
|
|
200 public CopyEvent(){
|
|
201 super(new Entity(Node.TYPE_ABOX, OC, false));
|
|
202 }
|
|
203
|
|
204 public ListenerObject getPersonCopiedForLo() {
|
|
205 return personCopiedForLo;
|
|
206 }
|
|
207
|
|
208 public void setPersonCopiedForLo(ListenerObject personCopiedForLo) {
|
|
209 this.personCopiedForLo = personCopiedForLo;
|
|
210 }
|
|
211
|
|
212 public ListenerObject getPersonCopyingTextLo() {
|
|
213 return personCopyingTextLo;
|
|
214 }
|
|
215
|
|
216 public void setPersonCopyingTextLo(ListenerObject personCopyingTextLo) {
|
|
217 this.personCopyingTextLo = personCopyingTextLo;
|
|
218 }
|
|
219
|
|
220 public ListenerObject getRepositoryLo() {
|
|
221 return repositoryLo;
|
|
222 }
|
|
223
|
|
224 public void setRepositoryLo(ListenerObject repositoryLo) {
|
|
225 this.repositoryLo = repositoryLo;
|
|
226 }
|
|
227
|
|
228 public Calendar getDate() {
|
|
229 return date;
|
|
230 }
|
|
231
|
|
232 public void setDate(Calendar date) {
|
|
233 this.date = date;
|
|
234 }
|
|
235 }
|