Search in sources :

Example 1 with Criteria

use of org.apache.nifi.update.attributes.Criteria in project nifi by apache.

the class RuleResource method searchRules.

@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Path("/rules/search-results")
public Response searchRules(@QueryParam("processorId") final String processorId, @QueryParam("q") final String term) {
    // get the web context
    final NiFiWebConfigurationContext configurationContext = (NiFiWebConfigurationContext) servletContext.getAttribute("nifi-web-configuration-context");
    // build the web context config
    final NiFiWebRequestContext requestContext = getRequestContext(processorId);
    // load the criteria
    final Criteria criteria = getCriteria(configurationContext, requestContext);
    final List<Rule> rules = criteria.getRules();
    // generate the rules
    List<RuleDTO> ruleDtos = null;
    if (rules != null) {
        ruleDtos = new ArrayList<>(rules.size());
        for (final Rule rule : rules) {
            if (StringUtils.containsIgnoreCase(rule.getName(), term)) {
                final RuleDTO ruleDto = DtoFactory.createRuleDTO(rule);
                ruleDtos.add(ruleDto);
            }
        }
    }
    // sort the rules
    Collections.sort(ruleDtos, new Comparator<RuleDTO>() {

        @Override
        public int compare(RuleDTO r1, RuleDTO r2) {
            final Collator collator = Collator.getInstance(Locale.US);
            return collator.compare(r1.getName(), r2.getName());
        }
    });
    // create the response entity
    final RulesEntity responseEntity = new RulesEntity();
    responseEntity.setProcessorId(processorId);
    responseEntity.setRules(ruleDtos);
    // generate the response
    final ResponseBuilder response = Response.ok(responseEntity);
    return noCache(response).build();
}
Also used : RuleDTO(org.apache.nifi.update.attributes.dto.RuleDTO) Criteria(org.apache.nifi.update.attributes.Criteria) RulesEntity(org.apache.nifi.update.attributes.entity.RulesEntity) Collator(java.text.Collator) Rule(org.apache.nifi.update.attributes.Rule) 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 Criteria

use of org.apache.nifi.update.attributes.Criteria in project nifi by apache.

the class RuleResource method getRules.

@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Path("/rules")
public Response getRules(@QueryParam("processorId") final String processorId, @DefaultValue("false") @QueryParam("verbose") final Boolean verbose) {
    // get the web context
    final NiFiWebConfigurationContext configurationContext = (NiFiWebConfigurationContext) servletContext.getAttribute("nifi-web-configuration-context");
    // build the web context config
    final NiFiWebRequestContext requestContext = getRequestContext(processorId);
    // load the criteria
    final Criteria criteria = getCriteria(configurationContext, requestContext);
    final List<Rule> rules = criteria.getRules();
    // generate the rules
    List<RuleDTO> ruleDtos = null;
    if (rules != null) {
        ruleDtos = new ArrayList<>(rules.size());
        for (final Rule rule : rules) {
            final RuleDTO ruleDto = DtoFactory.createRuleDTO(rule);
            ruleDtos.add(ruleDto);
            // prune if appropriate
            if (!verbose) {
                ruleDto.setConditions(null);
                ruleDto.setActions(null);
            }
        }
    }
    // create the response entity
    final RulesEntity responseEntity = new RulesEntity();
    responseEntity.setProcessorId(processorId);
    responseEntity.setRules(ruleDtos);
    // generate the response
    final ResponseBuilder response = Response.ok(responseEntity);
    return noCache(response).build();
}
Also used : RuleDTO(org.apache.nifi.update.attributes.dto.RuleDTO) Criteria(org.apache.nifi.update.attributes.Criteria) Rule(org.apache.nifi.update.attributes.Rule) RulesEntity(org.apache.nifi.update.attributes.entity.RulesEntity) 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 3 with Criteria

use of org.apache.nifi.update.attributes.Criteria in project nifi by apache.

the class RuleResource method getCriteria.

