Search in sources :

Example 1 with EvaluationContextEntity

use of org.apache.nifi.update.attributes.entity.EvaluationContextEntity in project nifi by apache.

the class RuleResource method getEvaluationContext.

@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Path("/evaluation-context")
public Response getEvaluationContext(@QueryParam("processorId") final String processorId) {
    // get the web context
    final NiFiWebConfigurationContext nifiWebContext = (NiFiWebConfigurationContext) servletContext.getAttribute("nifi-web-configuration-context");
    // build the web context config
    final NiFiWebRequestContext contextConfig = getRequestContext(processorId);
    // load the criteria
    final Criteria criteria = getCriteria(nifiWebContext, contextConfig);
    // create the response entity
    final EvaluationContextEntity responseEntity = new EvaluationContextEntity();
    responseEntity.setProcessorId(processorId);
    responseEntity.setFlowFilePolicy(criteria.getFlowFilePolicy().name());
    responseEntity.setRuleOrder(criteria.getRuleOrder());
    // generate the response
    final ResponseBuilder response = Response.ok(responseEntity);
    return noCache(response).build();
}
Also used : EvaluationContextEntity(org.apache.nifi.update.attributes.entity.EvaluationContextEntity) Criteria(org.apache.nifi.update.attributes.Criteria) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) NiFiWebConfigurationContext(org.apache.nifi.web.NiFiWebConfigurationContext) NiFiWebRequestContext(org.apache.nifi.web.NiFiWebRequestContext) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with EvaluationContextEntity

use of org.apache.nifi.update.attributes.entity.EvaluationContextEntity in project nifi by apache.

the class RuleResource method updateEvaluationContext.

@PUT
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Path("/evaluation-context")
public Response updateEvaluationContext(@Context final UriInfo uriInfo, final EvaluationContextEntity requestEntity) {
    // get the web context
    final NiFiWebConfigurationContext configurationContext = (NiFiWebConfigurationContext) servletContext.getAttribute("nifi-web-configuration-context");
    // ensure the evaluation context has been specified
    if (requestEntity == null) {
        throw new WebApplicationException(badRequest("The evaluation context must be specified."));
    }
    // ensure the id has been specified
    if (requestEntity.getRuleOrder() == null && requestEntity.getFlowFilePolicy() == null) {
        throw new WebApplicationException(badRequest("Either the rule order or the matching strategy must be specified."));
    }
    // build the web context config
    final NiFiWebConfigurationRequestContext requestContext = getConfigurationRequestContext(requestEntity.getProcessorId(), requestEntity.getRevision(), requestEntity.getClientId());
    // load the criteria
    final Criteria criteria = getCriteria(configurationContext, requestContext);
    // if a new rule order is specified, attempt to set it
    if (requestEntity.getRuleOrder() != null) {
        try {
            criteria.reorder(requestEntity.getRuleOrder());
        } catch (final IllegalArgumentException iae) {
            throw new WebApplicationException(iae, badRequest(iae.getMessage()));
        }
    }
    // if a new matching strategy is specified, attempt to set it
    if (requestEntity.getFlowFilePolicy() != null) {
        try {
            criteria.setFlowFilePolicy(FlowFilePolicy.valueOf(requestEntity.getFlowFilePolicy()));
        } catch (final IllegalArgumentException iae) {
            throw new WebApplicationException(iae, badRequest("The specified matching strategy is unknown: " + requestEntity.getFlowFilePolicy()));
        }
    }
    // save the criteria
    saveCriteria(requestContext, criteria);
    // create the response entity
    final EvaluationContextEntity responseEntity = new EvaluationContextEntity();
    responseEntity.setClientId(requestEntity.getClientId());
    responseEntity.setRevision(requestEntity.getRevision());
    responseEntity.setProcessorId(requestEntity.getProcessorId());
    responseEntity.setFlowFilePolicy(criteria.getFlowFilePolicy().name());
    responseEntity.setRuleOrder(criteria.getRuleOrder());
    // generate the response
    final ResponseBuilder response = Response.ok(responseEntity);
    return noCache(response).build();
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) NiFiWebConfigurationRequestContext(org.apache.nifi.web.NiFiWebConfigurationRequestContext) EvaluationContextEntity(org.apache.nifi.update.attributes.entity.EvaluationContextEntity) Criteria(org.apache.nifi.update.attributes.Criteria) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) NiFiWebConfigurationContext(org.apache.nifi.web.NiFiWebConfigurationContext) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Aggregations

Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)2 Criteria (org.apache.nifi.update.attributes.Criteria)2 EvaluationContextEntity (org.apache.nifi.update.attributes.entity.EvaluationContextEntity)2 NiFiWebConfigurationContext (org.apache.nifi.web.NiFiWebConfigurationContext)2 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 PUT (javax.ws.rs.PUT)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 NiFiWebConfigurationRequestContext (org.apache.nifi.web.NiFiWebConfigurationRequestContext)1 NiFiWebRequestContext (org.apache.nifi.web.NiFiWebRequestContext)1