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