Search in sources :

Example 1 with Predicate

use of org.apache.commons.collections4.Predicate in project nifi by apache.

the class StandardNiFiServiceFacade method getProcessorDiagnostics.

@Override
public ProcessorDiagnosticsEntity getProcessorDiagnostics(final String id) {
    final ProcessorNode processor = processorDAO.getProcessor(id);
    final ProcessorStatus processorStatus = controllerFacade.getProcessorStatus(id);
    // Generate Processor Diagnostics
    final NiFiUser user = NiFiUserUtils.getNiFiUser();
    final ProcessorDiagnosticsDTO dto = controllerFacade.getProcessorDiagnostics(processor, processorStatus, bulletinRepository, serviceId -> createControllerServiceEntity(serviceId, user));
    // Filter anything out of diagnostics that the user is not authorized to see.
    final List<JVMDiagnosticsSnapshotDTO> jvmDiagnosticsSnaphots = new ArrayList<>();
    final JVMDiagnosticsDTO jvmDiagnostics = dto.getJvmDiagnostics();
    jvmDiagnosticsSnaphots.add(jvmDiagnostics.getAggregateSnapshot());
    // filter controller-related information
    final boolean canReadController = authorizableLookup.getController().isAuthorized(authorizer, RequestAction.READ, user);
    if (!canReadController) {
        for (final JVMDiagnosticsSnapshotDTO snapshot : jvmDiagnosticsSnaphots) {
            snapshot.setControllerDiagnostics(null);
        }
    }
    // filter system diagnostics information
    final boolean canReadSystem = authorizableLookup.getSystem().isAuthorized(authorizer, RequestAction.READ, user);
    if (!canReadSystem) {
        for (final JVMDiagnosticsSnapshotDTO snapshot : jvmDiagnosticsSnaphots) {
            snapshot.setSystemDiagnosticsDto(null);
        }
    }
    final boolean canReadFlow = authorizableLookup.getFlow().isAuthorized(authorizer, RequestAction.READ, user);
    if (!canReadFlow) {
        for (final JVMDiagnosticsSnapshotDTO snapshot : jvmDiagnosticsSnaphots) {
            snapshot.setFlowDiagnosticsDto(null);
        }
    }
    // filter connections
    final Predicate<ConnectionDiagnosticsDTO> connectionAuthorized = connectionDiagnostics -> {
        final String connectionId = connectionDiagnostics.getConnection().getId();
        return authorizableLookup.getConnection(connectionId).getAuthorizable().isAuthorized(authorizer, RequestAction.READ, user);
    };
    // Filter incoming connections by what user is authorized to READ
    final Set<ConnectionDiagnosticsDTO> incoming = dto.getIncomingConnections();
    final Set<ConnectionDiagnosticsDTO> filteredIncoming = incoming.stream().filter(connectionAuthorized).collect(Collectors.toSet());
    dto.setIncomingConnections(filteredIncoming);
    // Filter outgoing connections by what user is authorized to READ
    final Set<ConnectionDiagnosticsDTO> outgoing = dto.getOutgoingConnections();
    final Set<ConnectionDiagnosticsDTO> filteredOutgoing = outgoing.stream().filter(connectionAuthorized).collect(Collectors.toSet());
    dto.setOutgoingConnections(filteredOutgoing);
    // Filter out any controller services that are referenced by the Processor
    final Set<ControllerServiceDiagnosticsDTO> referencedServices = dto.getReferencedControllerServices();
    final Set<ControllerServiceDiagnosticsDTO> filteredReferencedServices = referencedServices.stream().filter(csDiagnostics -> {
        final String csId = csDiagnostics.getControllerService().getId();
        return authorizableLookup.getControllerService(csId).getAuthorizable().isAuthorized(authorizer, RequestAction.READ, user);
    }).map(csDiagnostics -> {
        // Filter out any referencing components because those are generally not relevant from this context.
        final ControllerServiceDTO serviceDto = csDiagnostics.getControllerService().getComponent();
        if (serviceDto != null) {
            serviceDto.setReferencingComponents(null);
        }
        return csDiagnostics;
    }).collect(Collectors.toSet());
    dto.setReferencedControllerServices(filteredReferencedServices);
    final Revision revision = revisionManager.getRevision(id);
    final RevisionDTO revisionDto = dtoFactory.createRevisionDTO(revision);
    final PermissionsDTO permissionsDto = dtoFactory.createPermissionsDto(processor);
    final List<BulletinEntity> bulletins = bulletinRepository.findBulletinsForSource(id).stream().map(bulletin -> dtoFactory.createBulletinDto(bulletin)).map(bulletin -> entityFactory.createBulletinEntity(bulletin, permissionsDto.getCanRead())).collect(Collectors.toList());
    final ProcessorStatusDTO processorStatusDto = dtoFactory.createProcessorStatusDto(controllerFacade.getProcessorStatus(processor.getIdentifier()));
    return entityFactory.createProcessorDiagnosticsEntity(dto, revisionDto, permissionsDto, processorStatusDto, bulletins);
}
Also used : EnforcePolicyPermissionsThroughBaseResource(org.apache.nifi.authorization.resource.EnforcePolicyPermissionsThroughBaseResource) ConnectionDiagnosticsDTO(org.apache.nifi.web.api.dto.diagnostics.ConnectionDiagnosticsDTO) FlowComparison(org.apache.nifi.registry.flow.diff.FlowComparison) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) ProcessorEntity(org.apache.nifi.web.api.entity.ProcessorEntity) AuthorizeAccess(org.apache.nifi.authorization.AuthorizeAccess) VersionedFlowSnapshotMetadata(org.apache.nifi.registry.flow.VersionedFlowSnapshotMetadata) SnippetEntity(org.apache.nifi.web.api.entity.SnippetEntity) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) NiFiRegistryException(org.apache.nifi.registry.client.NiFiRegistryException) Scope(org.apache.nifi.components.state.Scope) ControllerFacade(org.apache.nifi.web.controller.ControllerFacade) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) Map(java.util.Map) UserGroupDAO(org.apache.nifi.web.dao.UserGroupDAO) CurrentUserEntity(org.apache.nifi.web.api.entity.CurrentUserEntity) Connection(org.apache.nifi.connectable.Connection) RevisionUpdate(org.apache.nifi.web.revision.RevisionUpdate) BulletinDTO(org.apache.nifi.web.api.dto.BulletinDTO) FlowDifferenceFilters(org.apache.nifi.util.FlowDifferenceFilters) NodeEvent(org.apache.nifi.cluster.event.NodeEvent) VersionedFlowDTO(org.apache.nifi.web.api.dto.VersionedFlowDTO) RemoteProcessGroupPortDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO) ComponentReferenceEntity(org.apache.nifi.web.api.entity.ComponentReferenceEntity) PortDTO(org.apache.nifi.web.api.dto.PortDTO) UserDTO(org.apache.nifi.web.api.dto.UserDTO) Stream(java.util.stream.Stream) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) InstantiatedVersionedProcessor(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedProcessor) ProcessGroupDAO(org.apache.nifi.web.dao.ProcessGroupDAO) ProcessorDiagnosticsEntity(org.apache.nifi.web.api.entity.ProcessorDiagnosticsEntity) RegistryDAO(org.apache.nifi.web.dao.RegistryDAO) UserEntity(org.apache.nifi.web.api.entity.UserEntity) CountersSnapshotDTO(org.apache.nifi.web.api.dto.CountersSnapshotDTO) SnippetUtils(org.apache.nifi.web.util.SnippetUtils) RemoteProcessGroupStatusEntity(org.apache.nifi.web.api.entity.RemoteProcessGroupStatusEntity) PreviousValue(org.apache.nifi.history.PreviousValue) StandardComparableDataFlow(org.apache.nifi.registry.flow.diff.StandardComparableDataFlow) ConnectionDAO(org.apache.nifi.web.dao.ConnectionDAO) ProvenanceEventDTO(org.apache.nifi.web.api.dto.provenance.ProvenanceEventDTO) ControllerServiceEntity(org.apache.nifi.web.api.entity.ControllerServiceEntity) ConfigurableComponent(org.apache.nifi.components.ConfigurableComponent) TemplateEntity(org.apache.nifi.web.api.entity.TemplateEntity) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO) Supplier(java.util.function.Supplier) CollectionUtils(org.apache.commons.collections4.CollectionUtils) LineageDTO(org.apache.nifi.web.api.dto.provenance.lineage.LineageDTO) LinkedHashMap(java.util.LinkedHashMap) FlowChangeAction(org.apache.nifi.action.FlowChangeAction) ProcessGroupCounts(org.apache.nifi.groups.ProcessGroupCounts) VariableRegistryDTO(org.apache.nifi.web.api.dto.VariableRegistryDTO) FlowDTO(org.apache.nifi.web.api.dto.flow.FlowDTO) RegistryDTO(org.apache.nifi.web.api.dto.RegistryDTO) ProvenanceDTO(org.apache.nifi.web.api.dto.provenance.ProvenanceDTO) ClusterRoles(org.apache.nifi.cluster.coordination.node.ClusterRoles) VersionedFlowState(org.apache.nifi.registry.flow.VersionedFlowState) FlowConfigurationEntity(org.apache.nifi.web.api.entity.FlowConfigurationEntity) ContentDirection(org.apache.nifi.controller.repository.claim.ContentDirection) PortDAO(org.apache.nifi.web.dao.PortDAO) AuthorizableLookup(org.apache.nifi.authorization.AuthorizableLookup) RequestAction(org.apache.nifi.authorization.RequestAction) IOException(java.io.IOException) CountersDTO(org.apache.nifi.web.api.dto.CountersDTO) VersionedFlowSnapshot(org.apache.nifi.registry.flow.VersionedFlowSnapshot) NiFiRegistryFlowMapper(org.apache.nifi.registry.flow.mapping.NiFiRegistryFlowMapper) HistoryDTO(org.apache.nifi.web.api.dto.action.HistoryDTO) SystemDiagnosticsDTO(org.apache.nifi.web.api.dto.SystemDiagnosticsDTO) ControllerServiceDiagnosticsDTO(org.apache.nifi.web.api.dto.diagnostics.ControllerServiceDiagnosticsDTO) BulletinFactory(org.apache.nifi.events.BulletinFactory) VersionedFlowSnapshotMetadataEntity(org.apache.nifi.web.api.entity.VersionedFlowSnapshotMetadataEntity) ProcessorStatusEntity(org.apache.nifi.web.api.entity.ProcessorStatusEntity) ComponentStateDTO(org.apache.nifi.web.api.dto.ComponentStateDTO) UserDAO(org.apache.nifi.web.dao.UserDAO) RemoteProcessGroupDAO(org.apache.nifi.web.dao.RemoteProcessGroupDAO) UnknownNodeException(org.apache.nifi.cluster.manager.exception.UnknownNodeException) FlowEntity(org.apache.nifi.web.api.entity.FlowEntity) AffectedComponentEntity(org.apache.nifi.web.api.entity.AffectedComponentEntity) BucketEntity(org.apache.nifi.web.api.entity.BucketEntity) ScheduleComponentsEntity(org.apache.nifi.web.api.entity.ScheduleComponentsEntity) DisconnectionCode(org.apache.nifi.cluster.coordination.node.DisconnectionCode) ProcessGroup(org.apache.nifi.groups.ProcessGroup) BulletinQueryDTO(org.apache.nifi.web.api.dto.BulletinQueryDTO) ListIterator(java.util.ListIterator) Date(java.util.Date) ProcessorStatusDTO(org.apache.nifi.web.api.dto.status.ProcessorStatusDTO) RegistryClientEntity(org.apache.nifi.web.api.entity.RegistryClientEntity) SnippetDAO(org.apache.nifi.web.dao.SnippetDAO) StandardFlowComparator(org.apache.nifi.registry.flow.diff.StandardFlowComparator) ControllerConfigurationEntity(org.apache.nifi.web.api.entity.ControllerConfigurationEntity) LabelDTO(org.apache.nifi.web.api.dto.LabelDTO) ControllerConfigurationDTO(org.apache.nifi.web.api.dto.ControllerConfigurationDTO) InstantiatedVersionedRemoteGroupPort(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedRemoteGroupPort) ControllerStatusDTO(org.apache.nifi.web.api.dto.status.ControllerStatusDTO) UpdateRevisionTask(org.apache.nifi.web.revision.UpdateRevisionTask) VersionedComponent(org.apache.nifi.registry.flow.VersionedComponent) Label(org.apache.nifi.controller.label.Label) RevisionClaim(org.apache.nifi.web.revision.RevisionClaim) Authorizable(org.apache.nifi.authorization.resource.Authorizable) ControllerServiceReferencingComponentDTO(org.apache.nifi.web.api.dto.ControllerServiceReferencingComponentDTO) RequiredPermission(org.apache.nifi.components.RequiredPermission) EntityFactory(org.apache.nifi.web.api.dto.EntityFactory) Collection(java.util.Collection) RemoteProcessGroupPortEntity(org.apache.nifi.web.api.entity.RemoteProcessGroupPortEntity) RevisionManager(org.apache.nifi.web.revision.RevisionManager) UUID(java.util.UUID) Snippet(org.apache.nifi.controller.Snippet) PortEntity(org.apache.nifi.web.api.entity.PortEntity) Collectors(java.util.stream.Collectors) ResourceFactory(org.apache.nifi.authorization.resource.ResourceFactory) StateMap(org.apache.nifi.components.state.StateMap) Objects(java.util.Objects) Response(javax.ws.rs.core.Response) ComponentReferenceDTO(org.apache.nifi.web.api.dto.ComponentReferenceDTO) ProcessGroupEntity(org.apache.nifi.web.api.entity.ProcessGroupEntity) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) ControllerServiceState(org.apache.nifi.controller.service.ControllerServiceState) ConnectionStatusDTO(org.apache.nifi.web.api.dto.status.ConnectionStatusDTO) ReportingTaskDTO(org.apache.nifi.web.api.dto.ReportingTaskDTO) AuditService(org.apache.nifi.admin.service.AuditService) FlowSnippetDTO(org.apache.nifi.web.api.dto.FlowSnippetDTO) ReportingTaskDAO(org.apache.nifi.web.dao.ReportingTaskDAO) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO) ProcessorNode(org.apache.nifi.controller.ProcessorNode) Bucket(org.apache.nifi.registry.bucket.Bucket) NodeHeartbeat(org.apache.nifi.cluster.coordination.heartbeat.NodeHeartbeat) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) ProcessGroupStatusDTO(org.apache.nifi.web.api.dto.status.ProcessGroupStatusDTO) Group(org.apache.nifi.authorization.Group) Function(java.util.function.Function) FlowRegistry(org.apache.nifi.registry.flow.FlowRegistry) PermissionsDTO(org.apache.nifi.web.api.dto.PermissionsDTO) HashSet(java.util.HashSet) ListingRequestDTO(org.apache.nifi.web.api.dto.ListingRequestDTO) ControllerServiceReferencingComponentEntity(org.apache.nifi.web.api.entity.ControllerServiceReferencingComponentEntity) VersionControlInformationDTO(org.apache.nifi.web.api.dto.VersionControlInformationDTO) ReportingTaskNode(org.apache.nifi.controller.ReportingTaskNode) ValidationResult(org.apache.nifi.components.ValidationResult) ComponentDifferenceDTO(org.apache.nifi.web.api.dto.ComponentDifferenceDTO) Logger(org.slf4j.Logger) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) PropertyHistoryDTO(org.apache.nifi.web.api.dto.PropertyHistoryDTO) FlowFileDTO(org.apache.nifi.web.api.dto.FlowFileDTO) VariableRegistryEntity(org.apache.nifi.web.api.entity.VariableRegistryEntity) VersionedFlow(org.apache.nifi.registry.flow.VersionedFlow) IllegalNodeDeletionException(org.apache.nifi.cluster.manager.exception.IllegalNodeDeletionException) DropRequestDTO(org.apache.nifi.web.api.dto.DropRequestDTO) LabelEntity(org.apache.nifi.web.api.entity.LabelEntity) RemoteProcessGroupEntity(org.apache.nifi.web.api.entity.RemoteProcessGroupEntity) NiFiUserUtils(org.apache.nifi.authorization.user.NiFiUserUtils) BulletinRepository(org.apache.nifi.reporting.BulletinRepository) AccessPolicyEntity(org.apache.nifi.web.api.entity.AccessPolicyEntity) NodeDTO(org.apache.nifi.web.api.dto.NodeDTO) Operation(org.apache.nifi.action.Operation) SnippetDTO(org.apache.nifi.web.api.dto.SnippetDTO) Comparator(java.util.Comparator) CounterDTO(org.apache.nifi.web.api.dto.CounterDTO) InstantiatedVersionedComponent(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedComponent) Arrays(java.util.Arrays) StatusHistoryEntity(org.apache.nifi.web.api.entity.StatusHistoryEntity) FlowChangePurgeDetails(org.apache.nifi.action.details.FlowChangePurgeDetails) PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) ProcessGroupStatusSnapshotDTO(org.apache.nifi.web.api.dto.status.ProcessGroupStatusSnapshotDTO) ControllerServiceDAO(org.apache.nifi.web.dao.ControllerServiceDAO) AuthorizationRequest(org.apache.nifi.authorization.AuthorizationRequest) PropertyDescriptorDTO(org.apache.nifi.web.api.dto.PropertyDescriptorDTO) FunnelDAO(org.apache.nifi.web.dao.FunnelDAO) AuthorizationResult(org.apache.nifi.authorization.AuthorizationResult) TenantEntity(org.apache.nifi.web.api.entity.TenantEntity) ProcessGroupFlowEntity(org.apache.nifi.web.api.entity.ProcessGroupFlowEntity) RootGroupPort(org.apache.nifi.remote.RootGroupPort) BulletinQuery(org.apache.nifi.reporting.BulletinQuery) Connectable(org.apache.nifi.connectable.Connectable) Bulletin(org.apache.nifi.reporting.Bulletin) FunnelDTO(org.apache.nifi.web.api.dto.FunnelDTO) ProcessorStatus(org.apache.nifi.controller.status.ProcessorStatus) HistoryQueryDTO(org.apache.nifi.web.api.dto.action.HistoryQueryDTO) ControllerServiceReferencingComponentsEntity(org.apache.nifi.web.api.entity.ControllerServiceReferencingComponentsEntity) FunnelEntity(org.apache.nifi.web.api.entity.FunnelEntity) AccessPolicyDAO(org.apache.nifi.web.dao.AccessPolicyDAO) ProcessGroupStatus(org.apache.nifi.controller.status.ProcessGroupStatus) History(org.apache.nifi.history.History) AccessPolicySummaryEntity(org.apache.nifi.web.api.entity.AccessPolicySummaryEntity) Set(java.util.Set) BulletinBoardDTO(org.apache.nifi.web.api.dto.BulletinBoardDTO) VersionedFlowCoordinates(org.apache.nifi.registry.flow.VersionedFlowCoordinates) FlowController(org.apache.nifi.controller.FlowController) ProcessorDAO(org.apache.nifi.web.dao.ProcessorDAO) StandardCharsets(java.nio.charset.StandardCharsets) FlowComparisonEntity(org.apache.nifi.web.api.entity.FlowComparisonEntity) ScheduledState(org.apache.nifi.controller.ScheduledState) WebApplicationException(javax.ws.rs.WebApplicationException) ActionEntity(org.apache.nifi.web.api.entity.ActionEntity) DtoFactory(org.apache.nifi.web.api.dto.DtoFactory) RemoteProcessGroupStatusDTO(org.apache.nifi.web.api.dto.status.RemoteProcessGroupStatusDTO) ControllerBulletinsEntity(org.apache.nifi.web.api.entity.ControllerBulletinsEntity) Resource(org.apache.nifi.authorization.Resource) FlowComparator(org.apache.nifi.registry.flow.diff.FlowComparator) StaticDifferenceDescriptor(org.apache.nifi.registry.flow.diff.StaticDifferenceDescriptor) LeaderElectionManager(org.apache.nifi.controller.leader.election.LeaderElectionManager) Counter(org.apache.nifi.controller.Counter) AccessDeniedException(org.apache.nifi.authorization.AccessDeniedException) InstantiatedVersionedProcessGroup(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedProcessGroup) TemplateDAO(org.apache.nifi.web.dao.TemplateDAO) ArrayList(java.util.ArrayList) NiFiUser(org.apache.nifi.authorization.user.NiFiUser) ComponentType(org.apache.nifi.reporting.ComponentType) ControllerServiceReference(org.apache.nifi.controller.service.ControllerServiceReference) StandardRevisionClaim(org.apache.nifi.web.revision.StandardRevisionClaim) NodeConnectionState(org.apache.nifi.cluster.coordination.node.NodeConnectionState) AccessPolicyDTO(org.apache.nifi.web.api.dto.AccessPolicyDTO) VersionControlComponentMappingEntity(org.apache.nifi.web.api.entity.VersionControlComponentMappingEntity) RequiredPermissionDTO(org.apache.nifi.web.api.dto.RequiredPermissionDTO) NodeConnectionStatus(org.apache.nifi.cluster.coordination.node.NodeConnectionStatus) LinkedHashSet(java.util.LinkedHashSet) DocumentedTypeDTO(org.apache.nifi.web.api.dto.DocumentedTypeDTO) FlowConfigurationDTO(org.apache.nifi.web.api.dto.FlowConfigurationDTO) ConfiguredComponent(org.apache.nifi.controller.ConfiguredComponent) ProvenanceOptionsDTO(org.apache.nifi.web.api.dto.provenance.ProvenanceOptionsDTO) LabelDAO(org.apache.nifi.web.dao.LabelDAO) InstantiatedVersionedControllerService(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedControllerService) StartVersionControlRequestEntity(org.apache.nifi.web.api.entity.StartVersionControlRequestEntity) ComponentDTO(org.apache.nifi.web.api.dto.ComponentDTO) Authorizer(org.apache.nifi.authorization.Authorizer) NiFiProperties(org.apache.nifi.util.NiFiProperties) ComponentHistoryDTO(org.apache.nifi.web.api.dto.ComponentHistoryDTO) BulletinEntity(org.apache.nifi.web.api.entity.BulletinEntity) VersionedFlowEntity(org.apache.nifi.web.api.entity.VersionedFlowEntity) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) Permissions(org.apache.nifi.registry.authorization.Permissions) PreviousValueDTO(org.apache.nifi.web.api.dto.PreviousValueDTO) ProcessorConfigDTO(org.apache.nifi.web.api.dto.ProcessorConfigDTO) LoggerFactory(org.slf4j.LoggerFactory) Port(org.apache.nifi.connectable.Port) ProcessGroupStatusEntity(org.apache.nifi.web.api.entity.ProcessGroupStatusEntity) TemplateDTO(org.apache.nifi.web.api.dto.TemplateDTO) ActivateControllerServicesEntity(org.apache.nifi.web.api.entity.ActivateControllerServicesEntity) UserGroupEntity(org.apache.nifi.web.api.entity.UserGroupEntity) UserGroupDTO(org.apache.nifi.web.api.dto.UserGroupDTO) ConnectionStatusEntity(org.apache.nifi.web.api.entity.ConnectionStatusEntity) JVMDiagnosticsSnapshotDTO(org.apache.nifi.web.api.dto.diagnostics.JVMDiagnosticsSnapshotDTO) ProcessGroupStatusSnapshotEntity(org.apache.nifi.web.api.entity.ProcessGroupStatusSnapshotEntity) DifferenceType(org.apache.nifi.registry.flow.diff.DifferenceType) AccessPolicySummaryDTO(org.apache.nifi.web.api.dto.AccessPolicySummaryDTO) NodeProcessGroupStatusSnapshotDTO(org.apache.nifi.web.api.dto.status.NodeProcessGroupStatusSnapshotDTO) VersionedConnection(org.apache.nifi.registry.flow.VersionedConnection) Template(org.apache.nifi.controller.Template) FlowRegistryClient(org.apache.nifi.registry.flow.FlowRegistryClient) BucketDTO(org.apache.nifi.web.api.dto.BucketDTO) ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) ReportingTaskEntity(org.apache.nifi.web.api.entity.ReportingTaskEntity) Predicate(java.util.function.Predicate) Sets(com.google.common.collect.Sets) User(org.apache.nifi.authorization.User) JVMDiagnosticsDTO(org.apache.nifi.web.api.dto.diagnostics.JVMDiagnosticsDTO) SystemDiagnostics(org.apache.nifi.diagnostics.SystemDiagnostics) List(java.util.List) Result(org.apache.nifi.authorization.AuthorizationResult.Result) VersionControlInformation(org.apache.nifi.registry.flow.VersionControlInformation) StatusHistoryDTO(org.apache.nifi.web.api.dto.status.StatusHistoryDTO) HeartbeatMonitor(org.apache.nifi.cluster.coordination.heartbeat.HeartbeatMonitor) Optional(java.util.Optional) Action(org.apache.nifi.action.Action) Funnel(org.apache.nifi.connectable.Funnel) ClusterDTO(org.apache.nifi.web.api.dto.ClusterDTO) VariableEntity(org.apache.nifi.web.api.entity.VariableEntity) HashMap(java.util.HashMap) ConciseEvolvingDifferenceDescriptor(org.apache.nifi.registry.flow.diff.ConciseEvolvingDifferenceDescriptor) ResourceDTO(org.apache.nifi.web.api.dto.ResourceDTO) AffectedComponentDTO(org.apache.nifi.web.api.dto.AffectedComponentDTO) HistoryQuery(org.apache.nifi.history.HistoryQuery) ExpiredRevisionClaimException(org.apache.nifi.web.revision.ExpiredRevisionClaimException) PortStatusDTO(org.apache.nifi.web.api.dto.status.PortStatusDTO) ComparableDataFlow(org.apache.nifi.registry.flow.diff.ComparableDataFlow) ClusterCoordinator(org.apache.nifi.cluster.coordination.ClusterCoordinator) StandardRevisionUpdate(org.apache.nifi.web.revision.StandardRevisionUpdate) ComponentRestrictionPermissionDTO(org.apache.nifi.web.api.dto.ComponentRestrictionPermissionDTO) Validator(org.apache.nifi.components.Validator) PortStatusEntity(org.apache.nifi.web.api.entity.PortStatusEntity) ControllerDTO(org.apache.nifi.web.api.dto.ControllerDTO) ProcessorDiagnosticsDTO(org.apache.nifi.web.api.dto.diagnostics.ProcessorDiagnosticsDTO) ComponentVariableRegistry(org.apache.nifi.registry.ComponentVariableRegistry) FlowDifference(org.apache.nifi.registry.flow.diff.FlowDifference) ConnectionEntity(org.apache.nifi.web.api.entity.ConnectionEntity) UserContextKeys(org.apache.nifi.authorization.UserContextKeys) VersionControlInformationEntity(org.apache.nifi.web.api.entity.VersionControlInformationEntity) DeleteRevisionTask(org.apache.nifi.web.revision.DeleteRevisionTask) Component(org.apache.nifi.action.Component) AccessPolicy(org.apache.nifi.authorization.AccessPolicy) SearchResultsDTO(org.apache.nifi.web.api.dto.search.SearchResultsDTO) RegistryEntity(org.apache.nifi.web.api.entity.RegistryEntity) Collections(java.util.Collections) ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) NiFiUser(org.apache.nifi.authorization.user.NiFiUser) ControllerServiceDiagnosticsDTO(org.apache.nifi.web.api.dto.diagnostics.ControllerServiceDiagnosticsDTO) PermissionsDTO(org.apache.nifi.web.api.dto.PermissionsDTO) ArrayList(java.util.ArrayList) JVMDiagnosticsDTO(org.apache.nifi.web.api.dto.diagnostics.JVMDiagnosticsDTO) ProcessorStatus(org.apache.nifi.controller.status.ProcessorStatus) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO) BulletinEntity(org.apache.nifi.web.api.entity.BulletinEntity) JVMDiagnosticsSnapshotDTO(org.apache.nifi.web.api.dto.diagnostics.JVMDiagnosticsSnapshotDTO) ProcessorStatusDTO(org.apache.nifi.web.api.dto.status.ProcessorStatusDTO) ProcessorNode(org.apache.nifi.controller.ProcessorNode) ConnectionDiagnosticsDTO(org.apache.nifi.web.api.dto.diagnostics.ConnectionDiagnosticsDTO) ProcessorDiagnosticsDTO(org.apache.nifi.web.api.dto.diagnostics.ProcessorDiagnosticsDTO)

