Search in sources :

Example 51 with MCRObject

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);
    }
}
Also used : MCRDOIParser(org.mycore.pi.doi.MCRDOIParser) MCRException(org.mycore.common.MCRException) MCRObject(org.mycore.datamodel.metadata.MCRObject) MCRDigitalObjectIdentifier(org.mycore.pi.doi.MCRDigitalObjectIdentifier) MCRDOIRegistrationService(org.mycore.pi.doi.MCRDOIRegistrationService) MCRDataciteClient(org.mycore.pi.doi.MCRDataciteClient) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) URI(java.net.URI) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand)

Example 52 with 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;
}
Also used : MCRObject(org.mycore.datamodel.metadata.MCRObject) MCRPI(org.mycore.pi.backend.MCRPI) MCRDerivate(org.mycore.datamodel.metadata.MCRDerivate)

Example 53 with MCRObject

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);
}
Also used : MCRObject(org.mycore.datamodel.metadata.MCRObject) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand)

Example 54 with MCRObject

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);
    }
}
Also used : MCRObject(org.mycore.datamodel.metadata.MCRObject) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) URISyntaxException(java.net.URISyntaxException) Document(org.jdom2.Document) MCRPersistentIdentifierException(org.mycore.pi.exceptions.MCRPersistentIdentifierException) URI(java.net.URI)

Example 55 with MCRObject

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);
    }
}
Also used : SyndFeed(com.rometools.rome.feed.synd.SyndFeed) MCRObject(org.mycore.datamodel.metadata.MCRObject) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) ArrayList(java.util.ArrayList)

Aggregations

MCRObject (org.mycore.datamodel.metadata.MCRObject)71 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)33 Document (org.jdom2.Document)18 Element (org.jdom2.Element)17 MCRException (org.mycore.common.MCRException)16 MCRDerivate (org.mycore.datamodel.metadata.MCRDerivate)14 MCRMetaLinkID (org.mycore.datamodel.metadata.MCRMetaLinkID)14 MCRCommand (org.mycore.frontend.cli.annotation.MCRCommand)12 IOException (java.io.IOException)11 MCRAccessException (org.mycore.access.MCRAccessException)11 MCRMODSWrapper (org.mycore.mods.MCRMODSWrapper)9 MCRPersistenceException (org.mycore.common.MCRPersistenceException)7 Date (java.util.Date)6 JDOMException (org.jdom2.JDOMException)6 MCRActiveLinkException (org.mycore.datamodel.common.MCRActiveLinkException)6 MCRPersistentIdentifierException (org.mycore.pi.exceptions.MCRPersistentIdentifierException)6 SAXException (org.xml.sax.SAXException)6 URI (java.net.URI)5 URISyntaxException (java.net.URISyntaxException)5 ArrayList (java.util.ArrayList)5