Search in sources :

Example 36 with MCRException

use of org.mycore.common.MCRException in project mycore by MyCoRe-Org.

the class MCRPIRegistrationServiceManager method getRegistrationService.

public <T extends MCRPersistentIdentifier> MCRPIRegistrationService<T> getRegistrationService(String registrationServiceID) {
    String propertyName = REGISTRATION_SERVICE_CONFIG_PREFIX + registrationServiceID;
    Class<? extends MCRPIRegistrationService<T>> piClass = MCRConfiguration.instance().getClass(propertyName);
    try {
        Constructor<? extends MCRPIRegistrationService<T>> constructor = piClass.getConstructor(String.class);
        return constructor.newInstance(registrationServiceID);
    } catch (NoSuchMethodException e) {
        throw new MCRConfigurationException("The property : " + propertyName + " points to existing class, but without string constructor(serviceid)!", e);
    } catch (IllegalAccessException | InstantiationException | InvocationTargetException e) {
        throw new MCRException("Cant initialize class the class defined in: " + propertyName, e);
    }
}
Also used : MCRException(org.mycore.common.MCRException) MCRConfigurationException(org.mycore.common.config.MCRConfigurationException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 37 with MCRException

use of org.mycore.common.MCRException in project mycore by MyCoRe-Org.

the class MCROAISolrSearcher method query.

@Override
public MCROAIResult query(MCRSet set, Instant from, Instant until) {
    this.set = set;
    this.from = from;
    this.until = until;
    try {
        return handleResult(solrQuery(Optional.empty()));
    } catch (SolrServerException | IOException e) {
        throw new MCRException("Error while handling query.", e);
    }
}
Also used : MCRException(org.mycore.common.MCRException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IOException(java.io.IOException)

Example 38 with MCRException

use of org.mycore.common.MCRException in project mycore by MyCoRe-Org.

the class MCROAISolrSearcher method query.

@Override
public MCROAIResult query(String cursor) {
    this.updateRunningExpirationTimer();
    Optional<String> currentCursor = Optional.of(cursor);
    try {
        return handleResult(currentCursor.equals(this.lastCursor) ? this.nextResult : solrQuery(currentCursor));
    } catch (SolrServerException | IOException e) {
        throw new MCRException("Error while handling query.", e);
    }
}
Also used : MCRException(org.mycore.common.MCRException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IOException(java.io.IOException)

Example 39 with MCRException

use of org.mycore.common.MCRException in project mycore by MyCoRe-Org.

the class MCRPersistentIdentifierRegistrationResource method register.

@POST
@Path("service/{serviceName}/{mycoreId}")
@Produces(MediaType.APPLICATION_JSON)
public Response register(@PathParam("serviceName") String serviceName, @PathParam("mycoreId") String mycoreId, @DefaultValue("") @QueryParam("additional") String additional) {
    if (!MCRPIRegistrationServiceManager.getInstance().getServiceIDList().contains(serviceName)) {
        return Response.status(Response.Status.BAD_REQUEST).entity(buildErrorJSON("No Registration Service found for " + serviceName)).build();
    }
    MCRPIRegistrationService<MCRPersistentIdentifier> registrationService = MCRPIRegistrationServiceManager.getInstance().getRegistrationService(serviceName);
    MCRObjectID mycoreIDObject;
    try {
        mycoreIDObject = MCRObjectID.getInstance(mycoreId);
    } catch (MCRException e) {
        LOGGER.error(e);
        return Response.status(Response.Status.BAD_REQUEST).entity(buildErrorJSON("The provided id " + mycoreId + " seems to be invalid!", e)).build();
    }
    MCRPersistentIdentifier identifier;
    MCRBase object = MCRMetadataManager.retrieve(mycoreIDObject);
    try {
        identifier = registrationService.register(object, additional, true);
    } catch (MCRPersistentIdentifierException | MCRActiveLinkException e) {
        LOGGER.error(e);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(buildErrorJSON("Error while register new identifier!", e)).build();
    } catch (MCRAccessException e) {
        LOGGER.error(e);
        return Response.status(Response.Status.FORBIDDEN).entity(buildErrorJSON("Error while register new identifier!", e)).build();
    }
    return Response.status(Response.Status.CREATED).entity(buildIdentifierObject(identifier)).build();
}
Also used : MCRException(org.mycore.common.MCRException) MCRActiveLinkException(org.mycore.datamodel.common.MCRActiveLinkException) MCRAccessException(org.mycore.access.MCRAccessException) MCRBase(org.mycore.datamodel.metadata.MCRBase) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) MCRPersistentIdentifier(org.mycore.pi.MCRPersistentIdentifier) MCRPersistentIdentifierException(org.mycore.pi.exceptions.MCRPersistentIdentifierException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 40 with MCRException

use of org.mycore.common.MCRException 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());
}
Also used : MCRException(org.mycore.common.MCRException) MCRObject(org.mycore.datamodel.metadata.MCRObject) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) URISyntaxException(java.net.URISyntaxException) Document(org.jdom2.Document) URI(java.net.URI) Date(java.util.Date)

Aggregations

MCRException (org.mycore.common.MCRException)131 IOException (java.io.IOException)39 Element (org.jdom2.Element)26 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)19 Document (org.jdom2.Document)18 MCRCommand (org.mycore.frontend.cli.annotation.MCRCommand)18 File (java.io.File)15 MCRConfigurationException (org.mycore.common.config.MCRConfigurationException)12 MCRObject (org.mycore.datamodel.metadata.MCRObject)12 ArrayList (java.util.ArrayList)11 JDOMException (org.jdom2.JDOMException)11 MCRAccessException (org.mycore.access.MCRAccessException)11 MCRPath (org.mycore.datamodel.niofs.MCRPath)10 SAXException (org.xml.sax.SAXException)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)7 List (java.util.List)7 MCRActiveLinkException (org.mycore.datamodel.common.MCRActiveLinkException)7 SAXParseException (org.xml.sax.SAXParseException)7 URI (java.net.URI)6 Path (java.nio.file.Path)6