use of org.apache.nifi.web.NiFiWebConfigurationContext in project nifi by apache.
the class TestTransformJSONResource method testValidateWithCustomSpecEmptyModule.
@Test
public void testValidateWithCustomSpecEmptyModule() {
final NiFiWebConfigurationContext niFiWebConfigurationContext = mock(NiFiWebConfigurationContext.class);
final Map<String, String> properties = new HashMap<>();
properties.put("jolt-transform", "jolt-transform-custom");
final ComponentDetails componentDetails = new ComponentDetails.Builder().properties(properties).build();
Mockito.when(servletContext.getAttribute(Mockito.anyString())).thenReturn(niFiWebConfigurationContext);
Mockito.when(niFiWebConfigurationContext.getComponentDetails(any(NiFiWebRequestContext.class))).thenReturn(componentDetails);
JoltSpecificationDTO joltSpecificationDTO = new JoltSpecificationDTO("jolt-transform-custom", "[{ \"operation\": \"default\", \"spec\":{ \"custom-id\" :4 }}]");
joltSpecificationDTO.setCustomClass("TestCustomJoltTransform");
ValidationDTO validate = client().target(getBaseUri()).path("/standard/transformjson/validate").request().post(Entity.json(joltSpecificationDTO), ValidationDTO.class);
assertNotNull(validate);
assertTrue(!validate.isValid());
}
use of org.apache.nifi.web.NiFiWebConfigurationContext in project nifi by apache.
the class ProcessorResource method setProperties.
@PUT
@Produces({ MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_JSON })
@Path("/properties")
public Response setProperties(@QueryParam("processorId") final String processorId, @QueryParam("revisionId") final Long revisionId, @QueryParam("clientId") final String clientId, Map<String, String> properties) {
final NiFiWebConfigurationContext nifiWebContext = getWebConfigurationContext();
final NiFiWebConfigurationRequestContext niFiRequestContext = ProcessorWebUtils.getRequestContext(processorId, revisionId, clientId, request);
final ComponentDetails componentDetails = nifiWebContext.updateComponent(niFiRequestContext, null, properties);
final Response.ResponseBuilder response = ProcessorWebUtils.applyCacheControl(Response.ok(componentDetails));
return response.build();
}
use of org.apache.nifi.web.NiFiWebConfigurationContext in project nifi by apache.
the class TestProcessorWebUtils method testGetComponentDetailsForProcessor.
@Test
public void testGetComponentDetailsForProcessor() {
HttpServletRequest request = mock(HttpServletRequest.class);
NiFiWebConfigurationContext configurationContext = mock(NiFiWebConfigurationContext.class);
when(configurationContext.getComponentDetails(any(HttpServletRequestContext.class))).thenReturn(new ComponentDetails.Builder().build());
ComponentDetails componentDetails = ProcessorWebUtils.getComponentDetails(configurationContext, "1", request);
assertNotNull(componentDetails);
}
use of org.apache.nifi.web.NiFiWebConfigurationContext in project nifi by apache.
the class TestProcessorWebUtils method testGetComponentDetailsForProcessorWithSpecificClientRevision.
@Test
public void testGetComponentDetailsForProcessorWithSpecificClientRevision() {
NiFiWebConfigurationContext configurationContext = mock(NiFiWebConfigurationContext.class);
when(configurationContext.getComponentDetails(any(HttpServletConfigurationRequestContext.class))).thenReturn(new ComponentDetails.Builder().build());
ComponentDetails componentDetails = ProcessorWebUtils.getComponentDetails(configurationContext, "1", 1L, "client1", mock(HttpServletRequest.class));
assertNotNull(componentDetails);
}
use of org.apache.nifi.web.NiFiWebConfigurationContext 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();
}
Aggregations