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