Commit b031bab4 authored by Raimbek Egemberdiev's avatar Raimbek Egemberdiev

удален зависимост на guava, оставлено только для тестов

parent 80327073
group 'kz.arta.synergy.api' group 'kz.arta.synergy.api'
version '1.2' version '1.3'
apply plugin: 'java' apply plugin: 'java'
apply plugin: 'artifactory-publish' apply plugin: 'artifactory-publish'
...@@ -25,7 +25,7 @@ def jacksonVersion = '1.9.2' ...@@ -25,7 +25,7 @@ def jacksonVersion = '1.9.2'
dependencies { dependencies {
testCompile group: 'org.testng', name: 'testng', version: '6.8' testCompile group: 'org.testng', name: 'testng', version: '6.8'
testCompile group: 'org.mockito', name: 'mockito-all', version: '1.10.19' testCompile group: 'org.mockito', name: 'mockito-all', version: '1.10.19'
compile group: 'com.google.guava', name: 'guava', version: '19.0' testCompile 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-core-asl', version: jacksonVersion, transitive: false)
compile(group: 'org.codehaus.jackson', name: 'jackson-mapper-asl', version: jacksonVersion, transitive: false) compile(group: 'org.codehaus.jackson', name: 'jackson-mapper-asl', version: jacksonVersion, transitive: false)
} }
......
package kz.arta.synergy.api; package kz.arta.synergy.api;
import com.google.common.base.Function; import kz.arta.synergy.api.asforms.utils.Strings;
import com.google.common.base.Joiner;
import com.google.common.base.Predicates;
import com.google.common.base.Strings;
import com.google.common.collect.FluentIterable;
import java.io.*; import java.io.*;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
...@@ -91,23 +87,27 @@ public class RestHttpQuery { ...@@ -91,23 +87,27 @@ public class RestHttpQuery {
return query; return query;
} }
private String joinParamsForQuery(Map<String, ?> params) { public String joinParamsForQuery(Map<String, ?> params) {
if (params == null) return ""; if (params == null) return "";
return FluentIterable.from(params.entrySet()).transform( String result = "";
new Function<Map.Entry<String, ?>, String>() { for (Map.Entry<String, ?> param : params.entrySet()) {
@Override
public String apply(Map.Entry<String, ?> input) { if (param.getValue() == null || param.getValue().toString().isEmpty()) {
String value = input.getValue().toString(); continue;
}
String value;
try { try {
value = URLEncoder.encode(value, "UTF-8"); value = URLEncoder.encode(String.valueOf(param.getValue()), "UTF-8");
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
value = null; value = null;
} }
if (value == null || value.isEmpty()) return null;
return input.getKey() + "=" + value; result += param.getKey() + "=" + value + "&";
} }
}).filter(Predicates.notNull()).join(Joiner.on("&"));
return result.substring(0, result.length() - 1);
} }
private String readStringReturn(HttpURLConnection conn) throws IOException { private String readStringReturn(HttpURLConnection conn) throws IOException {
......
package kz.arta.synergy.api.asforms.converter.components; package kz.arta.synergy.api.asforms.converter.components;
import com.google.common.base.Strings;
import kz.arta.synergy.api.asforms.annotations.KeyValue; import kz.arta.synergy.api.asforms.annotations.KeyValue;
import kz.arta.synergy.api.asforms.exceptions.UnsupportedFieldTypeException; import kz.arta.synergy.api.asforms.exceptions.UnsupportedFieldTypeException;
import kz.arta.synergy.api.asforms.pojo.AsFormData; import kz.arta.synergy.api.asforms.pojo.AsFormData;
import kz.arta.synergy.api.asforms.pojo.AsFormDataContainer; import kz.arta.synergy.api.asforms.pojo.AsFormDataContainer;
import kz.arta.synergy.api.asforms.utils.Strings;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.lang.reflect.Field; import java.lang.reflect.Field;
......
package kz.arta.synergy.api.asforms.converter.components; package kz.arta.synergy.api.asforms.converter.components;
import com.google.common.base.Strings;
import kz.arta.synergy.api.asforms.annotations.DateCmp; import kz.arta.synergy.api.asforms.annotations.DateCmp;
import kz.arta.synergy.api.asforms.pojo.AsFormData; import kz.arta.synergy.api.asforms.pojo.AsFormData;
import kz.arta.synergy.api.asforms.pojo.AsFormDataContainer; import kz.arta.synergy.api.asforms.pojo.AsFormDataContainer;
import kz.arta.synergy.api.asforms.pojo.ComponentTypes; import kz.arta.synergy.api.asforms.pojo.ComponentTypes;
import kz.arta.synergy.api.asforms.utils.Strings;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.lang.reflect.Field; import java.lang.reflect.Field;
......
package kz.arta.synergy.api.asforms.utils;
/**
* @author raimbek
* @since 29.11.2016
*/
public class Strings {
public static boolean isNullOrEmpty(String s) {
return s == null || s.length() == 0;
}
}
package kz.arta.synergy.api.dictionaries; package kz.arta.synergy.api.dictionaries;
import com.google.common.base.Strings;
import kz.arta.synergy.api.JsonUtils; 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.asforms.utils.Strings;
import kz.arta.synergy.api.dictionaries.annotations.DictionaryCode; import kz.arta.synergy.api.dictionaries.annotations.DictionaryCode;
import kz.arta.synergy.api.dictionaries.annotations.DictionaryColumn; import kz.arta.synergy.api.dictionaries.annotations.DictionaryColumn;
import kz.arta.synergy.api.dictionaries.pojo.Dictionary; import kz.arta.synergy.api.dictionaries.pojo.Dictionary;
......
package kz.arta.synergy.api.dictionaries.pojo; package kz.arta.synergy.api.dictionaries.pojo;
import com.google.common.base.Strings;
import kz.arta.synergy.api.asforms.utils.Strings;
import java.util.List; import java.util.List;
......
package kz.arta.synergy.api;
import org.testng.Assert;
import org.testng.annotations.Test;
import java.util.HashMap;
import java.util.Map;
/**
* @author raimbek
* @since 29.11.2016
*/
public class RestHttpQueryTest {
@Test
public void testJoinParamsForQuery() throws Exception {
RestHttpQuery restHttpQuery = new RestHttpQuery(null);
Map<String, Object> params = new HashMap<>();
params.put("one", "value1");
params.put("two", "value2");
params.put("null_value", null);
params.put("three", "кирилица с пробелом");
String expected = "two=value2&one=value1&three=%D0%BA%D0%B8%D1%80%D0%B8%D0%BB%D0%B8%D1%86%D0%B0+%D1%81+%D0%BF%D1%80%D0%BE%D0%B1%D0%B5%D0%BB%D0%BE%D0%BC";
String result = restHttpQuery.joinParamsForQuery(params);
Assert.assertEquals(result, expected);
}
}
\ 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