@Test public void testMergePropertiesToFeatures() throws ServiceException, IOException, SAXException { String featureSet = readResource(INPUT_FILE_PATH_MERGE_PROPERTIES_TO_FEATURES); String result = service.mergePropertiesToFeatures(featureSet, MERGE_PROPERTIES_TO_FEATURES_AGGREGATE_RESULTS, MERGE_PROPERTIES_TO_FEATURES_ROW_ORDER, MERGE_PROPERTIES_TO_FEATURES_COLUMN_ORDER); String expected = readResource(EXPECTED_FILE_PATH_MERGE_PROPERTIES_TO_FEATURES); assertXmlIsValid(expected, result); }
public String mergePropertiesToFeatures(String featureSet, String aggregateResults, List<String> rowOrder, List<String> colOrder) throws ServiceException { Map<String, Node> colvalues = new HashMap<String, Node>(); for (String col : colOrder) { colvalues.put(col, null); } final Document wpsDoc = createDoc(featureSet); try { JSONObject js = new JSONObject(aggregateResults); NodeList featureMembers = wpsDoc.getElementsByTagNameNS("*", FEATURE_MEMBER_TAG_NAME); if (featureMembers.getLength() > 0) { Iterator<?> keys = js.keys(); int cnt = 0; while (keys.hasNext()) { keys.next(); if (cnt < js.length() - 1) { Node copiedMember = wpsDoc.importNode(featureMembers.item(0), true); featureMembers.item(0).getParentNode().appendChild(copiedMember); } cnt++; } } featureMembers = wpsDoc.getElementsByTagNameNS("*", FEATURE_MEMBER_TAG_NAME); for (int i = 0; i < featureMembers.getLength(); i++) { Node featureMember = featureMembers.item(i); String nodeNameWithoutNamespace = featureMember.getNodeName() .substring(featureMember.getNodeName().indexOf(":") + 1); if (!FEATURE_MEMBER_TAG_NAME.equals(nodeNameWithoutNamespace)) { continue; } NodeList meh = featureMember.getChildNodes(); Node feature = null; for (int j = 0; j < meh.getLength(); j++) { if (meh.item(j).getNodeName().indexOf("feature:") == 0) { feature = meh.item(j); break; } } String currow = i < rowOrder.size() ? rowOrder.get(i) : null; Iterator<?> keys = js.keys(); while (keys.hasNext()) { String key = (String) keys.next(); if (js.get(key) instanceof JSONObject) { if (currow != null && key.equals(currow)) { Node elem = feature.getOwnerDocument().createElement("feature:___"); elem.setTextContent(key); feature.appendChild(elem); JSONObject subjs = js.getJSONObject(key); Iterator<?> subkeys = subjs.keys(); while (subkeys.hasNext()) { String subkey = (String) subkeys.next(); Node subelem = feature.getOwnerDocument() .createElement("feature:" + subkey.replace(" ", "_")); subelem.setTextContent(subjs.get(subkey).toString()); colvalues.put(subkey, subelem); } for (int j = 0; j < colvalues.size(); j++) { if (colvalues.get(colOrder.get(j)) != null) { feature.appendChild(colvalues.get(colOrder.get(j))); } } } } } } } catch (JSONException e) { log.debug("Aggregate feature property insertion failed", e); } return getStringFromDocument(wpsDoc); }
TransformationService { public String mergePropertiesToFeatures(String featureSet, String aggregateResults, List<String> rowOrder, List<String> colOrder) throws ServiceException { Map<String, Node> colvalues = new HashMap<String, Node>(); for (String col : colOrder) { colvalues.put(col, null); } final Document wpsDoc = createDoc(featureSet); try { JSONObject js = new JSONObject(aggregateResults); NodeList featureMembers = wpsDoc.getElementsByTagNameNS("*", FEATURE_MEMBER_TAG_NAME); if (featureMembers.getLength() > 0) { Iterator<?> keys = js.keys(); int cnt = 0; while (keys.hasNext()) { keys.next(); if (cnt < js.length() - 1) { Node copiedMember = wpsDoc.importNode(featureMembers.item(0), true); featureMembers.item(0).getParentNode().appendChild(copiedMember); } cnt++; } } featureMembers = wpsDoc.getElementsByTagNameNS("*", FEATURE_MEMBER_TAG_NAME); for (int i = 0; i < featureMembers.getLength(); i++) { Node featureMember = featureMembers.item(i); String nodeNameWithoutNamespace = featureMember.getNodeName() .substring(featureMember.getNodeName().indexOf(":") + 1); if (!FEATURE_MEMBER_TAG_NAME.equals(nodeNameWithoutNamespace)) { continue; } NodeList meh = featureMember.getChildNodes(); Node feature = null; for (int j = 0; j < meh.getLength(); j++) { if (meh.item(j).getNodeName().indexOf("feature:") == 0) { feature = meh.item(j); break; } } String currow = i < rowOrder.size() ? rowOrder.get(i) : null; Iterator<?> keys = js.keys(); while (keys.hasNext()) { String key = (String) keys.next(); if (js.get(key) instanceof JSONObject) { if (currow != null && key.equals(currow)) { Node elem = feature.getOwnerDocument().createElement("feature:___"); elem.setTextContent(key); feature.appendChild(elem); JSONObject subjs = js.getJSONObject(key); Iterator<?> subkeys = subjs.keys(); while (subkeys.hasNext()) { String subkey = (String) subkeys.next(); Node subelem = feature.getOwnerDocument() .createElement("feature:" + subkey.replace(" ", "_")); subelem.setTextContent(subjs.get(subkey).toString()); colvalues.put(subkey, subelem); } for (int j = 0; j < colvalues.size(); j++) { if (colvalues.get(colOrder.get(j)) != null) { feature.appendChild(colvalues.get(colOrder.get(j))); } } } } } } } catch (JSONException e) { log.debug("Aggregate feature property insertion failed", e); } return getStringFromDocument(wpsDoc); } }
TransformationService { public String mergePropertiesToFeatures(String featureSet, String aggregateResults, List<String> rowOrder, List<String> colOrder) throws ServiceException { Map<String, Node> colvalues = new HashMap<String, Node>(); for (String col : colOrder) { colvalues.put(col, null); } final Document wpsDoc = createDoc(featureSet); try { JSONObject js = new JSONObject(aggregateResults); NodeList featureMembers = wpsDoc.getElementsByTagNameNS("*", FEATURE_MEMBER_TAG_NAME); if (featureMembers.getLength() > 0) { Iterator<?> keys = js.keys(); int cnt = 0; while (keys.hasNext()) { keys.next(); if (cnt < js.length() - 1) { Node copiedMember = wpsDoc.importNode(featureMembers.item(0), true); featureMembers.item(0).getParentNode().appendChild(copiedMember); } cnt++; } } featureMembers = wpsDoc.getElementsByTagNameNS("*", FEATURE_MEMBER_TAG_NAME); for (int i = 0; i < featureMembers.getLength(); i++) { Node featureMember = featureMembers.item(i); String nodeNameWithoutNamespace = featureMember.getNodeName() .substring(featureMember.getNodeName().indexOf(":") + 1); if (!FEATURE_MEMBER_TAG_NAME.equals(nodeNameWithoutNamespace)) { continue; } NodeList meh = featureMember.getChildNodes(); Node feature = null; for (int j = 0; j < meh.getLength(); j++) { if (meh.item(j).getNodeName().indexOf("feature:") == 0) { feature = meh.item(j); break; } } String currow = i < rowOrder.size() ? rowOrder.get(i) : null; Iterator<?> keys = js.keys(); while (keys.hasNext()) { String key = (String) keys.next(); if (js.get(key) instanceof JSONObject) { if (currow != null && key.equals(currow)) { Node elem = feature.getOwnerDocument().createElement("feature:___"); elem.setTextContent(key); feature.appendChild(elem); JSONObject subjs = js.getJSONObject(key); Iterator<?> subkeys = subjs.keys(); while (subkeys.hasNext()) { String subkey = (String) subkeys.next(); Node subelem = feature.getOwnerDocument() .createElement("feature:" + subkey.replace(" ", "_")); subelem.setTextContent(subjs.get(subkey).toString()); colvalues.put(subkey, subelem); } for (int j = 0; j < colvalues.size(); j++) { if (colvalues.get(colOrder.get(j)) != null) { feature.appendChild(colvalues.get(colOrder.get(j))); } } } } } } } catch (JSONException e) { log.debug("Aggregate feature property insertion failed", e); } return getStringFromDocument(wpsDoc); }  }
TransformationService { public String mergePropertiesToFeatures(String featureSet, String aggregateResults, List<String> rowOrder, List<String> colOrder) throws ServiceException { Map<String, Node> colvalues = new HashMap<String, Node>(); for (String col : colOrder) { colvalues.put(col, null); } final Document wpsDoc = createDoc(featureSet); try { JSONObject js = new JSONObject(aggregateResults); NodeList featureMembers = wpsDoc.getElementsByTagNameNS("*", FEATURE_MEMBER_TAG_NAME); if (featureMembers.getLength() > 0) { Iterator<?> keys = js.keys(); int cnt = 0; while (keys.hasNext()) { keys.next(); if (cnt < js.length() - 1) { Node copiedMember = wpsDoc.importNode(featureMembers.item(0), true); featureMembers.item(0).getParentNode().appendChild(copiedMember); } cnt++; } } featureMembers = wpsDoc.getElementsByTagNameNS("*", FEATURE_MEMBER_TAG_NAME); for (int i = 0; i < featureMembers.getLength(); i++) { Node featureMember = featureMembers.item(i); String nodeNameWithoutNamespace = featureMember.getNodeName() .substring(featureMember.getNodeName().indexOf(":") + 1); if (!FEATURE_MEMBER_TAG_NAME.equals(nodeNameWithoutNamespace)) { continue; } NodeList meh = featureMember.getChildNodes(); Node feature = null; for (int j = 0; j < meh.getLength(); j++) { if (meh.item(j).getNodeName().indexOf("feature:") == 0) { feature = meh.item(j); break; } } String currow = i < rowOrder.size() ? rowOrder.get(i) : null; Iterator<?> keys = js.keys(); while (keys.hasNext()) { String key = (String) keys.next(); if (js.get(key) instanceof JSONObject) { if (currow != null && key.equals(currow)) { Node elem = feature.getOwnerDocument().createElement("feature:___"); elem.setTextContent(key); feature.appendChild(elem); JSONObject subjs = js.getJSONObject(key); Iterator<?> subkeys = subjs.keys(); while (subkeys.hasNext()) { String subkey = (String) subkeys.next(); Node subelem = feature.getOwnerDocument() .createElement("feature:" + subkey.replace(" ", "_")); subelem.setTextContent(subjs.get(subkey).toString()); colvalues.put(subkey, subelem); } for (int j = 0; j < colvalues.size(); j++) { if (colvalues.get(colOrder.get(j)) != null) { feature.appendChild(colvalues.get(colOrder.get(j))); } } } } } } } catch (JSONException e) { log.debug("Aggregate feature property insertion failed", e); } return getStringFromDocument(wpsDoc); }  String stripNamespace(final String tag); String mergePropertiesToFeatures(String featureSet, String aggregateResults, List<String> rowOrder,
            List<String> colOrder); String wpsFeatureCollectionToWfst(final String wps, String uuid, long analysis_id, List<String> fields,
            Map<String, String> fieldTypes, String geometryProperty, String ns_prefix); String getStringFromDocument(Document doc); }
