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.identifiers.FedoraId;
021import org.fcrepo.kernel.api.models.Container;
022import org.fcrepo.kernel.api.models.FedoraResource;
023import org.fcrepo.kernel.api.models.ResourceFactory;
024import org.fcrepo.persistence.api.PersistentStorageSessionManager;
025
026import java.net.URI;
027import java.util.List;
028import java.util.stream.Stream;
029
030import static org.fcrepo.kernel.api.RdfLexicon.CONTAINER;
031import static org.fcrepo.kernel.api.RdfLexicon.FEDORA_CONTAINER;
032import static org.fcrepo.kernel.api.RdfLexicon.RDF_SOURCE;
033
034
035/**
036 * Implementation of an LDP Container resource
037 *
038 * @author bbpennel
039 */
040public class ContainerImpl extends FedoraResourceImpl implements Container {
041
042    private static final URI RDF_SOURCE_URI = URI.create(RDF_SOURCE.toString());
043    private static final URI CONTAINER_URI = URI.create(CONTAINER.toString());
044    private static final URI FEDORA_CONTAINER_URI = URI.create(FEDORA_CONTAINER.toString());
045
046    /**
047     * Construct the container
048     *
049     * @param fedoraID internal identifier
050     * @param txId transaction id
051     * @param pSessionManager session manager
052     * @param resourceFactory resource factory
053     */
054    public ContainerImpl(final FedoraId fedoraID, final String txId,
055                         final PersistentStorageSessionManager pSessionManager, final ResourceFactory resourceFactory) {
056        super(fedoraID, txId, pSessionManager, resourceFactory);
057    }
058
059    @Override
060    public FedoraResource getDescribedResource() {
061        return this;
062    }
063
064    @Override
065    public List<URI> getSystemTypes(final boolean forRdf) {
066        var types = resolveSystemTypes(forRdf);
067
068        if (types == null) {
069            types = super.getSystemTypes(forRdf);
070            types.add(RDF_SOURCE_URI);
071            types.add(CONTAINER_URI);
072            types.add(FEDORA_CONTAINER_URI);
073        }
074
075        return types;
076    }
077
078    @Override
079    public Stream<FedoraResource> getChildren(final Boolean recursive) {
080        return resourceFactory.getChildren(txId, fedoraId);
081    }
082}