Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

Search defaulter cases for given tenantId. #14

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions case-management/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,21 @@
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-validator/commons-validator -->
<dependency>
<groupId>commons-validator</groupId>
<artifactId>commons-validator</artifactId>
<version>1.6</version>
</dependency>


<!-- Egov dependencies -->
<dependency>
<groupId>org.egov</groupId>
<artifactId>mdms-client</artifactId>
<version>0.0.2-SNAPSHOT</version>
</dependency>

</dependencies>
<repositories>
<repository>
Expand Down
2 changes: 1 addition & 1 deletion case-management/src/main/java/egov/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication
@ComponentScan(basePackages = { "egov", "egov.dataupload.web.controllers" , "egov.dataupload.config"})
@ComponentScan(basePackages = { "egov", "egov.casemanagement.web.controllers" , "egov.casemanagement.config"})
public class Main {
public static void main(String[] args) throws Exception {
SpringApplication.run(Main.class, args);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package egov.dataupload.config;
package egov.casemanagement.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.*;
Expand Down Expand Up @@ -104,4 +104,22 @@ public MappingJackson2HttpMessageConverter jacksonConverter(ObjectMapper objectM
@Value("${egov.root.tenant.id}")
private String rootTenantId;

@Value("${send.email.topic}")
private String sendEmailTopic;

@Value("${send.sms.topic}")
private String sendSmsTopic;

@Value("${cova.health.record.topic}")
private String covaHealthRecordTopic;

@Value("${cova.fetch.url}")
private String covaFetchUrl;

@Value("${cova.create.health.record.url}")
private String covaCreateHealthRecordUrl;

@Value("${cova.auth.token}")
private String covaAuthToken;

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package egov.dataupload.config;
package egov.casemanagement.config;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down Expand Up @@ -54,4 +54,9 @@ public RestHighLevelClient client(){
RestHighLevelClient client = new RestHighLevelClient(builder);
return client;
}

@Bean
public RestClient restClient(){
return client().getLowLevelClient();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package egov.dataupload.models;
package egov.casemanagement.models;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package egov.dataupload.models.Idgen;
package egov.casemanagement.models.Idgen;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package egov.dataupload.models.Idgen;
package egov.casemanagement.models.Idgen;

import lombok.AllArgsConstructor;
import lombok.Builder;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package egov.dataupload.models.Idgen;
package egov.casemanagement.models.Idgen;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package egov.dataupload.models.Idgen;
package egov.casemanagement.models.Idgen;

import lombok.AllArgsConstructor;
import lombok.Builder;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package egov.casemanagement.models.cova;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.*;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class CovaData {
@JsonProperty("mobile_no")
private String mobileNumber = null;

@JsonProperty("district_name")
private String district = null;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package egov.casemanagement.models.cova;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.*;

import java.util.List;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class CovaSearchResponse {
@JsonProperty("response")
private int response = 0;

@JsonProperty("sys_message")
private String sys_message = null;

@JsonProperty("data")
private List<CovaData> data = null;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package egov.dataupload.models.sign;
package egov.casemanagement.models.sign;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package egov.dataupload.models.sign;
package egov.casemanagement.models.sign;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package egov.dataupload.models.user;
package egov.casemanagement.models.user;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package egov.dataupload.models.user;
package egov.casemanagement.models.user;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package egov.dataupload.models.user;
package egov.casemanagement.models.user;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package egov.dataupload.models.user;
package egov.casemanagement.models.user;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package egov.dataupload.producer;
package egov.casemanagement.producer;

import lombok.extern.slf4j.Slf4j;
import org.egov.tracer.kafka.CustomKafkaTemplate;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
package egov.dataupload.repository;
package egov.casemanagement.repository;

import com.fasterxml.jackson.databind.ObjectMapper;
import egov.dataupload.config.Configuration;
import egov.dataupload.web.models.CaseSearchRequest;
import egov.dataupload.web.models.ModelCase;
import egov.casemanagement.config.Configuration;
import egov.casemanagement.web.models.CaseSearchRequest;
import egov.casemanagement.web.models.ModelCase;
import lombok.extern.slf4j.Slf4j;
import org.egov.tracer.model.CustomException;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.*;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -40,8 +38,18 @@ public class ElasticSearchRepository implements SearchRepository{

@Override
public List<ModelCase> searchCases(CaseSearchRequest request){
SearchRequest searchRequest = new SearchRequest(configuration.getEsIndexName());
SearchSourceBuilder sourceBuilder = getSearchBody(request);
return getCasesFromES(sourceBuilder);
}

@Override
public List<ModelCase> searchDefaulterCases(String tenantId, Long timestamp) {
SearchSourceBuilder searchSourceBuilder = getSearchBodyForDefaulterCases(tenantId, timestamp);
return getCasesFromES(searchSourceBuilder);
}

private List<ModelCase> getCasesFromES(SearchSourceBuilder sourceBuilder) {
SearchRequest searchRequest = new SearchRequest(configuration.getEsIndexName());
searchRequest.source(sourceBuilder);

List<ModelCase> cases = new ArrayList<>();
Expand All @@ -68,19 +76,19 @@ private SearchSourceBuilder getSearchBody(CaseSearchRequest request) {
List<QueryBuilder> queries = new ArrayList<>();

if(request.getCaseId() != null)
queries.add(QueryBuilders.termsQuery("case.caseId.keyword", request.getCaseId()));
queries.add(QueryBuilders.termsQuery("case.caseId", request.getCaseId()));

if(request.getUserUuids() != null)
queries.add(QueryBuilders.termsQuery("case.userUuid.keyword", request.getUserUuids()));
queries.add(QueryBuilders.termsQuery("case.userUuid", request.getUserUuids()));

if(request.getStatus() != null)
queries.add(QueryBuilders.termsQuery("case.status.keyword", request.getStatus()));
queries.add(QueryBuilders.termsQuery("case.status", request.getStatus()));

if(request.getUuid() != null)
queries.add(QueryBuilders.termsQuery("case.uuid.keyword", request.getUuid()));
queries.add(QueryBuilders.termsQuery("case.uuid", request.getUuid()));

if(request.getTenantId() != null)
queries.add(QueryBuilders.termsQuery("case.tenantId.keyword", request.getTenantId()));
queries.add(QueryBuilders.termsQuery("case.tenantId", request.getTenantId()));

BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
for (QueryBuilder curr : queries) {
Expand All @@ -90,4 +98,27 @@ private SearchSourceBuilder getSearchBody(CaseSearchRequest request) {
sourceBuilder.query(boolQueryBuilder);
return sourceBuilder;
}

private SearchSourceBuilder getSearchBodyForDefaulterCases(String tenantId, Long timestamp) {


RangeQueryBuilder rangeQueryBuilder = QueryBuilders.rangeQuery("case.healthDetails.auditDetails.lastModifiedTime");
rangeQueryBuilder.gte(timestamp);

MatchQueryBuilder statusQuery = QueryBuilders.matchQuery("case.status", "active");

MatchQueryBuilder tenantIdQuery = QueryBuilders.matchQuery("case.tenantId", tenantId);

BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
boolQueryBuilder.should(statusQuery);
boolQueryBuilder.should(tenantIdQuery);
boolQueryBuilder.mustNot(rangeQueryBuilder);

SearchSourceBuilder sourceBuilder = new SearchSourceBuilder().timeout(new TimeValue(60, TimeUnit.SECONDS));

sourceBuilder.query(boolQueryBuilder);

return sourceBuilder;
}

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package egov.dataupload.repository;
package egov.casemanagement.repository;


import egov.dataupload.config.Configuration;
import egov.dataupload.models.Idgen.IdGenerationRequest;
import egov.dataupload.models.Idgen.IdGenerationResponse;
import egov.dataupload.models.Idgen.IdRequest;
import egov.dataupload.models.Idgen.IdResponse;
import egov.casemanagement.config.Configuration;
import egov.casemanagement.models.Idgen.IdGenerationRequest;
import egov.casemanagement.models.Idgen.IdGenerationResponse;
import egov.casemanagement.models.Idgen.IdRequest;
import egov.casemanagement.models.Idgen.IdResponse;
import org.egov.common.contract.request.RequestInfo;
import org.egov.tracer.model.CustomException;
import org.egov.tracer.model.ServiceCallException;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package egov.casemanagement.repository;

import egov.casemanagement.web.models.CaseSearchRequest;
import egov.casemanagement.web.models.ModelCase;

import java.util.List;

public interface SearchRepository {
public List<ModelCase> searchCases(CaseSearchRequest request);
List<ModelCase> searchDefaulterCases(String tenantId, Long timestamp);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package egov.dataupload.repository;
package egov.casemanagement.repository;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
Expand Down Expand Up @@ -30,9 +30,9 @@ public ServiceRequestRepository(ObjectMapper mapper, RestTemplate restTemplate)
public Object fetchResult(String uri, Object request) {
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
Object response = null;
log.info("URI: "+uri.toString());
log.info("URI: "+ uri);
try {
response = restTemplate.postForObject(uri.toString(), request, Map.class);
response = restTemplate.postForObject(uri, request, Map.class);
}catch(HttpClientErrorException e) {
log.error("External Service threw an Exception: ",e);
throw new ServiceCallException(e.getResponseBodyAsString());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package egov.dataupload.repository;
package egov.casemanagement.repository;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import egov.dataupload.config.Configuration;
import egov.dataupload.models.sign.SignRequest;
import egov.dataupload.models.sign.SignResponse;
import egov.casemanagement.config.Configuration;
import egov.casemanagement.models.sign.SignRequest;
import egov.casemanagement.models.sign.SignResponse;
import lombok.extern.slf4j.Slf4j;
import org.egov.tracer.model.CustomException;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down
Loading