Example 2 with Predicate

use of org.apache.commons.collections4.Predicate in project xwiki-platform by xwiki.

the class ExtensionHistoryScriptServiceTest method getRecords.

@Test
public void getRecords() throws Exception {
    InstallRequest devInstallReq = new InstallRequest();
    devInstallReq.addNamespace("wiki:dev");
    ExtensionJobHistoryRecord devInstall = new ExtensionJobHistoryRecord("install", devInstallReq, null, null, null);
    UninstallRequest devUninstallReq = new UninstallRequest();
    devUninstallReq.addNamespace("wiki:dev");
    ExtensionJobHistoryRecord devUninstall = new ExtensionJobHistoryRecord("uninstall", devUninstallReq, null, null, null);
    ExtensionJobHistoryRecord globalInstall = new ExtensionJobHistoryRecord("install", new InstallRequest(), null, null, null);
    ExtensionJobHistoryRecord globalUninstall = new ExtensionJobHistoryRecord("uninstall", new UninstallRequest(), null, null, null);
    InstallRequest draftsInstallReq = new InstallRequest();
    draftsInstallReq.addNamespace("wiki:drafts");
    ExtensionJobHistoryRecord draftsInstall = new ExtensionJobHistoryRecord("install", draftsInstallReq, null, null, null);
    List<ExtensionJobHistoryRecord> records = Arrays.asList(devInstall, globalInstall);
    ExtensionJobHistory history = this.mocker.getInstance(ExtensionJobHistory.class);
    ArgumentCaptor<Predicate<ExtensionJobHistoryRecord>> predicateCaptor = ArgumentCaptor.forClass((Class) Predicate.class);
    when(history.getRecords(predicateCaptor.capture(), eq("offsetRecordId"), eq(5))).thenReturn(records);
    when(this.xcontext.getWikiId()).thenReturn("dev");
    assertEquals(records, this.mocker.getComponentUnderTest().getRecords().fromThisWiki().ofType(Arrays.asList("install")).list("offsetRecordId", 5));
    Predicate<ExtensionJobHistoryRecord> predicate = predicateCaptor.getValue();
    assertTrue(predicate.evaluate(devInstall));
    assertTrue(predicate.evaluate(globalInstall));
    assertFalse(predicate.evaluate(devUninstall));
    assertFalse(predicate.evaluate(globalUninstall));
    assertFalse(predicate.evaluate(draftsInstall));
}
Also used : ExtensionJobHistoryRecord(org.xwiki.extension.job.history.ExtensionJobHistoryRecord) InstallRequest(org.xwiki.extension.job.InstallRequest) ExtensionJobHistory(org.xwiki.extension.job.history.ExtensionJobHistory) UninstallRequest(org.xwiki.extension.job.UninstallRequest) Predicate(org.apache.commons.collections4.Predicate) Test(org.junit.Test)

