Commit a132f0a8 authored by Abzal Kultayev's avatar Abzal Kultayev

[TASK #CMER] Сохранение файлов в реестр Документы-Услуги 2 работают теперь

parent 7592ec7c
...@@ -4,6 +4,8 @@ import kz.arta.synergy.api.JsonUtils; ...@@ -4,6 +4,8 @@ import kz.arta.synergy.api.JsonUtils;
import kz.arta.synergy.api.Query; import kz.arta.synergy.api.Query;
import kz.arta.synergy.api.QueryContext; import kz.arta.synergy.api.QueryContext;
import kz.arta.synergy.api.RestHttpQuery; import kz.arta.synergy.api.RestHttpQuery;
import kz.arta.synergy.api.services.storage.Attachment;
import kz.arta.synergy.api.services.storage.AttachmentList;
import java.io.IOException; import java.io.IOException;
...@@ -34,4 +36,41 @@ public class StorageService { ...@@ -34,4 +36,41 @@ public class StorageService {
return JsonUtils.getValueByKey(result, "file"); return JsonUtils.getValueByKey(result, "file");
} }
/**
* Метод добавляет вложение к документу из временного файла, загруженного на сервер с помощью API метода rest/api/storage/start_upload
* @param documentID идентификатор документа
* @param filename название файла
* @param filepath путь до файла на сервере
* @return errorCode и errorMessage
* @throws IOException при проблеммах с сетью
*/
public String createAttachment(String documentID, String filename, String filepath) throws IOException {
Query query = Query.newInstance()
.methodPost()
.url("/rest/api/docflow/doc/attachment/create")
.formParam("fileName", filename)
.formParam("filePath", filepath)
.formParam("path", "ase:workContainer")
.formParam("documentID", documentID);
return restHttpQuery.doQuery(query);
}
public Attachment createAndGetAttachment(String documentID, String filename, String filepath) throws IOException {
String attachment = createAttachment(documentID, filename, filepath);
if (!JsonUtils.getValueByKey(attachment, "errorCode").equals("0")) {
throw new IOException("Attachment was not created");
}
AttachmentList lastAttachments = getLastAttachments(documentID);
return lastAttachments.get(0);
}
public AttachmentList getLastAttachments(String documentID) throws IOException {
Query query = Query.newInstance()
.url("/rest/api/docflow/doc/last_attachments")
.queryParam("documentID", documentID);
return JsonUtils.read(restHttpQuery.doQuery(query), AttachmentList.class);
}
} }
package kz.arta.synergy.api.services.storage;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonProperty;
/**
* Created by: Abzal Kultayev
* Date: 14.11.16
* Time: 13:19
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class Attachment {
private String uuid;
private String dataUUID;
private boolean mobile;
private String name;
@JsonProperty("is_editable")
private boolean isEditable;
@JsonProperty("created_label")
private String createdLabel;
private String created;
private String icon;
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public String getDataUUID() {
return dataUUID;
}
public void setDataUUID(String dataUUID) {
this.dataUUID = dataUUID;
}
public boolean isMobile() {
return mobile;
}
public void setMobile(boolean mobile) {
this.mobile = mobile;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public boolean isEditable() {
return isEditable;
}
public void setEditable(boolean editable) {
isEditable = editable;
}
public String getCreatedLabel() {
return createdLabel;
}
public void setCreatedLabel(String createdLabel) {
this.createdLabel = createdLabel;
}
public String getCreated() {
return created;
}
public void setCreated(String created) {
this.created = created;
}
public String getIcon() {
return icon;
}
public void setIcon(String icon) {
this.icon = icon;
}
}
package kz.arta.synergy.api.services.storage;
import java.util.ArrayList;
/**
* Created by: Abzal Kultayev
* Date: 14.11.16
* Time: 13:36
*/
public class AttachmentList extends ArrayList<Attachment> {
}
package kz.arta.synergy.api.services; package kz.arta.synergy.api.services;
import kz.arta.synergy.api.QueryContext; import kz.arta.synergy.api.QueryContext;
import kz.arta.synergy.api.services.storage.Attachment;
import kz.arta.synergy.api.services.storage.AttachmentList;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import static org.testng.Assert.*; import static org.testng.Assert.*;
...@@ -12,10 +14,30 @@ import static org.testng.Assert.*; ...@@ -12,10 +14,30 @@ import static org.testng.Assert.*;
*/ */
public class StorageServiceTest { public class StorageServiceTest {
StorageService service = StorageService.newInstance(new QueryContext("http://192.168.3.233:8080/Synergy", "NppAdmin", "123456")); StorageService service = StorageService.newInstance(new QueryContext("http://192.168.3.233:8080/Synergy", "NppAdmin", "123456"));
private String documentID = "05647530-a72f-11e6-bfd9-00163ebf20cd";
@Test @Test
public void testStartUploadFile() throws Exception { public void testStartUploadFile() throws Exception {
String tempFileName = service.startUploadFile(); String tempFileName = service.startUploadFile();
assertNotNull(tempFileName); assertNotNull(tempFileName);
} }
@Test
public void testCreateAttachment() throws Exception {
String tempFileName = service.startUploadFile();
String attachment = service.createAttachment(documentID, "FILENAME.PDF", tempFileName);
assertEquals(attachment, "");
}
@Test
public void testLastAttachments() throws Exception {
AttachmentList attachmentList = service.getLastAttachments(documentID);
assertNotNull(attachmentList);
}
@Test
public void testCreateAndGetAttachment() throws Exception {
String tempFileName = service.startUploadFile();
Attachment attachment = service.createAndGetAttachment(documentID, "Filename.pdf", tempFileName);
assertNotNull(attachment);
}
} }
\ 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