Search in sources :

Example 86 with MCRCommand

use of org.mycore.frontend.cli.annotation.MCRCommand in project mycore by MyCoRe-Org.

the class MCRSolrCommands method createIndex.

@MCRCommand(syntax = "create solr metadata and content index at {0}", help = "create solr's metadata and content index on specific solr server core", order = 120)
public static void createIndex(String url) throws Exception {
    MCRSolrCore core = new MCRSolrCore(url);
    SolrClient concurrentSolrClient = core.getConcurrentClient();
    SolrClient solrClient = core.getClient();
    MCRSolrIndexer.rebuildMetadataIndex(concurrentSolrClient);
    MCRSolrIndexer.rebuildContentIndex(solrClient);
    if (concurrentSolrClient instanceof ConcurrentUpdateSolrClient) {
        ((ConcurrentUpdateSolrClient) concurrentSolrClient).blockUntilFinished();
    }
    solrClient.optimize();
}
Also used : SolrClient(org.apache.solr.client.solrj.SolrClient) ConcurrentUpdateSolrClient(org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrClient) MCRSolrCore(org.mycore.solr.MCRSolrCore) ConcurrentUpdateSolrClient(org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrClient) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand)

Example 87 with MCRCommand

use of org.mycore.frontend.cli.annotation.MCRCommand in project mycore by MyCoRe-Org.

the class MCRDOICommands method updateMediaListForDOI.

@MCRCommand(syntax = REPAIR_MEDIALIST_OF_0_AND_SERVICE_1, help = "Sends new media list to Datacite. {0} is the DOI. The Service ID{1} is the id from the configuration.")
public static void updateMediaListForDOI(String doiString, String serviceID) {
    MCRDOIRegistrationService registrationService = new MCRDOIRegistrationService(serviceID);
    MCRDataciteClient dataciteClient = registrationService.getDataciteClient();
    MCRDigitalObjectIdentifier doi = new MCRDOIParser().parse(doiString).orElseThrow(() -> new IllegalArgumentException("The String " + doiString + " is no valid DOI!"));
    try {
        URI uri = dataciteClient.resolveDOI(doi);
        if (uri.toString().startsWith(registrationService.getRegisterURL())) {
            String s = uri.toString();
            LOGGER.info("Checking DOI: {} / {}", doi.asString(), s);
            String idString = s.substring(s.lastIndexOf("/") + 1);
            MCRObjectID objectID = MCRObjectID.getInstance(idString);
            if (MCRMetadataManager.exists(objectID)) {
                MCRObject obj = MCRMetadataManager.retrieveMCRObject(objectID);
                List<Map.Entry<String, URI>> newMediaList = registrationService.getMediaList(obj);
                List<Map.Entry<String, URI>> oldMediaList;
                try {
                    oldMediaList = dataciteClient.getMediaList(doi);
                } catch (MCRIdentifierUnresolvableException e) {
                    LOGGER.warn("{} had no media list!", doi);
                    oldMediaList = new ArrayList<>();
                }
                HashMap<String, URI> newHashMap = new HashMap<>();
                newMediaList.forEach(e -> newHashMap.put(e.getKey(), e.getValue()));
                oldMediaList.forEach(e -> {
                    /*
                        Currently it is not possible to delete inserted values key values (mime types).
                        So we update old media mimetypes which are not present in new list to the same URL of the first
                        mimetype entry.
                        */
                    if (!newHashMap.containsKey(e.getKey())) {
                        newHashMap.put(e.getKey(), newMediaList.stream().findFirst().orElseThrow(() -> new MCRException("new media list is empty (this should not happen)")).getValue());
                    }
                });
                dataciteClient.setMediaList(doi, newHashMap.entrySet().stream().collect(Collectors.toList()));
                LOGGER.info("Updated media-list of {}", doiString);
            } else {
                LOGGER.info("Object {} does not exist in this application!", objectID);
            }
        } else {
            LOGGER.info("DOI is not from this application: ({}) {}", uri, registrationService.getRegisterURL());
        }
    } catch (MCRPersistentIdentifierException e) {
        LOGGER.error("Error occurred for DOI: {}", doi, e);
    }
}
Also used : MCRException(org.mycore.common.MCRException) MCRIdentifierUnresolvableException(org.mycore.pi.exceptions.MCRIdentifierUnresolvableException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MCRPersistentIdentifierException(org.mycore.pi.exceptions.MCRPersistentIdentifierException) URI(java.net.URI) MCRDOIParser(org.mycore.pi.doi.MCRDOIParser) 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) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand)

Example 88 with MCRCommand

use of org.mycore.frontend.cli.annotation.MCRCommand 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 89 with MCRCommand

use of org.mycore.frontend.cli.annotation.MCRCommand in project mycore by MyCoRe-Org.

the class MCRPICommands method migrateURNGranularToServiceID.

@MCRCommand(syntax = "migrate urn granular to service id {0}", help = "Used to migrate urn granular to MyCoRe-PI. " + "{0} should be your granular service id.")
public static void migrateURNGranularToServiceID(String serviceID) {
    Session session = MCRHIBConnection.instance().getSession();
    MCRXMLMetadataManager.instance().listIDsOfType("derivate").forEach(derivateID -> {
        MCRDerivate derivate = MCRMetadataManager.retrieveMCRDerivate(MCRObjectID.getInstance(derivateID));
        String urn = derivate.getDerivate().getURN();
        if (urn != null) {
            LOGGER.info("Found URN in :{}", derivateID);
            MCRPI derivatePI = new MCRPI(urn, MCRDNBURN.TYPE, derivateID, "", serviceID, new Date());
            if (MCRPersistentIdentifierManager.getInstance().exist(derivatePI)) {
                LOGGER.warn("PI-Entry for {} already exist!", urn);
            } else {
                session.save(derivatePI);
                derivate.getUrnMap().forEach((file, fileURN) -> {
                    MCRPI filePI = new MCRPI(fileURN, MCRDNBURN.TYPE, derivateID, file, serviceID, new Date());
                    if (MCRPersistentIdentifierManager.getInstance().exist(filePI)) {
                        LOGGER.warn("PI-Entry for {} already exist!", fileURN);
                    } else {
                        session.save(fileURN);
                    }
                });
            }
        }
    });
}
Also used : MCRPI(org.mycore.pi.backend.MCRPI) MCRDerivate(org.mycore.datamodel.metadata.MCRDerivate) Date(java.util.Date) Session(org.hibernate.Session) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand)

Example 90 with MCRCommand

use of org.mycore.frontend.cli.annotation.MCRCommand 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)

Aggregations

MCRCommand (org.mycore.frontend.cli.annotation.MCRCommand)106 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)37 MCRException (org.mycore.common.MCRException)34 IOException (java.io.IOException)30 File (java.io.File)22 ArrayList (java.util.ArrayList)18 Document (org.jdom2.Document)17 JDOMException (org.jdom2.JDOMException)17 MCRObject (org.mycore.datamodel.metadata.MCRObject)17 Path (java.nio.file.Path)16 SAXException (org.xml.sax.SAXException)16 EntityManager (javax.persistence.EntityManager)15 MCRAccessException (org.mycore.access.MCRAccessException)15 MCRActiveLinkException (org.mycore.datamodel.common.MCRActiveLinkException)15 MCRPath (org.mycore.datamodel.niofs.MCRPath)15 FileNotFoundException (java.io.FileNotFoundException)13 SAXParseException (org.xml.sax.SAXParseException)12 List (java.util.List)11 Element (org.jdom2.Element)11 MCRPersistenceException (org.mycore.common.MCRPersistenceException)11