Skip to content

Commit

Permalink
Merge pull request #389 from odisha-muktasoft/updated-develop
Browse files Browse the repository at this point in the history
Updated develop
  • Loading branch information
egov-arindam authored May 14, 2024
2 parents 65c4946 + 5a28d0c commit 554f400
Show file tree
Hide file tree
Showing 342 changed files with 15,690 additions and 2,228 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,35 @@ public void enrichContractOnCreate(ContractRequest contractRequest){
// Enrich UUID and AuditDetails
enrichIdsAgreementDateAndAuditDetailsOnCreate(contractRequest);
// Enrich Supplement number and mark contracts and document status as in-workflow
if (contractRequest.getContract().getBusinessService() != null
&& (contractRequest.getContract().getBusinessService().equalsIgnoreCase(CONTRACT_TIME_EXTENSION_BUSINESS_SERVICE)
|| contractRequest.getContract().getBusinessService().equalsIgnoreCase(CONTRACT_REVISION_ESTIMATE))) {
if (contractRequest.getContract().getBusinessService() != null) {

switch(contractRequest.getContract().getBusinessService()){
case CONTRACT_TIME_EXTENSION_BUSINESS_SERVICE:
{
enrichSupplementNumber(contractRequest);
markContractAndDocumentsStatus(contractRequest, Status.INWORKFLOW);
markLineItemsAndAmountBreakupsStatus(contractRequest, Status.INWORKFLOW);

break;
}
case CONTRACT_REVISION_ESTIMATE:
{
enrichSupplementNumber(contractRequest);
markContractAndDocumentsStatus(contractRequest, Status.ACTIVE);
markLineItemsAndAmountBreakupsStatus(contractRequest, Status.ACTIVE);
enrichPreviousContractLineItems(contractRequest);
break;
}
default:
{
log.info("Request Triggered for buisness service CONTRACT ");
enrichContractNumber(contractRequest);

}
}
// Enrich Supplement Number
enrichSupplementNumber(contractRequest);
markContractAndDocumentsStatus(contractRequest, Status.INWORKFLOW);
markLineItemsAndAmountBreakupsStatus(contractRequest, Status.INWORKFLOW);

} else {
// Enrich Contract Number
enrichContractNumber(contractRequest);

}
}

Expand Down Expand Up @@ -458,9 +476,8 @@ private void setContractLineItemRef(ContractRequest contractRequest, Estimate es
}

public void enrichPreviousContractLineItems(ContractRequest contractRequest) {
if (contractRequest.getContract().getBusinessService() != null && (contractRequest.getContract().getBusinessService().equalsIgnoreCase(CONTRACT_TIME_EXTENSION_BUSINESS_SERVICE)
|| contractRequest.getContract().getBusinessService().equalsIgnoreCase(CONTRACT_REVISION_ESTIMATE))
&& ACCEPT_ACTION.equalsIgnoreCase(contractRequest.getWorkflow().getAction())) {
if (contractRequest.getContract().getBusinessService() != null
&&!CONTRACT_BUSINESS_SERVICE.equals(contractRequest.getContract().getBusinessService())){
log.info("Setting previous contract statuses inactive");
Contract previousActiveContract = contractServiceUtil.getActiveContractsFromDB(contractRequest).get(0);

Expand All @@ -469,20 +486,42 @@ public void enrichPreviousContractLineItems(ContractRequest contractRequest) {
.contract(previousActiveContract).build();
ProcessInstance processInstance = workflowService.getProcessInstance(contractRequestFromDB);
contractRequestFromDB.getContract().setProcessInstance(processInstance);
markContractAndDocumentsStatus(contractRequestFromDB, Status.INACTIVE);
markLineItemsAndAmountBreakupsStatus(contractRequestFromDB, Status.INACTIVE);
contractProducer.push(config.getUpdateContractTopic(), contractRequestFromDB);

// Push updated end date to kafka topic to update attendance register end date
JsonNode requestInfo = mapper.convertValue(contractRequest.getRequestInfo(), JsonNode.class);
JsonNode attendanceContractRevisionRequest = mapper.createObjectNode()
.putPOJO("RequestInfo", requestInfo)
.put("tenantId", contractRequest.getContract().getTenantId())
.put("referenceId", contractRequest.getContract().getContractNumber())
.put("endDate", contractRequest.getContract().getEndDate());

log.info("Pushing updated end date to attendance register end date update topic");
contractProducer.push(config.getUpdateTimeExtensionTopic(), attendanceContractRevisionRequest);

switch (contractRequest.getContract().getBusinessService()){
case CONTRACT_TIME_EXTENSION_BUSINESS_SERVICE:
{
if(APPROVE_ACTION.equalsIgnoreCase(contractRequest.getWorkflow().getAction())){
markContractAndDocumentsStatus(contractRequestFromDB, Status.INACTIVE);
markLineItemsAndAmountBreakupsStatus(contractRequestFromDB, Status.INACTIVE);
contractProducer.push(config.getUpdateContractTopic(), contractRequestFromDB);
// Push updated end date to kafka topic to update attendance register end date
JsonNode requestInfo = mapper.convertValue(contractRequest.getRequestInfo(), JsonNode.class);
JsonNode attendanceContractRevisionRequest = mapper.createObjectNode()
.putPOJO("RequestInfo", requestInfo)
.put("tenantId", contractRequest.getContract().getTenantId())
.put("referenceId", contractRequest.getContract().getContractNumber())
.put("endDate", contractRequest.getContract().getEndDate());

log.info("Pushing updated end date to attendance register end date update topic");
contractProducer.push(config.getUpdateTimeExtensionTopic(), attendanceContractRevisionRequest);
}
break;
}
case CONTRACT_REVISION_ESTIMATE:
{
markContractAndDocumentsStatus(contractRequestFromDB, Status.INACTIVE);
markLineItemsAndAmountBreakupsStatus(contractRequestFromDB, Status.INACTIVE);
contractProducer.push(config.getUpdateContractTopic(), contractRequestFromDB);
break;
}
default:
log.info("Update Request For Original Contract");
}





}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import java.util.Map;

import static org.egov.works.util.ContractServiceConstants.APPROVE_ACTION;
import static org.egov.works.util.ContractServiceConstants.REVISION_ESTIMATE;

@Component
Expand Down Expand Up @@ -42,7 +43,12 @@ public void listen(final String consumerRecord, @Header(KafkaHeaders.RECEIVED_TO
try {
request = objectMapper.readValue(consumerRecord, EstimateRequest.class);
if(request.getEstimate().getBusinessService().equals(REVISION_ESTIMATE)){
contractService.createAndPostRevisedContractRequest(request);
if(!request.getWorkflow().getAction().equals(APPROVE_ACTION)){
throw new CustomException("REVISED_ESTIMATE_NOT_APPROVED", "Revised Estimate is not Approved");
}else{
contractService.createAndPostRevisedContractRequest(request);
}

}else{
log.info("Request is not for Revised Estimate");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,6 @@ public void createAndPostRevisedContractRequest(EstimateRequest request){
List<String> estimateIds= new ArrayList<>();
// Need to check the status of the estimate if it is Active or not
if(request.getEstimate().getStatus().equals(Status.ACTIVE)){
if(!request.getWorkflow().getAction().equals("APPROVE")){
throw new CustomException("REVISED_ESTIMATE_NOT_APPROVED", "Revised Estimate is not Approved");
}

if(request.getEstimate()!=null || request.getEstimate().getOldUuid()!=null){
tenantId=request.getEstimate().getTenantId();
Expand All @@ -176,7 +173,7 @@ public void createAndPostRevisedContractRequest(EstimateRequest request){
createContract(createRevisedContractRequest(contractList,request));
}
}else {
log.info("ESTIMATE_NOT_ACTIVE","Estimate is not in Active state");
log.info("ESTIMATE_NOT_ACTIVE","Revised Estimate is not in Active state");
}
}

Expand All @@ -203,7 +200,7 @@ private ContractRequest createRevisedContractRequest(List<Contract> contractList
throw new CustomException("WF_STATUS_NOT_APPROVED","Time Extension wfStatus is not Approved");
}

Workflow workflow=Workflow.builder().action("SUBMIT").assignees(new ArrayList<>()).build();
Workflow workflow=Workflow.builder().action(SUBMIT).assignees(new ArrayList<>()).build();

return ContractRequest.builder()
.requestInfo(request.getRequestInfo())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package org.egov.works.service;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.jayway.jsonpath.JsonPath;
import digit.models.coremodels.RequestInfoWrapper;
import digit.models.coremodels.SMSRequest;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.egov.common.contract.request.RequestInfo;
import org.egov.tracer.model.CustomException;
import org.egov.works.config.ContractServiceConfiguration;
import org.egov.works.kafka.ContractProducer;
import org.egov.works.repository.ServiceRequestRepository;
Expand Down Expand Up @@ -68,25 +70,32 @@ public class NotificationService {
* @param request
*/
public void sendNotification(ContractRequest request) {
Workflow workflow = request.getWorkflow();

if (request.getContract().getBusinessService() != null
&& !request.getContract().getBusinessService().isEmpty()
&& request.getContract().getBusinessService().equalsIgnoreCase(CONTRACT_TIME_EXTENSION_BUSINESS_SERVICE)) {
pushNotificationForRevisedContract (request);

}else {
if (REJECT_ACTION.equalsIgnoreCase(workflow.getAction())) {
pushNotificationToCreatorForRejectAction(request);
} else if (APPROVE_ACTION.equalsIgnoreCase(workflow.getAction())) {
//No template present for Creator Approve Action
pushNotificationToCreatorForApproveAction(request);
pushNotificationToCBOForApproveAction(request);
} else if (ACCEPT_ACTION.equalsIgnoreCase(workflow.getAction())) {
pushNotificationToCreatorForAcceptAction(request);
} else if ("DECLINE".equalsIgnoreCase(workflow.getAction())) {
pushNotificationToCreatorForDeclineAction(request);
if(config.getIsSMSEnabled()){
log.info("Notification is enabled for this service");

Workflow workflow = request.getWorkflow();

if (request.getContract().getBusinessService() != null
&& !request.getContract().getBusinessService().isEmpty()
&& request.getContract().getBusinessService().equalsIgnoreCase(CONTRACT_TIME_EXTENSION_BUSINESS_SERVICE)) {
pushNotificationForRevisedContract (request);

}else {
if (REJECT_ACTION.equalsIgnoreCase(workflow.getAction())) {
pushNotificationToCreatorForRejectAction(request);
} else if (APPROVE_ACTION.equalsIgnoreCase(workflow.getAction())) {
//No template present for Creator Approve Action
pushNotificationToCreatorForApproveAction(request);
pushNotificationToCBOForApproveAction(request);
} else if (ACCEPT_ACTION.equalsIgnoreCase(workflow.getAction())) {
pushNotificationToCreatorForAcceptAction(request);
} else if ("DECLINE".equalsIgnoreCase(workflow.getAction())) {
pushNotificationToCreatorForDeclineAction(request);
}
}
}else{
log.info("Notification is not enabled for this service");
}

}
Expand Down Expand Up @@ -140,8 +149,18 @@ private void pushNotificationToOriginator (ContractRequest request, String messa
List<Contract> contractsFromDB = contractService.getContracts(contractCriteria);
Contract originalContractFromDB = contractsFromDB.stream().filter(contract -> (contract.getBusinessService() != null && contract.getBusinessService().equalsIgnoreCase(CONTRACT_TIME_EXTENSION_BUSINESS_SERVICE))).collect(Collectors.toList()).get(0);
log.info("Getting officer-in-charge for contract :: " + originalContractFromDB.getContractNumber());
String officerInChargeUuid = originalContractFromDB.getAuditDetails().getCreatedBy();
Map<String,String> officerInChargeMobileNumberMap =hrmsUtils.getEmployeeDetailsByUuid(request.getRequestInfo(), request.getContract().getTenantId(),officerInChargeUuid);
ObjectMapper objectMapper = new ObjectMapper();
String officerInchargeCode = null;
try{
Map<String, Object> addtionalDetailsMap = objectMapper.convertValue(originalContractFromDB.getAdditionalDetails(), Map.class);
if (addtionalDetailsMap.containsKey("officerInChargeName")) {
Map<String, String> officerInChargeNameMap = (Map<String, String>) addtionalDetailsMap.get("officerInChargeName");
officerInchargeCode = officerInChargeNameMap.get("code");
}
}catch (Exception e){
throw new CustomException("OFFICER_INCHARGE_NOT_FOUND","Failed tp fetch officerInCharge details");
}
Map<String,String> officerInChargeMobileNumberMap =hrmsUtils.getEmployeeDetailsByCode(request.getRequestInfo(), request.getContract().getTenantId(),officerInchargeCode);
String officerInChargeMobileNumber = officerInChargeMobileNumberMap.get(MOBILE_NUMBER);
Map<String, String> smsDetailsMap = new HashMap<>();

Expand Down Expand Up @@ -419,11 +438,12 @@ private String getMessage(ContractRequest request, boolean isCBORole) {
*/
public String getMessage(ContractRequest request, String msgCode) {
String locale = "en_IN";
String rootTenantId = request.getContract().getTenantId().split("\\.")[0];
if(request.getRequestInfo().getMsgId().split("\\|").length > 1)
locale = request.getRequestInfo().getMsgId().split("\\|")[1];
Map<String, Map<String, String>> localizedMessageMap = getLocalisedMessages(request.getRequestInfo(), request.getContract().getTenantId(),
Map<String, Map<String, String>> localizedMessageMap = getLocalisedMessages(request.getRequestInfo(), rootTenantId,
locale, ContractServiceConstants.CONTRACTS_MODULE_CODE);
return localizedMessageMap.get(locale + "|" + request.getContract().getTenantId()).get(msgCode);
return localizedMessageMap.get(locale + "|" + rootTenantId).get(msgCode);
}
private String buildMessageForRevisedContract(Map<String, String> userDetailsForSMS, String message, Boolean isSendBack) {
if (Boolean.FALSE.equals(isSendBack)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,6 @@ private ContractServiceConstants() {}
public static final String REVISION_ESTIMATE="REVISION-ESTIMATE";

public static final String REJECTED_STATUS = "REJECTED";

public static final String SUBMIT="SUBMIT";
}
41 changes: 41 additions & 0 deletions backend/contracts/src/main/java/org/egov/works/util/HRMSUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.springframework.util.CollectionUtils;
import org.springframework.web.client.RestTemplate;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -56,6 +57,7 @@ public List<String> getRoleCodesByEmployeeId(RequestInfo requestInfo, String ten
return roles;
}


public Map<String, String> getEmployeeDetailsByUuid(RequestInfo requestInfo, String tenantId, String uuid) {
StringBuilder url = getHRMSURIWithUUid(tenantId, uuid);

Expand Down Expand Up @@ -84,6 +86,34 @@ public Map<String, String> getEmployeeDetailsByUuid(RequestInfo requestInfo, Str
return userDetailsForSMS;
}

public Map<String, String> getEmployeeDetailsByCode(RequestInfo requestInfo, String tenantId, String code) {
StringBuilder url = getHRMSURIWithCode(tenantId,code);

RequestInfoWrapper requestInfoWrapper = RequestInfoWrapper.builder().requestInfo(requestInfo).build();

Object res = serviceRequestRepository.fetchResult(url, requestInfoWrapper);

Map<String, String> userDetailsForSMS = new HashMap<>();
List<String> userNames = null;
List<String> mobileNumbers = null;
List<String> designations=null;

try {
designations = JsonPath.read(res, HRMS_USER_DESIGNATION);
userNames = JsonPath.read(res, HRMS_USER_USERNAME_CODE);
mobileNumbers = JsonPath.read(res, HRMS_USER_MOBILE_NO);

} catch (Exception e) {
throw new CustomException("PARSING_ERROR", "Failed to parse HRMS response");
}

userDetailsForSMS.put("userName", userNames.get(0));
userDetailsForSMS.put("mobileNumber", mobileNumbers.get(0));
userDetailsForSMS.put("designation", designations.get(0));

return userDetailsForSMS;
}

private StringBuilder getHRMSURI(String tenantId, List<String> employeeIds) {

StringBuilder builder = new StringBuilder(config.getHrmsHost());
Expand All @@ -95,6 +125,17 @@ private StringBuilder getHRMSURI(String tenantId, List<String> employeeIds) {

return builder;
}
private StringBuilder getHRMSURIWithCode(String tenantId, String code) {

StringBuilder builder = new StringBuilder(config.getHrmsHost());
builder.append(config.getHrmsEndPoint());
builder.append("?tenantId=");
builder.append(tenantId);
builder.append("&codes=");
builder.append(code);

return builder;
}

private StringBuilder getHRMSURIWithUUid(String tenantId, String employeeUuid) {

Expand Down
Loading

0 comments on commit 554f400

Please sign in to comment.