Commit 59631fd1 authored by Natalia Klimova's avatar Natalia Klimova

Update route_setting.rst

parent 49508a67
...@@ -423,65 +423,98 @@ counter_number - код поля "Номер заявки" ...@@ -423,65 +423,98 @@ counter_number - код поля "Номер заявки"
var result = true; var result = true;
var message = 'ok'; var message = 'ok';
function getHttpClient(){
function getHttpClient() {
let client = new org.apache.commons.httpclient.HttpClient(); let client = new org.apache.commons.httpclient.HttpClient();
let creds = new org.apache.commons.httpclient.UsernamePasswordCredentials(login, password); let creds = new org.apache.commons.httpclient.UsernamePasswordCredentials(login, password);
client.getParams().setAuthenticationPreemptive(true); client.getParams().setAuthenticationPreemptive(true);
client.getState().setCredentials(org.apache.commons.httpclient.auth.AuthScope.ANY, creds); client.getState().setCredentials(org.apache.commons.httpclient.auth.AuthScope.ANY, creds);
return client; return client;
} }
function httpGetMethod(methods, type) { function httpGetMethod(methods, type) {
let client = getHttpClient(); let client = getHttpClient();
let get = new org.apache.commons.httpclient.methods.GetMethod("http://127.0.0.1:8080/Synergy/" + methods); let get = new org.apache.commons.httpclient.methods.GetMethod(
"http://127.0.0.1:8080/Synergy/" + methods
);
get.setRequestHeader("Content-type", "application/json"); get.setRequestHeader("Content-type", "application/json");
client.executeMethod(get); client.executeMethod(get);
let resp = get.getResponseBodyAsString(); let resp = get.getResponseBodyAsString();
get.releaseConnection(); get.releaseConnection();
return type == 'text' ? resp : JSON.parse(resp); return type == 'text' ? resp : JSON.parse(resp);
} }
function httpPostMethod(methods, params, contentType) { function httpPostMethod(methods, params, contentType) {
let client = getHttpClient(); let client = getHttpClient();
let post = new org.apache.commons.httpclient.methods.PostMethod("http://127.0.0.1:8080/Synergy/" + methods); let post = new org.apache.commons.httpclient.methods.PostMethod(
if(contentType) post.setRequestBody(JSON.stringify(params)); "http://127.0.0.1:8080/Synergy/" + methods
else for(let key in params) post.addParameter(key, params[key]); );
post.setRequestHeader("Content-type", contentType || "application/x-www-form-urlencoded; charset=utf-8");
if (contentType) {
post.setRequestBody(JSON.stringify(params));
} else {
for (let key in params) post.addParameter(key, params[key]);
}
post.setRequestHeader(
"Content-type",
contentType || "application/x-www-form-urlencoded; charset=utf-8"
);
let resp = client.executeMethod(post); let resp = client.executeMethod(post);
if(contentType) resp = JSON.parse(post.getResponseBodyAsString());
if (contentType) {
resp = JSON.parse(post.getResponseBodyAsString());
}
post.releaseConnection(); post.releaseConnection();
return resp; return resp;
} }
function getProcesses(documentID) { function getProcesses(documentID) {
return httpGetMethod("rest/api/workflow/get_execution_process?documentID=" + documentID); return httpGetMethod("rest/api/workflow/get_execution_process?documentID=" + documentID);
} }
function getWorkCompletionData(workID) { function getWorkCompletionData(workID) {
return httpGetMethod("rest/api/workflow/work/get_completion_data?workID=" + workID); return httpGetMethod("rest/api/workflow/work/get_completion_data?workID=" + workID);
} }
function getFormData(asfDataId) { function getFormData(asfDataId) {
return httpGetMethod("rest/api/asforms/data/" + asfDataId) return httpGetMethod("rest/api/asforms/data/" + asfDataId);
} }
function mergeFormData function(uuid, data) {
return httpPostMethod("rest/api/asforms/data/merge", { function mergeFormData(uuid, data) {
return httpPostMethod(
"rest/api/asforms/data/merge",
{
uuid: uuid, uuid: uuid,
data: data data: data
}, "application/json; charset=utf-8"); },
"application/json; charset=utf-8"
);
} }
let UTILS = { let UTILS = {
createField: function(fieldData) { createField: function (fieldData) {
let field = {}; let field = {};
for (let key in fieldData) field[key] = fieldData[key]; for (let key in fieldData) field[key] = fieldData[key];
return field; return field;
}, },
getValue: function(data, cmpID) {
getValue: function (data, cmpID) {
data = data.data ? data.data : data; data = data.data ? data.data : data;
for(let i = 0; i < data.length; i++) for (let i = 0; i < data.length; i++) {
if (data[i].id === cmpID) return data[i]; if (data[i].id === cmpID) return data[i];
}
return null; return null;
}, },
setValue: function(asfData, cmpID, data) {
setValue: function (asfData, cmpID, data) {
let field = this.getValue(asfData, cmpID); let field = this.getValue(asfData, cmpID);
if(field) {
if (field) {
for (let key in data) { for (let key in data) {
if(key === 'id' || key === 'type') continue; if (key === 'id' || key === 'type') continue;
field[key] = data[key]; field[key] = data[key];
} }
return field; return field;
...@@ -493,36 +526,43 @@ counter_number - код поля "Номер заявки" ...@@ -493,36 +526,43 @@ counter_number - код поля "Номер заявки"
return field; return field;
} }
} }
} };
function processesFilter(processes) { function processesFilter(processes) {
let result = []; let result = [];
function search(p) { function search(p) {
p.forEach(function(x) { p.forEach(function (x) {
if (x.typeID == 'ASSIGNMENT_ITEM' && x.finished) result.push(x); if (x.typeID == 'ASSIGNMENT_ITEM' && x.finished) result.push(x);
if (x.subProcesses.length > 0) search(x.subProcesses); if (x.subProcesses.length > 0) search(x.subProcesses);
}); });
} }
search(processes); search(processes);
return result.sort(function(a, b) {
return result.sort(function (a, b) {
return new Date(b.finished) - new Date(a.finished); return new Date(b.finished) - new Date(a.finished);
}); });
} }
try { try {
let processes = processesFilter(getProcesses(documentID)); let processes = processesFilter(getProcesses(documentID));
if(!processes.length) throw new Error('Не найденно завершенной работы'); if (!processes.length) throw new Error('Не найденно завершенной работы');
let resultFormWork = getWorkCompletionData(processes[0].actionID); let resultFormWork = getWorkCompletionData(processes[0].actionID);
if(!resultFormWork || !resultFormWork.result.hasOwnProperty('dataUUID')) throw new Error('Не найдена форма завершения'); if (!resultFormWork || !resultFormWork.result.hasOwnProperty('dataUUID')) {
throw new Error('Не найдена форма завершения');
}
let completionFormData = getFormData(resultFormWork.result.dataUUID); let completionFormData = getFormData(resultFormWork.result.dataUUID);
let newFormData = []; let newFormData = [];
let matching = []; let matching = [];
//поля для сопоставления с фз на основную форму // поля для сопоставления с фз на основную форму
matching.push({from: ‘поле на форме завершения’, to: ‘поле основной формы’}); matching.push({ from: 'поле на форме завершения', to: 'поле основной формы' });
matching.forEach(function (id) { matching.forEach(function (id) {
let fromData = UTILS.getValue(completionFormData, id.from); let fromData = UTILS.getValue(completionFormData, id.from);
......
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