private Criteria getCriteria(final NiFiWebConfigurationContext configurationContext, final NiFiWebRequestContext requestContext) {
    final ComponentDetails processorDetails;
    try {
        // load the processor configuration
        processorDetails = configurationContext.getComponentDetails(requestContext);
    } catch (final InvalidRevisionException ire) {
        throw new WebApplicationException(ire, invalidRevision(ire.getMessage()));
    } catch (final Exception e) {
        final String message = String.format("Unable to get UpdateAttribute[id=%s] criteria: %s", requestContext.getId(), e);
        logger.error(message, e);
        throw new WebApplicationException(e, error(message));
    }
    Criteria criteria = null;
    if (processorDetails != null) {
        try {
            criteria = CriteriaSerDe.deserialize(processorDetails.getAnnotationData());
        } catch (final IllegalArgumentException iae) {
            final String message = String.format("Unable to deserialize existing rules for UpdateAttribute[id=%s]. Deserialization error: %s", requestContext.getId(), iae);
            logger.error(message, iae);
            throw new WebApplicationException(iae, error(message));
        }
    }
    // ensure the criteria isn't null
    if (criteria == null) {
        criteria = new Criteria();
    }
    return criteria;
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) Criteria(org.apache.nifi.update.attributes.Criteria) ComponentDetails(org.apache.nifi.web.ComponentDetails) NotFoundException(javax.ws.rs.NotFoundException) WebApplicationException(javax.ws.rs.WebApplicationException) InvalidRevisionException(org.apache.nifi.web.InvalidRevisionException) InvalidRevisionException(org.apache.nifi.web.InvalidRevisionException)

Example 4 with Criteria

use of org.apache.nifi.update.attributes.Criteria 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 5 with Criteria

use of org.apache.nifi.update.attributes.Criteria in project nifi by apache.

the class RuleResource method getRule.

@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Path("/rules/{id}")
public Response getRule(@PathParam("id") final String ruleId, @QueryParam("processorId") final String processorId, @DefaultValue("false") @QueryParam("verbose") final Boolean verbose) {
    // get the web context
    final NiFiWebConfigurationContext configurationContext = (NiFiWebConfigurationContext) servletContext.getAttribute("nifi-web-configuration-context");
    // build the web context config
    final NiFiWebRequestContext requestContext = getRequestContext(processorId);
    // load the criteria and get the rule
    final Criteria criteria = getCriteria(configurationContext, requestContext);
    final Rule rule = criteria.getRule(ruleId);
    if (rule == null) {
        throw new NotFoundException();
    }
    // convert to a dto
    final RuleDTO ruleDto = DtoFactory.createRuleDTO(rule);
    // prune if appropriate
    if (!verbose) {
        ruleDto.setConditions(null);
        ruleDto.setActions(null);
    }
    // create the response entity
    final RuleEntity responseEntity = new RuleEntity();
    responseEntity.setProcessorId(processorId);
    responseEntity.setRule(ruleDto);
    // generate the response
    final ResponseBuilder response = Response.ok(responseEntity);
    return noCache(response).build();
}
Also used : RuleDTO(org.apache.nifi.update.attributes.dto.RuleDTO) NotFoundException(javax.ws.rs.NotFoundException) Criteria(org.apache.nifi.update.attributes.Criteria) Rule(org.apache.nifi.update.attributes.Rule) RuleEntity(org.apache.nifi.update.attributes.entity.RuleEntity) 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)

Aggregations

Criteria (org.apache.nifi.update.attributes.Criteria)14 Rule (org.apache.nifi.update.attributes.Rule)10 Path (javax.ws.rs.Path)8 Produces (javax.ws.rs.Produces)8 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)8 NiFiWebConfigurationContext (org.apache.nifi.web.NiFiWebConfigurationContext)8 Action (org.apache.nifi.update.attributes.Action)5 RuleDTO (org.apache.nifi.update.attributes.dto.RuleDTO)5 GET (javax.ws.rs.GET)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 NiFiWebConfigurationRequestContext (org.apache.nifi.web.NiFiWebConfigurationRequestContext)4 NiFiWebRequestContext (org.apache.nifi.web.NiFiWebRequestContext)4 ArrayList (java.util.ArrayList)3 Consumes (javax.ws.rs.Consumes)3 NotFoundException (javax.ws.rs.NotFoundException)3 Condition (org.apache.nifi.update.attributes.Condition)3 RuleEntity (org.apache.nifi.update.attributes.entity.RuleEntity)3 RulesEntity (org.apache.nifi.update.attributes.entity.RulesEntity)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2