001/*
002 * Licensed to DuraSpace under one or more contributor license agreements.
003 * See the NOTICE file distributed with this work for additional information
004 * regarding copyright ownership.
005 *
006 * DuraSpace licenses this file to you under the Apache License,
007 * Version 2.0 (the "License"); you may not use this file except in
008 * compliance with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.fcrepo.kernel.impl.models;
019
020import org.fcrepo.kernel.api.Transaction;
021import org.fcrepo.kernel.api.identifiers.FedoraId;
022import org.fcrepo.kernel.api.models.Container;
023import org.fcrepo.kernel.api.models.FedoraResource;
024import org.fcrepo.kernel.api.models.ResourceFactory;
025import org.fcrepo.persistence.api.PersistentStorageSessionManager;
026
027import java.net.URI;
028import java.util.List;
029import java.util.stream.Stream;
030
031import static org.fcrepo.kernel.api.RdfLexicon.CONTAINER;
032import static org.fcrepo.kernel.api.RdfLexicon.FEDORA_CONTAINER;
033import static org.fcrepo.kernel.api.RdfLexicon.RDF_SOURCE;
034
035
036/**
037 * Implementation of an LDP Container resource
038 *
039 * @author bbpennel
040 */
041public class ContainerImpl extends FedoraResourceImpl implements Container {
042
043    private static final URI RDF_SOURCE_URI = URI.create(RDF_SOURCE.toString());
044    private static final URI CONTAINER_URI = URI.create(CONTAINER.toString());
045    private static final URI FEDORA_CONTAINER_URI = URI.create(FEDORA_CONTAINER.toString());
046
047    /**
048     * Construct the container
049     *
050     * @param fedoraID internal identifier
051     * @param transaction transaction
052     * @param pSessionManager session manager
053     * @param resourceFactory resource factory
054     */
055    public ContainerImpl(final FedoraId fedoraID, final Transaction transaction,
056                         final PersistentStorageSessionManager pSessionManager, final ResourceFactory resourceFactory) {
057        super(fedoraID, transaction, pSessionManager, resourceFactory);
058    }
059
060    @Override
061    public FedoraResource getDescribedResource() {
062        return this;
063    }
064
065    @Override
066    public List<URI> getSystemTypes(final boolean forRdf) {
067        var types = resolveSystemTypes(forRdf);
068
069        if (types == null) {
070            types = super.getSystemTypes(forRdf);
071            types.add(RDF_SOURCE_URI);
072            types.add(CONTAINER_URI);
073            types.add(FEDORA_CONTAINER_URI);
074        }
075
076        return types;
077    }
078
079    @Override
080    public Stream<FedoraResource> getChildren(final Boolean recursive) {
081        return resourceFactory.getChildren(transaction, fedoraId);
082    }
083}