Commit fdd8570f by Mikhail Gashenko

JsonNode: (draft10) successful push data to user's card

parent 1ccf1eb2
......@@ -10,6 +10,7 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import javax.xml.bind.DatatypeConverter;
/**
......@@ -68,6 +69,7 @@ public class APIFormsServiceSave {
connection.setRequestProperty("Accept", "application/json; charset=utf-8");
connection.setRequestProperty("Authorization", "Basic " + encoded);
connection.setRequestProperty("Connection", "Keep-Alive");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setUseCaches(true);
connection.setDoInput(true);
connection.setDoOutput(true);
......@@ -81,7 +83,7 @@ public class APIFormsServiceSave {
request.writeBytes("parentID=" + parentID);
}
request.writeBytes("&");
request.writeBytes("data=" + data);
request.writeBytes("data=" + URLEncoder.encode(data, "UTF-8"));
request.flush();
request.close();
......
......@@ -2,7 +2,7 @@ package kz.arta.synergy.astdev.custom_bp;
import java.util.List;
import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.node.ObjectNode;
//import org.codehaus.jackson.node.ObjectNode;
/**
*
......@@ -20,16 +20,18 @@ public class AsNode {
private String value;
@JsonProperty("key")
private String key;
@JsonProperty("data")
private List<AsNode> data;
@JsonProperty("formatVersion")
private String formatVersion;
@JsonProperty("manualTags")
private ObjectNode manualTags;
// @JsonProperty("formatVersion")
// private String formatVersion;
// @JsonProperty("manualTags")
// private ObjectNode manualTags;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
......@@ -37,6 +39,7 @@ public class AsNode {
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
......@@ -44,6 +47,7 @@ public class AsNode {
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
......@@ -51,13 +55,15 @@ public class AsNode {
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
//
// public void setKey(String key) {
// this.key = key;
// }
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
......@@ -65,22 +71,25 @@ public class AsNode {
public List<AsNode> getData() {
return data;
}
public void setData(List<AsNode> data) {
this.data = data;
}
public String getFormatVersion() {
return formatVersion;
}
public void setFormatVersion(String formatVersion) {
this.formatVersion = formatVersion;
}
public ObjectNode getManualTags() {
return manualTags;
}
public void setManualTags(ObjectNode manualTags) {
this.manualTags = manualTags;
}
// public String getFormatVersion() {
// return formatVersion;
// }
//
// public void setFormatVersion(String formatVersion) {
// this.formatVersion = formatVersion;
// }
//
// public ObjectNode getManualTags() {
// return manualTags;
// }
//
// public void setManualTags(ObjectNode manualTags) {
// this.manualTags = manualTags;
// }
}
}
\ No newline at end of file
......@@ -23,6 +23,7 @@ import javax.naming.NameNotFoundException;
import javax.naming.directory.AttributeModificationException;
import javax.xml.bind.DatatypeConverter;
import kz.arta.synergy.api.rest.sample.asforms.APIFormsServiceSave;
import org.codehaus.jackson.map.DeserializationConfig;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.codehaus.jackson.type.TypeReference;
......@@ -101,6 +102,13 @@ public class Main implements MessageListener {
}
}
// Configure ObjectMapper
OBJECT_MAPPER.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
// SOURCE FORM: Получение данных исходной формы (той, по которой запущен маршрут)
URL sourceFormURL = new URL(SYNERGY_ADDRESS + "/rest/api/asforms/data/" + SOURCE_FORM_DATA_UUID);
String sourceFormDataAsString = synergyApiGetString(sourceFormURL);
......@@ -115,14 +123,23 @@ public class Main implements MessageListener {
}
sourceFormData = OBJECT_MAPPER.readValue(SourceRootDataNode, new TypeReference<List<AsNode>>() {}); // map content of single root 'data' node
// TARGET FORM: Получение ID пользователя указанного в форме
String userID = getComponentValueByID(this.sourceFormData, "user1", fields.KEY);
// По ID пользователя указанного в карточке и ID формы получаем DataUUID целевой карточки (ID for work: "04f7809d-f44c-4a2d-950d-6aa8e6c3fea1")
String userCardDataUUID = getCardDataUUID(userID, TARGET_FORM_UUID);
TARGET_FORM_DATA_UUID = getCardDataUUID(userID, TARGET_FORM_UUID);
// Получение данных целевой карточки по dataUUID
URL targetFormURL = new URL(SYNERGY_ADDRESS + "/rest/api/asforms/data/" + userCardDataUUID);
TARGET_FORM_DATA_UUID = synergyApiGetString(targetFormURL);
JsonNode TargetRootNode = OBJECT_MAPPER.readTree(TARGET_FORM_DATA_UUID);
URL targetFormURL = new URL(SYNERGY_ADDRESS + "/rest/api/asforms/data/" + TARGET_FORM_DATA_UUID);
String targetFormDataAsString = synergyApiGetString(targetFormURL);
JsonNode TargetRootNode = OBJECT_MAPPER.readTree(targetFormDataAsString);
if (TargetRootNode.isNull()) {
throw new AttributeModificationException("GMP: Passed data has no JSON content");
}
......@@ -143,17 +160,14 @@ public class Main implements MessageListener {
// String t32b1, t30b1, t28b1;
// first table
String b2b1 = getComponentValueByID(this.sourceFormData, "b2-b1-b1", fields.KEY);
String b4b1 = getComponentValueByID(this.sourceFormData, "b4-b1-b1", fields.KEY);
String b2b1 = getComponentValueByID(this.sourceFormData, "b2-b1-b1", fields.VALUE);
String b4b1 = getComponentValueByID(this.sourceFormData, "b4-b1-b1", fields.VALUE);
if (!b2b1.isEmpty() && !b4b1.isEmpty()) {
updateFieldValue(this.targetFormData, "start-b1", fields.KEY, b2b1);
updateFieldValue(this.targetFormData, "finish-b1", fields.KEY, b4b1);
updateFieldValue(this.targetFormData, "start-b1", fields.VALUE, b2b1);
updateFieldValue(this.targetFormData, "finish-b1", fields.VALUE, b4b1);
updateTargetForm();
unlockRoute();
return;
}
// Second table
......@@ -173,20 +187,24 @@ public class Main implements MessageListener {
// }
// Разблокировка маршрута
unlockRoute();
} catch (Exception exc) {
LOGGER.error(exc.getMessage(), exc);
} finally {
unlockRoute();
}
}
private void updateTargetForm() throws IOException {
private void updateTargetForm() throws IOException, Exception {
// SERIALIZATION
OBJECT_MAPPER.setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL);
String serialData = OBJECT_MAPPER.writeValueAsString(targetFormData);
APIFormsServiceSave saver = new APIFormsServiceSave(LOGIN, PASSWORD, SYNERGY_ADDRESS, TARGET_FORM_UUID, TARGET_FORM_DATA_UUID, "\"data\": " + serialData);
// String login, String password, String address, String formUUID, String uuid, String data
APIFormsServiceSave saver = new APIFormsServiceSave(LOGIN, PASSWORD, SYNERGY_ADDRESS, TARGET_FORM_UUID, TARGET_FORM_DATA_UUID, "\"data\": " + serialData);
saver.save();
}
/**
......@@ -239,8 +257,7 @@ public class Main implements MessageListener {
targetNode.setLabel(newFieldValue);
break;
case KEY:
targetNode.setKey(newFieldValue);
break;
throw new AttributeModificationException("GMP: Modification of \"key\" attribute is forbidden according to specification");
case VALUE:
targetNode.setValue(newFieldValue);
break;
......
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