DSpace refactored service api

This commit is contained in:
KevinVdV
2014-11-08 09:19:09 +01:00
parent fcb3717aad
commit 54222f3c1d
1145 changed files with 52233 additions and 57064 deletions

View File

@@ -10,20 +10,27 @@ package org.dspace.identifier;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
import org.dspace.AbstractUnitTest;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.*;
import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.content.service.CollectionService;
import org.dspace.content.service.CommunityService;
import org.dspace.content.service.ItemService;
import org.dspace.content.service.WorkspaceItemService;
import org.dspace.core.Context;
import org.dspace.identifier.ezid.DateToYear;
import org.dspace.identifier.ezid.Transform;
import org.dspace.kernel.ServiceManager;
import org.dspace.services.ConfigurationService;
import org.dspace.utils.DSpace;
import org.dspace.workflow.WorkflowException;
import org.dspace.workflow.WorkflowItem;
import org.dspace.workflow.WorkflowManager;
import org.dspace.workflow.factory.WorkflowServiceFactory;
import org.junit.*;
import static org.junit.Assert.*;
@@ -58,26 +65,29 @@ public class EZIDIdentifierProviderTest
private static Collection collection;
protected CommunityService communityService = ContentServiceFactory.getInstance().getCommunityService();
protected CollectionService collectionService = ContentServiceFactory.getInstance().getCollectionService();
protected ItemService itemService = ContentServiceFactory.getInstance().getItemService();
protected WorkspaceItemService workspaceItemService = ContentServiceFactory.getInstance().getWorkspaceItemService();
/** The most recently created test Item's ID */
private static int itemID;
private static Item item;
public EZIDIdentifierProviderTest()
{
}
private static void dumpMetadata(Item eyetem)
private void dumpMetadata(Item eyetem)
{
if (null == eyetem)
return;
Metadatum[] metadata = eyetem.getMetadata("dc", Item.ANY, Item.ANY, Item.ANY);
for (Metadatum metadatum : metadata)
List<MetadataValue> metadata = itemService.getMetadata(eyetem, "dc", Item.ANY, Item.ANY, Item.ANY);
for (MetadataValue metadatum : metadata)
System.out.printf("Metadata: %s.%s.%s(%s) = %s\n",
metadatum.schema,
metadatum.element,
metadatum.qualifier,
metadatum.language,
metadatum.value);
metadatum.getMetadataField().getMetadataSchema().getName(),
metadatum.getMetadataField().getElement(),
metadatum.getMetadataField().getQualifier(),
metadatum.getLanguage(),
metadatum.getValue());
}
/**
@@ -88,23 +98,25 @@ public class EZIDIdentifierProviderTest
* @throws IOException
*/
private Item newItem(Context ctx)
throws SQLException, AuthorizeException, IOException
{
throws SQLException, AuthorizeException, IOException, WorkflowException {
ctx.turnOffAuthorisationSystem();
//Install a fresh item
WorkspaceItem wsItem = WorkspaceItem.create(context, collection, false);
Item item = InstallItem.installItem(context, wsItem);
itemID = item.getID();
context.turnOffAuthorisationSystem();
item.addMetadata("dc", "contributor", "author", null, "Author, A. N.");
item.addMetadata("dc", "title", null, null, "A Test Object");
item.addMetadata("dc", "publisher", null, null, "DSpace Test Harness");
item.update();
WorkspaceItem wsItem = workspaceItemService.create(context, collection, false);
WorkflowItem wfItem = WorkflowServiceFactory.getInstance().getWorkflowService().start(context, wsItem);
item = wfItem.getItem();
itemService.addMetadata(context, item, "dc", "contributor", "author", null, "Author, A. N.");
itemService.addMetadata(context, item, "dc", "title", null, null, "A Test Object");
itemService.addMetadata(context, item, "dc", "publisher", null, null, "DSpace Test Harness");
itemService.update(context, item);
// Commit work, clean up
ctx.commit();
ctx.restoreAuthSystemState();
return item;
@@ -124,12 +136,20 @@ public class EZIDIdentifierProviderTest
// Don't try to send mail.
config.setProperty("mail.server.disabled", "true");
EZIDIdentifierProvider instance = new EZIDIdentifierProvider();
instance.setConfigurationService(config);
instance.setCrosswalk(aCrosswalk);
instance.setCrosswalkTransform(crosswalkTransforms);
instance.setItemService(ContentServiceFactory.getInstance().getItemService());
new DSpace().getServiceManager().registerServiceNoAutowire(EZIDIdentifierProvider.class.getName(), instance);
assertNotNull(new DSpace().getServiceManager().getServiceByName(EZIDIdentifierProvider.class.getName(), EZIDIdentifierProvider.class));
}
@AfterClass
public static void tearDownClass()
throws Exception
{
new DSpace().getServiceManager().unregisterService(EZIDIdentifierProvider.class.getName());
System.out.print("Tearing down\n\n");
}
@@ -140,15 +160,13 @@ public class EZIDIdentifierProviderTest
context.turnOffAuthorisationSystem();
// Create an environment for our test objects to live in.
community = Community.create(null, context);
community.setMetadata("name", "A Test Community");
community.update();
community = communityService.create(community, context);
communityService.setMetadata(context, community, "name", "A Test Community");
communityService.update(context, community);
collection = community.createCollection();
collection.setMetadata("name", "A Test Collection");
collection.update();
context.commit();
collection = collectionService.create(context, community);
collectionService.setMetadata(context, collection, "name", "A Test Collection");
collectionService.update(context, collection);
}
@After
@@ -157,7 +175,7 @@ public class EZIDIdentifierProviderTest
{
context.restoreAuthSystemState();
dumpMetadata(Item.find(context, itemID));
dumpMetadata(item);
}
/**
@@ -168,7 +186,7 @@ public class EZIDIdentifierProviderTest
{
System.out.println("supports Class");
EZIDIdentifierProvider instance = new EZIDIdentifierProvider();
EZIDIdentifierProvider instance = new DSpace().getServiceManager().getServiceByName(EZIDIdentifierProvider.class.getName(), EZIDIdentifierProvider.class);
Class<? extends Identifier> identifier = DOI.class;
boolean result = instance.supports(identifier);
@@ -183,7 +201,7 @@ public class EZIDIdentifierProviderTest
{
System.out.println("supports String");
EZIDIdentifierProvider instance = new EZIDIdentifierProvider();
EZIDIdentifierProvider instance = new DSpace().getServiceManager().getServiceByName(EZIDIdentifierProvider.class.getName(), EZIDIdentifierProvider.class);
String identifier = "doi:" + TEST_SHOULDER;
boolean result = instance.supports(identifier);
@@ -394,17 +412,17 @@ public class EZIDIdentifierProviderTest
System.out.println("crosswalkMetadata");
// Set up the instance to be tested
EZIDIdentifierProvider instance = new EZIDIdentifierProvider();
instance.setConfigurationService(config);
instance.setCrosswalk(aCrosswalk);
instance.setCrosswalkTransform(crosswalkTransforms);
EZIDIdentifierProvider instance = new DSpace().getServiceManager().getServiceByName(EZIDIdentifierProvider.class.getName(), EZIDIdentifierProvider.class);
// instance.setConfigurationService(config);
// instance.setCrosswalk(aCrosswalk);
// instance.setCrosswalkTransform(crosswalkTransforms);
// Let's have a fresh Item to work with
DSpaceObject dso = newItem(context);
String handle = dso.getHandle();
// Test!
Map<String, String> metadata = instance.crosswalkMetadata(dso);
Map<String, String> metadata = instance.crosswalkMetadata(context, dso);
// Evaluate
String target = (String) metadata.get("_target");