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