mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-10 11:33:11 +00:00
[CSTPER-221] Handle Providers enhanced for Communities and Collections
This commit is contained in:
@@ -55,6 +55,8 @@ import org.dspace.eperson.service.SubscribeService;
|
|||||||
import org.dspace.event.Event;
|
import org.dspace.event.Event;
|
||||||
import org.dspace.harvest.HarvestedCollection;
|
import org.dspace.harvest.HarvestedCollection;
|
||||||
import org.dspace.harvest.service.HarvestedCollectionService;
|
import org.dspace.harvest.service.HarvestedCollectionService;
|
||||||
|
import org.dspace.identifier.IdentifierException;
|
||||||
|
import org.dspace.identifier.service.IdentifierService;
|
||||||
import org.dspace.workflow.factory.WorkflowServiceFactory;
|
import org.dspace.workflow.factory.WorkflowServiceFactory;
|
||||||
import org.dspace.xmlworkflow.WorkflowConfigurationException;
|
import org.dspace.xmlworkflow.WorkflowConfigurationException;
|
||||||
import org.dspace.xmlworkflow.factory.XmlWorkflowFactory;
|
import org.dspace.xmlworkflow.factory.XmlWorkflowFactory;
|
||||||
@@ -92,6 +94,8 @@ public class CollectionServiceImpl extends DSpaceObjectServiceImpl<Collection> i
|
|||||||
protected CommunityService communityService;
|
protected CommunityService communityService;
|
||||||
@Autowired(required = true)
|
@Autowired(required = true)
|
||||||
protected GroupService groupService;
|
protected GroupService groupService;
|
||||||
|
@Autowired(required = true)
|
||||||
|
protected IdentifierService identifierService;
|
||||||
|
|
||||||
@Autowired(required = true)
|
@Autowired(required = true)
|
||||||
protected LicenseService licenseService;
|
protected LicenseService licenseService;
|
||||||
@@ -131,11 +135,15 @@ public class CollectionServiceImpl extends DSpaceObjectServiceImpl<Collection> i
|
|||||||
//Add our newly created collection to our community, authorization checks occur in THIS method
|
//Add our newly created collection to our community, authorization checks occur in THIS method
|
||||||
communityService.addCollection(context, community, newCollection);
|
communityService.addCollection(context, community, newCollection);
|
||||||
|
|
||||||
//Update our community so we have a collection identifier
|
//Update our collection so we have a collection identifier
|
||||||
|
try {
|
||||||
if (handle == null) {
|
if (handle == null) {
|
||||||
handleService.createHandle(context, newCollection);
|
identifierService.register(context, newCollection);
|
||||||
} else {
|
} else {
|
||||||
handleService.createHandle(context, newCollection, handle);
|
identifierService.register(context, newCollection, handle);
|
||||||
|
}
|
||||||
|
} catch (IdentifierException e) {
|
||||||
|
throw new RuntimeException("Can't create an Identifier!");
|
||||||
}
|
}
|
||||||
|
|
||||||
// create the default authorization policy for collections
|
// create the default authorization policy for collections
|
||||||
|
@@ -37,6 +37,8 @@ import org.dspace.core.LogManager;
|
|||||||
import org.dspace.eperson.Group;
|
import org.dspace.eperson.Group;
|
||||||
import org.dspace.eperson.service.GroupService;
|
import org.dspace.eperson.service.GroupService;
|
||||||
import org.dspace.event.Event;
|
import org.dspace.event.Event;
|
||||||
|
import org.dspace.identifier.IdentifierException;
|
||||||
|
import org.dspace.identifier.service.IdentifierService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -69,6 +71,8 @@ public class CommunityServiceImpl extends DSpaceObjectServiceImpl<Community> imp
|
|||||||
protected BitstreamService bitstreamService;
|
protected BitstreamService bitstreamService;
|
||||||
@Autowired(required = true)
|
@Autowired(required = true)
|
||||||
protected SiteService siteService;
|
protected SiteService siteService;
|
||||||
|
@Autowired(required = true)
|
||||||
|
protected IdentifierService identifierService;
|
||||||
|
|
||||||
protected CommunityServiceImpl() {
|
protected CommunityServiceImpl() {
|
||||||
super();
|
super();
|
||||||
@@ -92,13 +96,12 @@ public class CommunityServiceImpl extends DSpaceObjectServiceImpl<Community> imp
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (handle == null) {
|
if (handle == null) {
|
||||||
handleService.createHandle(context, newCommunity);
|
identifierService.register(context, newCommunity);
|
||||||
} else {
|
} else {
|
||||||
handleService.createHandle(context, newCommunity, handle);
|
identifierService.register(context, newCommunity, handle);
|
||||||
}
|
}
|
||||||
} catch (IllegalStateException ie) {
|
} catch (IdentifierException e) {
|
||||||
//If an IllegalStateException is thrown, then an existing object is already using this handle
|
throw new RuntimeException("Can't create an Identifier!");
|
||||||
throw ie;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parent != null) {
|
if (parent != null) {
|
||||||
|
@@ -13,11 +13,14 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.dspace.authorize.AuthorizeException;
|
import org.dspace.authorize.AuthorizeException;
|
||||||
|
import org.dspace.content.Collection;
|
||||||
|
import org.dspace.content.Community;
|
||||||
import org.dspace.content.DSpaceObject;
|
import org.dspace.content.DSpaceObject;
|
||||||
import org.dspace.content.Item;
|
import org.dspace.content.Item;
|
||||||
import org.dspace.content.MetadataSchemaEnum;
|
import org.dspace.content.MetadataSchemaEnum;
|
||||||
import org.dspace.content.MetadataValue;
|
import org.dspace.content.MetadataValue;
|
||||||
import org.dspace.content.service.ItemService;
|
import org.dspace.content.factory.ContentServiceFactory;
|
||||||
|
import org.dspace.content.service.DSpaceObjectService;
|
||||||
import org.dspace.core.ConfigurationManager;
|
import org.dspace.core.ConfigurationManager;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.dspace.core.LogManager;
|
import org.dspace.core.LogManager;
|
||||||
@@ -48,7 +51,7 @@ public class HandleIdentifierProvider extends IdentifierProvider {
|
|||||||
@Autowired(required = true)
|
@Autowired(required = true)
|
||||||
protected HandleService handleService;
|
protected HandleService handleService;
|
||||||
@Autowired(required = true)
|
@Autowired(required = true)
|
||||||
protected ItemService itemService;
|
protected ContentServiceFactory contentServiceFactory;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean supports(Class<? extends Identifier> identifier) {
|
public boolean supports(Class<? extends Identifier> identifier) {
|
||||||
@@ -91,7 +94,7 @@ public class HandleIdentifierProvider extends IdentifierProvider {
|
|||||||
String id = mint(context, dso);
|
String id = mint(context, dso);
|
||||||
|
|
||||||
// move canonical to point the latest version
|
// move canonical to point the latest version
|
||||||
if (dso instanceof Item) {
|
if (dso instanceof Item || dso instanceof Collection || dso instanceof Community) {
|
||||||
Item item = (Item) dso;
|
Item item = (Item) dso;
|
||||||
populateHandleMetadata(context, item, id);
|
populateHandleMetadata(context, item, id);
|
||||||
}
|
}
|
||||||
@@ -108,7 +111,7 @@ public class HandleIdentifierProvider extends IdentifierProvider {
|
|||||||
public void register(Context context, DSpaceObject dso, String identifier) {
|
public void register(Context context, DSpaceObject dso, String identifier) {
|
||||||
try {
|
try {
|
||||||
handleService.createHandle(context, dso, identifier);
|
handleService.createHandle(context, dso, identifier);
|
||||||
if (dso instanceof Item) {
|
if (dso instanceof Item || dso instanceof Collection || dso instanceof Community) {
|
||||||
Item item = (Item) dso;
|
Item item = (Item) dso;
|
||||||
populateHandleMetadata(context, item, identifier);
|
populateHandleMetadata(context, item, identifier);
|
||||||
}
|
}
|
||||||
@@ -220,22 +223,24 @@ public class HandleIdentifierProvider extends IdentifierProvider {
|
|||||||
return prefix;
|
return prefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void populateHandleMetadata(Context context, Item item, String handle)
|
protected void populateHandleMetadata(Context context, DSpaceObject dso, String handle)
|
||||||
throws SQLException, IOException, AuthorizeException {
|
throws SQLException, IOException, AuthorizeException {
|
||||||
String handleref = handleService.getCanonicalForm(handle);
|
String handleref = handleService.getCanonicalForm(handle);
|
||||||
|
|
||||||
|
DSpaceObjectService<DSpaceObject> dsoService = contentServiceFactory.getDSpaceObjectService(dso);
|
||||||
|
|
||||||
// Add handle as identifier.uri DC value.
|
// Add handle as identifier.uri DC value.
|
||||||
// First check that identifier doesn't already exist.
|
// First check that identifier doesn't already exist.
|
||||||
boolean identifierExists = false;
|
boolean identifierExists = false;
|
||||||
List<MetadataValue> identifiers = itemService
|
List<MetadataValue> identifiers = dsoService
|
||||||
.getMetadata(item, MetadataSchemaEnum.DC.getName(), "identifier", "uri", Item.ANY);
|
.getMetadata(dso, MetadataSchemaEnum.DC.getName(), "identifier", "uri", Item.ANY);
|
||||||
for (MetadataValue identifier : identifiers) {
|
for (MetadataValue identifier : identifiers) {
|
||||||
if (handleref.equals(identifier.getValue())) {
|
if (handleref.equals(identifier.getValue())) {
|
||||||
identifierExists = true;
|
identifierExists = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!identifierExists) {
|
if (!identifierExists) {
|
||||||
itemService.addMetadata(context, item, MetadataSchemaEnum.DC.getName(),
|
dsoService.addMetadata(context, dso, MetadataSchemaEnum.DC.getName(),
|
||||||
"identifier", "uri", null, handleref);
|
"identifier", "uri", null, handleref);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -17,10 +17,14 @@ import java.util.regex.Pattern;
|
|||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.dspace.authorize.AuthorizeException;
|
import org.dspace.authorize.AuthorizeException;
|
||||||
|
import org.dspace.content.Collection;
|
||||||
|
import org.dspace.content.Community;
|
||||||
import org.dspace.content.DSpaceObject;
|
import org.dspace.content.DSpaceObject;
|
||||||
import org.dspace.content.Item;
|
import org.dspace.content.Item;
|
||||||
import org.dspace.content.MetadataSchemaEnum;
|
import org.dspace.content.MetadataSchemaEnum;
|
||||||
import org.dspace.content.MetadataValue;
|
import org.dspace.content.MetadataValue;
|
||||||
|
import org.dspace.content.factory.ContentServiceFactory;
|
||||||
|
import org.dspace.content.service.DSpaceObjectService;
|
||||||
import org.dspace.content.service.ItemService;
|
import org.dspace.content.service.ItemService;
|
||||||
import org.dspace.core.ConfigurationManager;
|
import org.dspace.core.ConfigurationManager;
|
||||||
import org.dspace.core.Constants;
|
import org.dspace.core.Constants;
|
||||||
@@ -67,6 +71,9 @@ public class VersionedHandleIdentifierProvider extends IdentifierProvider {
|
|||||||
@Autowired(required = true)
|
@Autowired(required = true)
|
||||||
private ItemService itemService;
|
private ItemService itemService;
|
||||||
|
|
||||||
|
@Autowired(required = true)
|
||||||
|
protected ContentServiceFactory contentServiceFactory;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean supports(Class<? extends Identifier> identifier) {
|
public boolean supports(Class<? extends Identifier> identifier) {
|
||||||
return Handle.class.isAssignableFrom(identifier);
|
return Handle.class.isAssignableFrom(identifier);
|
||||||
@@ -110,6 +117,9 @@ public class VersionedHandleIdentifierProvider extends IdentifierProvider {
|
|||||||
if (dso instanceof Item) {
|
if (dso instanceof Item) {
|
||||||
populateHandleMetadata(context, (Item) dso, id);
|
populateHandleMetadata(context, (Item) dso, id);
|
||||||
}
|
}
|
||||||
|
if (dso instanceof Collection || dso instanceof Community) {
|
||||||
|
populateNotVersionedHandleMetadata(context, dso, id);
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error(LogManager.getHeader(context, "Error while attempting to create handle",
|
log.error(LogManager.getHeader(context, "Error while attempting to create handle",
|
||||||
"Item id: " + (dso != null ? dso.getID() : "")), e);
|
"Item id: " + (dso != null ? dso.getID() : "")), e);
|
||||||
@@ -122,6 +132,7 @@ public class VersionedHandleIdentifierProvider extends IdentifierProvider {
|
|||||||
@Override
|
@Override
|
||||||
public void register(Context context, DSpaceObject dso, String identifier)
|
public void register(Context context, DSpaceObject dso, String identifier)
|
||||||
throws IdentifierException {
|
throws IdentifierException {
|
||||||
|
// FIXME are Collections and Communities to be handled here?
|
||||||
if (dso instanceof Item && identifier != null) {
|
if (dso instanceof Item && identifier != null) {
|
||||||
Item item = (Item) dso;
|
Item item = (Item) dso;
|
||||||
|
|
||||||
@@ -444,4 +455,27 @@ public class VersionedHandleIdentifierProvider extends IdentifierProvider {
|
|||||||
}
|
}
|
||||||
itemService.update(context, item);
|
itemService.update(context, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void populateNotVersionedHandleMetadata(Context context, DSpaceObject dso, String handle)
|
||||||
|
throws SQLException, IOException, AuthorizeException {
|
||||||
|
String handleref = handleService.getCanonicalForm(handle);
|
||||||
|
|
||||||
|
DSpaceObjectService<DSpaceObject> dsoService = contentServiceFactory.getDSpaceObjectService(dso);
|
||||||
|
|
||||||
|
// Add handle as identifier.uri DC value.
|
||||||
|
// First check that identifier doesn't already exist.
|
||||||
|
boolean identifierExists = false;
|
||||||
|
// List<MetadataValue> identifiers = dsoObjectService
|
||||||
|
List<MetadataValue> identifiers = dsoService
|
||||||
|
.getMetadata(dso, MetadataSchemaEnum.DC.getName(), "identifier", "uri", Item.ANY);
|
||||||
|
for (MetadataValue identifier : identifiers) {
|
||||||
|
if (handleref.equals(identifier.getValue())) {
|
||||||
|
identifierExists = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!identifierExists) {
|
||||||
|
dsoService.addMetadata(context, dso, MetadataSchemaEnum.DC.getName(),
|
||||||
|
"identifier", "uri", null, handleref);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user