001/*
002 * The contents of this file are subject to the license and copyright
003 * detailed in the LICENSE and NOTICE files at the root of the source
004 * tree.
005 */
006package org.fcrepo.kernel.impl.models;
007
008import org.fcrepo.kernel.api.Transaction;
009import org.fcrepo.kernel.api.cache.UserTypesCache;
010import org.fcrepo.kernel.api.identifiers.FedoraId;
011import org.fcrepo.kernel.api.models.Container;
012import org.fcrepo.kernel.api.models.FedoraResource;
013import org.fcrepo.kernel.api.models.ResourceFactory;
014import org.fcrepo.persistence.api.PersistentStorageSessionManager;
015
016import java.net.URI;
017import java.util.List;
018import java.util.stream.Stream;
019
020import static org.fcrepo.kernel.api.RdfLexicon.CONTAINER;
021import static org.fcrepo.kernel.api.RdfLexicon.FEDORA_CONTAINER;
022import static org.fcrepo.kernel.api.RdfLexicon.RDF_SOURCE;
023
024
025/**
026 * Implementation of an LDP Container resource
027 *
028 * @author bbpennel
029 */
030public class ContainerImpl extends FedoraResourceImpl implements Container {
031
032    private static final URI RDF_SOURCE_URI = URI.create(RDF_SOURCE.toString());
033    private static final URI CONTAINER_URI = URI.create(CONTAINER.toString());
034    private static final URI FEDORA_CONTAINER_URI = URI.create(FEDORA_CONTAINER.toString());
035
036    /**
037     * Construct the container
038     *
039     * @param fedoraID internal identifier
040     * @param transaction transaction
041     * @param pSessionManager session manager
042     * @param resourceFactory resource factory
043     * @param userTypesCache the user types cache
044     */
045    public ContainerImpl(final FedoraId fedoraID,
046                         final Transaction transaction,
047                         final PersistentStorageSessionManager pSessionManager,
048                         final ResourceFactory resourceFactory,
049                         final UserTypesCache userTypesCache) {
050        super(fedoraID, transaction, pSessionManager, resourceFactory, userTypesCache);
051    }
052
053    @Override
054    public FedoraResource getDescribedResource() {
055        return this;
056    }
057
058    @Override
059    public List<URI> getSystemTypes(final boolean forRdf) {
060        var types = resolveSystemTypes(forRdf);
061
062        if (types == null) {
063            types = super.getSystemTypes(forRdf);
064            types.add(RDF_SOURCE_URI);
065            types.add(CONTAINER_URI);
066            types.add(FEDORA_CONTAINER_URI);
067        }
068
069        return types;
070    }
071
072    @Override
073    public Stream<FedoraResource> getChildren(final Boolean recursive) {
074        return resourceFactory.getChildren(transaction, fedoraId);
075    }
076}