Example 3 with Predicate

use of org.apache.commons.collections4.Predicate in project archiva by apache.

the class RepositoryScannerInstance method visitFile.

@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
    if (excludeMatcher.stream().noneMatch(m -> m.matches(file)) && includeMatcher.stream().allMatch(m -> m.matches(file))) {
        log.debug("Walk Step: {}, {}", file);
        stats.increaseFileCount();
        // consume files regardless - the predicate will check the timestamp
        Path repoPath = PathUtil.getPathFromUri(repository.getLocation());
        BaseFile basefile = new BaseFile(repoPath.toString(), file.toFile());
        // Timestamp finished points to the last successful scan, not this current one.
        if (Files.getLastModifiedTime(file).toMillis() >= changesSince) {
            stats.increaseNewFileCount();
        }
        consumerProcessFile.setBasefile(basefile);
        consumerWantsFile.setBasefile(basefile);
        Closure<RepositoryContentConsumer> processIfWanted = IfClosure.ifClosure(consumerWantsFile, consumerProcessFile);
        IterableUtils.forEach(this.knownConsumers, processIfWanted);
        if (consumerWantsFile.getWantedFileCount() <= 0) {
            // Nothing known processed this file.  It is invalid!
            IterableUtils.forEach(this.invalidConsumers, consumerProcessFile);
        }
    }
    return FileVisitResult.CONTINUE;
}
Also used : PathUtil(org.apache.archiva.common.utils.PathUtil) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) IfClosure(org.apache.commons.collections4.functors.IfClosure) Closure(org.apache.commons.collections4.Closure) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) IterableUtils(org.apache.commons.collections4.IterableUtils) RepositoryContentConsumer(org.apache.archiva.consumers.RepositoryContentConsumer) Map(java.util.Map) PathMatcher(java.nio.file.PathMatcher) ConsumerWantsFilePredicate(org.apache.archiva.consumers.functors.ConsumerWantsFilePredicate) SystemUtils(org.apache.commons.lang.SystemUtils) Path(java.nio.file.Path) TriggerBeginScanClosure(org.apache.archiva.repository.scanner.functors.TriggerBeginScanClosure) Logger(org.slf4j.Logger) FileVisitor(java.nio.file.FileVisitor) Files(java.nio.file.Files) ConsumerProcessFileClosure(org.apache.archiva.repository.scanner.functors.ConsumerProcessFileClosure) KnownRepositoryContentConsumer(org.apache.archiva.consumers.KnownRepositoryContentConsumer) IOException(java.io.IOException) FileSystem(java.nio.file.FileSystem) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) Collectors(java.util.stream.Collectors) ManagedRepository(org.apache.archiva.repository.ManagedRepository) FileVisitResult(java.nio.file.FileVisitResult) List(java.util.List) BaseFile(org.apache.archiva.common.utils.BaseFile) InvalidRepositoryContentConsumer(org.apache.archiva.consumers.InvalidRepositoryContentConsumer) TriggerScanCompletedClosure(org.apache.archiva.repository.scanner.functors.TriggerScanCompletedClosure) FileSystems(java.nio.file.FileSystems) Path(java.nio.file.Path) BaseFile(org.apache.archiva.common.utils.BaseFile) RepositoryContentConsumer(org.apache.archiva.consumers.RepositoryContentConsumer) KnownRepositoryContentConsumer(org.apache.archiva.consumers.KnownRepositoryContentConsumer) InvalidRepositoryContentConsumer(org.apache.archiva.consumers.InvalidRepositoryContentConsumer)

