/** * 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 after the specified {@link * Resource} * * @param toInsert Process element to insert * @param after Process element to insert after */ public void insertAfter(Resource toInsert, Resource after) { List<Statement> outgoing = process.getOutgoingEdges(after); Model model = process.getModel(); if (outgoing.size() > 1) { throw new IllegalArgumentException("Cannot insert after nodes with multiple outgoing links."); } model.add(after, RNRM.isFlowingTo, toInsert); if (outgoing.size() > 0) { Statement stmt = outgoing.get(0); Resource next = stmt.getResource(); model.remove(stmt); model.add(toInsert, RNRM.isFlowingTo, next); } }
/** * Removes an outgoing rnrm:isFlowingTo edge from the specified element such that a path from the * element to the end of the process still exists. * * @param procElement Element to remove an outgoing edge from * @return True if an edge was safely removed. False if no edges could be removed without * eliminating the path. */ public boolean removeNonBreakingOutgoingArc(Resource procElement) { boolean foundSafeRemoval = false; if (process.completePathExists()) { List<Statement> outgoingArcs = process.getOutgoingEdges(procElement); for (Statement stmt : outgoingArcs) { process.getModel().remove(stmt); if (process.pathExists(procElement, process.getEndElement())) { foundSafeRemoval = true; break; } else { process.getModel().add(stmt); } } } return foundSafeRemoval; }
/** * Removes all {@link Statement}s representing an outgoing rnrm:isFlowingTo edge. * * @param procElement */ public void removeOutgoingLinks(Resource procElement) { List<Statement> toRemove = process.getOutgoingEdges(procElement); Statement[] stmts = new Statement[toRemove.size()]; process.getModel().remove(toRemove.toArray(stmts)); }