use of org.mycore.datamodel.metadata.MCRObject in project mycore by MyCoRe-Org.
the class MCRDOICommands method repairIncompleteRegisteredDOI.
@MCRCommand(syntax = "repair incomplete registered doi {0} with registration service {1}", help = "Use this method if a DOI is registered, but not inserted in the Database. {0} is the DOI and " + "{1} the registration service from configuration.")
public static void repairIncompleteRegisteredDOI(String doiString, String serviceID) throws MCRPersistentIdentifierException, MCRAccessException, MCRActiveLinkException {
MCRDOIRegistrationService registrationService = new MCRDOIRegistrationService(serviceID);
MCRDataciteClient dataciteClient = registrationService.getDataciteClient();
MCRDigitalObjectIdentifier doi = new MCRDOIParser().parse(doiString).orElseThrow(() -> new MCRException("Invalid DOI: " + doiString));
URI uri = dataciteClient.resolveDOI(doi);
if (!uri.toString().startsWith(registrationService.getRegisterURL())) {
LOGGER.info("DOI/URL is not from this application: {}/{}", doi.asString(), uri);
return;
}
MCRObjectID objectID = getObjectID(uri);
if (!MCRMetadataManager.exists(objectID)) {
LOGGER.info("Could not find Object : {}", objectID);
return;
}
MCRObject mcrObject = MCRMetadataManager.retrieveMCRObject(objectID);
MCRPersistentIdentifierMetadataManager<MCRDigitalObjectIdentifier> synchronizer = registrationService.getMetadataManager();
if (!registrationService.isRegistered(objectID, doiString)) {
LOGGER.info("{} is not found in PI-Database. Insert it..", objectID);
registrationService.insertIdentifierToDatabase(mcrObject, "", doi);
}
if (!synchronizer.getIdentifier(mcrObject, "").isPresent()) {
LOGGER.info("Object doesn't have Identifier inscribed! Insert it..");
synchronizer.insertIdentifier(doi, mcrObject, "");
MCRMetadataManager.update(mcrObject);
}
}
use of org.mycore.datamodel.metadata.MCRObject in project mycore by MyCoRe-Org.
the class MCRPIRegistrationService method register.
/**
* Validates everything, registers a new Identifier, inserts the identifier to object metadata and writes a
* information to the Database.
*
* @param obj the object which has to be identified
* @param additional additional information for the persistent identifier
* @param updateObject if true this method calls {@link MCRMetadataManager#update(MCRBase)}
* @return the assigned Identifier
* @throws MCRAccessException the current User doesn't have the rights to insert the Identifier to Metadata
* @throws MCRActiveLinkException the {@link MCRPersistentIdentifierMetadataManager} lets
* {@link org.mycore.datamodel.metadata.MCRMetadataManager#update(MCRObject)} throw this
* @throws MCRPersistentIdentifierException see {@link org.mycore.pi.exceptions}
*/
public T register(MCRBase obj, String additional, boolean updateObject) throws MCRAccessException, MCRActiveLinkException, MCRPersistentIdentifierException {
this.validateRegistration(obj, additional);
T identifier = this.registerIdentifier(obj, additional);
this.getMetadataManager().insertIdentifier(identifier, obj, additional);
MCRPI databaseEntry = insertIdentifierToDatabase(obj, additional, identifier);
addFlagToObject(obj, databaseEntry);
if (updateObject) {
if (obj instanceof MCRObject) {
MCRMetadataManager.update((MCRObject) obj);
} else if (obj instanceof MCRDerivate) {
MCRMetadataManager.update((MCRDerivate) obj);
}
}
return identifier;
}
use of org.mycore.datamodel.metadata.MCRObject in project mycore by MyCoRe-Org.
the class MCRPICommands method updateObject.
@MCRCommand(syntax = "update all PI of object {0}", help = "Triggers the update method of every Object!")
public static void updateObject(String objectIDString) {
MCRObjectID objectID = MCRObjectID.getInstance(objectIDString);
MCRObject object = MCRMetadataManager.retrieveMCRObject(objectID);
MCRPersistentIdentifierEventHandler.updateObject(object);
}
use of org.mycore.datamodel.metadata.MCRObject in project mycore by MyCoRe-Org.
the class MCRDOIRegistrationService method updateJob.
@Override
public void updateJob(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);
Document newDataciteMetadata = transformToDatacite(doi, object);
MCRDataciteClient dataciteClient = getDataciteClient();
try {
URI uri = dataciteClient.resolveDOI(doi);
URI registeredURI = getRegisteredURI(object);
if (!uri.equals(registeredURI)) {
LOGGER.info("Sending new URL({}) to Datacite!", registeredURI);
dataciteClient.mintDOI(doi, registeredURI);
}
} catch (URISyntaxException e) {
throw new MCRPersistentIdentifierException("Error while updating URL!", e);
}
Document oldDataciteMetadata = dataciteClient.resolveMetadata(doi);
if (!MCRXMLHelper.deepEqual(newDataciteMetadata, oldDataciteMetadata)) {
LOGGER.info("Sending new Metadata of {} to Datacite!", idString);
dataciteClient.deleteMetadata(doi);
dataciteClient.storeMetadata(newDataciteMetadata);
}
}
use of org.mycore.datamodel.metadata.MCRObject in project mycore by MyCoRe-Org.
the class MCRRSSFeedImporter method importPublications.
public void importPublications(String projectID) throws Exception {
LOGGER.info("Getting new publications from {} RSS feed...", sourceSystemID);
SyndFeed feed = retrieveFeed();
List<MCRObject> importedObjects = new ArrayList<>();
for (SyndEntry entry : feed.getEntries()) {
MCRObject importedObject = handleFeedEntry(entry, projectID);
if (importedObject != null) {
importedObjects.add(importedObject);
}
}
int numPublicationsImported = importedObjects.size();
LOGGER.info("imported {} publications.", numPublicationsImported);
if ((numPublicationsImported > 0) && (xsl2BuildNotificationMail != null)) {
sendNotificationMail(importedObjects);
}
}
Aggregations