TransformationService { public String mergePropertiesToFeatures(String featureSet, String aggregateResults, List<String> rowOrder, List<String> colOrder) throws ServiceException { Map<String, Node> colvalues = new HashMap<String, Node>(); for (String col : colOrder) { colvalues.put(col, null); } final Document wpsDoc = createDoc(featureSet); try { JSONObject js = new JSONObject(aggregateResults); NodeList featureMembers = wpsDoc.getElementsByTagNameNS("*", FEATURE_MEMBER_TAG_NAME); if (featureMembers.getLength() > 0) { Iterator<?> keys = js.keys(); int cnt = 0; while (keys.hasNext()) { keys.next(); if (cnt < js.length() - 1) { Node copiedMember = wpsDoc.importNode(featureMembers.item(0), true); featureMembers.item(0).getParentNode().appendChild(copiedMember); } cnt++; } } featureMembers = wpsDoc.getElementsByTagNameNS("*", FEATURE_MEMBER_TAG_NAME); for (int i = 0; i < featureMembers.getLength(); i++) { Node featureMember = featureMembers.item(i); String nodeNameWithoutNamespace = featureMember.getNodeName() .substring(featureMember.getNodeName().indexOf(":") + 1); if (!FEATURE_MEMBER_TAG_NAME.equals(nodeNameWithoutNamespace)) { continue; } NodeList meh = featureMember.getChildNodes(); Node feature = null; for (int j = 0; j < meh.getLength(); j++) { if (meh.item(j).getNodeName().indexOf("feature:") == 0) { feature = meh.item(j); break; } } String currow = i < rowOrder.size() ? rowOrder.get(i) : null; Iterator<?> keys = js.keys(); while (keys.hasNext()) { String key = (String) keys.next(); if (js.get(key) instanceof JSONObject) { if (currow != null && key.equals(currow)) { Node elem = feature.getOwnerDocument().createElement("feature:___"); elem.setTextContent(key); feature.appendChild(elem); JSONObject subjs = js.getJSONObject(key); Iterator<?> subkeys = subjs.keys(); while (subkeys.hasNext()) { String subkey = (String) subkeys.next(); Node subelem = feature.getOwnerDocument() .createElement("feature:" + subkey.replace(" ", "_")); subelem.setTextContent(subjs.get(subkey).toString()); colvalues.put(subkey, subelem); } for (int j = 0; j < colvalues.size(); j++) { if (colvalues.get(colOrder.get(j)) != null) { feature.appendChild(colvalues.get(colOrder.get(j))); } } } } } } } catch (JSONException e) { log.debug("Aggregate feature property insertion failed", e); } return getStringFromDocument(wpsDoc); }  String stripNamespace(final String tag); String mergePropertiesToFeatures(String featureSet, String aggregateResults, List<String> rowOrder,
            List<String> colOrder); String wpsFeatureCollectionToWfst(final String wps, String uuid, long analysis_id, List<String> fields,
            Map<String, String> fieldTypes, String geometryProperty, String ns_prefix); String getStringFromDocument(Document doc);  }