Commit fdd8570f by Mikhail Gashenko

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

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