@Test public void testUpdateMatchCountsForPGroup() { final String pGroupId = "section1"; dao.updateMatchCountsForPGroup(collectionId, pGroupId); final MongoCollection<Document> matchCollection = dao.getExistingCollection(collectionId); final Document query = new Document("pGroupId", pGroupId); final List<CanvasMatches> updatedMatchList = dao.getMatches(matchCollection, query, false); Assert.assertEquals("invalid number of matches returned, matches=" + updatedMatchList, 3, updatedMatchList.size()); for (final CanvasMatches canvasMatches : updatedMatchList) { final Matches matches = canvasMatches.getMatches(); final Integer expectedMatchCount = matches.getWs().length; Assert.assertEquals("match counts not updated", expectedMatchCount, canvasMatches.getMatchCount()); } }
public void updateMatchCountsForPGroup(final MatchCollectionId collectionId, final String pGroupId) { LOG.debug("updateMatchCountsForPGroup: entry, collectionId={}, pGroupId={}", collectionId, pGroupId); final ProcessTimer timer = new ProcessTimer(); final MongoCollection<Document> collection = getExistingCollection(collectionId); MongoUtil.validateRequiredParameter("pGroupId", pGroupId); final Document matchCriteria = new Document("pGroupId", pGroupId); final Document projectCriteria = new Document("_id", "$_id").append("matchCount", new Document("$size", "$matches.w")); final List<Document> pipeline = new ArrayList<>(); pipeline.add(new Document("$match", matchCriteria)); pipeline.add(new Document("$project", projectCriteria)); final List<WriteModel<Document>> modelList = new ArrayList<>(); try (final MongoCursor<Document> cursor = collection.aggregate(pipeline).iterator()) { while (cursor.hasNext()) { final Document result = cursor.next(); final Document filter = new Document("_id", result.getObjectId("_id")); final Document update = new Document("$set", new Document("matchCount", result.getInteger("matchCount"))); modelList.add(new UpdateOneModel<>(filter, update)); } } if (LOG.isDebugEnabled()) { LOG.debug("updateMatchCountsForPGroup: calculated match counts for {} pairs returned by {}.aggregate({})", modelList.size(), MongoUtil.fullName(collection), MongoUtil.toJson(pipeline)); } final BulkWriteResult result = collection.bulkWrite(modelList, MongoUtil.UNORDERED_OPTION); if (LOG.isDebugEnabled()) { final String bulkResultMessage = MongoUtil.toMessage("matches", result, modelList.size()); LOG.debug("updateMatchCountsForPGroup: {} using {}.initializeUnorderedBulkOp(), elapsedMilliseconds={}", bulkResultMessage, MongoUtil.fullName(collection), timer.getElapsedMilliseconds()); } }
MatchDao { public void updateMatchCountsForPGroup(final MatchCollectionId collectionId, final String pGroupId) { LOG.debug("updateMatchCountsForPGroup: entry, collectionId={}, pGroupId={}", collectionId, pGroupId); final ProcessTimer timer = new ProcessTimer(); final MongoCollection<Document> collection = getExistingCollection(collectionId); MongoUtil.validateRequiredParameter("pGroupId", pGroupId); final Document matchCriteria = new Document("pGroupId", pGroupId); final Document projectCriteria = new Document("_id", "$_id").append("matchCount", new Document("$size", "$matches.w")); final List<Document> pipeline = new ArrayList<>(); pipeline.add(new Document("$match", matchCriteria)); pipeline.add(new Document("$project", projectCriteria)); final List<WriteModel<Document>> modelList = new ArrayList<>(); try (final MongoCursor<Document> cursor = collection.aggregate(pipeline).iterator()) { while (cursor.hasNext()) { final Document result = cursor.next(); final Document filter = new Document("_id", result.getObjectId("_id")); final Document update = new Document("$set", new Document("matchCount", result.getInteger("matchCount"))); modelList.add(new UpdateOneModel<>(filter, update)); } } if (LOG.isDebugEnabled()) { LOG.debug("updateMatchCountsForPGroup: calculated match counts for {} pairs returned by {}.aggregate({})", modelList.size(), MongoUtil.fullName(collection), MongoUtil.toJson(pipeline)); } final BulkWriteResult result = collection.bulkWrite(modelList, MongoUtil.UNORDERED_OPTION); if (LOG.isDebugEnabled()) { final String bulkResultMessage = MongoUtil.toMessage("matches", result, modelList.size()); LOG.debug("updateMatchCountsForPGroup: {} using {}.initializeUnorderedBulkOp(), elapsedMilliseconds={}", bulkResultMessage, MongoUtil.fullName(collection), timer.getElapsedMilliseconds()); } } }
MatchDao { public void updateMatchCountsForPGroup(final MatchCollectionId collectionId, final String pGroupId) { LOG.debug("updateMatchCountsForPGroup: entry, collectionId={}, pGroupId={}", collectionId, pGroupId); final ProcessTimer timer = new ProcessTimer(); final MongoCollection<Document> collection = getExistingCollection(collectionId); MongoUtil.validateRequiredParameter("pGroupId", pGroupId); final Document matchCriteria = new Document("pGroupId", pGroupId); final Document projectCriteria = new Document("_id", "$_id").append("matchCount", new Document("$size", "$matches.w")); final List<Document> pipeline = new ArrayList<>(); pipeline.add(new Document("$match", matchCriteria)); pipeline.add(new Document("$project", projectCriteria)); final List<WriteModel<Document>> modelList = new ArrayList<>(); try (final MongoCursor<Document> cursor = collection.aggregate(pipeline).iterator()) { while (cursor.hasNext()) { final Document result = cursor.next(); final Document filter = new Document("_id", result.getObjectId("_id")); final Document update = new Document("$set", new Document("matchCount", result.getInteger("matchCount"))); modelList.add(new UpdateOneModel<>(filter, update)); } } if (LOG.isDebugEnabled()) { LOG.debug("updateMatchCountsForPGroup: calculated match counts for {} pairs returned by {}.aggregate({})", modelList.size(), MongoUtil.fullName(collection), MongoUtil.toJson(pipeline)); } final BulkWriteResult result = collection.bulkWrite(modelList, MongoUtil.UNORDERED_OPTION); if (LOG.isDebugEnabled()) { final String bulkResultMessage = MongoUtil.toMessage("matches", result, modelList.size()); LOG.debug("updateMatchCountsForPGroup: {} using {}.initializeUnorderedBulkOp(), elapsedMilliseconds={}", bulkResultMessage, MongoUtil.fullName(collection), timer.getElapsedMilliseconds()); } } MatchDao(final MongoClient client); }
MatchDao { public void updateMatchCountsForPGroup(final MatchCollectionId collectionId, final String pGroupId) { LOG.debug("updateMatchCountsForPGroup: entry, collectionId={}, pGroupId={}", collectionId, pGroupId); final ProcessTimer timer = new ProcessTimer(); final MongoCollection<Document> collection = getExistingCollection(collectionId); MongoUtil.validateRequiredParameter("pGroupId", pGroupId); final Document matchCriteria = new Document("pGroupId", pGroupId); final Document projectCriteria = new Document("_id", "$_id").append("matchCount", new Document("$size", "$matches.w")); final List<Document> pipeline = new ArrayList<>(); pipeline.add(new Document("$match", matchCriteria)); pipeline.add(new Document("$project", projectCriteria)); final List<WriteModel<Document>> modelList = new ArrayList<>(); try (final MongoCursor<Document> cursor = collection.aggregate(pipeline).iterator()) { while (cursor.hasNext()) { final Document result = cursor.next(); final Document filter = new Document("_id", result.getObjectId("_id")); final Document update = new Document("$set", new Document("matchCount", result.getInteger("matchCount"))); modelList.add(new UpdateOneModel<>(filter, update)); } } if (LOG.isDebugEnabled()) { LOG.debug("updateMatchCountsForPGroup: calculated match counts for {} pairs returned by {}.aggregate({})", modelList.size(), MongoUtil.fullName(collection), MongoUtil.toJson(pipeline)); } final BulkWriteResult result = collection.bulkWrite(modelList, MongoUtil.UNORDERED_OPTION); if (LOG.isDebugEnabled()) { final String bulkResultMessage = MongoUtil.toMessage("matches", result, modelList.size()); LOG.debug("updateMatchCountsForPGroup: {} using {}.initializeUnorderedBulkOp(), elapsedMilliseconds={}", bulkResultMessage, MongoUtil.fullName(collection), timer.getElapsedMilliseconds()); } } MatchDao(final MongoClient client); static MatchDao build(); List<MatchCollectionMetaData> getMatchCollectionMetaData(); List<String> getDistinctPGroupIds(final MatchCollectionId collectionId); List<String> getDistinctQGroupIds(final MatchCollectionId collectionId); List<String> getDistinctGroupIds(final MatchCollectionId collectionId); List<String> getMultiConsensusPGroupIds(final MatchCollectionId collectionId); Set<String> getMultiConsensusGroupIds(final MatchCollectionId collectionId); void writeMatchesWithPGroup(final MatchCollectionId collectionId,
                                       final List<MatchCollectionId> mergeCollectionIdList,
                                       final String pGroupId,
                                       final boolean excludeMatchDetails,
                                       final OutputStream outputStream); void writeMatchesWithinGroup(final MatchCollectionId collectionId,
                                        final List<MatchCollectionId> mergeCollectionIdList,
                                        final String groupId,
                                        final boolean excludeMatchDetails,
                                        final OutputStream outputStream); void writeMatchesOutsideGroup(final MatchCollectionId collectionId,
                                         final List<MatchCollectionId> mergeCollectionIdList,
                                         final String groupId,
                                         final boolean excludeMatchDetails,
                                         final OutputStream outputStream); List<CanvasMatches> getMatchesWithinGroup(final MatchCollectionId collectionId,
                                                     final String groupId,
                                                     final boolean excludeMatchDetails); List<CanvasMatches> getMatchesOutsideGroup(final MatchCollectionId collectionId,
                                                      final String groupId,
                                                      final boolean excludeMatchDetails); List<CanvasMatches> getMatchesBetweenGroups(final MatchCollectionId collectionId,
                                                       final String pGroupId,
                                                       final String qGroupId,
                                                       final boolean excludeMatchDetails); void writeMatchesBetweenGroups(final MatchCollectionId collectionId,
                                          final List<MatchCollectionId> mergeCollectionIdList,
                                          final String pGroupId,
                                          final String qGroupId,
                                          final boolean excludeMatchDetails,
                                          final OutputStream outputStream); void writeMatchesBetweenObjectAndGroup(final MatchCollectionId collectionId,
                                                  final List<MatchCollectionId> mergeCollectionIdList,
                                                  final String pGroupId,
                                                  final String pId,
                                                  final String qGroupId,
                                                  final boolean excludeMatchDetails,
                                                  final OutputStream outputStream); CanvasMatches getMatchesBetweenObjects(final MatchCollectionId collectionId,
                                                  final String pGroupId,
                                                  final String pId,
                                                  final String qGroupId,
                                                  final String qId); void writeMatchesBetweenObjects(final MatchCollectionId collectionId,
                                           final List<MatchCollectionId> mergeCollectionIdList,
                                           final String pGroupId,
                                           final String pId,
                                           final String qGroupId,
                                           final String qId,
                                           final OutputStream outputStream); void writeMatchesInvolvingObject(final MatchCollectionId collectionId,
                                            final List<MatchCollectionId> mergeCollectionIdList,
                                            final String groupId,
                                            final String id,
                                            final OutputStream outputStream); void removeMatchesInvolvingObject(final MatchCollectionId collectionId,
                                             final String groupId,
                                             final String id); void removeMatchesBetweenTiles(final MatchCollectionId collectionId,
                                          final String pGroupId,
                                          final String pId,
                                          final String qGroupId,
                                          final String qId); void removeMatchesBetweenGroups(final MatchCollectionId collectionId,
                                           final String pGroupId,
                                           final String qGroupId); void removeMatchesWithPGroup(final MatchCollectionId collectionId,
                                        final String pGroupId); void removeMatchesOutsideGroup(final MatchCollectionId collectionId,
                                          final String groupId); void saveMatches(final MatchCollectionId collectionId,
                            final List<CanvasMatches> matchesList); void removeAllMatches(final MatchCollectionId collectionId); void renameMatchCollection(final MatchCollectionId fromCollectionId,
                                      final MatchCollectionId toCollectionId); MatchTrial getMatchTrial(final String trialId); MatchTrial insertMatchTrial(final MatchTrial matchTrial); void updateMatchCountsForPGroup(final MatchCollectionId collectionId,
                                           final String pGroupId); }
