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");
}
}
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);
}
}
}
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);
}
}
}
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;
}
}
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;
}
Aggregations