@Override public Set<ParentNode> createNodes(String collection, List<Map<String, Object>> records) throws IOException { InputNodeList list = new InputNodeList(); List<InputNode> inList = new ArrayList<InputNode>(); for (Map<String, Object> map : records) { InputNode node = InputNodeCreator.createInputNodeFromMap(map); if (node != null) { inList.add(node); } } WebTarget target = client.target("/nodes/nodes/generate"); Form form = new Form(); list.setInputNodeList(inList); form.param("recordValues", objectMapper.writeValueAsString(list)); Set<ParentNode> parentNodeSet = target .path("") .request() .post(Entity.form(form)) .readEntity(ParentNodeList.class) .getParentNodeList(); Set<String> ids = new HashSet<String>(); for (ParentNode parentNode : parentNodeSet) { ids.add(parentNode.getId()); } cacheDAO.addParentsToSet(collection, ids); return parentNodeSet; }
@Override public ParentNode createNode(String collection, Map<String, Object> params) throws IOException { InputNode node = InputNodeCreator.createInputNodeFromMap(params); if (node != null) { WebTarget target = client.target("/nodes/node/generate"); Form form = new Form(); form.param("recordValues", objectMapper.writeValueAsString(node)); ParentNode pNode = target.path("").request().post(Entity.form(form)).readEntity(ParentNode.class); cacheDAO.addParentToSet(collection, pNode.getId()); return pNode; } return null; }