Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bulk fiscal event push request , Junit - iFIX dept entity and fiscal event service, And Log4j vulnerability fixes #24

Merged
merged 4 commits into from
Jan 12, 2022
Merged
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
4 changes: 2 additions & 2 deletions build/maven/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM egovio/alpine-maven-builder-jdk-8:1-master-NA-6036091e AS build
FROM dwssio/alpine-maven-builder-jdk-8:1-master-NA-6036091e AS build
ARG WORK_DIR
WORKDIR /app

Expand All @@ -14,7 +14,7 @@ RUN mvn -B -f /app/pom.xml package


# Create runtime image
FROM egovio/8-openjdk-alpine
FROM dwssio/8-openjdk-alpine


WORKDIR /opt/egov
Expand Down
2 changes: 1 addition & 1 deletion core/ifix-zuul/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<name>ifix-zuul</name>
<description>Api gateway for iFIX</description>
<properties>
<log4j2.version>2.16.0</log4j2.version>
<log4j2.version>2.17.0</log4j2.version>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
2 changes: 1 addition & 1 deletion core/libraries/ifix-services-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<description>Shared classes among services</description>

<properties>
<log4j2.version>2.16.0</log4j2.version>
<log4j2.version>2.17.0</log4j2.version>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
2 changes: 1 addition & 1 deletion core/libraries/ifix-tracer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</snapshotRepository>
</distributionManagement>
<properties>
<log4j2.version>2.16.0</log4j2.version>
<log4j2.version>2.17.0</log4j2.version>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
2 changes: 1 addition & 1 deletion domain-services/fiscal-event-post-processor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<name>fiscal-event-post-processor</name>
<version>1.0.2</version>
<properties>
<log4j2.version>2.16.0</log4j2.version>
<log4j2.version>2.17.0</log4j2.version>
<java.version>1.8</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
Expand Down
3 changes: 3 additions & 0 deletions domain-services/fiscal-event-service/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Changelog
All notable changes to this module will be documented in this file.

## 1.0.2 - 2021-10-29
- Fiscal-Event-Service will receive bulk fiscal event request data in push api request. And it will validate all the bulk data in request and in case of any missing required or invalid attributes , will throw the corresponding error message and stop processing.

## 1.0.1 - 2021-10-08
- Fiscal-Event-Service receives the EventType enum of FiscalEvent model in ALL_CAPS but it will process it in
Pascal_Case. The record in the kafka topic will get the enum in Pascal_Case.
Expand Down
5 changes: 5 additions & 0 deletions domain-services/fiscal-event-service/CODECOVERAGEREPORT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Junit Code Coverage Report
All junit code coverage report to this module will be documented in this file.

