@Test public void testBulkReplaceUnits_bulkUpdate() throws Exception { String dataSetFile = "DataMigrationR6/30UnitDataSet/R6UnitDataSet.json"; importUnitDataSetFile(dataSetFile); Unit u1 = (Unit) MetadataCollections.UNIT.getCollection().find(eq(Unit.ID, "1")).first(); u1.put("TEST1", "VALUE1"); Unit u6 = (Unit) MetadataCollections.UNIT.getCollection().find(eq(Unit.ID, "6")).first(); u6.remove(Unit.ORIGINATING_AGENCY); u6.put("TEST6", "VALUE6"); repository.bulkReplaceUnits(Arrays.asList(u1, u6)); Unit u1_updated = (Unit) MetadataCollections.UNIT.getCollection().find(eq(Unit.ID, "1")).first(); Unit u6_updated = (Unit) MetadataCollections.UNIT.getCollection().find(eq(Unit.ID, "6")).first(); assertThat(u1_updated.get("TEST1")).isEqualTo("VALUE1"); assertThat(u6_updated.get("TEST6")).isEqualTo("VALUE6"); assertThat(u6_updated.get(Unit.ORIGINATING_AGENCY)).isNull(); }
public void bulkReplaceUnits(List<Unit> updatedUnits) { List<WriteModel<Unit>> updates = new ArrayList<>(); for (Unit unit : updatedUnits) { ReplaceOneModel<Unit> replaceOneModel = new ReplaceOneModel<>(eq(Unit.ID, unit.getId()), unit, new UpdateOptions().upsert(false)); updates.add(replaceOneModel); } MetadataCollections.UNIT.getCollection().bulkWrite(updates, new BulkWriteOptions().ordered(false)); }
DataMigrationRepository { public void bulkReplaceUnits(List<Unit> updatedUnits) { List<WriteModel<Unit>> updates = new ArrayList<>(); for (Unit unit : updatedUnits) { ReplaceOneModel<Unit> replaceOneModel = new ReplaceOneModel<>(eq(Unit.ID, unit.getId()), unit, new UpdateOptions().upsert(false)); updates.add(replaceOneModel); } MetadataCollections.UNIT.getCollection().bulkWrite(updates, new BulkWriteOptions().ordered(false)); } }
DataMigrationRepository { public void bulkReplaceUnits(List<Unit> updatedUnits) { List<WriteModel<Unit>> updates = new ArrayList<>(); for (Unit unit : updatedUnits) { ReplaceOneModel<Unit> replaceOneModel = new ReplaceOneModel<>(eq(Unit.ID, unit.getId()), unit, new UpdateOptions().upsert(false)); updates.add(replaceOneModel); } MetadataCollections.UNIT.getCollection().bulkWrite(updates, new BulkWriteOptions().ordered(false)); } DataMigrationRepository(); @VisibleForTesting  DataMigrationRepository(int bulkSize); }
DataMigrationRepository { public void bulkReplaceUnits(List<Unit> updatedUnits) { List<WriteModel<Unit>> updates = new ArrayList<>(); for (Unit unit : updatedUnits) { ReplaceOneModel<Unit> replaceOneModel = new ReplaceOneModel<>(eq(Unit.ID, unit.getId()), unit, new UpdateOptions().upsert(false)); updates.add(replaceOneModel); } MetadataCollections.UNIT.getCollection().bulkWrite(updates, new BulkWriteOptions().ordered(false)); } DataMigrationRepository(); @VisibleForTesting  DataMigrationRepository(int bulkSize); CloseableIterator<List<Unit>> selectUnitBulkInTopDownHierarchyLevel(); Map<String, Unit> getUnitGraphByIds(Collection<String> unitIds); void bulkReplaceUnits(List<Unit> updatedUnits); CloseableIterator<List<String>> selectObjectGroupBulk(); void bulkUpgradeObjectGroups(List<String> objectGroupIds); }
DataMigrationRepository { public void bulkReplaceUnits(List<Unit> updatedUnits) { List<WriteModel<Unit>> updates = new ArrayList<>(); for (Unit unit : updatedUnits) { ReplaceOneModel<Unit> replaceOneModel = new ReplaceOneModel<>(eq(Unit.ID, unit.getId()), unit, new UpdateOptions().upsert(false)); updates.add(replaceOneModel); } MetadataCollections.UNIT.getCollection().bulkWrite(updates, new BulkWriteOptions().ordered(false)); } DataMigrationRepository(); @VisibleForTesting  DataMigrationRepository(int bulkSize); CloseableIterator<List<Unit>> selectUnitBulkInTopDownHierarchyLevel(); Map<String, Unit> getUnitGraphByIds(Collection<String> unitIds); void bulkReplaceUnits(List<Unit> updatedUnits); CloseableIterator<List<String>> selectObjectGroupBulk(); void bulkUpgradeObjectGroups(List<String> objectGroupIds);  }