mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-17 23:13:10 +00:00
resolve cherry-pick issue
This commit is contained in:
@@ -316,7 +316,31 @@ public abstract class DSpaceObjectServiceImpl<T extends DSpaceObject> implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addMetadata(Context context, T dso, MetadataField metadataField, String language, String value) throws SQLException {
|
public void addMetadata(Context context, T dso, MetadataField metadataField, String language, String value) throws SQLException {
|
||||||
addMetadata(context, dso, metadataField, language, Arrays.asList(value), null, null);
|
addMetadata(context, dso, metadataField, language, Arrays.asList(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addMetadata(Context context, T dso, MetadataField metadataField, String language, List<String> values) throws SQLException {
|
||||||
|
String fieldKey = metadataAuthorityService.makeFieldKey(metadataField.getMetadataSchema().getName(), metadataField.getElement(), metadataField.getQualifier());
|
||||||
|
if (metadataAuthorityService.isAuthorityControlled(fieldKey))
|
||||||
|
{
|
||||||
|
List<String> authorities = new ArrayList<String>();
|
||||||
|
List<Integer> confidences = new ArrayList<Integer>();
|
||||||
|
for (int i = 0; i < values.size(); ++i)
|
||||||
|
{
|
||||||
|
if(dso instanceof Item)
|
||||||
|
{
|
||||||
|
getAuthoritiesAndConfidences(fieldKey, ((Item) dso).getOwningCollection(), values, authorities, confidences, i);
|
||||||
|
}else{
|
||||||
|
getAuthoritiesAndConfidences(fieldKey, null, values, authorities, confidences, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
addMetadata(context, dso, metadataField, language, values, authorities, confidences);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
addMetadata(context, dso, metadataField, language, values, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -0,0 +1,115 @@
|
|||||||
|
/**
|
||||||
|
* 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.content.crosswalk;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.tuple.ImmutableTriple;
|
||||||
|
import org.apache.commons.lang3.tuple.Triple;
|
||||||
|
import org.dspace.authorize.AuthorizeException;
|
||||||
|
import org.dspace.content.MetadataField;
|
||||||
|
import org.dspace.content.MetadataSchema;
|
||||||
|
import org.dspace.content.NonUniqueMetadataException;
|
||||||
|
import org.dspace.content.factory.ContentServiceFactory;
|
||||||
|
import org.dspace.content.service.MetadataFieldService;
|
||||||
|
import org.dspace.content.service.MetadataSchemaService;
|
||||||
|
import org.dspace.core.ConfigurationManager;
|
||||||
|
import org.dspace.core.Context;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class CrosswalkMetadataValidator {
|
||||||
|
|
||||||
|
protected MetadataSchemaService metadataSchemaService;
|
||||||
|
protected MetadataFieldService metadataFieldService;
|
||||||
|
|
||||||
|
private String schemaChoice;
|
||||||
|
private String fieldChoice;
|
||||||
|
|
||||||
|
private Map<Triple<String, String, String>, MetadataField> validatedMetadataFields;
|
||||||
|
|
||||||
|
public CrosswalkMetadataValidator() {
|
||||||
|
metadataSchemaService = ContentServiceFactory.getInstance().getMetadataSchemaService();
|
||||||
|
metadataFieldService = ContentServiceFactory.getInstance().getMetadataFieldService();
|
||||||
|
|
||||||
|
validatedMetadataFields = new HashMap<>();
|
||||||
|
|
||||||
|
// The two options, with three possibilities each: add, ignore, fail
|
||||||
|
schemaChoice = ConfigurationManager.getProperty("oai", "harvester.unknownSchema");
|
||||||
|
if (schemaChoice == null)
|
||||||
|
{
|
||||||
|
schemaChoice = "fail";
|
||||||
|
}
|
||||||
|
|
||||||
|
fieldChoice = ConfigurationManager.getProperty("oai", "harvester.unknownField");
|
||||||
|
if (fieldChoice == null)
|
||||||
|
{
|
||||||
|
fieldChoice = "fail";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scans metadata for elements not defined in this DSpace instance. It then takes action based
|
||||||
|
* on a configurable parameter (fail, ignore, add).
|
||||||
|
*/
|
||||||
|
public MetadataField checkMetadata(Context context, String schema, String element, String qualifier, boolean forceCreate) throws SQLException, AuthorizeException, CrosswalkException {
|
||||||
|
if(!validatedBefore(schema, element, qualifier)) {
|
||||||
|
// Verify that the schema exists
|
||||||
|
MetadataSchema mdSchema = metadataSchemaService.find(context, schema);
|
||||||
|
MetadataField mdField = null;
|
||||||
|
|
||||||
|
if (mdSchema == null) {
|
||||||
|
// add a new schema, giving it a namespace of "unknown". Possibly a very bad idea.
|
||||||
|
if (forceCreate && schemaChoice.equals("add")) {
|
||||||
|
try {
|
||||||
|
mdSchema = metadataSchemaService.create(context, schema, String.valueOf(new Date().getTime()));
|
||||||
|
mdSchema.setNamespace("unknown" + mdSchema.getSchemaID());
|
||||||
|
metadataSchemaService.update(context, mdSchema);
|
||||||
|
} catch (NonUniqueMetadataException e) {
|
||||||
|
// This case should not be possible
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ignore the offending schema, quietly dropping all of its metadata elements before they clog our gears
|
||||||
|
else if (!schemaChoice.equals("ignore")) {
|
||||||
|
throw new CrosswalkException("The '" + schema + "' schema has not been defined in this DSpace instance. ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mdSchema != null) {
|
||||||
|
// Verify that the element exists; this part is reachable only if the metadata schema is valid
|
||||||
|
mdField = metadataFieldService.findByElement(context, mdSchema, element, qualifier);
|
||||||
|
if (mdField == null) {
|
||||||
|
if (forceCreate && fieldChoice.equals("add")) {
|
||||||
|
try {
|
||||||
|
metadataFieldService.create(context, mdSchema, element, qualifier, null);
|
||||||
|
} catch (NonUniqueMetadataException e) {
|
||||||
|
// This case should also not be possible
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
} else if (!fieldChoice.equals("ignore")) {
|
||||||
|
throw new CrosswalkException("The '" + element + "." + qualifier + "' element has not been defined in this DSpace instance. ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
validatedMetadataFields.put(createKey(schema, element, qualifier), mdField);
|
||||||
|
}
|
||||||
|
|
||||||
|
return validatedMetadataFields.get(createKey(schema, element, qualifier));
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean validatedBefore(String schema, String element, String qualifier) {
|
||||||
|
return validatedMetadataFields.containsKey(createKey(schema, element, qualifier));
|
||||||
|
}
|
||||||
|
|
||||||
|
private ImmutableTriple<String, String, String> createKey(final String schema, final String element, final String qualifier) {
|
||||||
|
return new ImmutableTriple<String, String, String>(schema, element, qualifier);
|
||||||
|
}
|
||||||
|
}
|
@@ -1,93 +0,0 @@
|
|||||||
/**
|
|
||||||
* 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.content.crosswalk;
|
|
||||||
|
|
||||||
import org.dspace.authorize.AuthorizeException;
|
|
||||||
import org.dspace.content.MetadataField;
|
|
||||||
import org.dspace.content.MetadataSchema;
|
|
||||||
import org.dspace.content.NonUniqueMetadataException;
|
|
||||||
import org.dspace.content.factory.ContentServiceFactory;
|
|
||||||
import org.dspace.content.service.MetadataFieldService;
|
|
||||||
import org.dspace.content.service.MetadataSchemaService;
|
|
||||||
import org.dspace.core.ConfigurationManager;
|
|
||||||
import org.dspace.core.Context;
|
|
||||||
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
public class CrosswalkUtils {
|
|
||||||
|
|
||||||
protected static final MetadataSchemaService metadataSchemaService = ContentServiceFactory.getInstance().getMetadataSchemaService();
|
|
||||||
protected static final MetadataFieldService metadataFieldService = ContentServiceFactory.getInstance().getMetadataFieldService();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Scans metadata for elements not defined in this DSpace instance. It then takes action based
|
|
||||||
* on a configurable parameter (fail, ignore, add).
|
|
||||||
* @param context context
|
|
||||||
* @param schema schema
|
|
||||||
* @param element element
|
|
||||||
* @param qualifier qualifier
|
|
||||||
* @param forceCreate force create flag
|
|
||||||
* @throws SQLException if database error
|
|
||||||
* @throws AuthorizeException if authorization error
|
|
||||||
* @throws CrosswalkException if crosswalk error
|
|
||||||
*/
|
|
||||||
public static void checkMetadata(Context context, String schema, String element, String qualifier, boolean forceCreate) throws SQLException, AuthorizeException, CrosswalkException {
|
|
||||||
// The two options, with three possibilities each: add, ignore, fail
|
|
||||||
String schemaChoice = ConfigurationManager.getProperty("oai", "harvester.unknownSchema");
|
|
||||||
if (schemaChoice == null)
|
|
||||||
{
|
|
||||||
schemaChoice = "fail";
|
|
||||||
}
|
|
||||||
|
|
||||||
String fieldChoice = ConfigurationManager.getProperty("oai", "harvester.unknownField");
|
|
||||||
if (fieldChoice == null)
|
|
||||||
{
|
|
||||||
fieldChoice = "fail";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Verify that the schema exists
|
|
||||||
MetadataSchema mdSchema = metadataSchemaService.find(context, schema);
|
|
||||||
if (mdSchema == null) {
|
|
||||||
// add a new schema, giving it a namespace of "unknown". Possibly a very bad idea.
|
|
||||||
if (forceCreate && schemaChoice.equals("add"))
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
mdSchema = metadataSchemaService.create(context, schema, String.valueOf(new Date().getTime()));
|
|
||||||
mdSchema.setNamespace("unknown"+mdSchema.getSchemaID());
|
|
||||||
metadataSchemaService.update(context, mdSchema);
|
|
||||||
} catch (NonUniqueMetadataException e) {
|
|
||||||
// This case should not be possible
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// ignore the offending schema, quietly dropping all of its metadata elements before they clog our gears
|
|
||||||
else if (!schemaChoice.equals("ignore")) {
|
|
||||||
throw new CrosswalkException("The '" + schema + "' schema has not been defined in this DSpace instance. ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mdSchema != null) {
|
|
||||||
// Verify that the element exists; this part is reachable only if the metadata schema is valid
|
|
||||||
MetadataField mdField = metadataFieldService.findByElement(context, mdSchema, element, qualifier);
|
|
||||||
if (mdField == null) {
|
|
||||||
if (forceCreate && fieldChoice.equals("add")) {
|
|
||||||
try {
|
|
||||||
metadataFieldService.create(context, mdSchema, element, qualifier, null);
|
|
||||||
} catch (NonUniqueMetadataException e) {
|
|
||||||
// This case should also not be possible
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (!fieldChoice.equals("ignore")) {
|
|
||||||
throw new CrosswalkException("The '" + element + "." + qualifier + "' element has not been defined in this DSpace instance. ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -7,13 +7,10 @@
|
|||||||
*/
|
*/
|
||||||
package org.dspace.content.crosswalk;
|
package org.dspace.content.crosswalk;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.dspace.authorize.AuthorizeException;
|
import org.dspace.authorize.AuthorizeException;
|
||||||
import org.dspace.content.DSpaceObject;
|
import org.dspace.content.DSpaceObject;
|
||||||
import org.dspace.content.Item;
|
import org.dspace.content.Item;
|
||||||
|
import org.dspace.content.MetadataField;
|
||||||
import org.dspace.content.factory.ContentServiceFactory;
|
import org.dspace.content.factory.ContentServiceFactory;
|
||||||
import org.dspace.content.service.ItemService;
|
import org.dspace.content.service.ItemService;
|
||||||
import org.dspace.core.Constants;
|
import org.dspace.core.Constants;
|
||||||
@@ -21,6 +18,10 @@ import org.dspace.core.Context;
|
|||||||
import org.jdom.Element;
|
import org.jdom.Element;
|
||||||
import org.jdom.Namespace;
|
import org.jdom.Namespace;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DIM ingestion crosswalk
|
* DIM ingestion crosswalk
|
||||||
* <p>
|
* <p>
|
||||||
@@ -33,7 +34,7 @@ public class DIMIngestionCrosswalk implements IngestionCrosswalk
|
|||||||
{
|
{
|
||||||
private static final Namespace DIM_NS = Namespace.getNamespace("http://www.dspace.org/xmlns/dspace/dim");
|
private static final Namespace DIM_NS = Namespace.getNamespace("http://www.dspace.org/xmlns/dspace/dim");
|
||||||
protected ItemService itemService = ContentServiceFactory.getInstance().getItemService();
|
protected ItemService itemService = ContentServiceFactory.getInstance().getItemService();
|
||||||
|
private CrosswalkMetadataValidator metadataValidator = new CrosswalkMetadataValidator();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void ingest(Context context, DSpaceObject dso, List<Element> metadata, boolean createMissingMetadataFields) throws CrosswalkException, IOException, SQLException, AuthorizeException {
|
public void ingest(Context context, DSpaceObject dso, List<Element> metadata, boolean createMissingMetadataFields) throws CrosswalkException, IOException, SQLException, AuthorizeException {
|
||||||
@@ -69,8 +70,8 @@ public class DIMIngestionCrosswalk implements IngestionCrosswalk
|
|||||||
String schema = field.getAttributeValue("mdschema");
|
String schema = field.getAttributeValue("mdschema");
|
||||||
String element = field.getAttributeValue("element");
|
String element = field.getAttributeValue("element");
|
||||||
String qualifier = field.getAttributeValue("qualifier");
|
String qualifier = field.getAttributeValue("qualifier");
|
||||||
CrosswalkUtils.checkMetadata(context, schema, element, qualifier, createMissingMetadataFields);
|
MetadataField metadataField = metadataValidator.checkMetadata(context, schema, element, qualifier, createMissingMetadataFields);
|
||||||
itemService.addMetadata(context, item, schema, element, qualifier,
|
itemService.addMetadata(context, item, metadataField,
|
||||||
field.getAttributeValue("lang"), field.getText());
|
field.getAttributeValue("lang"), field.getText());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -7,13 +7,10 @@
|
|||||||
*/
|
*/
|
||||||
package org.dspace.content.crosswalk;
|
package org.dspace.content.crosswalk;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.dspace.authorize.AuthorizeException;
|
import org.dspace.authorize.AuthorizeException;
|
||||||
import org.dspace.content.DSpaceObject;
|
import org.dspace.content.DSpaceObject;
|
||||||
import org.dspace.content.Item;
|
import org.dspace.content.Item;
|
||||||
|
import org.dspace.content.MetadataField;
|
||||||
import org.dspace.content.MetadataSchema;
|
import org.dspace.content.MetadataSchema;
|
||||||
import org.dspace.content.factory.ContentServiceFactory;
|
import org.dspace.content.factory.ContentServiceFactory;
|
||||||
import org.dspace.content.service.ItemService;
|
import org.dspace.content.service.ItemService;
|
||||||
@@ -22,6 +19,10 @@ import org.dspace.core.Context;
|
|||||||
import org.jdom.Element;
|
import org.jdom.Element;
|
||||||
import org.jdom.Namespace;
|
import org.jdom.Namespace;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DIM ingestion crosswalk
|
* DIM ingestion crosswalk
|
||||||
* <p>
|
* <p>
|
||||||
@@ -34,6 +35,7 @@ public class OAIDCIngestionCrosswalk
|
|||||||
implements IngestionCrosswalk
|
implements IngestionCrosswalk
|
||||||
{
|
{
|
||||||
protected ItemService itemService = ContentServiceFactory.getInstance().getItemService();
|
protected ItemService itemService = ContentServiceFactory.getInstance().getItemService();
|
||||||
|
private CrosswalkMetadataValidator metadataValidator = new CrosswalkMetadataValidator();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void ingest(Context context, DSpaceObject dso, List<Element> metadata, boolean createMissingMetadataFields) throws CrosswalkException, IOException, SQLException, AuthorizeException {
|
public void ingest(Context context, DSpaceObject dso, List<Element> metadata, boolean createMissingMetadataFields) throws CrosswalkException, IOException, SQLException, AuthorizeException {
|
||||||
@@ -64,8 +66,8 @@ public class OAIDCIngestionCrosswalk
|
|||||||
if (lang == null) {
|
if (lang == null) {
|
||||||
lang = element.getAttributeValue("lang");
|
lang = element.getAttributeValue("lang");
|
||||||
}
|
}
|
||||||
CrosswalkUtils.checkMetadata(context, MetadataSchema.DC_SCHEMA, element.getName(), null, createMissingMetadataFields);
|
MetadataField metadataField = metadataValidator.checkMetadata(context, MetadataSchema.DC_SCHEMA, element.getName(), null, createMissingMetadataFields);
|
||||||
itemService.addMetadata(context, item, "dc", element.getName(), null, lang, element.getText());
|
itemService.addMetadata(context, item, metadataField, lang, element.getText());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -7,18 +7,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.dspace.content.crosswalk;
|
package org.dspace.content.crosswalk;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.StringReader;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Enumeration;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
import org.apache.commons.lang.ArrayUtils;
|
import org.apache.commons.lang.ArrayUtils;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.dspace.authorize.AuthorizeException;
|
import org.dspace.authorize.AuthorizeException;
|
||||||
@@ -34,6 +22,13 @@ import org.jdom.Element;
|
|||||||
import org.jdom.Namespace;
|
import org.jdom.Namespace;
|
||||||
import org.jdom.input.SAXBuilder;
|
import org.jdom.input.SAXBuilder;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.StringReader;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configurable QDC Crosswalk
|
* Configurable QDC Crosswalk
|
||||||
* <p>
|
* <p>
|
||||||
@@ -122,6 +117,8 @@ public class QDCCrosswalk extends SelfNamedPlugin
|
|||||||
|
|
||||||
protected ItemService itemService = ContentServiceFactory.getInstance().getItemService();
|
protected ItemService itemService = ContentServiceFactory.getInstance().getItemService();
|
||||||
|
|
||||||
|
private CrosswalkMetadataValidator metadataValidator = new CrosswalkMetadataValidator();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fill in the plugin-name table from DSpace configuration entries
|
* Fill in the plugin-name table from DSpace configuration entries
|
||||||
* for configuration files for flavors of QDC crosswalk:
|
* for configuration files for flavors of QDC crosswalk:
|
||||||
@@ -468,7 +465,15 @@ public class QDCCrosswalk extends SelfNamedPlugin
|
|||||||
else if (element2qdc.containsKey(key))
|
else if (element2qdc.containsKey(key))
|
||||||
{
|
{
|
||||||
String qdc[] = (element2qdc.get(key)).split("\\.");
|
String qdc[] = (element2qdc.get(key)).split("\\.");
|
||||||
CrosswalkUtils.checkMetadata(context, qdc[0], qdc[1], qdc[2], createMissingMetadataFields);
|
|
||||||
|
MetadataField metadataField;
|
||||||
|
if (qdc.length == 3) {
|
||||||
|
metadataField = metadataValidator.checkMetadata(context, qdc[0], qdc[1], qdc[2], createMissingMetadataFields);
|
||||||
|
} else if (qdc.length == 2) {
|
||||||
|
metadataField = metadataValidator.checkMetadata(context, qdc[0], qdc[1], null, createMissingMetadataFields);
|
||||||
|
} else {
|
||||||
|
throw new CrosswalkInternalException("Unrecognized format in QDC element identifier for key=\"" + key + "\", qdc=\"" + element2qdc.get(key) + "\"");
|
||||||
|
}
|
||||||
|
|
||||||
// get language - prefer xml:lang, accept lang.
|
// get language - prefer xml:lang, accept lang.
|
||||||
String lang = me.getAttributeValue("lang", Namespace.XML_NAMESPACE);
|
String lang = me.getAttributeValue("lang", Namespace.XML_NAMESPACE);
|
||||||
@@ -477,18 +482,7 @@ public class QDCCrosswalk extends SelfNamedPlugin
|
|||||||
lang = me.getAttributeValue("lang");
|
lang = me.getAttributeValue("lang");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qdc.length == 3)
|
itemService.addMetadata(context, item, metadataField, lang, me.getText());
|
||||||
{
|
|
||||||
itemService.addMetadata(context, item, qdc[0], qdc[1], qdc[2], lang, me.getText());
|
|
||||||
}
|
|
||||||
else if (qdc.length == 2)
|
|
||||||
{
|
|
||||||
itemService.addMetadata(context, item, qdc[0], qdc[1], null, lang, me.getText());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new CrosswalkInternalException("Unrecognized format in QDC element identifier for key=\"" + key + "\", qdc=\"" + element2qdc.get(key) + "\"");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@@ -18,12 +18,7 @@ import javax.xml.transform.TransformerException;
|
|||||||
import org.apache.commons.lang.ArrayUtils;
|
import org.apache.commons.lang.ArrayUtils;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.dspace.authorize.AuthorizeException;
|
import org.dspace.authorize.AuthorizeException;
|
||||||
import org.dspace.content.DSpaceObject;
|
import org.dspace.content.*;
|
||||||
import org.dspace.content.Collection;
|
|
||||||
import org.dspace.content.Community;
|
|
||||||
import org.dspace.content.Item;
|
|
||||||
import org.dspace.content.MetadataField;
|
|
||||||
import org.dspace.content.MetadataSchema;
|
|
||||||
import org.dspace.content.authority.Choices;
|
import org.dspace.content.authority.Choices;
|
||||||
import org.dspace.content.factory.ContentServiceFactory;
|
import org.dspace.content.factory.ContentServiceFactory;
|
||||||
import org.dspace.content.packager.PackageUtils;
|
import org.dspace.content.packager.PackageUtils;
|
||||||
@@ -41,6 +36,12 @@ import org.jdom.output.XMLOutputter;
|
|||||||
import org.jdom.transform.JDOMResult;
|
import org.jdom.transform.JDOMResult;
|
||||||
import org.jdom.transform.JDOMSource;
|
import org.jdom.transform.JDOMSource;
|
||||||
|
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configurable XSLT-driven ingestion Crosswalk
|
* Configurable XSLT-driven ingestion Crosswalk
|
||||||
* <p>
|
* <p>
|
||||||
@@ -100,7 +101,8 @@ public class XSLTIngestionCrosswalk
|
|||||||
String authority = field.getAttributeValue("authority");
|
String authority = field.getAttributeValue("authority");
|
||||||
String sconf = field.getAttributeValue("confidence");
|
String sconf = field.getAttributeValue("confidence");
|
||||||
|
|
||||||
CrosswalkUtils.checkMetadata(context, schema, element, qualifier, createMissingMetadataFields);
|
CrosswalkMetadataValidator metadataValidator = new CrosswalkMetadataValidator();
|
||||||
|
MetadataField metadataField = metadataValidator.checkMetadata(context, schema, element, qualifier, createMissingMetadataFields);
|
||||||
// sanity check: some XSL puts an empty string in qualifier,
|
// sanity check: some XSL puts an empty string in qualifier,
|
||||||
// change it to null so we match the unqualified DC field:
|
// change it to null so we match the unqualified DC field:
|
||||||
if (qualifier != null && qualifier.equals(""))
|
if (qualifier != null && qualifier.equals(""))
|
||||||
@@ -113,11 +115,11 @@ public class XSLTIngestionCrosswalk
|
|||||||
{
|
{
|
||||||
int confidence = (sconf != null && sconf.length() > 0) ?
|
int confidence = (sconf != null && sconf.length() > 0) ?
|
||||||
Choices.getConfidenceValue(sconf) : Choices.CF_UNSET;
|
Choices.getConfidenceValue(sconf) : Choices.CF_UNSET;
|
||||||
itemService.addMetadata(context, item, schema, element, qualifier, lang, field.getText(), authority, confidence);
|
itemService.addMetadata(context, item, metadataField, lang, field.getText(), authority, confidence);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
itemService.addMetadata(context, item, schema, element, qualifier, lang, field.getText());
|
itemService.addMetadata(context, item, metadataField, lang, field.getText());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -10,12 +10,12 @@ package org.dspace.content.dao.impl;
|
|||||||
import org.dspace.content.MetadataField;
|
import org.dspace.content.MetadataField;
|
||||||
import org.dspace.content.MetadataSchema;
|
import org.dspace.content.MetadataSchema;
|
||||||
import org.dspace.content.dao.MetadataFieldDAO;
|
import org.dspace.content.dao.MetadataFieldDAO;
|
||||||
import org.dspace.core.Context;
|
|
||||||
import org.dspace.core.AbstractHibernateDAO;
|
import org.dspace.core.AbstractHibernateDAO;
|
||||||
|
import org.dspace.core.Context;
|
||||||
import org.hibernate.Criteria;
|
import org.hibernate.Criteria;
|
||||||
import org.hibernate.FetchMode;
|
import org.hibernate.FetchMode;
|
||||||
|
import org.hibernate.Query;
|
||||||
import org.hibernate.criterion.Order;
|
import org.hibernate.criterion.Order;
|
||||||
import org.hibernate.criterion.Restrictions;
|
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -37,36 +37,70 @@ public class MetadataFieldDAOImpl extends AbstractHibernateDAO<MetadataField> im
|
|||||||
@Override
|
@Override
|
||||||
public MetadataField find(Context context, int metadataFieldId, MetadataSchema metadataSchema, String element,
|
public MetadataField find(Context context, int metadataFieldId, MetadataSchema metadataSchema, String element,
|
||||||
String qualifier) throws SQLException{
|
String qualifier) throws SQLException{
|
||||||
Criteria criteria = createCriteria(context, MetadataField.class);
|
Query query;
|
||||||
criteria.add(
|
|
||||||
Restrictions.and(
|
|
||||||
Restrictions.not(Restrictions.eq("id", metadataFieldId)),
|
|
||||||
Restrictions.eq("metadataSchema.id", metadataSchema.getSchemaID()),
|
|
||||||
Restrictions.eq("element", element),
|
|
||||||
Restrictions.eqOrIsNull("qualifier", qualifier)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
criteria.setFetchMode("metadataSchema", FetchMode.JOIN);
|
|
||||||
criteria.setCacheable(true);
|
|
||||||
|
|
||||||
return singleResult(criteria);
|
if(qualifier != null) {
|
||||||
|
query = createQuery(context, "SELECT mf " +
|
||||||
|
"FROM MetadataField mf " +
|
||||||
|
"JOIN FETCH mf.metadataSchema ms " +
|
||||||
|
"WHERE mf.id != :id " +
|
||||||
|
"AND ms.name = :name AND mf.element = :element " +
|
||||||
|
"AND qualifier = :qualifier");
|
||||||
|
} else {
|
||||||
|
query = createQuery(context, "SELECT mf " +
|
||||||
|
"FROM MetadataField mf " +
|
||||||
|
"JOIN FETCH mf.metadataSchema ms " +
|
||||||
|
"WHERE mf.id != :id " +
|
||||||
|
"AND ms.name = :name AND mf.element = :element " +
|
||||||
|
"AND mf.qualifier IS NULL");
|
||||||
|
}
|
||||||
|
|
||||||
|
query.setParameter("id", metadataFieldId);
|
||||||
|
query.setParameter("name", metadataSchema.getName());
|
||||||
|
query.setParameter("element", element);
|
||||||
|
|
||||||
|
if(qualifier != null) {
|
||||||
|
query.setParameter("qualifier", qualifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
query.setCacheable(true);
|
||||||
|
return singleResult(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MetadataField findByElement(Context context, MetadataSchema metadataSchema, String element, String qualifier) throws SQLException
|
public MetadataField findByElement(Context context, MetadataSchema metadataSchema, String element, String qualifier) throws SQLException
|
||||||
{
|
{
|
||||||
Criteria criteria = createCriteria(context, MetadataField.class);
|
return findByElement(context, metadataSchema.getName(), element, qualifier);
|
||||||
criteria.add(
|
}
|
||||||
Restrictions.and(
|
|
||||||
Restrictions.eq("metadataSchema.id", metadataSchema.getSchemaID()),
|
|
||||||
Restrictions.eq("element", element),
|
|
||||||
Restrictions.eqOrIsNull("qualifier", qualifier)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
criteria.setFetchMode("metadataSchema", FetchMode.JOIN);
|
|
||||||
criteria.setCacheable(true);
|
|
||||||
|
|
||||||
return singleResult(criteria);
|
@Override
|
||||||
|
public MetadataField findByElement(Context context, String metadataSchema, String element, String qualifier) throws SQLException
|
||||||
|
{
|
||||||
|
Query query;
|
||||||
|
|
||||||
|
if(qualifier != null) {
|
||||||
|
query = createQuery(context, "SELECT mf " +
|
||||||
|
"FROM MetadataField mf " +
|
||||||
|
"JOIN FETCH mf.metadataSchema ms " +
|
||||||
|
"WHERE ms.name = :name AND mf.element = :element " +
|
||||||
|
"AND qualifier = :qualifier");
|
||||||
|
} else {
|
||||||
|
query = createQuery(context, "SELECT mf " +
|
||||||
|
"FROM MetadataField mf " +
|
||||||
|
"JOIN FETCH mf.metadataSchema ms " +
|
||||||
|
"WHERE ms.name = :name AND mf.element = :element " +
|
||||||
|
"AND mf.qualifier IS NULL");
|
||||||
|
}
|
||||||
|
|
||||||
|
query.setParameter("name", metadataSchema);
|
||||||
|
query.setParameter("element", element);
|
||||||
|
|
||||||
|
if(qualifier != null) {
|
||||||
|
query.setParameter("qualifier", qualifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
query.setCacheable(true);
|
||||||
|
return singleResult(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -78,50 +112,35 @@ public class MetadataFieldDAOImpl extends AbstractHibernateDAO<MetadataField> im
|
|||||||
return list(criteria);
|
return list(criteria);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public MetadataField findByElement(Context context, String metadataSchema, String element, String qualifier) throws SQLException
|
|
||||||
{
|
|
||||||
Criteria criteria = createCriteria(context, MetadataField.class);
|
|
||||||
criteria.createAlias("metadataSchema", "s").add(
|
|
||||||
Restrictions.and(
|
|
||||||
Restrictions.eq("s.name", metadataSchema),
|
|
||||||
Restrictions.eq("element", element),
|
|
||||||
Restrictions.eqOrIsNull("qualifier", qualifier)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
criteria.setFetchMode("metadataSchema", FetchMode.JOIN);
|
|
||||||
criteria.setCacheable(true);
|
|
||||||
|
|
||||||
return singleResult(criteria);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<MetadataField> findFieldsByElementNameUnqualified(Context context, String metadataSchema, String element) throws SQLException
|
public List<MetadataField> findFieldsByElementNameUnqualified(Context context, String metadataSchema, String element) throws SQLException
|
||||||
{
|
{
|
||||||
Criteria criteria = createCriteria(context, MetadataField.class);
|
Query query = createQuery(context, "SELECT mf " +
|
||||||
criteria.createAlias("metadataSchema", "s").add(
|
"FROM MetadataField mf " +
|
||||||
Restrictions.and(
|
"JOIN FETCH mf.metadataSchema ms " +
|
||||||
Restrictions.eq("s.name", metadataSchema),
|
"WHERE ms.name = :name AND mf.element = :element ");
|
||||||
Restrictions.eq("element", element)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
criteria.setFetchMode("metadataSchema", FetchMode.JOIN);
|
|
||||||
criteria.setCacheable(true);
|
|
||||||
|
|
||||||
return list(criteria);
|
|
||||||
|
query.setParameter("name", metadataSchema);
|
||||||
|
query.setParameter("element", element);
|
||||||
|
|
||||||
|
query.setCacheable(true);
|
||||||
|
return list(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<MetadataField> findAllInSchema(Context context, MetadataSchema metadataSchema) throws SQLException {
|
public List<MetadataField> findAllInSchema(Context context, MetadataSchema metadataSchema) throws SQLException {
|
||||||
// Get all the metadatafieldregistry rows
|
|
||||||
Criteria criteria = createCriteria(context, MetadataField.class);
|
|
||||||
criteria.createAlias("metadataSchema", "s");
|
|
||||||
criteria.add(Restrictions.eq("s.id", metadataSchema.getSchemaID()));
|
|
||||||
criteria.addOrder(Order.asc("s.name")).addOrder(Order.asc("element")).addOrder(Order.asc("qualifier"));
|
|
||||||
criteria.setFetchMode("metadataSchema", FetchMode.JOIN);
|
|
||||||
|
|
||||||
criteria.setCacheable(true);
|
Query query = createQuery(context, "SELECT mf " +
|
||||||
return list(criteria);
|
"FROM MetadataField mf " +
|
||||||
|
"JOIN FETCH mf.metadataSchema ms " +
|
||||||
|
"WHERE ms.name = :name " +
|
||||||
|
"ORDER BY mf.element ASC, mf.qualifier ASC ");
|
||||||
|
|
||||||
|
query.setParameter("name", metadataSchema.getName());
|
||||||
|
|
||||||
|
query.setCacheable(true);
|
||||||
|
return list(query);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -9,11 +9,11 @@ package org.dspace.content.dao.impl;
|
|||||||
|
|
||||||
import org.dspace.content.MetadataSchema;
|
import org.dspace.content.MetadataSchema;
|
||||||
import org.dspace.content.dao.MetadataSchemaDAO;
|
import org.dspace.content.dao.MetadataSchemaDAO;
|
||||||
import org.dspace.core.Context;
|
|
||||||
import org.dspace.core.AbstractHibernateDAO;
|
import org.dspace.core.AbstractHibernateDAO;
|
||||||
|
import org.dspace.core.Context;
|
||||||
import org.hibernate.Criteria;
|
import org.hibernate.Criteria;
|
||||||
|
import org.hibernate.Query;
|
||||||
import org.hibernate.criterion.Order;
|
import org.hibernate.criterion.Order;
|
||||||
import org.hibernate.criterion.Restrictions;
|
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -44,11 +44,14 @@ public class MetadataSchemaDAOImpl extends AbstractHibernateDAO<MetadataSchema>
|
|||||||
public MetadataSchema findByNamespace(Context context, String namespace) throws SQLException
|
public MetadataSchema findByNamespace(Context context, String namespace) throws SQLException
|
||||||
{
|
{
|
||||||
// Grab rows from DB
|
// Grab rows from DB
|
||||||
Criteria criteria = createCriteria(context, MetadataSchema.class);
|
Query query = createQuery(context,
|
||||||
criteria.add(Restrictions.eq("namespace", namespace));
|
"SELECT ms FROM MetadataSchema ms " +
|
||||||
criteria.setCacheable(true);
|
"WHERE ms.namespace = :namespace ");
|
||||||
|
|
||||||
return singleResult(criteria);
|
query.setParameter("namespace", namespace);
|
||||||
|
|
||||||
|
query.setCacheable(true);
|
||||||
|
return singleResult(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -74,14 +77,15 @@ public class MetadataSchemaDAOImpl extends AbstractHibernateDAO<MetadataSchema>
|
|||||||
@Override
|
@Override
|
||||||
public boolean uniqueNamespace(Context context, int metadataSchemaId, String namespace) throws SQLException
|
public boolean uniqueNamespace(Context context, int metadataSchemaId, String namespace) throws SQLException
|
||||||
{
|
{
|
||||||
Criteria criteria = createCriteria(context, MetadataSchema.class);
|
Query query = createQuery(context,
|
||||||
criteria.add(Restrictions.and(
|
"SELECT ms FROM MetadataSchema ms " +
|
||||||
Restrictions.not(Restrictions.eq("id", metadataSchemaId)),
|
"WHERE ms.namespace = :namespace and ms.id != :id");
|
||||||
Restrictions.eq("namespace", namespace)
|
|
||||||
));
|
|
||||||
criteria.setCacheable(true);
|
|
||||||
|
|
||||||
return singleResult(criteria) == null;
|
query.setParameter("namespace", namespace);
|
||||||
|
query.setParameter("id", metadataSchemaId);
|
||||||
|
|
||||||
|
query.setCacheable(true);
|
||||||
|
return singleResult(query) == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -96,14 +100,15 @@ public class MetadataSchemaDAOImpl extends AbstractHibernateDAO<MetadataSchema>
|
|||||||
@Override
|
@Override
|
||||||
public boolean uniqueShortName(Context context, int metadataSchemaId, String name) throws SQLException
|
public boolean uniqueShortName(Context context, int metadataSchemaId, String name) throws SQLException
|
||||||
{
|
{
|
||||||
Criteria criteria = createCriteria(context, MetadataSchema.class);
|
Query query = createQuery(context,
|
||||||
criteria.add(Restrictions.and(
|
"SELECT ms FROM MetadataSchema ms " +
|
||||||
Restrictions.not(Restrictions.eq("id", metadataSchemaId)),
|
"WHERE ms.name = :name and ms.id != :id");
|
||||||
Restrictions.eq("name", name)
|
|
||||||
));
|
|
||||||
criteria.setCacheable(true);
|
|
||||||
|
|
||||||
return singleResult(criteria) == null;
|
query.setParameter("name", name);
|
||||||
|
query.setParameter("id", metadataSchemaId);
|
||||||
|
|
||||||
|
query.setCacheable(true);
|
||||||
|
return singleResult(query) == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -119,12 +124,13 @@ public class MetadataSchemaDAOImpl extends AbstractHibernateDAO<MetadataSchema>
|
|||||||
@Override
|
@Override
|
||||||
public MetadataSchema find(Context context, String shortName) throws SQLException
|
public MetadataSchema find(Context context, String shortName) throws SQLException
|
||||||
{
|
{
|
||||||
Criteria criteria = createCriteria(context, MetadataSchema.class);
|
Query query = createQuery(context,
|
||||||
criteria.add(
|
"SELECT ms FROM MetadataSchema ms " +
|
||||||
Restrictions.eq("name", shortName)
|
"WHERE ms.name = :name");
|
||||||
);
|
|
||||||
criteria.setCacheable(true);
|
|
||||||
|
|
||||||
return singleResult(criteria);
|
query.setParameter("name", shortName);
|
||||||
|
|
||||||
|
query.setCacheable(true);
|
||||||
|
return singleResult(query);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -276,6 +276,7 @@ public interface DSpaceObjectService<T extends DSpaceObject> {
|
|||||||
|
|
||||||
public void addMetadata(Context context, T dso, MetadataField metadataField, String language, String value) throws SQLException;
|
public void addMetadata(Context context, T dso, MetadataField metadataField, String language, String value) throws SQLException;
|
||||||
|
|
||||||
|
public void addMetadata(Context context, T dso, MetadataField metadataField, String language, List<String> values) throws SQLException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a single metadata field. This is appended to existing
|
* Add a single metadata field. This is appended to existing
|
||||||
|
@@ -8,7 +8,9 @@
|
|||||||
package org.dspace.core;
|
package org.dspace.core;
|
||||||
|
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
import org.hibernate.*;
|
import org.hibernate.Criteria;
|
||||||
|
import org.hibernate.Query;
|
||||||
|
import org.hibernate.Session;
|
||||||
import org.hibernate.criterion.Projections;
|
import org.hibernate.criterion.Projections;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
@@ -161,6 +163,17 @@ public abstract class AbstractHibernateDAO<T> implements GenericDAO<T> {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public T singleResult(final Query query) {
|
||||||
|
query.setMaxResults(1);
|
||||||
|
List<T> list = list(query);
|
||||||
|
if(CollectionUtils.isNotEmpty(list))
|
||||||
|
{
|
||||||
|
return list.get(0);
|
||||||
|
}else{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public T uniqueResult(Query query)
|
public T uniqueResult(Query query)
|
||||||
{
|
{
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
Reference in New Issue
Block a user