diff --git a/src/main/java/kz/arta/synergy/api/asforms/AsFormService.java b/src/main/java/kz/arta/synergy/api/asforms/AsFormService.java index 67198ce4b4f7d2d8ed4c3ce69d8aa32a99a7f572..dee205fd30d0e3b3fc3d2f9db4e3618c41540724 100644 --- a/src/main/java/kz/arta/synergy/api/asforms/AsFormService.java +++ b/src/main/java/kz/arta/synergy/api/asforms/AsFormService.java @@ -158,4 +158,14 @@ public class AsFormService { return restHttpQuery.doQueryAndReturnBytes(query); } + + public AsFormDefinition getFormDefinitionExt(String formId, String formCode, String version) throws IOException { + Query query = Query.newInstance() + .url("/rest/api/asforms/form_ext") + .queryParam("formID", formId) + .queryParam("formCode", formCode) + .queryParam("version", version); + String result = restHttpQuery.doQuery(query); + return JsonUtils.read(result, AsFormDefinition.class); + } } diff --git a/src/main/java/kz/arta/synergy/api/asforms/pojo/AsFormDefinition.java b/src/main/java/kz/arta/synergy/api/asforms/pojo/AsFormDefinition.java new file mode 100644 index 0000000000000000000000000000000000000000..cd3c6adf37bc457dc7edf0a5da5b0e52eb520d01 --- /dev/null +++ b/src/main/java/kz/arta/synergy/api/asforms/pojo/AsFormDefinition.java @@ -0,0 +1,127 @@ +package kz.arta.synergy.api.asforms.pojo; + +import com.fasterxml.jackson.annotation.JsonInclude; +import org.codehaus.jackson.annotate.JsonIgnoreProperties; + +import java.util.List; +import java.util.Map; + +/** + * @author raimbek + * @since 25.11.2016 + */ +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class AsFormDefinition { + private String uuid; + private String version; + private String typeform; + private String name; + private String nameru; + private String namekz; + private String code; + private String description; + private String type; + private Map<String, String> config; + private List<AsFormProperty> properties; + + public String getUuid() { + return uuid; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getTypeform() { + return typeform; + } + + public void setTypeform(String typeform) { + this.typeform = typeform; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getNameru() { + return nameru; + } + + public void setNameru(String nameru) { + this.nameru = nameru; + } + + public String getNamekz() { + return namekz; + } + + public void setNamekz(String namekz) { + this.namekz = namekz; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public Map<String, String> getConfig() { + return config; + } + + public void setConfig(Map<String, String> config) { + this.config = config; + } + + public List<AsFormProperty> getProperties() { + return properties; + } + + public void setProperties(List<AsFormProperty> properties) { + this.properties = properties; + } + + public boolean hasCmp(String id) { + for (AsFormProperty property : properties) { + if (property.getId().equals(id)) { + return true; + } + if (property.hasCmp(id)) { + return true; + } + } + return false; + } +} diff --git a/src/main/java/kz/arta/synergy/api/asforms/pojo/AsFormProperty.java b/src/main/java/kz/arta/synergy/api/asforms/pojo/AsFormProperty.java new file mode 100644 index 0000000000000000000000000000000000000000..ea8ad94d27b38626b1292ddd7845193e67d19bec --- /dev/null +++ b/src/main/java/kz/arta/synergy/api/asforms/pojo/AsFormProperty.java @@ -0,0 +1,83 @@ +package kz.arta.synergy.api.asforms.pojo; + +import com.fasterxml.jackson.annotation.JsonInclude; +import org.codehaus.jackson.annotate.JsonIgnoreProperties; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * @author raimbek + * @since 25.11.2016 + */ +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class AsFormProperty { + private String id; + private String type; + private String label; + private Map<String, Object> config; + private Map<String, String> style; + private List<AsFormProperty> properties = new ArrayList<>(); + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + public Map<String, Object> getConfig() { + return config; + } + + public void setConfig(Map<String, Object> config) { + this.config = config; + } + + public Map<String, String> getStyle() { + return style; + } + + public void setStyle(Map<String, String> style) { + this.style = style; + } + + public List<AsFormProperty> getProperties() { + return properties; + } + + public void setProperties(List<AsFormProperty> properties) { + this.properties = properties; + } + + public boolean hasCmp(String id) { + for (AsFormProperty property : properties) { + if (property.getId().equals(id)) { + return true; + } + if (property.hasCmp(id)) { + return true; + } + } + return false; + } +} diff --git a/src/test/java/kz/arta/synergy/api/asforms/AsFormServiceTest.java b/src/test/java/kz/arta/synergy/api/asforms/AsFormServiceTest.java index 35326846e5450ad633592602f893a655b033d5a9..91985f43c424abff0b3c395de25fa9763ea77b43 100644 --- a/src/test/java/kz/arta/synergy/api/asforms/AsFormServiceTest.java +++ b/src/test/java/kz/arta/synergy/api/asforms/AsFormServiceTest.java @@ -115,4 +115,5 @@ public class AsFormServiceTest { AsFormData tableCmp = asFormWrapper.getData("table_cmp"); Assert.assertEquals(tableCmp.getData().size(), 4); } + } diff --git a/src/test/java/kz/arta/synergy/api/asforms/AsFormsServiceGetExtTest.java b/src/test/java/kz/arta/synergy/api/asforms/AsFormsServiceGetExtTest.java new file mode 100644 index 0000000000000000000000000000000000000000..70ed7d0f8ec4e961e58bb26b321df6b8ea9c21e0 --- /dev/null +++ b/src/test/java/kz/arta/synergy/api/asforms/AsFormsServiceGetExtTest.java @@ -0,0 +1,35 @@ +package kz.arta.synergy.api.asforms; + +import com.google.common.base.Charsets; +import com.google.common.io.Resources; +import kz.arta.synergy.api.Query; +import kz.arta.synergy.api.QueryContext; +import kz.arta.synergy.api.RestHttpQuery; +import kz.arta.synergy.api.asforms.pojo.AsFormDefinition; +import org.mockito.Mockito; +import org.testng.Assert; +import org.testng.annotations.Test; + +import java.net.URL; + +/** + * @author raimbek + * @since 25.11.2016 + */ +public class AsFormsServiceGetExtTest { + + + @Test + public void testGetFormDefinitionExt() throws Exception { + URL url = Resources.getResource("data/form-ext.json"); + String formExtJson = Resources.toString(url, Charsets.UTF_8); + + RestHttpQuery restHttpQueryMock = Mockito.mock(RestHttpQuery.class); + Mockito.when(restHttpQueryMock.doQuery(Mockito.any(Query.class))).thenReturn(formExtJson); + AsFormService asFormService = AsFormService.newInstance(new QueryContext("localhost")).setRestHttpQuery(restHttpQueryMock); + + AsFormDefinition formDefinition = asFormService.getFormDefinitionExt(null, null, null); + Assert.assertTrue(formDefinition.hasCmp("avtor")); + Assert.assertFalse(formDefinition.hasCmp("not-cmp")); + } +} diff --git a/src/test/resources/data/form-ext.json b/src/test/resources/data/form-ext.json new file mode 100644 index 0000000000000000000000000000000000000000..ad437b8dd8299872a1c6bef26459222b67d5dc28 --- /dev/null +++ b/src/test/resources/data/form-ext.json @@ -0,0 +1,294 @@ +{ + "uuid": "d339c65f-20af-4e09-8175-8232470af558", + "version": 1, + "typeform": "0", + "name": "РееÑÑ‚Ñ€ поручений", + "nameru": "РееÑÑ‚Ñ€ поручений", + "namekz": "РееÑÑ‚Ñ€ поручений", + "code": "РееÑÑ‚Ñ€_поручений", + "description": null, + "type": "form", + "config": {}, + "properties": [ + { + "id": "cmp-ysik8x", + "type": "table", + "config": {}, + "properties": [ + { + "id": "cmp-i8anf4", + "type": "label", + "config": {}, + "label": "Ðвтор:", + "style": { + "align": "left", + "font": "Arial", + "fontsize": "12" + } + }, + { + "id": "avtor", + "type": "entity", + "config": { + "entity": "users", + "read-only": true, + "fill-with-current": true, + "script": "", + "customNameFormats": { + "ru": "${l} ${f.short}.${p.short.dot}", + "kz": "${l} ${f.short}.${p.short.dot}", + "en": "${l} ${f.short}.${p.short.dot}" + } + }, + "style": { + "width": "200", + "align": "left", + "font": "Arial", + "fontsize": "12" + } + } + ], + "layout": { + "columns": 4, + "rows": 1, + "components": [ + { + "id": "cmp-i8anf4", + "column": 2, + "row": 0 + }, + { + "id": "avtor", + "column": 3, + "row": 0 + } + ] + }, + "style": { + "align": "left", + "font": "Arial", + "fontsize": "12" + } + }, + { + "id": "cmp-pjaioc", + "type": "table", + "config": {}, + "properties": [ + { + "id": "cmp-1f7nnj", + "type": "label", + "config": {}, + "label": "Поручение", + "style": { + "align": "left", + "font": "Arial", + "fontsize": "12", + "bold": true + } + }, + { + "id": "task", + "type": "textarea", + "config": {}, + "style": { + "width": "400", + "height": "60", + "align": "left", + "font": "Arial", + "fontsize": "12" + } + }, + { + "id": "cmp-houxfj", + "type": "label", + "config": {}, + "label": "ОтветÑтвенный", + "style": { + "align": "left", + "font": "Arial", + "fontsize": "12", + "bold": true + } + }, + { + "id": "user", + "type": "entity", + "config": { + "entity": "users", + "read-only": false, + "customNameFormats": { + "ru": "${l} ${f} ${p}", + "kz": "${l} ${f} ${p}", + "en": "${l} ${f} ${p}" + }, + "script": "" + }, + "style": { + "width": "400", + "align": "left", + "font": "Arial", + "fontsize": "12" + } + } + ], + "layout": { + "columns": 2, + "rows": 2, + "config": [ + { + "column": 0, + "width": "300" + } + ], + "components": [ + { + "id": "cmp-1f7nnj", + "column": 0, + "row": 0 + }, + { + "id": "task", + "column": 1, + "row": 0 + }, + { + "id": "cmp-houxfj", + "column": 0, + "row": 1 + }, + { + "id": "user", + "column": 1, + "row": 1 + } + ] + }, + "style": { + "align": "left", + "font": "Arial", + "fontsize": "12" + } + }, + { + "id": "cmp-6euqrr", + "type": "label", + "config": {}, + "label": " ", + "style": { + "height": "15", + "align": "left", + "font": "Arial", + "fontsize": "12" + } + }, + { + "id": "cmp-h7st94", + "type": "table", + "config": {}, + "properties": [ + { + "id": "cmp-txmcm4", + "type": "label", + "config": {}, + "label": "СÑылка на проект", + "style": { + "align": "left", + "font": "Arial", + "fontsize": "12", + "bold": true + } + }, + { + "id": "project", + "type": "projectlink", + "config": {}, + "style": { + "width": "400", + "align": "left", + "font": "Arial", + "fontsize": "12" + } + } + ], + "layout": { + "columns": 2, + "rows": 1, + "config": [ + { + "column": 0, + "width": "300" + } + ], + "components": [ + { + "id": "cmp-txmcm4", + "column": 0, + "row": 0 + }, + { + "id": "project", + "column": 1, + "row": 0 + } + ] + }, + "style": { + "align": "left", + "font": "Arial", + "fontsize": "12" + } + } + ], + "data": [ + { + "id": "avtor", + "type": "entity", + "formatVersion": "V1" + }, + { + "id": "user", + "type": "entity", + "formatVersion": "V1" + }, + { + "id": "project", + "default": "{\"valueID\":null,\"value\":null}" + } + ], + "datasources": [], + "pointers": [], + "collations": [], + "layout": { + "totalPages": 1, + "pages": [ + { + "page": 1, + "columns": 1, + "rows": 5, + "components": [ + { + "id": "cmp-ysik8x", + "column": 0, + "row": 0 + }, + { + "id": "cmp-pjaioc", + "column": 0, + "row": 2 + }, + { + "id": "cmp-6euqrr", + "column": 0, + "row": 3 + }, + { + "id": "cmp-h7st94", + "column": 0, + "row": 4 + } + ] + } + ] + } +} \ No newline at end of file