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
9ad35fe6
Commit
9ad35fe6
authored
Nov 10, 2016
by
Raimbek Egemberdiev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
query context
parent
f5ebfd9a
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
156 additions
and
61 deletions
+156
-61
build.gradle
build.gradle
+1
-0
src/main/java/kz/arta/synergy/api/ConfigProvider.java
src/main/java/kz/arta/synergy/api/ConfigProvider.java
+0
-8
src/main/java/kz/arta/synergy/api/QueryContext.java
src/main/java/kz/arta/synergy/api/QueryContext.java
+65
-0
src/main/java/kz/arta/synergy/api/RestHttpQuery.java
src/main/java/kz/arta/synergy/api/RestHttpQuery.java
+83
-0
src/main/java/kz/arta/synergy/api/SynergyApiProvider.java
src/main/java/kz/arta/synergy/api/SynergyApiProvider.java
+0
-18
src/main/java/kz/arta/synergy/api/asforms/AsFormProvider.java
...main/java/kz/arta/synergy/api/asforms/AsFormProvider.java
+7
-13
src/main/java/kz/arta/synergy/api/asforms/annotations/Form.java
...in/java/kz/arta/synergy/api/asforms/annotations/Form.java
+0
-21
src/test/java/kz/arta/synergy/pojo/TestForm.java
src/test/java/kz/arta/synergy/pojo/TestForm.java
+0
-1
No files found.
build.gradle
View file @
9ad35fe6
...
@@ -13,4 +13,5 @@ dependencies {
...
@@ -13,4 +13,5 @@ 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'
}
}
src/main/java/kz/arta/synergy/api/ConfigProvider.java
deleted
100644 → 0
View file @
f5ebfd9a
package
kz.arta.synergy.api
;
/**
* @author raimbek
* @since 10.11.2016
*/
public
class
ConfigProvider
{
}
src/main/java/kz/arta/synergy/api/QueryContext.java
0 → 100644
View file @
9ad35fe6
package
kz.arta.synergy.api
;
import
javax.xml.bind.DatatypeConverter
;
/**
* Created by: Abzal Kultayev
* Date: 07.11.16
* Time: 15:11
*
* Контекст для запросов
*/
public
class
QueryContext
{
/**
* Адрес сервера
*/
private
String
address
;
/**
* Логин пользователя
*/
private
String
login
;
/**
* Пароль пользователя
*/
private
String
password
;
public
QueryContext
(
String
address
)
{
this
.
address
=
address
;
}
public
QueryContext
(
String
address
,
String
login
,
String
password
)
{
this
.
address
=
address
;
this
.
login
=
login
;
this
.
password
=
password
;
}
public
String
getAddress
()
{
return
address
;
}
public
void
setAddress
(
String
address
)
{
this
.
address
=
address
;
}
public
String
getLogin
()
{
return
login
;
}
public
void
setLogin
(
String
login
)
{
this
.
login
=
login
;
}
public
String
getPassword
()
{
return
password
;
}
public
void
setPassword
(
String
password
)
{
this
.
password
=
password
;
}
public
String
getAuthHeader
()
{
return
DatatypeConverter
.
printBase64Binary
((
getLogin
()
+
":"
+
getPassword
()).
getBytes
());
}
}
src/main/java/kz/arta/synergy/api/RestHttpQuery.java
0 → 100644
View file @
9ad35fe6
package
kz.arta.synergy.api
;
import
com.google.common.base.Function
;
import
com.google.common.base.Joiner
;
import
com.google.common.base.Predicates
;
import
com.google.common.collect.FluentIterable
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.io.UnsupportedEncodingException
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.net.URLEncoder
;
import
java.util.Map
;
/**
* Created by: Abzal Kultayev
* Date: 07.11.16
* Time: 15:08
*/
public
class
RestHttpQuery
{
public
static
final
int
TIMEOUT
=
10
*
60
*
1000
;
public
String
doGetQuery
(
QueryContext
context
,
String
query
)
throws
IOException
{
URL
url
=
new
URL
(
context
.
getAddress
()
+
query
);
HttpURLConnection
conn
=
(
HttpURLConnection
)
url
.
openConnection
();
conn
.
setConnectTimeout
(
TIMEOUT
);
conn
.
setReadTimeout
(
TIMEOUT
);
conn
.
setRequestMethod
(
"GET"
);
conn
.
setRequestProperty
(
"Accept"
,
"application/json; charset=utf-8"
);
authentication
(
context
,
conn
);
return
readStringReturn
(
conn
);
}
public
String
doGetQuery
(
QueryContext
context
,
String
query
,
Map
<
String
,
?>
params
)
throws
IOException
{
return
doGetQuery
(
context
,
makeQuery
(
query
,
params
));
}
private
String
makeQuery
(
String
query
,
Map
<
String
,
?>
params
)
{
String
joined
=
joinParamsForQuery
(
params
);
if
(!
joined
.
isEmpty
())
return
query
+
"?"
+
joined
;
return
query
;
}
private
String
joinParamsForQuery
(
Map
<
String
,
?>
params
)
{
if
(
params
==
null
)
return
""
;
return
FluentIterable
.
from
(
params
.
entrySet
()).
transform
(
new
Function
<
Map
.
Entry
<
String
,
?>,
String
>()
{
@Override
public
String
apply
(
Map
.
Entry
<
String
,
?>
input
)
{
String
value
=
input
.
getValue
().
toString
();
try
{
value
=
URLEncoder
.
encode
(
value
,
"UTF-8"
);
}
catch
(
UnsupportedEncodingException
e
)
{
value
=
null
;
}
if
(
value
==
null
||
value
.
isEmpty
())
return
null
;
return
input
.
getKey
()
+
"="
+
value
;
}
}).
filter
(
Predicates
.
notNull
()).
join
(
Joiner
.
on
(
"&"
));
}
private
String
readStringReturn
(
HttpURLConnection
conn
)
throws
IOException
{
String
output
;
StringBuilder
result
=
new
StringBuilder
();
BufferedReader
br
=
new
BufferedReader
(
new
InputStreamReader
(
conn
.
getInputStream
(),
"UTF-8"
));
while
((
output
=
br
.
readLine
())
!=
null
)
{
result
.
append
(
output
);
}
conn
.
disconnect
();
return
result
.
toString
();
}
private
void
authentication
(
QueryContext
context
,
HttpURLConnection
conn
)
{
if
(
context
.
getLogin
()
!=
null
&&
context
.
getPassword
()
!=
null
)
{
conn
.
setRequestProperty
(
"Authorization"
,
"Basic "
+
context
.
getAuthHeader
());
}
}
}
src/main/java/kz/arta/synergy/api/SynergyApiProvider.java
deleted
100644 → 0
View file @
f5ebfd9a
package
kz.arta.synergy.api
;
import
kz.arta.synergy.api.asforms.exceptions.SynergyApiCallException
;
import
kz.arta.synergy.api.asforms.pojo.AsFormWrapper
;
/**
* @author raimbek
* @since 09.11.2016
*/
public
class
SynergyApiProvider
{
public
AsFormWrapper
getAsfData
(
String
dataUUID
)
throws
SynergyApiCallException
{
return
new
AsFormWrapper
();
}
public
String
saveData
(
AsFormWrapper
asfData
)
{
return
null
;
}
}
src/main/java/kz/arta/synergy/api/asforms/AsFormProvider.java
View file @
9ad35fe6
package
kz.arta.synergy.api.asforms
;
package
kz.arta.synergy.api.asforms
;
import
kz.arta.synergy.api.SynergyApiProvider
;
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
;
...
@@ -18,25 +17,20 @@ import java.util.Set;
...
@@ -18,25 +17,20 @@ import java.util.Set;
*/
*/
public
class
AsFormProvider
{
public
class
AsFormProvider
{
private
SynergyApiProvider
synergyApiProvider
;
private
AsFormProvider
()
{
private
AsFormProvider
()
{
}
}
public
static
AsFormProvider
newInstance
(
SynergyApiProvider
synergyApiProvider
)
{
public
static
AsFormProvider
newInstance
()
{
AsFormProvider
asFormProvider
=
new
AsFormProvider
();
return
new
AsFormProvider
();
asFormProvider
.
synergyApiProvider
=
synergyApiProvider
;
return
asFormProvider
;
}
}
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) {
AsFormWrapper
asfData
=
synergyApiProvider
.
getAsfData
(
dataUUID
);
return create(formClass, asfData);
return create(formClass, asfData);
}
}
*/
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
);
...
@@ -47,9 +41,9 @@ public class AsFormProvider {
...
@@ -47,9 +41,9 @@ public class AsFormProvider {
return
asForm
;
return
asForm
;
}
}
public
<
T
extends
AsForm
>
String
save
(
T
asForm
)
{
/*
public <T extends AsForm> String save(T asForm) {
return
synergyApiProvider
.
saveData
(
toAsfData
(
asForm
));
}
}
*/
public
<
T
extends
AsForm
>
AsFormWrapper
toAsfData
(
T
asForm
)
{
public
<
T
extends
AsForm
>
AsFormWrapper
toAsfData
(
T
asForm
)
{
AsFormWrapper
asFormWrapper
=
new
AsFormWrapper
();
AsFormWrapper
asFormWrapper
=
new
AsFormWrapper
();
...
...
src/main/java/kz/arta/synergy/api/asforms/annotations/Form.java
deleted
100644 → 0
View file @
f5ebfd9a
package
kz.arta.synergy.api.asforms.annotations
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
/**
* @author raimbek
* @since 10.11.2016
*/
@Target
(
ElementType
.
TYPE
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
public
@interface
Form
{
String
id
()
default
""
;
String
code
()
default
""
;
String
config
()
default
""
;
}
src/test/java/kz/arta/synergy/pojo/TestForm.java
View file @
9ad35fe6
...
@@ -11,7 +11,6 @@ import java.util.List;
...
@@ -11,7 +11,6 @@ import java.util.List;
* @author raimbek
* @author raimbek
* @since 09.11.2016
* @since 09.11.2016
*/
*/
@Form
(
config
=
"application_form"
)
public
class
TestForm
extends
AsForm
{
public
class
TestForm
extends
AsForm
{
@TextInput
(
"text_input"
)
@TextInput
(
"text_input"
)
...
...
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