Search in sources :

Example 1 with NiFiWebConfigurationContext

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());
}
Also used : HashMap(java.util.HashMap) JoltSpecificationDTO(org.apache.nifi.web.standard.api.transformjson.dto.JoltSpecificationDTO) ValidationDTO(org.apache.nifi.web.standard.api.transformjson.dto.ValidationDTO) NiFiWebConfigurationContext(org.apache.nifi.web.NiFiWebConfigurationContext) ComponentDetails(org.apache.nifi.web.ComponentDetails) NiFiWebRequestContext(org.apache.nifi.web.NiFiWebRequestContext) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 2 with NiFiWebConfigurationContext

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();
}
Also used : Response(javax.ws.rs.core.Response) NiFiWebConfigurationRequestContext(org.apache.nifi.web.NiFiWebConfigurationRequestContext) NiFiWebConfigurationContext(org.apache.nifi.web.NiFiWebConfigurationContext) ComponentDetails(org.apache.nifi.web.ComponentDetails) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 3 with NiFiWebConfigurationContext

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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) NiFiWebConfigurationContext(org.apache.nifi.web.NiFiWebConfigurationContext) ComponentDetails(org.apache.nifi.web.ComponentDetails) HttpServletRequestContext(org.apache.nifi.web.HttpServletRequestContext) Test(org.junit.Test)

Example 4 with NiFiWebConfigurationContext

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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletConfigurationRequestContext(org.apache.nifi.web.HttpServletConfigurationRequestContext) NiFiWebConfigurationContext(org.apache.nifi.web.NiFiWebConfigurationContext) ComponentDetails(org.apache.nifi.web.ComponentDetails) Test(org.junit.Test)

Example 5 with NiFiWebConfigurationContext

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

Aggregations

NiFiWebConfigurationContext (org.apache.nifi.web.NiFiWebConfigurationContext)20 Path (javax.ws.rs.Path)10 Produces (javax.ws.rs.Produces)10 ComponentDetails (org.apache.nifi.web.ComponentDetails)10 NiFiWebRequestContext (org.apache.nifi.web.NiFiWebRequestContext)9 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)8 Criteria (org.apache.nifi.update.attributes.Criteria)8 Test (org.junit.Test)8 HashMap (java.util.HashMap)6 Rule (org.apache.nifi.update.attributes.Rule)6 NiFiWebConfigurationRequestContext (org.apache.nifi.web.NiFiWebConfigurationRequestContext)6 JerseyTest (org.glassfish.jersey.test.JerseyTest)6 GET (javax.ws.rs.GET)5 RuleDTO (org.apache.nifi.update.attributes.dto.RuleDTO)5 Consumes (javax.ws.rs.Consumes)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 JoltSpecificationDTO (org.apache.nifi.web.standard.api.transformjson.dto.JoltSpecificationDTO)4 ValidationDTO (org.apache.nifi.web.standard.api.transformjson.dto.ValidationDTO)4 NotFoundException (javax.ws.rs.NotFoundException)3 PUT (javax.ws.rs.PUT)3