Search in sources :

Example 6 with MetadataValue

use of org.dspace.content.MetadataValue in project DSpace by DSpace.

the class ConcatenateTest method testGetValues.

@Test
public void testGetValues() {
    // Setup objects utilized in unit test
    List<String> list = new ArrayList<>();
    List<String> valueList = new ArrayList<>();
    List<MetadataValue> metadataValueList = new ArrayList<>();
    MetadataValue metadataValue = mock(MetadataValue.class);
    Item item = mock(Item.class);
    metadataValueList.add(metadataValue);
    String s = "dc.title";
    list.add(s);
    List<String> splittedString = Splitter.on(".").splitToList(s);
    concatenate.setFields(list);
    valueList.add("TestValue");
    // Mock the state of objects utilized in getValues() to meet the success criteria of an invocation
    when(itemService.getMetadata(item, splittedString.size() > 0 ? splittedString.get(0) : null, splittedString.size() > 1 ? splittedString.get(1) : null, splittedString.size() > 2 ? splittedString.get(2) : null, Item.ANY, false)).thenReturn(metadataValueList);
    when(metadataValue.getValue()).thenReturn("TestValue");
    // The reported values should match our defined valueList
    assertEquals("TestGetValues 0", valueList, concatenate.getValues(context, item));
}
Also used : MetadataValue(org.dspace.content.MetadataValue) Item(org.dspace.content.Item) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 7 with MetadataValue

use of org.dspace.content.MetadataValue in project DSpace by DSpace.

the class DOIIdentifierProviderTest method testRemove_DOI_from_item_metadata.

@Test
public void testRemove_DOI_from_item_metadata() throws SQLException, AuthorizeException, IOException, IdentifierException, WorkflowException, IllegalAccessException {
    Item item = newItem();
    String doi = DOI.SCHEME + PREFIX + "/" + NAMESPACE_SEPARATOR + Long.toHexString(new Date().getTime());
    context.turnOffAuthorisationSystem();
    itemService.addMetadata(context, item, DOIIdentifierProvider.MD_SCHEMA, DOIIdentifierProvider.DOI_ELEMENT, DOIIdentifierProvider.DOI_QUALIFIER, null, doiService.DOIToExternalForm(doi));
    itemService.update(context, item);
    provider.removeDOIFromObject(context, item, doi);
    context.restoreAuthSystemState();
    List<MetadataValue> metadata = itemService.getMetadata(item, DOIIdentifierProvider.MD_SCHEMA, DOIIdentifierProvider.DOI_ELEMENT, DOIIdentifierProvider.DOI_QUALIFIER, null);
    boolean foundDOI = false;
    for (MetadataValue id : metadata) {
        if (id.getValue().equals(doiService.DOIToExternalForm(doi))) {
            foundDOI = true;
        }
    }
    assertFalse("Cannot remove DOI from item metadata.", foundDOI);
}
Also used : Item(org.dspace.content.Item) WorkspaceItem(org.dspace.content.WorkspaceItem) WorkflowItem(org.dspace.workflow.WorkflowItem) MetadataValue(org.dspace.content.MetadataValue) Date(java.util.Date) Test(org.junit.Test) AbstractUnitTest(org.dspace.AbstractUnitTest)

Example 8 with MetadataValue

use of org.dspace.content.MetadataValue in project DSpace by DSpace.

the class DOIIdentifierProviderTest method testStore_DOI_as_item_metadata.

@Test
public void testStore_DOI_as_item_metadata() throws SQLException, AuthorizeException, IOException, IdentifierException, IllegalAccessException, WorkflowException {
    Item item = newItem();
    String doi = DOI.SCHEME + PREFIX + "/" + NAMESPACE_SEPARATOR + Long.toHexString(new Date().getTime());
    context.turnOffAuthorisationSystem();
    provider.saveDOIToObject(context, item, doi);
    context.restoreAuthSystemState();
    List<MetadataValue> metadata = itemService.getMetadata(item, DOIIdentifierProvider.MD_SCHEMA, DOIIdentifierProvider.DOI_ELEMENT, DOIIdentifierProvider.DOI_QUALIFIER, null);
    boolean result = false;
    for (MetadataValue id : metadata) {
        if (id.getValue().equals(doiService.DOIToExternalForm(doi))) {
            result = true;
        }
    }
    assertTrue("Cannot store DOI as item metadata value.", result);
}
Also used : Item(org.dspace.content.Item) WorkspaceItem(org.dspace.content.WorkspaceItem) WorkflowItem(org.dspace.workflow.WorkflowItem) MetadataValue(org.dspace.content.MetadataValue) Date(java.util.Date) Test(org.junit.Test) AbstractUnitTest(org.dspace.AbstractUnitTest)

