comparison src/main/java/de/mpiwg/itgroup/ismi/util/guiComponents/MisattributionTable.java @ 136:502ae5b1a07d

fixing bugs from re-use efforts. misc cleanups.
author casties
date Thu, 02 Mar 2017 19:48:58 +0100
parents aef031e76278
children
comparison
equal deleted inserted replaced
135:0183b8a09717 136:502ae5b1a07d
99 } 99 }
100 return false; 100 return false;
101 } 101 }
102 102
103 /** 103 /**
104 * Save all misattributions. 104 * Save all misattributions on this text.
105 * 105 *
106 * Deletes removed misattributions. 106 * Deletes removed misattributions.
107 * 107 *
108 * @param text 108 * @param text
109 * @return 109 * @return
110 * @throws Exception 110 * @throws Exception
111 */ 111 */
112 public Entity saveMisattributions(Entity text) throws Exception { 112 public Entity saveMisattributions(Entity text) throws Exception {
113 // remember old misattributions 113 // remember old misattributions
114 List<Relation> oldRels = text.getSourceRelations(Misattribution.HAS_AUTHOR_MISATT, Misattribution.MISATT); 114 List<Relation> oldRels = text.getSourceRelations(Misattribution.HAS_AUTHOR_MISATT, Misattribution.MISATT);
115 // delete old relations 115 List<Entity> misatts = new ArrayList<Entity>();
116 text.removeAllSourceRelationsByName(Misattribution.HAS_AUTHOR_MISATT); 116 // save new misattributions
117 // create new misattributions
118 for (Misattribution misatt : this.getMisattList()) { 117 for (Misattribution misatt : this.getMisattList()) {
119 text = misatt.saveAndGetMisattribution(text); 118 misatt.saveMisattribution(text);
119 misatts.add(misatt.getMisatt());
120 } 120 }
121 // update relations
122 this.replaceMultipleSourceRelations(text, misatts, Misattribution.MISATT, Misattribution.HAS_AUTHOR_MISATT);
121 // check for orphaned old misattributions 123 // check for orphaned old misattributions
122 for (Relation rel : oldRels) { 124 for (Relation rel : oldRels) {
123 boolean match = false; 125 boolean found = false;
124 for (Misattribution mi : this.getMisattList()) { 126 for (Entity miEnt : misatts) {
125 Entity miEnt = mi.getMisatt();
126 if (miEnt != null && rel.getTargetId() == miEnt.getId()) { 127 if (miEnt != null && rel.getTargetId() == miEnt.getId()) {
127 match = true; 128 found = true;
128 break; 129 break;
129 } 130 }
130 } 131 }
131 if (!match) { 132 if (!found) {
132 Entity ent = getWrapper().getEntityById(rel.getTargetId()); 133 Entity miEnt = getWrapper().getEntityById(rel.getTargetId());
133 logger.warn("Orphaned MISATTRIBUTION will be deleted: " + ent); 134 logger.warn("Orphaned MISATTRIBUTION will be deleted: " + miEnt);
134 getWrapper().removeCurrentVersionEntity(ent, getUserName()); 135 getWrapper().removeCurrentVersionEntity(miEnt, getUserName());
135 } 136 }
136 } 137 }
137 return text; 138 return text;
138 } 139 }
139 140