Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
synergy-api-util
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Raimbek Egemberdiev
synergy-api-util
Commits
034811a3
Commit
034811a3
authored
Nov 10, 2016
by
Raimbek Egemberdiev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rest query
parent
9ad35fe6
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
126 additions
and
25 deletions
+126
-25
build.gradle
build.gradle
+3
-0
src/main/java/kz/arta/synergy/api/JsonUtils.java
src/main/java/kz/arta/synergy/api/JsonUtils.java
+39
-0
src/main/java/kz/arta/synergy/api/RestHttpQuery.java
src/main/java/kz/arta/synergy/api/RestHttpQuery.java
+15
-5
src/main/java/kz/arta/synergy/api/asforms/AsFormProvider.java
...main/java/kz/arta/synergy/api/asforms/AsFormProvider.java
+27
-9
src/main/java/kz/arta/synergy/api/asforms/pojo/AdvancedSearchParams.java
...z/arta/synergy/api/asforms/pojo/AdvancedSearchParams.java
+3
-0
src/main/java/kz/arta/synergy/api/asforms/pojo/AdvancedSearchResult.java
...z/arta/synergy/api/asforms/pojo/AdvancedSearchResult.java
+3
-0
src/main/java/kz/arta/synergy/api/asforms/pojo/AsForm.java
src/main/java/kz/arta/synergy/api/asforms/pojo/AsForm.java
+3
-0
src/main/java/kz/arta/synergy/api/asforms/pojo/AsFormData.java
...ain/java/kz/arta/synergy/api/asforms/pojo/AsFormData.java
+3
-0
src/main/java/kz/arta/synergy/api/asforms/pojo/AsFormDataContainer.java
...kz/arta/synergy/api/asforms/pojo/AsFormDataContainer.java
+3
-0
src/main/java/kz/arta/synergy/api/asforms/pojo/AsFormWrapper.java
.../java/kz/arta/synergy/api/asforms/pojo/AsFormWrapper.java
+12
-0
src/test/java/kz/arta/synergy/api/asforms/AsFormProviderTest.java
.../java/kz/arta/synergy/api/asforms/AsFormProviderTest.java
+15
-8
src/test/java/kz/arta/synergy/api/asforms/AsFormTest.java
src/test/java/kz/arta/synergy/api/asforms/AsFormTest.java
+0
-3
No files found.
build.gradle
View file @
034811a3
...
@@ -9,9 +9,12 @@ repositories {
...
@@ -9,9 +9,12 @@ repositories {
mavenCentral
()
mavenCentral
()
}
}
def
jacksonVersion
=
'1.9.2'
dependencies
{
dependencies
{
// compile group: 'cglib', name: 'cglib', version: '3.2.4'
// compile group: 'cglib', name: 'cglib', version: '3.2.4'
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.9.5'
testCompile
group:
'org.mockito'
,
name:
'mockito-all'
,
version:
'1.9.5'
compile
group:
'com.google.guava'
,
name:
'guava'
,
version:
'19.0'
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
)
}
}
src/main/java/kz/arta/synergy/api/JsonUtils.java
0 → 100644
View file @
034811a3
package
kz.arta.synergy.api
;
import
org.codehaus.jackson.JsonNode
;
import
org.codehaus.jackson.map.ObjectMapper
;
import
org.codehaus.jackson.type.TypeReference
;
import
java.io.IOException
;
public
class
JsonUtils
{
private
static
final
ObjectMapper
MAPPER
=
new
ObjectMapper
();
private
JsonUtils
()
{
}
public
static
String
toJson
(
Object
object
)
throws
IOException
{
return
MAPPER
.
writeValueAsString
(
object
);
}
public
static
JsonNode
readTree
(
String
content
)
throws
IOException
{
return
MAPPER
.
readTree
(
content
);
}
public
static
ObjectMapper
getMapper
()
{
return
MAPPER
;
}
public
static
<
T
>
T
read
(
String
result
,
Class
<
T
>
synResponseClass
)
throws
IOException
{
return
MAPPER
.
readValue
(
result
,
synResponseClass
);
}
public
static
<
T
>
T
read
(
String
result
,
TypeReference
<
T
>
typeReference
)
throws
IOException
{
return
MAPPER
.
readValue
(
result
,
typeReference
);
}
public
static
String
getValueByKey
(
String
jsonData
,
String
key
)
throws
IOException
{
return
MAPPER
.
readTree
(
jsonData
).
path
(
key
).
getTextValue
();
}
}
src/main/java/kz/arta/synergy/api/RestHttpQuery.java
View file @
034811a3
...
@@ -22,20 +22,30 @@ import java.util.Map;
...
@@ -22,20 +22,30 @@ import java.util.Map;
public
class
RestHttpQuery
{
public
class
RestHttpQuery
{
public
static
final
int
TIMEOUT
=
10
*
60
*
1000
;
public
static
final
int
TIMEOUT
=
10
*
60
*
1000
;
public
String
doGetQuery
(
QueryContext
context
,
String
query
)
throws
IOException
{
private
QueryContext
context
;
public
RestHttpQuery
(
QueryContext
context
)
{
this
.
context
=
context
;
}
public
String
doGetQuery
(
String
query
)
throws
IOException
{
URL
url
=
new
URL
(
context
.
getAddress
()
+
query
);
URL
url
=
new
URL
(
context
.
getAddress
()
+
query
);
HttpURLConnection
conn
=
(
HttpURLConnection
)
url
.
openConnection
();
HttpURLConnection
conn
=
(
HttpURLConnection
)
url
.
openConnection
();
conn
.
setConnectTimeout
(
TIMEOUT
);
conn
.
setConnectTimeout
(
TIMEOUT
);
conn
.
setReadTimeout
(
TIMEOUT
);
conn
.
setReadTimeout
(
TIMEOUT
);
conn
.
setRequestMethod
(
"GET"
);
conn
.
setRequestMethod
(
"GET"
);
conn
.
setRequestProperty
(
"Accept"
,
"application/json; charset=utf-8"
);
conn
.
setRequestProperty
(
"Accept"
,
"application/json; charset=utf-8"
);
authentication
(
con
text
,
con
n
);
authentication
(
conn
);
return
readStringReturn
(
conn
);
return
readStringReturn
(
conn
);
}
}
public
String
doGetQuery
(
QueryContext
context
,
String
query
,
Map
<
String
,
?>
params
)
throws
IOException
{
/*public String doPostQuery() {
return
doGetQuery
(
context
,
makeQuery
(
query
,
params
));
}*/
public
String
doGetQuery
(
String
query
,
Map
<
String
,
?>
params
)
throws
IOException
{
return
doGetQuery
(
makeQuery
(
query
,
params
));
}
}
private
String
makeQuery
(
String
query
,
Map
<
String
,
?>
params
)
{
private
String
makeQuery
(
String
query
,
Map
<
String
,
?>
params
)
{
...
@@ -75,7 +85,7 @@ public class RestHttpQuery {
...
@@ -75,7 +85,7 @@ public class RestHttpQuery {
return
result
.
toString
();
return
result
.
toString
();
}
}
private
void
authentication
(
QueryContext
context
,
HttpURLConnection
conn
)
{
private
void
authentication
(
HttpURLConnection
conn
)
{
if
(
context
.
getLogin
()
!=
null
&&
context
.
getPassword
()
!=
null
)
{
if
(
context
.
getLogin
()
!=
null
&&
context
.
getPassword
()
!=
null
)
{
conn
.
setRequestProperty
(
"Authorization"
,
"Basic "
+
context
.
getAuthHeader
());
conn
.
setRequestProperty
(
"Authorization"
,
"Basic "
+
context
.
getAuthHeader
());
}
}
...
...
src/main/java/kz/arta/synergy/api/asforms/AsFormProvider.java
View file @
034811a3
package
kz.arta.synergy.api.asforms
;
package
kz.arta.synergy.api.asforms
;
import
kz.arta.synergy.api.JsonUtils
;
import
kz.arta.synergy.api.QueryContext
;
import
kz.arta.synergy.api.RestHttpQuery
;
import
kz.arta.synergy.api.asforms.annotations.*
;
import
kz.arta.synergy.api.asforms.annotations.*
;
import
kz.arta.synergy.api.asforms.exceptions.CreateAsFormException
;
import
kz.arta.synergy.api.asforms.exceptions.CreateAsFormException
;
import
kz.arta.synergy.api.asforms.exceptions.UnsupportedFieldTypeException
;
import
kz.arta.synergy.api.asforms.exceptions.UnsupportedFieldTypeException
;
import
kz.arta.synergy.api.asforms.pojo.*
;
import
kz.arta.synergy.api.asforms.pojo.*
;
import
java.io.IOException
;
import
java.lang.annotation.Annotation
;
import
java.lang.annotation.Annotation
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Field
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
...
@@ -17,20 +21,24 @@ import java.util.Set;
...
@@ -17,20 +21,24 @@ import java.util.Set;
*/
*/
public
class
AsFormProvider
{
public
class
AsFormProvider
{
private
AsFormProvider
()
{
private
RestHttpQuery
restHttpQuery
;
private
AsFormProvider
(
QueryContext
context
)
{
this
.
restHttpQuery
=
new
RestHttpQuery
(
context
);
}
}
public
static
AsFormProvider
newInstance
()
{
public
static
AsFormProvider
newInstance
(
QueryContext
context
)
{
return
new
AsFormProvider
();
return
new
AsFormProvider
(
context
);
}
}
public
List
<
AdvancedSearchResult
>
advancedSearch
(
AdvancedSearchParams
advancedSearchParams
)
{
public
List
<
AdvancedSearchResult
>
advancedSearch
(
AdvancedSearchParams
advancedSearchParams
)
{
return
new
ArrayList
<
AdvancedSearchResult
>();
return
new
ArrayList
<
AdvancedSearchResult
>();
}
}
/*public <T extends AsForm> T fetch(Class<T> formClass, String dataUUID) {
public
<
T
extends
AsForm
>
T
fetch
(
Class
<
T
>
formClass
,
String
dataUUID
)
throws
IOException
{
return create(formClass, asfData);
String
data
=
restHttpQuery
.
doGetQuery
(
"/rest/api/asforms/data/"
+
dataUUID
);
}*/
return
create
(
formClass
,
JsonUtils
.
read
(
data
,
AsFormWrapper
.
class
));
}
public
<
T
extends
AsForm
>
T
create
(
Class
<
T
>
asFormClass
,
AsFormWrapper
asfData
)
{
public
<
T
extends
AsForm
>
T
create
(
Class
<
T
>
asFormClass
,
AsFormWrapper
asfData
)
{
T
asForm
=
createAsFormObject
(
asFormClass
,
asfData
,
null
);
T
asForm
=
createAsFormObject
(
asFormClass
,
asfData
,
null
);
...
@@ -41,9 +49,11 @@ public class AsFormProvider {
...
@@ -41,9 +49,11 @@ public class AsFormProvider {
return
asForm
;
return
asForm
;
}
}
/*public <T extends AsForm> String save(T asForm) {
public
<
T
extends
AsForm
>
String
save
(
T
asForm
)
throws
IOException
{
AsFormWrapper
asFormWrapper
=
toAsfData
(
asForm
);
}*/
JsonUtils
.
toJson
(
asFormWrapper
);
return
null
;
}
public
<
T
extends
AsForm
>
AsFormWrapper
toAsfData
(
T
asForm
)
{
public
<
T
extends
AsForm
>
AsFormWrapper
toAsfData
(
T
asForm
)
{
AsFormWrapper
asFormWrapper
=
new
AsFormWrapper
();
AsFormWrapper
asFormWrapper
=
new
AsFormWrapper
();
...
@@ -301,4 +311,12 @@ public class AsFormProvider {
...
@@ -301,4 +311,12 @@ public class AsFormProvider {
}
}
return
fetchKey
;
return
fetchKey
;
}
}
public
RestHttpQuery
getRestHttpQuery
()
{
return
restHttpQuery
;
}
public
void
setRestHttpQuery
(
RestHttpQuery
restHttpQuery
)
{
this
.
restHttpQuery
=
restHttpQuery
;
}
}
}
src/main/java/kz/arta/synergy/api/asforms/pojo/AdvancedSearchParams.java
View file @
034811a3
package
kz.arta.synergy.api.asforms.pojo
;
package
kz.arta.synergy.api.asforms.pojo
;
import
org.codehaus.jackson.annotate.JsonIgnoreProperties
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.List
;
...
@@ -8,6 +10,7 @@ import java.util.List;
...
@@ -8,6 +10,7 @@ import java.util.List;
* @author raimbek
* @author raimbek
* @since 02.11.2016
* @since 02.11.2016
*/
*/
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
AdvancedSearchParams
{
public
class
AdvancedSearchParams
{
private
String
query
;
private
String
query
;
private
List
<
String
>
parameters
=
new
ArrayList
<
String
>();
private
List
<
String
>
parameters
=
new
ArrayList
<
String
>();
...
...
src/main/java/kz/arta/synergy/api/asforms/pojo/AdvancedSearchResult.java
View file @
034811a3
package
kz.arta.synergy.api.asforms.pojo
;
package
kz.arta.synergy.api.asforms.pojo
;
import
org.codehaus.jackson.annotate.JsonIgnoreProperties
;
/**
/**
* @author raimbek
* @author raimbek
* @since 02.11.2016
* @since 02.11.2016
*/
*/
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
AdvancedSearchResult
{
public
class
AdvancedSearchResult
{
private
String
dataUUID
;
private
String
dataUUID
;
private
String
documentID
;
private
String
documentID
;
...
...
src/main/java/kz/arta/synergy/api/asforms/pojo/AsForm.java
View file @
034811a3
package
kz.arta.synergy.api.asforms.pojo
;
package
kz.arta.synergy.api.asforms.pojo
;
import
org.codehaus.jackson.annotate.JsonIgnoreProperties
;
/**
/**
* @author raimbek
* @author raimbek
* @since 09.11.2016
* @since 09.11.2016
*/
*/
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
AsForm
{
public
class
AsForm
{
private
String
nodeUUID
;
private
String
nodeUUID
;
...
...
src/main/java/kz/arta/synergy/api/asforms/pojo/AsFormData.java
View file @
034811a3
package
kz.arta.synergy.api.asforms.pojo
;
package
kz.arta.synergy.api.asforms.pojo
;
import
org.codehaus.jackson.annotate.JsonIgnoreProperties
;
import
java.util.List
;
import
java.util.List
;
/**
/**
* @author raimbek
* @author raimbek
* @since 09.11.2016
* @since 09.11.2016
*/
*/
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
AsFormData
extends
AsFormDataContainer
{
public
class
AsFormData
extends
AsFormDataContainer
{
private
String
id
;
private
String
id
;
private
String
type
;
private
String
type
;
...
...
src/main/java/kz/arta/synergy/api/asforms/pojo/AsFormDataContainer.java
View file @
034811a3
package
kz.arta.synergy.api.asforms.pojo
;
package
kz.arta.synergy.api.asforms.pojo
;
import
org.codehaus.jackson.annotate.JsonIgnoreProperties
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
...
@@ -7,6 +9,7 @@ import java.util.List;
...
@@ -7,6 +9,7 @@ import java.util.List;
* @author raimbek
* @author raimbek
* @since 10.11.2016
* @since 10.11.2016
*/
*/
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
AsFormDataContainer
{
public
class
AsFormDataContainer
{
private
List
<
AsFormData
>
data
;
private
List
<
AsFormData
>
data
;
...
...
src/main/java/kz/arta/synergy/api/asforms/pojo/AsFormWrapper.java
View file @
034811a3
package
kz.arta.synergy.api.asforms.pojo
;
package
kz.arta.synergy.api.asforms.pojo
;
import
org.codehaus.jackson.annotate.JsonIgnoreProperties
;
/**
/**
* @author raimbek
* @author raimbek
* @since 09.11.2016
* @since 09.11.2016
*/
*/
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
AsFormWrapper
extends
AsFormDataContainer
{
public
class
AsFormWrapper
extends
AsFormDataContainer
{
private
String
nodeUUID
;
private
String
nodeUUID
;
private
String
uuid
;
private
String
uuid
;
private
String
form
;
private
String
form
;
private
String
modified
;
private
String
modified
;
private
String
version
;
public
AsFormWrapper
()
{
public
AsFormWrapper
()
{
}
}
...
@@ -44,4 +48,12 @@ public class AsFormWrapper extends AsFormDataContainer {
...
@@ -44,4 +48,12 @@ public class AsFormWrapper extends AsFormDataContainer {
public
void
setModified
(
String
modified
)
{
public
void
setModified
(
String
modified
)
{
this
.
modified
=
modified
;
this
.
modified
=
modified
;
}
}
public
String
getVersion
()
{
return
version
;
}
public
void
setVersion
(
String
version
)
{
this
.
version
=
version
;
}
}
}
src/test/java/kz/arta/synergy/api/asforms/AsFormProviderTest.java
View file @
034811a3
package
kz.arta.synergy.api.asforms
;
package
kz.arta.synergy.api.asforms
;
import
kz.arta.synergy.api.
SynergyApiProvider
;
import
kz.arta.synergy.api.
QueryContext
;
import
kz.arta.synergy.api.asforms.pojo.AsFormData
;
import
kz.arta.synergy.api.asforms.pojo.AsFormData
;
import
kz.arta.synergy.api.asforms.pojo.AsFormWrapper
;
import
kz.arta.synergy.api.asforms.pojo.AsFormWrapper
;
import
kz.arta.synergy.api.asforms.pojo.ComponentTypes
;
import
kz.arta.synergy.api.asforms.pojo.ComponentTypes
;
import
kz.arta.synergy.pojo.TableCmp
;
import
kz.arta.synergy.pojo.TableCmp
;
import
kz.arta.synergy.pojo.TestForm
;
import
kz.arta.synergy.pojo.TestForm
;
import
org.mockito.Mockito
;
import
org.testng.Assert
;
import
org.testng.Assert
;
import
org.testng.annotations.BeforeClass
;
import
org.testng.annotations.BeforeClass
;
import
org.testng.annotations.Test
;
import
org.testng.annotations.Test
;
import
java.io.IOException
;
import
java.util.List
;
import
java.util.List
;
/**
/**
...
@@ -36,8 +36,8 @@ public class AsFormProviderTest {
...
@@ -36,8 +36,8 @@ public class AsFormProviderTest {
AsFormProvider
asFormProvider
;
AsFormProvider
asFormProvider
;
@BeforeClass
@BeforeClass
public
void
createAsfWrapper
()
{
public
void
createAsfWrapper
()
throws
IOException
{
AsFormWrapper
asFormWrapper
=
new
AsFormWrapper
();
/*
AsFormWrapper asFormWrapper = new AsFormWrapper();
asFormWrapper.addData(AsFormData.textbox("text_input", expectedTextInputValue));
asFormWrapper.addData(AsFormData.textbox("text_input", expectedTextInputValue));
asFormWrapper.addData(AsFormData.textbox("double_input", expectedDoubleValue));
asFormWrapper.addData(AsFormData.textbox("double_input", expectedDoubleValue));
asFormWrapper.addData(AsFormData.textbox("integer_input", expectedIntegerValue));
asFormWrapper.addData(AsFormData.textbox("integer_input", expectedIntegerValue));
...
@@ -54,11 +54,18 @@ public class AsFormProviderTest {
...
@@ -54,11 +54,18 @@ public class AsFormProviderTest {
tableData.addData(AsFormData.numericinput("table_input_2-b2", expectedTableInputValueB2, expectedTableInputValueB2));
tableData.addData(AsFormData.numericinput("table_input_2-b2", expectedTableInputValueB2, expectedTableInputValueB2));
asFormWrapper.getData().add(tableData);
asFormWrapper.getData().add(tableData);
SynergyApiProvider
synergyApiProviderMock
=
Mockito
.
mock
(
SynergyApiProvider
.
class
);
RestHttpQuery restHttpQueryMock = Mockito.mock(RestHttpQuery.class);
Mockito
.
when
(
synergyApiProviderMock
.
getAsfData
(
Mockito
.
anyString
())).
thenReturn
(
asFormWrapper
);
//Mockito.when(restHttpQueryMock.doGetQuery(Mockito.anyString())).thenReturn(asFormWrapper)
asFormProvider = AsFormProvider.newInstance(new QueryContext("localhost"));
//asFormProvider.setRestHttpQuery();
testForm = asFormProvider.fetch(TestForm.class, "123456");*/
}
asFormProvider
=
AsFormProvider
.
newInstance
(
synergyApiProviderMock
);
@Test
testForm
=
asFormProvider
.
fetch
(
TestForm
.
class
,
"123456"
);
public
void
testQuery
()
throws
IOException
{
asFormProvider
=
AsFormProvider
.
newInstance
(
new
QueryContext
(
"http://192.168.0.143:8080/Synergy"
,
"NppAdmin"
,
"123456"
));
TestForm
fetch
=
asFormProvider
.
fetch
(
TestForm
.
class
,
"2ae95419-af0e-4017-bad9-ff527591ef02"
);
System
.
out
.
println
();
}
}
@Test
@Test
...
...
src/test/java/kz/arta/synergy/api/asforms/AsFormTest.java
View file @
034811a3
package
kz.arta.synergy.api.asforms
;
package
kz.arta.synergy.api.asforms
;
import
kz.arta.synergy.api.SynergyApiProvider
;
import
org.testng.annotations.Test
;
import
org.testng.annotations.Test
;
/**
/**
...
@@ -9,8 +8,6 @@ import org.testng.annotations.Test;
...
@@ -9,8 +8,6 @@ import org.testng.annotations.Test;
*/
*/
public
class
AsFormTest
{
public
class
AsFormTest
{
private
SynergyApiProvider
synergyApiProvider
;
@Test
@Test
public
void
createAsForm
()
{
public
void
createAsForm
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment