Commit 88291365 authored by Raimbek Egemberdiev's avatar Raimbek Egemberdiev

метод getFormDefinitionExt

parent f2e65a2e
......@@ -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);
}
}
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;
}
}
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;
}
}
......@@ -115,4 +115,5 @@ public class AsFormServiceTest {
AsFormData tableCmp = asFormWrapper.getData("table_cmp");
Assert.assertEquals(tableCmp.getData().size(), 4);
}
}
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"));
}
}
{
"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
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