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