Skip to content

Commit

Permalink
107258, 107261 changes merger (#127)
Browse files Browse the repository at this point in the history
Co-authored-by: Ravi Saurav <[email protected]>
Co-authored-by: SaipradeepR <[email protected]>
  • Loading branch information
3 people authored Nov 2, 2023
1 parent 8109f51 commit 12d4326
Show file tree
Hide file tree
Showing 7 changed files with 427 additions and 97 deletions.
76 changes: 76 additions & 0 deletions src/main/java/org/sunbird/workflow/config/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,27 @@ public class Configuration {
@Value("${blended.program.batch.in.progress.message}")
private String batchInProgressMessage;

@Value("${bp.mail.body.forwarded.to}")
private String learnerForwardedMailBody;

@Value("${bp.mail.body.rejected.or.remove}")
private String rejectedOrRemovedMailBody;

@Value("${bp.mail.body.approve}")
private String approvedMailBody;

@Value("${notify.email.template}")
private String notificationEmailTemplate;

@Value("${bp.approval.request.mail.body}")
private String approvalRequetMailBody;

@Value("${bp.request.forwarded.mail.body}")
private String requestForwardedMailBody;

@Value("${bp.nomination.request.mail.body}")
private String nominationRequestMailBody;

public String getModificationRecordAllowActions() {
return modificationRecordAllowActions;
}
Expand Down Expand Up @@ -597,4 +618,59 @@ public void setBatchInProgressMessage(String batchInProgressMessage) {
this.batchInProgressMessage = batchInProgressMessage;
}

public String getLearnerForwardedMailBody() {
return learnerForwardedMailBody;
}

public void setLearnerForwardedMailBody(String learnerForwardedMailBody) {
this.learnerForwardedMailBody = learnerForwardedMailBody;
}

public String getRejectedOrRemovedMailBody() {
return rejectedOrRemovedMailBody;
}

public void setRejectedOrRemovedMailBody(String rejectedOrRemovedMailBody) {
this.rejectedOrRemovedMailBody = rejectedOrRemovedMailBody;
}

public String getApprovedMailBody() {
return approvedMailBody;
}

public void setApprovedMailBody(String approvedMailBody) {
this.approvedMailBody = approvedMailBody;
}

public String getNotificationEmailTemplate() {
return notificationEmailTemplate;
}

public void setNotificationEmailTemplate(String notificationEmailTemplate) {
this.notificationEmailTemplate = notificationEmailTemplate;
}

public String getApprovalRequetMailBody() {
return approvalRequetMailBody;
}

public void setApprovalRequetMailBody(String approvalRequetMailBody) {
this.approvalRequetMailBody = approvalRequetMailBody;
}

public String getRequestForwardedMailBody() {
return requestForwardedMailBody;
}

public void setRequestForwardedMailBody(String requestForwardedMailBody) {
this.requestForwardedMailBody = requestForwardedMailBody;
}

public String getNominationRequestMailBody() {
return nominationRequestMailBody;
}

public void setNominationRequestMailBody(String nominationRequestMailBody) {
this.nominationRequestMailBody = nominationRequestMailBody;
}
}
12 changes: 12 additions & 0 deletions src/main/java/org/sunbird/workflow/config/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,18 @@ private Constants() {
public static final String BATCH_SIZE_ERROR = "Batch Size Error";;
public static final String TRUE="True";
public static final String ACTIVE = "active";
public static final String DESCRIPTION = "description";
public static final String COURSE_NAME = "courseName";
public static final String BATCH_NAME = "batchName";
public static final String BATCH_START_DATE = "batchStartDate";
public static final String FROM_EMAIL = "fromEmail";
public static final String DEV_HIERARCHY_STORE = "dev_hierarchy_store";
public static final String CONTENT_HIERARCHY = "content_hierarchy";
public static final String IDENTIFIER = "identifier";
public static final String HIERARCHY = "hierarchy";
public static final Object KARMYOGI_BHARAT = "Karmyogi Bharat";
public static final String TO_PROGRAMME_COORDINATOR = "Programme Coordinator";
public static final String TO_MDO_ADMIN = "MDO Admin";
public static final String DOMAIN ="domain";
public static final String TABLE_MASTER_DATA = "master_data";
public static final String CONTEXT_TYPE = "contextType";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
package org.sunbird.workflow.consumer;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Service;
import org.sunbird.workflow.config.Constants;
import org.sunbird.workflow.models.WfNotification;
import org.sunbird.workflow.models.WfRequest;
import org.sunbird.workflow.service.impl.NotificationServiceImpl;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.sunbird.workflow.utils.CassandraOperation;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class NotificationConsumer {
Expand All @@ -22,30 +31,35 @@ public class NotificationConsumer {
@Autowired
private NotificationServiceImpl notificationService;

@Autowired
private CassandraOperation cassandraOperation;

@KafkaListener(groupId = "workflowNotificationTopic-consumer", topics = "${kafka.topics.workflow.notification}")
public void processMessage(ConsumerRecord<String, String> data) {
WfRequest wfRequest = null;
WfNotification wfNotification = null;
try {
String message = String.valueOf(data.value());
wfRequest = mapper.readValue(message, WfRequest.class);
logger.info("Recevied data in notification consumer : {}", mapper.writeValueAsString(wfRequest));
switch (wfRequest.getServiceName()) {
wfNotification = mapper.readValue(message, WfNotification.class);
Map<String, Object> courseAttributes = getCourseAttributes(wfNotification.getCourseId());
wfNotification.setCourseName((String) courseAttributes.get(Constants.COURSE_NAME));
logger.info("Recevied data in notification consumer : {}", mapper.writeValueAsString(wfNotification));
switch (wfNotification.getServiceName()) {
case Constants.PROFILE_SERVICE_NAME:
notificationService.sendNotification(wfRequest);
notificationService.sendNotificationToMdoAdmin(wfRequest);
notificationService.sendNotification(wfNotification);
notificationService.sendNotificationToMdoAdmin(wfNotification);
break;
case Constants.POSITION_SERVICE_NAME:
case Constants.DOMAIN_SERVICE_NAME:
case Constants.ORGANISATION_SERVICE_NAME:
notificationService.sendEmailNotification(wfRequest);
notificationService.sendEmailNotification(wfNotification);
break;
case Constants.BLENDED_PROGRAM_SERVICE_NAME:
case Constants.ONE_STEP_MDO_APPROVAL:
case Constants.ONE_STEP_PC_APPROVAL:
case Constants.TWO_STEP_MDO_AND_PC_APPROVAL:
case Constants.TWO_STEP_PC_AND_MDO_APPROVAL:
notificationService.sendNotification(wfRequest);
notificationService.sendNotificationToMdoAdminAndPC(wfRequest);
notificationService.sendNotification(wfNotification);
notificationService.sendNotificationToMdoAdminAndPC(wfNotification);
break;
case Constants.USER_REGISTRATION_SERVICE_NAME:
// nothing to do
Expand All @@ -58,4 +72,18 @@ public void processMessage(ConsumerRecord<String, String> data) {
logger.error("Error while deserialization the object value", ex);
}
}

public Map<String, Object> getCourseAttributes(String courseId){
Map<String, Object> propertiesMap = new HashMap<>();
Map<String, Object> courseDetails = new HashMap<>();
propertiesMap.put(Constants.IDENTIFIER, courseId);
List<Map<String, Object>> coursesDataList = cassandraOperation.getRecordsByProperties(Constants.DEV_HIERARCHY_STORE,
Constants.CONTENT_HIERARCHY,
propertiesMap,
Arrays.asList(Constants.IDENTIFIER, Constants.HIERARCHY));
Map<String, Object> hierarchy = new Gson().fromJson((String) coursesDataList.get(0).get("hierarchy"), new TypeToken<HashMap<String, Object>>(){}.getType());
courseDetails.put(Constants.COURSE_NAME, hierarchy.get(Constants.NAME));
return courseDetails;
}

}
36 changes: 36 additions & 0 deletions src/main/java/org/sunbird/workflow/models/WfNotification.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.sunbird.workflow.models;

import java.util.Date;

public class WfNotification extends WfRequest{

private String courseName;

private String batchName;

private Date batchStartDate;

public String getCourseName() {
return courseName;
}

public void setCourseName(String courseName) {
this.courseName = courseName;
}

public String getBatchName() {
return batchName;
}

public void setBatchName(String batchName) {
this.batchName = batchName;
}

public Date getBatchStartDate() {
return batchStartDate;
}

public void setBatchStartDate(Date batchStartDate) {
this.batchStartDate = batchStartDate;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ public Response enrolBPWorkFlow(String rootOrg, String org, WfRequest wfRequest)
response.put(Constants.STATUS, HttpStatus.BAD_REQUEST);
return response;
}
WfNotification wfNotification = getWorkFlowNotificationRequest(wfRequest);
wfNotification.setBatchName((String) courseBatchDetails.get(Constants.BATCH_NAME));
wfNotification.setBatchStartDate((Date) courseBatchDetails.get(Constants.START_DATE));
Response response = saveEnrollUserIntoWfStatus(rootOrg, org, wfRequest);
wfRequest.setServiceName(Constants.BLENDED_PROGRAM_SERVICE_NAME);
producer.push(configuration.getWorkflowApplicationTopic(), wfRequest);
Expand All @@ -107,7 +110,11 @@ public Response enrolBPWorkFlow(String rootOrg, String org, WfRequest wfRequest)
@Override
public Response updateBPWorkFlow(String rootOrg, String org, WfRequest wfRequest,String userId,String role) {
Response response = new Response();
String validationError = validateBatchUserRequestAccess(wfRequest);
Map<String, Object> batchDetailsMap = new HashMap<>();
WfNotification wfNotification = getWorkFlowNotificationRequest(wfRequest);
String validationError = validateBatchUserRequestAccess(wfRequest, batchDetailsMap);
wfNotification.setBatchName((String) batchDetailsMap.get(Constants.BATCH_NAME));
wfNotification.setBatchStartDate((Date) batchDetailsMap.get(Constants.START_DATE));
if (Constants.BATCH_START_DATE_ERROR.equals(validationError)) {
response.put(Constants.ERROR_MESSAGE, configuration.getBatchInProgressMessage());
response.put(Constants.STATUS, HttpStatus.BAD_REQUEST);
Expand Down Expand Up @@ -200,7 +207,7 @@ private Map<String, Object> getCurrentBatchAttributes(String batchId, String cou
Constants.KEYSPACE_SUNBIRD_COURSES,
Constants.TABLE_COURSE_BATCH,
propertyMap,
Arrays.asList(Constants.BATCH_ATTRIBUTES, Constants.ENROLMENT_END_DATE, Constants.START_DATE));
Arrays.asList(Constants.BATCH_ATTRIBUTES, Constants.ENROLMENT_END_DATE, Constants.START_DATE, Constants.NAME));
if (CollectionUtils.isNotEmpty(batchAttributesDetails)) {
Map<String, Object> courseBatch = (Map<String, Object>) batchAttributesDetails.get(0);
if (courseBatch.containsKey(Constants.BATCH_ATTRIBUTES)) {
Expand All @@ -221,10 +228,15 @@ private Map<String, Object> getCurrentBatchAttributes(String batchId, String cou
Date batchStartDate = courseBatch.containsKey(Constants.START_DATE)
? (Date) courseBatch.get(Constants.START_DATE)
: null;
String batchName = batchAttributes != null
&& courseBatch.containsKey(Constants.NAME)
? (String) courseBatch.get(Constants.NAME)
: "";
Map<String, Object> result = new HashMap<>();
result.put(Constants.CURRENT_BATCH_SIZE, currentBatchSize);
result.put(Constants.ENROLMENT_END_DATE, enrollmentEndDate);
result.put(Constants.START_DATE, batchStartDate);
result.put(Constants.BATCH_NAME, batchName);
return result;
} catch (Exception e) {
logger.error(String.format("Failed to retrieve course batch details. CourseId: %s, BatchId: %s",
Expand Down Expand Up @@ -322,12 +334,14 @@ public void processWFRequest(WfRequest wfRequest) {
}


private String validateBatchUserRequestAccess(WfRequest wfRequest) {
private String validateBatchUserRequestAccess(WfRequest wfRequest, Map<String, Object> batchDetailsMap) {
Map<String, Object> courseBatchDetails = getCurrentBatchAttributes(wfRequest.getApplicationId(),
wfRequest.getCourseId());
batchDetailsMap.put(Constants.START_DATE, courseBatchDetails.get(Constants.START_DATE));
batchDetailsMap.put(Constants.BATCH_NAME, courseBatchDetails.get(Constants.BATCH_NAME));
boolean nonEnrolmentState = configuration.getBpBatchFullValidationExcludeStates().contains(wfRequest.getAction());
if(nonEnrolmentState)
return "";
Map<String, Object> courseBatchDetails = getCurrentBatchAttributes(wfRequest.getApplicationId(),
wfRequest.getCourseId());
boolean batchStartDateValid = validateBatchStartDate(courseBatchDetails);
if(!batchStartDateValid)
return Constants.BATCH_START_DATE_ERROR;
Expand Down Expand Up @@ -497,6 +511,9 @@ public Response adminEnrolBPWorkFlow(String rootOrg, String org, WfRequest wfReq
response.put(Constants.MESSAGE, "Not allowed to enroll the user to the Blended Program");
response.put(Constants.STATUS, HttpStatus.OK);
} else {
WfNotification wfNotification = getWorkFlowNotificationRequest(wfRequest);
wfNotification.setBatchName((String) courseBatchDetails.get(Constants.BATCH_NAME));
wfNotification.setBatchStartDate((Date) courseBatchDetails.get(Constants.START_DATE));
response = saveAdminEnrollUserIntoWfStatus(rootOrg, org, wfRequest);
// producer.push(configuration.getWorkFlowNotificationTopic(), wfRequest);
wfRequest.setAction(Constants.INITIATE);
Expand Down Expand Up @@ -567,9 +584,12 @@ public Response removeBPWorkFlow(String rootOrg, String org, WfRequest wfRequest
response.put(Constants.ERROR_MESSAGE, HttpStatus.INTERNAL_SERVER_ERROR);
} else if (approvedLearners.size() == 1)
wfRequest.setWfId(approvedLearners.get(0).getWfId());
response = workflowService.workflowTransition(rootOrg, org, wfRequest,userId,role);

WfNotification wfNotification = getWorkFlowNotificationRequest(wfRequest);
wfNotification.setBatchName((String) courseBatchDetails.get(Constants.BATCH_NAME));
wfNotification.setBatchStartDate((Date) courseBatchDetails.get(Constants.START_DATE));
response = workflowService.workflowTransition(rootOrg, org, wfNotification, userId,role);
response.put(Constants.STATUS, HttpStatus.OK);

return response;
}

Expand Down Expand Up @@ -996,7 +1016,24 @@ private void handleApprovalRequest(WfRequest wfRequest) {
} catch (IOException e) {
throw new ApplicationException(Constants.WORKFLOW_PARSING_ERROR_MESSAGE, e);
}
}


private WfNotification getWorkFlowNotificationRequest(WfRequest wfRequest) {
WfNotification wfNotification = new WfNotification();
wfNotification.setState(wfRequest.getState());
wfNotification.setAction(wfRequest.getAction());
wfNotification.setDeptName(wfRequest.getDeptName());
wfNotification.setComment(wfRequest.getComment());
wfNotification.setWfId(wfRequest.getWfId());
wfNotification.setServiceName(wfRequest.getServiceName());
wfNotification.setActorUserId(wfNotification.getActorUserId());
wfNotification.setCourseId(wfRequest.getCourseId());
wfNotification.setUpdateFieldValues(wfRequest.getUpdateFieldValues());
wfNotification.setRootOrgId(wfRequest.getRootOrgId());
wfNotification.setUserId(wfRequest.getUserId());
wfNotification.setApplicationId(wfRequest.getApplicationId());

return wfNotification;
}
}
Loading

0 comments on commit 12d4326

Please sign in to comment.