Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
18 changes: 18 additions & 0 deletions health-services/geopode-adapter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Swagger generated server

Spring Boot Server


## Overview
This server was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project.
By using the [OpenAPI-Spec](https://github.com/swagger-api/swagger-core), you can easily generate a server stub.
This is an example of building a swagger-enabled server in Java using the SpringBoot framework.

The underlying library integrating swagger to SpringBoot is [springfox](https://github.com/springfox/springfox)

Start your server as an simple java application

You can view the api documentation in swagger-ui by pointing to
http://localhost:8080/

Change default port value in application.properties
135 changes: 135 additions & 0 deletions health-services/geopode-adapter/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.egov</groupId>
<artifactId>geopode-adapter</artifactId>
<packaging>jar</packaging>
<name>geopode-adapter</name>
<version>1.0.0</version>
<properties>
<java.version>17</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.2</version>
</parent>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>9.22.3</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.7.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-core</artifactId>
<version>1.5.18</version>
</dependency>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations</artifactId>
<version>2.2.8</version>
</dependency>
<dependency>
<groupId>net.minidev</groupId>
<artifactId>json-smart</artifactId>
<version>2.5.0</version>
</dependency>
<!-- Egov dependencies -->
<dependency>
<groupId>org.egov.services</groupId>
<artifactId>tracer</artifactId>
<version>2.9.0-SNAPSHOT</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.egov.services</groupId>-->
<!-- <artifactId>digit-models</artifactId>-->
<!-- <version>1.0.0-SNAPSHOT</version>-->
<!-- </dependency>-->
<dependency>
<groupId>org.egov</groupId>
<artifactId>mdms-client</artifactId>
<version>2.9.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
<!-- Bean Validation API support -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
</dependencies>
<repositories>
<repository>
<id>repo.egovernments.org</id>
<name>eGov ERP Releases Repository</name>
<url>https://nexus-repo.egovernments.org/nexus/content/repositories/releases/</url>
</repository>
<repository>
<id>repo.egovernments.org.snapshots</id>
<name>eGov ERP Releases Repository</name>
<url>https://nexus-repo.egovernments.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>repo.egovernments.org.public</id>
<name>eGov Public Repository Group</name>
<url>https://nexus-repo.egovernments.org/nexus/content/groups/public/</url>
</repository>
<repository>
<id>repo.digit.org</id>
<name>eGov DIGIT Releases Repository</name>
<url>https://nexus-repo.digit.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>
</project>
17 changes: 17 additions & 0 deletions health-services/geopode-adapter/src/main/java/digit/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package digit;

import org.egov.tracer.config.TracerConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Import;

@Import({ TracerConfiguration.class })
@SpringBootApplication
@ComponentScan(basePackages = { "digit", "digit.web.controllers" , "digit.config"})
public class Main {
public static void main(String[] args) throws Exception {
SpringApplication.run(Main.class, args);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package digit.config;

import lombok.*;
import org.egov.tracer.config.TracerConfiguration;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Import;
import org.springframework.stereotype.Component;

@Component
@Data
@Import({TracerConfiguration.class})
@NoArgsConstructor
@AllArgsConstructor
@Setter
@Getter
public class Configuration {

//MDMS
@Value("${egov.mdms.host}")
private String mdmsHost;

@Value("${egov.mdms.search.endpoint}")
private String mdmsEndPoint;

//Boundary Service
@Value("${egov.boundary.service.host}")
private String boundaryServiceHost;

@Value("${egov.boundary.entity.create.endpoint}")
private String boundaryEntityCreateEndpoint;

@Value("${egov.boundary.hierarchy.create.endpoint}")
private String boundaryHierarchyCreateEndpoint;

@Value("${egov.boundary.relationship.create.endpoint}")
private String boundaryRelationshipCreateEndpoint;

@Value("${egov.boundary.hierarchy.search.endpoint}")
private String boundaryHierarchySearchEndpoint;

@Value("${egov.geopode.arcgis}")
private String arcgisEndpoint;

@Value("${egov.mdms.v2.search.endpoint}")
private String mdmsV2EndPoint;

@Value("${egov.geopode.default.offset}")
private String defaultOffset;

@Value("${egov.geopode.default.limit}")
private String defaultLimit;

@Value("${egov.mdms.tenantId}")
private String tenantId;

@Value("${egov.mdms.schemaCode}")
private String schemaCode;

@Value("${egov.geopode.localHost}")
private String geopodeLocalHost;

@Value("${egov.geopode.arcgis.search}")
private String geopodeSearchEndpoint;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package digit.config;


import org.springframework.stereotype.Component;


@Component
public class ServiceConstants {

public static final String EXTERNAL_SERVICE_EXCEPTION = "External Service threw an Exception: ";
public static final String SEARCHER_SERVICE_EXCEPTION = "Exception while fetching from searcher: ";

// Error Constants
public static final String ERROR_WHILE_FETCHING_FROM_MDMS = "Exception occurred while fetching category lists from mdms: ";

public static final String ERROR_CREATING_BOUNDARY_HIERARCHY_WITH_GIVEN_HIERARCHY = "Error encountered while creating boundary hierarchy with given hierarchy ";

// Common constants
public static final String BOUNDARY_CREATION_RESPONSE = "GeoPoDe Boundary Creation started successfully!";
public static final String LOG_PLACEHOLDER = "{}";

public static final String[] HIERARCHY_ORDER = { "ADM0_NAME", "ADM1_NAME", "ADM2_NAME", "ADM3_NAME" };
public static final String ERROR_IN_SEARCH="Error when fetching from Boundary-definition";
public static final String ERROR_IN_ARC_SEARCH="Error when fetching from Arcgis";
public static final String HIERARCHY_TYPE = "admin4";
public static final String ERROR_FETCHING_FROM_MDMS="Error Fetching Data from mdms";
public static final String NO_MDMS_DATA_FOUND_FOR_GIVEN_TENANT_ISO_CODE="For given tenatId and ISO code no country exists";
public static final String COUNTRY_OUTFIELDS="ADM1_NAME";
public static final String FORMAT_VALUE="json";
public static final String ERROR_FETCHING_FROM_BOUNDARY="Error Fetching Data from boundary";
public static final String ROOT_BOUNDARY_ALREADY_EXISTS="Root Boundary already created";
public static final String RESPONSE_FROM_GEOPODE_API = "[\n" +
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will be fetched from boundary-service heirarchy

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When call is being made to boundary, service and error comes, I use these constants in the catch

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is error coming?

" {\n" +
" \"feature\": \"admin_0\",\n" +
" \"type_code\": \"Country\",\n" +
" \"level\": 0,\n" +
" \"parent\": null\n" +
" },\n" +
" {\n" +
" \"feature\": \"admin_1\",\n" +
" \"type_code\": \"State\",\n" +
" \"level\": 1,\n" +
" \"parent\": \"Country\"\n" +
" },\n" +
" {\n" +
" \"feature\": \"admin_2\",\n" +
" \"type_code\": \"LGA\",\n" +
" \"level\": 2,\n" +
" \"parent\": \"State\"\n" +
" },\n" +
" {\n" +
" \"feature\": \"admin_3\",\n" +
" \"type_code\": \"Ward\",\n" +
" \"level\": 3,\n" +
" \"parent\": \"LGA\"\n" +
" }\n" +
"]";


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package digit.kafka;

import lombok.extern.slf4j.Slf4j;
import org.egov.tracer.kafka.CustomKafkaTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

// NOTE: If tracer is disabled change CustomKafkaTemplate to KafkaTemplate in autowiring

@Service
@Slf4j
public class Producer {

@Autowired
private CustomKafkaTemplate<String, Object> kafkaTemplate;

public void push(String topic, Object value) {
kafkaTemplate.send(topic, value);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package digit.repository;


import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import lombok.extern.slf4j.Slf4j;
import org.egov.tracer.model.ServiceCallException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestTemplate;

import java.util.Map;

import static digit.config.ServiceConstants.*;

@Repository
@Slf4j
public class ServiceRequestRepository {

private ObjectMapper mapper;

private RestTemplate restTemplate;


@Autowired
public ServiceRequestRepository(ObjectMapper mapper, RestTemplate restTemplate) {
this.mapper = mapper;
this.restTemplate = restTemplate;
}


public Object fetchResult(StringBuilder uri, Object request) {
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
Object response = null;
try {
response = restTemplate.postForObject(uri.toString(), request, Map.class);
} catch (HttpClientErrorException e) {
log.error(EXTERNAL_SERVICE_EXCEPTION, e);
throw new ServiceCallException(e.getResponseBodyAsString());
} catch (Exception e) {
log.error(SEARCHER_SERVICE_EXCEPTION, e);
}

return response;
}
}
Loading
Loading