Search in sources :

Example 36 with BulletinEntity

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();
    });
}
Also used : BulletinDTO(org.apache.nifi.web.api.dto.BulletinDTO) BulletinEntity(org.apache.nifi.web.api.entity.BulletinEntity) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 37 with BulletinEntity

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;
}
Also used : BulletinEntity(org.apache.nifi.web.api.entity.BulletinEntity) Date(java.util.Date)

Aggregations

BulletinEntity (org.apache.nifi.web.api.entity.BulletinEntity)37 ArrayList (java.util.ArrayList)32 List (java.util.List)29 NodeIdentifier (org.apache.nifi.cluster.protocol.NodeIdentifier)29 Date (java.util.Date)28 HashMap (java.util.HashMap)28 Map (java.util.Map)28 Collections (java.util.Collections)27 Bulletin (org.apache.nifi.reporting.Bulletin)27 Set (java.util.Set)26 Comparator (java.util.Comparator)25 Collectors (java.util.stream.Collectors)25 Arrays (java.util.Arrays)24 Collection (java.util.Collection)24 HashSet (java.util.HashSet)24 LinkedHashMap (java.util.LinkedHashMap)24 LinkedHashSet (java.util.LinkedHashSet)24 Function (java.util.function.Function)24 Supplier (java.util.function.Supplier)24 WebApplicationException (javax.ws.rs.WebApplicationException)24