Commit cdeba25a by everdarkgreen

JsonNode: (draft12) production adaptation

parent 34167fae
<?xml version="1.0" encoding="UTF-8"?>
<project-shared-configuration>
<!--
This file contains additional configuration written by modules in the NetBeans IDE.
The configuration is intended to be shared among all the users of project and
therefore it is assumed to be part of version control checkout.
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
-->
<libraries xmlns="http://www.netbeans.org/ns/cdnjs-libraries/1"/>
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
<!--
Properties that influence various parts of the IDE, especially code formatting and the like.
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
That way multiple projects can share the same settings (useful for formatting rules for example).
Any value defined here will override the pom.xml file value but is only applicable to the current project.
-->
<org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_j2eeVersion>1.6-web</org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_j2eeVersion>
<org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>JBoss4</org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>
<netbeans.hint.jdkPlatform>JDK_1.7</netbeans.hint.jdkPlatform>
<org-netbeans-modules-css-prep.less_2e_mappings>/less:/css</org-netbeans-modules-css-prep.less_2e_mappings>
<org-netbeans-modules-css-prep.less_2e_enabled>false</org-netbeans-modules-css-prep.less_2e_enabled>
<org-netbeans-modules-css-prep.sass_2e_enabled>false</org-netbeans-modules-css-prep.sass_2e_enabled>
<org-netbeans-modules-css-prep.sass_2e_compiler_2e_options/>
<org-netbeans-modules-css-prep.less_2e_compiler_2e_options/>
<org-netbeans-modules-css-prep.sass_2e_mappings>/scss:/css</org-netbeans-modules-css-prep.sass_2e_mappings>
<org-netbeans-modules-web-clientproject-api.js_2e_libs_2e_folder>js/libs</org-netbeans-modules-web-clientproject-api.js_2e_libs_2e_folder>
<org-netbeans-modules-javascript2-requirejs.enabled>true</org-netbeans-modules-javascript2-requirejs.enabled>
</properties>
</project-shared-configuration>
<?xml version="1.0" encoding="UTF-8"?>
<actions>
<action>
<actionName>build</actionName>
<packagings>
<packaging>*</packaging>
</packagings>
<goals>
<goal>install</goal>
<goal>checkstyle:check</goal>
</goals>
</action>
</actions>
...@@ -104,8 +104,9 @@ ...@@ -104,8 +104,9 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId> <artifactId>maven-checkstyle-plugin</artifactId>
<version>${maven.checkstyle.plugin.version}</version>
<configuration> <configuration>
<configLocation>config/sun_checks.xml</configLocation> <configLocation>config/google_checks.xml</configLocation>
</configuration> </configuration>
</plugin> </plugin>
</plugins> </plugins>
......
package kz.arta.synergy.astdev.custom_bp; package kz.arta.synergy.astdev.custom_bp;
import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.core.JsonToken;
import org.codehaus.jackson.JsonNode; import org.codehaus.jackson.JsonNode;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import javax.jms.Message; import javax.jms.Message;
import javax.jms.MessageListener; import javax.jms.MessageListener;
import javax.jms.TextMessage; import javax.jms.TextMessage;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
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.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.ejb.ActivationConfigProperty; import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven; import javax.ejb.MessageDriven;
import javax.naming.NameNotFoundException; 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.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;
/** /**
* *
* @author drpsy * @author drpsy
*/ */
@MessageDriven(name = "CustomBP", activationConfig = { @MessageDriven(name = "CustomBP", activationConfig = {
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"), @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName = "destination", propertyValue = "java:jboss/queues/Integration/CustomBP"), @ActivationConfigProperty(propertyName = "destination", propertyValue = "java:jboss/queues/Integration/CustomBP"),
@ActivationConfigProperty(propertyName = "reconnectAttempts", propertyValue = "32"), @ActivationConfigProperty(propertyName = "reconnectAttempts", propertyValue = "32"),
@ActivationConfigProperty(propertyName = "reconnectInterval", propertyValue = "4000"), @ActivationConfigProperty(propertyName = "reconnectInterval", propertyValue = "4000"),
@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge")}) @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge")})
public class Main implements MessageListener { public class Main implements MessageListener {
private static final Logger LOGGER = LoggerFactory.getLogger(Main.class); private static final Logger LOGGER = LoggerFactory.getLogger(Main.class);
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
private static enum ObjectType { private static enum ObjectType {
DATE, TEXTBOX, USER DATE, TEXTBOX, USER
} }
private static enum FieldType { private static enum FieldType {
ID, TYPE, LABEL, KEY, VALUE ID, TYPE, LABEL, KEY, VALUE
} }
private String executionID = null; // идентификатор блокирующего процесса private String executionID = null; // идентификатор блокирующего процесса
private String documentID = null; // идентификатор документа реестра private String documentID = null; // идентификатор документа реестра
private static final String LOGIN = "111111"; private static final String LOGIN = "Ипатьев";
private static final String PASSWORD = "1"; 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";
private final String SYNERGY_ADDRESS = "http://127.0.0.1:8080/Synergy"; private final String SYNERGY_ADDRESS = "http://127.0.0.1:8080/Synergy";
private String SOURCE_FORM_DATA_UUID = null; // идентификатор данных по форме записи реестра private String SOURCE_FORM_DATA_UUID = null; // идентификатор данных по форме записи реестра
private String TARGET_FORM_DATA_UUID = null; private String TARGET_FORM_DATA_UUID = null;
@JsonSerialize(using = AsNodeSerializer.class) @JsonSerialize(using = AsNodeSerializer.class)
private List<AsNode> sourceFormData = null; private List<AsNode> sourceFormData = null;
@JsonSerialize(using = AsNodeSerializer.class) @JsonSerialize(using = AsNodeSerializer.class)
private List<AsNode> targetFormData = null; private List<AsNode> targetFormData = null;
/** /**
* *
* @param message * @param message
*/ */
@Override @Override
public void onMessage(Message message) { public void onMessage(Message message) {
// <editor-fold defaultstate="collapsed" desc=" DESCRIPTION "> // <editor-fold defaultstate="collapsed" desc=" DESCRIPTION ">
if (!(message instanceof TextMessage)) { if (!(message instanceof TextMessage)) {
return; return;
} }
try { try {
JsonFactory factory = new JsonFactory(); JsonFactory factory = new JsonFactory();
JsonParser parser = factory.createParser(((TextMessage) message).getText()); JsonParser parser = factory.createParser(((TextMessage) message).getText());
JsonToken token = null; JsonToken token = null;
while ((token = parser.nextToken()) != null) { while ((token = parser.nextToken()) != null) {
if (token == JsonToken.FIELD_NAME) { if (token == JsonToken.FIELD_NAME) {
String fieldName = parser.getText(); String fieldName = parser.getText();
parser.nextToken(); parser.nextToken();
String value = parser.getText(); String value = parser.getText();
switch (fieldName) { switch (fieldName) {
case "dataUUID": case "dataUUID":
SOURCE_FORM_DATA_UUID = value; SOURCE_FORM_DATA_UUID = value;
break; break;
case "executionID": case "executionID":
executionID = value; executionID = value;
break; break;
case "documentID": case "documentID":
documentID = value; documentID = value;
break; break;
default: default:
break; break;
} }
} }
} }
// </editor-fold> // </editor-fold>
// Configure ObjectMapper // Configure ObjectMapper
OBJECT_MAPPER.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); 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);
JsonNode SourceRootNode = OBJECT_MAPPER.readTree(sourceFormDataAsString); // read the whole tree JsonNode SourceRootNode = OBJECT_MAPPER.readTree(sourceFormDataAsString); // read the whole tree
if (SourceRootNode.isNull()) { if (SourceRootNode.isNull()) {
throw new AttributeModificationException("GMP: Passed data has no JSON content"); throw new AttributeModificationException("GMP: Passed data has no JSON content");
} }
JsonNode SourceRootDataNode = SourceRootNode.get("data"); // read single root 'data' node JsonNode SourceRootDataNode = SourceRootNode.get("data"); // read single root 'data' node
if (SourceRootDataNode == null) { if (SourceRootDataNode == null) {
throw new AttributeModificationException("GMP: Invalid form data, root \"data\" node does not exists"); throw new AttributeModificationException("GMP: Invalid form data, root \"data\" node does not exists");
} }
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", FieldType.KEY); String userID = getComponentValueByID(this.sourceFormData, "user1", FieldType.KEY);
// По ID пользователя указанного в карточке и ID формы получаем DataUUID целевой карточки (ID for work: "04f7809d-f44c-4a2d-950d-6aa8e6c3fea1") // По ID пользователя указанного в карточке и ID формы получаем DataUUID целевой карточки (ID for work: "04f7809d-f44c-4a2d-950d-6aa8e6c3fea1")
TARGET_FORM_DATA_UUID = 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/" + TARGET_FORM_DATA_UUID); URL targetFormURL = new URL(SYNERGY_ADDRESS + "/rest/api/asforms/data/" + TARGET_FORM_DATA_UUID);
String targetFormDataAsString = synergyApiGetString(targetFormURL); String targetFormDataAsString = synergyApiGetString(targetFormURL);
JsonNode TargetRootNode = OBJECT_MAPPER.readTree(targetFormDataAsString); 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");
} }
JsonNode TargetRootDataNode = TargetRootNode.get("data"); JsonNode TargetRootDataNode = TargetRootNode.get("data");
if (TargetRootDataNode == null) { if (TargetRootDataNode == null) {
throw new AttributeModificationException("GMP: Invalid form data, root \"data\" node does not exists"); throw new AttributeModificationException("GMP: Invalid form data, root \"data\" node does not exists");
} }
targetFormData = OBJECT_MAPPER.readValue(TargetRootDataNode, new TypeReference<List<AsNode>>() {}); targetFormData = OBJECT_MAPPER.readValue(TargetRootDataNode, new TypeReference<List<AsNode>>() {});
// Получение значений текущих дат исходной формы // common vacation period
String b5b1; String dateStart = getComponentValueByID(this.sourceFormData, "date_start", FieldType.KEY);
String dateFinish = getComponentValueByID(this.sourceFormData, "date_finish", FieldType.KEY);
String t2b1; if (dateStart == null || dateFinish == null) {
String t8b1; throw new Exception("Vacation period is not specified");
}
// String t18b1, t20b1, t16b1;
// String t26b1, t24b1, t22b1; // first table
// String t32b1, t30b1, t28b1; String b2b1 = getComponentValueByID(this.sourceFormData, "b2-b1", FieldType.KEY);
String b4b1 = getComponentValueByID(this.sourceFormData, "b4-b1", FieldType.KEY);
// first table
String b2b1 = getComponentValueByID(this.sourceFormData, "b2-b1-b1", FieldType.KEY); if (notNull(b2b1, b4b1)) { // отображается key
String b4b1 = getComponentValueByID(this.sourceFormData, "b4-b1-b1", FieldType.KEY); constructNewTableRow(b2b1, b4b1, dateStart, dateFinish);
updateTargetForm();
if (b2b1 == null || b4b1 == null) { // отображается key return;
throw new Exception ("Source date fields is empty"); }
} else {
constructNewTableRow(b2b1, b4b1); String t4b1 = getComponentValueByID(this.sourceFormData, "t4-b1", FieldType.KEY);
updateTargetForm(); 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);
if (notNull(t4b1, t6b1, t10b1, t12b1)) {
// boolean key_b2b1 = false, key_b4b1 = false, val_b2b1 = false, val_b4b1 = false; constructNewTableRow(t4b1, t6b1, dateStart, dateFinish);
// if (!b2b1.isEmpty() && !b4b1.isEmpty()) { // do not update with empty values constructNewTableRow(t10b1, t12b1, dateStart, dateFinish);
// key_b2b1 = updateFieldValue(this.targetFormData, "start-b1", FieldType.KEY, b2b1); updateTargetForm();
// key_b4b1 = updateFieldValue(this.targetFormData, "finish-b1", FieldType.KEY, b4b1); return;
// val_b2b1 = updateFieldValue(this.targetFormData, "start-b1", FieldType.VALUE, dateValueFromKey(b2b1)); }
// val_b4b1 = updateFieldValue(this.targetFormData, "finish-b1", FieldType.VALUE, dateValueFromKey(b4b1));
// } String t18b1 = getComponentValueByID(this.sourceFormData, "t18-b1", FieldType.KEY);
// String t20b1 = getComponentValueByID(this.sourceFormData, "t20-b1", FieldType.KEY);
// if (key_b2b1 && key_b4b1 && val_b2b1 && val_b4b1) { String t24b1 = getComponentValueByID(this.sourceFormData, "t24-b1", FieldType.KEY);
// updateTargetForm(); 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);
if (notNull(t18b1, t20b1, t24b1, t26b1, t30b1, t32b1)) {
// Second table constructNewTableRow(t18b1, t20b1, dateStart, dateFinish);
// String t4b1 = getComponentValueByID(sourceFormData, "t2-b1", ObjectType.DATE); constructNewTableRow(t24b1, t26b1, dateStart, dateFinish);
// String t6b1 = getComponentValueByID(sourceFormData, "b6-b1", ObjectType.DATE); constructNewTableRow(t30b1, t32b1, dateStart, dateFinish);
// String t10b1 = getComponentValueByID(sourceFormData, "t10-b1", ObjectType.DATE); updateTargetForm();
// String t12b1 = getComponentValueByID(sourceFormData, "t12-b1", ObjectType.DATE); return;
// }
// if (!t4b1.isEmpty() && !t6b1.isEmpty() && !t10b1.isEmpty() && !t12b1.isEmpty()) {
// setComponentValueByID(targetFormData, "start-b1", "key", b2b1); } catch (Exception exc) {
// setComponentValueByID(targetFormData, "start-b1", "key", b2b1); LOGGER.error(exc.getMessage(), exc);
// setComponentValueByID(targetFormData, "start-b1", "key", b2b1); } finally {
// setComponentValueByID(targetFormData, "start-b1", "key", b2b1); unlockRoute(); // Разблокировка маршрута
// }
// unlockRoute(); }
// return;
// } private static boolean notNull(Object... args) {
for (Object arg : args) {
// Разблокировка маршрута if (arg == null) {
return false;
}
} catch (Exception exc) { }
LOGGER.error(exc.getMessage(), exc); return true;
} finally { }
unlockRoute();
} private void constructNewTableRow(String vacStart, String vacEnd, String perStart, String perEnd) throws Exception {
} AsNode tableNode = findNode(targetFormData, "table");
if (tableNode != null) {
private void constructNewTableRow(String b2b1, String b4b1) throws Exception { List<AsNode> tableDataNodesList = tableNode.getData();
AsNode tableNode = findNode(targetFormData, "table"); String tablesCounter = Integer.toString(appendabeTableRowsCount(tableDataNodesList, "start", "b") + 1);
if (tableNode != null) {
List<AsNode> tableDataNodesList = tableNode.getData(); AsNode n1 = new AsNode();
String tablesCounter = Integer.toString(appendabeTableRowsCount(tableDataNodesList, "start", "b") + 1); AsNode n2 = new AsNode();
AsNode n3 = new AsNode();
AsNode n1 = new AsNode(); AsNode n4 = new AsNode();
AsNode n2 = new AsNode(); AsNode n5 = new AsNode();
AsNode n3 = new AsNode(); AsNode n6 = new AsNode();
AsNode n4 = new AsNode(); AsNode n7 = new AsNode();
AsNode n5 = new AsNode();
AsNode n6 = new AsNode(); n1.setId("start-b" + tablesCounter);
AsNode n7 = new AsNode(); n1.setType("date");
n1.setLabel(" ");
n1.setId("start-b" + tablesCounter); n1.setValue(dateValueFromKey(vacStart));
n1.setType("date"); n1.setKey(vacStart);
n1.setLabel(" ");
n1.setValue(dateValueFromKey(b2b1)); n2.setId("finish-b" + tablesCounter);
n1.setKey(b2b1); n2.setType("date");
n2.setLabel(" ");
n2.setId("finish-b" + tablesCounter); n2.setValue(dateValueFromKey(vacEnd));
n2.setType("date"); n2.setKey(vacEnd);
n2.setLabel(" ");
n2.setValue(dateValueFromKey(b4b1)); n3.setId("days-b" + tablesCounter);
n2.setKey(b4b1); n3.setType("textbox");
n3.setLabel(" ");
n3.setId("days-b" + tablesCounter); // n3.setValue(Integer.toString(dateDiffToDays(b2b1, b4b1)));
n3.setType("textbox"); n3.setValue("");
n3.setLabel(" ");
n3.setValue(Integer.toString(dateDiffToDays(b2b1, b4b1))); n4.setId("matpom-b" + tablesCounter);
n4.setType("listbox");
n4.setId("matpom-b" + tablesCounter); n4.setValue("");
n4.setType("listbox"); n4.setKey("1");
n4.setValue("");
n4.setKey("1"); n5.setId("period_start-b" + tablesCounter);
n5.setType("date");
n5.setId("period_start-b" + tablesCounter); n5.setValue(dateValueFromKey(perStart));
n5.setType("date"); n5.setKey(perStart);
n6.setId("period_finish-b" + tablesCounter); n6.setId("period_finish-b" + tablesCounter);
n6.setType("date"); n6.setType("date");
n6.setValue(dateValueFromKey(perEnd));
n7.setId("otozvano-b" + tablesCounter); n6.setKey(perEnd);
n7.setType("texbox");
n7.setLabel(" "); n7.setId("otozvano-b" + tablesCounter);
n7.setType("texbox");
tableDataNodesList.add(n1); n7.setLabel(" ");
tableDataNodesList.add(n2);
tableDataNodesList.add(n3); tableDataNodesList.add(n1);
tableDataNodesList.add(n4); tableDataNodesList.add(n2);
tableDataNodesList.add(n5); tableDataNodesList.add(n3);
tableDataNodesList.add(n6); tableDataNodesList.add(n4);
tableDataNodesList.add(n7); tableDataNodesList.add(n5);
} tableDataNodesList.add(n6);
} tableDataNodesList.add(n7);
}
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); private int dateDiffToDays(String dateLess, String dateMore) throws ParseException {
Date dateMore_ = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(dateMore);
long diff = dateMore_.getTime() - dateLess_.getTime(); Date dateLess_ = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(dateLess);
TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS);
long diff = dateMore_.getTime() - dateLess_.getTime();
return (int) TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS); TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS);
}
return (int) TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS);
private int appendabeTableRowsCount(List<AsNode> lan, String tableID, String tableElementID) { }
int counter = 0;
for (;;) { private int appendabeTableRowsCount(List<AsNode> lan, String tableID, String tableElementID) {
String searchString = tableID + "-" + tableElementID + Integer.toString(counter + 1); int counter = 0;
AsNode n = findNode(lan, searchString); for (;;) {
if (n == null) { String searchString = tableID + "-" + tableElementID + Integer.toString(counter + 1);
break; AsNode n = findNode(lan, searchString);
} else { if (n == null) {
counter++; break;
} } else {
} counter++;
return counter; }
} }
return counter;
private void updateTargetForm() throws IOException, Exception { }
// SERIALIZATION
OBJECT_MAPPER.setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL); private void updateTargetForm() throws IOException, Exception {
String serialData = OBJECT_MAPPER.writeValueAsString(targetFormData); // SERIALIZATION
OBJECT_MAPPER.setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL);
// String login, String password, String address, String formUUID, String uuid, String data String serialData = OBJECT_MAPPER.writeValueAsString(targetFormData);
APIFormsServiceSave saver = new APIFormsServiceSave(LOGIN, PASSWORD, SYNERGY_ADDRESS, TARGET_FORM_UUID, TARGET_FORM_DATA_UUID, "\"data\": " + serialData);
saver.save(); // 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();
/** }
* Returns node which has specifies ID
* @param nodesList - List of nodes /**
* @param objectID - Component ID * Returns node which has specifies ID
* @return AsNode if such exists, null otherwise * @param nodesList - List of nodes
*/ * @param objectID - Component ID
private static AsNode findNode(List<AsNode> nodesList, String objectID) { * @return AsNode if such exists, null otherwise
AsNode result = null; */
private static AsNode findNode(List<AsNode> nodesList, String objectID) {
for (AsNode n : nodesList) { AsNode result = null;
if (result != null) break; // prevent relooping if result has already been found
for (AsNode n : nodesList) {
if (objectID.equals(n.getId())) { if (result != null) break; // prevent relooping if result has already been found
result = n;
} else if (n.getData() != null) { if (objectID.equals(n.getId())) {
result = findNode(n.getData(), objectID); result = n;
} } else if (n.getData() != null) {
} result = findNode(n.getData(), objectID);
}
return result; }
}
return result;
private static String dateValueFromKey (String keyValue) throws ParseException { }
Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(keyValue);
return new SimpleDateFormat("dd.MM.yyy").format(date); private static String dateValueFromKey (String keyValue) throws ParseException {
} Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(keyValue);
return new SimpleDateFormat("dd.MM.yyy").format(date);
/** }
* Setting new value of requested field of requested component with specified ID
* @param targetJsonAsString /**
* @param objectID * Setting new value of requested field of requested component with specified ID
* @param fieldType * @param targetJsonAsString
* @param newFieldValue * @param objectID
* @throws AttributeModificationException * @param fieldType
* @throws IOException * @param newFieldValue
*/ * @throws AttributeModificationException
private boolean updateFieldValue (List<AsNode> dataNodesList, String objectID, FieldType fieldType, String newFieldValue) { * @throws IOException
try { */
AsNode targetNode = findNode(dataNodesList, objectID); private boolean updateFieldValue (List<AsNode> dataNodesList, String objectID, FieldType fieldType, String newFieldValue) {
if (targetNode == null) { try {
return false; AsNode targetNode = findNode(dataNodesList, objectID);
} else { if (targetNode == null) {
switch (fieldType) { return false;
case ID: } else {
targetNode.setId(newFieldValue); switch (fieldType) {
break; case ID:
case TYPE: targetNode.setId(newFieldValue);
targetNode.setType(newFieldValue); break;
break; case TYPE:
case LABEL: targetNode.setType(newFieldValue);
targetNode.setLabel(newFieldValue); break;
break; case LABEL:
case KEY: targetNode.setLabel(newFieldValue);
targetNode.setKey(newFieldValue); break;
break; case KEY:
case VALUE: targetNode.setKey(newFieldValue);
targetNode.setValue(newFieldValue); break;
break; case VALUE:
} targetNode.setValue(newFieldValue);
} break;
return true; }
} catch (Exception e) { }
throw e; return true;
} } catch (Exception e) {
} throw e;
}
/** }
* Returns user's card data UUID by form's UUID
* @param userID - User identifier /**
* @param formUUID - Form's data UUID * Returns user's card data UUID by form's UUID
* @return Specified user's card data UUID * @param userID - User identifier
*/ * @param formUUID - Form's data UUID
private static String getCardDataUUID (String userID, String formUUID) { * @return Specified user's card data UUID
ObjectMapper mapper = new ObjectMapper(); */
try { private static String getCardDataUUID (String userID, String formUUID) {
URL url = new URL("http://127.0.0.1:8080/Synergy/rest/api/personalrecord/forms/" + userID); ObjectMapper mapper = new ObjectMapper();
String res = synergyApiGetString(url); try {
URL url = new URL("http://127.0.0.1:8080/Synergy/rest/api/personalrecord/forms/" + userID);
List<Card> cardsList = mapper.readValue(res, new TypeReference<List<Card>>(){}); String res = synergyApiGetString(url);
for (Card c : cardsList) { List<Card> cardsList = mapper.readValue(res, new TypeReference<List<Card>>(){});
if (formUUID.equals(c.getFormUUID())) {
return c.getDataUUID(); for (Card c : cardsList) {
} if (formUUID.equals(c.getFormUUID())) {
} return c.getDataUUID();
} catch (Exception exc) { }
LOGGER.error(exc.getMessage(), exc); }
} } catch (Exception exc) {
return new String(); LOGGER.error(exc.getMessage(), exc);
} }
return new String();
/** }
* Returns value of of specified field of component with specified ID
* @param targetJsonAsString /**
* @param objectID * Returns value of of specified field of component with specified ID
* @param fieldType * @param targetJsonAsString
* @return * @param objectID
* @throws NameNotFoundException * @param fieldType
* @throws IOException * @return
*/ * @throws NameNotFoundException
private static String getComponentValueByID(List<AsNode> dataNodesList, String objectID, FieldType fieldType) throws Exception { * @throws IOException
String result = null; */
try { private static String getComponentValueByID(List<AsNode> dataNodesList, String objectID, FieldType fieldType) throws Exception {
String result = null;
AsNode targetNode = findNode(dataNodesList, objectID); try {
if (targetNode == null) {
return null; AsNode targetNode = findNode(dataNodesList, objectID);
} else { if (targetNode == null) {
switch (fieldType) { return null;
case ID: } else {
result = targetNode.getId(); // may be for cheking if component with such ID exists at all switch (fieldType) {
break; case ID:
case TYPE: result = targetNode.getId(); // may be for cheking if component with such ID exists at all
result = targetNode.getType(); break;
break; case TYPE:
case LABEL: result = targetNode.getType();
result = targetNode.getLabel(); break;
break; case LABEL:
case KEY: result = targetNode.getLabel();
result = targetNode.getKey(); break;
break; case KEY:
case VALUE: result = targetNode.getKey();
result = targetNode.getValue(); break;
break; case VALUE:
} result = targetNode.getValue();
} break;
return result; }
} catch (Exception e) { }
throw e; return result;
} } catch (Exception e) {
throw e;
} }
/** }
* Route unlocking
*/ /**
private void unlockRoute() { * Route unlocking
try { */
String address = "http://127.0.0.1:8080/Synergy"; private void unlockRoute() {
String signal = "got_agree"; try {
URL url = new URL(address + "/rest/api/processes/signal?signal=" + signal + "&executionID=" + this.executionID + "&param1=resolution&value1=signal_is_" + signal); String address = "http://127.0.0.1:8080/Synergy";
synergyApiGetString(url); String signal = "got_agree";
} catch (Exception exc) { URL url = new URL(address + "/rest/api/processes/signal?signal=" + signal + "&executionID=" + this.executionID + "&param1=resolution&value1=signal_is_" + signal);
LOGGER.error(exc.getMessage(), exc); synergyApiGetString(url);
} } catch (Exception exc) {
} LOGGER.error(exc.getMessage(), exc);
}
private static String synergyApiGetString(final URL requestURL) { }
try {
String output; private static String synergyApiGetString(final URL requestURL) {
try {
HttpURLConnection conn = (HttpURLConnection) requestURL.openConnection(); String output;
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "application/json; charset=utf-8"); HttpURLConnection conn = (HttpURLConnection) requestURL.openConnection();
conn.setRequestMethod("GET");
String encoded = DatatypeConverter.printBase64Binary((LOGIN + ":" + PASSWORD).getBytes()); // String encoded = Base64.encode((this.LOGIN + ":" + this.PASSWORD).getBytes()); conn.setRequestProperty("Accept", "application/json; charset=utf-8");
conn.setRequestProperty("Authorization", "Basic " + encoded);
String encoded = DatatypeConverter.printBase64Binary((LOGIN + ":" + PASSWORD).getBytes()); // String encoded = Base64.encode((this.LOGIN + ":" + this.PASSWORD).getBytes());
BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); conn.setRequestProperty("Authorization", "Basic " + encoded);
StringBuilder result = new StringBuilder();
while ((output = br.readLine()) != null) { BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));
result.append(output); StringBuilder result = new StringBuilder();
} while ((output = br.readLine()) != null) {
result.append(output);
conn.disconnect(); }
JsonFactory factory = new JsonFactory(); conn.disconnect();
return result.toString();
} catch (Exception exc) { JsonFactory factory = new JsonFactory();
LOGGER.error(exc.getMessage(), exc); return result.toString();
} } catch (Exception exc) {
LOGGER.error(exc.getMessage(), exc);
return null; }
}
} return null;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
<context-root>/cwm</context-root>
</jboss-web>
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