Mercurial > hg > ismi-richfaces
comparison src/main/java/de/mpiwg/itgroup/ismi/entry/beans/CurrentWitnessBean.java @ 134:25bfcc9d757c
effort to re-use more relations when saving entities.
new replaceMultipleSourceRelations() and changes to use it.
changes for renamed replaceUniqueSourceRelation().
author | casties |
---|---|
date | Fri, 24 Feb 2017 20:25:33 +0100 |
parents | 5ccd6e709f95 |
children | 502ae5b1a07d |
comparison
equal
deleted
inserted
replaced
133:5ccd6e709f95 | 134:25bfcc9d757c |
---|---|
222 getAttributes().put("creation_date", this.copyDate.toJSONString()); | 222 getAttributes().put("creation_date", this.copyDate.toJSONString()); |
223 | 223 |
224 this.entity = this.updateEntityAttributes(this.entity); | 224 this.entity = this.updateEntityAttributes(this.entity); |
225 | 225 |
226 // WITNESS -> is_part_of -> CODEX | 226 // WITNESS -> is_part_of -> CODEX |
227 this.entity.replaceSourceRelation(getCodexLo().entity, CODEX, is_part_of); | 227 this.entity.replaceUniqueSourceRelation(getCodexLo().entity, CODEX, is_part_of); |
228 | 228 |
229 // WITNESS -> is_exemplar_of -> TEXT -> was_created_by -> PERSON | 229 // WITNESS -> is_exemplar_of -> TEXT -> was_created_by -> PERSON |
230 //replaceSourceRelation(this.entity, this.author, PERSON, was_created_by); | 230 //replaceSourceRelation(this.entity, this.author, PERSON, was_created_by); |
231 | 231 |
232 // WITENSS -> was_copied_by -> PERSON | 232 // WITENSS -> was_copied_by -> PERSON |
233 this.entity.replaceSourceRelation(this.copyistLo.entity, PERSON, rel_was_copied_by); | 233 this.entity.replaceUniqueSourceRelation(this.copyistLo.entity, PERSON, rel_was_copied_by); |
234 | 234 |
235 // WITNESS -> was_copied_in -> PLACE | 235 // WITNESS -> was_copied_in -> PLACE |
236 replaceAliasSourceRelation(this.entity, this.copyPlaceLo, PLACE, "was_copied_in", "was_copied_in_as"); | 236 replaceUniqueAliasSourceRelation(this.entity, this.copyPlaceLo, PLACE, rel_was_copied_in, rel_was_copied_in_as); |
237 | 237 |
238 //REFERENCE -> is_reference_of -> WITNESS | 238 //REFERENCE -> is_reference_of -> WITNESS |
239 //this.entity = this.prepareReferencesToSave(this.entity); | |
240 this.prepareEndNoteRefs2Save(); | 239 this.prepareEndNoteRefs2Save(); |
241 | 240 |
242 //WITNESS -> was studied by manyToMany -> PERSON | 241 //WITNESS -> was studied by manyToMany -> PERSON |
243 this.entity.removeAllSourceRelationsByName(rel_was_studied_by); | 242 replaceMultipleSourceRelations(entity, studiedByList.getEntities(), PERSON, rel_was_studied_by); |
244 for(Entity target : this.studiedByList.getEntities()){ | |
245 Entity target0 = getWrapper().getEntityByIdWithContent(target.getId()); | |
246 new Relation(this.entity, target0, rel_was_studied_by); | |
247 } | |
248 | 243 |
249 // WITNESS -> had_patron -> PERSON | 244 // WITNESS -> had_patron -> PERSON |
250 this.entity.replaceSourceRelation(this.patronageLo.entity, PERSON, rel_had_patron); | 245 this.entity.replaceUniqueSourceRelation(this.patronageLo.entity, PERSON, rel_had_patron); |
251 | 246 |
252 | 247 |
253 /* | 248 /* |
254 * save misidentifications | 249 * save misidentifications |
255 */ | 250 */ |
256 this.entity = this.misidentTable.saveMisidentifications(this.entity); | 251 this.entity = this.misidentTable.saveMisidentifications(this.entity); |
257 | 252 |
258 // WITNESS -> is_exemplar_of -> TEXT | 253 // WITNESS -> is_exemplar_of -> TEXT |
259 this.entity.replaceSourceRelation(this.titleLo.entity, TEXT, is_exemplar_of); | 254 this.entity.replaceUniqueSourceRelation(this.titleLo.entity, TEXT, is_exemplar_of); |
255 | |
260 // legacy relations(?) | 256 // legacy relations(?) |
261 this.entity.removeAllSourceRelationsByName(is_possible_exemplar_of); | 257 this.entity.removeAllSourceRelationsByName(is_possible_exemplar_of); |
262 this.entity.removeAllSourceRelations(rel_has_title_written_as, ALIAS); | 258 this.entity.removeAllSourceRelations(rel_has_title_written_as, ALIAS); |
263 this.entity.removeAllSourceRelations(rel_has_author_written_as, ALIAS); | 259 this.entity.removeAllSourceRelations(rel_has_author_written_as, ALIAS); |
264 | 260 |
265 if(textUnknown){ | |
266 for(Entity target : this.possibleExamplerOfList.getEntities()){ | |
267 Entity target0 = getWrapper().getEntityByIdWithContent(target.getId()); | |
268 new Relation(this.entity, target0, is_possible_exemplar_of); | |
269 } | |
270 }else{ | |
271 this.saveIndirectedAliases(); | |
272 } | |
273 | |
274 // WITNESS -> is_part_of_codex | 261 // WITNESS -> is_part_of_codex |
275 if(this.isSelectedSaveAsNew()){ | 262 if(this.isSelectedSaveAsNew()){ |
276 //this.entity = getWrapper().saveEntityAsNew(this.entity, user.getEmail()); | 263 //this.entity = getWrapper().saveEntityAsNew(this.entity, user.getEmail()); |
277 }else{ | 264 }else{ |
265 // save this entity | |
278 this.entity = getWrapper().saveEntity(this.entity, user.getEmail(), editWitnessIntent); | 266 this.entity = getWrapper().saveEntity(this.entity, user.getEmail(), editWitnessIntent); |
279 } | 267 } |
268 // re-set form | |
280 this.setEntity(this.entity); | 269 this.setEntity(this.entity); |
281 | 270 |
282 logger.info("Entity saved - Time = " + (System.currentTimeMillis() - start) + ", " + entity); | 271 logger.info("Entity saved - Time = " + (System.currentTimeMillis() - start) + ", " + entity); |
283 this.printSuccessSavingEntity(); | 272 this.printSuccessSavingEntity(); |
284 | 273 |
290 | 279 |
291 saveEnd(); | 280 saveEnd(); |
292 return PAGE_EDITOR; | 281 return PAGE_EDITOR; |
293 } | 282 } |
294 | 283 |
295 private void saveIndirectedAliases() throws Exception{ | |
296 | |
297 User user = getSessionUser(); | |
298 | |
299 //WITNESS -> has_title_written_as -> ALIAS | |
300 if(StringUtils.isNotEmpty(valueTextWritten)){ | |
301 Entity alias = null; | |
302 if(this.suggestedTitlesWritten != null){ | |
303 for(SelectItem item : this.suggestedTitlesWritten){ | |
304 Long id = (Long)item.getValue(); | |
305 if(id != null){ | |
306 Entity candidate = getWrapper().getEntityById(id); | |
307 if(candidate != null && valueTextWritten.equals(candidate.getOwnValue())){ | |
308 alias = candidate; | |
309 break; | |
310 } | |
311 } | |
312 } | |
313 } | |
314 | |
315 if(alias == null){ | |
316 alias = new Entity(Node.TYPE_ABOX, ALIAS, false); | |
317 alias.addAttribute(new Attribute(ALIAS, "text", valueTextWritten)); | |
318 alias = getWrapper().saveEntity(alias, user.getEmail(), null); | |
319 new Relation(alias, this.titleLo.getEntity(), "is_alias_title_of"); | |
320 alias = getWrapper().saveEntity(alias, user.getEmail(), null); | |
321 } | |
322 if(alias.isLightweight()){ | |
323 alias = getWrapper().getEntityByIdWithContent(alias.getId()); | |
324 } | |
325 this.entity.replaceSourceRelation(alias, ALIAS, rel_has_title_written_as); | |
326 } | |
327 | |
328 | |
329 if(StringUtils.isNotEmpty(this.valueAuthorWritten)){ | |
330 Entity alias = null; | |
331 if(suggestedAuthorsWritten != null){ | |
332 for(SelectItem item : this.suggestedAuthorsWritten){ | |
333 Long id = (Long)item.getValue(); | |
334 if(id != null){ | |
335 Entity candidate = getWrapper().getEntityById(id); | |
336 if(candidate != null && valueAuthorWritten.equals(candidate.getOwnValue())){ | |
337 alias = candidate; | |
338 break; | |
339 } | |
340 } | |
341 } | |
342 } | |
343 | |
344 if(alias == null){ | |
345 alias = new Entity(Node.TYPE_ABOX, ALIAS, false); | |
346 alias.addAttribute(new Attribute(ALIAS, "text", valueAuthorWritten)); | |
347 alias = getWrapper().saveEntity(alias, user.getEmail(), null); | |
348 new Relation(alias, this.authorLo.getEntity(), "is_alias_name_of"); | |
349 alias = getWrapper().saveEntity(alias, user.getEmail(), null); | |
350 } | |
351 if(alias.isLightweight()){ | |
352 alias = getWrapper().getEntityByIdWithContent(alias.getId()); | |
353 } | |
354 this.entity.replaceSourceRelation(alias, ALIAS, rel_has_author_written_as); | |
355 } | |
356 } | |
357 | |
358 public String saveAsNewEntity() { | 284 public String saveAsNewEntity() { |
359 this.setSelectedSaveAsNew(true); | 285 this.setSelectedSaveAsNew(true); |
360 return save(); | 286 return save(); |
361 } | 287 } |
362 | 288 |
363 /* rich | |
364 public void patronageChangeListener(ValueChangeEvent event) { | |
365 //patronageLo = changeListener(event, patronageLo, PERSON, "name"); | |
366 patronageLo = changeValuePersonByRole(event, patronageLo, "Patron"); | |
367 | |
368 } | |
369 | |
370 public void copyistChangeListener(ValueChangeEvent event) { | |
371 copyistLo = changeValuePersonByRole(event, copyistLo, "Copyist"); | |
372 } | |
373 | |
374 public void copyPlacesChangeListener(ValueChangeEvent event) { | |
375 copyPlaceLo = changeListener(event, copyPlaceLo,"PLACE", "name"); | |
376 }*/ | |
377 | |
378 public void updateTitle(){ | 289 public void updateTitle(){ |
379 | 290 |
380 if(titleLo.entity != null && titleLo.entity.isPersistent()){ | 291 if(titleLo.entity != null && titleLo.entity.isPersistent()){ |
381 | 292 |
382 this.textUnknown = UNKNOWN.equals(titleLo.entity.getOwnValue()); | 293 this.textUnknown = UNKNOWN.equals(titleLo.entity.getOwnValue()); |