@Test public void findCollectionByProcessIdTenant() throws Exception { List<String> units1 = Arrays.asList("unit1", "unit2", "unit4"); List<String> units2 = Arrays.asList("unit3", "unit4"); repository.bulkAppendReport(buildReport(units1, "procId1")); repository.bulkAppendReport(buildReport(units2, "procId2")); CloseableIterator<Document> documents = repository.findCollectionByProcessIdTenant("procId1", VitamThreadUtils.getVitamSession().getTenantId()); List<String> unitIds = Streams.stream(documents) .map(doc -> doc.getString("id")) .collect(Collectors.toList()); assertThat(unitIds).containsExactlyInAnyOrderElementsOf(units1); }
public CloseableIterator<Document> findCollectionByProcessIdTenant(String processId, int tenantId) { MongoCursor<Document> cursor = collection.aggregate( Arrays.asList( Aggregates.match(and( eq(UnitComputedInheritedRulesInvalidationModel.PROCESS_ID, processId), eq(UnitComputedInheritedRulesInvalidationModel.TENANT, tenantId) )), Aggregates.project(Projections.fields( new Document("_id", 0), new Document("id", "$_metadata.id") ) )) ) .allowDiskUse(true) .iterator(); return new CloseableIterator<Document>() { @Override public void close() { cursor.close(); } @Override public boolean hasNext() { return cursor.hasNext(); } @Override public Document next() { return cursor.next(); } }; }
UnitComputedInheritedRulesInvalidationRepository extends ReportCommonRepository { public CloseableIterator<Document> findCollectionByProcessIdTenant(String processId, int tenantId) { MongoCursor<Document> cursor = collection.aggregate( Arrays.asList( Aggregates.match(and( eq(UnitComputedInheritedRulesInvalidationModel.PROCESS_ID, processId), eq(UnitComputedInheritedRulesInvalidationModel.TENANT, tenantId) )), Aggregates.project(Projections.fields( new Document("_id", 0), new Document("id", "$_metadata.id") ) )) ) .allowDiskUse(true) .iterator(); return new CloseableIterator<Document>() { @Override public void close() { cursor.close(); } @Override public boolean hasNext() { return cursor.hasNext(); } @Override public Document next() { return cursor.next(); } }; } }
UnitComputedInheritedRulesInvalidationRepository extends ReportCommonRepository { public CloseableIterator<Document> findCollectionByProcessIdTenant(String processId, int tenantId) { MongoCursor<Document> cursor = collection.aggregate( Arrays.asList( Aggregates.match(and( eq(UnitComputedInheritedRulesInvalidationModel.PROCESS_ID, processId), eq(UnitComputedInheritedRulesInvalidationModel.TENANT, tenantId) )), Aggregates.project(Projections.fields( new Document("_id", 0), new Document("id", "$_metadata.id") ) )) ) .allowDiskUse(true) .iterator(); return new CloseableIterator<Document>() { @Override public void close() { cursor.close(); } @Override public boolean hasNext() { return cursor.hasNext(); } @Override public Document next() { return cursor.next(); } }; } @VisibleForTesting  UnitComputedInheritedRulesInvalidationRepository(MongoDbAccess mongoDbAccess, String collectionName);  UnitComputedInheritedRulesInvalidationRepository(SimpleMongoDBAccess mongoDbAccess); }
UnitComputedInheritedRulesInvalidationRepository extends ReportCommonRepository { public CloseableIterator<Document> findCollectionByProcessIdTenant(String processId, int tenantId) { MongoCursor<Document> cursor = collection.aggregate( Arrays.asList( Aggregates.match(and( eq(UnitComputedInheritedRulesInvalidationModel.PROCESS_ID, processId), eq(UnitComputedInheritedRulesInvalidationModel.TENANT, tenantId) )), Aggregates.project(Projections.fields( new Document("_id", 0), new Document("id", "$_metadata.id") ) )) ) .allowDiskUse(true) .iterator(); return new CloseableIterator<Document>() { @Override public void close() { cursor.close(); } @Override public boolean hasNext() { return cursor.hasNext(); } @Override public Document next() { return cursor.next(); } }; } @VisibleForTesting  UnitComputedInheritedRulesInvalidationRepository(MongoDbAccess mongoDbAccess, String collectionName);  UnitComputedInheritedRulesInvalidationRepository(SimpleMongoDBAccess mongoDbAccess); void bulkAppendReport(List<UnitComputedInheritedRulesInvalidationModel> reports); CloseableIterator<Document> findCollectionByProcessIdTenant(String processId, int tenantId); void deleteReportByIdAndTenant(String processId, int tenantId); }
UnitComputedInheritedRulesInvalidationRepository extends ReportCommonRepository { public CloseableIterator<Document> findCollectionByProcessIdTenant(String processId, int tenantId) { MongoCursor<Document> cursor = collection.aggregate( Arrays.asList( Aggregates.match(and( eq(UnitComputedInheritedRulesInvalidationModel.PROCESS_ID, processId), eq(UnitComputedInheritedRulesInvalidationModel.TENANT, tenantId) )), Aggregates.project(Projections.fields( new Document("_id", 0), new Document("id", "$_metadata.id") ) )) ) .allowDiskUse(true) .iterator(); return new CloseableIterator<Document>() { @Override public void close() { cursor.close(); } @Override public boolean hasNext() { return cursor.hasNext(); } @Override public Document next() { return cursor.next(); } }; } @VisibleForTesting  UnitComputedInheritedRulesInvalidationRepository(MongoDbAccess mongoDbAccess, String collectionName);  UnitComputedInheritedRulesInvalidationRepository(SimpleMongoDBAccess mongoDbAccess); void bulkAppendReport(List<UnitComputedInheritedRulesInvalidationModel> reports); CloseableIterator<Document> findCollectionByProcessIdTenant(String processId, int tenantId); void deleteReportByIdAndTenant(String processId, int tenantId);  }