mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
Remove deprecated setMetadata of CommunityService, CollectionService #2956
This introduces a new class: a holder for metadata field names.
This commit is contained in:
@@ -7,6 +7,14 @@
|
||||
*/
|
||||
package org.dspace.administer;
|
||||
|
||||
import static org.dspace.content.service.DSpaceObjectService.MD_COPYRIGHT_TEXT;
|
||||
import static org.dspace.content.service.DSpaceObjectService.MD_INTRODUCTORY_TEXT;
|
||||
import static org.dspace.content.service.DSpaceObjectService.MD_LICENSE;
|
||||
import static org.dspace.content.service.DSpaceObjectService.MD_NAME;
|
||||
import static org.dspace.content.service.DSpaceObjectService.MD_PROVENANCE_DESCRIPTION;
|
||||
import static org.dspace.content.service.DSpaceObjectService.MD_SHORT_DESCRIPTION;
|
||||
import static org.dspace.content.service.DSpaceObjectService.MD_SIDEBAR_TEXT;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
@@ -35,6 +43,7 @@ import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.content.Community;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.content.MetadataFieldName;
|
||||
import org.dspace.content.MetadataSchemaEnum;
|
||||
import org.dspace.content.MetadataValue;
|
||||
import org.dspace.content.factory.ContentServiceFactory;
|
||||
@@ -88,12 +97,12 @@ public class StructBuilder {
|
||||
/**
|
||||
* A table to hold metadata for the collection being worked on.
|
||||
*/
|
||||
private static final Map<String, String> collectionMap = new HashMap<>();
|
||||
private static final Map<String, MetadataFieldName> collectionMap = new HashMap<>();
|
||||
|
||||
/**
|
||||
* A table to hold metadata for the community being worked on.
|
||||
*/
|
||||
private static final Map<String, String> communityMap = new HashMap<>();
|
||||
private static final Map<String, MetadataFieldName> communityMap = new HashMap<>();
|
||||
|
||||
protected static CommunityService communityService
|
||||
= ContentServiceFactory.getInstance().getCommunityService();
|
||||
@@ -261,19 +270,19 @@ public class StructBuilder {
|
||||
}
|
||||
|
||||
// load the mappings into the member variable hashmaps
|
||||
communityMap.put("name", "name");
|
||||
communityMap.put("description", "short_description");
|
||||
communityMap.put("intro", "introductory_text");
|
||||
communityMap.put("copyright", "copyright_text");
|
||||
communityMap.put("sidebar", "side_bar_text");
|
||||
communityMap.put("name", MD_NAME);
|
||||
communityMap.put("description", MD_SHORT_DESCRIPTION);
|
||||
communityMap.put("intro", MD_INTRODUCTORY_TEXT);
|
||||
communityMap.put("copyright", MD_COPYRIGHT_TEXT);
|
||||
communityMap.put("sidebar", MD_SIDEBAR_TEXT);
|
||||
|
||||
collectionMap.put("name", "name");
|
||||
collectionMap.put("description", "short_description");
|
||||
collectionMap.put("intro", "introductory_text");
|
||||
collectionMap.put("copyright", "copyright_text");
|
||||
collectionMap.put("sidebar", "side_bar_text");
|
||||
collectionMap.put("license", "license");
|
||||
collectionMap.put("provenance", "provenance_description");
|
||||
collectionMap.put("name", MD_NAME);
|
||||
collectionMap.put("description", MD_SHORT_DESCRIPTION);
|
||||
collectionMap.put("intro", MD_INTRODUCTORY_TEXT);
|
||||
collectionMap.put("copyright", MD_COPYRIGHT_TEXT);
|
||||
collectionMap.put("sidebar", MD_SIDEBAR_TEXT);
|
||||
collectionMap.put("license", MD_LICENSE);
|
||||
collectionMap.put("provenance", MD_PROVENANCE_DESCRIPTION);
|
||||
|
||||
Element[] elements = new Element[]{};
|
||||
try {
|
||||
@@ -619,14 +628,16 @@ public class StructBuilder {
|
||||
}
|
||||
|
||||
// default the short description to be an empty string
|
||||
communityService.setMetadata(context, community, "short_description", " ");
|
||||
communityService.setMetadataSingleValue(context, community,
|
||||
MD_SHORT_DESCRIPTION, null, " ");
|
||||
|
||||
// now update the metadata
|
||||
Node tn = communities.item(i);
|
||||
for (Map.Entry<String, String> entry : communityMap.entrySet()) {
|
||||
for (Map.Entry<String, MetadataFieldName> entry : communityMap.entrySet()) {
|
||||
NodeList nl = XPathAPI.selectNodeList(tn, entry.getKey());
|
||||
if (nl.getLength() == 1) {
|
||||
communityService.setMetadata(context, community, entry.getValue(), getStringValue(nl.item(0)));
|
||||
communityService.setMetadataSingleValue(context, community,
|
||||
entry.getValue(), null, getStringValue(nl.item(0)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -728,14 +739,16 @@ public class StructBuilder {
|
||||
Collection collection = collectionService.create(context, parent);
|
||||
|
||||
// default the short description to the empty string
|
||||
collectionService.setMetadata(context, collection, "short_description", " ");
|
||||
collectionService.setMetadataSingleValue(context, collection,
|
||||
MD_SHORT_DESCRIPTION, Item.ANY, " ");
|
||||
|
||||
// import the rest of the metadata
|
||||
Node tn = collections.item(i);
|
||||
for (Map.Entry<String, String> entry : collectionMap.entrySet()) {
|
||||
for (Map.Entry<String, MetadataFieldName> entry : collectionMap.entrySet()) {
|
||||
NodeList nl = XPathAPI.selectNodeList(tn, entry.getKey());
|
||||
if (nl.getLength() == 1) {
|
||||
collectionService.setMetadata(context, collection, entry.getValue(), getStringValue(nl.item(0)));
|
||||
collectionService.setMetadataSingleValue(context, collection,
|
||||
entry.getValue(), null, getStringValue(nl.item(0)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -803,5 +816,4 @@ public class StructBuilder {
|
||||
|
||||
return elements;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -7,6 +7,8 @@
|
||||
*/
|
||||
package org.dspace.content;
|
||||
|
||||
import static org.dspace.content.service.DSpaceObjectService.MD_LICENSE;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
@@ -47,7 +49,6 @@ import org.hibernate.proxy.HibernateProxyHelper;
|
||||
* effect.
|
||||
*
|
||||
* @author Robert Tansley
|
||||
* @version $Revision$
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "collection")
|
||||
@@ -88,7 +89,7 @@ public class Collection extends DSpaceObject implements DSpaceObjectLegacySuppor
|
||||
joinColumns = {@JoinColumn(name = "collection_id")},
|
||||
inverseJoinColumns = {@JoinColumn(name = "community_id")}
|
||||
)
|
||||
private Set<Community> communities = new HashSet<>();
|
||||
private final Set<Community> communities = new HashSet<>();
|
||||
|
||||
@Transient
|
||||
private transient CollectionService collectionService;
|
||||
@@ -230,7 +231,7 @@ public class Collection extends DSpaceObject implements DSpaceObjectLegacySuppor
|
||||
* @throws SQLException if database error
|
||||
*/
|
||||
public void setLicense(Context context, String license) throws SQLException {
|
||||
getCollectionService().setMetadata(context, this, "license", license);
|
||||
getCollectionService().setMetadataSingleValue(context, this, MD_LICENSE, Item.ANY, license);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -293,9 +293,10 @@ public class CollectionServiceImpl extends DSpaceObjectServiceImpl<Collection> i
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMetadata(Context context, Collection collection, String field, String value)
|
||||
throws MissingResourceException, SQLException {
|
||||
if ((field.trim()).equals("name") && (value == null || value.trim().equals(""))) {
|
||||
public void setMetadataSingleValue(Context context, Collection collection,
|
||||
MetadataFieldName field, String language, String value)
|
||||
throws MissingResourceException, SQLException {
|
||||
if (field.equals(MD_NAME) && (value == null || value.trim().equals(""))) {
|
||||
try {
|
||||
value = I18nUtil.getMessage("org.dspace.workflow.WorkflowManager.untitled");
|
||||
} catch (MissingResourceException e) {
|
||||
@@ -303,21 +304,19 @@ public class CollectionServiceImpl extends DSpaceObjectServiceImpl<Collection> i
|
||||
}
|
||||
}
|
||||
|
||||
String[] MDValue = getMDValueByLegacyField(field);
|
||||
|
||||
/*
|
||||
* Set metadata field to null if null
|
||||
* and trim strings to eliminate excess
|
||||
* whitespace.
|
||||
*/
|
||||
if (value == null) {
|
||||
clearMetadata(context, collection, MDValue[0], MDValue[1], MDValue[2], Item.ANY);
|
||||
clearMetadata(context, collection, field.SCHEMA, field.ELEMENT, field.QUALIFIER, Item.ANY);
|
||||
collection.setMetadataModified();
|
||||
} else {
|
||||
setMetadataSingleValue(context, collection, MDValue[0], MDValue[1], MDValue[2], null, value);
|
||||
super.setMetadataSingleValue(context, collection, field, null, value);
|
||||
}
|
||||
|
||||
collection.addDetails(field);
|
||||
collection.addDetails(field.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -175,10 +175,10 @@ public class CommunityServiceImpl extends DSpaceObjectServiceImpl<Community> imp
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMetadata(Context context, Community community, String field, String value)
|
||||
throws MissingResourceException, SQLException {
|
||||
if ((field.trim()).equals("name")
|
||||
&& (value == null || value.trim().equals(""))) {
|
||||
public void setMetadataSingleValue(Context context, Community community,
|
||||
MetadataFieldName field, String language, String value)
|
||||
throws MissingResourceException, SQLException {
|
||||
if (field.equals(MD_NAME) && (value == null || value.trim().equals(""))) {
|
||||
try {
|
||||
value = I18nUtil.getMessage("org.dspace.workflow.WorkflowManager.untitled");
|
||||
} catch (MissingResourceException e) {
|
||||
@@ -186,19 +186,19 @@ public class CommunityServiceImpl extends DSpaceObjectServiceImpl<Community> imp
|
||||
}
|
||||
}
|
||||
|
||||
String[] MDValue = getMDValueByLegacyField(field);
|
||||
|
||||
/*
|
||||
* Set metadata field to null if null
|
||||
* and trim strings to eliminate excess
|
||||
* whitespace.
|
||||
*/
|
||||
if (value == null) {
|
||||
clearMetadata(context, community, MDValue[0], MDValue[1], MDValue[2], Item.ANY);
|
||||
clearMetadata(context, community, field.SCHEMA, field.ELEMENT, field.QUALIFIER, Item.ANY);
|
||||
community.setMetadataModified();
|
||||
} else {
|
||||
setMetadataSingleValue(context, community, MDValue[0], MDValue[1], MDValue[2], null, value);
|
||||
super.setMetadataSingleValue(context, community, field, null, value);
|
||||
}
|
||||
community.addDetails(field);
|
||||
|
||||
community.addDetails(field.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -131,7 +131,7 @@ public abstract class DSpaceObjectServiceImpl<T extends DSpaceObject> implements
|
||||
@Override
|
||||
public List<MetadataValue> getMetadata(T dso, String schema, String element, String qualifier, String lang) {
|
||||
// Build up list of matching values
|
||||
List<MetadataValue> values = new ArrayList<MetadataValue>();
|
||||
List<MetadataValue> values = new ArrayList<>();
|
||||
for (MetadataValue dcv : dso.getMetadata()) {
|
||||
if (match(schema, element, qualifier, lang, dcv)) {
|
||||
values.add(dcv);
|
||||
@@ -298,7 +298,6 @@ public abstract class DSpaceObjectServiceImpl<T extends DSpaceObject> implements
|
||||
}
|
||||
}
|
||||
metadataValue.setValue(String.valueOf(dcvalue));
|
||||
;
|
||||
} else {
|
||||
metadataValue.setValue(null);
|
||||
}
|
||||
@@ -337,8 +336,8 @@ public abstract class DSpaceObjectServiceImpl<T extends DSpaceObject> implements
|
||||
.makeFieldKey(metadataField.getMetadataSchema().getName(), metadataField.getElement(),
|
||||
metadataField.getQualifier());
|
||||
if (metadataAuthorityService.isAuthorityControlled(fieldKey)) {
|
||||
List<String> authorities = new ArrayList<String>();
|
||||
List<Integer> confidences = new ArrayList<Integer>();
|
||||
List<String> authorities = new ArrayList<>();
|
||||
List<Integer> confidences = new ArrayList<>();
|
||||
for (int i = 0; i < values.size(); ++i) {
|
||||
if (dso instanceof Item) {
|
||||
getAuthoritiesAndConfidences(fieldKey, ((Item) dso).getOwningCollection(), values, authorities,
|
||||
@@ -443,6 +442,21 @@ public abstract class DSpaceObjectServiceImpl<T extends DSpaceObject> implements
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMetadataSingleValue(Context context, T dso, MetadataFieldName field,
|
||||
String language, String value)
|
||||
throws SQLException {
|
||||
if (value != null) {
|
||||
clearMetadata(context, dso, field.SCHEMA, field.ELEMENT, field.QUALIFIER,
|
||||
language);
|
||||
|
||||
String newValueLanguage = (Item.ANY.equals(language)) ? null : language;
|
||||
addMetadata(context, dso, field.SCHEMA, field.ELEMENT, field.QUALIFIER,
|
||||
newValueLanguage, value);
|
||||
dso.setMetadataModified();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method for pattern-matching metadata elements. This
|
||||
* method will return <code>true</code> if the given schema,
|
||||
@@ -592,6 +606,7 @@ public abstract class DSpaceObjectServiceImpl<T extends DSpaceObject> implements
|
||||
//RelationshipMetadataValue instance.
|
||||
//This is done to ensure that the order is correct.
|
||||
metadataValues.sort(new Comparator<MetadataValue>() {
|
||||
@Override
|
||||
public int compare(MetadataValue o1, MetadataValue o2) {
|
||||
int compare = o1.getPlace() - o2.getPlace();
|
||||
if (compare == 0) {
|
||||
@@ -762,7 +777,12 @@ public abstract class DSpaceObjectServiceImpl<T extends DSpaceObject> implements
|
||||
}
|
||||
|
||||
/**
|
||||
* Supports moving metadata by updating the place of the metadata value
|
||||
* Supports moving metadata by updating the place of the metadata value.
|
||||
*
|
||||
* @param context current DSpace session.
|
||||
* @param dso unused.
|
||||
* @param place ordinal position of the value in the list of that field's values.
|
||||
* @param rr the value to be placed.
|
||||
*/
|
||||
protected void moveSingleMetadataValue(Context context, T dso, int place, MetadataValue rr) {
|
||||
//just move the metadata
|
||||
|
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
package org.dspace.content;
|
||||
|
||||
import java.util.Arrays;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
@@ -32,11 +33,11 @@ public class MetadataFieldName {
|
||||
*/
|
||||
public MetadataFieldName(@Nonnull String schema, @Nonnull String element, String qualifier) {
|
||||
if (null == schema) {
|
||||
throw new IllegalArgumentException("Schema must not be null.");
|
||||
throw new NullPointerException("Schema must not be null.");
|
||||
}
|
||||
|
||||
if (null == element) {
|
||||
throw new IllegalArgumentException("Element must not be null.");
|
||||
throw new NullPointerException("Element must not be null.");
|
||||
}
|
||||
|
||||
SCHEMA = schema;
|
||||
@@ -51,11 +52,11 @@ public class MetadataFieldName {
|
||||
*/
|
||||
public MetadataFieldName(@Nonnull String schema, @Nonnull String element) {
|
||||
if (null == schema) {
|
||||
throw new IllegalArgumentException("Schema must not be null.");
|
||||
throw new NullPointerException("Schema must not be null.");
|
||||
}
|
||||
|
||||
if (null == element) {
|
||||
throw new IllegalArgumentException("Element must not be null.");
|
||||
throw new NullPointerException("Element must not be null.");
|
||||
}
|
||||
|
||||
SCHEMA = schema;
|
||||
@@ -101,4 +102,54 @@ public class MetadataFieldName {
|
||||
ELEMENT = element;
|
||||
QUALIFIER = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize a tuple of (schema, element, qualifier) to name a metadata field.
|
||||
* @param name a dotted-triple {@code schema.element[.qualifier]}. If the
|
||||
* optional qualifier is omitted, it will be stored as {@code null}.
|
||||
*/
|
||||
public MetadataFieldName(@Nonnull String name) {
|
||||
String[] elements = parse(name);
|
||||
SCHEMA = elements[0];
|
||||
ELEMENT = elements[1];
|
||||
QUALIFIER = elements[2];
|
||||
}
|
||||
|
||||
/**
|
||||
* Split a dotted-triple field name {@code schema.element[.qualifier]} into
|
||||
* its components.
|
||||
* @param name the dotted-triple field name.
|
||||
* @return the components. Always of size 3. If the qualifier is omitted,
|
||||
* the third element is {@code null}.
|
||||
* @throws IllegalArgumentException if there are not at least two components.
|
||||
* @throws NullPointerException if {@code name} is null.
|
||||
*/
|
||||
public static String[] parse(@Nonnull String name) {
|
||||
if (null == name) {
|
||||
throw new NullPointerException("Name is null");
|
||||
}
|
||||
|
||||
String[] elements = name.split("\\.", 3);
|
||||
if (elements.length < 2) {
|
||||
throw new IllegalArgumentException("Not enough elements: " + name);
|
||||
}
|
||||
return Arrays.copyOf(elements, 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a dotted-atoms representation of this field name.
|
||||
* @return SCHEMA.ELEMENT.QUALIFIER
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder buffer = new StringBuilder(32);
|
||||
buffer.append(SCHEMA)
|
||||
.append('.')
|
||||
.append(ELEMENT);
|
||||
if (null != QUALIFIER) {
|
||||
buffer.append('.')
|
||||
.append(QUALIFIER);
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
}
|
||||
|
@@ -23,10 +23,11 @@ import org.dspace.content.Community;
|
||||
import org.dspace.content.DSpaceObject;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.content.MetadataField;
|
||||
import org.dspace.content.MetadataFieldName;
|
||||
import org.dspace.content.MetadataSchema;
|
||||
import org.dspace.content.MetadataSchemaEnum;
|
||||
import org.dspace.content.authority.Choices;
|
||||
import org.dspace.content.factory.ContentServiceFactory;
|
||||
import org.dspace.content.packager.PackageUtils;
|
||||
import org.dspace.content.service.CollectionService;
|
||||
import org.dspace.content.service.CommunityService;
|
||||
import org.dspace.content.service.ItemService;
|
||||
@@ -180,15 +181,11 @@ public class XSLTIngestionCrosswalk
|
||||
}
|
||||
|
||||
// return coll/comm "metadata" label corresponding to a DIM field.
|
||||
private static String getMetadataForDIM(Element field) {
|
||||
private static MetadataFieldName getMetadataForDIM(Element field) {
|
||||
// make up fieldname, then look for it in xwalk
|
||||
String element = field.getAttributeValue("element");
|
||||
String qualifier = field.getAttributeValue("qualifier");
|
||||
String fname = "dc." + element;
|
||||
if (qualifier != null) {
|
||||
fname += "." + qualifier;
|
||||
}
|
||||
return PackageUtils.dcToContainerMetadata(fname);
|
||||
return new MetadataFieldName(MetadataSchemaEnum.DC.getName(), element, qualifier);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -234,16 +231,18 @@ public class XSLTIngestionCrosswalk
|
||||
} else if ("field".equals(field.getName()) &&
|
||||
DIM_NS.equals(field.getNamespace()) &&
|
||||
schema != null && "dc".equals(schema)) {
|
||||
String md = getMetadataForDIM(field);
|
||||
MetadataFieldName md = getMetadataForDIM(field);
|
||||
if (md == null) {
|
||||
log.warn("Cannot map to Coll/Comm metadata field, DIM element=" +
|
||||
field.getAttributeValue("element") + ", qualifier=" + field
|
||||
.getAttributeValue("qualifier"));
|
||||
} else {
|
||||
if (type == Constants.COLLECTION) {
|
||||
collectionService.setMetadata(context, (Collection) dso, md, field.getText());
|
||||
collectionService.setMetadataSingleValue(context,
|
||||
(Collection) dso, md, null, field.getText());
|
||||
} else {
|
||||
communityService.setMetadata(context, (Community) dso, md, field.getText());
|
||||
communityService.setMetadataSingleValue(context,
|
||||
(Community) dso, md, null, field.getText());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@@ -21,6 +21,7 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.content.Bitstream;
|
||||
@@ -30,6 +31,7 @@ import org.dspace.content.Collection;
|
||||
import org.dspace.content.Community;
|
||||
import org.dspace.content.DSpaceObject;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.content.MetadataFieldName;
|
||||
import org.dspace.content.MetadataSchemaEnum;
|
||||
import org.dspace.content.MetadataValue;
|
||||
import org.dspace.content.WorkspaceItem;
|
||||
@@ -57,7 +59,6 @@ import org.dspace.workflow.factory.WorkflowServiceFactory;
|
||||
* Container class for code that is useful to many packagers.
|
||||
*
|
||||
* @author Larry Stone
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
public class PackageUtils {
|
||||
@@ -65,7 +66,7 @@ public class PackageUtils {
|
||||
/**
|
||||
* log4j category
|
||||
*/
|
||||
private static final Logger log = org.apache.logging.log4j.LogManager.getLogger(PackageUtils.class);
|
||||
private static final Logger log = LogManager.getLogger(PackageUtils.class);
|
||||
|
||||
// Map of metadata elements for Communities and Collections
|
||||
// Format is alternating key/value in a straight array; use this
|
||||
@@ -159,7 +160,7 @@ public class PackageUtils {
|
||||
public static void checkItemMetadata(Item item)
|
||||
throws PackageValidationException {
|
||||
List<MetadataValue> t = itemService.getMetadata(item, MetadataSchemaEnum.DC.getName(), "title", null, Item.ANY);
|
||||
if (t == null || t.size() == 0) {
|
||||
if (t == null || t.isEmpty()) {
|
||||
throw new PackageValidationException("Item cannot be created without the required \"title\" DC metadata.");
|
||||
}
|
||||
}
|
||||
@@ -704,7 +705,9 @@ public class PackageUtils {
|
||||
// to clear out all the Collection database fields.
|
||||
for (String dbField : ccMetadataToDC.keySet()) {
|
||||
try {
|
||||
collectionService.setMetadata(context, collection, dbField, null);
|
||||
String[] elements = MetadataFieldName.parse(dbField);
|
||||
collectionService.clearMetadata(context, collection,
|
||||
elements[0], elements[1], elements[2], Item.ANY);
|
||||
} catch (IllegalArgumentException ie) {
|
||||
// ignore the error -- just means the field doesn't exist in DB
|
||||
// Communities & Collections don't include the exact same metadata fields
|
||||
@@ -718,7 +721,9 @@ public class PackageUtils {
|
||||
// to clear out all the Community database fields.
|
||||
for (String dbField : ccMetadataToDC.keySet()) {
|
||||
try {
|
||||
communityService.setMetadata(context, community, dbField, null);
|
||||
String[] elements = MetadataFieldName.parse(dbField);
|
||||
communityService.clearMetadata(context, community,
|
||||
elements[0], elements[1], elements[2], Item.ANY);
|
||||
} catch (IllegalArgumentException ie) {
|
||||
// ignore the error -- just means the field doesn't exist in DB
|
||||
// Communities & Collections don't include the exact same metadata fields
|
||||
|
@@ -12,7 +12,6 @@ import java.io.InputStream;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.MissingResourceException;
|
||||
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.content.Bitstream;
|
||||
@@ -23,11 +22,10 @@ import org.dspace.core.Context;
|
||||
import org.dspace.discovery.SearchServiceException;
|
||||
import org.dspace.eperson.Group;
|
||||
|
||||
|
||||
/**
|
||||
* Service interface class for the Collection object.
|
||||
* The implementation of this class is responsible for all business logic calls for the Collection object and is
|
||||
* autowired by spring
|
||||
* The implementation of this class is responsible for all business logic calls
|
||||
* for the Collection object and is autowired by Spring.
|
||||
*
|
||||
* @author kevinvandevelde at atmire.com
|
||||
*/
|
||||
@@ -93,20 +91,6 @@ public interface CollectionService
|
||||
|
||||
public List<Collection> findGroupMapped(Context context, int actionID) throws java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* Set a metadata value
|
||||
*
|
||||
* @param context DSpace Context
|
||||
* @param collection Collection
|
||||
* @param field the name of the metadata field to get
|
||||
* @param value value to set the field to
|
||||
* @throws MissingResourceException if resource missing
|
||||
* @throws SQLException if database error
|
||||
*/
|
||||
@Deprecated
|
||||
public void setMetadata(Context context, Collection collection, String field, String value)
|
||||
throws MissingResourceException, SQLException;
|
||||
|
||||
/**
|
||||
* Give the collection a logo. Passing in <code>null</code> removes any
|
||||
* existing logo. You will need to set the format of the new logo bitstream
|
||||
@@ -149,9 +133,12 @@ public interface CollectionService
|
||||
* <code>null</code> can be passed in if there should be no associated
|
||||
* group for that workflow step; any existing group is NOT deleted.
|
||||
*
|
||||
* @param context current DSpace session.
|
||||
* @param collection Collection
|
||||
* @param step the workflow step (1-3)
|
||||
* @param group the new workflow group, or <code>null</code>
|
||||
* @throws SQLException passed through.
|
||||
* @throws AuthorizeException passed through.
|
||||
*/
|
||||
public void setWorkflowGroup(Context context, Collection collection, int step, Group group)
|
||||
throws SQLException, AuthorizeException;
|
||||
|
@@ -11,7 +11,6 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.MissingResourceException;
|
||||
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.content.Bitstream;
|
||||
@@ -87,22 +86,6 @@ public interface CommunityService extends DSpaceObjectService<Community>, DSpace
|
||||
*/
|
||||
public List<Community> findAllTop(Context context) throws SQLException;
|
||||
|
||||
/**
|
||||
* Set a metadata value
|
||||
*
|
||||
* @param context context
|
||||
* @param community community
|
||||
* @param field the name of the metadata field to get
|
||||
* @param value value to set the field to
|
||||
* @throws IllegalArgumentException if the requested metadata field doesn't exist
|
||||
* @throws MissingResourceException if resource missing
|
||||
* @throws SQLException if database error
|
||||
* @deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
public void setMetadata(Context context, Community community, String field, String value)
|
||||
throws MissingResourceException, SQLException;
|
||||
|
||||
/**
|
||||
* Give the community a logo. Passing in <code>null</code> removes any
|
||||
* existing logo. You will need to set the format of the new logo bitstream
|
||||
|
@@ -460,6 +460,24 @@ public interface DSpaceObjectService<T extends DSpaceObject> {
|
||||
public void setMetadataSingleValue(Context context, T dso, String schema, String element, String qualifier,
|
||||
String language, String value) throws SQLException;
|
||||
|
||||
/**
|
||||
* Set first metadata field value
|
||||
*
|
||||
* @param context DSpace context
|
||||
* @param dso DSpaceObject
|
||||
* @param field {schema, element, qualifier} for the desired field.
|
||||
* @param language the ISO639 language code, optionally followed by an underscore
|
||||
* and the ISO3166 country code. <code>null</code> means only
|
||||
* values with no language are removed, and <code>Item.ANY</code>
|
||||
* means values with any country code or no country code are
|
||||
* removed.
|
||||
* @param value metadata value
|
||||
* @throws SQLException if database error
|
||||
*/
|
||||
public void setMetadataSingleValue(Context context, T dso,
|
||||
MetadataFieldName field, String language, String value)
|
||||
throws SQLException;
|
||||
|
||||
public void updateLastModified(Context context, T dso) throws SQLException, AuthorizeException;
|
||||
|
||||
public void update(Context context, T dso) throws SQLException, AuthorizeException;
|
||||
|
@@ -269,6 +269,7 @@ public class CollectionTest extends AbstractDSpaceObjectTest {
|
||||
|
||||
/**
|
||||
* Test of setMetadata method, of class Collection.
|
||||
* @throws java.sql.SQLException if metadata cannot be set.
|
||||
*/
|
||||
@Test
|
||||
public void testSetMetadata() throws SQLException {
|
||||
@@ -280,13 +281,20 @@ public class CollectionTest extends AbstractDSpaceObjectTest {
|
||||
String provDesc = "provenance description";
|
||||
String license = "license text";
|
||||
|
||||
collectionService.setMetadata(context, collection, "name", name);
|
||||
collectionService.setMetadata(context, collection, "short_description", sdesc);
|
||||
collectionService.setMetadata(context, collection, "introductory_text", itext);
|
||||
collectionService.setMetadata(context, collection, "copyright_text", copy);
|
||||
collectionService.setMetadata(context, collection, "side_bar_text", sidebar);
|
||||
collectionService.setMetadata(context, collection, "provenance_description", provDesc);
|
||||
collectionService.setMetadata(context, collection, "license", license);
|
||||
collectionService.setMetadataSingleValue(context, collection,
|
||||
CollectionService.MD_NAME, null, name);
|
||||
collectionService.setMetadataSingleValue(context, collection,
|
||||
CollectionService.MD_SHORT_DESCRIPTION, null, sdesc);
|
||||
collectionService.setMetadataSingleValue(context, collection,
|
||||
CollectionService.MD_INTRODUCTORY_TEXT, null, itext);
|
||||
collectionService.setMetadataSingleValue(context, collection,
|
||||
CollectionService.MD_COPYRIGHT_TEXT, null, copy);
|
||||
collectionService.setMetadataSingleValue(context, collection,
|
||||
CollectionService.MD_SIDEBAR_TEXT, null, sidebar);
|
||||
collectionService.setMetadataSingleValue(context, collection,
|
||||
CollectionService.MD_PROVENANCE_DESCRIPTION, null, provDesc);
|
||||
collectionService.setMetadataSingleValue(context, collection,
|
||||
CollectionService.MD_LICENSE, null, license);
|
||||
|
||||
assertEquals("Name was not set properly.", name,
|
||||
collectionService.getMetadataFirstValue(collection,
|
||||
|
@@ -301,6 +301,7 @@ public class CommunityTest extends AbstractDSpaceObjectTest {
|
||||
|
||||
/**
|
||||
* Test of setMetadata method, of class Community.
|
||||
* @throws java.sql.SQLException if metadata cannot be set.
|
||||
*/
|
||||
@Test
|
||||
public void testSetMetadata() throws SQLException {
|
||||
@@ -310,11 +311,16 @@ public class CommunityTest extends AbstractDSpaceObjectTest {
|
||||
String copy = "copyright declaration";
|
||||
String sidebar = "side bar text";
|
||||
|
||||
communityService.setMetadata(context, c, "name", name);
|
||||
communityService.setMetadata(context, c, "short_description", sdesc);
|
||||
communityService.setMetadata(context, c, "introductory_text", itext);
|
||||
communityService.setMetadata(context, c, "copyright_text", copy);
|
||||
communityService.setMetadata(context, c, "side_bar_text", sidebar);
|
||||
communityService.setMetadataSingleValue(context, c,
|
||||
CommunityService.MD_NAME, null, name);
|
||||
communityService.setMetadataSingleValue(context, c,
|
||||
CommunityService.MD_SHORT_DESCRIPTION, null, sdesc);
|
||||
communityService.setMetadataSingleValue(context, c,
|
||||
CommunityService.MD_INTRODUCTORY_TEXT, null, itext);
|
||||
communityService.setMetadataSingleValue(context, c,
|
||||
CommunityService.MD_COPYRIGHT_TEXT, null, copy);
|
||||
communityService.setMetadataSingleValue(context, c,
|
||||
CommunityService.MD_SIDEBAR_TEXT, null, sidebar);
|
||||
|
||||
assertEquals("Name not set properly.", name,
|
||||
communityService.getMetadataFirstValue(c, CommunityService.MD_NAME, Item.ANY));
|
||||
|
@@ -101,10 +101,12 @@ public class DOIIdentifierProviderTest
|
||||
context.turnOffAuthorisationSystem();
|
||||
// Create an environment for our test objects to live in.
|
||||
community = communityService.create(null, context);
|
||||
communityService.setMetadata(context, community, "name", "A Test Community");
|
||||
communityService.setMetadataSingleValue(context, community,
|
||||
CommunityService.MD_NAME, null, "A Test Community");
|
||||
communityService.update(context, community);
|
||||
collection = collectionService.create(context, community);
|
||||
collectionService.setMetadata(context, collection, "name", "A Test Collection");
|
||||
collectionService.setMetadataSingleValue(context, collection,
|
||||
CollectionService.MD_NAME, null, "A Test Collection");
|
||||
collectionService.update(context, collection);
|
||||
//we need to commit the changes so we don't block the table for testing
|
||||
context.restoreAuthSystemState();
|
||||
|
@@ -180,11 +180,13 @@ public class EZIDIdentifierProviderTest
|
||||
|
||||
// Create an environment for our test objects to live in.
|
||||
community = communityService.create(community, context);
|
||||
communityService.setMetadata(context, community, "name", "A Test Community");
|
||||
communityService.setMetadataSingleValue(context, community,
|
||||
CommunityService.MD_NAME, null, "A Test Community");
|
||||
communityService.update(context, community);
|
||||
|
||||
collection = collectionService.create(context, community);
|
||||
collectionService.setMetadata(context, collection, "name", "A Test Collection");
|
||||
collectionService.setMetadataSingleValue(context, collection,
|
||||
CollectionService.MD_NAME, null, "A Test Collection");
|
||||
collectionService.update(context, collection);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user