use of org.mycore.datamodel.metadata.MCRObjectID in project mycore by MyCoRe-Org.
the class MCRExtractRelatedItemsEventHandler method extractRelatedItems.
private void extractRelatedItems(final MCREvent evt, final MCRObject object) {
if (!MCRMODSWrapper.isSupported(object)) {
return;
}
Element mods = new MCRMODSWrapper(object).getMODS();
MCRObjectID oid = object.getId();
for (Element relatedItem : mods.getChildren("relatedItem", MCRConstants.MODS_NAMESPACE)) {
String href = relatedItem.getAttributeValue("href", MCRConstants.XLINK_NAMESPACE);
LOGGER.info("Found related item in {}, href={}", object.getId(), href);
// MCR-957: only create releated object if mycoreId
MCRObjectID mcrIdCheck;
try {
mcrIdCheck = MCRObjectID.getInstance(href);
} catch (Exception e) {
// not a valid MCRObjectID -> don't create anyway
continue;
}
// create if integer value == 0
if (mcrIdCheck.getNumberAsInteger() == 0) {
// MCR-931: check for type='host' and present parent document
if (!isHost(relatedItem) || object.getStructure().getParentID() == null) {
MCRObjectID relatedID;
try {
relatedID = createRelatedObject(relatedItem, oid);
} catch (MCRAccessException e) {
throw new MCRException(e);
}
href = relatedID.toString();
LOGGER.info("Setting href of related item to {}", href);
relatedItem.setAttribute("href", href, MCRConstants.XLINK_NAMESPACE);
if (isHost(relatedItem)) {
LOGGER.info("Setting {} as parent of {}", href, oid);
object.getStructure().setParent(relatedID);
}
}
} else if (isParentExists(relatedItem)) {
MCRObjectID relatedID = MCRObjectID.getInstance(href);
if (object.getStructure().getParentID() == null) {
LOGGER.info("Setting {} as parent of {}", href, oid);
object.getStructure().setParent(relatedID);
} else if (!object.getStructure().getParentID().equals(relatedID)) {
LOGGER.info("Setting {} as parent of {}", href, oid);
object.getStructure().setParent(relatedID);
}
}
}
}
use of org.mycore.datamodel.metadata.MCRObjectID in project mycore by MyCoRe-Org.
the class MCRRSSFeedImporter method buildMCRObject.
private MCRObject buildMCRObject(Element publicationXML, String projectID) {
MCRObject obj = new MCRObject(new Document(publicationXML));
MCRMODSWrapper wrapper = new MCRMODSWrapper(obj);
wrapper.setServiceFlag("status", STATUS_FLAG);
MCRObjectID oid = MCRObjectID.getNextFreeId(projectID, "mods");
obj.setId(oid);
return obj;
}
use of org.mycore.datamodel.metadata.MCRObjectID in project mycore by MyCoRe-Org.
the class MCROAIDeletedSearcher method searchDeleted.
/**
* Returns a list with identifiers of the deleted objects within the given date boundary.
* If the record policy indicates that there is no support for tracking deleted an empty
* list is returned.
*
* @param from from date
* @param until to date
*
* @return a list with identifiers of the deleted objects
*/
protected List<Header> searchDeleted(Instant from, Instant until) {
DeletedRecordPolicy deletedRecordPolicy = this.identify.getDeletedRecordPolicy();
if (from == null || DeletedRecordPolicy.No.equals(deletedRecordPolicy) || DeletedRecordPolicy.Transient.equals(deletedRecordPolicy)) {
return new ArrayList<>();
}
LOGGER.info("Getting identifiers of deleted items");
Map<MCRObjectID, Instant> deletedItems = MCRMetadataHistoryManager.getDeletedItems(from, Optional.ofNullable(until));
List<String> types = getConfig().getStrings(getConfigPrefix() + "DeletedRecordTypes", null);
if (types == null || types.isEmpty()) {
return deletedItems.entrySet().stream().map(this::toHeader).collect(Collectors.toList());
}
return deletedItems.entrySet().stream().filter(e -> types.contains(e.getKey().getTypeId())).map(this::toHeader).collect(Collectors.toList());
}
use of org.mycore.datamodel.metadata.MCRObjectID in project mycore by MyCoRe-Org.
the class MCRMODSMetadataShareAgent method receiveMetadata.
/* (non-Javadoc)
* @see org.mycore.datamodel.metadata.share.MCRMetadataShareAgent#inheritMetadata(org.mycore.datamodel.metadata.MCRObject, org.mycore.datamodel.metadata.MCRObject)
*/
@Override
public void receiveMetadata(MCRObject child) {
MCRMODSWrapper childWrapper = new MCRMODSWrapper(child);
MCRObjectID parentID = child.getStructure().getParentID();
LOGGER.debug("Removing old inherited Metadata.");
childWrapper.removeInheritedMetadata();
if (parentID != null && MCRMODSWrapper.isSupported(parentID)) {
MCRObject parent = MCRMetadataManager.retrieveMCRObject(parentID);
MCRMODSWrapper parentWrapper = new MCRMODSWrapper(parent);
inheritToChild(parentWrapper, childWrapper);
}
for (Element relatedItem : childWrapper.getLinkedRelatedItems()) {
String type = relatedItem.getAttributeValue("type");
String holderId = relatedItem.getAttributeValue("href", MCRConstants.XLINK_NAMESPACE);
LOGGER.info("receive metadata from {} document {}", type, holderId);
if ((holderId == null || parentID != null && parentID.toString().equals(holderId)) && MCRMODSRelationshipType.host.name().equals(type)) {
// already received metadata from parent;
continue;
}
MCRObjectID holderObjectID = MCRObjectID.getInstance(holderId);
if (MCRMODSWrapper.isSupported(holderObjectID)) {
MCRObject targetObject = MCRMetadataManager.retrieveMCRObject(holderObjectID);
MCRMODSWrapper targetWrapper = new MCRMODSWrapper(targetObject);
relatedItem.addContent(targetWrapper.getMODS().cloneContent());
}
}
}
use of org.mycore.datamodel.metadata.MCRObjectID in project mycore by MyCoRe-Org.
the class MCRMODSWrapper method setID.
public MCRObjectID setID(String projectID, int ID) {
MCRObjectID objID = MCRObjectID.getInstance(MCRObjectID.formatID(projectID, MODS_OBJECT_TYPE, ID));
object.setId(objID);
return objID;
}
Aggregations