All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.dspace.rdf.storage.LocalURIGenerator Maven / Gradle / Ivy

There is a newer version: 8.0
Show newest version
/**
 * The contents of this file are subject to the license and copyright
 * detailed in the LICENSE and NOTICE files at the root of the source
 * tree and available online at
 *
 * http://www.dspace.org/license/
 */

package org.dspace.rdf.storage;

import java.sql.SQLException;
import java.util.List;
import java.util.UUID;

import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.Logger;
import org.dspace.content.DSpaceObject;
import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.content.service.SiteService;
import org.dspace.core.Constants;
import org.dspace.core.Context;
import org.dspace.rdf.RDFUtil;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author Pascal-Nicolas Becker (dspace -at- pascal -hyphen- becker -dot- de)
 */
public class LocalURIGenerator implements URIGenerator {
    private static final Logger log = org.apache.logging.log4j.LogManager.getLogger(LocalURIGenerator.class);

    @Autowired(required = true)
    protected SiteService siteService;

    @Override
    public String generateIdentifier(Context context, int type, UUID id,
                                     String handle, List identifiers)
        throws SQLException {
        String urlPrefix = DSpaceServicesFactory.getInstance().getConfigurationService()
                                                .getProperty(RDFUtil.CONTEXT_PATH_KEY) + "/resource/";

        if (type == Constants.SITE) {
            return urlPrefix + siteService.findSite(context).getHandle();
        }

        if (type == Constants.COMMUNITY
            || type == Constants.COLLECTION
            || type == Constants.ITEM) {
            if (StringUtils.isEmpty(handle)) {
                throw new IllegalArgumentException("Handle is null");
            }
            return urlPrefix + handle;
        }

        return null;
    }

    @Override
    public String generateIdentifier(Context context, DSpaceObject dso) throws SQLException {
        if (dso.getType() != Constants.SITE
            && dso.getType() != Constants.COMMUNITY
            && dso.getType() != Constants.COLLECTION
            && dso.getType() != Constants.ITEM) {
            return null;
        }

        return generateIdentifier(context, dso.getType(), dso.getID(), dso.getHandle(),
                                  ContentServiceFactory.getInstance().getDSpaceObjectService(dso)
                                                       .getIdentifiers(context, dso));
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy