Skip to content
This repository has been archived by the owner on Aug 4, 2023. It is now read-only.

Assignment-5 of developer training guid #172

Open
wants to merge 1 commit 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
1 change: 1 addition & 0 deletions tutorials/Assignment-5/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Run the services and all the necessary dependencies and figure out why desired response is not returned. Clear out any previously added configuration files(such as indexer.yml, persister.yml etc) and add the files present in this assignment.
25 changes: 25 additions & 0 deletions tutorials/Assignment-5/btr-calculator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# BTR Calculator

This module calculates the birth registration application
charges and creates bill for the application.

### Service Dependencies
- egov-mdms
- billing service

## Service Details

The service generates demand based on input amount from
mdms.

### API Details

`BasePath` /birth-calculator/v1/[API endpoint]

#### Method

a) `_calculate`
- Calculates the amount due and generates the demand.

b) `_getbill`
- Fetches the bill for given application number.

Large diffs are not rendered by default.

111 changes: 111 additions & 0 deletions tutorials/Assignment-5/btr-calculator/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
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>birth-calculator</artifactId>
<packaging>jar</packaging>
<name>birth-calculator</name>
<version>1.0.0</version>
<properties>
<java.version>1.8</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>2.2.6.RELEASE</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>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>
<!-- Egov dependencies -->
<dependency>
<groupId>org.egov.services</groupId>
<artifactId>tracer</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.egov.services</groupId>
<artifactId>services-common</artifactId>
<version>1.0.1-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>0.0.2-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>javax.validation</groupId>
<artifactId>validation-api</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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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,26 @@
package digit.config;

import lombok.Getter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

@Configuration
@Getter
public class BTRCalculatorConfigs {

@Value("${egov.billingservice.host}")
private String billingServiceHost;

@Value("${egov.demand.create.endpoint}")
private String demandCreateEndpoint;

@Value("${egov.billingservice.fetch.bill}")
private String fetchBillEndpoint;

@Value("${btr.taxhead.master.code}")
private String taxHeadMasterCode;

@Value("${btr.module.code}")
private String moduleCode;

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

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.egov.tracer.config.TracerConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;

import javax.annotation.PostConstruct;
import java.util.TimeZone;


@Import({TracerConfiguration.class})
public class MainConfiguration {

@Value("${app.timezone}")
private String timeZone;

@PostConstruct
public void initialize() {
TimeZone.setDefault(TimeZone.getTimeZone(timeZone));
}

@Bean
public ObjectMapper objectMapper() {
return new ObjectMapper().disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES).setTimeZone(TimeZone.getTimeZone(timeZone));
}

@Bean
@Autowired
public MappingJackson2HttpMessageConverter jacksonConverter(ObjectMapper objectMapper) {
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
converter.setObjectMapper(objectMapper);
return converter;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
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;

@Repository
@Slf4j
public class ServiceRequestRepository {

private final ObjectMapper mapper;

private final 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 threw an Exception: ", e);
throw new ServiceCallException(e.getResponseBodyAsString());
} catch (Exception e) {
log.error("Exception while fetching from searcher: ", e);
}

return response;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package digit.service;

import digit.util.MdmsUtil;
import digit.util.ResponseInfoFactory;
import digit.web.models.Calculation;
import digit.web.models.CalculationCriteria;
import digit.web.models.CalculationReq;
import digit.web.models.CalculationRes;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.LinkedList;
import java.util.List;

@Service
public class CalculationService {

@Autowired
private MdmsUtil mdmsUtil;

@Autowired
private ResponseInfoFactory responseInfoFactory;

@Autowired
private DemandService demandService;

public List<Calculation> calculate(CalculationReq calculationReq){
List<Calculation> calculations = getCalculations(calculationReq);
CalculationRes calculationRes = CalculationRes.builder().responseInfo(responseInfoFactory.createResponseInfoFromRequestInfo(calculationReq.getRequestInfo(),true)).calculation(calculations).build();

demandService.generateDemands(calculationReq.getRequestInfo(),calculations);
return calculations;
}

public List<Calculation> getCalculations(CalculationReq calculationReq){
List<Calculation> calculations = new LinkedList<>();
for(CalculationCriteria calculationCriteria : calculationReq.getCalculationCriteria()) {
Calculation calculation = new Calculation();
calculation.setApplicationNumber(calculationCriteria.getApplicationNumber());
calculation.setTenantId(calculationCriteria.getTenantId());
calculation.setTotalAmount(Double.valueOf(getAmount(calculationReq)));
calculations.add(calculation);
}
return calculations;
}

private Integer getAmount(CalculationReq calculationReq) {
return mdmsUtil.fetchRegistrationChargesFromMdms(calculationReq.getRequestInfo(), calculationReq.getCalculationCriteria().get(0).getTenantId());
}

}
Loading