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