use of java.util.function.Function in project gatk by broadinstitute.
the class ReadsDataSourceUnitTest method testManuallySpecifiedIndicesWithCustomReaderFactoryAndNullWrappers.
@Test(dataProvider = "manuallySpecifiedIndexTestData")
public void testManuallySpecifiedIndicesWithCustomReaderFactoryAndNullWrappers(final List<Path> bams, final List<Path> indices) {
final SamReaderFactory customFactory = SamReaderFactory.makeDefault().validationStringency(ValidationStringency.STRICT);
// ReadsDataSource should not be using the wrapper since the files are not on the Google cloud.
// So we pass this invalid wrapper: if the code tries to use it, it'll blow up.
Function<SeekableByteChannel, SeekableByteChannel> nullWrapper = (SeekableByteChannel) -> null;
try (final ReadsDataSource readsSource = new ReadsDataSource(bams, indices, customFactory, nullWrapper, nullWrapper)) {
Assert.assertTrue(readsSource.indicesAvailable(), "Explicitly-provided indices not detected for bams: " + bams);
final Iterator<GATKRead> queryReads = readsSource.query(new SimpleInterval("1", 1, 300));
int queryCount = 0;
while (queryReads.hasNext()) {
++queryCount;
queryReads.next();
}
Assert.assertEquals(queryCount, 5, "Wrong number of reads returned in query");
}
}
use of java.util.function.Function in project ddf by codice.
the class Historian method version.
/**
* Versions updated {@link Metacard}s and {@link ContentItem}s.
*
* @param streamUpdateRequest Needed to pass {@link ddf.catalog.core.versioning.MetacardVersion#SKIP_VERSIONING}
* flag into downstream update
* @param updateStorageResponse Versions this response's updated items
* @return the update response originally passed in
* @throws UnsupportedQueryException
* @throws SourceUnavailableException
* @throws IngestException
*/
public UpdateStorageResponse version(UpdateStorageRequest streamUpdateRequest, UpdateStorageResponse updateStorageResponse, UpdateResponse updateResponse) throws UnsupportedQueryException, SourceUnavailableException, IngestException {
if (doSkip(updateStorageResponse)) {
return updateStorageResponse;
}
setSkipFlag(streamUpdateRequest);
setSkipFlag(updateStorageResponse);
List<Metacard> updatedMetacards = updateStorageResponse.getUpdatedContentItems().stream().filter(ci -> StringUtils.isBlank(ci.getQualifier())).map(ContentItem::getMetacard).filter(Objects::nonNull).filter(isNotVersionNorDeleted).collect(Collectors.toList());
Map<String, Metacard> originalMetacards = query(forIds(updatedMetacards.stream().map(Metacard::getId).collect(Collectors.toList())));
Collection<ReadStorageRequest> ids = getReadStorageRequests(updatedMetacards);
Map<String, List<ContentItem>> content = getContent(ids);
Function<String, Action> getAction = (id) -> content.containsKey(id) ? Action.VERSIONED_CONTENT : Action.VERSIONED;
Map<String, Metacard> versionMetacards = getVersionMetacards(originalMetacards.values(), getAction, (Subject) updateResponse.getProperties().get(SecurityConstants.SECURITY_SUBJECT));
CreateStorageResponse createStorageResponse = versionContentItems(content, versionMetacards);
if (createStorageResponse == null) {
LOGGER.debug("Could not version content items.");
return updateStorageResponse;
}
setResourceUriForContent(/*mutable*/
versionMetacards, createStorageResponse);
storeVersionMetacards(versionMetacards);
return updateStorageResponse;
}
use of java.util.function.Function in project ddf by codice.
the class Historian method version.
/**
* Versions deleted {@link Metacard}s.
*
* @param deleteResponse Versions this responses deleted metacards
*/
public DeleteResponse version(DeleteResponse deleteResponse) throws SourceUnavailableException, IngestException {
if (doSkip(deleteResponse)) {
return deleteResponse;
}
setSkipFlag(deleteResponse);
List<Metacard> deletedMetacards = deleteResponse.getDeletedMetacards().stream().filter(isNotVersionNorDeleted).collect(Collectors.toList());
// [ContentItem.getId: content items]
Map<String, List<ContentItem>> contentItems = getContent(getReadStorageRequests(deletedMetacards));
Function<String, Action> getAction = (id) -> contentItems.containsKey(id) ? Action.DELETED_CONTENT : Action.DELETED;
// [MetacardVersion.VERSION_OF_ID: versioned metacard]
Map<String, Metacard> versionedMap = getVersionMetacards(deletedMetacards, getAction, (Subject) deleteResponse.getRequest().getProperties().get(SecurityConstants.SECURITY_SUBJECT));
CreateStorageResponse createStorageResponse = versionContentItems(contentItems, versionedMap);
if (createStorageResponse != null) {
setResourceUriForContent(/*Mutable*/
versionedMap, createStorageResponse);
}
executeAsSystem(() -> catalogProvider().create(new CreateRequestImpl(new ArrayList<>(versionedMap.values()))));
String emailAddress = SubjectUtils.getEmailAddress((Subject) deleteResponse.getProperties().get(SecurityConstants.SECURITY_SUBJECT));
List<Metacard> deletionMetacards = versionedMap.entrySet().stream().map(s -> new DeletedMetacardImpl(uuidGenerator.generateUuid(), s.getKey(), emailAddress, s.getValue().getId(), MetacardVersionImpl.toMetacard(s.getValue(), metacardTypes))).collect(Collectors.toList());
executeAsSystem(() -> catalogProvider().create(new CreateRequestImpl(deletionMetacards, new HashMap<>())));
return deleteResponse;
}
use of java.util.function.Function in project ddf by codice.
the class MetacardApplication method patchMetacards.
protected UpdateResponse patchMetacards(List<MetacardChanges> metacardChanges) throws SourceUnavailableException, IngestException, FederationException, UnsupportedQueryException {
Set<String> changedIds = metacardChanges.stream().flatMap(mc -> mc.getIds().stream()).collect(Collectors.toSet());
Map<String, Result> results = util.getMetacards(changedIds, "*");
for (MetacardChanges changeset : metacardChanges) {
for (AttributeChange attributeChange : changeset.getAttributes()) {
for (String id : changeset.getIds()) {
List<String> values = attributeChange.getValues();
Metacard result = results.get(id).getMetacard();
Function<Serializable, Serializable> mapFunc = Function.identity();
if (isChangeTypeDate(attributeChange, result)) {
mapFunc = mapFunc.andThen(util::parseDate);
}
result.setAttribute(new AttributeImpl(attributeChange.getAttribute(), values.stream().filter(Objects::nonNull).map(mapFunc).collect(Collectors.toList())));
}
}
}
List<Metacard> changedMetacards = results.values().stream().map(Result::getMetacard).collect(Collectors.toList());
return catalogFramework.update(new UpdateRequestImpl(changedMetacards.stream().map(Metacard::getId).collect(Collectors.toList()).toArray(new String[0]), changedMetacards));
}
use of java.util.function.Function in project dhis2-core by dhis2.
the class QueryPlannerTest method planQueryStartEndDateQueryGrouperB.
/**
* Splits in 4 queries for each period to satisfy optimal for a total
* of 4 queries, because all queries have different periods.
*/
@Test
public void planQueryStartEndDateQueryGrouperB() {
DataQueryParams params = DataQueryParams.newBuilder().withDataElements(getList(deA, deB)).withOrganisationUnits(getList(ouA)).withFilterPeriods(getList(createPeriod("200101"), createPeriod("200102"), createPeriod("200103"), createPeriod("200104"))).build();
List<Function<DataQueryParams, List<DataQueryParams>>> queryGroupers = Lists.newArrayList();
queryGroupers.add(q -> queryPlanner.groupByStartEndDate(q));
QueryPlannerParams plannerParams = QueryPlannerParams.newBuilder().withOptimalQueries(4).withTableName(ANALYTICS_TABLE_NAME).withQueryGroupers(queryGroupers).build();
DataQueryGroups queryGroups = queryPlanner.planQuery(params, plannerParams);
List<DataQueryParams> queries = queryGroups.getAllQueries();
assertEquals(2, queries.size());
assertEquals(1, queryGroups.getSequentialQueries().size());
assertEquals(2, queryGroups.getLargestGroupSize());
for (DataQueryParams query : queries) {
assertNotNull(query.getStartDate());
assertNotNull(query.getEndDate());
assertDimensionNameNotNull(query);
assertNull(query.getFilter(PERIOD_DIM_ID));
}
}
Aggregations