Commit 466d0b4e authored by Raimbek Egemberdiev's avatar Raimbek Egemberdiev

fix: AsFormData перегружал методы AsFormDataContainer

parent 9debbcab
......@@ -11,9 +11,8 @@ repositories {
def jacksonVersion = '1.9.2'
dependencies {
// compile group: 'cglib', name: 'cglib', version: '3.2.4'
testCompile group: 'org.testng', name: 'testng', version: '6.8'
testCompile group: 'org.mockito', name: 'mockito-all', version: '1.9.5'
testCompile group: 'org.mockito', name: 'mockito-all', version: '1.10.19'
compile group: 'com.google.guava', name: 'guava', version: '19.0'
compile(group: 'org.codehaus.jackson', name: 'jackson-core-asl', version: jacksonVersion, transitive: false)
compile(group: 'org.codehaus.jackson', name: 'jackson-mapper-asl', version: jacksonVersion, transitive: false)
......
......@@ -26,7 +26,7 @@ public class RestHttpQuery {
this.context = context;
}
public String doQuery(Query query) throws IOException {
private HttpURLConnection doQueryAndReturnConnection(Query query) throws IOException {
URL url = new URL(context.getAddress() + makeQuery(query.getUrl(), query.getQueryParams()));
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(TIMEOUT);
......@@ -56,8 +56,29 @@ public class RestHttpQuery {
request.flush();
request.close();
}
return conn;
}
public String doQuery(Query query) throws IOException {
HttpURLConnection conn = doQueryAndReturnConnection(query);
return readStringReturn(conn);
}
public byte[] doQueryAndReturnBytes(Query query) throws IOException {
HttpURLConnection conn = doQueryAndReturnConnection(query);
InputStream is = conn.getInputStream();
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int nRead;
byte[] data = new byte[16384];
while ((nRead = is.read(data, 0, data.length)) != -1) {
buffer.write(data, 0, nRead);
}
buffer.flush();
return buffer.toByteArray();
}
private String makeQuery(String query, Map<String, ?> params) {
......
......@@ -149,4 +149,13 @@ public class AsFormService {
public <T extends AsForm> AsFormWrapper toAsfData(T asForm) {
return asFormConverter.toAsfData(asForm);
}
public byte[] printForm(String dataUUID, String format) throws IOException {
Query query = Query.newInstance()
.url("/rest/api/asforms/template/print/form")
.queryParam("dataUUID", dataUUID)
.queryParam("format", format);
return restHttpQuery.doQueryAndReturnBytes(query);
}
}
......@@ -21,7 +21,7 @@ import java.util.Map;
*/
public class DefaultAsFormConverter implements AsFormConverter {
Map<Class<? extends Annotation>, ComponentConverter> componentConverters = new HashMap<>();
private final Map<Class<? extends Annotation>, ComponentConverter> componentConverters = new HashMap<>();
public DefaultAsFormConverter() {
registerConverter(Cmp.class, new CommonConverter());
......
......@@ -107,9 +107,9 @@ public abstract class AbstractComponentConverter implements ComponentConverter {
private String getValueForClassField(Field field, AsFormDataContainer asfData, String cmpId) {
if (hasKeyValueAnnotation(field)) {
return asfData.getKey(cmpId);
return asfData.getKeyFromInnerData(cmpId);
}
return asfData.getValue(cmpId);
return asfData.getValueFromInnerData(cmpId);
}
private String getNumberValueForField(AsFormDataContainer asfData, Field field, String cmpId) {
......
......@@ -31,7 +31,7 @@ public class AsFormDataContainer {
return null;
}
public String getValue(String cmpId) {
public String getValueFromInnerData(String cmpId) {
AsFormData data = getData(cmpId);
if (data != null) {
return data.getValue();
......@@ -39,15 +39,15 @@ public class AsFormDataContainer {
return null;
}
public String getValue(String cmpId, String defaultValue) {
String value = getValue(cmpId);
public String getValueFromInnerData(String cmpId, String defaultValue) {
String value = getValueFromInnerData(cmpId);
if (value == null) {
return defaultValue;
}
return value;
}
public String getKey(String cmpId) {
public String getKeyFromInnerData(String cmpId) {
AsFormData data = getData(cmpId);
if (data != null) {
return data.getKey();
......@@ -55,8 +55,8 @@ public class AsFormDataContainer {
return null;
}
public String getKey(String cmpId, String defaultKey) {
String key = getKey(cmpId);
public String getKeyFromInnerData(String cmpId, String defaultKey) {
String key = getKeyFromInnerData(cmpId);
if (key == null) {
return defaultKey;
}
......
package kz.arta.synergy.api.pojo;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonProperty;
/**
* @author raimbek
* @since 03.08.2016
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class SynergyFile {
private String identifier;
private String name;
@JsonProperty("is_folder")
private boolean isFolder;
public SynergyFile() {
}
public String getIdentifier() {
return identifier;
}
public void setIdentifier(String identifier) {
this.identifier = identifier;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public boolean isFolder() {
return isFolder;
}
public void setIsFolder(boolean isFolder) {
this.isFolder = isFolder;
}
}
......@@ -4,10 +4,13 @@ import kz.arta.synergy.api.JsonUtils;
import kz.arta.synergy.api.Query;
import kz.arta.synergy.api.QueryContext;
import kz.arta.synergy.api.RestHttpQuery;
import kz.arta.synergy.api.pojo.SynergyFile;
import kz.arta.synergy.api.services.storage.Attachment;
import kz.arta.synergy.api.services.storage.AttachmentList;
import org.codehaus.jackson.type.TypeReference;
import java.io.IOException;
import java.util.List;
/**
* Created by: Abzal Kultayev
......@@ -73,4 +76,19 @@ public class StorageService {
return JsonUtils.read(restHttpQuery.doQuery(query), AttachmentList.class);
}
/**
* Получит список файлов в папке
* @param parentID id родительской папки, если не передано,
* будет возвращено корневые папки
* @return список файлов
* @throws IOException
*/
public List<SynergyFile> storageList(String parentID) throws IOException {
Query query = Query.newInstance()
.url("/rest/api/storage/list");
if (parentID != null) {
query.queryParam("parentID", parentID);
}
return JsonUtils.read(restHttpQuery.doQuery(query), new TypeReference<List<SynergyFile>>() {});
}
}
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