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

Update route_setting.rst

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