Example 9 with MetadataValue

use of org.dspace.content.MetadataValue in project DSpace by DSpace.

the class DOIIdentifierProviderTest method testDelete_all_DOIs.

@Test
public void testDelete_all_DOIs() throws SQLException, AuthorizeException, IOException, IdentifierException, IllegalAccessException, WorkflowException {
    Item item = newItem();
    String doi1 = this.createDOI(item, DOIIdentifierProvider.IS_REGISTERED, true);
    String doi2 = this.createDOI(item, DOIIdentifierProvider.IS_REGISTERED, true);
    // remove one of it
    context.turnOffAuthorisationSystem();
    provider.delete(context, item);
    context.restoreAuthSystemState();
    // assure that the right one was removed
    List<MetadataValue> metadata = itemService.getMetadata(item, DOIIdentifierProvider.MD_SCHEMA, DOIIdentifierProvider.DOI_ELEMENT, DOIIdentifierProvider.DOI_QUALIFIER, null);
    boolean foundDOI1 = false;
    boolean foundDOI2 = false;
    for (MetadataValue id : metadata) {
        if (id.getValue().equals(doiService.DOIToExternalForm(doi1))) {
            foundDOI1 = true;
        }
        if (id.getValue().equals(doiService.DOIToExternalForm(doi2))) {
            foundDOI2 = true;
        }
    }
    assertFalse("Cannot remove DOI from item metadata.", foundDOI1);
    assertFalse("Did not removed all DOIs from item metadata.", foundDOI2);
    DOI doiRow1 = doiService.findByDoi(context, doi1.substring(DOI.SCHEME.length()));
    assumeNotNull(doiRow1);
    assertTrue("Status of deleted DOI was not set correctly.", DOIIdentifierProvider.TO_BE_DELETED.equals(doiRow1.getStatus()));
    DOI doiRow2 = doiService.findByDoi(context, doi1.substring(DOI.SCHEME.length()));
    assumeNotNull(doiRow2);
    assertTrue("Did not set the status of all deleted DOIs as expected.", DOIIdentifierProvider.TO_BE_DELETED.equals(doiRow2.getStatus()));
}
Also used : Item(org.dspace.content.Item) WorkspaceItem(org.dspace.content.WorkspaceItem) WorkflowItem(org.dspace.workflow.WorkflowItem) MetadataValue(org.dspace.content.MetadataValue) Test(org.junit.Test) AbstractUnitTest(org.dspace.AbstractUnitTest)

Example 10 with MetadataValue

use of org.dspace.content.MetadataValue in project DSpace by DSpace.

the class AtomStatementDisseminator method stringMetadata.

private String stringMetadata(Item item, String field) {
    if (field == null) {
        return null;
    }
    List<MetadataValue> dcvs = itemService.getMetadataByMetadataString(item, field);
    if (dcvs == null || dcvs.isEmpty()) {
        return null;
    }
    StringBuilder md = new StringBuilder();
    for (MetadataValue dcv : dcvs) {
        if (md.length() > 0) {
            md.append(", ");
        }
        md.append(dcv.getValue());
    }
    return md.toString();
}
Also used : MetadataValue(org.dspace.content.MetadataValue)

Aggregations

MetadataValue (org.dspace.content.MetadataValue)140 Item (org.dspace.content.Item)45 ArrayList (java.util.ArrayList)39 SQLException (java.sql.SQLException)29 MetadataField (org.dspace.content.MetadataField)22 Test (org.junit.Test)21 Date (java.util.Date)16 Collection (org.dspace.content.Collection)16 IOException (java.io.IOException)15 AuthorizeException (org.dspace.authorize.AuthorizeException)13 List (java.util.List)11 Community (org.dspace.content.Community)11 WorkspaceItem (org.dspace.content.WorkspaceItem)11 MetadataValueRest (org.dspace.app.rest.model.MetadataValueRest)10 DCDate (org.dspace.content.DCDate)9 MetadataSchema (org.dspace.content.MetadataSchema)9 EPerson (org.dspace.eperson.EPerson)9 WorkflowItem (org.dspace.workflow.WorkflowItem)9 AbstractUnitTest (org.dspace.AbstractUnitTest)8 AbstractEntityIntegrationTest (org.dspace.app.rest.test.AbstractEntityIntegrationTest)8