Example 4 with Predicate

use of org.apache.commons.collections4.Predicate in project herd by FINRAOS.

the class TagServiceImpl method indexValidateTagsList.

/**
 * A helper method that will validate a list of tags
 *
 * @param tagEntityList the list of tags that will be validated
 *
 * @return true all of the tags are valid in the index
 */
private boolean indexValidateTagsList(final List<TagEntity> tagEntityList) {
    final String indexName = SearchIndexTypeEntity.SearchIndexTypes.TAG.name().toLowerCase();
    final String documentType = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class);
    Predicate<TagEntity> validInIndexPredicate = tagEntity -> {
        // Fetch Join with .size()
        tagEntity.getChildrenTagEntities().size();
        // Convert the tag entity to a JSON string
        final String jsonString = tagHelper.safeObjectMapperWriteValueAsString(tagEntity);
        return this.indexFunctionsDao.isValidDocumentIndex(indexName, documentType, tagEntity.getId().toString(), jsonString);
    // searchFunctions.getIsValidFunction().test(indexName, documentType, tagEntity.getId().toString(), jsonString);
    };
    boolean isValid = true;
    for (TagEntity tagEntity : tagEntityList) {
        if (!validInIndexPredicate.test(tagEntity)) {
            isValid = false;
        }
    }
    return isValid;
}
Also used : SEARCH_INDEX_UPDATE_TYPE_CREATE(org.finra.herd.model.dto.SearchIndexUpdateDto.SEARCH_INDEX_UPDATE_TYPE_CREATE) LoggerFactory(org.slf4j.LoggerFactory) TagTypeDaoHelper(org.finra.herd.service.helper.TagTypeDaoHelper) Autowired(org.springframework.beans.factory.annotation.Autowired) TagCreateRequest(org.finra.herd.model.api.xml.TagCreateRequest) StringUtils(org.apache.commons.lang3.StringUtils) SearchIndexUpdateDto(org.finra.herd.model.dto.SearchIndexUpdateDto) Tag(org.finra.herd.model.api.xml.Tag) BigDecimal(java.math.BigDecimal) Future(java.util.concurrent.Future) TagSearchKey(org.finra.herd.model.api.xml.TagSearchKey) Map(java.util.Map) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) AsyncResult(org.springframework.scheduling.annotation.AsyncResult) TagTypeEntity(org.finra.herd.model.jpa.TagTypeEntity) ConfigurationValue(org.finra.herd.model.dto.ConfigurationValue) ImmutableSet(com.google.common.collect.ImmutableSet) Predicate(java.util.function.Predicate) TagUpdateRequest(org.finra.herd.model.api.xml.TagUpdateRequest) Set(java.util.Set) List(java.util.List) ConfigurationHelper(org.finra.herd.core.helper.ConfigurationHelper) TagListResponse(org.finra.herd.model.api.xml.TagListResponse) TagTypeKey(org.finra.herd.model.api.xml.TagTypeKey) IndexFunctionsDao(org.finra.herd.dao.IndexFunctionsDao) Async(org.springframework.scheduling.annotation.Async) TagSearchFilter(org.finra.herd.model.api.xml.TagSearchFilter) TagHelper(org.finra.herd.service.helper.TagHelper) TagSearchRequest(org.finra.herd.model.api.xml.TagSearchRequest) HashMap(java.util.HashMap) BooleanUtils(org.apache.commons.lang3.BooleanUtils) DaoSpringModuleConfig(org.finra.herd.dao.config.DaoSpringModuleConfig) CollectionUtils(org.apache.commons.collections4.CollectionUtils) SearchIndexUpdateHelper(org.finra.herd.service.helper.SearchIndexUpdateHelper) ArrayList(java.util.ArrayList) AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) TagSearchResponse(org.finra.herd.model.api.xml.TagSearchResponse) SEARCH_INDEX_UPDATE_TYPE_UPDATE(org.finra.herd.model.dto.SearchIndexUpdateDto.SEARCH_INDEX_UPDATE_TYPE_UPDATE) Service(org.springframework.stereotype.Service) TagChild(org.finra.herd.model.api.xml.TagChild) TagKey(org.finra.herd.model.api.xml.TagKey) TagDao(org.finra.herd.dao.TagDao) Logger(org.slf4j.Logger) AlternateKeyHelper(org.finra.herd.service.helper.AlternateKeyHelper) SearchableService(org.finra.herd.service.SearchableService) HerdDateUtils(org.finra.herd.core.HerdDateUtils) TagEntity(org.finra.herd.model.jpa.TagEntity) BusinessObjectDefinitionDao(org.finra.herd.dao.BusinessObjectDefinitionDao) TagService(org.finra.herd.service.TagService) SEARCH_INDEX_UPDATE_TYPE_DELETE(org.finra.herd.model.dto.SearchIndexUpdateDto.SEARCH_INDEX_UPDATE_TYPE_DELETE) TagDaoHelper(org.finra.herd.service.helper.TagDaoHelper) Collections(java.util.Collections) SearchIndexTypeEntity(org.finra.herd.model.jpa.SearchIndexTypeEntity) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) TagEntity(org.finra.herd.model.jpa.TagEntity)

