use of org.springframework.data.domain.SliceImpl in project spring-data-mongodb by spring-projects.
the class StringBasedAggregation method doExecute.
/*
* (non-Javascript)
* @see org.springframework.data.mongodb.repository.query.AbstractReactiveMongoQuery#doExecute(org.springframework.data.mongodb.repository.query.MongoQueryMethod, org.springframework.data.repository.query.ResultProcessor, org.springframework.data.mongodb.repository.query.ConvertingParameterAccessor, java.lang.Class)
*/
@Override
protected Object doExecute(MongoQueryMethod method, ResultProcessor resultProcessor, ConvertingParameterAccessor accessor, Class<?> typeToRead) {
Class<?> sourceType = method.getDomainClass();
Class<?> targetType = typeToRead;
List<AggregationOperation> pipeline = computePipeline(method, accessor);
AggregationUtils.appendSortIfPresent(pipeline, accessor, typeToRead);
if (method.isSliceQuery()) {
AggregationUtils.appendLimitAndOffsetIfPresent(pipeline, accessor, LongUnaryOperator.identity(), limit -> limit + 1);
} else {
AggregationUtils.appendLimitAndOffsetIfPresent(pipeline, accessor);
}
boolean isSimpleReturnType = isSimpleReturnType(typeToRead);
boolean isRawAggregationResult = ClassUtils.isAssignable(AggregationResults.class, typeToRead);
if (isSimpleReturnType) {
targetType = Document.class;
} else if (isRawAggregationResult) {
// 🙈
targetType = method.getReturnType().getRequiredActualType().getRequiredComponentType().getType();
}
AggregationOptions options = computeOptions(method, accessor);
TypedAggregation<?> aggregation = new TypedAggregation<>(sourceType, pipeline, options);
if (method.isStreamQuery()) {
Stream<?> stream = mongoOperations.aggregateStream(aggregation, targetType).stream();
if (isSimpleReturnType) {
return stream.map(it -> AggregationUtils.extractSimpleTypeResult((Document) it, typeToRead, mongoConverter));
}
return stream;
}
AggregationResults<Object> result = (AggregationResults<Object>) mongoOperations.aggregate(aggregation, targetType);
if (isRawAggregationResult) {
return result;
}
List<Object> results = result.getMappedResults();
if (method.isCollectionQuery()) {
return isSimpleReturnType ? convertResults(typeToRead, results) : results;
}
if (method.isSliceQuery()) {
Pageable pageable = accessor.getPageable();
int pageSize = pageable.getPageSize();
List<Object> resultsToUse = isSimpleReturnType ? convertResults(typeToRead, results) : results;
boolean hasNext = resultsToUse.size() > pageSize;
return new SliceImpl<>(hasNext ? resultsToUse.subList(0, pageSize) : resultsToUse, pageable, hasNext);
}
Object uniqueResult = result.getUniqueMappedResult();
return isSimpleReturnType ? AggregationUtils.extractSimpleTypeResult((Document) uniqueResult, typeToRead, mongoConverter) : uniqueResult;
}
use of org.springframework.data.domain.SliceImpl in project credhub by cloudfoundry-incubator.
the class EncryptionKeyRotatorTest method beforeEach.
@Before
public void beforeEach() {
oldUuid = UUID.randomUUID();
UUID activeUuid = UUID.randomUUID();
encryptedValueDataService = mock(EncryptedValueDataService.class);
keySet = new EncryptionKeySet();
keySet.add(new EncryptionKey(mock(EncryptionService.class), oldUuid, mock(Key.class)));
keySet.add(new EncryptionKey(mock(EncryptionService.class), activeUuid, mock(Key.class)));
keySet.setActive(activeUuid);
encryptedValue1 = mock(EncryptedValue.class);
encryptedValue2 = mock(EncryptedValue.class);
encryptedValue3 = mock(EncryptedValue.class);
encryptionKeyCanaryMapper = mock(EncryptionKeyCanaryMapper.class);
inactiveCanaries = newArrayList(oldUuid);
when(encryptedValueDataService.findByCanaryUuids(inactiveCanaries)).thenReturn(new SliceImpl<>(asList(encryptedValue1, encryptedValue2))).thenReturn(new SliceImpl<>(asList(encryptedValue3))).thenReturn(new SliceImpl<>(new ArrayList<>()));
final EncryptionKeyRotator encryptionKeyRotator = new EncryptionKeyRotator(encryptedValueDataService, encryptionKeyCanaryMapper, keySet);
encryptionKeyRotator.rotate();
}
Aggregations