Commit f20f72d2 by everdarkgreen

assignment bug

parent a5d60174
...@@ -9,6 +9,7 @@ import com.sun.org.apache.xerces.internal.impl.dv.util.Base64; ...@@ -9,6 +9,7 @@ import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
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.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -23,30 +24,30 @@ import javax.ejb.ActivationConfigProperty; ...@@ -23,30 +24,30 @@ import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven; import javax.ejb.MessageDriven;
@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);
@Override @Override
public void onMessage(Message message) { public void onMessage(Message message) {
LOGGER.error("CWM work starts");
String dataUUID = null; LOGGER.error("CWM work starts");
String executionID = null;
String documentID = null; String dataUUID = null; // идентификатор данных по форме записи реестра
String executionID = null; // идентификатор блокирующего процесса
String documentID = null; // идентификатор документа реестра
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;
...@@ -72,55 +73,89 @@ public class Main implements MessageListener { ...@@ -72,55 +73,89 @@ public class Main implements MessageListener {
} }
} }
// Выполнение каких-либо действий // Получение данных исходной формы
// URL getFormDataURL = new URL("http://127.0.0.1:8080/Synergy/rest/api/asforms/data/" + dataUUID);
JsonParser sourceFormData = synergyApiGet(getFormDataURL);
// Получение значений текущих дат исходной формы
String b2b1, b4b1, b5b1;
String t4b1, t6b1, t2b1;
String t10b1, t12b1, t8b1;
String t18b1, t20b1, t16b1;
String t26b1, t24b1, t22b1;
String t32b1, t30b1, t28b1;
b2b1 = getDateKeyByFieldName(sourceFormData, "b2-b1");
b4b1 = getDateKeyByFieldName(sourceFormData, "b4-b1");
LOGGER.info(getDateKeyByFieldName(sourceFormData, "b2-b1"));
// Получение данных целевой карточки
// Разблокировка маршрута // Разблокировка маршрута
String address = "http://127.0.0.1:8080/Synergy"; String address = "http://127.0.0.1:8080/Synergy";
String login = "1";
String password = "1";
String signal = "got_agree"; String signal = "got_agree";
boolean isSuccess = false; URL url = new URL(address + "/rest/api/processes/signal?signal=" + signal + "&executionID=" + executionID + "&param1=resolution&value1=signal_is_" + signal);
synergyApiGet(url);
try {
URL url = new URL(address + "/rest/api/processes/signal?signal=" + signal + "&executionID=" + executionID + "&param1=resolution&value1=signal_is_" + signal);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "application/json; charset=utf-8");
String encoded = Base64.encode((login + ":" + password).getBytes()); } catch (Exception exc) {
conn.setRequestProperty("Authorization", "Basic " + encoded); LOGGER.error(exc.getMessage(), exc);
}
String output; }
StringBuffer result = new StringBuffer();
BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); private String getDateKeyByFieldName(final JsonParser formJson, final String fieldName) {
String value = new String();
try {
while (!formJson.isClosed()) {
if (JsonToken.FIELD_NAME.equals(formJson.nextToken())) {
if ("id".equals(formJson.getCurrentName()) && fieldName.equals(formJson.nextTextValue())) {
formJson.nextToken();
formJson.nextToken();
formJson.nextToken();
LOGGER.info(fieldName + ": " + formJson.nextTextValue());
value = formJson.nextTextValue();
break;
}
while ((output = br.readLine()) != null) {
result.append(output);
} }
}
} catch (Exception exc) {
LOGGER.error(exc.getMessage(), exc);
}
return value;
}
private static JsonParser synergyApiGet(final URL requestURL) {
String login = "Ипатьев";
String password = "1";
conn.disconnect(); try {
String output;
factory = new JsonFactory(); HttpURLConnection conn = (HttpURLConnection) requestURL.openConnection();
parser = factory.createParser(result.toString()); conn.setRequestMethod("GET");
token = null; conn.setRequestProperty("Accept", "application/json; charset=utf-8");
while ((token = parser.nextToken()) != null) { String encoded = Base64.encode((login + ":" + password).getBytes());
if (token == JsonToken.FIELD_NAME) { conn.setRequestProperty("Authorization", "Basic " + encoded);
String fieldName = parser.getText();
token = parser.nextToken(); BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));
if (fieldName.equals("errorCode") && parser.getText().equals("0")) { StringBuilder result = new StringBuilder();
isSuccess = true; while ((output = br.readLine()) != null) {
} result.append(output);
}
}
} catch (Exception exc) {
LOGGER.error(exc.getMessage(), exc);
} }
conn.disconnect();
JsonFactory factory = new JsonFactory();
return factory.createParser(result.toString());
} catch (Exception exc) { } catch (Exception exc) {
LOGGER.error(exc.getMessage(), exc); LOGGER.error(exc.getMessage(), exc);
} }
return null;
} }
} }
\ 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