Mercurial > hg > ismi-richfaces
annotate src/main/java/de/mpiwg/itgroup/ismi/merge/ImportMerge.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 | 28a0c2726466 |
children | 3c585df9f874 |
rev | line source |
---|---|
96 | 1 package de.mpiwg.itgroup.ismi.merge; |
2 | |
3 import java.io.File; | |
4 import java.io.FileInputStream; | |
5 import java.io.InputStreamReader; | |
6 import java.io.Reader; | |
7 import java.io.Serializable; | |
8 import java.util.ArrayList; | |
9 import java.util.HashMap; | |
10 import java.util.List; | |
11 import java.util.Map; | |
12 | |
13 import javax.faces.event.ActionEvent; | |
14 import javax.faces.model.SelectItem; | |
15 | |
16 import org.apache.commons.lang.StringUtils; | |
17 import org.apache.log4j.Logger; | |
18 import org.mpi.openmind.repository.bo.Attribute; | |
19 import org.mpi.openmind.repository.bo.Entity; | |
20 import org.mpi.openmind.repository.bo.Node; | |
21 import org.mpi.openmind.repository.bo.Relation; | |
22 import org.mpi.openmind.repository.utils.CsvNodeListReader; | |
98 | 23 import org.richfaces.event.FileUploadEvent; |
24 import org.richfaces.model.UploadedFile; | |
96 | 25 |
26 import de.mpiwg.itgroup.ismi.entry.beans.AbstractISMIBean; | |
27 | |
28 public class ImportMerge extends AbstractISMIBean implements Serializable { | |
29 | |
30 private static Logger logger = Logger.getLogger(ImportMerge.class); | |
31 | |
32 private static final long serialVersionUID = 1L; | |
33 | |
34 private String importFilename = "/var/tmp/ismi-import.csv"; | |
35 private String importFileMsg = null; | |
36 | |
37 private List<Node> importNodeList; | |
38 private int importNodeIdx; | |
39 private int importNodeListLength = 0; | |
40 private Node importNode; | |
41 private String importNodeMsg; | |
42 | |
43 public static String FIRST_VALUE = "old value"; | |
44 public static String SECOND_VALUE = "new value"; | |
45 public static String IGNORE = "ignore"; | |
46 public static String TAKE = "take"; | |
47 | |
48 private boolean showAttributeMapping = false; | |
49 private boolean showSrcRelationMapping = false; | |
50 private boolean showTarRelationMapping = false; | |
51 | |
52 private boolean entitiesLoaded = false; | |
53 | |
54 private Map<String, String> firstAttMap = new HashMap<String, String>(); | |
55 private Map<String, String> secondAttMap = new HashMap<String, String>(); | |
56 | |
57 private Entity firstEntity; | |
58 private Entity secondEntity; | |
59 | |
60 private String firstId; | |
61 private String secondId; | |
62 | |
63 private Entity entResult; | |
64 private List<Attribute> resultAtts; | |
65 private List<Relation> resultSrcRels; | |
66 private List<Relation> resultTarRels; | |
67 | |
68 private List<String> attLabels; | |
69 private Map<String, String> selectedAtts; | |
70 | |
71 Map<Long, String> selectedFirstSrcRelations; | |
72 Map<Long, String> selectedSecondSrcRelations; | |
73 Map<Long, String> selectedFirstTarRelations; | |
74 Map<Long, String> selectedSecondTarRelations; | |
75 | |
76 | |
77 public ImportMerge() { | |
78 } | |
79 | |
98 | 80 public void uploadListener(FileUploadEvent event) throws Exception { |
81 UploadedFile item = event.getUploadedFile(); | |
82 importFilename = item.getName(); | |
83 reset(); | |
84 try { | |
85 Reader importReader = new InputStreamReader(item.getInputStream(), "UTF-8"); | |
86 importNodeList = CsvNodeListReader.readCsv(importReader); | |
87 | |
88 this.importNodeListLength = importNodeList.size(); | |
89 this.importFileMsg = "File "+ importFilename + " contains " + importNodeListLength + " Nodes"; | |
90 this.importNodeIdx = 0; | |
91 loadImportNode(); | |
92 | |
93 } catch (Exception e) { | |
94 addErrorMsg("The import file could no be loaded."); | |
95 addErrorMsg("Error: "+e); | |
96 } | |
97 } | |
98 | |
99 | |
97 | 100 /** |
101 * Action that loads the import file and parses it into the Nodes list. | |
102 * | |
103 * @param event | |
104 */ | |
96 | 105 public void loadImportFile(ActionEvent event) { |
106 reset(); | |
107 try { | |
108 File importFile = new File(this.importFilename); | |
109 if (!importFile.canRead()) { | |
110 this.importFileMsg = "File missing!"; | |
111 return; | |
112 } | |
113 Reader importReader = new InputStreamReader(new FileInputStream(importFile), "UTF-8"); | |
114 importNodeList = CsvNodeListReader.readCsv(importReader); | |
115 | |
116 this.importNodeListLength = importNodeList.size(); | |
117 this.importFileMsg = importNodeListLength + " Nodes"; | |
118 this.importNodeIdx = 0; | |
97 | 119 loadImportNode(); |
96 | 120 |
121 } catch (Exception e) { | |
122 addErrorMsg("The import file could no be loaded."); | |
123 addErrorMsg("Error: "+e); | |
124 } | |
125 } | |
126 | |
97 | 127 /** |
128 * Load the current Node from the import list. | |
129 * | |
130 * @param event | |
131 */ | |
132 public void loadImportNode() { | |
96 | 133 reset(); |
134 try { | |
135 importNode = importNodeList.get(importNodeIdx); | |
136 importNodeMsg = null; | |
137 firstEntity = null; | |
138 secondEntity = null; | |
139 | |
140 if (importNode.getNodeType().equals("ATTRIBUTE")) { | |
97 | 141 /* |
142 * Attribute | |
143 */ | |
96 | 144 Attribute att = (Attribute) importNode; |
145 String attName = att.getName(); | |
146 if (attName == null) { | |
147 importNodeMsg = "Attribute has no name!"; | |
148 return; | |
149 } | |
150 Long source_id = att.getSourceId(); | |
151 if (source_id == null) { | |
152 importNodeMsg = "Attribute has no source_id to attach to!"; | |
153 return; | |
154 } else { | |
155 Entity systemEnt = getWrapper().getEntityById(source_id); | |
156 if (systemEnt != null) { | |
157 if (systemEnt.isLightweight()) { | |
158 systemEnt = getWrapper().getEntityContent(systemEnt); | |
159 } | |
160 Attribute systemAtt = systemEnt.getAttributeByName(attName); | |
161 if ((systemAtt != null) && (systemAtt.getOwnValue().equals(att.getOwnValue()))) { | |
162 importNodeMsg = "Same attribute exists already!"; | |
163 return; | |
164 } | |
165 // create new Entity with this Attribute | |
166 Entity newEnt = (Entity) systemEnt.clone(); | |
167 newEnt.addAttribute(att); | |
168 this.secondEntity = newEnt; | |
169 // compare with old version | |
170 this.firstEntity = systemEnt; | |
171 } else { | |
172 importNodeMsg = "Entity for Attribute does not exist!"; | |
173 return; | |
174 } | |
175 } | |
176 } else if (importNode.getNodeType().equals("ENTITY")) { | |
97 | 177 /* |
178 * Entity | |
179 */ | |
96 | 180 Entity ent = (Entity) importNode; |
181 Long id = ent.getId(); | |
182 if (id == null) { | |
183 // new Entity | |
184 this.secondEntity = ent; | |
185 // what to use to compare? | |
186 this.firstEntity = new Entity(); | |
97 | 187 this.firstEntity.setLightweight(false); |
96 | 188 |
189 } else { | |
190 // entity exists | |
191 Entity systemEnt = getWrapper().getEntityById(id); | |
192 if (systemEnt != null) { | |
193 if (systemEnt.isLightweight()) { | |
194 systemEnt = getWrapper().getEntityContent(systemEnt); | |
195 } | |
196 importNodeMsg = "Entity exists (but may be different)."; | |
197 // TODO: does it make sense to check for equality? | |
198 this.secondEntity = ent; | |
199 // compare with old version | |
200 this.firstEntity = systemEnt; | |
201 } else { | |
97 | 202 importNodeMsg = "Entity does not exist!"; |
96 | 203 // TODO: try to undelete? |
204 this.firstEntity = new Entity(); | |
97 | 205 this.firstEntity.setLightweight(false); |
96 | 206 this.secondEntity = ent; |
207 } | |
208 } | |
209 } else if (importNode.getNodeType().equals("RELATION")) { | |
97 | 210 /* |
211 * Relation | |
212 */ | |
96 | 213 Relation rel = (Relation) importNode; |
214 String relName = rel.getObjectClass(); | |
215 if (relName == null) { | |
216 importNodeMsg = "Relation has no name!"; | |
217 return; | |
218 } | |
219 Long source_id = rel.getSourceId(); | |
220 Long target_id = rel.getTargetId(); | |
221 if (source_id == null) { | |
134
25bfcc9d757c
effort to re-use more relations when saving entities.
casties
parents:
124
diff
changeset
|
222 // no source id |
96 | 223 importNodeMsg = "Relation has no source_id!"; |
224 return; | |
225 } else if (target_id == null) { | |
134
25bfcc9d757c
effort to re-use more relations when saving entities.
casties
parents:
124
diff
changeset
|
226 // no target id |
96 | 227 importNodeMsg = "Relation has no target_id!"; |
228 return; | |
229 } else { | |
134
25bfcc9d757c
effort to re-use more relations when saving entities.
casties
parents:
124
diff
changeset
|
230 // get source and target Entities |
96 | 231 Entity sourceEnt = getWrapper().getEntityById(source_id); |
232 Entity targetEnt = getWrapper().getEntityById(target_id); | |
233 if (sourceEnt == null) { | |
234 importNodeMsg = "Relation source does not exist!"; | |
235 } else if (targetEnt == null) { | |
236 importNodeMsg = "Relation target does not exist!"; | |
237 } else { | |
238 if (sourceEnt.isLightweight()) { | |
239 sourceEnt = getWrapper().getEntityContent(sourceEnt); | |
240 } | |
134
25bfcc9d757c
effort to re-use more relations when saving entities.
casties
parents:
124
diff
changeset
|
241 // get existing Relation |
96 | 242 Relation systemRel = sourceEnt.getSourceRelation(relName, target_id); |
243 if ((systemRel != null) && (systemRel.getObjectClass().equals(rel.getObjectClass()))) { | |
244 // TODO: also check Relation attributes | |
245 importNodeMsg = "Same Relation exists already!"; | |
246 return; | |
247 } | |
248 // create new Entity with this Relation | |
97 | 249 Entity newEnt = new Entity(); |
250 newEnt.setLightweight(false); | |
96 | 251 newEnt.addSourceRelation(rel); |
252 this.secondEntity = newEnt; | |
253 // compare with old version | |
254 this.firstEntity = sourceEnt; | |
255 } | |
256 } | |
257 } | |
258 } catch (Exception e) { | |
259 addErrorMsg("The import Node could no be loaded."); | |
97 | 260 addErrorMsg("Error: "+e); |
96 | 261 } |
262 } | |
263 | |
264 public void skipCurrentNode(ActionEvent event) { | |
265 importNodeIdx += 1; | |
266 if (importNodeIdx >= importNodeList.size()) { | |
267 importNodeIdx = importNodeList.size() - 1; | |
268 } | |
269 if (importNodeIdx < 0) { | |
270 importNodeIdx = 0; | |
271 } | |
97 | 272 loadImportNode(); |
96 | 273 } |
274 | |
275 public void loadFirstEntity(ActionEvent event) { | |
276 reset(); | |
277 try { | |
278 if (firstEntity != null && secondEntity != null) { | |
97 | 279 // create list of differences |
96 | 280 deployDifferences(); |
281 } else { | |
282 if (importNodeMsg != null) { | |
283 addErrorMsg(importNodeMsg); | |
284 } | |
285 } | |
286 } catch (Exception e) { | |
287 addErrorMsg("The first entity could no be loaded."); | |
288 } | |
289 } | |
290 | |
291 @Override | |
292 public void reset() { | |
293 this.attLabels = new ArrayList<String>(); | |
294 this.selectedAtts = new HashMap<String, String>(); | |
295 this.selectedFirstSrcRelations = new HashMap<Long, String>(); | |
296 this.selectedSecondSrcRelations = new HashMap<Long, String>(); | |
297 this.selectedFirstTarRelations = new HashMap<Long, String>(); | |
298 this.selectedSecondTarRelations = new HashMap<Long, String>(); | |
299 this.entResult = null; | |
300 | |
301 this.entitiesLoaded = false; | |
302 this.showAttributeMapping = false; | |
303 this.showSrcRelationMapping = false; | |
304 this.showTarRelationMapping = false; | |
305 } | |
306 | |
97 | 307 /** |
308 * Create list of differences in attributes and relations for display. | |
309 */ | |
96 | 310 private void deployDifferences() { |
311 this.showAttributeMapping = true; | |
312 this.showSrcRelationMapping = true; | |
313 this.showTarRelationMapping = true; | |
314 this.entitiesLoaded = true; | |
315 if (this.firstEntity != null && this.secondEntity != null) { | |
316 /* | |
317 if (firstEntity.isLightweight()) { | |
318 this.firstEntity = getWrapper().getEntityContent(this.firstEntity); | |
319 } | |
320 if (secondEntity.isLightweight()) { | |
321 this.secondEntity = getWrapper().getEntityContent(this.secondEntity); | |
322 } | |
323 | |
324 this.firstEntity = (Entity) firstEntity.clone(); | |
325 this.secondEntity = (Entity) secondEntity.clone(); | |
326 */ | |
327 | |
97 | 328 /* |
329 * attributes | |
330 */ | |
96 | 331 this.attLabels = new ArrayList<String>(); |
332 this.selectedAtts = new HashMap<String, String>(); | |
333 this.firstAttMap = new HashMap<String, String>(); | |
334 this.secondAttMap = new HashMap<String, String>(); | |
335 | |
336 for (Attribute att : this.firstEntity.getAttributes()) { | |
337 firstAttMap.put(att.getName(), att.getValue()); | |
338 if (!attLabels.contains(att.getName())) { | |
339 attLabels.add(att.getName()); | |
340 selectedAtts.put(att.getName(), FIRST_VALUE); | |
341 } | |
342 } | |
343 | |
344 for (Attribute att : this.secondEntity.getAttributes()) { | |
345 secondAttMap.put(att.getName(), att.getValue()); | |
346 if (!attLabels.contains(att.getName())) { | |
347 attLabels.add(att.getName()); | |
348 selectedAtts.put(att.getName(), FIRST_VALUE); | |
349 } | |
350 } | |
351 | |
97 | 352 /* |
353 * source relations | |
354 */ | |
96 | 355 this.selectedFirstSrcRelations = new HashMap<Long, String>(); |
356 this.selectedSecondSrcRelations = new HashMap<Long, String>(); | |
357 | |
358 for (Relation rel : this.firstEntity.getSourceRelations()) { | |
359 rel.setTarget(getWrapper().getEntityById(rel.getTargetId())); | |
360 selectedFirstSrcRelations.put(rel.getId(), TAKE); | |
361 } | |
362 | |
363 for (Relation rel : this.secondEntity.getSourceRelations()) { | |
364 rel.setTarget(getWrapper().getEntityById(rel.getTargetId())); | |
365 selectedSecondSrcRelations.put(rel.getId(), TAKE); | |
366 } | |
367 | |
97 | 368 /* |
369 * target relations | |
370 */ | |
96 | 371 this.selectedFirstTarRelations = new HashMap<Long, String>(); |
372 this.selectedSecondTarRelations = new HashMap<Long, String>(); | |
373 | |
374 for (Relation rel : this.firstEntity.getTargetRelations()) { | |
375 rel.setSource(getWrapper().getEntityById(rel.getSourceId())); | |
376 selectedFirstTarRelations.put(rel.getId(), TAKE); | |
377 } | |
378 | |
379 for (Relation rel : this.secondEntity.getTargetRelations()) { | |
380 rel.setSource(getWrapper().getEntityById(rel.getSourceId())); | |
381 selectedSecondTarRelations.put(rel.getId(), TAKE); | |
382 } | |
383 | |
384 } | |
385 } | |
386 | |
97 | 387 /** |
388 * Preview merged Entity as text. | |
389 * | |
390 * @param event | |
391 */ | |
96 | 392 public void preview(ActionEvent event) { |
393 this.generateResultEntity(); | |
394 } | |
395 | |
97 | 396 /** |
397 * Execute Merge action from UI. | |
398 */ | |
399 public void listenerExecuteMerge() { | |
400 this.executeMerge(); | |
401 getAppBean().getSimpleSearchCache().setMapDirty(true); | |
402 } | |
403 | |
404 /** | |
405 * Merge Entities. | |
406 * | |
407 * firstEntity is current one. secondEntity is imported. | |
408 */ | |
96 | 409 private void executeMerge() { |
410 | |
97 | 411 logger.info("Starting merge import " + firstEntity.getObjectClass() + " [" + getUserName() + "]" |
96 | 412 + "[firstEntity=" + firstEntity.getId() + ", secondEntity=" + secondEntity.getId() + "]"); |
413 | |
414 try { | |
415 this.generateResultEntity(); | |
416 if (this.entResult != null) { | |
97 | 417 // print to log |
96 | 418 this.printMergeInfo(entResult); |
97 | 419 // save the new Entity |
124
28a0c2726466
changed saveEntity() to use new EditIntent. Set up EditIntent for TEXT, PERSON, REFERENCE.
casties
parents:
108
diff
changeset
|
420 this.getWrapper().saveEntity(this.entResult, getSessionUser().getEmail() + "_merge", null); |
97 | 421 // update generated ownvalues |
96 | 422 this.updateRelatedOW(this.entResult, getSessionUser().getEmail() + "_merge"); |
423 | |
97 | 424 logger.info("Merge import successful " + firstEntity.getObjectClass() + " [" + getUserName() + "]" |
96 | 425 + "[firstEntity=" + firstEntity.getId() + ", secondEntity=" + secondEntity.getId() |
426 + ", generatedEntity=" + entResult.getId() + "]"); | |
427 | |
428 this.firstEntity = null; | |
429 this.secondEntity = null; | |
430 | |
97 | 431 addGeneralMsg("The imported entity was merged successfully"); |
96 | 432 addGeneralMsg("The new entity has the id " + this.entResult.getId()); |
433 this.reset(); | |
434 } | |
435 } catch (Exception e) { | |
436 printInternalError(e); | |
437 logger.error("[" + getUserName() + "] " + e.getMessage(), e); | |
438 } | |
439 } | |
440 | |
441 private void printMergeInfo(Entity ent) { | |
442 StringBuilder sb = new StringBuilder("\n\n"); | |
443 | |
444 sb.append("-----------------------------------------\n"); | |
445 sb.append("Merging result [" + getUserName() + "]\n"); | |
446 sb.append(ent.toString() + "\n"); | |
447 sb.append("Attributes:\n"); | |
448 for (Attribute att : ent.getAttributes()) { | |
449 sb.append("\t" + att.toString() + "\n"); | |
450 } | |
451 | |
452 sb.append("Src Relations:\n"); | |
453 for (Relation src : ent.getSourceRelations()) { | |
454 sb.append("\t" + src.toString() + "\n"); | |
455 } | |
456 | |
457 sb.append("Tar Relations:\n"); | |
458 for (Relation tar : ent.getTargetRelations()) { | |
459 sb.append("\t" + tar.toString() + "\n"); | |
460 } | |
461 | |
462 sb.append("-----------------------------------------\n"); | |
463 logger.info(sb.toString()); | |
464 } | |
465 | |
97 | 466 /** |
467 * Generate new Entity taking selected Attributes and Relations from both Entities. | |
468 * | |
469 * Uses id from firstEntity, creating a new version of this entity. | |
470 */ | |
471 private void generateResultEntity() { | |
472 // create new Entity | |
473 this.entResult = new Entity(); | |
474 this.entResult.setLightweight(false); | |
475 // use id from firstEntity | |
476 Long newId = this.firstEntity.getId(); | |
477 if (newId == null) { | |
478 // Entity is new -- try imported id | |
479 newId = secondEntity.getId(); | |
480 } | |
481 this.entResult.setId(newId); | |
482 // use object_class from firstEntity | |
483 String oc = this.firstEntity.getObjectClass(); | |
484 if (oc == null) { | |
485 // Entity is new -- try imported object_class | |
486 oc = secondEntity.getObjectClass(); | |
487 } | |
488 this.entResult.setObjectClass(oc); | |
489 | |
490 /* | |
491 * generating attributes | |
492 */ | |
493 try { | |
494 for (String attName : this.selectedAtts.keySet()) { | |
495 String selected = this.selectedAtts.get(attName); | |
496 String value = ""; | |
497 if (selected.equals(FIRST_VALUE)) { | |
498 value = (firstEntity.getAttributeByName(attName) == null) ? "" | |
499 : firstEntity.getAttributeByName(attName).getOwnValue(); | |
500 } else if (selected.equals(SECOND_VALUE)) { | |
501 value = (secondEntity.getAttributeByName(attName) == null) ? "" | |
502 : secondEntity.getAttributeByName(attName).getOwnValue(); | |
503 } | |
504 this.entResult.addAttribute(new Attribute(attName, "text", value)); | |
505 } | |
506 } catch (Exception e) { | |
507 logger.error(e); | |
508 addErrorMsg("Please inform support of this exception: " + e.getMessage()); | |
509 } | |
510 | |
511 /* | |
512 * generating source relations | |
513 */ | |
514 for (Relation rel : firstEntity.getSourceRelations()) { | |
515 String selectedValue = this.selectedFirstSrcRelations.get(rel.getId()); | |
516 if (StringUtils.isNotEmpty(selectedValue) && selectedValue.equals(TAKE)) { | |
517 if (!this.entResult.containsSourceRelation(rel.getOwnValue(), rel.getTargetId())) { | |
518 this.entResult.addSourceRelation(generateSrcRelation(rel)); | |
519 } | |
520 } | |
521 } | |
522 | |
523 for (Relation rel : secondEntity.getSourceRelations()) { | |
524 String selectedValue = this.selectedSecondSrcRelations.get(rel.getId()); | |
525 if (StringUtils.isNotEmpty(selectedValue) && selectedValue.equals(TAKE)) { | |
526 if (!this.entResult.containsSourceRelation(rel.getOwnValue(), rel.getTargetId())) { | |
527 this.entResult.addSourceRelation(generateSrcRelation(rel)); | |
528 } | |
529 } | |
530 } | |
531 | |
532 /* | |
533 * generating target relations | |
534 */ | |
535 for (Relation rel : firstEntity.getTargetRelations()) { | |
536 String selectedValue = this.selectedFirstTarRelations.get(rel.getId()); | |
537 if (StringUtils.isNotEmpty(selectedValue) && selectedValue.equals(TAKE)) { | |
538 // ensuring that there is no two equals relations. | |
539 if (!this.entResult.containsTargetRelation(rel.getOwnValue(), rel.getSourceId())) { | |
540 this.entResult.addTargetRelation(generateTarRelation(rel)); | |
541 } | |
542 } | |
543 } | |
544 | |
545 for (Relation rel : secondEntity.getTargetRelations()) { | |
546 String selectedValue = this.selectedSecondTarRelations.get(rel.getId()); | |
547 if (StringUtils.isNotEmpty(selectedValue) && selectedValue.equals(TAKE)) { | |
548 if (!this.entResult.containsTargetRelation(rel.getOwnValue(), rel.getSourceId())) { | |
549 this.entResult.addTargetRelation(generateTarRelation(rel)); | |
550 } | |
551 } | |
552 } | |
553 } | |
554 | |
555 private Relation generateSrcRelation(Relation rel) { | |
556 Relation newRel = new Relation(); | |
557 newRel.setOwnValue(rel.getOwnValue()); | |
558 newRel.setTarget(getWrapper().getEntityById(rel.getTargetId())); | |
559 return newRel; | |
560 } | |
561 | |
562 private Relation generateTarRelation(Relation rel) { | |
563 Relation newRel = new Relation(); | |
564 newRel.setOwnValue(rel.getOwnValue()); | |
565 newRel.setSource(getWrapper().getEntityById(rel.getSourceId())); | |
566 return newRel; | |
567 } | |
568 | |
569 public List<SelectItem> getAttSelectItems() { | |
570 List<SelectItem> items = new ArrayList<SelectItem>(); | |
571 items.add(new SelectItem(FIRST_VALUE)); | |
572 items.add(new SelectItem(SECOND_VALUE)); | |
573 items.add(new SelectItem(IGNORE)); | |
574 return items; | |
575 } | |
576 | |
577 public List<SelectItem> getRelSelectItems() { | |
578 List<SelectItem> items = new ArrayList<SelectItem>(); | |
579 items.add(new SelectItem(TAKE)); | |
580 items.add(new SelectItem(IGNORE)); | |
581 return items; | |
582 } | |
583 | |
96 | 584 public void actionShowTarRelationMapping(ActionEvent event) { |
585 this.showTarRelationMapping = true; | |
586 } | |
587 | |
588 public void actionHideTarRelationMapping(ActionEvent event) { | |
589 this.showTarRelationMapping = false; | |
590 } | |
591 | |
592 public void actionShowSrcRelationMapping(ActionEvent event) { | |
593 this.showSrcRelationMapping = true; | |
594 } | |
595 | |
596 public void actionHideSrcRelationMapping(ActionEvent event) { | |
597 this.showSrcRelationMapping = false; | |
598 } | |
599 | |
600 public void actionShowAttributeMapping(ActionEvent event) { | |
601 this.showAttributeMapping = true; | |
602 } | |
603 | |
604 public void actionHideAttributeMapping(ActionEvent event) { | |
605 this.showAttributeMapping = false; | |
606 } | |
607 | |
608 public Entity getEntResult() { | |
609 return entResult; | |
610 } | |
611 | |
612 public void setEntResult(Entity entResult) { | |
613 this.entResult = entResult; | |
614 } | |
615 | |
616 public List<Attribute> getResultAtts() { | |
617 return resultAtts; | |
618 } | |
619 | |
620 public void setResultAtts(List<Attribute> resultAtts) { | |
621 this.resultAtts = resultAtts; | |
622 } | |
623 | |
624 public List<Relation> getResultSrcRels() { | |
625 return resultSrcRels; | |
626 } | |
627 | |
628 public void setResultSrcRels(List<Relation> resultSrcRels) { | |
629 this.resultSrcRels = resultSrcRels; | |
630 } | |
631 | |
632 public List<Relation> getResultTarRels() { | |
633 return resultTarRels; | |
634 } | |
635 | |
636 public void setResultTarRels(List<Relation> resultTarRels) { | |
637 this.resultTarRels = resultTarRels; | |
638 } | |
639 | |
640 public Entity getFirstEntity() { | |
641 return firstEntity; | |
642 } | |
643 | |
644 public void setFirstEntity(Entity firstEntity) { | |
645 this.firstEntity = firstEntity; | |
646 } | |
647 | |
648 public Entity getSecondEntity() { | |
649 return secondEntity; | |
650 } | |
651 | |
652 public void setSecondEntity(Entity secondEntity) { | |
653 this.secondEntity = secondEntity; | |
654 } | |
655 | |
656 public String getFirstId() { | |
657 return firstId; | |
658 } | |
659 | |
660 public void setFirstId(String firstId) { | |
661 this.firstId = firstId; | |
662 } | |
663 | |
664 public String getSecondId() { | |
665 return secondId; | |
666 } | |
667 | |
668 public void setSecondId(String secondId) { | |
669 this.secondId = secondId; | |
670 } | |
671 | |
672 public List<String> getAttLabels() { | |
673 return attLabels; | |
674 } | |
675 | |
676 public void setAttLabels(List<String> attLabels) { | |
677 this.attLabels = attLabels; | |
678 } | |
679 | |
680 public Map<String, String> getFirstAttMap() { | |
681 return firstAttMap; | |
682 } | |
683 | |
684 public void setFirstAttMap(Map<String, String> firstAttMap) { | |
685 this.firstAttMap = firstAttMap; | |
686 } | |
687 | |
688 public Map<String, String> getSecondAttMap() { | |
689 return secondAttMap; | |
690 } | |
691 | |
692 public void setSecondAttMap(Map<String, String> secondAttMap) { | |
693 this.secondAttMap = secondAttMap; | |
694 } | |
695 | |
696 public Map<String, String> getSelectedAtts() { | |
697 return selectedAtts; | |
698 } | |
699 | |
700 public void setSelectedAtts(Map<String, String> selectedAtts) { | |
701 this.selectedAtts = selectedAtts; | |
702 } | |
703 | |
704 public boolean isShowAttributeMapping() { | |
705 return showAttributeMapping; | |
706 } | |
707 | |
708 public void setShowAttributeMapping(boolean showAttributeMapping) { | |
709 this.showAttributeMapping = showAttributeMapping; | |
710 } | |
711 | |
712 public boolean isEntitiesLoaded() { | |
713 return entitiesLoaded; | |
714 } | |
715 | |
716 public void setEntitiesLoaded(boolean entitiesLoaded) { | |
717 this.entitiesLoaded = entitiesLoaded; | |
718 } | |
719 | |
720 public Map<Long, String> getSelectedFirstSrcRelations() { | |
721 return selectedFirstSrcRelations; | |
722 } | |
723 | |
724 public void setSelectedFirstSrcRelations(Map<Long, String> selectedFirstSrcRelations) { | |
725 this.selectedFirstSrcRelations = selectedFirstSrcRelations; | |
726 } | |
727 | |
728 public Map<Long, String> getSelectedSecondSrcRelations() { | |
729 return selectedSecondSrcRelations; | |
730 } | |
731 | |
732 public void setSelectedSecondSrcRelations(Map<Long, String> selectedSecondSrcRelations) { | |
733 this.selectedSecondSrcRelations = selectedSecondSrcRelations; | |
734 } | |
735 | |
736 public boolean isShowSrcRelationMapping() { | |
737 return showSrcRelationMapping; | |
738 } | |
739 | |
740 public void setShowSrcRelationMapping(boolean showSrcRelationMapping) { | |
741 this.showSrcRelationMapping = showSrcRelationMapping; | |
742 } | |
743 | |
744 public boolean isShowTarRelationMapping() { | |
745 return showTarRelationMapping; | |
746 } | |
747 | |
748 public void setShowTarRelationMapping(boolean showTarRelationMapping) { | |
749 this.showTarRelationMapping = showTarRelationMapping; | |
750 } | |
751 | |
752 public Map<Long, String> getSelectedFirstTarRelations() { | |
753 return selectedFirstTarRelations; | |
754 } | |
755 | |
756 public void setSelectedFirstTarRelations(Map<Long, String> selectedFirstTarRelations) { | |
757 this.selectedFirstTarRelations = selectedFirstTarRelations; | |
758 } | |
759 | |
760 public Map<Long, String> getSelectedSecondTarRelations() { | |
761 return selectedSecondTarRelations; | |
762 } | |
763 | |
764 public void setSelectedSecondTarRelations(Map<Long, String> selectedSecondTarRelations) { | |
765 this.selectedSecondTarRelations = selectedSecondTarRelations; | |
766 } | |
767 | |
768 /** | |
769 * @return the importFilename | |
770 */ | |
771 public String getImportFilename() { | |
772 return importFilename; | |
773 } | |
774 | |
775 /** | |
776 * @param importFilename | |
777 * the importFilename to set | |
778 */ | |
779 public void setImportFilename(String importFilename) { | |
780 this.importFilename = importFilename; | |
781 } | |
782 | |
783 /** | |
784 * @return the importFileMsg | |
785 */ | |
786 public String getImportFileMsg() { | |
787 return importFileMsg; | |
788 } | |
789 | |
790 /** | |
791 * @param importFileMsg | |
792 * the importFileMsg to set | |
793 */ | |
794 public void setImportFileMsg(String importFileMsg) { | |
795 this.importFileMsg = importFileMsg; | |
796 } | |
797 | |
798 /** | |
799 * @return the importNode | |
800 */ | |
801 public Node getImportNode() { | |
802 return importNode; | |
803 } | |
804 | |
805 public String getImportNodeAsText() { | |
806 String s = ""; | |
807 try { | |
808 String nt = importNode.getNodeType(); | |
809 if (nt.equals("ATTRIBUTE")) { | |
810 Attribute att = (Attribute) importNode; | |
97 | 811 s = "ATTRIBUTE " + att.getName() + " [" + att.getSourceObjectClass() + " " + att.getSourceId() + "] = " + att.getOwnValue(); |
96 | 812 } else if (nt.equals("ENTITY")) { |
813 Entity ent = (Entity) importNode; | |
97 | 814 s = "ENTITY " + ent.getObjectClass() + " [" + ent.getId() + "] : " + ent.getOwnValue(); |
96 | 815 } else if (nt.equals("RELATION")) { |
816 Relation rel = (Relation) importNode; | |
97 | 817 s = "RELATION " + rel.getObjectClass() + " [" + rel.getId() + "] : " |
96 | 818 + "source=[" + rel.getSourceObjectClass() + " " + rel.getSourceId() + "] " |
819 + "target=[" + rel.getTargetObjectClass() + " " + rel.getTargetId() + "]"; | |
820 } else { | |
821 s = importNode.toString(); | |
822 } | |
823 } catch (Exception e) { | |
824 logger.error(e); | |
825 } | |
826 return s; | |
827 } | |
828 | |
829 /** | |
830 * @param importNode the importNode to set | |
831 */ | |
832 public void setImportNode(Node importNode) { | |
833 this.importNode = importNode; | |
834 } | |
835 | |
836 /** | |
108 | 837 * @return the importNodeList |
838 */ | |
839 public List<Node> getImportNodeList() { | |
840 return importNodeList; | |
841 } | |
842 | |
843 /** | |
844 * @param importNodeList the importNodeList to set | |
845 */ | |
846 public void setImportNodeList(List<Node> importNodeList) { | |
847 this.importNodeList = importNodeList; | |
848 } | |
849 | |
850 /** | |
96 | 851 * @return the importNodeListLength |
852 */ | |
853 public int getImportNodeListLength() { | |
854 return importNodeListLength; | |
855 } | |
856 | |
857 /** | |
858 * @return the importNodeIdx | |
859 */ | |
860 public int getImportNodeIdx() { | |
861 return importNodeIdx; | |
862 } | |
863 | |
864 /** | |
865 * @param importNodeIdx the importNodeIdx to set | |
866 */ | |
867 public void setImportNodeIdx(int importNodeIdx) { | |
868 this.importNodeIdx = importNodeIdx; | |
869 } | |
870 | |
871 /** | |
872 * @return the importNodeMsg | |
873 */ | |
874 public String getImportNodeMsg() { | |
875 return importNodeMsg; | |
876 } | |
877 | |
878 /** | |
879 * @param importNodeMsg the importNodeMsg to set | |
880 */ | |
881 public void setImportNodeMsg(String importNodeMsg) { | |
882 this.importNodeMsg = importNodeMsg; | |
883 } | |
884 | |
885 } |