Commit 6ebd14df by everdarkgreen

JsonNode: (draft13) adding headers to empty card

parent cdeba25a
......@@ -7,7 +7,7 @@
</packagings>
<goals>
<goal>install</goal>
<goal>checkstyle:check</goal>
</goals>
</action>
</actions>
......@@ -12,7 +12,9 @@ import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
......@@ -25,6 +27,7 @@ import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.naming.NameNotFoundException;
import javax.naming.directory.AttributeModificationException;
import javax.servlet.ServletContext;
import javax.xml.bind.DatatypeConverter;
import kz.arta.synergy.api.rest.sample.asforms.APIFormsServiceSave;
import org.codehaus.jackson.map.DeserializationConfig;
......@@ -60,7 +63,8 @@ public class Main implements MessageListener {
private static final String LOGIN = "Ипатьев";
private static final String PASSWORD = "1";
private final String TARGET_FORM_UUID = "fb44d99d-1579-4ac3-884a-01a6d4f71f9c";
// private final String TARGET_FORM_UUID = "fb44d99d-1579-4ac3-884a-01a6d4f71f9c"; // home
private final String TARGET_FORM_UUID = "04f7809d-f44c-4a2d-950d-6aa8e6c3fea1"; // work
private final String SYNERGY_ADDRESS = "http://127.0.0.1:8080/Synergy";
private String SOURCE_FORM_DATA_UUID = null; // идентификатор данных по форме записи реестра
private String TARGET_FORM_DATA_UUID = null;
......@@ -111,6 +115,8 @@ public class Main implements MessageListener {
// Configure ObjectMapper
OBJECT_MAPPER.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
constructTableHeader();
// SOURCE FORM: Получение данных исходной формы (той, по которой запущен маршрут)
URL sourceFormURL = new URL(SYNERGY_ADDRESS + "/rest/api/asforms/data/" + SOURCE_FORM_DATA_UUID);
String sourceFormDataAsString = synergyApiGetString(sourceFormURL);
......@@ -126,6 +132,9 @@ public class Main implements MessageListener {
// TARGET FORM: Получение ID пользователя указанного в форме
String userID = getComponentValueByID(this.sourceFormData, "user1", FieldType.KEY);
if (userID == null) {
throw new Exception("User in not specified in the order (value of \"user1\" field is not found)");
}
// По ID пользователя указанного в карточке и ID формы получаем DataUUID целевой карточки (ID for work: "04f7809d-f44c-4a2d-950d-6aa8e6c3fea1")
TARGET_FORM_DATA_UUID = getCardDataUUID(userID, TARGET_FORM_UUID);
// Получение данных целевой карточки по dataUUID
......@@ -143,45 +152,58 @@ public class Main implements MessageListener {
targetFormData = OBJECT_MAPPER.readValue(TargetRootDataNode, new TypeReference<List<AsNode>>() {});
// common vacation period
String dateStart = getComponentValueByID(this.sourceFormData, "date_start", FieldType.KEY);
String dateFinish = getComponentValueByID(this.sourceFormData, "date_finish", FieldType.KEY);
if (dateStart == null || dateFinish == null) {
String vacStart = getComponentValueByID(this.sourceFormData, "date_start", FieldType.KEY);
String vacEnd = getComponentValueByID(this.sourceFormData, "date_finish", FieldType.KEY);
String days = getComponentValueByID(this.sourceFormData, "days", FieldType.VALUE);
if (vacStart == null || vacEnd == null) {
throw new Exception("Vacation period is not specified");
}
// first table
// first table - periods
String b2b1 = getComponentValueByID(this.sourceFormData, "b2-b1", FieldType.KEY);
String b4b1 = getComponentValueByID(this.sourceFormData, "b4-b1", FieldType.KEY);
// first table - num of days
String b5b1 = getComponentValueByID(this.sourceFormData, "b5-b1", FieldType.VALUE);
if (notNull(b2b1, b4b1)) { // отображается key
constructNewTableRow(b2b1, b4b1, dateStart, dateFinish);
constructNewTableRow(vacStart, vacEnd, b2b1, b4b1, b5b1);
updateTargetForm();
return;
}
// second table - periods
String t4b1 = getComponentValueByID(this.sourceFormData, "t4-b1", FieldType.KEY);
String t6b1 = getComponentValueByID(this.sourceFormData, "t6-b1", FieldType.KEY);
String t10b1 = getComponentValueByID(this.sourceFormData, "t10-b1", FieldType.KEY);
String t12b1 = getComponentValueByID(this.sourceFormData, "t12-b1", FieldType.KEY);
// second table - num of days
String t2b1 = getComponentValueByID(this.sourceFormData, "t2-b1", FieldType.VALUE);
String t8b1 = getComponentValueByID(this.sourceFormData, "t8-b1", FieldType.VALUE);
if (notNull(t4b1, t6b1, t10b1, t12b1)) {
constructNewTableRow(t4b1, t6b1, dateStart, dateFinish);
constructNewTableRow(t10b1, t12b1, dateStart, dateFinish);
constructNewTableRow(vacStart, vacEnd, t4b1, t6b1, t2b1);
constructNewTableRow(vacStart, vacEnd, t10b1, t12b1, t8b1);
updateTargetForm();
return;
}
// third table - periods
String t18b1 = getComponentValueByID(this.sourceFormData, "t18-b1", FieldType.KEY);
String t20b1 = getComponentValueByID(this.sourceFormData, "t20-b1", FieldType.KEY);
String t24b1 = getComponentValueByID(this.sourceFormData, "t24-b1", FieldType.KEY);
String t26b1 = getComponentValueByID(this.sourceFormData, "t26-b1", FieldType.KEY);
String t30b1 = getComponentValueByID(this.sourceFormData, "t30-b1", FieldType.KEY);
String t32b1 = getComponentValueByID(this.sourceFormData, "t32-b1", FieldType.KEY);
// third table - num of days
String t16b1 = getComponentValueByID(this.sourceFormData, "t16-b1", FieldType.VALUE);
String t22b1 = getComponentValueByID(this.sourceFormData, "t22-b1", FieldType.VALUE);
String t28b1 = getComponentValueByID(this.sourceFormData, "t28-b1", FieldType.VALUE);
if (notNull(t18b1, t20b1, t24b1, t26b1, t30b1, t32b1)) {
constructNewTableRow(t18b1, t20b1, dateStart, dateFinish);
constructNewTableRow(t24b1, t26b1, dateStart, dateFinish);
constructNewTableRow(t30b1, t32b1, dateStart, dateFinish);
constructNewTableRow(vacStart, vacEnd, t18b1, t20b1, t16b1);
constructNewTableRow(vacStart, vacEnd, t24b1, t26b1, t22b1);
constructNewTableRow(vacStart, vacEnd, t30b1, t32b1, t28b1);
updateTargetForm();
return;
}
......@@ -193,6 +215,12 @@ public class Main implements MessageListener {
}
}
private List<AsNode> constructTableHeader() throws IOException {
InputStream inputStream = getClass().getClassLoader().getResourceAsStream("table_header.json");
List<AsNode> l = OBJECT_MAPPER.readValue(inputStream, new TypeReference<List<AsNode>>() {});
return l;
}
private static boolean notNull(Object... args) {
for (Object arg : args) {
if (arg == null) {
......@@ -202,7 +230,7 @@ public class Main implements MessageListener {
return true;
}
private void constructNewTableRow(String vacStart, String vacEnd, String perStart, String perEnd) throws Exception {
private void constructNewTableRow(String vacStart, String vacEnd, String perStart, String perEnd, String numDays) throws Exception {
AsNode tableNode = findNode(targetFormData, "table");
if (tableNode != null) {
List<AsNode> tableDataNodesList = tableNode.getData();
......@@ -231,13 +259,12 @@ public class Main implements MessageListener {
n3.setId("days-b" + tablesCounter);
n3.setType("textbox");
n3.setLabel(" ");
// n3.setValue(Integer.toString(dateDiffToDays(b2b1, b4b1)));
n3.setValue("");
n3.setValue(numDays);
n4.setId("matpom-b" + tablesCounter);
n4.setType("listbox");
n4.setValue("");
n4.setKey("1");
n4.setKey(""); // TODO: Update or not update?
n5.setId("period_start-b" + tablesCounter);
n5.setType("date");
......
[
{
"id": "cmp-9s7zv2",
"type": "label",
"label": "Дата начала "
}, {
"id": "cmp-lvooqn",
"type": "label",
"label": "Дата завершения "
}, {
"id": "cmp-dcqvt9",
"type": "label",
"label": "Количество дней"
}, {
"id": "cmp-828sd4",
"type": "label",
"label": "с выплатой материальной помощи"
}, {
"id": "jgj",
"type": "label",
"label": "Дата начала периода"
}, {
"id": "pejgjk",
"type": "label",
"label": "Дата завершения периода"
}
]
\ No newline at end of file
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