Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Register
Sign in
Toggle navigation
Menu
UPSMF
uphrh-smf-form
Commits
ef15e4d2
Commit
ef15e4d2
authored
2 years ago
by
shishir suman
Browse files
Options
Download
Patches
Plain Diff
changes for csv download
parent
af84506c
master
cvs_download
delete-form
1 merge request
!9
Cvs download
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
pom.xml
+6
-1
pom.xml
src/main/java/com/tarento/formservice/controllers/FormsController.java
+17
-10
.../com/tarento/formservice/controllers/FormsController.java
src/main/java/com/tarento/formservice/model/InstituteCSVResponseDto.java
+11
-0
...om/tarento/formservice/model/InstituteCSVResponseDto.java
src/main/java/com/tarento/formservice/model/InstituteDownloadRequestDto.java
+15
-0
...arento/formservice/model/InstituteDownloadRequestDto.java
src/main/java/com/tarento/formservice/repository/ElasticSearchRepository.java
+13
-0
...rento/formservice/repository/ElasticSearchRepository.java
src/main/java/com/tarento/formservice/service/FormsService.java
+3
-9
...in/java/com/tarento/formservice/service/FormsService.java
src/main/java/com/tarento/formservice/service/impl/FormsServiceImpl.java
+62
-17
...om/tarento/formservice/service/impl/FormsServiceImpl.java
src/main/java/com/tarento/formservice/utils/CloudStorage.java
+1
-1
...main/java/com/tarento/formservice/utils/CloudStorage.java
src/main/java/com/tarento/formservice/utils/PathRoutes.java
+1
-0
src/main/java/com/tarento/formservice/utils/PathRoutes.java
src/main/resources/application.properties
+5
-5
src/main/resources/application.properties
with
134 additions
and
43 deletions
+134
-43
pom.xml
+
6
−
1
View file @
ef15e4d2
...
...
@@ -44,7 +44,12 @@
<artifactId>
javax.mail
</artifactId>
<version>
1.6.0
</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.opencsv/opencsv -->
<dependency>
<groupId>
com.opencsv
</groupId>
<artifactId>
opencsv
</artifactId>
<version>
5.7.1
</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
<dependency>
<groupId>
org.apache.poi
</groupId>
...
...
This diff is collapsed.
Click to expand it.
src/main/java/com/tarento/formservice/controllers/FormsController.java
+
17
−
10
View file @
ef15e4d2
...
...
@@ -6,6 +6,7 @@ import java.util.HashMap;
import
java.util.List
;
import
java.util.Map
;
import
com.tarento.formservice.model.*
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.tomcat.util.codec.binary.Base64
;
import
org.slf4j.Logger
;
...
...
@@ -24,16 +25,6 @@ import org.springframework.web.multipart.MultipartFile;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.google.gson.Gson
;
import
com.tarento.formservice.model.AssignApplication
;
import
com.tarento.formservice.model.Consent
;
import
com.tarento.formservice.model.FormData
;
import
com.tarento.formservice.model.IncomingData
;
import
com.tarento.formservice.model.KeyValue
;
import
com.tarento.formservice.model.KeyValueList
;
import
com.tarento.formservice.model.SearchObject
;
import
com.tarento.formservice.model.SearchRequestDto
;
import
com.tarento.formservice.model.Status
;
import
com.tarento.formservice.model.UserInfo
;
import
com.tarento.formservice.models.Form
;
import
com.tarento.formservice.models.FormDetail
;
import
com.tarento.formservice.service.FormsService
;
...
...
@@ -169,6 +160,22 @@ public class FormsController {
return
ResponseGenerator
.
failureResponse
(
Constants
.
ResponseMessages
.
ERROR_MESSAGE
);
}
@PostMapping
(
value
=
PathRoutes
.
FormServiceApi
.
GET_INSTITUTE_DATA
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
public
String
getInstituteData
(
@RequestHeader
(
value
=
Constants
.
Parameters
.
X_USER_INFO
,
required
=
false
)
String
xUserInfo
,
@RequestBody
InstituteDownloadRequestDto
instituteDownloadRequestDto
)
throws
JsonProcessingException
{
List
<
Map
<
String
,
Object
>>
responseData
=
new
ArrayList
<>();
UserInfo
userInfo
=
null
;
if
(
StringUtils
.
isNotBlank
(
xUserInfo
))
{
userInfo
=
new
Gson
().
fromJson
(
xUserInfo
,
UserInfo
.
class
);
}
responseData
=
formsService
.
getInstitutesData
(
userInfo
,
instituteDownloadRequestDto
);
if
(
responseData
!=
null
)
{
return
ResponseGenerator
.
successResponse
(
responseData
);
}
return
ResponseGenerator
.
failureResponse
(
Constants
.
ResponseMessages
.
ERROR_MESSAGE
);
}
@GetMapping
(
value
=
PathRoutes
.
FormServiceApi
.
GET_APPLICATIONS_STATUS_COUNT
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
public
String
getApplicationsStatusCount
(
@RequestHeader
(
value
=
Constants
.
Parameters
.
X_USER_INFO
,
required
=
false
)
String
xUserInfo
)
...
...
This diff is collapsed.
Click to expand it.
src/main/java/com/tarento/formservice/model/InstituteCSVResponseDto.java
0 → 100644
+
11
−
0
View file @
ef15e4d2
package
com.tarento.formservice.model
;
import
lombok.Getter
;
import
lombok.Setter
;
@Getter
@Setter
public
class
InstituteCSVResponseDto
{
private
String
data
;
}
This diff is collapsed.
Click to expand it.
src/main/java/com/tarento/formservice/model/InstituteDownloadRequestDto.java
0 → 100644
+
15
−
0
View file @
ef15e4d2
package
com.tarento.formservice.model
;
import
lombok.Getter
;
import
lombok.Setter
;
import
java.util.List
;
@Getter
@Setter
public
class
InstituteDownloadRequestDto
{
private
Integer
page
;
private
Integer
size
;
}
This diff is collapsed.
Click to expand it.
src/main/java/com/tarento/formservice/repository/ElasticSearchRepository.java
+
13
−
0
View file @
ef15e4d2
...
...
@@ -25,6 +25,8 @@ import org.elasticsearch.client.RequestOptions;
import
org.elasticsearch.client.RestClient
;
import
org.elasticsearch.client.RestClientBuilder.HttpClientConfigCallback
;
import
org.elasticsearch.client.RestHighLevelClient
;
import
org.elasticsearch.client.core.CountRequest
;
import
org.elasticsearch.client.core.CountResponse
;
import
org.elasticsearch.common.xcontent.XContentType
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -268,4 +270,15 @@ public class ElasticSearchRepository {
}
return
response
;
}
public
CountResponse
executeCountRequest
(
CountRequest
countRequest
)
{
CountResponse
response
=
null
;
try
{
response
=
client
.
count
(
countRequest
,
RequestOptions
.
DEFAULT
);
}
catch
(
IOException
e
)
{
LOGGER
.
error
(
marker
,
"Encountered an error while connecting : "
,
e
);
LOGGER
.
error
(
marker
,
"Error Message to report : {}"
,
e
.
getMessage
());
}
return
response
;
}
}
This diff is collapsed.
Click to expand it.
src/main/java/com/tarento/formservice/service/FormsService.java
+
3
−
9
View file @
ef15e4d2
...
...
@@ -5,17 +5,9 @@ import java.util.List;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentMap
;
import
com.tarento.formservice.model.*
;
import
org.springframework.web.multipart.MultipartFile
;
import
com.tarento.formservice.model.AssignApplication
;
import
com.tarento.formservice.model.Consent
;
import
com.tarento.formservice.model.IncomingData
;
import
com.tarento.formservice.model.KeyValueList
;
import
com.tarento.formservice.model.ResponseData
;
import
com.tarento.formservice.model.SearchRequestDto
;
import
com.tarento.formservice.model.State
;
import
com.tarento.formservice.model.StateMatrix
;
import
com.tarento.formservice.model.UserInfo
;
import
com.tarento.formservice.models.Form
;
import
com.tarento.formservice.models.FormDetail
;
...
...
@@ -43,6 +35,8 @@ public interface FormsService {
List
<
Map
<
String
,
Object
>>
getAllPlainForms
();
List
<
Map
<
String
,
Object
>>
getInstitutesData
(
UserInfo
userInfo
,
InstituteDownloadRequestDto
instituteDownloadRequestDto
);
KeyValueList
getApplicationsStatusCount
(
UserInfo
userInfo
);
public
Boolean
saveFormSubmitv1
(
IncomingData
incomingData
,
UserInfo
userInfo
,
String
action
);
...
...
This diff is collapsed.
Click to expand it.
src/main/java/com/tarento/formservice/service/impl/FormsServiceImpl.java
+
62
−
17
View file @
ef15e4d2
...
...
@@ -13,10 +13,13 @@ import java.util.Random;
import
java.util.concurrent.ConcurrentMap
;
import
java.util.stream.Collectors
;
import
com.tarento.formservice.model.*
;
import
org.apache.commons.lang3.StringUtils
;
import
org.elasticsearch.action.search.MultiSearchResponse
;
import
org.elasticsearch.action.search.SearchRequest
;
import
org.elasticsearch.action.search.SearchResponse
;
import
org.elasticsearch.client.core.CountRequest
;
import
org.elasticsearch.client.core.CountResponse
;
import
org.elasticsearch.index.query.BoolQueryBuilder
;
import
org.elasticsearch.index.query.QueryBuilders
;
import
org.elasticsearch.index.query.RangeQueryBuilder
;
...
...
@@ -48,23 +51,6 @@ import com.fasterxml.jackson.databind.JsonNode;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.google.gson.Gson
;
import
com.tarento.formservice.dao.FormsDao
;
import
com.tarento.formservice.model.AssignApplication
;
import
com.tarento.formservice.model.Assignee
;
import
com.tarento.formservice.model.Consent
;
import
com.tarento.formservice.model.IncomingData
;
import
com.tarento.formservice.model.KeyValue
;
import
com.tarento.formservice.model.KeyValueList
;
import
com.tarento.formservice.model.ResponseData
;
import
com.tarento.formservice.model.Result
;
import
com.tarento.formservice.model.Role
;
import
com.tarento.formservice.model.Roles
;
import
com.tarento.formservice.model.SearchObject
;
import
com.tarento.formservice.model.SearchRequestDto
;
import
com.tarento.formservice.model.State
;
import
com.tarento.formservice.model.StateMatrix
;
import
com.tarento.formservice.model.Status
;
import
com.tarento.formservice.model.UserInfo
;
import
com.tarento.formservice.model.WorkflowDto
;
import
com.tarento.formservice.models.Field
;
import
com.tarento.formservice.models.Form
;
import
com.tarento.formservice.models.FormDetail
;
...
...
@@ -380,6 +366,65 @@ public class FormsServiceImpl implements FormsService {
return
null
;
}
@Override
public
List
<
Map
<
String
,
Object
>>
getInstitutesData
(
UserInfo
userInfo
,
InstituteDownloadRequestDto
instituteDownloadRequestDto
)
{
try
{
// count builder
CountRequest
countRequest
=
new
CountRequest
(
appConfig
.
getFormDataIndex
()).
query
(
QueryBuilders
.
matchAllQuery
());
CountResponse
countResponse
=
elasticRepository
.
executeCountRequest
(
countRequest
);
LOGGER
.
debug
(
"count Response : {}"
,
countResponse
);
if
(
countResponse
==
null
||
countResponse
.
getCount
()
<=
0
)
{
// no data in index
return
null
;
}
// query builder
SearchSourceBuilder
searchSourceBuilder
=
new
SearchSourceBuilder
();
// setting size and range in query
setSizeAndRangeLimit
(
instituteDownloadRequestDto
,
searchSourceBuilder
,
countResponse
);
// creating bool query
BoolQueryBuilder
boolBuilder
=
QueryBuilders
.
boolQuery
();
boolBuilder
.
must
(
QueryBuilders
.
matchAllQuery
());
searchSourceBuilder
.
query
(
boolBuilder
).
sort
(
Constants
.
TIMESTAMP
,
SortOrder
.
DESC
);
// es call
SearchRequest
searchRequest
=
new
SearchRequest
(
appConfig
.
getFormDataIndex
()).
source
(
searchSourceBuilder
);
LOGGER
.
info
(
"Search Request : "
+
searchRequest
);
return
formsDao
.
searchResponse
(
searchRequest
);
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
String
.
format
(
Constants
.
EXCEPTION
,
"getApplications"
,
e
.
getMessage
()));
}
return
null
;
}
private
static
void
setSizeAndRangeLimit
(
InstituteDownloadRequestDto
instituteDownloadRequestDto
,
SearchSourceBuilder
searchSourceBuilder
,
CountResponse
countResponse
)
{
// setting from limit if size is present in request
if
(
instituteDownloadRequestDto
.
getSize
()
!=
null
&&
instituteDownloadRequestDto
.
getSize
()
>
0
)
{
searchSourceBuilder
.
size
(
instituteDownloadRequestDto
.
getSize
());
int
fromRange
=
0
;
if
(
instituteDownloadRequestDto
.
getPage
()
==
0
)
{
fromRange
=
instituteDownloadRequestDto
.
getSize
()*(
instituteDownloadRequestDto
.
getPage
());
}
else
if
(
instituteDownloadRequestDto
.
getPage
()
>
0
)
{
fromRange
=
instituteDownloadRequestDto
.
getSize
()*(
instituteDownloadRequestDto
.
getPage
()-
1
);
}
searchSourceBuilder
.
from
(
fromRange
);
}
else
{
int
count
=
Long
.
valueOf
(
countResponse
.
getCount
()).
intValue
();
searchSourceBuilder
.
size
(
count
);
}
}
public
InstituteCSVResponseDto
createCSVFile
(
List
<
Map
<
String
,
Object
>>
instituteData
)
{
if
(
instituteData
==
null
||
instituteData
.
isEmpty
())
{
//return error
}
for
(
Map
<
String
,
Object
>
data
:
instituteData
)
{
System
.
out
.
print
(
"data : "
+
data
);
}
return
null
;
}
/**
* Add filters in search response
*/
...
...
This diff is collapsed.
Click to expand it.
src/main/java/com/tarento/formservice/utils/CloudStorage.java
+
1
−
1
View file @
ef15e4d2
...
...
@@ -15,7 +15,7 @@ import org.sunbird.cloud.storage.factory.StorageServiceFactory;
import
scala.Option
;
@Service
public
class
CloudStorage
{
public
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
CloudStorage
.
class
);
...
...
This diff is collapsed.
Click to expand it.
src/main/java/com/tarento/formservice/utils/PathRoutes.java
+
1
−
0
View file @
ef15e4d2
...
...
@@ -11,6 +11,7 @@ public interface PathRoutes {
final
String
SAVE_FORM_SUBMIT_V1
=
"/v1/saveFormSubmit"
;
final
String
SAVE_FORM_SUBMIT_BULK
=
"/saveFormSubmitBulk"
;
final
String
GET_ALL_APPLICATIONS
=
"/getAllApplications"
;
final
String
GET_INSTITUTE_DATA
=
"/getInstituteData"
;
final
String
GET_APPLICATIONS_BY_ID
=
"/getApplicationsById"
;
final
String
GET_APPLICATIONS_STATUS_COUNT
=
"/getApplicationsStatusCount"
;
final
String
FILE_UPLOAD
=
"/fileUpload"
;
...
...
This diff is collapsed.
Click to expand it.
src/main/resources/application.properties
+
5
−
5
View file @
ef15e4d2
server.port
=
8099
spring.datasource.driver-class-name
=
com.mysql.cj.jdbc.Driver
spring.datasource.url
=
jdbc:mysql://
localhost
:3306/retail_user
spring.datasource.username
=
r
etail_user
spring.datasource.password
=
ReTail
123
T
spring.datasource.url
=
jdbc:mysql://
159.223.143.139
:3306/retail_user
spring.datasource.username
=
r
oot
spring.datasource.password
=
Testing@
123
#----------------------------- ELASTIC SEARCH CONFIGURATIONS ------------------------------#
services.esindexer.host
=
elastic.pulz.app
services.esindexer.host
=
159.223.143.139
services.esindexer.host.name
=
elastic.pulz.app
services.esindexer.host.port
=
443
services.esindexer.host.port
=
9200
services.esindexer.username
=
elastic
services.esindexer.password
=
PuAz@itAqwsaR34bYu
# INDEX AND DOCUMENT TYPES
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets