本文整理汇总了Java中org.springframework.data.mongodb.core.aggregation.AggregationResults.getUniqueMappedResult方法的典型用法代码示例。如果您正苦于以下问题:Java AggregationResults.getUniqueMappedResult方法的具体用法?Java AggregationResults.getUniqueMappedResult怎么用?Java AggregationResults.getUniqueMappedResult使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.data.mongodb.core.aggregation.AggregationResults
的用法示例。
在下文中一共展示了AggregationResults.getUniqueMappedResult方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: programIncrementBoardFeatures
import org.springframework.data.mongodb.core.aggregation.AggregationResults; //导入方法依赖的package包/类
@Override
public List<String> programIncrementBoardFeatures(List<String> boards, List<String> programIncrementFeatures){
Aggregation agg = newAggregation(
match(Criteria
.where("sParentKey")
.in(programIncrementFeatures)
.and("keywords")
.in(boards)
),
group()
.addToSet("sParentKey")
.as("features"),
project("features")
.andExclude("_id")
);
AggregationResults<ProgramIncrementBoardFeatures> aggregationResult
= mongoTemplate.aggregate(agg, "feature", ProgramIncrementBoardFeatures.class);
return aggregationResult.getUniqueMappedResult() != null ? aggregationResult.getUniqueMappedResult().features : new ArrayList<>();
}
示例2: getBacklogEstimateByKeywords
import org.springframework.data.mongodb.core.aggregation.AggregationResults; //导入方法依赖的package包/类
@Override
public Double getBacklogEstimateByKeywords(List<String> boards) {
Aggregation agg = newAggregation(
match(Criteria
.where("keywords").in(boards)
.and("sSprintAssetState").ne("ACTIVE")
.and("sTypeName").in(Arrays.asList("Story","Bug"))
.and("sStatus").nin(Arrays.asList("Accepted", "Done"))
),
group()
.sum("dEstimate")
.as("value"),
project("value")
.andExclude("_id")
);
AggregationResults<DoubleValue> groupResults
= mongoTemplate.aggregate(agg, "feature", DoubleValue.class);
DoubleValue val = groupResults.getUniqueMappedResult();
return val == null ? 0 : val.value;
}
示例3: getSprintStatsByKeywords
import org.springframework.data.mongodb.core.aggregation.AggregationResults; //导入方法依赖的package包/类
@Override
public SprintStats getSprintStatsByKeywords(List<String> boards) {
Aggregation agg = newAggregation(
match(Criteria
.where("keywords").in(boards)
.and("sSprintAssetState").is("CLOSED")
.and("sTypeName").in(Arrays.asList("Story","Bug"))
.and("sStatus").in(Arrays.asList("Accepted", "Done"))
),
group("sSprintName")
.first("sprintBeginDate").as("start")
.first("sprintEndDate").as("end")
.sum("dEstimate").as("estimate")
,
group()
.avg("estimate").as("estimateAvg")
.avg(
Ceil.ceilValueOf(
Divide.valueOf(
Subtract.valueOf("end").subtract("start")
).divideBy(3600 * 1000 * 24)
)
).as("daysDurationAvg"),
project("daysDurationAvg","estimateAvg")
.andExclude("_id")
);
AggregationResults<SprintStats> groupResults
= mongoTemplate.aggregate(agg, "feature", SprintStats.class);
return groupResults.getUniqueMappedResult();
}
示例4: getProductIncrementFromPiPattern
import org.springframework.data.mongodb.core.aggregation.AggregationResults; //导入方法依赖的package包/类
@Override
public ProgramIncrementNamesAggregationResult getProductIncrementFromPiPattern(Pattern pi) {
Aggregation agg = newAggregation(
match(Criteria
//.where("keywords").in(boards)
.where("sPiNames").is(pi)
.and("sTypeName").is("Feature")
),
project("sPiNames")
.andExclude("_id"),
unwind("sPiNames"),
group()
.addToSet("sPiNames")
.as("piNames")
);
AggregationResults<ProgramIncrementNamesAggregationResult> aggregationResult
= mongoTemplate.aggregate(agg, "feature", ProgramIncrementNamesAggregationResult.class);
return aggregationResult.getUniqueMappedResult();
}
示例5: getInvoiceFor
import org.springframework.data.mongodb.core.aggregation.AggregationResults; //导入方法依赖的package包/类
/**
* The implementation uses the MongoDB aggregation framework support Spring Data provides as well as SpEL expressions
* to define arithmetical expressions. Note how we work with property names only and don't have to mitigate the nested
* {@code $_id} fields MongoDB usually requires.
*
* @see example.springdata.mongodb.aggregation.OrderRepositoryCustom#getInvoiceFor(example.springdata.mongodb.aggregation.Order)
*/
@Override
public Invoice getInvoiceFor(Order order) {
AggregationResults<Invoice> results = operations.aggregate(newAggregation(Order.class, //
match(where("id").is(order.getId())), //
unwind("items"), //
project("id", "customerId", "items") //
.andExpression("'$items.price' * '$items.quantity'").as("lineTotal"), //
group("id") //
.sum("lineTotal").as("netAmount") //
.addToSet("items").as("items"), //
project("id", "items", "netAmount") //
.and("orderId").previousOperation() //
.andExpression("netAmount * [0]", taxRate).as("taxAmount") //
.andExpression("netAmount * (1 + [0])", taxRate).as("totalAmount") //
), Invoice.class);
return results.getUniqueMappedResult();
}
示例6: getRating
import org.springframework.data.mongodb.core.aggregation.AggregationResults; //导入方法依赖的package包/类
public double getRating(String appType, String appId) {
// mild fun with the mongodb aggregation framework...
AggregationResults<AvgRating> aggregate = mongoTemplate.aggregate(
newAggregation(
match(where("appType").is(CatalogEntryType.of(appType).toString()).and("appId").is(appId)),
group("appType", "appId").avg("rating").as("rating")
), "rating", AvgRating.class);
AvgRating uniqueMappedResult = aggregate.getUniqueMappedResult();
if (uniqueMappedResult == null) {
// there are no ratings for this app...
return 0;
}
float rating = uniqueMappedResult.getRating();
return Math.round(rating * 2) / 2.;
}
示例7: getSprintForId
import org.springframework.data.mongodb.core.aggregation.AggregationResults; //导入方法依赖的package包/类
@Override
public Sprint getSprintForId(String id, String collectorId) {
Aggregation agg = newAggregation(
match(where("sSprintID").is(id).and("collectorId").is(collectorId)),
firstSprintFields(group("sSprintID"))
.push(new BasicDBObject(FEATURE_FIELDS)).as("features")
);
AggregationResults<Sprint> aggregate =
mongoTemplate.aggregate(agg, "feature", Sprint.class);
return aggregate.getUniqueMappedResult();
}
示例8: shouldCategorizeInMultipleFacetsByPriceAndAuthor
import org.springframework.data.mongodb.core.aggregation.AggregationResults; //导入方法依赖的package包/类
/**
* Run a multi-faceted aggregation to get buckets by price (1-10, 10-50, 50-100 EURO) and by the first letter of the
* author name.
*/
@Test
@SuppressWarnings("unchecked")
public void shouldCategorizeInMultipleFacetsByPriceAndAuthor() {
Aggregation aggregation = newAggregation( //
match(Criteria.where("volumeInfo.authors").exists(true).and("volumeInfo.publisher").exists(true)),
facet() //
.and(match(Criteria.where("saleInfo.listPrice").exists(true)), //
replaceRoot("saleInfo"), //
bucket("listPrice.amount") //
.withBoundaries(1, 10, 50, 100))
.as("prices") //
.and(unwind("volumeInfo.authors"), //
replaceRoot("volumeInfo"), //
match(Criteria.where("authors").not().size(0)), //
project() //
.andExpression("substrCP(authors, 0, 1)").as("startsWith") //
.and("authors").as("author"), //
bucketAuto("startsWith", 10) //
.andOutput("author").push().as("authors") //
).as("authors"));
AggregationResults<DBObject> result = operations.aggregate(aggregation, "books", DBObject.class);
DBObject uniqueMappedResult = result.getUniqueMappedResult();
assertThat((List<Object>) uniqueMappedResult.get("prices")).hasSize(3);
assertThat((List<Object>) uniqueMappedResult.get("authors")).hasSize(8);
}
示例9: updatedSince
import org.springframework.data.mongodb.core.aggregation.AggregationResults; //导入方法依赖的package包/类
@Override
public UpdatedConversationIds updatedSince(Date date) {
//IMPLEMENTATION NOTES (Rupert Westenthaler, 2017-07-19):
// * we need to use $gte as we might get additional updates in the same ms ...
// * Instead of $max: modified we would like to use the current Server time of the
// aggregation, but this is not possible ATM (see https://jira.mongodb.org/browse/SERVER-23656)
// * The use of $gte together with lastModified menas that we will repeat reporting the
// Entities updated at lastModified on every call. To avoid this a Workaround is used
// that increases the reported lastModified time by 1ms in cases no update was done
// since the last call (meaning the parsed date equals the lastModified)
Aggregation agg = date != null ? //if a date is parsed search for updated after this date
Aggregation.newAggregation(Aggregation.match(Criteria.where("lastModified").gte(date)),
ID_MODIFIED_PROJECTION, GROUP_MODIFIED) :
//else return all updates
Aggregation.newAggregation(ID_MODIFIED_PROJECTION, GROUP_MODIFIED);
log.trace("UpdatedSince Aggregation: {}", agg);
AggregationResults<UpdatedConversationIds> aggResult = mongoTemplate.aggregate(agg,Conversation.class,
UpdatedConversationIds.class);
if(log.isTraceEnabled()){
log.trace("updated Conversations : {}", aggResult.getMappedResults());
}
if(aggResult.getUniqueMappedResult() == null){
return new UpdatedConversationIds(date, Collections.emptyList());
} else {
UpdatedConversationIds updates = aggResult.getUniqueMappedResult();
//NOTE: workaround for SERVER-23656 (see above impl. notes)
if(date != null && date.equals(updates.getLastModified())) { //no update since the last request
//increase the time by 1 ms to avoid re-indexing the last update
return new UpdatedConversationIds(new Date(date.getTime()+1), updates.ids());
} else {
return updates;
}
}
}
示例10: findExperience
import org.springframework.data.mongodb.core.aggregation.AggregationResults; //导入方法依赖的package包/类
@Override
public Experience findExperience(String consultantId, String experienceId) {
Aggregation aggregation = newAggregation(
match(where("id").is(consultantId)),
group("experiences"),
unwind(previousOperation()),
match(where(previousOperation() + "." + Fields.UNDERSCORE_ID).is(experienceId))
);
AggregationResults<Experience> aggregationResults = mongoTemplate.aggregate(aggregation, Consultant.class, Experience.class);
return aggregationResults.getUniqueMappedResult();
}
示例11: findEducation
import org.springframework.data.mongodb.core.aggregation.AggregationResults; //导入方法依赖的package包/类
@Override
public Education findEducation(String consultantId, String educationId) {
Aggregation aggregation = newAggregation(
match(where("id").is(consultantId)),
group("educationList"),
unwind(previousOperation()),
match(where(previousOperation() + "." + Fields.UNDERSCORE_ID).is(educationId))
);
AggregationResults<Education> aggregationResults = mongoTemplate.aggregate(aggregation, Consultant.class, Education.class);
return aggregationResults.getUniqueMappedResult();
}