Search in sources :

Example 1 with BulletinQuery

use of org.apache.nifi.reporting.BulletinQuery in project nifi by apache.

the class StandardNiFiServiceFacade method getControllerBulletins.

@Override
public ControllerBulletinsEntity getControllerBulletins() {
    final NiFiUser user = NiFiUserUtils.getNiFiUser();
    final ControllerBulletinsEntity controllerBulletinsEntity = new ControllerBulletinsEntity();
    final List<BulletinEntity> controllerBulletinEntities = new ArrayList<>();
    final Authorizable controllerAuthorizable = authorizableLookup.getController();
    final boolean authorized = controllerAuthorizable.isAuthorized(authorizer, RequestAction.READ, user);
    final List<BulletinDTO> bulletins = dtoFactory.createBulletinDtos(bulletinRepository.findBulletinsForController());
    controllerBulletinEntities.addAll(bulletins.stream().map(bulletin -> entityFactory.createBulletinEntity(bulletin, authorized)).collect(Collectors.toList()));
    // get the controller service bulletins
    final BulletinQuery controllerServiceQuery = new BulletinQuery.Builder().sourceType(ComponentType.CONTROLLER_SERVICE).build();
    final List<Bulletin> allControllerServiceBulletins = bulletinRepository.findBulletins(controllerServiceQuery);
    final List<BulletinEntity> controllerServiceBulletinEntities = new ArrayList<>();
    for (final Bulletin bulletin : allControllerServiceBulletins) {
        try {
            final Authorizable controllerServiceAuthorizable = authorizableLookup.getControllerService(bulletin.getSourceId()).getAuthorizable();
            final boolean controllerServiceAuthorized = controllerServiceAuthorizable.isAuthorized(authorizer, RequestAction.READ, user);
            final BulletinEntity controllerServiceBulletin = entityFactory.createBulletinEntity(dtoFactory.createBulletinDto(bulletin), controllerServiceAuthorized);
            controllerServiceBulletinEntities.add(controllerServiceBulletin);
            controllerBulletinEntities.add(controllerServiceBulletin);
        } catch (final ResourceNotFoundException e) {
        // controller service missing.. skip
        }
    }
    controllerBulletinsEntity.setControllerServiceBulletins(controllerServiceBulletinEntities);
    // get the reporting task bulletins
    final BulletinQuery reportingTaskQuery = new BulletinQuery.Builder().sourceType(ComponentType.REPORTING_TASK).build();
    final List<Bulletin> allReportingTaskBulletins = bulletinRepository.findBulletins(reportingTaskQuery);
    final List<BulletinEntity> reportingTaskBulletinEntities = new ArrayList<>();
    for (final Bulletin bulletin : allReportingTaskBulletins) {
        try {
            final Authorizable reportingTaskAuthorizable = authorizableLookup.getReportingTask(bulletin.getSourceId()).getAuthorizable();
            final boolean reportingTaskAuthorizableAuthorized = reportingTaskAuthorizable.isAuthorized(authorizer, RequestAction.READ, user);
            final BulletinEntity reportingTaskBulletin = entityFactory.createBulletinEntity(dtoFactory.createBulletinDto(bulletin), reportingTaskAuthorizableAuthorized);
            reportingTaskBulletinEntities.add(reportingTaskBulletin);
            controllerBulletinEntities.add(reportingTaskBulletin);
        } catch (final ResourceNotFoundException e) {
        // reporting task missing.. skip
        }
    }
    controllerBulletinsEntity.setReportingTaskBulletins(reportingTaskBulletinEntities);
    controllerBulletinsEntity.setBulletins(pruneAndSortBulletins(controllerBulletinEntities, BulletinRepository.MAX_BULLETINS_FOR_CONTROLLER));
    return controllerBulletinsEntity;
}
Also used : ControllerBulletinsEntity(org.apache.nifi.web.api.entity.ControllerBulletinsEntity) NiFiUser(org.apache.nifi.authorization.user.NiFiUser) BulletinQuery(org.apache.nifi.reporting.BulletinQuery) ArrayList(java.util.ArrayList) BulletinEntity(org.apache.nifi.web.api.entity.BulletinEntity) Bulletin(org.apache.nifi.reporting.Bulletin) Authorizable(org.apache.nifi.authorization.resource.Authorizable) BulletinDTO(org.apache.nifi.web.api.dto.BulletinDTO)

Aggregations

ArrayList (java.util.ArrayList)1 Authorizable (org.apache.nifi.authorization.resource.Authorizable)1 NiFiUser (org.apache.nifi.authorization.user.NiFiUser)1 Bulletin (org.apache.nifi.reporting.Bulletin)1 BulletinQuery (org.apache.nifi.reporting.BulletinQuery)1 BulletinDTO (org.apache.nifi.web.api.dto.BulletinDTO)1 BulletinEntity (org.apache.nifi.web.api.entity.BulletinEntity)1 ControllerBulletinsEntity (org.apache.nifi.web.api.entity.ControllerBulletinsEntity)1