# HG changeset patch # User casties # Date 1485969604 -3600 # Node ID aef031e7627822242f6e99ea34bc4698c6e83a0e # Parent efeab3bd856fe7ee13dd3d31dd03dfa2ce444018 105: MISATTRIBUTION should be deleted when detached Task-Url: https://it-dev.mpiwg-berlin.mpg.de/tracs/ismi/ticket/105 diff -r efeab3bd856f -r aef031e76278 src/main/java/de/mpiwg/itgroup/ismi/util/guiComponents/MisattributionTable.java --- a/src/main/java/de/mpiwg/itgroup/ismi/util/guiComponents/MisattributionTable.java Wed Feb 01 18:09:09 2017 +0100 +++ b/src/main/java/de/mpiwg/itgroup/ismi/util/guiComponents/MisattributionTable.java Wed Feb 01 18:20:04 2017 +0100 @@ -5,7 +5,9 @@ import javax.faces.event.ActionEvent; +import org.apache.log4j.Logger; import org.mpi.openmind.repository.bo.Entity; +import org.mpi.openmind.repository.bo.Relation; import de.mpiwg.itgroup.ismi.auxObjects.ListenerObject; import de.mpiwg.itgroup.ismi.entry.beans.AbstractISMIBean; @@ -13,6 +15,7 @@ public class MisattributionTable extends AbstractISMIBean { private static final long serialVersionUID = -2756216426560705499L; + private static Logger logger = Logger.getLogger(MisattributionTable.class); private List> list = new ArrayList>(); @@ -97,32 +100,42 @@ return false; } - /* - public void listenerChanged(ValueChangeEvent event) { - this.lo = changeListener(event, lo, this.oc, this.attName); - if(lo.entity != null && lo.entity.isPersistent()){ - lo.statusImage.setStatus(StatusImage.STATUS_OK); - }else{ - lo.statusImage.setStatus(StatusImage.STATUS_UNSET); - } - } - */ - - /** * Save all misattributions. * + * Deletes removed misattributions. + * * @param text * @return * @throws Exception */ - public Entity saveMisattributions(Entity text) throws Exception{ - for(Misattribution misatt : this.getMisattList()){ + public Entity saveMisattributions(Entity text) throws Exception { + // remember old misattributions + List oldRels = text.getSourceRelations(Misattribution.HAS_AUTHOR_MISATT, Misattribution.MISATT); + // delete old relations + text.removeAllSourceRelationsByName(Misattribution.HAS_AUTHOR_MISATT); + // create new misattributions + for (Misattribution misatt : this.getMisattList()) { text = misatt.saveAndGetMisattribution(text); } + // check for orphaned old misattributions + for (Relation rel : oldRels) { + boolean match = false; + for (Misattribution mi : this.getMisattList()) { + Entity miEnt = mi.getMisatt(); + if (miEnt != null && rel.getTargetId() == miEnt.getId()) { + match = true; + break; + } + } + if (!match) { + Entity ent = getWrapper().getEntityById(rel.getTargetId()); + logger.warn("Orphaned MISATTRIBUTION will be deleted: " + ent); + getWrapper().removeCurrentVersionEntity(ent, getUserName()); + } + } return text; - } - + } private List getMisattList() { List list = new ArrayList();