/** * Deletes the given process element from the rnrm:isFlowingTo linked list without breaking the * path. The element is also removed from the process. * * @param processElement */ public void deleteFromPath(Resource processElement) { Model model = process.getModel(); List<Statement> incoming = process.getIncomingEdges(processElement); List<Statement> outgoing = process.getOutgoingEdges(processElement); if (incoming.size() > 1 || outgoing.size() > 1) { throw new IllegalArgumentException( "Error deleting element. Elements with more than 1 outgoing or incoming links cannot be deleted."); } Resource before = null; Resource after = null; Statement stmt = null; if (incoming.size() > 0) { stmt = incoming.get(0); before = stmt.getSubject(); model.remove(stmt); } if (outgoing.size() > 0) { stmt = outgoing.get(0); after = stmt.getResource(); model.remove(stmt); } if (null != before && null != after) { model.add(before, RNRM.isFlowingTo, after); } // now disassociate this element from the process removeFromProcess(processElement); }
/** * Inserts the given {@link Resource} into the rnrm:isFlowingTo path before the specified {@link * Resource} * * @param toInsert Process element to insert * @param before Process element to insert before */ public void insertBefore(Resource toInsert, Resource before) { List<Statement> incoming = process.getIncomingEdges(before); Model model = process.getModel(); if (incoming.size() > 1) { throw new IllegalArgumentException( "Cannot insert before nodes with multiple incoming links."); } model.add(toInsert, RNRM.isFlowingTo, before); if (incoming.size() > 0) { Statement stmt = incoming.get(0); Resource prior = stmt.getSubject(); model.remove(stmt); model.add(prior, RNRM.isFlowingTo, toInsert); } }
/** * Removes an incoming rnrm:isFlowingTo edge from the specified element such that a path from the * start element to the specified element still exists. * * @param procElement Element to remove an incoming edge from * @return True if an edge was safely removed. False if no edges could be removed without * eliminating the path. */ public boolean removeNonBreakingIncomingArc(Resource procElement) { boolean foundSafeRemoval = false; if (process.completePathExists()) { List<Statement> incomingArcs = process.getIncomingEdges(procElement); for (Statement stmt : incomingArcs) { process.getModel().remove(stmt); if (process.pathExists(process.getStartElement(), procElement)) { foundSafeRemoval = true; break; } else { process.getModel().add(stmt); } } } return foundSafeRemoval; }
/** * Removes all {@link Statement}s representing an incoming rnrm:isFlowingTo edge. * * @param procElement */ public void removeIncomingLinks(Resource procElement) { List<Statement> toRemove = process.getIncomingEdges(procElement); Statement[] stmts = new Statement[toRemove.size()]; process.getModel().remove(toRemove.toArray(stmts)); }