mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-15 14:03:17 +00:00
[DS-3439] Copy collection template item specified metadata during Sword v2 METS deposit ingestion.
This commit is contained in:
@@ -18,6 +18,7 @@ import java.util.LinkedList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -276,6 +277,55 @@ public class ItemServiceImpl extends DSpaceObjectServiceImpl<Item> implements It
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void populateWithTemplateItemMetadata(Context context, Collection collection, boolean template, Item item)
|
||||||
|
throws SQLException {
|
||||||
|
|
||||||
|
Item templateItem = collection.getTemplateItem();
|
||||||
|
|
||||||
|
Optional<MetadataValue> colEntityType = getDSpaceEntityType(collection);
|
||||||
|
Optional<MetadataValue> templateItemEntityType = getDSpaceEntityType(templateItem);
|
||||||
|
|
||||||
|
if (template && colEntityType.isPresent() && templateItemEntityType.isPresent() &&
|
||||||
|
!StringUtils.equals(colEntityType.get().getValue(), templateItemEntityType.get().getValue())) {
|
||||||
|
throw new IllegalStateException("The template item has entity type : (" +
|
||||||
|
templateItemEntityType.get().getValue() + ") different than collection entity type : " +
|
||||||
|
colEntityType.get().getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (template && colEntityType.isPresent() && templateItemEntityType.isEmpty()) {
|
||||||
|
MetadataValue original = colEntityType.get();
|
||||||
|
MetadataField metadataField = original.getMetadataField();
|
||||||
|
MetadataSchema metadataSchema = metadataField.getMetadataSchema();
|
||||||
|
// NOTE: dspace.entity.type = <blank> does not make sense
|
||||||
|
// the collection entity type is by default blank when a collection is first created
|
||||||
|
if (StringUtils.isNotBlank(original.getValue())) {
|
||||||
|
addMetadata(context, item, metadataSchema.getName(), metadataField.getElement(),
|
||||||
|
metadataField.getQualifier(), original.getLanguage(), original.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (template && (templateItem != null)) {
|
||||||
|
List<MetadataValue> md = getMetadata(templateItem, Item.ANY, Item.ANY, Item.ANY, Item.ANY);
|
||||||
|
|
||||||
|
for (MetadataValue aMd : md) {
|
||||||
|
MetadataField metadataField = aMd.getMetadataField();
|
||||||
|
MetadataSchema metadataSchema = metadataField.getMetadataSchema();
|
||||||
|
addMetadata(context, item, metadataSchema.getName(), metadataField.getElement(),
|
||||||
|
metadataField.getQualifier(), aMd.getLanguage(), aMd.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Optional<MetadataValue> getDSpaceEntityType(DSpaceObject dSpaceObject) {
|
||||||
|
return Objects.nonNull(dSpaceObject) ? dSpaceObject.getMetadata()
|
||||||
|
.stream()
|
||||||
|
.filter(x -> x.getMetadataField().toString('.')
|
||||||
|
.equalsIgnoreCase("dspace.entity.type"))
|
||||||
|
.findFirst()
|
||||||
|
: Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterator<Item> findAll(Context context) throws SQLException {
|
public Iterator<Item> findAll(Context context) throws SQLException {
|
||||||
return itemDAO.findAll(context, true);
|
return itemDAO.findAll(context, true);
|
||||||
|
@@ -12,11 +12,8 @@ import java.sql.SQLException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.dspace.app.util.DCInputsReaderException;
|
import org.dspace.app.util.DCInputsReaderException;
|
||||||
import org.dspace.app.util.Util;
|
import org.dspace.app.util.Util;
|
||||||
@@ -134,41 +131,7 @@ public class WorkspaceItemServiceImpl implements WorkspaceItemService {
|
|||||||
.addPolicy(context, item, Constants.DELETE, item.getSubmitter(), ResourcePolicy.TYPE_SUBMISSION);
|
.addPolicy(context, item, Constants.DELETE, item.getSubmitter(), ResourcePolicy.TYPE_SUBMISSION);
|
||||||
|
|
||||||
// Copy template if appropriate
|
// Copy template if appropriate
|
||||||
Item templateItem = collection.getTemplateItem();
|
itemService.populateWithTemplateItemMetadata(context, collection, template, item);
|
||||||
|
|
||||||
Optional<MetadataValue> colEntityType = getDSpaceEntityType(collection);
|
|
||||||
Optional<MetadataValue> templateItemEntityType = getDSpaceEntityType(templateItem);
|
|
||||||
|
|
||||||
if (template && colEntityType.isPresent() && templateItemEntityType.isPresent() &&
|
|
||||||
!StringUtils.equals(colEntityType.get().getValue(), templateItemEntityType.get().getValue())) {
|
|
||||||
throw new IllegalStateException("The template item has entity type : (" +
|
|
||||||
templateItemEntityType.get().getValue() + ") different than collection entity type : " +
|
|
||||||
colEntityType.get().getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (template && colEntityType.isPresent() && templateItemEntityType.isEmpty()) {
|
|
||||||
MetadataValue original = colEntityType.get();
|
|
||||||
MetadataField metadataField = original.getMetadataField();
|
|
||||||
MetadataSchema metadataSchema = metadataField.getMetadataSchema();
|
|
||||||
// NOTE: dspace.entity.type = <blank> does not make sense
|
|
||||||
// the collection entity type is by default blank when a collection is first created
|
|
||||||
if (StringUtils.isNotBlank(original.getValue())) {
|
|
||||||
itemService.addMetadata(context, item, metadataSchema.getName(), metadataField.getElement(),
|
|
||||||
metadataField.getQualifier(), original.getLanguage(), original.getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (template && (templateItem != null)) {
|
|
||||||
List<MetadataValue> md = itemService.getMetadata(templateItem, Item.ANY, Item.ANY, Item.ANY, Item.ANY);
|
|
||||||
|
|
||||||
for (MetadataValue aMd : md) {
|
|
||||||
MetadataField metadataField = aMd.getMetadataField();
|
|
||||||
MetadataSchema metadataSchema = metadataField.getMetadataSchema();
|
|
||||||
itemService.addMetadata(context, item, metadataSchema.getName(), metadataField.getElement(),
|
|
||||||
metadataField.getQualifier(), aMd.getLanguage(),
|
|
||||||
aMd.getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
itemService.update(context, item);
|
itemService.update(context, item);
|
||||||
|
|
||||||
@@ -204,15 +167,6 @@ public class WorkspaceItemServiceImpl implements WorkspaceItemService {
|
|||||||
return workspaceItem;
|
return workspaceItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Optional<MetadataValue> getDSpaceEntityType(DSpaceObject dSpaceObject) {
|
|
||||||
return Objects.nonNull(dSpaceObject) ? dSpaceObject.getMetadata()
|
|
||||||
.stream()
|
|
||||||
.filter(x -> x.getMetadataField().toString('.')
|
|
||||||
.equalsIgnoreCase("dspace.entity.type"))
|
|
||||||
.findFirst()
|
|
||||||
: Optional.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WorkspaceItem create(Context c, WorkflowItem workflowItem) throws SQLException, AuthorizeException {
|
public WorkspaceItem create(Context c, WorkflowItem workflowItem) throws SQLException, AuthorizeException {
|
||||||
WorkspaceItem workspaceItem = workspaceItemDAO.create(c, new WorkspaceItem());
|
WorkspaceItem workspaceItem = workspaceItemDAO.create(c, new WorkspaceItem());
|
||||||
|
@@ -636,6 +636,9 @@ public abstract class AbstractMETSIngester extends AbstractPackageIngester {
|
|||||||
owningCollection = inProgressSubmission.getCollection();
|
owningCollection = inProgressSubmission.getCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
itemService.populateWithTemplateItemMetadata(context, owningCollection, params.useCollectionTemplate(),
|
||||||
|
item);
|
||||||
|
|
||||||
addLicense(context, item, license, owningCollection
|
addLicense(context, item, license, owningCollection
|
||||||
, params);
|
, params);
|
||||||
|
|
||||||
|
@@ -83,6 +83,18 @@ public interface ItemService
|
|||||||
*/
|
*/
|
||||||
public Item createTemplateItem(Context context, Collection collection) throws SQLException, AuthorizeException;
|
public Item createTemplateItem(Context context, Collection collection) throws SQLException, AuthorizeException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Populate the given item with all template item specified metadata.
|
||||||
|
*
|
||||||
|
* @param context DSpace context object
|
||||||
|
* @param collection Collection (parent)
|
||||||
|
* @param template if <code>true</code>, the item inherits all collection's template item metadata
|
||||||
|
* @param item item to populate with template item specified metadata
|
||||||
|
* @throws SQLException if database error
|
||||||
|
*/
|
||||||
|
public void populateWithTemplateItemMetadata (Context context, Collection collection, boolean template, Item item)
|
||||||
|
throws SQLException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all the items in the archive. Only items with the "in archive" flag
|
* Get all the items in the archive. Only items with the "in archive" flag
|
||||||
* set are included. The order of the list is indeterminate.
|
* set are included. The order of the list is indeterminate.
|
||||||
|
Reference in New Issue
Block a user