MatchDao { public void updateMatchCountsForPGroup(final MatchCollectionId collectionId, final String pGroupId) { LOG.debug("updateMatchCountsForPGroup: entry, collectionId={}, pGroupId={}", collectionId, pGroupId); final ProcessTimer timer = new ProcessTimer(); final MongoCollection<Document> collection = getExistingCollection(collectionId); MongoUtil.validateRequiredParameter("pGroupId", pGroupId); final Document matchCriteria = new Document("pGroupId", pGroupId); final Document projectCriteria = new Document("_id", "$_id").append("matchCount", new Document("$size", "$matches.w")); final List<Document> pipeline = new ArrayList<>(); pipeline.add(new Document("$match", matchCriteria)); pipeline.add(new Document("$project", projectCriteria)); final List<WriteModel<Document>> modelList = new ArrayList<>(); try (final MongoCursor<Document> cursor = collection.aggregate(pipeline).iterator()) { while (cursor.hasNext()) { final Document result = cursor.next(); final Document filter = new Document("_id", result.getObjectId("_id")); final Document update = new Document("$set", new Document("matchCount", result.getInteger("matchCount"))); modelList.add(new UpdateOneModel<>(filter, update)); } } if (LOG.isDebugEnabled()) { LOG.debug("updateMatchCountsForPGroup: calculated match counts for {} pairs returned by {}.aggregate({})", modelList.size(), MongoUtil.fullName(collection), MongoUtil.toJson(pipeline)); } final BulkWriteResult result = collection.bulkWrite(modelList, MongoUtil.UNORDERED_OPTION); if (LOG.isDebugEnabled()) { final String bulkResultMessage = MongoUtil.toMessage("matches", result, modelList.size()); LOG.debug("updateMatchCountsForPGroup: {} using {}.initializeUnorderedBulkOp(), elapsedMilliseconds={}", bulkResultMessage, MongoUtil.fullName(collection), timer.getElapsedMilliseconds()); } } MatchDao(final MongoClient client); static MatchDao build(); List<MatchCollectionMetaData> getMatchCollectionMetaData(); List<String> getDistinctPGroupIds(final MatchCollectionId collectionId); List<String> getDistinctQGroupIds(final MatchCollectionId collectionId); List<String> getDistinctGroupIds(final MatchCollectionId collectionId); List<String> getMultiConsensusPGroupIds(final MatchCollectionId collectionId); Set<String> getMultiConsensusGroupIds(final MatchCollectionId collectionId); void writeMatchesWithPGroup(final MatchCollectionId collectionId,
                                       final List<MatchCollectionId> mergeCollectionIdList,
                                       final String pGroupId,
                                       final boolean excludeMatchDetails,
                                       final OutputStream outputStream); void writeMatchesWithinGroup(final MatchCollectionId collectionId,
                                        final List<MatchCollectionId> mergeCollectionIdList,
                                        final String groupId,
                                        final boolean excludeMatchDetails,
                                        final OutputStream outputStream); void writeMatchesOutsideGroup(final MatchCollectionId collectionId,
                                         final List<MatchCollectionId> mergeCollectionIdList,
                                         final String groupId,
                                         final boolean excludeMatchDetails,
                                         final OutputStream outputStream); List<CanvasMatches> getMatchesWithinGroup(final MatchCollectionId collectionId,
                                                     final String groupId,
                                                     final boolean excludeMatchDetails); List<CanvasMatches> getMatchesOutsideGroup(final MatchCollectionId collectionId,
                                                      final String groupId,
                                                      final boolean excludeMatchDetails); List<CanvasMatches> getMatchesBetweenGroups(final MatchCollectionId collectionId,
                                                       final String pGroupId,
                                                       final String qGroupId,
                                                       final boolean excludeMatchDetails); void writeMatchesBetweenGroups(final MatchCollectionId collectionId,
                                          final List<MatchCollectionId> mergeCollectionIdList,
                                          final String pGroupId,
                                          final String qGroupId,
                                          final boolean excludeMatchDetails,
                                          final OutputStream outputStream); void writeMatchesBetweenObjectAndGroup(final MatchCollectionId collectionId,
                                                  final List<MatchCollectionId> mergeCollectionIdList,
                                                  final String pGroupId,
                                                  final String pId,
                                                  final String qGroupId,
                                                  final boolean excludeMatchDetails,
                                                  final OutputStream outputStream); CanvasMatches getMatchesBetweenObjects(final MatchCollectionId collectionId,
                                                  final String pGroupId,
                                                  final String pId,
                                                  final String qGroupId,
                                                  final String qId); void writeMatchesBetweenObjects(final MatchCollectionId collectionId,
                                           final List<MatchCollectionId> mergeCollectionIdList,
                                           final String pGroupId,
                                           final String pId,
                                           final String qGroupId,
                                           final String qId,
                                           final OutputStream outputStream); void writeMatchesInvolvingObject(final MatchCollectionId collectionId,
                                            final List<MatchCollectionId> mergeCollectionIdList,
                                            final String groupId,
                                            final String id,
                                            final OutputStream outputStream); void removeMatchesInvolvingObject(final MatchCollectionId collectionId,
                                             final String groupId,
                                             final String id); void removeMatchesBetweenTiles(final MatchCollectionId collectionId,
                                          final String pGroupId,
                                          final String pId,
                                          final String qGroupId,
                                          final String qId); void removeMatchesBetweenGroups(final MatchCollectionId collectionId,
                                           final String pGroupId,
                                           final String qGroupId); void removeMatchesWithPGroup(final MatchCollectionId collectionId,
                                        final String pGroupId); void removeMatchesOutsideGroup(final MatchCollectionId collectionId,
                                          final String groupId); void saveMatches(final MatchCollectionId collectionId,
                            final List<CanvasMatches> matchesList); void removeAllMatches(final MatchCollectionId collectionId); void renameMatchCollection(final MatchCollectionId fromCollectionId,
                                      final MatchCollectionId toCollectionId); MatchTrial getMatchTrial(final String trialId); MatchTrial insertMatchTrial(final MatchTrial matchTrial); void updateMatchCountsForPGroup(final MatchCollectionId collectionId,
                                           final String pGroupId);  }