Search in sources :

Example 1 with ComponentDetails

use of org.apache.nifi.web.ComponentDetails 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 ComponentDetails

use of org.apache.nifi.web.ComponentDetails 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 ComponentDetails

use of org.apache.nifi.web.ComponentDetails 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 ComponentDetails

use of org.apache.nifi.web.ComponentDetails 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 ComponentDetails

use of org.apache.nifi.web.ComponentDetails 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)

Aggregations

ComponentDetails (org.apache.nifi.web.ComponentDetails)11 NiFiWebConfigurationContext (org.apache.nifi.web.NiFiWebConfigurationContext)10 Test (org.junit.Test)8 HashMap (java.util.HashMap)6 JerseyTest (org.glassfish.jersey.test.JerseyTest)6 NiFiWebRequestContext (org.apache.nifi.web.NiFiWebRequestContext)5 JoltSpecificationDTO (org.apache.nifi.web.standard.api.transformjson.dto.JoltSpecificationDTO)4 ValidationDTO (org.apache.nifi.web.standard.api.transformjson.dto.ValidationDTO)4 Response (javax.ws.rs.core.Response)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 NiFiWebConfigurationRequestContext (org.apache.nifi.web.NiFiWebConfigurationRequestContext)2 Map (java.util.Map)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 NotFoundException (javax.ws.rs.NotFoundException)1 PUT (javax.ws.rs.PUT)1 WebApplicationException (javax.ws.rs.WebApplicationException)1