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);
}
}
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);
}
}
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);
}
}
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();
}
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());
}
Aggregations