Example 5 with Predicate

use of org.apache.commons.collections4.Predicate in project herd by FINRAOS.

the class StorageFileDaoImpl method getStorageFilePathsByStorageUnitIds.

@Override
public MultiValuedMap<Integer, String> getStorageFilePathsByStorageUnitIds(List<Integer> storageUnitIds) {
    // Create a map that can hold a collection of values against each key.
    MultiValuedMap<Integer, String> result = new ArrayListValuedHashMap<>();
    // Retrieve the pagination size for the storage file paths query configured in the system.
    Integer paginationSize = configurationHelper.getProperty(ConfigurationValue.STORAGE_FILE_PATHS_QUERY_PAGINATION_SIZE, Integer.class);
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Tuple> criteria = builder.createTupleQuery();
    // The criteria root is the storage file.
    Root<StorageFileEntity> storageFileEntity = criteria.from(StorageFileEntity.class);
    // Get the columns.
    Path<Integer> storageUnitIdColumn = storageFileEntity.get(StorageFileEntity_.storageUnitId);
    Path<String> storageFilePathColumn = storageFileEntity.get(StorageFileEntity_.path);
    // Create the standard restrictions (i.e. the standard where clauses).
    Predicate queryRestriction = getPredicateForInClause(builder, storageUnitIdColumn, storageUnitIds);
    // Add the select clause.
    criteria.multiselect(storageUnitIdColumn, storageFilePathColumn);
    // Add the where clause.
    criteria.where(queryRestriction);
    // Execute the query using pagination and populate the result map.
    int startPosition = 0;
    while (true) {
        // Run the query to get a list of tuples back.
        List<Tuple> tuples = entityManager.createQuery(criteria).setFirstResult(startPosition).setMaxResults(paginationSize).getResultList();
        // Populate the result map from the returned tuples (i.e. 1 tuple for each row).
        for (Tuple tuple : tuples) {
            // Extract the tuple values.
            Integer storageUnitId = tuple.get(storageUnitIdColumn);
            String storageFilePath = tuple.get(storageFilePathColumn);
            // Update the result map.
            result.put(storageUnitId, storageFilePath);
        }
        // Break out of the while loop if we got less results than the pagination size.
        if (tuples.size() < paginationSize) {
            break;
        }
        // Increment the start position.
        startPosition += paginationSize;
    }
    return result;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Predicate(javax.persistence.criteria.Predicate) StorageFileEntity(org.finra.herd.model.jpa.StorageFileEntity) ArrayListValuedHashMap(org.apache.commons.collections4.multimap.ArrayListValuedHashMap) Tuple(javax.persistence.Tuple)

Aggregations

ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)6 List (java.util.List)6 Map (java.util.Map)6 Predicate (java.util.function.Predicate)5 CollectionUtils (org.apache.commons.collections4.CollectionUtils)5 Collections (java.util.Collections)4 Set (java.util.Set)4 Predicate (org.apache.commons.collections4.Predicate)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 IOException (java.io.IOException)3 HashSet (java.util.HashSet)3 Supplier (java.util.function.Supplier)3 Collectors (java.util.stream.Collectors)3 StringUtils (org.apache.commons.lang3.StringUtils)3 BigDecimal (java.math.BigDecimal)2 Collection (java.util.Collection)2 Date (java.util.Date)2 LinkedHashMap (java.util.LinkedHashMap)2