use of org.apache.nifi.web.api.entity.BulletinEntity in project nifi by apache.
the class ControllerResource method createBulletin.
/**
* Creates a Bulletin.
*
* @param httpServletRequest request
* @param requestBulletinEntity A bulletinEntity.
* @return A bulletinEntity.
*/
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("bulletin")
@ApiOperation(value = "Creates a new bulletin", response = BulletinEntity.class, authorizations = { @Authorization(value = "Write - /controller") })
@ApiResponses(value = { @ApiResponse(code = 400, message = "NiFi was unable to complete the request because it was invalid. The request should not be retried without modification."), @ApiResponse(code = 401, message = "Client could not be authenticated."), @ApiResponse(code = 403, message = "Client is not authorized to make this request."), @ApiResponse(code = 409, message = "The request was valid but NiFi was not in the appropriate state to process it. Retrying the same request later may be successful.") })
public Response createBulletin(@Context final HttpServletRequest httpServletRequest, @ApiParam(value = "The reporting task configuration details.", required = true) final BulletinEntity requestBulletinEntity) {
if (requestBulletinEntity == null || requestBulletinEntity.getBulletin() == null) {
throw new IllegalArgumentException("Bulletin details must be specified.");
}
final BulletinDTO requestBulletin = requestBulletinEntity.getBulletin();
if (requestBulletin.getId() != null) {
throw new IllegalArgumentException("A bulletin ID cannot be specified.");
}
if (StringUtils.isBlank(requestBulletin.getMessage())) {
throw new IllegalArgumentException("The bulletin message must be specified.");
}
if (isReplicateRequest()) {
return replicate(HttpMethod.POST, requestBulletinEntity);
}
return withWriteLock(serviceFacade, requestBulletinEntity, lookup -> {
authorizeController(RequestAction.WRITE);
}, null, (bulletinEntity) -> {
final BulletinDTO bulletin = bulletinEntity.getBulletin();
final BulletinEntity entity = serviceFacade.createBulletin(bulletin, true);
return generateOkResponse(entity).build();
});
}
use of org.apache.nifi.web.api.entity.BulletinEntity in project nifi by apache.
the class DtoFactory method createBulletinBoardDto.
/**
* Creates a BulletinBoardDTO for the specified bulletins.
*
* @param bulletins bulletins
* @return dto
*/
public BulletinBoardDTO createBulletinBoardDto(final List<BulletinEntity> bulletins) {
// sort the bulletins
Collections.sort(bulletins, new Comparator<BulletinEntity>() {
@Override
public int compare(final BulletinEntity bulletin1, final BulletinEntity bulletin2) {
if (bulletin1 == null && bulletin2 == null) {
return 0;
} else if (bulletin1 == null) {
return 1;
} else if (bulletin2 == null) {
return -1;
}
final Date timestamp1 = bulletin1.getTimestamp();
final Date timestamp2 = bulletin2.getTimestamp();
if (timestamp1 == null && timestamp2 == null) {
return 0;
} else if (timestamp1 == null) {
return 1;
} else if (timestamp2 == null) {
return -1;
} else {
return timestamp1.compareTo(timestamp2);
}
}
});
// create the bulletin board
final BulletinBoardDTO bulletinBoard = new BulletinBoardDTO();
bulletinBoard.setBulletins(bulletins);
bulletinBoard.setGenerated(new Date());
return bulletinBoard;
}
Aggregations