use of org.mycore.datamodel.metadata.MCRObjectID in project mycore by MyCoRe-Org.
the class MCRPICommands method removeControlFromObject.
@MCRCommand(syntax = "remove control {0} with service {1} with additional {2}", help = "This commands removes the " + "pi control from the object {0}(object id) with the serivce {1}(service id) and the additional {2}")
public static void removeControlFromObject(String objectIDString, String serviceID, String additional) throws MCRAccessException, MCRActiveLinkException, MCRPersistentIdentifierException {
MCRObjectID objectID = MCRObjectID.getInstance(objectIDString);
MCRPI mcrpi = MCRPersistentIdentifierManager.getInstance().get(serviceID, objectIDString, additional != null ? additional.trim() : null);
MCRPersistentIdentifierManager.getInstance().delete(mcrpi.getMycoreID(), mcrpi.getAdditional(), mcrpi.getType(), mcrpi.getService());
MCRBase base = MCRMetadataManager.retrieve(objectID);
if (MCRPIRegistrationService.removeFlagFromObject(base, mcrpi) == null) {
throw new MCRPersistentIdentifierException("Could not delete Flag of object (flag not found)!");
}
MCRMetadataManager.update(base);
}
use of org.mycore.datamodel.metadata.MCRObjectID in project mycore by MyCoRe-Org.
the class MCRPICommands method controlObjectWithServiceAndAdditional.
@MCRCommand(syntax = "try to control {0} with service {1} with additional {2}", help = "This command tries to" + " read a pi from the object {0} with the MetadataManager from the specified service {1}." + " If the service configuration is right then the pi is under control of MyCoRe.")
public static void controlObjectWithServiceAndAdditional(String objectIDString, String serviceID, final String additional) throws MCRAccessException, MCRActiveLinkException, IOException {
String trimAdditional = additional.trim();
MCRPIRegistrationService<MCRPersistentIdentifier> service = MCRPIRegistrationServiceManager.getInstance().getRegistrationService(serviceID);
MCRPersistentIdentifierMetadataManager<MCRPersistentIdentifier> metadataManager = service.getMetadataManager();
MCRObjectID objectID = MCRObjectID.getInstance(objectIDString);
MCRBase mcrBase = MCRMetadataManager.retrieve(objectID);
Optional<MCRPersistentIdentifier> identifier;
try {
identifier = metadataManager.getIdentifier(mcrBase, trimAdditional);
} catch (MCRPersistentIdentifierException e) {
LOGGER.info("Could not detect any identifier with service {}", serviceID, e);
return;
}
if (!identifier.isPresent()) {
LOGGER.info("Could not detect any identifier with service {}", serviceID);
return;
}
MCRPersistentIdentifier persistentIdentifier = identifier.get();
if (service.isRegistered(objectID, trimAdditional)) {
LOGGER.info("Already present in Database: {}", serviceID);
return;
}
MCRPI mcrpi = service.insertIdentifierToDatabase(mcrBase, trimAdditional, persistentIdentifier);
MCRPIRegistrationService.addFlagToObject(mcrBase, mcrpi);
MCRMetadataManager.update(mcrBase);
LOGGER.info("{}:{} is now under control of {}", objectID, trimAdditional, serviceID);
}
use of org.mycore.datamodel.metadata.MCRObjectID in project mycore by MyCoRe-Org.
the class MCRDOIRegistrationService method transformToDatacite.
protected Document transformToDatacite(MCRDigitalObjectIdentifier doi, MCRBase mcrBase) throws MCRPersistentIdentifierException {
MCRObjectID id = mcrBase.getId();
MCRBaseContent content = new MCRBaseContent(mcrBase);
try {
MCRContent transform = MCRContentTransformerFactory.getTransformer(this.transformer).transform(content);
Document dataciteDocument = transform.asXML();
insertDOI(dataciteDocument, doi);
Schema dataciteSchema = loadDataciteSchema();
try {
dataciteSchema.newValidator().validate(new JDOMSource(dataciteDocument));
} catch (SAXException e) {
String translatedInformation = MCRTranslation.translate(TRANSLATE_PREFIX + ERR_CODE_1_2);
throw new MCRPersistentIdentifierException("The document " + id + " does not generate well formed Datacite!", translatedInformation, ERR_CODE_1_2, e);
}
return dataciteDocument;
} catch (IOException | JDOMException | SAXException e) {
throw new MCRPersistentIdentifierException("Could not transform the content of " + id + " with the transformer " + transformer, e);
}
}
use of org.mycore.datamodel.metadata.MCRObjectID in project mycore by MyCoRe-Org.
the class MCRDOIRegistrationService method registerJob.
@Override
public void registerJob(Map<String, String> parameters) throws MCRPersistentIdentifierException {
MCRDigitalObjectIdentifier doi = getDOIFromJob(parameters);
String idString = parameters.get(CONTEXT_OBJ);
MCRObjectID objectID = MCRObjectID.getInstance(idString);
this.validateJobUserRights(objectID);
MCRObject object = MCRMetadataManager.retrieveMCRObject(objectID);
MCRObject mcrBase = MCRMetadataManager.retrieveMCRObject(objectID);
Document dataciteDocument = transformToDatacite(doi, mcrBase);
MCRDataciteClient dataciteClient = getDataciteClient();
dataciteClient.storeMetadata(dataciteDocument);
URI registeredURI;
try {
registeredURI = getRegisteredURI(object);
dataciteClient.mintDOI(doi, registeredURI);
} catch (URISyntaxException e) {
throw new MCRException("Base-URL seems to be invalid!", e);
}
List<Map.Entry<String, URI>> entryList = getMediaList((MCRObject) object);
dataciteClient.setMediaList(doi, entryList);
this.updateRegistrationDate(objectID, "", new Date());
}
use of org.mycore.datamodel.metadata.MCRObjectID in project mycore by MyCoRe-Org.
the class MCRDefaultDerivateTitleResolver method resolveTitle.
@Override
public String resolveTitle(String derivateIDString) {
MCRObjectID derivateID = MCRObjectID.getInstance(derivateIDString);
final MCRObjectID objectID = MCRMetadataManager.getObjectId(derivateID, EXPIRE_METADATA_CACHE_TIME, TimeUnit.SECONDS);
MCRObject object = MCRMetadataManager.retrieveMCRObject(objectID);
return object.getStructure().getDerivateLink(derivateID).getXLinkTitle();
}
Aggregations