Search in sources :

Example 1 with RulesEntity

use of org.apache.nifi.update.attributes.entity.RulesEntity 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 RulesEntity

use of org.apache.nifi.update.attributes.entity.RulesEntity 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 RulesEntity

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

the class RuleResource method deleteRule.

@DELETE
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Path("/rules/{id}")
public Response deleteRule(@PathParam("id") final String ruleId, @QueryParam("processorId") final String processorId, @QueryParam("clientId") final String clientId, @QueryParam("revision") final Long revision) {
    // get the web context
    final NiFiWebConfigurationContext configurationContext = (NiFiWebConfigurationContext) servletContext.getAttribute("nifi-web-configuration-context");
    // build the web context config
    final NiFiWebConfigurationRequestContext requestContext = getConfigurationRequestContext(processorId, revision, clientId);
    // 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();
    }
    // delete the rule
    criteria.deleteRule(rule);
    // save the criteria
    saveCriteria(requestContext, criteria);
    // create the response entity
    final RulesEntity responseEntity = new RulesEntity();
    responseEntity.setClientId(clientId);
    responseEntity.setRevision(revision);
    responseEntity.setProcessorId(processorId);
    // generate the response
    final ResponseBuilder response = Response.ok(responseEntity);
    return noCache(response).build();
}
Also used : NiFiWebConfigurationRequestContext(org.apache.nifi.web.NiFiWebConfigurationRequestContext) NotFoundException(javax.ws.rs.NotFoundException) 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) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces)

Aggregations

Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)3 Criteria (org.apache.nifi.update.attributes.Criteria)3 Rule (org.apache.nifi.update.attributes.Rule)3 RulesEntity (org.apache.nifi.update.attributes.entity.RulesEntity)3 NiFiWebConfigurationContext (org.apache.nifi.web.NiFiWebConfigurationContext)3 GET (javax.ws.rs.GET)2 RuleDTO (org.apache.nifi.update.attributes.dto.RuleDTO)2 NiFiWebRequestContext (org.apache.nifi.web.NiFiWebRequestContext)2 Collator (java.text.Collator)1 DELETE (javax.ws.rs.DELETE)1 NotFoundException (javax.ws.rs.NotFoundException)1 NiFiWebConfigurationRequestContext (org.apache.nifi.web.NiFiWebConfigurationRequestContext)1