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
c0765907
Commit
c0765907
authored
Nov 13, 2016
by
Raimbek Egemberdiev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
accrual as form
parent
0fb507c5
Changes
22
Show whitespace changes
Inline
Side-by-side
Showing
22 changed files
with
516 additions
and
25 deletions
+516
-25
src/main/java/kz/arta/synergy/api/QueryContext.java
src/main/java/kz/arta/synergy/api/QueryContext.java
+1
-1
src/main/java/kz/arta/synergy/api/RestHttpQuery.java
src/main/java/kz/arta/synergy/api/RestHttpQuery.java
+1
-1
src/main/java/kz/arta/synergy/api/asforms/AsFormService.java
src/main/java/kz/arta/synergy/api/asforms/AsFormService.java
+58
-4
src/main/java/kz/arta/synergy/api/asforms/AsfTableUtil.java
src/main/java/kz/arta/synergy/api/asforms/AsfTableUtil.java
+1
-1
src/main/java/kz/arta/synergy/api/asforms/annotations/DateCmp.java
...java/kz/arta/synergy/api/asforms/annotations/DateCmp.java
+20
-0
src/main/java/kz/arta/synergy/api/asforms/annotations/Entity.java
.../java/kz/arta/synergy/api/asforms/annotations/Entity.java
+1
-1
src/main/java/kz/arta/synergy/api/asforms/annotations/ListBox.java
...java/kz/arta/synergy/api/asforms/annotations/ListBox.java
+1
-1
src/main/java/kz/arta/synergy/api/asforms/annotations/NumericInput.java
...kz/arta/synergy/api/asforms/annotations/NumericInput.java
+1
-1
src/main/java/kz/arta/synergy/api/asforms/annotations/TextBox.java
...java/kz/arta/synergy/api/asforms/annotations/TextBox.java
+1
-1
src/main/java/kz/arta/synergy/api/asforms/converter/DefaultAsFormConverter.java
...synergy/api/asforms/converter/DefaultAsFormConverter.java
+2
-0
src/main/java/kz/arta/synergy/api/asforms/converter/components/AbstractComponentConverter.java
...orms/converter/components/AbstractComponentConverter.java
+40
-11
src/main/java/kz/arta/synergy/api/asforms/converter/components/ComponentConverter.java
.../api/asforms/converter/components/ComponentConverter.java
+1
-1
src/main/java/kz/arta/synergy/api/asforms/converter/components/DateConverter.java
...nergy/api/asforms/converter/components/DateConverter.java
+73
-0
src/main/java/kz/arta/synergy/api/asforms/converter/components/TableConverter.java
...ergy/api/asforms/converter/components/TableConverter.java
+1
-1
src/main/java/kz/arta/synergy/api/asforms/exceptions/CreateAsFormException.java
...synergy/api/asforms/exceptions/CreateAsFormException.java
+12
-0
src/main/java/kz/arta/synergy/api/asforms/exceptions/FormRecordNotFound.java
...ta/synergy/api/asforms/exceptions/FormRecordNotFound.java
+11
-0
src/main/java/kz/arta/synergy/api/asforms/exceptions/FoundTooManyRecords.java
...a/synergy/api/asforms/exceptions/FoundTooManyRecords.java
+11
-0
src/main/java/kz/arta/synergy/api/asforms/pojo/RegistryRecord.java
...java/kz/arta/synergy/api/asforms/pojo/RegistryRecord.java
+30
-0
src/main/java/kz/arta/synergy/api/asforms/pojo/SearchIndexResult.java
...a/kz/arta/synergy/api/asforms/pojo/SearchIndexResult.java
+31
-0
src/main/java/kz/arta/synergy/api/asforms/utils/SearchIndexParamsBuilder.java
...a/synergy/api/asforms/utils/SearchIndexParamsBuilder.java
+111
-0
src/main/java/kz/arta/synergy/api/services/RegistryService.java
...in/java/kz/arta/synergy/api/services/RegistryService.java
+5
-1
src/test/java/kz/arta/synergy/api/asforms/utils/SearchIndexParamsBuilderTest.java
...nergy/api/asforms/utils/SearchIndexParamsBuilderTest.java
+103
-0
No files found.
src/main/java/kz/arta/synergy/api/QueryContext.java
View file @
c0765907
...
...
@@ -4,7 +4,7 @@ import javax.xml.bind.DatatypeConverter;
/**
* Created by: Abzal Kultayev
* Date: 07.11.16
* Date
Cmp
: 07.11.16
* Time: 15:11
*
* Контекст для запросов
...
...
src/main/java/kz/arta/synergy/api/RestHttpQuery.java
View file @
c0765907
...
...
@@ -14,7 +14,7 @@ import java.util.Map;
/**
* Created by: Abzal Kultayev
* Date: 07.11.16
* Date
Cmp
: 07.11.16
* Time: 15:08
*/
public
class
RestHttpQuery
{
...
...
src/main/java/kz/arta/synergy/api/asforms/AsFormService.java
View file @
c0765907
...
...
@@ -6,10 +6,10 @@ import kz.arta.synergy.api.QueryContext;
import
kz.arta.synergy.api.RestHttpQuery
;
import
kz.arta.synergy.api.asforms.converter.AsFormConverter
;
import
kz.arta.synergy.api.asforms.converter.DefaultAsFormConverter
;
import
kz.arta.synergy.api.asforms.
pojo.AdvancedSearchParams
;
import
kz.arta.synergy.api.asforms.
pojo.AdvancedSearchResult
;
import
kz.arta.synergy.api.asforms.pojo.
AsForm
;
import
kz.arta.synergy.api.asforms.
pojo.AsFormWrapp
er
;
import
kz.arta.synergy.api.asforms.
exceptions.FormRecordNotFound
;
import
kz.arta.synergy.api.asforms.
exceptions.FoundTooManyRecords
;
import
kz.arta.synergy.api.asforms.pojo.
*
;
import
kz.arta.synergy.api.asforms.
utils.SearchIndexParamsBuild
er
;
import
org.codehaus.jackson.type.TypeReference
;
import
java.io.IOException
;
...
...
@@ -59,12 +59,66 @@ public class AsFormService {
return
JsonUtils
.
read
(
result
,
new
TypeReference
<
List
<
AdvancedSearchResult
>>()
{});
}
public
AdvancedSearchResult
advancedSearchOne
(
AdvancedSearchParams
searchParams
)
throws
IOException
,
FormRecordNotFound
,
FoundTooManyRecords
{
Query
query
=
Query
.
newInstance
()
.
methodPost
()
.
header
(
"Content-Type"
,
"application/json; charset=utf-8"
)
.
url
(
"/rest/api/asforms/search/advanced"
)
.
body
(
JsonUtils
.
toJson
(
searchParams
));
String
response
=
restHttpQuery
.
doQuery
(
query
);
List
<
AdvancedSearchResult
>
results
=
JsonUtils
.
read
(
response
,
new
TypeReference
<
List
<
AdvancedSearchResult
>>()
{});
if
(
results
==
null
||
results
.
isEmpty
())
{
throw
new
FormRecordNotFound
();
}
else
if
(
results
.
size
()
>
1
)
{
throw
new
FoundTooManyRecords
();
}
return
results
.
get
(
0
);
}
public
List
<
AdvancedSearchResult
>
advancedSearch
(
String
formId
,
String
key
,
String
value
)
throws
IOException
{
return
advancedSearch
(
AdvancedSearchParams
.
build
(
String
.
format
(
"where uuid='%s' and %s='%s'"
,
formId
,
key
,
value
),
key
));
}
public
List
<
AdvancedSearchResult
>
advancedSearchOne
(
String
formId
,
String
key
,
String
value
)
throws
IOException
{
return
advancedSearchOne
(
formId
,
key
,
value
);
}
public
SearchIndexResult
searchIndex
(
SearchIndexParamsBuilder
builder
)
throws
IOException
{
Query
query
=
Query
.
newInstance
().
url
(
"/rest/api/asforms/search_index?"
+
builder
.
build
());
String
responce
=
restHttpQuery
.
doQuery
(
query
);
return
JsonUtils
.
read
(
responce
,
SearchIndexResult
.
class
);
}
public
RegistryRecord
searchIndexOne
(
SearchIndexParamsBuilder
builder
)
throws
IOException
,
FormRecordNotFound
,
FoundTooManyRecords
{
SearchIndexResult
result
=
searchIndex
(
builder
);
if
(
result
==
null
||
result
.
getCount
()
==
0
)
{
throw
new
FormRecordNotFound
();
}
else
if
(
result
.
getCount
()
>
1
)
{
throw
new
FoundTooManyRecords
();
}
return
result
.
getRecords
().
get
(
0
);
}
public
SearchIndexResult
searchIndex
(
String
formId
,
String
key
,
String
value
)
throws
IOException
{
SearchIndexParamsBuilder
builder
=
SearchIndexParamsBuilder
.
newBuilder
()
.
form
(
formId
)
.
exact
(
key
,
value
);
return
searchIndex
(
builder
);
}
public
RegistryRecord
searchIndexOne
(
String
formId
,
String
key
,
String
value
)
throws
IOException
,
FormRecordNotFound
,
FoundTooManyRecords
{
SearchIndexParamsBuilder
builder
=
SearchIndexParamsBuilder
.
newBuilder
()
.
form
(
formId
)
.
exact
(
key
,
value
);
return
searchIndexOne
(
builder
);
}
public
<
T
extends
AsForm
>
T
getData
(
Class
<
T
>
formClass
,
String
dataUUID
)
throws
IOException
{
return
asFormConverter
.
toAsForm
(
formClass
,
getData
(
dataUUID
));
}
...
...
src/main/java/kz/arta/synergy/api/asforms/AsfTableUtil.java
View file @
c0765907
...
...
@@ -10,7 +10,7 @@ import java.util.regex.Pattern;
/**
* User: vsl
* Date: 3/18/15
* Date
Cmp
: 3/18/15
* Time: 9:48 AM
*
* Утилиты для работы с данными форм
...
...
src/main/java/kz/arta/synergy/api/asforms/annotations/DateCmp.java
0 → 100644
View file @
c0765907
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 09.11.2016
*/
@Target
(
ElementType
.
FIELD
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
public
@interface
DateCmp
{
String
value
()
default
""
;
String
format
()
default
"yyyy-MM-dd hh:mm:ss"
;
}
src/main/java/kz/arta/synergy/api/asforms/annotations/Entity.java
View file @
c0765907
...
...
@@ -13,6 +13,6 @@ import java.lang.annotation.Target;
@Retention
(
RetentionPolicy
.
RUNTIME
)
public
@interface
Entity
{
String
value
();
String
value
()
default
""
;
}
src/main/java/kz/arta/synergy/api/asforms/annotations/ListBox.java
View file @
c0765907
...
...
@@ -13,6 +13,6 @@ import java.lang.annotation.Target;
@Retention
(
RetentionPolicy
.
RUNTIME
)
public
@interface
ListBox
{
String
value
();
String
value
()
default
""
;
}
src/main/java/kz/arta/synergy/api/asforms/annotations/NumericInput.java
View file @
c0765907
...
...
@@ -13,6 +13,6 @@ import java.lang.annotation.Target;
@Retention
(
RetentionPolicy
.
RUNTIME
)
public
@interface
NumericInput
{
String
value
();
String
value
()
default
""
;
}
src/main/java/kz/arta/synergy/api/asforms/annotations/TextBox.java
View file @
c0765907
...
...
@@ -13,6 +13,6 @@ import java.lang.annotation.Target;
@Retention
(
RetentionPolicy
.
RUNTIME
)
public
@interface
TextBox
{
String
value
();
String
value
()
default
""
;
}
src/main/java/kz/arta/synergy/api/asforms/converter/DefaultAsFormConverter.java
View file @
c0765907
...
...
@@ -109,6 +109,8 @@ public class DefaultAsFormConverter implements AsFormConverter {
throw
new
CreateAsFormException
(
"Form class should has accessible without params constructor"
);
}
catch
(
IllegalAccessException
e
)
{
throw
new
CreateAsFormException
(
"Form class should be accessible"
);
}
catch
(
Exception
e
)
{
throw
new
CreateAsFormException
(
e
);
}
}
}
src/main/java/kz/arta/synergy/api/asforms/converter/components/AbstractComponentConverter.java
View file @
c0765907
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.exceptions.UnsupportedFieldTypeException
;
import
kz.arta.synergy.api.asforms.pojo.AsFormData
;
...
...
@@ -7,6 +8,8 @@ import kz.arta.synergy.api.asforms.pojo.AsFormDataContainer;
import
java.lang.annotation.Annotation
;
import
java.lang.reflect.Field
;
import
java.math.BigDecimal
;
import
java.math.BigInteger
;
/**
* @author raimbek
...
...
@@ -17,10 +20,8 @@ public abstract class AbstractComponentConverter implements ComponentConverter {
@Override
public
<
T
>
AsFormData
toAsfData
(
T
asForm
,
Field
field
,
Annotation
annotation
,
String
index
)
throws
IllegalAccessException
{
field
.
setAccessible
(
true
);
String
cmpId
=
getCmpId
(
annotation
);
if
(
index
!=
null
)
{
cmpId
=
cmpId
+
"-b"
+
index
;
}
String
cmpId
=
getCmpId
(
field
,
annotation
,
index
);
AsFormData
asFormData
=
AsFormData
.
create
(
cmpId
,
getType
(
annotation
));
Object
valueObject
=
field
.
get
(
asForm
);
...
...
@@ -36,13 +37,9 @@ public abstract class AbstractComponentConverter implements ComponentConverter {
}
@Override
public
<
T
>
void
setFieldValue
(
AsFormDataContainer
asfData
,
T
asFormObject
,
Field
field
,
Annotation
annotation
,
String
index
)
throws
IllegalAccess
Exception
{
public
<
T
>
void
setFieldValue
(
AsFormDataContainer
asfData
,
T
asFormObject
,
Field
field
,
Annotation
annotation
,
String
index
)
throws
Exception
{
field
.
setAccessible
(
true
);
String
cmpId
=
getCmpId
(
annotation
);
if
(
index
!=
null
)
{
cmpId
=
cmpId
+
"-b"
+
index
;
}
String
cmpId
=
getCmpId
(
field
,
annotation
,
index
);
if
(
field
.
getType
().
isAssignableFrom
(
String
.
class
))
{
// string
...
...
@@ -57,6 +54,14 @@ public abstract class AbstractComponentConverter implements ComponentConverter {
}
field
.
set
(
asFormObject
,
Integer
.
parseInt
(
value
));
}
else
if
(
field
.
getType
().
isAssignableFrom
(
BigInteger
.
class
))
{
// int
String
value
=
getValueForClassField
(
field
,
asfData
,
cmpId
);
if
(
value
==
null
)
{
value
=
"0"
;
}
field
.
set
(
asFormObject
,
new
BigInteger
(
value
));
}
else
if
(
field
.
getType
().
isAssignableFrom
(
Double
.
class
))
{
// double
String
value
=
getValueForClassField
(
field
,
asfData
,
cmpId
);
...
...
@@ -65,6 +70,14 @@ public abstract class AbstractComponentConverter implements ComponentConverter {
}
field
.
set
(
asFormObject
,
Double
.
parseDouble
(
value
));
}
else
if
(
field
.
getType
().
isAssignableFrom
(
BigDecimal
.
class
))
{
// double
String
value
=
getValueForClassField
(
field
,
asfData
,
cmpId
);
if
(
value
==
null
)
{
value
=
"0"
;
}
field
.
set
(
asFormObject
,
new
BigDecimal
(
value
));
}
else
if
(
field
.
getType
().
isAssignableFrom
(
AsFormData
.
class
))
{
// common type
AsFormData
data
=
asfData
.
getData
(
cmpId
);
...
...
@@ -89,6 +102,22 @@ public abstract class AbstractComponentConverter implements ComponentConverter {
}
}
protected
String
getCmpId
(
Field
field
,
Annotation
annotation
,
String
index
)
{
String
cmpId
=
getCmpId
(
annotation
);
// если id компонента пустой то используем
// название поле в качестве id компонента
if
(
Strings
.
isNullOrEmpty
(
cmpId
))
{
cmpId
=
field
.
getName
();
}
// учитываем случай с динамической таблицой
if
(
index
!=
null
)
{
cmpId
=
cmpId
+
"-b"
+
index
;
}
return
cmpId
;
}
private
String
getValueForClassField
(
Field
field
,
AsFormDataContainer
asfData
,
String
cmpId
)
{
if
(
hasKeyValueAnnotation
(
field
))
{
return
asfData
.
getKey
(
cmpId
);
...
...
@@ -96,7 +125,7 @@ public abstract class AbstractComponentConverter implements ComponentConverter {
return
asfData
.
getValue
(
cmpId
);
}
pr
ivate
boolean
hasKeyValueAnnotation
(
Field
field
)
{
pr
otected
boolean
hasKeyValueAnnotation
(
Field
field
)
{
boolean
fetchKey
=
false
;
Annotation
[]
declaredAnnotations
=
field
.
getDeclaredAnnotations
();
for
(
Annotation
annotation
:
declaredAnnotations
)
{
...
...
src/main/java/kz/arta/synergy/api/asforms/converter/components/ComponentConverter.java
View file @
c0765907
...
...
@@ -52,5 +52,5 @@ public interface ComponentConverter {
* @param <T> тип объекта формы
* @throws IllegalAccessException
*/
<
T
>
void
setFieldValue
(
AsFormDataContainer
asfData
,
T
asFormObject
,
Field
field
,
Annotation
annotation
,
String
index
)
throws
IllegalAccess
Exception
;
<
T
>
void
setFieldValue
(
AsFormDataContainer
asfData
,
T
asFormObject
,
Field
field
,
Annotation
annotation
,
String
index
)
throws
Exception
;
}
src/main/java/kz/arta/synergy/api/asforms/converter/components/DateConverter.java
0 → 100644
View file @
c0765907
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.pojo.AsFormData
;
import
kz.arta.synergy.api.asforms.pojo.AsFormDataContainer
;
import
kz.arta.synergy.api.asforms.pojo.ComponentTypes
;
import
java.lang.annotation.Annotation
;
import
java.lang.reflect.Field
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
/**
* @author raimbek
* @since 11.11.2016
*/
public
class
DateConverter
extends
AbstractComponentConverter
{
@Override
public
<
T
>
AsFormData
toAsfData
(
T
asForm
,
Field
field
,
Annotation
annotation
,
String
index
)
throws
IllegalAccessException
{
AsFormData
asFormData
=
super
.
toAsfData
(
asForm
,
field
,
annotation
,
index
);
if
(
field
.
getType
().
isAssignableFrom
(
Date
.
class
))
{
Date
date
=
(
Date
)
field
.
get
(
asForm
);
String
dateFormat
=
getDateFormat
(
annotation
);
String
dateValue
=
new
SimpleDateFormat
(
dateFormat
).
format
(
date
);
asFormData
.
setValue
(
dateValue
);
asFormData
.
setKey
(
dateValue
);
}
else
{
asFormData
.
setKey
(
String
.
valueOf
(
field
.
get
(
asForm
)));
}
return
asFormData
;
}
@Override
public
<
T
>
void
setFieldValue
(
AsFormDataContainer
asfData
,
T
asFormObject
,
Field
field
,
Annotation
annotation
,
String
index
)
throws
Exception
{
if
(
field
.
getType
().
isAssignableFrom
(
Date
.
class
))
{
field
.
setAccessible
(
true
);
String
cmpId
=
getCmpId
(
field
,
annotation
,
index
);
AsFormData
data
=
asfData
.
getData
(
cmpId
);
String
dateString
;
if
(
ComponentTypes
.
DATE
.
equals
(
data
.
getType
())
||
hasKeyValueAnnotation
(
field
))
{
dateString
=
data
.
getKey
();
}
else
{
dateString
=
data
.
getValue
();
}
if
(!
Strings
.
isNullOrEmpty
(
dateString
))
{
String
dateFormat
=
getDateFormat
(
annotation
);
Date
date
=
new
SimpleDateFormat
(
dateFormat
).
parse
(
dateString
);
field
.
set
(
asFormObject
,
date
);
}
}
else
{
super
.
setFieldValue
(
asfData
,
asFormObject
,
field
,
annotation
,
index
);
}
}
private
String
getDateFormat
(
Annotation
annotation
)
{
return
((
DateCmp
)
annotation
).
format
();
}
@Override
public
String
getType
(
Annotation
annotation
)
{
return
ComponentTypes
.
DATE
;
}
@Override
public
String
getCmpId
(
Annotation
annotation
)
{
return
((
DateCmp
)
annotation
).
value
();
}
}
src/main/java/kz/arta/synergy/api/asforms/converter/components/TableConverter.java
View file @
c0765907
...
...
@@ -44,7 +44,7 @@ public class TableConverter extends AbstractComponentConverter {
}
@Override
public
<
T
>
void
setFieldValue
(
AsFormDataContainer
asfData
,
T
asFormObject
,
Field
field
,
Annotation
annotation
,
String
index
)
throws
IllegalAccess
Exception
{
public
<
T
>
void
setFieldValue
(
AsFormDataContainer
asfData
,
T
asFormObject
,
Field
field
,
Annotation
annotation
,
String
index
)
throws
Exception
{
Table
tableAnnotation
=
(
Table
)
annotation
;
if
(
field
.
getType
().
isAssignableFrom
(
AsFormData
.
class
))
{
super
.
setFieldValue
(
asfData
,
asFormObject
,
field
,
tableAnnotation
,
index
);
...
...
src/main/java/kz/arta/synergy/api/asforms/exceptions/CreateAsFormException.java
View file @
c0765907
...
...
@@ -9,4 +9,16 @@ public class CreateAsFormException extends RuntimeException {
public
CreateAsFormException
(
String
message
)
{
super
(
message
);
}
public
CreateAsFormException
(
String
message
,
Throwable
cause
)
{
super
(
message
,
cause
);
}
public
CreateAsFormException
(
Throwable
cause
)
{
super
(
cause
);
}
public
CreateAsFormException
(
String
message
,
Throwable
cause
,
boolean
enableSuppression
,
boolean
writableStackTrace
)
{
super
(
message
,
cause
,
enableSuppression
,
writableStackTrace
);
}
}
src/main/java/kz/arta/synergy/api/asforms/exceptions/FormRecordNotFound.java
0 → 100644
View file @
c0765907
package
kz.arta.synergy.api.asforms.exceptions
;
public
class
FormRecordNotFound
extends
Exception
{
public
FormRecordNotFound
()
{
super
(
"Form record not found"
);
}
public
FormRecordNotFound
(
String
message
)
{
super
(
message
);
}
}
src/main/java/kz/arta/synergy/api/asforms/exceptions/FoundTooManyRecords.java
0 → 100644
View file @
c0765907
package
kz.arta.synergy.api.asforms.exceptions
;
public
class
FoundTooManyRecords
extends
Exception
{
public
FoundTooManyRecords
()
{
super
(
"Found too many records"
);
}
public
FoundTooManyRecords
(
String
message
)
{
super
(
message
);
}
}
src/main/java/kz/arta/synergy/api/asforms/pojo/RegistryRecord.java
0 → 100644
View file @
c0765907
package
kz.arta.synergy.api.asforms.pojo
;
import
org.codehaus.jackson.annotate.JsonIgnoreProperties
;
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
RegistryRecord
{
private
String
dataUUID
;
private
String
documentID
;
public
RegistryRecord
()
{
}
public
String
getDataUUID
()
{
return
dataUUID
;
}
public
void
setDataUUID
(
String
dataUUID
)
{
this
.
dataUUID
=
dataUUID
;
}
public
String
getDocumentID
()
{
return
documentID
;
}
public
void
setDocumentID
(
String
documentID
)
{
this
.
documentID
=
documentID
;
}
}
src/main/java/kz/arta/synergy/api/asforms/pojo/SearchIndexResult.java
0 → 100644
View file @
c0765907
package
kz.arta.synergy.api.asforms.pojo
;
import
org.codehaus.jackson.annotate.JsonIgnoreProperties
;
import
java.util.List
;
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
SearchIndexResult
{
private
int
count
;
private
List
<
RegistryRecord
>
records
;
public
SearchIndexResult
()
{
}
public
int
getCount
()
{
return
count
;
}
public
void
setCount
(
int
count
)
{
this
.
count
=
count
;
}
public
List
<
RegistryRecord
>
getRecords
()
{
return
records
;
}
public
void
setRecords
(
List
<
RegistryRecord
>
records
)
{
this
.
records
=
records
;
}
}
src/main/java/kz/arta/synergy/api/asforms/utils/SearchIndexParamsBuilder.java
0 → 100644
View file @
c0765907
package
kz.arta.synergy.api.asforms.utils
;
import
java.util.HashMap
;
import
java.util.Map
;
public
class
SearchIndexParamsBuilder
{
private
String
form
;
private
String
term
=
"and"
;
private
Integer
startRecord
=
null
;
private
Integer
recordsCount
=
null
;
private
Boolean
showDeleted
=
null
;
private
Boolean
searchInRegistry
=
null
;
private
Map
<
String
,
String
>
typeExactParams
=
new
HashMap
<>();
private
Map
<
String
,
String
>
typePartialParams
=
new
HashMap
<>();
private
SearchIndexParamsBuilder
()
{
}
public
static
SearchIndexParamsBuilder
newBuilder
()
{
return
new
SearchIndexParamsBuilder
();
}
public
SearchIndexParamsBuilder
form
(
String
formId
)
{
this
.
form
=
formId
;
return
this
;
}
public
SearchIndexParamsBuilder
termOr
()
{
this
.
term
=
"or"
;
return
this
;
}
public
SearchIndexParamsBuilder
showDeleted
(
boolean
showDeleted
)
{
this
.
showDeleted
=
showDeleted
;
return
this
;
}
public
SearchIndexParamsBuilder
searchInRegistry
(
boolean
searchInRegistry
)
{
this
.
searchInRegistry
=
searchInRegistry
;
return
this
;
}
public
SearchIndexParamsBuilder
startRecord
(
int
startRecord
)
{
this
.
startRecord
=
startRecord
;
return
this
;
}
public
SearchIndexParamsBuilder
recordsCount
(
int
recordsCount
)
{
this
.
recordsCount
=
recordsCount
;
return
this
;
}
public
SearchIndexParamsBuilder
exact
(
String
field
,
String
search
)
{
typeExactParams
.
put
(
field
,
search
);
return
this
;
}
public
SearchIndexParamsBuilder
partial
(
String
field
,
String
search
)
{
typePartialParams
.
put
(
field
,
search
);
return
this
;
}
public
String
build
()
{
String
params
=
""
;
params
+=
searchParams
(
typeExactParams
,
"exact"
,
0
);
params
+=
searchParams
(
typePartialParams
,
"partial"
,
typeExactParams
.
size
());
params
+=
getParam
(
"startRecord"
,
startRecord
)
+
getParam
(
"recordsCount"
,
recordsCount
)
+
getParam
(
"showDeleted"
,
showDeleted
)
+
getParam
(
"searchInRegistry"
,
searchInRegistry
)
+
getParam
(
"term"
,
term
);
params
=
params
.
substring
(
0
,
params
.
length
()
-
1
);
return
params
;
}
private
String
searchParams
(
Map
<
String
,
String
>
params
,
String
type
,
int
index
)
{
String
result
=
""
;
for
(
Map
.
Entry
<
String
,
String
>
entry
:
params
.
entrySet
())
{
String
indexString
=
""
;
if
(
index
!=
0
)
{
indexString
=
String
.
valueOf
(
index
);
}
result
+=
String
.
format
(
"formUUID%s=%s&field%s=%s&search%s=%s&type%s=%s&"
,
indexString
,
form
,
indexString
,
entry
.
getKey
(),
indexString
,
entry
.
getValue
(),
indexString
,
type
);
index
++;
}
return
result
;
}
private
String
getParam
(
String
name
,
Object
value
)
{
if
(
value
==
null
||
String
.
valueOf
(
value
).
isEmpty
())
{
return
""
;
}
return
name
+
"="
+
value
+
"&"
;
}
}
src/main/java/kz/arta/synergy/api/services/RegistryService.java
View file @
c0765907
...
...
@@ -9,7 +9,7 @@ import java.io.IOException;
/**
* Created by: Abzal Kultayev
* Date: 11.11.16
* Date
Cmp
: 11.11.16
* Time: 18:17
*/
public
class
RegistryService
{
...
...
@@ -31,4 +31,8 @@ public class RegistryService {
String
response
=
restHttpQuery
.
doQuery
(
query
);
return
JsonUtils
.
readTree
(
response
).
get
(
"dataUUID"
).
getTextValue
();
}
public
void
activateRecord
(
String
dataUUID
)
{
}
}
src/test/java/kz/arta/synergy/api/asforms/utils/SearchIndexParamsBuilderTest.java
0 → 100644
View file @
c0765907
package
kz.arta.synergy.api.asforms.utils
;
import
org.testng.Assert
;
import
org.testng.annotations.Test
;
public
class
SearchIndexParamsBuilderTest
{
@Test
public
void
testBuildWithOneExactParam
()
throws
Exception
{
String
searchParams
=
SearchIndexParamsBuilder
.
newBuilder
()
.
form
(
"123"
)
.
startRecord
(
2
)
.
recordsCount
(
3
)
.
exact
(
"one"
,
"value_one"
)
.
build
();
Assert
.
assertEquals
(
searchParams
,
"formUUID=123&field=one&search=value_one&type=exact&startRecord=2&recordsCount=3&term=and"
);
}
@Test
public
void
testBuildWithOnePartialParam
()
throws
Exception
{
String
searchParams
=
SearchIndexParamsBuilder
.
newBuilder
()
.
form
(
"123"
)
.
startRecord
(
2
)
.
recordsCount
(
3
)
.
partial
(
"one"
,
"value_one"
)
.
build
();
Assert
.
assertEquals
(
searchParams
,
"formUUID=123&field=one&search=value_one&type=partial&startRecord=2&recordsCount=3&term=and"
);
}
@Test
public
void
testBuildTermOr
()
throws
Exception
{
String
searchParams
=
SearchIndexParamsBuilder
.
newBuilder
()
.
form
(
"123"
)
.
termOr
()
.
startRecord
(
2
)
.
recordsCount
(
3
)
.
partial
(
"one"
,
"value_one"
)
.
build
();
Assert
.
assertEquals
(
searchParams
,
"formUUID=123&field=one&search=value_one&type=partial&startRecord=2&recordsCount=3&term=or"
);
}
@Test
public
void
testBuildWithShowDeleted
()
throws
Exception
{
String
searchParams
=
SearchIndexParamsBuilder
.
newBuilder
()
.
form
(
"123"
)
.
exact
(
"one"
,
"value_one"
)
.
showDeleted
(
true
)
.
build
();
Assert
.
assertEquals
(
searchParams
,
"formUUID=123&field=one&search=value_one&type=exact&showDeleted=true&term=and"
);
}
@Test
public
void
testBuildWithSearchInRegistry
()
throws
Exception
{
String
searchParams
=
SearchIndexParamsBuilder
.
newBuilder
()
.
form
(
"123"
)
.
exact
(
"one"
,
"value_one"
)
.
searchInRegistry
(
true
)
.
build
();
Assert
.
assertEquals
(
searchParams
,
"formUUID=123&field=one&search=value_one&type=exact&searchInRegistry=true&term=and"
);
}
@Test
public
void
testBuildWithMultipleParams
()
throws
Exception
{
String
searchParams
=
SearchIndexParamsBuilder
.
newBuilder
()
.
form
(
"123"
)
.
startRecord
(
2
)
.
recordsCount
(
3
)
.
exact
(
"one"
,
"value_one"
)
.
partial
(
"two"
,
"value_two"
)
.
partial
(
"three"
,
"value_three"
)
.
exact
(
"four"
,
"value_four"
)
.
build
();
Assert
.
assertEquals
(
searchParams
,
"formUUID=123&field=one&search=value_one&type=exact&"
+
"formUUID1=123&field1=four&search1=value_four&type1=exact&"
+
"formUUID2=123&field2=two&search2=value_two&type2=partial&"
+
"formUUID3=123&field3=three&search3=value_three&type3=partial&"
+
"startRecord=2&recordsCount=3&term=and"
);
}
}
\ No newline at end of file
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