Search in sources :

Example 36 with MetadataValue

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

the class Item method setup.

private void setup(org.dspace.content.Item item, ServletContext servletContext, String expand, Context context) throws SQLException {
    List<String> expandFields = new ArrayList<String>();
    if (expand != null) {
        expandFields = Arrays.asList(expand.split(","));
    }
    if (expandFields.contains("metadata") || expandFields.contains("all")) {
        metadata = new ArrayList<MetadataEntry>();
        List<MetadataValue> metadataValues = itemService.getMetadata(item, org.dspace.content.Item.ANY, org.dspace.content.Item.ANY, org.dspace.content.Item.ANY, org.dspace.content.Item.ANY);
        for (MetadataValue metadataValue : metadataValues) {
            MetadataField metadataField = metadataValue.getMetadataField();
            if (!metadataExposureService.isHidden(context, metadataField.getMetadataSchema().getName(), metadataField.getElement(), metadataField.getQualifier())) {
                metadata.add(new MetadataEntry(metadataField.toString('.'), metadataValue.getValue(), metadataValue.getLanguage()));
            }
        }
    } else {
        this.addExpand("metadata");
    }
    this.setArchived(Boolean.toString(item.isArchived()));
    this.setWithdrawn(Boolean.toString(item.isWithdrawn()));
    this.setLastModified(item.getLastModified().toString());
    if (expandFields.contains("parentCollection") || expandFields.contains("all")) {
        if (item.getOwningCollection() != null) {
            this.parentCollection = new Collection(item.getOwningCollection(), servletContext, null, context, null, null);
        } else {
            this.addExpand("parentCollection");
        }
    } else {
        this.addExpand("parentCollection");
    }
    if (expandFields.contains("parentCollectionList") || expandFields.contains("all")) {
        this.parentCollectionList = new ArrayList<Collection>();
        List<org.dspace.content.Collection> collections = item.getCollections();
        for (org.dspace.content.Collection collection : collections) {
            this.parentCollectionList.add(new Collection(collection, servletContext, null, context, null, null));
        }
    } else {
        this.addExpand("parentCollectionList");
    }
    if (expandFields.contains("parentCommunityList") || expandFields.contains("all")) {
        this.parentCommunityList = new ArrayList<Community>();
        List<org.dspace.content.Community> communities = itemService.getCommunities(context, item);
        for (org.dspace.content.Community community : communities) {
            this.parentCommunityList.add(new Community(community, servletContext, null, context));
        }
    } else {
        this.addExpand("parentCommunityList");
    }
    // TODO: paging - offset, limit
    if (expandFields.contains("bitstreams") || expandFields.contains("all")) {
        bitstreams = new ArrayList<Bitstream>();
        List<Bundle> bundles = item.getBundles();
        for (Bundle bundle : bundles) {
            List<org.dspace.content.Bitstream> itemBitstreams = bundle.getBitstreams();
            for (org.dspace.content.Bitstream itemBitstream : itemBitstreams) {
                if (authorizeService.authorizeActionBoolean(context, itemBitstream, org.dspace.core.Constants.READ)) {
                    bitstreams.add(new Bitstream(itemBitstream, servletContext, null, context));
                }
            }
        }
    } else {
        this.addExpand("bitstreams");
    }
    if (!expandFields.contains("all")) {
        this.addExpand("all");
    }
}
Also used : ArrayList(java.util.ArrayList) MetadataField(org.dspace.content.MetadataField) MetadataValue(org.dspace.content.MetadataValue) Bundle(org.dspace.content.Bundle)

Example 37 with MetadataValue

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

the class ItemEntryGenerator method addSummary.

/**
 * Add the summary/abstract from the bibliographic metadata
 */
@Override
protected void addSummary() {
    List<MetadataValue> dcv = itemService.getMetadataByMetadataString(item, "dc.description.abstract");
    if (dcv != null) {
        for (MetadataValue aDcv : dcv) {
            Summary summary = new Summary();
            summary.setContent(aDcv.getValue());
            summary.setType(ContentType.TEXT);
            entry.setSummary(summary);
        }
    }
}
Also used : MetadataValue(org.dspace.content.MetadataValue) Summary(org.purl.sword.atom.Summary)

Example 38 with MetadataValue

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

the class ItemEntryGenerator method addTitle.

/**
 * Add the title from the bibliographic metadata
 */
@Override
protected void addTitle() {
    List<MetadataValue> dcv = itemService.getMetadataByMetadataString(item, "dc.title");
    if (dcv != null) {
        for (MetadataValue aDcv : dcv) {
            Title title = new Title();
            title.setContent(aDcv.getValue());
            title.setType(ContentType.TEXT);
            entry.setTitle(title);
        }
    }
}
Also used : MetadataValue(org.dspace.content.MetadataValue) Title(org.purl.sword.atom.Title)

Example 39 with MetadataValue

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

the class RequiredMetadata method perform.

/**
 * Perform the curation task upon passed DSO
 *
 * @param dso the DSpace object
 * @throws IOException if IO error
 */
