001/**
002 * Copyright 2015 DuraSpace, Inc.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.fcrepo.kernel.impl.rdf.impl;
017
018import com.hp.hpl.jena.rdf.model.Resource;
019import org.fcrepo.kernel.models.FedoraResource;
020import org.fcrepo.kernel.identifiers.IdentifierConverter;
021
022import javax.jcr.RepositoryException;
023import java.security.AccessControlException;
024
025import static com.hp.hpl.jena.datatypes.xsd.XSDDatatype.XSDboolean;
026import static com.hp.hpl.jena.graph.NodeFactory.createLiteral;
027import static com.hp.hpl.jena.graph.Triple.create;
028import static org.fcrepo.kernel.RdfLexicon.WRITABLE;
029
030/**
031 * @author cabeer
032 * @since 10/1/14
033 */
034public class AclRdfContext extends NodeRdfContext {
035    /**
036     * Default constructor.
037     *
038     * @param resource the resource
039     * @param idTranslator the property of idTranslator
040     * @throws javax.jcr.RepositoryException if repository exception occurred
041     */
042    public AclRdfContext(final FedoraResource resource,
043                         final IdentifierConverter<Resource, FedoraResource> idTranslator) throws RepositoryException {
044        super(resource, idTranslator);
045
046        // include writable status
047        concatWritable();
048    }
049
050    private void concatWritable() throws RepositoryException {
051        boolean writable = false;
052        try {
053            resource().getNode().getSession().checkPermission( resource().getPath(), "add_node,set_property,remove" );
054            writable = true;
055        } catch ( AccessControlException ex ) {
056            writable = false;
057        }
058
059        concat(create(subject(), WRITABLE.asNode(), createLiteral(String.valueOf(writable), XSDboolean)));
060    }
061
062}