Search in sources :

Example 1 with CamelException

use of org.apache.syncope.core.provisioning.camel.CamelException in project syncope by apache.

the class CamelRouteLogic method update.

@PreAuthorize("hasRole('" + CamelEntitlement.ROUTE_UPDATE + "')")
public void update(final AnyTypeKind anyTypeKind, final CamelRouteTO routeTO) {
    CamelRoute route = routeDAO.find(routeTO.getKey());
    if (route == null) {
        throw new NotFoundException("CamelRoute with key=" + routeTO.getKey());
    }
    if (route.getAnyTypeKind() != anyTypeKind) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidRequest);
        sce.getElements().add("Found " + anyTypeKind + ", expected " + route.getAnyTypeKind());
        throw sce;
    }
    String originalContent = route.getContent();
    LOG.debug("Updating route {} with content {}", routeTO.getKey(), routeTO.getContent());
    binder.update(route, routeTO);
    try {
        context.updateContext(routeTO.getKey());
    } catch (CamelException e) {
        // if an exception was thrown while updating the context, restore the former route definition
        LOG.debug("Update of route {} failed, reverting", routeTO.getKey());
        context.restoreRoute(routeTO.getKey(), originalContent);
        throw e;
    }
}
Also used : CamelException(org.apache.syncope.core.provisioning.camel.CamelException) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) CamelRoute(org.apache.syncope.core.persistence.api.entity.CamelRoute) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)1 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)1 CamelRoute (org.apache.syncope.core.persistence.api.entity.CamelRoute)1 CamelException (org.apache.syncope.core.provisioning.camel.CamelException)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1