@Override
public int perform(DSpaceObject dso) throws IOException {
    if (dso.getType() == Constants.ITEM) {
        Item item = (Item) dso;
        int count = 0;
        try {
            StringBuilder sb = new StringBuilder();
            String handle = item.getHandle();
            if (handle == null) {
                // we are still in workflow - no handle assigned
                handle = "in workflow";
            }
            sb.append("Item: ").append(handle);
            for (String req : getReqList(item.getOwningCollection().getHandle())) {
                List<MetadataValue> vals = itemService.getMetadataByMetadataString(item, req);
                if (vals.size() == 0) {
                    sb.append(" missing required field: ").append(req);
                    count++;
                }
            }
            if (count == 0) {
                sb.append(" has all required fields");
            }
            report(sb.toString());
            setResult(sb.toString());
        } catch (DCInputsReaderException dcrE) {
            throw new IOException(dcrE.getMessage(), dcrE);
        }
        return (count == 0) ? Curator.CURATE_SUCCESS : Curator.CURATE_FAIL;
    } else {
        setResult("Object skipped");
        return Curator.CURATE_SKIP;
    }
}
Also used : Item(org.dspace.content.Item) MetadataValue(org.dspace.content.MetadataValue) DCInputsReaderException(org.dspace.app.util.DCInputsReaderException) IOException(java.io.IOException)

Example 40 with MetadataValue

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

the class AbstractTranslator method perform.

@Override
public int perform(DSpaceObject dso) throws IOException {
    if (dso instanceof Item) {
        Item item = (Item) dso;
        /*
             * We lazily set success here because our success or failure
             * is per-field, not per-item
             */
        status = Curator.CURATE_SUCCESS;
        String handle = item.getHandle();
        log.debug("Translating metadata for " + handle);
        List<MetadataValue> authLangs = itemService.getMetadataByMetadataString(item, authLangField);
        if (authLangs.size() > 0) {
            /* Assume the first... multiple
                  "authoritative" languages won't work */
            authLang = authLangs.get(0).getValue();
            log.debug("Authoritative language for " + handle + " is " + authLang);
        }
        for (String lang : langs) {
            lang = lang.trim();
            for (String field : toTranslate) {
                boolean translated = false;
                field = field.trim();
                String[] fieldSegments = field.split("\\.");
                List<MetadataValue> fieldMetadata = null;
                if (fieldSegments.length > 2) {
                    // First, check to see if we've already got this in the target language
                    List<MetadataValue> checkMetadata = itemService.getMetadata(item, fieldSegments[0], fieldSegments[1], fieldSegments[2], lang);
                    if (checkMetadata.size() > 0) {
                        // We've already translated this, move along
                        log.debug(handle + "already has " + field + " in " + lang + ", skipping");
                        results.add(handle + ": Skipping " + lang + " translation " + "(" + field + ")");
                        translated = true;
                    }
                    // Let's carry on and get the authoritative version, then
                    fieldMetadata = itemService.getMetadata(item, fieldSegments[0], fieldSegments[1], fieldSegments[2], authLang);
                } else {
                    // First, check to see if we've already got this in the target language
                    List<MetadataValue> checkMetadata = itemService.getMetadata(item, fieldSegments[0], fieldSegments[1], null, lang);
                    if (checkMetadata.size() > 0) {
                        // We've already translated this, move along
                        log.debug(handle + "already has " + field + " in " + lang + ", skipping");
                        results.add(handle + ": Skipping " + lang + " translation " + "(" + field + ")");
                        translated = true;
                    }
                    // Let's carry on and get the authoritative version, then
                    fieldMetadata = itemService.getMetadata(item, fieldSegments[0], fieldSegments[1], null, authLang);
                }
                if (!translated && fieldMetadata.size() > 0) {
                    for (MetadataValue metadataValue : fieldMetadata) {
                        String value = metadataValue.getValue();
                        String translatedText = translateText(authLang, lang, value);
                        if (translatedText != null && !"".equals(translatedText)) {
                            try {
                                // Add the new metadata
                                if (fieldSegments.length > 2) {
                                    itemService.addMetadata(Curator.curationContext(), item, fieldSegments[0], fieldSegments[1], fieldSegments[2], lang, translatedText);
                                } else {
                                    itemService.addMetadata(Curator.curationContext(), item, fieldSegments[0], fieldSegments[1], null, lang, translatedText);
                                }
                                itemService.update(Curator.curationContext(), item);
                                results.add(handle + ": Translated " + authLang + " -> " + lang + " (" + field + ")");
                            } catch (Exception e) {
                                log.info(e.getLocalizedMessage());
                                status = Curator.CURATE_ERROR;
                            }
                        } else {
                            results.add(handle + ": Failed translation of " + authLang + " -> " + lang + "(" + field + ")");
                        }
                    }
                }
            }
        }
    }
    processResults();
    return status;
}
Also used : Item(org.dspace.content.Item) MetadataValue(org.dspace.content.MetadataValue) IOException(java.io.IOException)

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