Search in sources :

Example 1 with ConditionEntity

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

the class RuleResource method createCondition.

@POST
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Path("/rules/conditions")
public Response createCondition(@Context final UriInfo uriInfo, final ConditionEntity requestEntity) {
    // generate a new id
    final String uuid = UUID.randomUUID().toString();
    final Condition condition;
    try {
        // create the condition object
        final UpdateAttributeModelFactory factory = new UpdateAttributeModelFactory();
        condition = factory.createCondition(requestEntity.getCondition());
        condition.setId(uuid);
    } catch (final IllegalArgumentException iae) {
        throw new WebApplicationException(iae, badRequest(iae.getMessage()));
    }
    // build the response
    final ConditionEntity responseEntity = new ConditionEntity();
    responseEntity.setClientId(requestEntity.getClientId());
    responseEntity.setProcessorId(requestEntity.getProcessorId());
    responseEntity.setRevision(requestEntity.getRevision());
    responseEntity.setCondition(DtoFactory.createConditionDTO(condition));
    // generate the response
    final UriBuilder uriBuilder = uriInfo.getAbsolutePathBuilder();
    final ResponseBuilder response = Response.created(uriBuilder.path(uuid).build()).entity(responseEntity);
    return noCache(response).build();
}
Also used : Condition(org.apache.nifi.update.attributes.Condition) WebApplicationException(javax.ws.rs.WebApplicationException) UpdateAttributeModelFactory(org.apache.nifi.update.attributes.UpdateAttributeModelFactory) UriBuilder(javax.ws.rs.core.UriBuilder) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) ConditionEntity(org.apache.nifi.update.attributes.entity.ConditionEntity) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Aggregations

Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)1 UriBuilder (javax.ws.rs.core.UriBuilder)1 Condition (org.apache.nifi.update.attributes.Condition)1 UpdateAttributeModelFactory (org.apache.nifi.update.attributes.UpdateAttributeModelFactory)1 ConditionEntity (org.apache.nifi.update.attributes.entity.ConditionEntity)1