Search in sources :

Example 1 with PersistenceException

use of nl.knaw.huygens.persistence.PersistenceException in project timbuctoo by HuygensING.

the class HandleAdder method actualExecution.

private void actualExecution(HandleAdderParameters params) {
    try {
        URI uri = params.getUrlToRedirectTo();
        LOG.info(String.format("Retrieving persistent url for '%s'", uri));
        String persistentId = (manager.persistURL(uri.toString()));
        URI persistentUrl = new URI(manager.getPersistentURL(persistentId));
        transactionEnforcer.execute(timbuctooActions -> {
            try {
                timbuctooActions.addPid(persistentUrl, params.getEntityLookup());
                LOG.info("committed pid");
                return TransactionState.commit();
            } catch (NotFoundException e) {
                LOG.warn("Entity for entityLookup '{}' cannot be found", params.getEntityLookup());
                try {
                    manager.deletePersistentId(persistentId);
                } catch (PersistenceException e1) {
                    LOG.error("Cannot remove handle with id '{}'", persistentId);
                }
                return TransactionState.rollback();
            }
        });
    } catch (PersistenceException | URISyntaxException e) {
        LOG.error(Logmarkers.serviceUnavailable, "Could not create handle", e);
        if (params.getRetries() < 5) {
            LOG.warn(String.format("Re-adding %s%s job to the queue for '%s' '%s'", params.getRetries() + 1, getOrdinalSuffix(params.getRetries() + 1), params.getEntityLookup(), params.getUrlToRedirectTo()));
            this.sender.send(params.nextTry());
        }
    }
}
Also used : PersistenceException(nl.knaw.huygens.persistence.PersistenceException) NotFoundException(nl.knaw.huygens.timbuctoo.core.NotFoundException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Aggregations

URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 PersistenceException (nl.knaw.huygens.persistence.PersistenceException)1 NotFoundException (nl.knaw.huygens.timbuctoo.core.NotFoundException)1