Commit ce41fc8a by everdarkgreen

JsonNode: user search working

parent d1ffe8cb
......@@ -36,8 +36,8 @@ import org.codehaus.jackson.node.ArrayNode;
public class Main implements MessageListener {
private enum fieldType {
DATE, TEXTBOX
private static enum fieldType {
DATE, TEXTBOX, USER
}
private static final Logger LOGGER = LoggerFactory.getLogger(Main.class);
......@@ -81,10 +81,16 @@ public class Main implements MessageListener {
}
}
// Получение ID пользователя
// Получение данных исходной формы
URL getFormDataURL = new URL("http://127.0.0.1:8080/Synergy/rest/api/asforms/data/" + dataUUID);
// JsonParser sourceFormData = synergyApiGet(getFormDataURL);
String sourceFormDataString = synergyApiGetString(getFormDataURL);
URL sourceFormURL = new URL("http://127.0.0.1:8080/Synergy/rest/api/asforms/data/" + dataUUID);
// JsonParser sourceFormData = synergyApiGet(sourceFormURL);
String sourceFormData = synergyApiGetString(sourceFormURL);
// Получение ID пользователя
String userID = getComponentValueByID(sourceFormData, "user1", fieldType.USER);
// Получение значений текущих дат исходной формы
String b2b1, b4b1, b5b1;
......@@ -96,11 +102,18 @@ public class Main implements MessageListener {
String t26b1, t24b1, t22b1;
String t32b1, t30b1, t28b1;
b2b1 = getDateKeyByFieldName(sourceFormDataString, "t10-b1-b1");
LOGGER.info("*** t10-b1-b1 (2017-01-31 00:00:00) *** " + b2b1);
b2b1 = getComponentValueByID(sourceFormData, "b2-b1-b1", fieldType.DATE);
b4b1 = getComponentValueByID(sourceFormData, "b4-b1", fieldType.DATE);
b5b1 = getComponentValueByID(sourceFormData, "b5-b1", fieldType.TEXTBOX);
t4b1 = getComponentValueByID(sourceFormData, "b2-b1", fieldType.DATE);
// Получение данных целевой карточки
// URL targetFormURL = new URL("http://127.0.0.1:8080/Synergy/rest/api/asforms/data/")
// String targetFormData = synergyApiGetString(sourceFormURL)
// Разблокировка маршрута""
String address = "http://127.0.0.1:8080/Synergy";
......@@ -113,29 +126,59 @@ public class Main implements MessageListener {
}
}
private static String searchInNode(Iterator<JsonNode> iter, String fieldName, fieldType ft) {
String result = new String();
// different form's component keeps data in different places
String componentType = new String();
if (ft == fieldType.DATE || ft == fieldType.USER) {
componentType = "key";
} else if (ft == fieldType.TEXTBOX) {
componentType = "value";
}
while (iter.hasNext()) {
// search data through content of child 'data' nodes
JsonNode n = iter.next();
if (n.has("id") && n.has(componentType)) {
if (fieldName.equals(n.get("id").asText())) {
result = n.get(componentType).asText();
}
}
}
return result;
}
private static String getDateKeyByFieldName(final String formJson, final String fieldName) {
private static String getComponentValueByID(final String formJson, final String fieldName, fieldType ft) {
ObjectMapper mapper = new ObjectMapper();
String result = new String();
String componentType = new String();
try {
JsonNode rootNode = mapper.readTree(formJson);
// gettint first level (root) 'data' node, there may be only two levels
ArrayNode rootDN = (ArrayNode) rootNode.get("data");
Iterator<JsonNode> rootDNIterator = rootDN.getElements();
while (rootDNIterator.hasNext()) {
ArrayNode childNode = (ArrayNode) rootDNIterator.next().get("data");
Iterator<JsonNode> childDNIterator = childNode.getElements();
while (childDNIterator.hasNext()) {
JsonNode n = childDNIterator.next();
if (n.has("id") && n.has("value")) {
if (fieldName.equals(n.get("id").asText())) {
result = n.get("value").asText();
}
result = searchInNode(rootDNIterator, fieldName, ft);
if (!result.isEmpty()) {
return result;
}
Iterator<JsonNode> rootDNIterator2 = rootDN.getElements();
while (rootDNIterator2.hasNext()) {
ArrayNode childNode = (ArrayNode) rootDNIterator2.next().get("data");
Iterator<JsonNode> childDNIterator = childNode.getElements();
result = searchInNode(childDNIterator, fieldName, ft);
if (!result.isEmpty()) {
return result;
}
}
return result;
} catch (Exception exc) {
LOGGER.error("GMP: Invalid form data");
LOGGER.error(exc.getMessage(), exc);
}
return result;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment