annotate src/main/java/de/mpiwg/itgroup/ismi/util/guiComponents/Misidentification.java @ 120:71638720fe2f

working on MISIDENTIFICATION for witnesses.
author casties
date Fri, 06 Jan 2017 20:41:35 +0100
parents
children 6f0e9a333c15
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
120
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
1 package de.mpiwg.itgroup.ismi.util.guiComponents;
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
2
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
3 import java.io.Serializable;
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
4 import java.util.List;
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
5
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
6 import org.mpi.openmind.cache.WrapperService;
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
7 import org.mpi.openmind.repository.bo.Attribute;
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
8 import org.mpi.openmind.repository.bo.Entity;
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
9 import org.mpi.openmind.repository.bo.Node;
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
10 import org.mpi.openmind.repository.bo.Relation;
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
11
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
12 public class Misidentification implements Serializable {
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
13 private static final long serialVersionUID = -1840193000833171153L;
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
14
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
15 public static String TITLE = "title";
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
16 public static String TITLE_TRANSLIT = "title_translit";
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
17 public static String MISIDENT = "MISIDENTIFICATION";
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
18 public static String MISATTRIBUTED_TO = "misattributed_to";
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
19 public static String IS_REFERENCE_OF = "is_reference_of";
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
20 public static String HAS_MISIDENT = "has_misidentification";
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
21
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
22 private Entity misident;
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
23 private String title;
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
24 private String title_translit;
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
25 private Entity person;
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
26 private Reference ref;
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
27 private WrapperService ot;
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
28 private String userName;
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
29
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
30 public Misidentification(WrapperService ot, String userName) {
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
31 this.ot = ot;
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
32 this.userName = userName;
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
33 }
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
34
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
35 public Entity saveAndGetMisidentification(Entity witness) throws Exception {
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
36
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
37 // create misidentification if necessary
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
38 if (misident == null) {
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
39 misident = new Entity(Node.TYPE_ABOX, MISIDENT, false);
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
40 }
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
41
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
42 // set title
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
43 if (!misident.containsAttribute(TITLE)) {
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
44 misident.addAttribute(new Attribute(title, "text", title));
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
45 } else {
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
46 misident.getAttributeByName(TITLE).setOwnValue(title);
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
47 }
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
48 if (!misident.containsAttribute(TITLE_TRANSLIT)) {
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
49 misident.addAttribute(new Attribute(title, "text", title_translit));
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
50 } else {
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
51 misident.getAttributeByName(TITLE_TRANSLIT).setOwnValue(title_translit);
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
52 }
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
53
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
54 // save reference
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
55 Entity entityRef = this.ref.getEnt();
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
56 ot.saveEntity(entityRef, userName);
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
57
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
58 // set person relation to misidentification
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
59 this.misident.removeAllSourceRelations(MISATTRIBUTED_TO, "PERSON");
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
60 new Relation(misident, person, MISATTRIBUTED_TO);
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
61
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
62 // set reference relation to misidentification
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
63 this.misident.removeAllTargetRelations(IS_REFERENCE_OF, "REFERENCE");
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
64 new Relation(entityRef, misident, IS_REFERENCE_OF);
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
65
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
66 // set text relation to misidentification
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
67 this.misident.removeAllTargetRelations(HAS_MISIDENT, "WITNESS");
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
68 new Relation(witness, misident, HAS_MISIDENT);
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
69
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
70 // save misidentification
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
71 // FIXME: really save here?
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
72 ot.saveEntity(misident, userName);
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
73
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
74 return witness;
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
75 }
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
76
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
77 public static Misidentification create(String title, String title_translit, Entity person, WrapperService ot,
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
78 String userName) {
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
79 Misidentification obj = new Misidentification(ot, userName);
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
80 obj.setTitle(title);
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
81 obj.setTitle_translit(title_translit);
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
82 obj.setPerson(person);
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
83 obj.setRef(new Reference(null));
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
84
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
85 return obj;
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
86 }
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
87
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
88 public static Misidentification load(Entity misident, WrapperService ot, String userName) throws Exception {
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
89
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
90 Misidentification obj = new Misidentification(ot, userName);
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
91
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
92 if (misident.isLightweight()) {
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
93 obj.setMisident(ot.getEntityByIdWithContent(misident.getId()));
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
94 }
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
95
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
96 // load title
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
97 if (misident.containsAttribute(TITLE)) {
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
98 String t = misident.getAttributeByName(TITLE).getOwnValue();
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
99 obj.setTitle(t);
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
100 }
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
101 if (misident.containsAttribute(TITLE_TRANSLIT)) {
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
102 String tt = misident.getAttributeByName(TITLE_TRANSLIT).getOwnValue();
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
103 obj.setTitle_translit(tt);
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
104 }
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
105
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
106 // loading person. Person can be Light Weight
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
107 List<Entity> tmpList = ot.getTargetsForSourceRelation(misident, MISATTRIBUTED_TO, "PERSON", -1);
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
108 if (tmpList.size() > 1) {
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
109 throw new Exception(
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
110 "Misidentification (entity) can not have more than one person associated. " + misident.toString());
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
111 } else if (tmpList.size() == 1) {
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
112 obj.setPerson(tmpList.get(0));
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
113 }
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
114
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
115 // load references
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
116 tmpList = ot.getSourcesForTargetRelation(misident, IS_REFERENCE_OF, "REFERENCE", -1);
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
117 if (tmpList.size() > 0) {
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
118 Entity ref = tmpList.get(0);
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
119 if (ref.isLightweight()) {
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
120 ref = ot.getEntityByIdWithContent(ref.getId());
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
121 }
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
122 obj.setRef(new Reference(ref));
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
123 }
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
124
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
125 // this.person = person;
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
126 // this.ref = new Reference(ref);
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
127 return obj;
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
128 }
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
129
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
130 public Entity getPerson() {
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
131 return person;
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
132 }
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
133
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
134 public void setPerson(Entity person) {
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
135 this.person = person;
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
136 }
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
137
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
138 public Reference getRef() {
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
139 return ref;
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
140 }
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
141
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
142 public void setRef(Reference ref) {
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
143 this.ref = ref;
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
144 }
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
145
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
146 public Entity getMisident() {
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
147 return misident;
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
148 }
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
149
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
150 public void setMisident(Entity misident) {
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
151 this.misident = misident;
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
152 }
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
153
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
154 public String getTitle() {
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
155 return title;
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
156 }
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
157
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
158 public void setTitle(String title) {
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
159 this.title = title;
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
160 }
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
161
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
162 public String getTitle_translit() {
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
163 return title_translit;
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
164 }
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
165
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
166 public void setTitle_translit(String title_translit) {
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
167 this.title_translit = title_translit;
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
168 }
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
169
71638720fe2f working on MISIDENTIFICATION for witnesses.
casties
parents:
diff changeset
170 }