Search in sources :

Example 1 with CamelRoute

use of org.apache.syncope.core.persistence.api.entity.CamelRoute in project syncope by apache.

the class SyncopeCamelContext method getCamelContext.

public CamelContext getCamelContext() {
    synchronized (this) {
        if (camelContext == null) {
            camelContext = ApplicationContextProvider.getBeanFactory().getBean(SpringCamelContext.class);
            camelContext.addRoutePolicyFactory(new MetricsRoutePolicyFactory());
        }
        if (camelContext.getRoutes().isEmpty()) {
            List<CamelRoute> routes = routeDAO.findAll();
            LOG.debug("{} route(s) are going to be loaded ", routes.size());
            loadRouteDefinitions(routes.stream().map(input -> input.getContent()).collect(Collectors.toList()));
        }
    }
    return camelContext;
}
Also used : SpringCamelContext(org.apache.camel.spring.SpringCamelContext) CamelRoute(org.apache.syncope.core.persistence.api.entity.CamelRoute) MetricsRoutePolicyFactory(org.apache.camel.component.metrics.routepolicy.MetricsRoutePolicyFactory)

Example 2 with CamelRoute

use of org.apache.syncope.core.persistence.api.entity.CamelRoute 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)

Example 3 with CamelRoute

use of org.apache.syncope.core.persistence.api.entity.CamelRoute in project syncope by apache.

the class CamelRouteLogic method read.

@PreAuthorize("hasRole('" + CamelEntitlement.ROUTE_READ + "')")
@Transactional(readOnly = true)
public CamelRouteTO read(final AnyTypeKind anyTypeKind, final String key) {
    CamelRoute route = routeDAO.find(key);
    if (route == null) {
        throw new NotFoundException("CamelRoute with key=" + key);
    }
    if (route.getAnyTypeKind() != anyTypeKind) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidRequest);
        sce.getElements().add("Found " + anyTypeKind + ", expected " + route.getAnyTypeKind());
        throw sce;
    }
    return binder.getRouteTO(route);
}
Also used : 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) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

CamelRoute (org.apache.syncope.core.persistence.api.entity.CamelRoute)3 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)2 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 MetricsRoutePolicyFactory (org.apache.camel.component.metrics.routepolicy.MetricsRoutePolicyFactory)1 SpringCamelContext (org.apache.camel.spring.SpringCamelContext)1 CamelException (org.apache.syncope.core.provisioning.camel.CamelException)1 Transactional (org.springframework.transaction.annotation.Transactional)1