DS-3190: Refactor org.dspace.rdf.* to use spring.

dspace-rdf was developed as standalone module. At the end of the
development most of it was moved to be included into dspace-api. Instead
of using Spring it used its own class that instantiated all necessary
classes. This PR solves the problem described in DS-3190 by refactoring
org.dspace.rdf to adapt patterns used in DSpace 6. It introduces
[dspace]/config/spring/api/rdf.xml to configure spring to instantiate
all necessary classes. org.dspace.rdf.RDFConfiguration was removed
completely, the configuration keys are centralised in
org.dspace.rdf.RDFUtil. Instead of org.dspace.rdf.RDFConfiguration and
DSpace's old ConfigurationManager the new ConfigurationService is now
used everywhere. Configuration properties shouldn't be hold in variables
anymore so that RDF profits from the new autoreload function from
DS-2654.
This commit is contained in:
Pascal-Nicolas Becker
2016-04-28 21:55:31 +02:00
parent 2e309a116f
commit 90447ed0b1
18 changed files with 462 additions and 627 deletions

View File

@@ -24,6 +24,8 @@ import org.dspace.content.Site;
import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.core.Constants;
import org.dspace.core.Context;
import org.dspace.rdf.factory.RDFFactory;
import org.dspace.services.factory.DSpaceServicesFactory;
/**
*
@@ -32,6 +34,54 @@ import org.dspace.core.Context;
public class RDFUtil {
private static final Logger log = Logger.getLogger(RDFUtil.class);
private static final AuthorizeService authorizeService = AuthorizeServiceFactory.getInstance().getAuthorizeService();
public static final String CONTENT_NEGOTIATION_KEY = "rdf.contentNegotiation.enable";
/**
* Key of the Property to load the types of DSpaceObjects that should get
* converted.
*/
public static final String CONVERTER_DSOTYPES_KEY = "rdf.converter.DSOtypes";
/**
* Property key to load the password if authentication for the graph store
* endpoint is required.
*/
public static final String STORAGE_GRAPHSTORE_PASSWORD_KEY = "rdf.storage.graphstore.password";
/**
* Property key to load the URL of the dspace-rdf module. This is necessary
* to create links from the jspui or xmlui to RDF representation of
* DSpaceObjects.
*/
public static final String CONTEXT_PATH_KEY = "rdf.contextPath";
/**
* Property key to load the public address of the SPARQL endpoint.
*/
public static final String SPARQL_ENDPOINT_KEY = "rdf.public.sparql.endpoint";
/**
* Property key to load the username if authentication for the internal
* SPARQL endpoint is required.
*/
public static final String STORAGE_SPARQL_LOGIN_KEY = "rdf.storage.sparql.login";
/**
* Property key to load the password if authentication for the internal
* SPARQL endpoint is required.
*/
public static final String STORAGE_SPARQL_PASSWORD_KEY = "rdf.storage.sparql.password";
/**
* Property key to load the address of the SPARQL 1.1 GRAPH STORE HTTP
* PROTOCOL endpoint.
*/
public static final String STORAGE_GRAPHSTORE_ENDPOINT_KEY = "rdf.storage.graphstore.endpoint";
/**
* Property key to load the address of the SPARQL endpoint to use within
* DSpace. If the property is empty or does not exist, the public SPARQL
* endpoint will be used.
*/
public static final String STORAGE_SPARQL_ENDPOINT_KEY = "rdf.storage.sparql.endpoint";
/**
* Property key to load the username if authentication for the graph store
* endpoint is required.
*/
public static final String STORAGE_GRAPHSTORE_LOGIN_KEY = "rdf.storage.graphstore.login";
/**
* Loads converted data of a DSpaceObject identified by the URI provided
@@ -45,7 +95,7 @@ public class RDFUtil {
*/
public static Model loadModel(String identifier)
{
return RDFConfiguration.getRDFStorage().load(identifier);
return RDFFactory.getInstance().getRDFStorage().load(identifier);
}
/**
@@ -65,7 +115,7 @@ public class RDFUtil {
public static String generateIdentifier(Context context, DSpaceObject dso)
throws SQLException
{
return RDFConfiguration.getURIGenerator().generateIdentifier(context, dso);
return RDFFactory.getInstance().getURIGenerator().generateIdentifier(context, dso);
}
/**
@@ -89,7 +139,7 @@ public class RDFUtil {
String handle, List<String> identifier)
throws SQLException
{
return RDFConfiguration.getURIGenerator().generateIdentifier(context,
return RDFFactory.getInstance().getURIGenerator().generateIdentifier(context,
type, id, handle, identifier);
}
/**
@@ -124,22 +174,33 @@ public class RDFUtil {
ItemWithdrawnException, ItemNotDiscoverableException,
AuthorizeException, IllegalArgumentException
{
if (dso.getType() != Constants.SITE
&& dso.getType() != Constants.COMMUNITY
&& dso.getType() != Constants.COLLECTION
&& dso.getType() != Constants.ITEM)
String[] dsoTypes = DSpaceServicesFactory.getInstance()
.getConfigurationService()
.getArrayProperty(CONVERTER_DSOTYPES_KEY);
if (dsoTypes == null || dsoTypes.length == 0)
{
throw new IllegalArgumentException(ContentServiceFactory.getInstance().getDSpaceObjectService(dso).getTypeText(dso)
+ " is currently not supported as independent entity.");
log.warn("Property rdf." + CONVERTER_DSOTYPES_KEY + " was not found "
+ "or is empty. Will convert all type of DSpace Objects.");
} else {
boolean found = false;
for (String type : dsoTypes)
{
if (StringUtils.equalsIgnoreCase(Constants.typeText[dso.getType()], type.trim()))
{
found = true;
break;
}
}
if (!found)
{
log.warn("Configuration of DSpaceObjects of type "
+ Constants.typeText[dso.getType()]
+ " prohibitted by configuration.");
return null;
}
}
if (!RDFConfiguration.isConvertType(ContentServiceFactory.getInstance().getDSpaceObjectService(dso).getTypeText(dso)))
{
return null;
}
isPublic(context, dso);
return RDFConfiguration.getRDFConverter().convert(context, dso);
return RDFFactory.getInstance().getRDFConverter().convert(context, dso);
}
/**
@@ -190,11 +251,11 @@ public class RDFUtil {
{
// if data about this dso is stored in the triplestore already, we
// should remove it as a conversion currently result in no data
RDFConfiguration.getRDFStorage().delete(identifier);
RDFFactory.getInstance().getRDFStorage().delete(identifier);
return null;
}
RDFConfiguration.getRDFStorage().store(identifier, convertedData);
RDFFactory.getInstance().getRDFStorage().store(identifier, convertedData);
return convertedData;
}
@@ -274,7 +335,7 @@ public class RDFUtil {
*/
public static void delete(String uri)
{
RDFConfiguration.getRDFStorage().delete(uri);
RDFFactory.getInstance().getRDFStorage().delete(uri);
}
/**
@@ -290,11 +351,11 @@ public class RDFUtil {
public static void delete(Context ctx, int type, UUID id, String handle, List<String> identifiers)
throws SQLException, RDFMissingIdentifierException
{
String uri = RDFConfiguration.getURIGenerator().generateIdentifier(ctx,
type, id, handle, identifiers);
String uri = RDFFactory.getInstance().getURIGenerator()
.generateIdentifier(ctx, type, id, handle, identifiers);
if (uri != null)
{
RDFConfiguration.getRDFStorage().delete(uri);
RDFFactory.getInstance().getRDFStorage().delete(uri);
} else {
throw new RDFMissingIdentifierException(type, id);
}