@Test public void importDomain_shouldImportCategoryDomainData() { databaseUtils.cleanDomain(CATEGORY); JSONArray categoriesJson = new JSONArray(); JSONObject categoryJson = getCategoryJson(); categoriesJson.add(categoryJson); loadUtils.importDomain(CATEGORY, categoriesJson); databaseUtils.assertCount(CATEGORY, 1); String categoryId = (String) categoryJson.get("itemName()"); Category category = categoryBasePersistence.getCategory(categoryId); assertThat(category, notNullValue()); assertThat(category.getCategoryId(), is((String) categoryJson.get("itemName()"))); assertThat(category.getName(), is((String) categoryJson.get("name"))); assertThat(category.getDescription(), is((String) categoryJson.get("description"))); }
public void importDomain(final Domain domain, final JSONArray jsonArray) { logger.info("Import domain[{}]: starting...", domain); List<ReplaceableItem> items = Lists.newArrayListWithCapacity(jsonArray.size()); BatchPutAttributesRequest request; int count = 0; jsonArrayLoop: for (Object o : jsonArray) { ReplaceableItem item = null; JSONObject jsonObject = (JSONObject) o; jsonObjectItemNameLoop: for (Object key : jsonObject.keySet()) { if ("itemName()".equals(key)) { item = new ReplaceableItem((String) jsonObject.get(key)); break jsonObjectItemNameLoop; } } if (item == null) { logger.warn("Cannot initialize item for JSON object[" + jsonObject.toJSONString() + "]"); break jsonArrayLoop; } jsonObjectAttributesLoop: for (Object key : jsonObject.keySet()) { if ("itemName()".equals(key)) { continue jsonObjectAttributesLoop; } String value = (String) jsonObject.get(key); if (key.equals("listPrice") || key.equals("unitCost")) { value = encodeBigDecimal(new BigDecimal(value)); } else if (key.equals("quantity")) { value = encodeInteger(new Integer(value)); } item.withAttributes(new ReplaceableAttribute((String) key, value, true)); } logger.info("Populated replaceable item[{}]", item); items.add(item); if (items.size() == BATCH_PUT_LIMIT) { request = new BatchPutAttributesRequest(getFullDomainName(domain), items); amazonSimpleDBClient.batchPutAttributes(request); count += items.size(); items.clear(); } } request = new BatchPutAttributesRequest(getFullDomainName(domain), items); amazonSimpleDBClient.batchPutAttributes(request); count += items.size(); logger.info("Imported [{}] items to domain[{}]", count, domain); }
InitialDataLoadUtils { public void importDomain(final Domain domain, final JSONArray jsonArray) { logger.info("Import domain[{}]: starting...", domain); List<ReplaceableItem> items = Lists.newArrayListWithCapacity(jsonArray.size()); BatchPutAttributesRequest request; int count = 0; jsonArrayLoop: for (Object o : jsonArray) { ReplaceableItem item = null; JSONObject jsonObject = (JSONObject) o; jsonObjectItemNameLoop: for (Object key : jsonObject.keySet()) { if ("itemName()".equals(key)) { item = new ReplaceableItem((String) jsonObject.get(key)); break jsonObjectItemNameLoop; } } if (item == null) { logger.warn("Cannot initialize item for JSON object[" + jsonObject.toJSONString() + "]"); break jsonArrayLoop; } jsonObjectAttributesLoop: for (Object key : jsonObject.keySet()) { if ("itemName()".equals(key)) { continue jsonObjectAttributesLoop; } String value = (String) jsonObject.get(key); if (key.equals("listPrice") || key.equals("unitCost")) { value = encodeBigDecimal(new BigDecimal(value)); } else if (key.equals("quantity")) { value = encodeInteger(new Integer(value)); } item.withAttributes(new ReplaceableAttribute((String) key, value, true)); } logger.info("Populated replaceable item[{}]", item); items.add(item); if (items.size() == BATCH_PUT_LIMIT) { request = new BatchPutAttributesRequest(getFullDomainName(domain), items); amazonSimpleDBClient.batchPutAttributes(request); count += items.size(); items.clear(); } } request = new BatchPutAttributesRequest(getFullDomainName(domain), items); amazonSimpleDBClient.batchPutAttributes(request); count += items.size(); logger.info("Imported [{}] items to domain[{}]", count, domain); } }
InitialDataLoadUtils { public void importDomain(final Domain domain, final JSONArray jsonArray) { logger.info("Import domain[{}]: starting...", domain); List<ReplaceableItem> items = Lists.newArrayListWithCapacity(jsonArray.size()); BatchPutAttributesRequest request; int count = 0; jsonArrayLoop: for (Object o : jsonArray) { ReplaceableItem item = null; JSONObject jsonObject = (JSONObject) o; jsonObjectItemNameLoop: for (Object key : jsonObject.keySet()) { if ("itemName()".equals(key)) { item = new ReplaceableItem((String) jsonObject.get(key)); break jsonObjectItemNameLoop; } } if (item == null) { logger.warn("Cannot initialize item for JSON object[" + jsonObject.toJSONString() + "]"); break jsonArrayLoop; } jsonObjectAttributesLoop: for (Object key : jsonObject.keySet()) { if ("itemName()".equals(key)) { continue jsonObjectAttributesLoop; } String value = (String) jsonObject.get(key); if (key.equals("listPrice") || key.equals("unitCost")) { value = encodeBigDecimal(new BigDecimal(value)); } else if (key.equals("quantity")) { value = encodeInteger(new Integer(value)); } item.withAttributes(new ReplaceableAttribute((String) key, value, true)); } logger.info("Populated replaceable item[{}]", item); items.add(item); if (items.size() == BATCH_PUT_LIMIT) { request = new BatchPutAttributesRequest(getFullDomainName(domain), items); amazonSimpleDBClient.batchPutAttributes(request); count += items.size(); items.clear(); } } request = new BatchPutAttributesRequest(getFullDomainName(domain), items); amazonSimpleDBClient.batchPutAttributes(request); count += items.size(); logger.info("Imported [{}] items to domain[{}]", count, domain); }  }
InitialDataLoadUtils { public void importDomain(final Domain domain, final JSONArray jsonArray) { logger.info("Import domain[{}]: starting...", domain); List<ReplaceableItem> items = Lists.newArrayListWithCapacity(jsonArray.size()); BatchPutAttributesRequest request; int count = 0; jsonArrayLoop: for (Object o : jsonArray) { ReplaceableItem item = null; JSONObject jsonObject = (JSONObject) o; jsonObjectItemNameLoop: for (Object key : jsonObject.keySet()) { if ("itemName()".equals(key)) { item = new ReplaceableItem((String) jsonObject.get(key)); break jsonObjectItemNameLoop; } } if (item == null) { logger.warn("Cannot initialize item for JSON object[" + jsonObject.toJSONString() + "]"); break jsonArrayLoop; } jsonObjectAttributesLoop: for (Object key : jsonObject.keySet()) { if ("itemName()".equals(key)) { continue jsonObjectAttributesLoop; } String value = (String) jsonObject.get(key); if (key.equals("listPrice") || key.equals("unitCost")) { value = encodeBigDecimal(new BigDecimal(value)); } else if (key.equals("quantity")) { value = encodeInteger(new Integer(value)); } item.withAttributes(new ReplaceableAttribute((String) key, value, true)); } logger.info("Populated replaceable item[{}]", item); items.add(item); if (items.size() == BATCH_PUT_LIMIT) { request = new BatchPutAttributesRequest(getFullDomainName(domain), items); amazonSimpleDBClient.batchPutAttributes(request); count += items.size(); items.clear(); } } request = new BatchPutAttributesRequest(getFullDomainName(domain), items); amazonSimpleDBClient.batchPutAttributes(request); count += items.size(); logger.info("Imported [{}] items to domain[{}]", count, domain); }  void importInitialDataToSimpleDB(); void importInitialDataToSimpleDB(Domain domain); JSONArray readJSONFile(final Domain domain); void importDomain(final Domain domain, final JSONArray jsonArray); }
InitialDataLoadUtils { public void importDomain(final Domain domain, final JSONArray jsonArray) { logger.info("Import domain[{}]: starting...", domain); List<ReplaceableItem> items = Lists.newArrayListWithCapacity(jsonArray.size()); BatchPutAttributesRequest request; int count = 0; jsonArrayLoop: for (Object o : jsonArray) { ReplaceableItem item = null; JSONObject jsonObject = (JSONObject) o; jsonObjectItemNameLoop: for (Object key : jsonObject.keySet()) { if ("itemName()".equals(key)) { item = new ReplaceableItem((String) jsonObject.get(key)); break jsonObjectItemNameLoop; } } if (item == null) { logger.warn("Cannot initialize item for JSON object[" + jsonObject.toJSONString() + "]"); break jsonArrayLoop; } jsonObjectAttributesLoop: for (Object key : jsonObject.keySet()) { if ("itemName()".equals(key)) { continue jsonObjectAttributesLoop; } String value = (String) jsonObject.get(key); if (key.equals("listPrice") || key.equals("unitCost")) { value = encodeBigDecimal(new BigDecimal(value)); } else if (key.equals("quantity")) { value = encodeInteger(new Integer(value)); } item.withAttributes(new ReplaceableAttribute((String) key, value, true)); } logger.info("Populated replaceable item[{}]", item); items.add(item); if (items.size() == BATCH_PUT_LIMIT) { request = new BatchPutAttributesRequest(getFullDomainName(domain), items); amazonSimpleDBClient.batchPutAttributes(request); count += items.size(); items.clear(); } } request = new BatchPutAttributesRequest(getFullDomainName(domain), items); amazonSimpleDBClient.batchPutAttributes(request); count += items.size(); logger.info("Imported [{}] items to domain[{}]", count, domain); }  void importInitialDataToSimpleDB(); void importInitialDataToSimpleDB(Domain domain); JSONArray readJSONFile(final Domain domain); void importDomain(final Domain domain, final JSONArray jsonArray);  }