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.http.commons;
019
020import java.util.function.Supplier;
021
022import javax.inject.Inject;
023import javax.ws.rs.core.Context;
024import javax.ws.rs.core.HttpHeaders;
025import javax.ws.rs.core.UriInfo;
026
027import org.fcrepo.config.FedoraPropsConfig;
028import org.fcrepo.kernel.api.models.ResourceFactory;
029import org.fcrepo.kernel.api.services.VersionService;
030import org.fcrepo.kernel.api.services.functions.ConfigurableHierarchicalSupplier;
031import org.fcrepo.kernel.api.services.functions.UniqueValueSupplier;
032
033import org.jvnet.hk2.annotations.Optional;
034
035/**
036 * Superclass for Fedora JAX-RS Resources, providing convenience fields and methods.
037 *
038 * @author ajs6f
039 */
040public class AbstractResource {
041
042    @Inject
043    protected FedoraPropsConfig fedoraPropsConfig;
044
045    /**
046     * Useful for constructing URLs
047     */
048    @Context
049    protected UriInfo uriInfo;
050
051    /**
052     * For getting user agent
053     */
054    @Context
055    protected HttpHeaders headers;
056
057    @Inject
058    protected ResourceFactory resourceFactory;
059
060    /**
061     * The version service
062     */
063    @Inject
064    protected VersionService versionService;
065
066    /**
067     * A resource that can mint new Fedora PIDs.
068     */
069    @Inject
070    @Optional
071    protected Supplier<String> pidMinter;
072
073    // Mint non-hierarchical identifiers. To force pairtree creation as default, use
074    //  ConfigurableHierarchicalSupplier(int length, count) instead.
075    protected UniqueValueSupplier defaultPidMinter = new ConfigurableHierarchicalSupplier();
076
077}