mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-16 06:23:10 +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;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user