## 2021-11-16
- Code coverage report![ifix-fiscal-event-service-junit-report-1.0.2.png](ifix-fiscal-event-service-junit-report-1.0.2.png)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
openapi: 3.0.0
info:
title: fiscal-event-service
version: 1.0.0
version: 1.0.2
servers:
- url: https://<server_address>/fiscal-event-service
description: SwaggerHub API Auto Mocking
Expand Down Expand Up @@ -218,7 +218,9 @@ components:
requestHeader:
$ref: '#/components/schemas/RequestHeader'
fiscalEvent:
$ref: '#/components/schemas/FiscalEvent'
type: array
items:
$ref: '#/components/schemas/FiscalEvent'
description: Fiscal event request along with request metadata
FiscalEventGetRequest:
required:
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions domain-services/fiscal-event-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<artifactId>fiscal-event-service</artifactId>
<packaging>jar</packaging>
<name>fiscal-event-service</name>
<version>1.0.1</version>
<version>1.0.2</version>
<properties>
<log4j2.version>2.16.0</log4j2.version>
<log4j2.version>2.17.0</log4j2.version>
<java.version>1.8</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,7 @@ public void initialize() {

@Value("${ifix.master.project.search.path}")
private String ifixMasterProjectSearchPath;

@Value("${fiscal.event.push.request.max.size}")
private String fiscalEventPushReqMaxSize;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,34 @@ public class FiscalEventEnrichmentService {

public void enrichFiscalEventPushPost(FiscalEventRequest fiscalEventRequest) {
RequestHeader requestHeader = fiscalEventRequest.getRequestHeader();
FiscalEvent fiscalEvent = fiscalEventRequest.getFiscalEvent();
if (fiscalEvent != null) {
//set the id
fiscalEvent.setId(UUID.randomUUID().toString());

List<Amount> amounts = new ArrayList<>();
for (Amount amount : fiscalEvent.getAmountDetails()) {
Amount newAmount = new Amount();
BeanUtils.copyProperties(amount, newAmount);
//set the amount id
newAmount.setId(UUID.randomUUID().toString());
amounts.add(newAmount);
List<FiscalEvent> fiscalEvents = fiscalEventRequest.getFiscalEvent();
if (fiscalEvents != null && !fiscalEvents.isEmpty()) {
Long ingestionTime = System.currentTimeMillis();
for (FiscalEvent fiscalEvent : fiscalEvents) {
//set the id
fiscalEvent.setId(UUID.randomUUID().toString());

List<Amount> amounts = new ArrayList<>();
for (Amount amount : fiscalEvent.getAmountDetails()) {
Amount newAmount = new Amount();
BeanUtils.copyProperties(amount, newAmount);
//set the amount id
newAmount.setId(UUID.randomUUID().toString());
amounts.add(newAmount);
}
fiscalEvent.setAmountDetails(amounts);

AuditDetails auditDetails = null;
if (fiscalEvent.getAuditDetails() == null) {
auditDetails = fiscalEventUtil.enrichAuditDetails(requestHeader.getUserInfo().getUuid(), fiscalEvent.getAuditDetails(), true);
} else {
auditDetails = fiscalEventUtil.enrichAuditDetails(requestHeader.getUserInfo().getUuid(), fiscalEvent.getAuditDetails(), false);
}

//set the audit details
fiscalEvent.setAuditDetails(auditDetails);
fiscalEvent.setIngestionTime(ingestionTime);
}
fiscalEvent.setAmountDetails(amounts);

AuditDetails auditDetails = null;
if (fiscalEvent.getAuditDetails() == null) {
auditDetails = fiscalEventUtil.enrichAuditDetails(requestHeader.getUserInfo().getUuid(), fiscalEvent.getAuditDetails(), true);
} else {
auditDetails = fiscalEventUtil.enrichAuditDetails(requestHeader.getUserInfo().getUuid(), fiscalEvent.getAuditDetails(), false);
}

//set the audit details
fiscalEvent.setAuditDetails(auditDetails);
fiscalEvent.setIngestionTime(System.currentTimeMillis());
}

}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package org.egov.service;


import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.egov.common.contract.request.RequestHeader;
import org.egov.config.FiscalEventConfiguration;
import org.egov.producer.Producer;
import org.egov.repository.FiscalEventRepository;
Expand Down Expand Up @@ -50,7 +53,17 @@ public class FiscalEventService {
public FiscalEventRequest fiscalEventsV1PushPost(FiscalEventRequest fiscalEventRequest) {
validator.validateFiscalEventPushPost(fiscalEventRequest);
enricher.enrichFiscalEventPushPost(fiscalEventRequest);
producer.push(eventConfiguration.getFiscalPushRequest(), fiscalEventRequest);

if (fiscalEventRequest.getFiscalEvent() != null && !fiscalEventRequest.getFiscalEvent().isEmpty()) {
RequestHeader requestHeader = fiscalEventRequest.getRequestHeader();
for (FiscalEvent fiscalEvent : fiscalEventRequest.getFiscalEvent()) {
ObjectNode fiscalEventRequestNode = JsonNodeFactory.instance.objectNode();
fiscalEventRequestNode.putPOJO("requestHeader",requestHeader);
fiscalEventRequestNode.putPOJO("fiscalEvent",fiscalEvent);

producer.push(eventConfiguration.getFiscalPushRequest(), fiscalEventRequestNode);
}
}
return fiscalEventRequest;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import org.egov.config.FiscalEventConfiguration;
import org.egov.repository.ServiceRequestRepository;
import org.egov.tracer.model.CustomException;
import org.egov.web.models.Amount;
import org.egov.web.models.FiscalEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

Expand All @@ -33,12 +31,13 @@ public class CoaUtil {
* Get the COA Details from master data service
*
* @param requestHeader
* @param fiscalEvent
* @param coaIds
* @param tenantId
* @return
*/
public List<String> getCOAIdsFromCOAService(RequestHeader requestHeader, FiscalEvent fiscalEvent) {
public List<String> getCOAIdsFromCOAService(RequestHeader requestHeader, Set<String> coaIds, String tenantId) {
String url = createCoaSearchUrl();
Map<String, Object> coaSearchRequest = createSearchCoaRequest(requestHeader, fiscalEvent);
Map<String, Object> coaSearchRequest = createSearchCoaRequest(requestHeader, coaIds, tenantId);

Object response = serviceRequestRepository.fetchResult(url, coaSearchRequest);
List<String> responseCoaIds = null;
Expand All @@ -50,16 +49,12 @@ public List<String> getCOAIdsFromCOAService(RequestHeader requestHeader, FiscalE
return responseCoaIds;
}

private Map<String, Object> createSearchCoaRequest(RequestHeader requestHeader, FiscalEvent fiscalEvent) {
if (!StringUtils.isEmpty(fiscalEvent.getTenantId())) {
List<String> coaIds = new ArrayList<>();
for (Amount amount : fiscalEvent.getAmountDetails()) {
coaIds.add(amount.getCoaId());
}
private Map<String, Object> createSearchCoaRequest(RequestHeader requestHeader, Set<String> coaIds, String tenantId) {
if (StringUtils.isNotBlank(tenantId)) {
Map<String, Object> coaSearchRequest = new HashMap<>();
Map<String, Object> criteria = new HashMap<>();
criteria.put("Ids", coaIds);
criteria.put("tenantId", fiscalEvent.getTenantId());
criteria.put("tenantId", tenantId);

coaSearchRequest.put("requestHeader", requestHeader);
coaSearchRequest.put("criteria", criteria);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private MasterDataConstants() {
public static final String SEARCH_CRITERIA = "SEARCH_CRITERIA";

public static final String PROJECT_ID_EXPENDITURE_ID = "PROJECT_ID-EXPENDITURE_ID";
public static final String PROJECT_ID_DEPARTMENT_ENTITY_ID = "PROJECT_ID-EXPENDITURE_ID";
public static final String PROJECT_ID_DEPARTMENT_ENTITY_ID = "PROJECT_ID-DEPARTMENT_ENTITY_ID";


}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang3.StringUtils;
import org.egov.common.contract.request.RequestHeader;
import org.egov.config.FiscalEventConfiguration;
import org.egov.repository.ServiceRequestRepository;
import org.egov.web.models.FiscalEventRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.*;

@Component
public class ProjectUtil {
Expand All @@ -26,22 +23,20 @@ public class ProjectUtil {
ObjectMapper objectMapper;

/**
* @param fiscalEventRequest
* @param requestHeader
* @param projectIds
* @param tenantId
* @return
*/
public Optional<JsonNode> validateProjectId(FiscalEventRequest fiscalEventRequest) {
if (fiscalEventRequest != null && fiscalEventRequest.getRequestHeader() != null
&& fiscalEventRequest.getFiscalEvent() != null
&& !StringUtils.isEmpty(fiscalEventRequest.getFiscalEvent().getProjectId())) {
public Optional<JsonNode> validateProjectId(RequestHeader requestHeader, Set<String> projectIds, String tenantId) {
if (requestHeader != null && projectIds != null && !projectIds.isEmpty() && StringUtils.isNotBlank(tenantId)) {

Map<String, Object> projectValueMap = new HashMap<>();
projectValueMap.put(MasterDataConstants.IDS,
Collections.singletonList(fiscalEventRequest.getFiscalEvent().getProjectId()));
projectValueMap.put(MasterDataConstants.CRITERIA_TENANT_ID,
fiscalEventRequest.getFiscalEvent().getTenantId());
projectValueMap.put(MasterDataConstants.IDS, new ArrayList<>(projectIds));
projectValueMap.put(MasterDataConstants.CRITERIA_TENANT_ID, tenantId);

Map<String, Object> ProjectMap = new HashMap<>();
ProjectMap.put(MasterDataConstants.REQUEST_HEADER, fiscalEventRequest.getRequestHeader());
ProjectMap.put(MasterDataConstants.REQUEST_HEADER, requestHeader);
ProjectMap.put(MasterDataConstants.CRITERIA, projectValueMap);

Object response = serviceRequestRepository.fetchResult(createSearchProjectUrl(), ProjectMap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,15 @@ public class TenantUtil {
ServiceRequestRepository serviceRequestRepository;

/**
* @param tenantId
* @param tenantIds
* @param requestHeader
* @return
*/
public boolean validateTenant(String tenantId, RequestHeader requestHeader) {
if (StringUtils.isNotBlank(tenantId) && requestHeader != null) {
public boolean validateTenant(List<String> tenantIds, RequestHeader requestHeader) {
if (tenantIds!= null && !tenantIds.isEmpty() && requestHeader != null) {

Map<String, Object> tenantValueMap = new HashMap<>();
tenantValueMap.put(MasterDataConstants.IDS,
Collections.singletonList(tenantId));
tenantValueMap.put(MasterDataConstants.IDS,tenantIds);

Map<String, Object> tenantMap = new HashMap<>();
tenantMap.put(MasterDataConstants.REQUEST_HEADER, requestHeader);
Expand All @@ -46,7 +45,7 @@ public boolean validateTenant(String tenantId, RequestHeader requestHeader) {
try {
List list = JsonPath.read(response, MasterDataConstants.TENANT_LIST);

return list != null && !list.isEmpty();
return (list != null && !list.isEmpty() && (list.size() == tenantIds.size()));
} catch (Exception e) {
throw new CustomException(MasterDataConstants.JSONPATH_ERROR, "Failed to parse government response for tenantId");
}
Expand Down
Loading