Search in sources :

Example 1 with EmptyListException

use of org.apache.jena.rdf.model.EmptyListException in project jena by apache.

the class SecuredRDFListImpl method removeHead.

/**
 * @sec.graph Update
 * @sec.triple Delete for the head triple.
 * @throws UpdateDeniedException
 * @throws DeleteDeniedException
 * @throws EmptyListException
 * @throws ListIndexException
 * @throws InvalidListException
 * @throws AuthenticationRequiredException if user is not authenticated and is
 *                                         required to be.
 */
@Override
public SecuredRDFList removeHead() throws UpdateDeniedException, DeleteDeniedException, AuthenticationRequiredException {
    checkUpdate();
    final ExtendedIterator<RDFList> iter = getFilteredRDFListIterator(Action.Read);
    try {
        if (!iter.hasNext()) {
            throw new EmptyListException("Attempted to delete the head of a nil list");
        }
        final RDFList cell = iter.next();
        final Statement s = cell.getRequiredProperty(RDF.first);
        checkDelete(s);
        return SecuredRDFListImpl.getInstance(getModel(), baseRemove(cell));
    } finally {
        iter.close();
    }
}
Also used : SecuredRDFList(org.apache.jena.permissions.model.SecuredRDFList) RDFList(org.apache.jena.rdf.model.RDFList) Statement(org.apache.jena.rdf.model.Statement) EmptyListException(org.apache.jena.rdf.model.EmptyListException)

Example 2 with EmptyListException

use of org.apache.jena.rdf.model.EmptyListException in project jena by apache.

the class SecuredRDFListTest method testSetHead.

@Test
public void testSetHead() {
    try {
        RDFNode result = getSecuredRDFList().setHead(newResource1);
        if (!shouldRead() || !securityEvaluator.evaluate(Action.Update)) {
            fail("Should have thrown AccessDeniedException");
        }
        assertEquals(resource1, result);
        List<RDFNode> lst = ((RDFList) getBaseRDFNode()).asJavaList();
        Iterator<RDFNode> iter = lst.iterator();
        assertEquals(newResource1, iter.next());
        assertEquals(resource2, iter.next());
        assertEquals(resource3, iter.next());
        assertEquals(resource4, iter.next());
        assertFalse(iter.hasNext());
    } catch (final AccessDeniedException e) {
        if (shouldRead() && securityEvaluator.evaluate(Action.Update) && securityEvaluator.evaluate(Action.Delete)) {
            fail("Should not have thrown AccessDeniedException");
        }
    } catch (final EmptyListException e) {
        if (securityEvaluator.evaluate(Action.Read)) {
            fail("Should not have thrown EmptyListException");
        }
    }
}
Also used : AccessDeniedException(org.apache.jena.shared.AccessDeniedException) RDFList(org.apache.jena.rdf.model.RDFList) EmptyListException(org.apache.jena.rdf.model.EmptyListException) RDFNode(org.apache.jena.rdf.model.RDFNode) Test(org.junit.Test)

Example 3 with EmptyListException

use of org.apache.jena.rdf.model.EmptyListException in project jena by apache.

the class SecuredRDFListTest method testRemoveHead.

@Test
public void testRemoveHead() {
    try {
        RDFList rdfList = getSecuredRDFList().removeHead();
        if (!shouldRead() || !securityEvaluator.evaluate(Action.Update) || !securityEvaluator.evaluate(Action.Delete)) {
            fail("Should have thrown AccessDeniedException");
        }
        Iterator<RDFNode> iter = rdfList.asJavaList().iterator();
        assertEquals(resource2, iter.next());
        assertEquals(resource3, iter.next());
        assertEquals(resource4, iter.next());
        assertFalse(iter.hasNext());
    } catch (final AccessDeniedException e) {
        if (shouldRead() && securityEvaluator.evaluate(Action.Update) && securityEvaluator.evaluate(Action.Delete)) {
            fail("Should not have thrown AccessDeniedException");
        }
    } catch (final EmptyListException e) {
        if (securityEvaluator.evaluate(Action.Read)) {
            fail("Should not have thrown EmptyListException");
        }
    }
}
Also used : AccessDeniedException(org.apache.jena.shared.AccessDeniedException) RDFList(org.apache.jena.rdf.model.RDFList) EmptyListException(org.apache.jena.rdf.model.EmptyListException) RDFNode(org.apache.jena.rdf.model.RDFNode) Test(org.junit.Test)

Aggregations

EmptyListException (org.apache.jena.rdf.model.EmptyListException)3 RDFList (org.apache.jena.rdf.model.RDFList)3 RDFNode (org.apache.jena.rdf.model.RDFNode)2 AccessDeniedException (org.apache.jena.shared.AccessDeniedException)2 Test (org.junit.Test)2 SecuredRDFList (org.apache.jena.permissions.model.SecuredRDFList)1 Statement (org.apache.jena.rdf.model.Statement)1