Commit 191452a7 by Mikhail Gashenko

JsonNode: working

parent a9db2f2c
......@@ -12,7 +12,7 @@ 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;
......@@ -22,12 +22,12 @@ import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;
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;
......@@ -51,20 +51,20 @@ public class Main implements MessageListener {
private static final Logger LOGGER = LoggerFactory.getLogger(Main.class);
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
private static enum ObjectType {
private enum ObjectType {
DATE, TEXTBOX, USER
}
private static enum FieldType {
private enum FieldType {
ID, TYPE, LABEL, KEY, VALUE
}
private String executionID = null; // идентификатор блокирующего процесса
private String documentID = null; // идентификатор документа реестра
private static final String LOGIN = "Ипатьев";
private static final String LOGIN = "111111";
private static final String PASSWORD = "1";
// 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 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;
......@@ -129,7 +129,7 @@ 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", FieldType.KEY);
String userID = getElemValByID(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)");
}
......@@ -150,58 +150,57 @@ public class Main implements MessageListener {
targetFormData = OBJECT_MAPPER.readValue(TargetRootDataNode, new TypeReference<List<AsNode>>() {});
// common vacation period
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);
String vacStart = getElemValByID(this.sourceFormData, "date_start", FieldType.KEY);
String vacEnd = getElemValByID(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 - periods
String b2b1 = getComponentValueByID(this.sourceFormData, "b2-b1", FieldType.KEY);
String b4b1 = getComponentValueByID(this.sourceFormData, "b4-b1", FieldType.KEY);
String b2b1 = getElemValByID(this.sourceFormData, "b2-b1", FieldType.KEY);
String b4b1 = getElemValByID(this.sourceFormData, "b4-b1", FieldType.KEY);
// first table - num of days
String b5b1 = getComponentValueByID(this.sourceFormData, "b5-b1", FieldType.VALUE);
String b5b1 = getElemValByID(this.sourceFormData, "b5-b1", FieldType.VALUE);
if (notNull(b2b1, b4b1)) { // отображается key
constructNewTableRow(vacStart, vacEnd, b2b1, b4b1, b5b1);
addTblRow(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);
String t4b1 = getElemValByID(this.sourceFormData, "t4-b1", FieldType.KEY);
String t6b1 = getElemValByID(this.sourceFormData, "t6-b1", FieldType.KEY);
String t10b1 = getElemValByID(this.sourceFormData, "t10-b1", FieldType.KEY);
String t12b1 = getElemValByID(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);
String t2b1 = getElemValByID(this.sourceFormData, "t2-b1", FieldType.VALUE);
String t8b1 = getElemValByID(this.sourceFormData, "t8-b1", FieldType.VALUE);
if (notNull(t4b1, t6b1, t10b1, t12b1)) {
constructNewTableRow(vacStart, vacEnd, t4b1, t6b1, t2b1);
constructNewTableRow(vacStart, vacEnd, t10b1, t12b1, t8b1);
addTblRow(vacStart, vacEnd, t4b1, t6b1, t2b1);
addTblRow(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);
String t18b1 = getElemValByID(this.sourceFormData, "t18-b1", FieldType.KEY);
String t20b1 = getElemValByID(this.sourceFormData, "t20-b1", FieldType.KEY);
String t24b1 = getElemValByID(this.sourceFormData, "t24-b1", FieldType.KEY);
String t26b1 = getElemValByID(this.sourceFormData, "t26-b1", FieldType.KEY);
String t30b1 = getElemValByID(this.sourceFormData, "t30-b1", FieldType.KEY);
String t32b1 = getElemValByID(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);
String t16b1 = getElemValByID(this.sourceFormData, "t16-b1", FieldType.VALUE);
String t22b1 = getElemValByID(this.sourceFormData, "t22-b1", FieldType.VALUE);
String t28b1 = getElemValByID(this.sourceFormData, "t28-b1", FieldType.VALUE);
if (notNull(t18b1, t20b1, t24b1, t26b1, t30b1, t32b1)) {
constructNewTableRow(vacStart, vacEnd, t18b1, t20b1, t16b1);
constructNewTableRow(vacStart, vacEnd, t24b1, t26b1, t22b1);
constructNewTableRow(vacStart, vacEnd, t30b1, t32b1, t28b1);
addTblRow(vacStart, vacEnd, t18b1, t20b1, t16b1);
addTblRow(vacStart, vacEnd, t24b1, t26b1, t22b1);
addTblRow(vacStart, vacEnd, t30b1, t32b1, t28b1);
updateTargetForm();
return;
}
......@@ -213,12 +212,6 @@ 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) {
......@@ -228,8 +221,14 @@ public class Main implements MessageListener {
return true;
}
private void constructNewTableRow(String vacStart, String vacEnd, String perStart, String perEnd, String numDays) throws Exception {
private void addTblRow(String vacStart, String vacEnd, String perStart, String perEnd, String numDays) throws Exception {
AsNode tableNode = findNode(targetFormData, "table");
if (tableNode == null) {
addTableHeaders();
}
tableNode = findNode(targetFormData, "table"); // update reference
if (tableNode != null) {
List<AsNode> tableDataNodesList = tableNode.getData();
String tablesCounter = Integer.toString(appendabeTableRowsCount(tableDataNodesList, "start", "b") + 1);
......@@ -286,30 +285,22 @@ public class Main implements MessageListener {
tableDataNodesList.add(n6);
tableDataNodesList.add(n7);
} else {
// get root data node, it is our target
AsNode rootDataNode = findNode(targetFormData, "data");
throw new Exception ("Failed to add new table, aborting");
}
}
private void addTableHeaders() throws IOException {
InputStream inputStream = getClass().getClassLoader().getResourceAsStream("table_header.json");
List<AsNode> headers = OBJECT_MAPPER.readValue(inputStream, new TypeReference<List<AsNode>>() {});
// construct new "table" node
AsNode newDataNode = new AsNode();
List<AsNode> header = constructTableHeader();
// pushing fields to new node
newDataNode.setId("table");
newDataNode.setType("appendable_table");
newDataNode.setKey("");
newDataNode.setData(header);
}
}
private int dateDiffToDays(String dateLess, String dateMore) throws ParseException {
Date dateMore_ = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(dateMore);
Date dateLess_ = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(dateLess);
long diff = dateMore_.getTime() - dateLess_.getTime();
TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS);
newDataNode.setData(headers);
return (int) TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS);
targetFormData.add(newDataNode);
}
private int appendabeTableRowsCount(List<AsNode> lan, String tableID, String tableElementID) {
......@@ -436,7 +427,7 @@ public class Main implements MessageListener {
* @throws NameNotFoundException
* @throws IOException
*/
private static String getComponentValueByID(List<AsNode> dataNodesList, String objectID, FieldType fieldType) throws Exception {
private static String getElemValByID(List<AsNode> dataNodesList, String objectID, FieldType fieldType) throws Exception {
String result = null;
try {
......
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