Commit f308b53d authored by Samir Sadyhov's avatar Samir Sadyhov 🤔

update interpreter_library

parent e00e2ab6
let API = {
host: "http://127.0.0.1:8080/Synergy/",
getHttpClient: function(){
let client = new org.apache.commons.httpclient.HttpClient();
let creds = new org.apache.commons.httpclient.UsernamePasswordCredentials(login, password);
......@@ -8,7 +10,7 @@ let API = {
},
httpGetMethod: function(methods, type) {
let client = this.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(this.host + methods);
get.setRequestHeader("Content-type", "application/json");
client.executeMethod(get);
let resp = get.getResponseBodyAsString();
......@@ -17,7 +19,7 @@ let API = {
},
httpPostMethod: function(methods, params, contentType) {
let client = this.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(this.host + 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");
......@@ -83,6 +85,12 @@ let API = {
getSynergyCalendar: function(start, finish) {
return this.httpGetMethod("rest/api/settings/calendar?date_start=" + start + "&date_finish=" + finish);
},
getWorkTime: function(startDate, finishDate) {
return this.httpGetMethod("rest/api/workflow/getWorkTime?startDate=" + encodeURIComponent(startDate) + "&finishDate=" + encodeURIComponent(finishDate));
},
getFinishDate: function(startDate, duration) {
return this.httpGetMethod("rest/api/workflow/get_finish_date?startDate=" + encodeURIComponent(startDate) + "&duration=" + duration);
},
getFormForResult: function(formCode, workID) {
return this.httpGetMethod("rest/api/workflow/work/get_form_for_result?formCode=" + formCode + "&workID=" + workID);
},
......@@ -93,6 +101,56 @@ let API = {
type: 'work',
file_identifier: file_identifier
});
},
getPrintFilePDF: function(asfDataId) {
let client = this.getHttpClient();
let post = new org.apache.commons.httpclient.methods.PostMethod(this.host + "rest/api/asforms/data/print");
post.setRequestBody('{"dataUUID": "' + asfDataId + '", "format": "PDF"}');
post.setRequestHeader("Content-type", "application/json");
post.setRequestHeader("Content-disposition", "attachment; filename=printFile.pdf");
let resp = client.executeMethod(post);
let pdfResult = post.getResponseBody();
post.releaseConnection();
return pdfResult;
},
startUpload: function() {
return this.httpGetMethod("rest/api/storage/start_upload");
},
uploadPart: function(filePath, file) {
//filePath - result api/storage/start_upload
let client = this.getHttpClient();
let uploadPart = new org.apache.commons.httpclient.methods.PostMethod(this.host + "rest/api/storage/upload_part?file=" + filePath);
let base64 = java.util.Base64.getEncoder();
let encodedBytes = base64.encode(file);
encodedBytes = new org.apache.commons.httpclient.methods.multipart.ByteArrayPartSource("filename.txt", encodedBytes);
let filePart = new org.apache.commons.httpclient.methods.multipart.FilePart("body", encodedBytes);
let parts = new Array();
parts.push(filePart);
let entity = new org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity(parts, uploadPart.getParams());
uploadPart.setRequestEntity(entity);
let uploadStatus = client.executeMethod(uploadPart);
let uploadResult = uploadPart.getResponseBodyAsString();
uploadPart.releaseConnection();
return uploadResult;
},
addFileInForm: function(asfDataId, fileName, filePath, overwrite) {
//filePath - result api/storage/start_upload
let client = this.getHttpClient();
let params = "?dataUUID=" + asfDataId + "&fileName=" + fileName + "&filePath=" + filePath;
if(overwrite) params += "&overwrite=true";
let post = new org.apache.commons.httpclient.methods.PostMethod(this.host + "rest/api/storage/asffile/addFile" + params);
post.setRequestHeader("Content-type", "application/json; charset=utf-8");
let resp = client.executeMethod(post);
resp = JSON.parse(post.getResponseBodyAsString());
post.releaseConnection();
return resp;
},
appendTable: function(uuid, tableId, data) {
return this.httpPostMethod("rest/api/asforms/data/append_table", {
uuid: uuid,
tableId: tableId,
data: data
}, "application/json; charset=utf-8");
}
};
......
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