Search in sources :

Example 1 with DeleteDeniedException

use of org.apache.jena.shared.DeleteDeniedException in project jena by apache.

the class SecuredRDFListImpl method remove.

@Override
public RDFList remove(final RDFNode val) throws UpdateDeniedException, DeleteDeniedException, AuthenticationRequiredException {
    checkUpdate();
    RDFList cell = null;
    boolean denied = false;
    if (!canDelete(new Triple(Node.ANY, listFirst().asNode(), val.asNode()))) {
        // iterate over the deletable items
        // .mapWith(new
        final ExtendedIterator<RDFList> iter = getSecuredRDFListIterator(Action.Delete);
        // SecuredListMap());
        while (iter.hasNext()) {
            cell = iter.next();
            if (val.equals(cell.getRequiredProperty(listFirst()).getObject())) {
                if (canDelete(new Triple(cell.asNode(), listFirst().asNode(), val.asNode()))) {
                    return SecuredRDFListImpl.getInstance(getModel(), baseRemove(cell));
                } else {
                    denied = true;
                }
            }
        }
        if (denied) {
            throw new DeleteDeniedException(SecuredItem.Util.triplePermissionMsg(getModelNode()));
        } else {
            return this;
        }
    } else {
        return SecuredRDFListImpl.getInstance(getModel(), holder.getBaseItem().remove(val));
    }
}
Also used : Triple(org.apache.jena.graph.Triple) SecuredRDFList(org.apache.jena.permissions.model.SecuredRDFList) DeleteDeniedException(org.apache.jena.shared.DeleteDeniedException)

Example 2 with DeleteDeniedException

use of org.apache.jena.shared.DeleteDeniedException in project jena by apache.

the class GraphContractTest method testDelete_Triple.

/**
	 * Inference graphs can not be empty
	 */
@ContractTest
public void testDelete_Triple() {
    Graph graph = graphWith(producer.newInstance(), "S P O; S2 P2 O2; S3 P3 O3");
    Graph base = producer.newInstance();
    graph.getEventManager().register(GL);
    txnBegin(graph);
    graph.delete(triple("S P O"));
    txnCommit(graph);
    GL.assertContains("delete", graph, triple("S P O"));
    assertFalse("Graph should not contain <S P O>", graph.contains(triple("S P O")));
    assertNotEmpty(graph, base);
    assertTrue("Graph should contain <S2 P2 O2>", graph.contains(triple("S2 P2 O2")));
    assertTrue("Graph should contain <S3 P3 O3>", graph.contains(triple("S3 P3 O3")));
    // should not modify anything on wildcard delete
    GL.clear();
    try {
        txnBegin(graph);
        graph.delete(new Triple(node("S2"), node("P2"), Node.ANY));
        txnCommit(graph);
    } catch (DeleteDeniedException expected) {
        txnRollback(graph);
    }
    assertTrue("Graph should contain <S2 P2 O2>", graph.contains(triple("S2 P2 O2")));
    assertTrue("Graph should contain <S3 P3 O3>", graph.contains(triple("S3 P3 O3")));
    GL.assertHas("delete", graph, new Triple(node("S2"), node("P2"), Node.ANY));
}
Also used : GraphHelper.memGraph(org.apache.jena.testing_framework.GraphHelper.memGraph) DeleteDeniedException(org.apache.jena.shared.DeleteDeniedException) ContractTest(org.xenei.junit.contract.ContractTest)

Aggregations

DeleteDeniedException (org.apache.jena.shared.DeleteDeniedException)2 Triple (org.apache.jena.graph.Triple)1 SecuredRDFList (org.apache.jena.permissions.model.SecuredRDFList)1 GraphHelper.memGraph (org.apache.jena.testing_framework.GraphHelper.memGraph)1 ContractTest (org.xenei.junit.contract.ContractTest)1