@Test public void importCollection_shouldImportCategoryCollection() { JSONArray categoriesJson = new JSONArray(); JSONObject categoryJson = getCategoryJson(); categoriesJson.add(categoryJson); String collectionName = "categories"; loadUtils.importCollection(collectionName, categoriesJson); collection = database.getCollection(collectionName); assertThat(collection.count(), is((long) categoriesJson.size())); String _id = (String) categoryJson.get("_id"); DBObject categoryDBObject = collection.findOne(new BasicDBObject("_id", _id)); assertThat(categoryDBObject, notNullValue()); Category category = Category.fromDBObject(categoryDBObject); assertThat(category.getId(), is(_id)); assertThat(category.getCategoryId(), is((String) categoryJson.get("category_id"))); assertThat(category.getName(), is((String) categoryJson.get("name"))); assertThat(category.getDescription(), is((String) categoryJson.get("description"))); }
public void importCollection(final String collectionName, final JSONArray jsonArray) { logger.info("Import to collection[{}]: starting...", collectionName); collection = mongoClient.getDB(dbName).getCollection(collectionName); int count = 0; for (Object jsonObj : jsonArray) { DBObject document = (DBObject) JSON.parse(jsonObj.toString()); if (collectionName.equals("items")) { encodeBigDecimals(document); } DBObject query = new BasicDBObject("_id", document.get("_id")); if (collection.findOne(query) == null) { collection.insert(document); count++; } } logger.info("Imported [{}] documents to collection[{}]", count, collectionName); }
InitialDataLoadUtils { public void importCollection(final String collectionName, final JSONArray jsonArray) { logger.info("Import to collection[{}]: starting...", collectionName); collection = mongoClient.getDB(dbName).getCollection(collectionName); int count = 0; for (Object jsonObj : jsonArray) { DBObject document = (DBObject) JSON.parse(jsonObj.toString()); if (collectionName.equals("items")) { encodeBigDecimals(document); } DBObject query = new BasicDBObject("_id", document.get("_id")); if (collection.findOne(query) == null) { collection.insert(document); count++; } } logger.info("Imported [{}] documents to collection[{}]", count, collectionName); } }
InitialDataLoadUtils { public void importCollection(final String collectionName, final JSONArray jsonArray) { logger.info("Import to collection[{}]: starting...", collectionName); collection = mongoClient.getDB(dbName).getCollection(collectionName); int count = 0; for (Object jsonObj : jsonArray) { DBObject document = (DBObject) JSON.parse(jsonObj.toString()); if (collectionName.equals("items")) { encodeBigDecimals(document); } DBObject query = new BasicDBObject("_id", document.get("_id")); if (collection.findOne(query) == null) { collection.insert(document); count++; } } logger.info("Imported [{}] documents to collection[{}]", count, collectionName); } InitialDataLoadUtils(String dbPropertiesFile); }
InitialDataLoadUtils { public void importCollection(final String collectionName, final JSONArray jsonArray) { logger.info("Import to collection[{}]: starting...", collectionName); collection = mongoClient.getDB(dbName).getCollection(collectionName); int count = 0; for (Object jsonObj : jsonArray) { DBObject document = (DBObject) JSON.parse(jsonObj.toString()); if (collectionName.equals("items")) { encodeBigDecimals(document); } DBObject query = new BasicDBObject("_id", document.get("_id")); if (collection.findOne(query) == null) { collection.insert(document); count++; } } logger.info("Imported [{}] documents to collection[{}]", count, collectionName); } InitialDataLoadUtils(String dbPropertiesFile); void importInitialDataToMongo(); JSONArray readJSONFile(final String collectionName); void importCollection(final String collectionName, final JSONArray jsonArray); }
InitialDataLoadUtils { public void importCollection(final String collectionName, final JSONArray jsonArray) { logger.info("Import to collection[{}]: starting...", collectionName); collection = mongoClient.getDB(dbName).getCollection(collectionName); int count = 0; for (Object jsonObj : jsonArray) { DBObject document = (DBObject) JSON.parse(jsonObj.toString()); if (collectionName.equals("items")) { encodeBigDecimals(document); } DBObject query = new BasicDBObject("_id", document.get("_id")); if (collection.findOne(query) == null) { collection.insert(document); count++; } } logger.info("Imported [{}] documents to collection[{}]", count, collectionName); } InitialDataLoadUtils(String dbPropertiesFile); void importInitialDataToMongo(); JSONArray readJSONFile(final String collectionName); void importCollection(final String collectionName, final JSONArray jsonArray);  }