From 66f171c23dd9a2acb7460567debfb83dcaa21a50 Mon Sep 17 00:00:00 2001 From: Ravi Saurav Date: Tue, 17 Oct 2023 22:19:01 +0530 Subject: [PATCH 01/18] 109810:added active true condition for a user enrolled in differet batches/courses --- .../org/sunbird/workflow/service/impl/BPWorkFlowServiceImpl.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/sunbird/workflow/service/impl/BPWorkFlowServiceImpl.java b/src/main/java/org/sunbird/workflow/service/impl/BPWorkFlowServiceImpl.java index 5b752380..b0a44b57 100644 --- a/src/main/java/org/sunbird/workflow/service/impl/BPWorkFlowServiceImpl.java +++ b/src/main/java/org/sunbird/workflow/service/impl/BPWorkFlowServiceImpl.java @@ -675,6 +675,7 @@ public boolean enrollmentDateValidations(List> enrolledCours public List> getUserEnrolmentDetails(WfRequest wfRequest) { Map propertyMap = new HashMap<>(); propertyMap.put(Constants.USER_ID, wfRequest.getUserId()); + propertyMap.put(Constants.ACTIVE, Boolean.TRUE); return cassandraOperation.getRecordsByProperties( Constants.KEYSPACE_SUNBIRD_COURSES, Constants.USER_ENROLMENTS, From d7cb7a016960adae64f19657f77d8d4401b0441b Mon Sep 17 00:00:00 2001 From: Ravi Saurav Date: Wed, 18 Oct 2023 12:18:41 +0530 Subject: [PATCH 02/18] 109810:modified the active batch filter criteria --- .../workflow/service/impl/BPWorkFlowServiceImpl.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/sunbird/workflow/service/impl/BPWorkFlowServiceImpl.java b/src/main/java/org/sunbird/workflow/service/impl/BPWorkFlowServiceImpl.java index b0a44b57..4f9af021 100644 --- a/src/main/java/org/sunbird/workflow/service/impl/BPWorkFlowServiceImpl.java +++ b/src/main/java/org/sunbird/workflow/service/impl/BPWorkFlowServiceImpl.java @@ -675,13 +675,13 @@ public boolean enrollmentDateValidations(List> enrolledCours public List> getUserEnrolmentDetails(WfRequest wfRequest) { Map propertyMap = new HashMap<>(); propertyMap.put(Constants.USER_ID, wfRequest.getUserId()); - propertyMap.put(Constants.ACTIVE, Boolean.TRUE); - return cassandraOperation.getRecordsByProperties( + List> allEnrollmentDetails = cassandraOperation.getRecordsByProperties( Constants.KEYSPACE_SUNBIRD_COURSES, Constants.USER_ENROLMENTS, propertyMap, - Arrays.asList(Constants.BATCH_ID, Constants.USER_ID, Constants.COURSE_ID) + Arrays.asList(Constants.BATCH_ID, Constants.USER_ID, Constants.COURSE_ID, Constants.ACTIVE) ); + return allEnrollmentDetails.stream().filter( e -> (boolean)e.get(Constants.ACTIVE)).collect(Collectors.toList()); } /** From e543dddcaabc56295b8236f23cf498dbdc9fef92 Mon Sep 17 00:00:00 2001 From: Sahil-tarento <140611066+Sahil-tarento@users.noreply.github.com> Date: Fri, 20 Oct 2023 15:42:24 +0530 Subject: [PATCH 03/18] Dev 4.8.8 pagination (#114) * Domain Pagination Adding * Domain Pagination and Query changes --- .../workflow/postgres/repo/WfStatusRepo.java | 2 + .../DomainWhiteListWorkFlowServiceImpl.java | 61 ++++++++++++++++++- 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/sunbird/workflow/postgres/repo/WfStatusRepo.java b/src/main/java/org/sunbird/workflow/postgres/repo/WfStatusRepo.java index b76e29db..597ec7cf 100644 --- a/src/main/java/org/sunbird/workflow/postgres/repo/WfStatusRepo.java +++ b/src/main/java/org/sunbird/workflow/postgres/repo/WfStatusRepo.java @@ -82,4 +82,6 @@ public interface WfStatusRepo extends JpaRepository { @Query(value = "SELECT * FROM wingspan.wf_status WHERE current_status IN (?1) AND application_id IN (?2) ", nativeQuery = true) List findByStatusAndAppIds(List currentStatus, List applicationIds); + @Query(value = "select application_id from wingspan.wf_status where service_name = ?1 and current_status = ?2 and dept_name = ?3 group by application_id", countQuery = "select count(application_id) from wingspan.wf_status where service_name = ?1 and current_status = ?2 group by application_id", nativeQuery = true) + List getListOfDistinctApplicationUsingDept(String serviceName, String currentStatus, String deptName, Pageable pageable); } diff --git a/src/main/java/org/sunbird/workflow/service/impl/DomainWhiteListWorkFlowServiceImpl.java b/src/main/java/org/sunbird/workflow/service/impl/DomainWhiteListWorkFlowServiceImpl.java index c4ddb8a9..16f49456 100644 --- a/src/main/java/org/sunbird/workflow/service/impl/DomainWhiteListWorkFlowServiceImpl.java +++ b/src/main/java/org/sunbird/workflow/service/impl/DomainWhiteListWorkFlowServiceImpl.java @@ -1,20 +1,40 @@ package org.sunbird.workflow.service.impl; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; +import org.springframework.util.StringUtils; +import org.sunbird.workflow.config.Configuration; import org.sunbird.workflow.config.Constants; +import org.sunbird.workflow.exception.BadRequestException; import org.sunbird.workflow.models.Response; import org.sunbird.workflow.models.SearchCriteria; import org.sunbird.workflow.models.WfRequest; +import org.sunbird.workflow.postgres.entity.WfStatusEntity; +import org.sunbird.workflow.postgres.repo.WfStatusRepo; import org.sunbird.workflow.service.DomainWhiteListWorkFlowService; import org.sunbird.workflow.service.Workflowservice; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + @Service public class DomainWhiteListWorkFlowServiceImpl implements DomainWhiteListWorkFlowService { @Autowired private Workflowservice workflowService; + @Autowired + private Configuration configuration; + + @Autowired + private WfStatusRepo wfStatusRepo; + @Override public Response createDomainWorkFlow(String rootOrg, String org, WfRequest wfRequest) { Response response = workflowService.workflowTransition(rootOrg, org, wfRequest); @@ -35,7 +55,46 @@ public Response readDomainWFApplication(String rootOrg, String org, String wfId, @Override public Response domainSearch(String rootOrg, String org, SearchCriteria criteria) { - Response response = workflowService.applicationsSearch(rootOrg, org, criteria, Constants.DOMAIN_SEARCH_ENABLED); + Response response = applicationSearchOnApplicationIdGroup(criteria); return response; } + + public Response applicationSearchOnApplicationIdGroup(SearchCriteria criteria) { + Pageable pageable = getPageReqForApplicationSearch(criteria); + List applicationIds = criteria.getApplicationIds(); + Map> infos = null; + if (CollectionUtils.isEmpty(applicationIds)) { + applicationIds = wfStatusRepo.getListOfDistinctApplicationUsingDept(criteria.getServiceName(), + criteria.getApplicationStatus(), criteria.getDeptName(), pageable); + } + List wfStatusEntities = null; + wfStatusEntities = wfStatusRepo.findByServiceNameAndCurrentStatusAndDeptNameAndApplicationIdIn( + criteria.getServiceName(), criteria.getApplicationStatus(), criteria.getDeptName(), applicationIds); + + infos = wfStatusEntities.stream().collect(Collectors.groupingBy(WfStatusEntity::getApplicationId)); + Response response = new Response(); + response.put(Constants.MESSAGE, Constants.SUCCESSFUL); + response.put(Constants.DATA, infos); + response.put(Constants.STATUS, HttpStatus.OK); + return response; + } + + private Pageable getPageReqForApplicationSearch(SearchCriteria criteria) { + Pageable pageable; + if (criteria.isEmpty()) { + throw new BadRequestException(Constants.SEARCH_CRITERIA_VALIDATION); + } + Integer limit = configuration.getDefaultLimit(); + Integer offset = configuration.getDefaultOffset(); + if (criteria.getLimit() == null && criteria.getOffset() == null) + limit = configuration.getMaxLimit(); + if (criteria.getLimit() != null && criteria.getLimit() <= configuration.getDefaultLimit()) + limit = criteria.getLimit(); + if (criteria.getLimit() != null && criteria.getLimit() > configuration.getDefaultLimit()) + limit = configuration.getDefaultLimit(); + if (criteria.getOffset() != null) + offset = criteria.getOffset(); + pageable = PageRequest.of(offset, limit); + return pageable; + } } From 4a0a6f802ac604c7e37da9b1d16d45d6ac68f67b Mon Sep 17 00:00:00 2001 From: sahilchaudhary Date: Fri, 20 Oct 2023 19:13:19 +0530 Subject: [PATCH 04/18] KBE-542BE : Analysis and Implementation Email Domain approval from SPV Portal --- .../sunbird/workflow/config/Constants.java | 8 +++- .../DomainWhiteListWorkFlowService.java | 2 + .../ApplicationProcessingServiceImpl.java | 6 +++ .../DomainWhiteListWorkFlowServiceImpl.java | 41 ++++++++++++++++--- .../workflow/utils/CassandraOperation.java | 4 +- .../utils/CassandraOperationImpl.java | 19 ++++++++- .../resources/cassandratablecolumn.properties | 4 +- 7 files changed, 74 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/sunbird/workflow/config/Constants.java b/src/main/java/org/sunbird/workflow/config/Constants.java index 6fc9ecf3..05ad47a4 100644 --- a/src/main/java/org/sunbird/workflow/config/Constants.java +++ b/src/main/java/org/sunbird/workflow/config/Constants.java @@ -236,7 +236,11 @@ private Constants() { public static final String ORGANIZATION_NAME ="orgName"; public static final String BATCH_START_DATE_ERROR = "Batch Start Date Error"; 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 DOMAIN ="domain"; + public static final String TABLE_MASTER_DATA = "master_data"; + public static final String CONTEXT_TYPE = "contextType"; + public static final String CONTEXT_NAME = "contextName"; + public static final String USER_REGISTRATION_PRE_APPROVED_DOMAIN = "userRegistrationPreApprovedDomain"; +} \ No newline at end of file diff --git a/src/main/java/org/sunbird/workflow/service/DomainWhiteListWorkFlowService.java b/src/main/java/org/sunbird/workflow/service/DomainWhiteListWorkFlowService.java index fba908fc..cf14f0be 100644 --- a/src/main/java/org/sunbird/workflow/service/DomainWhiteListWorkFlowService.java +++ b/src/main/java/org/sunbird/workflow/service/DomainWhiteListWorkFlowService.java @@ -13,4 +13,6 @@ public interface DomainWhiteListWorkFlowService { public Response readDomainWFApplication(String rootOrg, String org, String wfId, String applicationId); public Response domainSearch(String rootOrg, String org, SearchCriteria criteria); + + public void processDomainRequest(WfRequest wfRequest); } diff --git a/src/main/java/org/sunbird/workflow/service/impl/ApplicationProcessingServiceImpl.java b/src/main/java/org/sunbird/workflow/service/impl/ApplicationProcessingServiceImpl.java index 50e6349c..7a450e44 100644 --- a/src/main/java/org/sunbird/workflow/service/impl/ApplicationProcessingServiceImpl.java +++ b/src/main/java/org/sunbird/workflow/service/impl/ApplicationProcessingServiceImpl.java @@ -15,6 +15,7 @@ import org.sunbird.workflow.postgres.entity.WfStatusEntity; import org.sunbird.workflow.postgres.repo.WfStatusRepo; import org.sunbird.workflow.service.BPWorkFlowService; +import org.sunbird.workflow.service.DomainWhiteListWorkFlowService; import org.sunbird.workflow.service.UserProfileWfService; import org.sunbird.workflow.service.UserRegistrationWfService; @@ -37,6 +38,9 @@ public class ApplicationProcessingServiceImpl { @Autowired private BPWorkFlowService bpWorkFlowService; + @Autowired + private DomainWhiteListWorkFlowService domainWhiteListWorkFlowService; + Logger logger = LogManager.getLogger(ApplicationProcessingServiceImpl.class); public void processWfApplicationRequest(WfRequest wfRequest) { @@ -49,6 +53,8 @@ public void processWfApplicationRequest(WfRequest wfRequest) { case Constants.USER_REGISTRATION_SERVICE_NAME: userRegService.processMessage(wfRequest); break; + case Constants.DOMAIN: + domainWhiteListWorkFlowService.processDomainRequest(wfRequest); case Constants.BLENDED_PROGRAM_SERVICE_NAME: case Constants.ONE_STEP_MDO_APPROVAL: case Constants.ONE_STEP_PC_APPROVAL: diff --git a/src/main/java/org/sunbird/workflow/service/impl/DomainWhiteListWorkFlowServiceImpl.java b/src/main/java/org/sunbird/workflow/service/impl/DomainWhiteListWorkFlowServiceImpl.java index 16f49456..85807b30 100644 --- a/src/main/java/org/sunbird/workflow/service/impl/DomainWhiteListWorkFlowServiceImpl.java +++ b/src/main/java/org/sunbird/workflow/service/impl/DomainWhiteListWorkFlowServiceImpl.java @@ -1,12 +1,12 @@ package org.sunbird.workflow.service.impl; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; -import org.springframework.util.CollectionUtils; -import org.springframework.util.StringUtils; import org.sunbird.workflow.config.Configuration; import org.sunbird.workflow.config.Constants; import org.sunbird.workflow.exception.BadRequestException; @@ -17,10 +17,9 @@ import org.sunbird.workflow.postgres.repo.WfStatusRepo; import org.sunbird.workflow.service.DomainWhiteListWorkFlowService; import org.sunbird.workflow.service.Workflowservice; +import org.sunbird.workflow.utils.CassandraOperation; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; @Service @@ -35,6 +34,9 @@ public class DomainWhiteListWorkFlowServiceImpl implements DomainWhiteListWorkFl @Autowired private WfStatusRepo wfStatusRepo; + @Autowired + CassandraOperation cassandraOperation; + @Override public Response createDomainWorkFlow(String rootOrg, String org, WfRequest wfRequest) { Response response = workflowService.workflowTransition(rootOrg, org, wfRequest); @@ -97,4 +99,33 @@ private Pageable getPageReqForApplicationSearch(SearchCriteria criteria) { pageable = PageRequest.of(offset, limit); return pageable; } + + @Override + public void processDomainRequest(WfRequest wfRequest) { + if (Constants.APPROVE_STATE.equalsIgnoreCase(wfRequest.getAction())) { + List> updatedFieldValues = wfRequest.getUpdateFieldValues(); + String approvedDomain = ""; + for (HashMap updatedFieldValue : updatedFieldValues) { + if (updatedFieldValue.containsKey(Constants.TO_VALUE)) { + Map toValueMap = (Map) updatedFieldValue.get(Constants.TO_VALUE); + approvedDomain = (String) toValueMap.get(Constants.DOMAIN); + } + } + if (StringUtils.isNotEmpty(approvedDomain) && !isAlreadyApprovedDomains(approvedDomain)) { + Map propertyMap = new HashMap<>(); + propertyMap.put(Constants.CONTEXT_TYPE, Constants.USER_REGISTRATION_PRE_APPROVED_DOMAIN); + propertyMap.put(Constants.CONTEXT_NAME, approvedDomain); + cassandraOperation.insertRecord(Constants.KEYSPACE_SUNBIRD, Constants.TABLE_MASTER_DATA, propertyMap); + } + } + } + + private Boolean isAlreadyApprovedDomains(String emailDomain) { + Map propertyMap = new HashMap<>(); + propertyMap.put(Constants.CONTEXT_TYPE, Constants.USER_REGISTRATION_PRE_APPROVED_DOMAIN); + propertyMap.put(Constants.CONTEXT_NAME, emailDomain); + List> listOfDomains = cassandraOperation.getRecordsByProperties( + Constants.KEYSPACE_SUNBIRD, Constants.TABLE_MASTER_DATA, propertyMap, Arrays.asList(Constants.CONTEXT_TYPE, Constants.CONTEXT_NAME)); + return CollectionUtils.isNotEmpty(listOfDomains); + } } diff --git a/src/main/java/org/sunbird/workflow/utils/CassandraOperation.java b/src/main/java/org/sunbird/workflow/utils/CassandraOperation.java index e2bcac94..0093a8b3 100644 --- a/src/main/java/org/sunbird/workflow/utils/CassandraOperation.java +++ b/src/main/java/org/sunbird/workflow/utils/CassandraOperation.java @@ -9,4 +9,6 @@ List> getRecordsByProperties(String keyspaceName, String tab Map propertyMap, List fields); int getCountByProperties(String keyspaceName, String tableName, Map propertyMap); -} + + void insertRecord(String keyspaceName, String tableName, Map request); +} \ No newline at end of file diff --git a/src/main/java/org/sunbird/workflow/utils/CassandraOperationImpl.java b/src/main/java/org/sunbird/workflow/utils/CassandraOperationImpl.java index 2bd99277..0c0a416c 100644 --- a/src/main/java/org/sunbird/workflow/utils/CassandraOperationImpl.java +++ b/src/main/java/org/sunbird/workflow/utils/CassandraOperationImpl.java @@ -89,4 +89,21 @@ private Select processQuery(String keyspaceName, String tableName, Map request) { + String query = CassandraUtil.getPreparedStatement(keyspaceName, tableName, request); + try { + PreparedStatement statement = connectionManager.getSession(keyspaceName).prepare(query); + BoundStatement boundStatement = new BoundStatement(statement); + Iterator iterator = request.values().iterator(); + Object[] array = new Object[request.keySet().size()]; + int i = 0; + while (iterator.hasNext()) { + array[i++] = iterator.next(); + } + connectionManager.getSession(keyspaceName).execute(boundStatement.bind(array)); + } catch (Exception e) { + String.format("Exception occurred while inserting record to %s %s", tableName, e.getMessage()); + } + } +} \ No newline at end of file diff --git a/src/main/resources/cassandratablecolumn.properties b/src/main/resources/cassandratablecolumn.properties index 93121384..d7ff50f0 100644 --- a/src/main/resources/cassandratablecolumn.properties +++ b/src/main/resources/cassandratablecolumn.properties @@ -1,2 +1,4 @@ #id=id -#failedrecordscount=failedRecordsCount \ No newline at end of file +#failedrecordscount=failedRecordsCount +contextType=contexttype +contextName=contextname \ No newline at end of file From 2c197c8dfcd89dc19c5aa0426548ba7ff32bfc28 Mon Sep 17 00:00:00 2001 From: Ravi Saurav Date: Mon, 23 Oct 2023 03:45:05 +0530 Subject: [PATCH 05/18] 107258:Changes to add batch name, course name, batch start date and new mail body, subject line for notification mail --- .../workflow/config/Configuration.java | 32 +++++++ .../sunbird/workflow/config/Constants.java | 4 + .../sunbird/workflow/models/WfRequest.java | 33 +++++++ .../service/impl/BPWorkFlowServiceImpl.java | 27 ++++-- .../service/impl/NotificationServiceImpl.java | 88 +++++++++++++++---- 5 files changed, 163 insertions(+), 21 deletions(-) diff --git a/src/main/java/org/sunbird/workflow/config/Configuration.java b/src/main/java/org/sunbird/workflow/config/Configuration.java index f7f9650d..26c93514 100644 --- a/src/main/java/org/sunbird/workflow/config/Configuration.java +++ b/src/main/java/org/sunbird/workflow/config/Configuration.java @@ -164,6 +164,15 @@ 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; + public String getModificationRecordAllowActions() { return modificationRecordAllowActions; } @@ -597,4 +606,27 @@ 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; + } } diff --git a/src/main/java/org/sunbird/workflow/config/Constants.java b/src/main/java/org/sunbird/workflow/config/Constants.java index 6fc9ecf3..4d9e17e2 100644 --- a/src/main/java/org/sunbird/workflow/config/Constants.java +++ b/src/main/java/org/sunbird/workflow/config/Constants.java @@ -239,4 +239,8 @@ private Constants() { 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"; } diff --git a/src/main/java/org/sunbird/workflow/models/WfRequest.java b/src/main/java/org/sunbird/workflow/models/WfRequest.java index 4513ad61..962dae09 100644 --- a/src/main/java/org/sunbird/workflow/models/WfRequest.java +++ b/src/main/java/org/sunbird/workflow/models/WfRequest.java @@ -1,5 +1,6 @@ package org.sunbird.workflow.models; +import java.util.Date; import java.util.HashMap; import java.util.List; @@ -26,8 +27,15 @@ public class WfRequest { private String deptName; private String rootOrgId; + private String courseId; + private String courseName; + + private String batchName; + + private Date batchStartDate; + public String getState() { return state; } @@ -123,4 +131,29 @@ public String getCourseId() { public void setCourseId(String courseId) { this.courseId = courseId; } + + 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; + } + } diff --git a/src/main/java/org/sunbird/workflow/service/impl/BPWorkFlowServiceImpl.java b/src/main/java/org/sunbird/workflow/service/impl/BPWorkFlowServiceImpl.java index 4f9af021..b0d54296 100644 --- a/src/main/java/org/sunbird/workflow/service/impl/BPWorkFlowServiceImpl.java +++ b/src/main/java/org/sunbird/workflow/service/impl/BPWorkFlowServiceImpl.java @@ -107,7 +107,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 batchDetailsMap = new HashMap<>(); + String validationError = validateBatchUserRequestAccess(wfRequest, batchDetailsMap); + wfRequest.setCourseName((String) batchDetailsMap.get(Constants.COURSE_NAME)); + wfRequest.setBatchName((String) batchDetailsMap.get(Constants.BATCH_NAME)); + wfRequest.setBatchStartDate((Date) batchDetailsMap.get(Constants.BATCH_START_DATE)); if (Constants.BATCH_START_DATE_ERROR.equals(validationError)) { response.put(Constants.ERROR_MESSAGE, configuration.getBatchInProgressMessage()); response.put(Constants.STATUS, HttpStatus.BAD_REQUEST); @@ -200,7 +204,7 @@ private Map 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, Constants.DESCRIPTION)); if (CollectionUtils.isNotEmpty(batchAttributesDetails)) { Map courseBatch = (Map) batchAttributesDetails.get(0); if (courseBatch.containsKey(Constants.BATCH_ATTRIBUTES)) { @@ -221,10 +225,20 @@ private Map getCurrentBatchAttributes(String batchId, String cou Date batchStartDate = courseBatch.containsKey(Constants.START_DATE) ? (Date) courseBatch.get(Constants.START_DATE) : null; + String courseName = batchAttributes != null + && courseBatch.containsKey(Constants.NAME) + ? (String) courseBatch.get(Constants.NAME) + : ""; + String batchName = batchAttributes != null + && courseBatch.containsKey(Constants.DESCRIPTION) + ? (String) courseBatch.get(Constants.DESCRIPTION) + : ""; Map 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.COURSE_NAME, courseName); + 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", @@ -322,12 +336,15 @@ public void processWFRequest(WfRequest wfRequest) { } - private String validateBatchUserRequestAccess(WfRequest wfRequest) { + private String validateBatchUserRequestAccess(WfRequest wfRequest, Map batchDetailsMap) { + Map courseBatchDetails = getCurrentBatchAttributes(wfRequest.getApplicationId(), + wfRequest.getCourseId()); + batchDetailsMap.put(Constants.BATCH_START_DATE, courseBatchDetails.get(Constants.START_DATE)); + batchDetailsMap.put(Constants.COURSE_NAME, courseBatchDetails.get(Constants.COURSE_NAME)); + batchDetailsMap.put(Constants.BATCH_NAME, courseBatchDetails.get(Constants.BATCH_NAME)); boolean nonEnrolmentState = configuration.getBpBatchFullValidationExcludeStates().contains(wfRequest.getAction()); if(nonEnrolmentState) return ""; - Map courseBatchDetails = getCurrentBatchAttributes(wfRequest.getApplicationId(), - wfRequest.getCourseId()); boolean batchStartDateValid = validateBatchStartDate(courseBatchDetails); if(!batchStartDateValid) return Constants.BATCH_START_DATE_ERROR; diff --git a/src/main/java/org/sunbird/workflow/service/impl/NotificationServiceImpl.java b/src/main/java/org/sunbird/workflow/service/impl/NotificationServiceImpl.java index a3aa4d66..4fac023b 100644 --- a/src/main/java/org/sunbird/workflow/service/impl/NotificationServiceImpl.java +++ b/src/main/java/org/sunbird/workflow/service/impl/NotificationServiceImpl.java @@ -31,7 +31,6 @@ @Service public class NotificationServiceImpl { - public static final String EMAILTEMPLATE = "emailtemplate"; Logger logger = LogManager.getLogger(ApplicationProcessingConsumer.class); @Autowired @@ -71,12 +70,30 @@ public class NotificationServiceImpl { private static final String TO_VALUE_CONST = "toValue"; + public static final String EMAILTEMPLATE = "emailtemplate"; + + private static final String COURSE_NAME_TAG = "#course_name"; + + private static final String BATCH_NAME_TAG = "#batch_name"; + + private static final String Role_TAG = "#role"; + + private static final String ACT_TAG = "#action"; + + private static final String BATCH_START_DATE_TAG = "#batch_start_date"; + private static final String MAIL_SUBJECT = "Your request is #state"; + private static final String MDO_MAIL_SUBJECT = "Request for approval"; + private static final String ENROLMENT_ACTION_SUBJECT = "Enrollment #action"; + private static final String MAIL_BODY = "Your request to update #fieldKey to #toValue is #state "; + private static final String BP_MAIL_BODY = "Your request for batch enrollment is #state."; + private static final String BP_MDO_PC_SUBJECT_LINE = "Enrollment Request Forwarded to #role"; + /** * Send notification to the user based on state of application * @@ -97,19 +114,18 @@ public void sendNotification(WfRequest wfRequest) { logger.info("Enter's in the notification block"); Set usersId = new HashSet<>(); usersId.add(wfRequest.getUserId()); - switch (wfRequest.getServiceName()) { - 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: - break; - default: - usersId.add(wfStatusEntity.getApplicationId()); + Set blendedProgrammeServiceNames = new HashSet<>(); + blendedProgrammeServiceNames.addAll(Arrays.asList(Constants.BLENDED_PROGRAM_SERVICE_NAME, + Constants.ONE_STEP_MDO_APPROVAL, + Constants.ONE_STEP_PC_APPROVAL, + Constants.TWO_STEP_MDO_AND_PC_APPROVAL, + Constants.TWO_STEP_PC_AND_MDO_APPROVAL)); + if(!blendedProgrammeServiceNames.contains(wfRequest.getServiceName())){ + usersId.add(wfStatusEntity.getApplicationId()); } HashMap usersObj = userProfileWfService.getUsersResult(usersId); Map recipientInfo; - if (Constants.BLENDED_PROGRAM_SERVICE_NAME.equalsIgnoreCase(wfRequest.getServiceName())) { + if (blendedProgrammeServiceNames.contains(wfRequest.getServiceName())) { recipientInfo = (Map)usersObj.get(wfRequest.getUserId()); } else { recipientInfo = (Map)usersObj.get(wfStatusEntity.getApplicationId()); @@ -123,14 +139,54 @@ public void sendNotification(WfRequest wfRequest) { Template template = new Template(); template.setId(EMAILTEMPLATE); Optional> updatedFieldValue = wfRequest.getUpdateFieldValues().stream().findFirst(); + String subjectLine = ""; if (updatedFieldValue.isPresent()) { - if (Constants.BLENDED_PROGRAM_SERVICE_NAME.equalsIgnoreCase(wfRequest.getServiceName())) { - params.put("body", BP_MAIL_BODY.replace(STATE_NAME_TAG, wfStatusEntity.getCurrentStatus())); - } else { + if (blendedProgrammeServiceNames.contains(wfRequest.getServiceName())) { + switch (wfStatusEntity.getCurrentStatus()){ + case Constants.SEND_FOR_PC_APPROVAL: + subjectLine = BP_MDO_PC_SUBJECT_LINE.replace(Role_TAG,Constants.PROGRAM_COORDINATOR.replace("_"," ")); + params.put("body",configuration.getLearnerForwardedMailBody() + .replace(COURSE_NAME_TAG, wfRequest.getCourseName()) + .replace(BATCH_NAME_TAG, wfRequest.getBatchName()) + .replace(BATCH_START_DATE_TAG, wfRequest.getBatchStartDate().toString()) + .replace(Role_TAG,Constants.PROGRAM_COORDINATOR.replace("_"," "))); + break; + case Constants.SEND_FOR_MDO_APPROVAL: + subjectLine = BP_MDO_PC_SUBJECT_LINE.replace(Role_TAG,Constants.MDO_ADMIN.split("_")[0]); + params.put("body",configuration.getApprovedMailBody() + .replace(COURSE_NAME_TAG, wfRequest.getCourseName()) + .replace(BATCH_NAME_TAG, wfRequest.getBatchName()) + .replace(BATCH_START_DATE_TAG, wfRequest.getBatchStartDate().toString()) + .replace(Role_TAG,Constants.MDO_ADMIN.split("_")[0])); + break; + case Constants.APPROVED: + subjectLine = ENROLMENT_ACTION_SUBJECT.replace(ACT_TAG, wfStatusEntity.getCurrentStatus()); + params.put("body", configuration.getApprovedMailBody() + .replace(BATCH_NAME_TAG, wfRequest.getBatchName()) + .replace(COURSE_NAME_TAG, wfRequest.getCourseName()) + .replace(BATCH_START_DATE_TAG, wfRequest.getBatchStartDate().toString())); + break; + case Constants.REJECTED: + case Constants.REMOVED: + subjectLine = ENROLMENT_ACTION_SUBJECT.replace(ACT_TAG, wfStatusEntity.getCurrentStatus()); + params.put("body",configuration.getRejectedOrRemovedMailBody() + .replace(BATCH_NAME_TAG, wfRequest.getBatchName()) + .replace(COURSE_NAME_TAG, wfRequest.getCourseName()) + .replace(ACT_TAG,wfStatusEntity.getCurrentStatus()) + .replace(BATCH_START_DATE_TAG, wfRequest.getBatchStartDate().toString())); + break; + default: + subjectLine = MAIL_SUBJECT.replace(STATE_NAME_TAG, wfStatusEntity.getCurrentStatus()); + params.put("body", BP_MAIL_BODY.replace(STATE_NAME_TAG, wfStatusEntity.getCurrentStatus())); + break; + } + } + else { HashMap toValue = (HashMap) updatedFieldValue.get().get(TO_VALUE_CONST); params.put("body", MAIL_BODY.replace(STATE_NAME_TAG, wfStatusEntity.getCurrentStatus()) .replace(FIELD_KEY_TAG, toValue.entrySet().iterator().next().getKey()).replace(TO_VALUE_TAG, (String) toValue.entrySet().iterator().next().getValue())); - } + subjectLine = MAIL_SUBJECT.replace(STATE_NAME_TAG, wfStatusEntity.getCurrentStatus()); + } } if (StringUtils.isNotBlank(wfRequest.getComment())) { String body = (String) params.get("body"); @@ -141,7 +197,7 @@ public void sendNotification(WfRequest wfRequest) { params.put("orgImageUrl", null); template.setParams(params); Config config = new Config(); - config.setSubject(MAIL_SUBJECT.replace(STATE_NAME_TAG, wfStatusEntity.getCurrentStatus())); + config.setSubject(subjectLine); config.setSender((String)senderInfo.get("email")); Map req = new HashMap<>(); request.setTemplate(template); From 0bafb5a30d6251603b5e8ad175a356bcae17dbb0 Mon Sep 17 00:00:00 2001 From: ravisaurav-tarento <142487505+ravisaurav-tarento@users.noreply.github.com> Date: Mon, 23 Oct 2023 03:49:27 +0530 Subject: [PATCH 06/18] Update application.properties 107258:email body in properties file --- src/main/resources/application.properties | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 0868e150..a236f4e4 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -106,3 +106,8 @@ blended.program.enrol.conflict.reject.reason=Conflict, User already enrolled to blended.program.enrol.batch.full.message=This batch is full wfstatus.allowed.action.for.modification.history.entry=REMOVE,REJECT,APPROVE blended.program.batch.in.progress.message=This batch is already in progress + +#blended_mail_subject_body +bp.mail.body.forwarded.to=Your enrollment request for #batch_name of the #course_name Program, starting on #batch_start_date has been forwarded to the #role for approval. +bp.mail.body.rejected.or.remove=We regret to inform you that your enrollment request for #batch_name of the #course_name Program, starting on #batch_start_date has been #action +bp.mail.body.approve="We are pleased to inform you that your enrollment request for #batch_name of the #course_name Program, starting on #batch_start_date has been approved. From b0682a2fe56dd8aec6e7a62b5773a63ff443b911 Mon Sep 17 00:00:00 2001 From: Ravi Saurav Date: Mon, 23 Oct 2023 12:04:54 +0530 Subject: [PATCH 07/18] 107258:modified property name in the config class to coorect value --- src/main/java/org/sunbird/workflow/config/Configuration.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/sunbird/workflow/config/Configuration.java b/src/main/java/org/sunbird/workflow/config/Configuration.java index 26c93514..d62fce87 100644 --- a/src/main/java/org/sunbird/workflow/config/Configuration.java +++ b/src/main/java/org/sunbird/workflow/config/Configuration.java @@ -170,7 +170,7 @@ public class Configuration { @Value("${bp.mail.body.rejected.or.remove}") private String rejectedOrRemovedMailBody; - @Value("${bp.mail.body.approve=}") + @Value("${bp.mail.body.approve}") private String approvedMailBody; public String getModificationRecordAllowActions() { From c1d34525b4b93ca2e52987b291b9574b2a4c452b Mon Sep 17 00:00:00 2001 From: sahilchaudhary Date: Mon, 23 Oct 2023 14:16:04 +0530 Subject: [PATCH 08/18] Domain Pagination and Query changes --- .../DomainWhiteListWorkFlowServiceImpl.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/sunbird/workflow/service/impl/DomainWhiteListWorkFlowServiceImpl.java b/src/main/java/org/sunbird/workflow/service/impl/DomainWhiteListWorkFlowServiceImpl.java index 16f49456..4d1f236f 100644 --- a/src/main/java/org/sunbird/workflow/service/impl/DomainWhiteListWorkFlowServiceImpl.java +++ b/src/main/java/org/sunbird/workflow/service/impl/DomainWhiteListWorkFlowServiceImpl.java @@ -16,6 +16,7 @@ import org.sunbird.workflow.postgres.entity.WfStatusEntity; import org.sunbird.workflow.postgres.repo.WfStatusRepo; import org.sunbird.workflow.service.DomainWhiteListWorkFlowService; +import org.sunbird.workflow.service.UserProfileWfService; import org.sunbird.workflow.service.Workflowservice; import java.util.ArrayList; @@ -35,6 +36,9 @@ public class DomainWhiteListWorkFlowServiceImpl implements DomainWhiteListWorkFl @Autowired private WfStatusRepo wfStatusRepo; + @Autowired + private UserProfileWfService userProfileWfService; + @Override public Response createDomainWorkFlow(String rootOrg, String org, WfRequest wfRequest) { Response response = workflowService.workflowTransition(rootOrg, org, wfRequest); @@ -55,11 +59,11 @@ public Response readDomainWFApplication(String rootOrg, String org, String wfId, @Override public Response domainSearch(String rootOrg, String org, SearchCriteria criteria) { - Response response = applicationSearchOnApplicationIdGroup(criteria); + Response response = applicationSearchOnApplicationIdGroup(criteria, rootOrg); return response; } - public Response applicationSearchOnApplicationIdGroup(SearchCriteria criteria) { + public Response applicationSearchOnApplicationIdGroup(SearchCriteria criteria, String rootOrg) { Pageable pageable = getPageReqForApplicationSearch(criteria); List applicationIds = criteria.getApplicationIds(); Map> infos = null; @@ -76,7 +80,7 @@ public Response applicationSearchOnApplicationIdGroup(SearchCriteria criteria) { response.put(Constants.MESSAGE, Constants.SUCCESSFUL); response.put(Constants.DATA, infos); response.put(Constants.STATUS, HttpStatus.OK); - return response; + return getResponse(rootOrg, response); } private Pageable getPageReqForApplicationSearch(SearchCriteria criteria) { @@ -97,4 +101,15 @@ private Pageable getPageReqForApplicationSearch(SearchCriteria criteria) { pageable = PageRequest.of(offset, limit); return pageable; } + + private Response getResponse(String rootOrg, Response wfApplicationSearchResponse) { + Response response; + List> userProfiles = userProfileWfService.enrichUserData( + (Map>) wfApplicationSearchResponse.get(Constants.DATA), rootOrg); + response = new Response(); + response.put(Constants.MESSAGE, Constants.SUCCESSFUL); + response.put(Constants.DATA, userProfiles); + response.put(Constants.STATUS, HttpStatus.OK); + return response; + } } From f92bbc518b9484b653107fb8c83102e3e1f2643b Mon Sep 17 00:00:00 2001 From: sahilchaudhary Date: Mon, 23 Oct 2023 17:50:58 +0530 Subject: [PATCH 09/18] Updated the count variable Implementation --- .../sunbird/workflow/postgres/repo/WfStatusRepo.java | 2 +- .../impl/DomainWhiteListWorkFlowServiceImpl.java | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/sunbird/workflow/postgres/repo/WfStatusRepo.java b/src/main/java/org/sunbird/workflow/postgres/repo/WfStatusRepo.java index 597ec7cf..ddd61712 100644 --- a/src/main/java/org/sunbird/workflow/postgres/repo/WfStatusRepo.java +++ b/src/main/java/org/sunbird/workflow/postgres/repo/WfStatusRepo.java @@ -83,5 +83,5 @@ public interface WfStatusRepo extends JpaRepository { List findByStatusAndAppIds(List currentStatus, List applicationIds); @Query(value = "select application_id from wingspan.wf_status where service_name = ?1 and current_status = ?2 and dept_name = ?3 group by application_id", countQuery = "select count(application_id) from wingspan.wf_status where service_name = ?1 and current_status = ?2 group by application_id", nativeQuery = true) - List getListOfDistinctApplicationUsingDept(String serviceName, String currentStatus, String deptName, Pageable pageable); + Page getListOfDistinctApplicationUsingDept(String serviceName, String currentStatus, String deptName, Pageable pageable); } diff --git a/src/main/java/org/sunbird/workflow/service/impl/DomainWhiteListWorkFlowServiceImpl.java b/src/main/java/org/sunbird/workflow/service/impl/DomainWhiteListWorkFlowServiceImpl.java index aa5b64cf..1e310642 100644 --- a/src/main/java/org/sunbird/workflow/service/impl/DomainWhiteListWorkFlowServiceImpl.java +++ b/src/main/java/org/sunbird/workflow/service/impl/DomainWhiteListWorkFlowServiceImpl.java @@ -3,6 +3,7 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; @@ -72,20 +73,24 @@ public Response applicationSearchOnApplicationIdGroup(SearchCriteria criteria, S Pageable pageable = getPageReqForApplicationSearch(criteria); List applicationIds = criteria.getApplicationIds(); Map> infos = null; + long totalDomainRequestCount = 0; if (CollectionUtils.isEmpty(applicationIds)) { - applicationIds = wfStatusRepo.getListOfDistinctApplicationUsingDept(criteria.getServiceName(), + Page applicationIdsPage = wfStatusRepo.getListOfDistinctApplicationUsingDept(criteria.getServiceName(), criteria.getApplicationStatus(), criteria.getDeptName(), pageable); + applicationIds = applicationIdsPage.getContent(); + totalDomainRequestCount = applicationIdsPage.getTotalElements(); } List wfStatusEntities = null; wfStatusEntities = wfStatusRepo.findByServiceNameAndCurrentStatusAndDeptNameAndApplicationIdIn( criteria.getServiceName(), criteria.getApplicationStatus(), criteria.getDeptName(), applicationIds); - infos = wfStatusEntities.stream().collect(Collectors.groupingBy(WfStatusEntity::getApplicationId)); Response response = new Response(); response.put(Constants.MESSAGE, Constants.SUCCESSFUL); response.put(Constants.DATA, infos); response.put(Constants.STATUS, HttpStatus.OK); - return getResponse(rootOrg, response); + response = getResponse(rootOrg, response); + response.put(Constants.COUNT, totalDomainRequestCount); + return response; } private Pageable getPageReqForApplicationSearch(SearchCriteria criteria) { From 1aa52edc2a19a0619726f1d49e2f8aa28dbea142 Mon Sep 17 00:00:00 2001 From: Sahil-tarento <140611066+Sahil-tarento@users.noreply.github.com> Date: Wed, 25 Oct 2023 17:23:25 +0530 Subject: [PATCH 10/18] BE : Analysis and Implementation Email Domain approval from SPV Portal (#119) * BE : Analysis and Implementation Email Domain approval from SPV Portal * Error Msg changes * Error Msg changes * Made the code review changes --- .../sunbird/workflow/config/Constants.java | 1 + .../controller/DomainWorkFlowController.java | 3 +- .../postgres/entity/WfDomainLookup.java | 43 +++++++++++++++++++ .../postgres/repo/WfDomainLookupRepo.java | 10 +++++ .../DomainWhiteListWorkFlowServiceImpl.java | 37 +++++++++++++--- 5 files changed, 88 insertions(+), 6 deletions(-) create mode 100644 src/main/java/org/sunbird/workflow/postgres/entity/WfDomainLookup.java create mode 100644 src/main/java/org/sunbird/workflow/postgres/repo/WfDomainLookupRepo.java diff --git a/src/main/java/org/sunbird/workflow/config/Constants.java b/src/main/java/org/sunbird/workflow/config/Constants.java index 05ad47a4..9e18c80a 100644 --- a/src/main/java/org/sunbird/workflow/config/Constants.java +++ b/src/main/java/org/sunbird/workflow/config/Constants.java @@ -243,4 +243,5 @@ private Constants() { public static final String CONTEXT_TYPE = "contextType"; public static final String CONTEXT_NAME = "contextName"; public static final String USER_REGISTRATION_PRE_APPROVED_DOMAIN = "userRegistrationPreApprovedDomain"; + public static final String DOMAIN_NAME_REQUEST_EXIST_MSG = "Already a request is raised for domain"; } \ No newline at end of file diff --git a/src/main/java/org/sunbird/workflow/controller/DomainWorkFlowController.java b/src/main/java/org/sunbird/workflow/controller/DomainWorkFlowController.java index c5b01588..f0c86613 100644 --- a/src/main/java/org/sunbird/workflow/controller/DomainWorkFlowController.java +++ b/src/main/java/org/sunbird/workflow/controller/DomainWorkFlowController.java @@ -5,6 +5,7 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import org.sunbird.workflow.config.Constants; import org.sunbird.workflow.models.Response; import org.sunbird.workflow.models.SearchCriteria; import org.sunbird.workflow.models.WfRequest; @@ -21,7 +22,7 @@ public class DomainWorkFlowController { public ResponseEntity domainWfCreate(@RequestHeader String rootOrg, @RequestHeader String org, @RequestBody WfRequest wfRequest) { Response response = domainWhiteListWorkFlowService.createDomainWorkFlow(rootOrg, org, wfRequest); - return new ResponseEntity<>(response, HttpStatus.OK); + return new ResponseEntity<>(response, (HttpStatus) response.get(Constants.STATUS)); } @PostMapping("/update") diff --git a/src/main/java/org/sunbird/workflow/postgres/entity/WfDomainLookup.java b/src/main/java/org/sunbird/workflow/postgres/entity/WfDomainLookup.java new file mode 100644 index 00000000..2841a865 --- /dev/null +++ b/src/main/java/org/sunbird/workflow/postgres/entity/WfDomainLookup.java @@ -0,0 +1,43 @@ +package org.sunbird.workflow.postgres.entity; + +import javax.persistence.*; + +@Entity +@Table(name = "wf_domain_lookup", schema = "wingspan") +public class WfDomainLookup extends Object{ + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "wf_domain_id", nullable = false) + private int id; + + @Column(name = "wf_id") + private String wfId; + + @Column(name = "domain_name") + private String domainName; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getWfId() { + return wfId; + } + + public void setWfId(String wfId) { + this.wfId = wfId; + } + + public String getDomainName() { + return domainName; + } + + public void setDomainName(String domainName) { + this.domainName = domainName; + } +} diff --git a/src/main/java/org/sunbird/workflow/postgres/repo/WfDomainLookupRepo.java b/src/main/java/org/sunbird/workflow/postgres/repo/WfDomainLookupRepo.java new file mode 100644 index 00000000..2a1b7fc3 --- /dev/null +++ b/src/main/java/org/sunbird/workflow/postgres/repo/WfDomainLookupRepo.java @@ -0,0 +1,10 @@ +package org.sunbird.workflow.postgres.repo; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.sunbird.workflow.postgres.entity.WfDomainLookup; + +import java.util.List; + +public interface WfDomainLookupRepo extends JpaRepository { + List findByDomainName(String domainValue); +} diff --git a/src/main/java/org/sunbird/workflow/service/impl/DomainWhiteListWorkFlowServiceImpl.java b/src/main/java/org/sunbird/workflow/service/impl/DomainWhiteListWorkFlowServiceImpl.java index 1e310642..302547a9 100644 --- a/src/main/java/org/sunbird/workflow/service/impl/DomainWhiteListWorkFlowServiceImpl.java +++ b/src/main/java/org/sunbird/workflow/service/impl/DomainWhiteListWorkFlowServiceImpl.java @@ -14,17 +14,16 @@ import org.sunbird.workflow.models.Response; import org.sunbird.workflow.models.SearchCriteria; import org.sunbird.workflow.models.WfRequest; +import org.sunbird.workflow.postgres.entity.WfDomainLookup; import org.sunbird.workflow.postgres.entity.WfStatusEntity; +import org.sunbird.workflow.postgres.repo.WfDomainLookupRepo; import org.sunbird.workflow.postgres.repo.WfStatusRepo; import org.sunbird.workflow.service.DomainWhiteListWorkFlowService; import org.sunbird.workflow.service.UserProfileWfService; import org.sunbird.workflow.service.Workflowservice; import org.sunbird.workflow.utils.CassandraOperation; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; @Service @@ -45,9 +44,37 @@ public class DomainWhiteListWorkFlowServiceImpl implements DomainWhiteListWorkFl @Autowired CassandraOperation cassandraOperation; + @Autowired + private WfDomainLookupRepo wfDomainLookupRepo; + @Override public Response createDomainWorkFlow(String rootOrg, String org, WfRequest wfRequest) { - Response response = workflowService.workflowTransition(rootOrg, org, wfRequest); + Response response = new Response(); + try { + HashMap updatedFieldValue = wfRequest.getUpdateFieldValues().stream().findFirst().get(); + HashMap toValue = (HashMap) updatedFieldValue.get("toValue"); + String domainValue = toValue.get("domain").isEmpty() ? "" : toValue.get("domain"); + List domainLookup = wfDomainLookupRepo.findByDomainName(domainValue); + if (CollectionUtils.isNotEmpty(domainLookup)) { + response.put(Constants.MESSAGE, Constants.DOMAIN_NAME_REQUEST_EXIST_MSG + ": " + domainValue); + response.put(Constants.STATUS, HttpStatus.ACCEPTED); + return response; + } + response = workflowService.workflowTransition(rootOrg, org, wfRequest); + if (HttpStatus.OK.compareTo((HttpStatus) response.getResult().get(Constants.STATUS)) == 0) { + WfDomainLookup wfDomainLookup = new WfDomainLookup(); + Map dataObject = (Map) response.getResult().getOrDefault(Constants.DATA, new HashMap()); + List wfIdList = (List) dataObject.getOrDefault(Constants.WF_IDS_CONSTANT, new ArrayList()); + wfDomainLookup.setWfId(wfIdList.get(0)); + wfDomainLookup.setDomainName(domainValue); + wfDomainLookupRepo.save(wfDomainLookup); + } + } catch (Exception e) { + String errMsg = String.format("Failed to get the stats for course. Exception: ", e.getMessage()); + response.put(Constants.ERROR_MESSAGE, errMsg); + response.put(Constants.STATUS, HttpStatus.INTERNAL_SERVER_ERROR); + response.setResponseCode(HttpStatus.INTERNAL_SERVER_ERROR); + } return response; } From 31adf270f3b5b77dda50e53ab5a93446cf26a7c0 Mon Sep 17 00:00:00 2001 From: tarentomaheshvakkund <139739142+tarentomaheshvakkund@users.noreply.github.com> Date: Wed, 25 Oct 2023 18:59:15 +0530 Subject: [PATCH 11/18] KBE 595 -BE - CB-Ext changes w.r.t. extPatch API 1. Removed the validateJsonAgainstSchema. 2. Handled the updatedProfileElementObj is the instance of boolean type and null object type. --- .../impl/UserProfileWfServiceImpl.java | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/sunbird/workflow/service/impl/UserProfileWfServiceImpl.java b/src/main/java/org/sunbird/workflow/service/impl/UserProfileWfServiceImpl.java index 3949048c..90fb0908 100644 --- a/src/main/java/org/sunbird/workflow/service/impl/UserProfileWfServiceImpl.java +++ b/src/main/java/org/sunbird/workflow/service/impl/UserProfileWfServiceImpl.java @@ -106,11 +106,6 @@ private void updateProfile(WfRequest wfRequest) { failedCase(wfRequest); return; } - if (validateJsonAgainstSchema(updateRequest)) { - updateRequest.put(Constants.VERIFIED_KARMAYOGI, true); - } else { - updateRequest.put(Constants.VERIFIED_KARMAYOGI, false); - } Map updateUserApiResp = requestServiceImpl .fetchResultUsingPatch(configuration.getLmsServiceHost() + configuration.getUserProfileUpdateEndPoint(), getUpdateRequest(wfRequest, updateRequest), getHeaders()); if (null != updateUserApiResp && !Constants.OK.equals(updateUserApiResp.get(Constants.RESPONSE_CODE))) { @@ -139,16 +134,23 @@ public Map updateRequestWithWF(String uuid, List existingProfileElementList = mapper.convertValue(updatedProfileElementObj, Map.class); updatedProfileElement.putAll(existingProfileElementList); + } else if (updatedProfileElementObj instanceof Boolean) { + Map toValueMap = (Map) wfRequestParamObj.get(Constants.TO_VALUE); + existingProfileDetail.put((String) wfRequestParamObj.get(Constants.FIELD_KEY), (Boolean) toValueMap.get(Constants.VERIFIED_KARMAYOGI)); } else if (null == updatedProfileElementObj) { - List> detailsList = new ArrayList<>(); - Map detailsMap = new HashMap<>(); - detailsMap = (Map) wfRequestParamObj.get("toValue"); - detailsList.add(detailsMap); - existingProfileDetail.put((String) wfRequestParamObj.get("fieldKey"), detailsList); - } - else { - logger.error("profile element to be updated is neither arraylist nor hashmap"); - return null; + if (Constants.VERIFIED_KARMAYOGI.equalsIgnoreCase((String) wfRequestParamObj.get(Constants.FIELD_KEY))) { + Map toValueMap = (Map) wfRequestParamObj.get(Constants.TO_VALUE); + existingProfileDetail.put((String) wfRequestParamObj.get(Constants.FIELD_KEY), (Boolean) toValueMap.get(Constants.VERIFIED_KARMAYOGI)); + } else if (Constants.PROFILE_DETAILS.equalsIgnoreCase((String) wfRequestParamObj.get(Constants.FIELD_KEY))) { + List> detailsList = new ArrayList<>(); + Map detailsMap = new HashMap<>(); + detailsMap = (Map) wfRequestParamObj.get(Constants.TO_VALUE); + detailsList.add(detailsMap); + existingProfileDetail.put((String) wfRequestParamObj.get(Constants.FIELD_KEY), detailsList); + } else { + logger.error("profile element to be updated is neither arraylist nor hashmap"); + return null; + } } Map objectMap = (Map) wfRequestParamObj.get(Constants.TO_VALUE); for (Map.Entry entry : objectMap.entrySet()) From f3b5040e65bce6367d50213e869e04c5036fe97e Mon Sep 17 00:00:00 2001 From: tarentomaheshvakkund <139739142+tarentomaheshvakkund@users.noreply.github.com> Date: Thu, 26 Oct 2023 10:15:48 +0530 Subject: [PATCH 12/18] Retained the previous code in comment mode Retained the previous code in comment mode --- .../workflow/service/impl/UserProfileWfServiceImpl.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/org/sunbird/workflow/service/impl/UserProfileWfServiceImpl.java b/src/main/java/org/sunbird/workflow/service/impl/UserProfileWfServiceImpl.java index 90fb0908..57efcebc 100644 --- a/src/main/java/org/sunbird/workflow/service/impl/UserProfileWfServiceImpl.java +++ b/src/main/java/org/sunbird/workflow/service/impl/UserProfileWfServiceImpl.java @@ -106,6 +106,12 @@ private void updateProfile(WfRequest wfRequest) { failedCase(wfRequest); return; } + //This field is updated via approval + /*if (validateJsonAgainstSchema(updateRequest)) { + updateRequest.put(Constants.VERIFIED_KARMAYOGI, true); + } else { + updateRequest.put(Constants.VERIFIED_KARMAYOGI, false); + }*/ Map updateUserApiResp = requestServiceImpl .fetchResultUsingPatch(configuration.getLmsServiceHost() + configuration.getUserProfileUpdateEndPoint(), getUpdateRequest(wfRequest, updateRequest), getHeaders()); if (null != updateUserApiResp && !Constants.OK.equals(updateUserApiResp.get(Constants.RESPONSE_CODE))) { From d0e999b9901df9d60400cc40d170723e78183ccc Mon Sep 17 00:00:00 2001 From: Sahil-tarento <140611066+Sahil-tarento@users.noreply.github.com> Date: Thu, 26 Oct 2023 18:07:45 +0530 Subject: [PATCH 13/18] Made the changes for adding the entity for Wf_domain_user_info (#121) * Made the changes for adding the entity for Wf_domain_user_info * Code Review changes --- .../postgres/entity/WfDomainUserInfo.java | 76 +++++++++++++++++++ .../postgres/entity/WfStatusEntity.java | 11 +++ .../postgres/repo/WfDomainUserInfoRepo.java | 13 ++++ .../DomainWhiteListWorkFlowServiceImpl.java | 68 ++++++++++++++--- 4 files changed, 156 insertions(+), 12 deletions(-) create mode 100644 src/main/java/org/sunbird/workflow/postgres/entity/WfDomainUserInfo.java create mode 100644 src/main/java/org/sunbird/workflow/postgres/repo/WfDomainUserInfoRepo.java diff --git a/src/main/java/org/sunbird/workflow/postgres/entity/WfDomainUserInfo.java b/src/main/java/org/sunbird/workflow/postgres/entity/WfDomainUserInfo.java new file mode 100644 index 00000000..f7061afa --- /dev/null +++ b/src/main/java/org/sunbird/workflow/postgres/entity/WfDomainUserInfo.java @@ -0,0 +1,76 @@ +package org.sunbird.workflow.postgres.entity; + +import javax.persistence.*; + +@Entity +@Table(name = "wf_domain_user_info", schema = "wingspan") +public class WfDomainUserInfo extends Object { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "wf_domain_user_info_id", nullable = false) + private int id; + + @Column(name = "domain_name") + private String domainName; + + @Column(name = "first_name") + private String firstName; + + @Column(name = "email") + private String email; + + @Column(name = "mobile") + private String mobile; + + @Column(name = "description") + private String description; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getDomainName() { + return domainName; + } + + public void setDomainName(String domainName) { + this.domainName = domainName; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getMobile() { + return mobile; + } + + public void setMobile(String mobile) { + this.mobile = mobile; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } +} diff --git a/src/main/java/org/sunbird/workflow/postgres/entity/WfStatusEntity.java b/src/main/java/org/sunbird/workflow/postgres/entity/WfStatusEntity.java index 0d679252..14377b12 100644 --- a/src/main/java/org/sunbird/workflow/postgres/entity/WfStatusEntity.java +++ b/src/main/java/org/sunbird/workflow/postgres/entity/WfStatusEntity.java @@ -55,6 +55,9 @@ public class WfStatusEntity { @Column(name = "modification_history") private String modificationHistory; + @Column(name = "additional_properties") + private String additionalProperties; + public String getModificationHistory() { return modificationHistory; } @@ -174,4 +177,12 @@ public String getDeptName() { public void setDeptName(String deptName) { this.deptName = deptName; } + + public String getAdditionalProperties() { + return additionalProperties; + } + + public void setAdditionalProperties(String additionalProperties) { + this.additionalProperties = additionalProperties; + } } diff --git a/src/main/java/org/sunbird/workflow/postgres/repo/WfDomainUserInfoRepo.java b/src/main/java/org/sunbird/workflow/postgres/repo/WfDomainUserInfoRepo.java new file mode 100644 index 00000000..5007616c --- /dev/null +++ b/src/main/java/org/sunbird/workflow/postgres/repo/WfDomainUserInfoRepo.java @@ -0,0 +1,13 @@ +package org.sunbird.workflow.postgres.repo; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.sunbird.workflow.postgres.entity.WfDomainLookup; +import org.sunbird.workflow.postgres.entity.WfDomainUserInfo; + +import java.util.List; + +public interface WfDomainUserInfoRepo extends JpaRepository { + Long countByDomainName(String domainValue); + + List findByDomainNameAndEmailAndMobile(String domainValue, String email, String mobile); +} diff --git a/src/main/java/org/sunbird/workflow/service/impl/DomainWhiteListWorkFlowServiceImpl.java b/src/main/java/org/sunbird/workflow/service/impl/DomainWhiteListWorkFlowServiceImpl.java index 302547a9..fd51d9be 100644 --- a/src/main/java/org/sunbird/workflow/service/impl/DomainWhiteListWorkFlowServiceImpl.java +++ b/src/main/java/org/sunbird/workflow/service/impl/DomainWhiteListWorkFlowServiceImpl.java @@ -1,5 +1,7 @@ package org.sunbird.workflow.service.impl; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -15,8 +17,10 @@ import org.sunbird.workflow.models.SearchCriteria; import org.sunbird.workflow.models.WfRequest; import org.sunbird.workflow.postgres.entity.WfDomainLookup; +import org.sunbird.workflow.postgres.entity.WfDomainUserInfo; import org.sunbird.workflow.postgres.entity.WfStatusEntity; import org.sunbird.workflow.postgres.repo.WfDomainLookupRepo; +import org.sunbird.workflow.postgres.repo.WfDomainUserInfoRepo; import org.sunbird.workflow.postgres.repo.WfStatusRepo; import org.sunbird.workflow.service.DomainWhiteListWorkFlowService; import org.sunbird.workflow.service.UserProfileWfService; @@ -47,6 +51,12 @@ public class DomainWhiteListWorkFlowServiceImpl implements DomainWhiteListWorkFl @Autowired private WfDomainLookupRepo wfDomainLookupRepo; + @Autowired + private WfDomainUserInfoRepo wfDomainUserInfoRepo; + + @Autowired + private ObjectMapper mapper; + @Override public Response createDomainWorkFlow(String rootOrg, String org, WfRequest wfRequest) { Response response = new Response(); @@ -54,20 +64,36 @@ public Response createDomainWorkFlow(String rootOrg, String org, WfRequest wfReq HashMap updatedFieldValue = wfRequest.getUpdateFieldValues().stream().findFirst().get(); HashMap toValue = (HashMap) updatedFieldValue.get("toValue"); String domainValue = toValue.get("domain").isEmpty() ? "" : toValue.get("domain"); - List domainLookup = wfDomainLookupRepo.findByDomainName(domainValue); - if (CollectionUtils.isNotEmpty(domainLookup)) { + String firstName = (String) updatedFieldValue.get("firstName"); + String email = (String) updatedFieldValue.get(Constants.EMAIL); + String phone = (String) updatedFieldValue.get("mobile"); + String description = (String) updatedFieldValue.get("description"); + List userInfo = wfDomainUserInfoRepo.findByDomainNameAndEmailAndMobile(domainValue, email, phone); + if (CollectionUtils.isEmpty(userInfo)) { + List domainLookup = wfDomainLookupRepo.findByDomainName(domainValue); + addWfDomainUserInfo(email, domainValue, phone, description, firstName); + Long userDomainInfoCount = wfDomainUserInfoRepo.countByDomainName(domainValue); + if (CollectionUtils.isNotEmpty(domainLookup)) { + WfStatusEntity wfStatusEntity = wfStatusRepo.findByWfId(domainLookup.get(0).getWfId()); + updateWfStatusEntity(wfStatusEntity, userDomainInfoCount.intValue()); + response.put(Constants.MESSAGE, Constants.DOMAIN_NAME_REQUEST_EXIST_MSG + ": " + domainValue); + response.put(Constants.STATUS, HttpStatus.ACCEPTED); + return response; + } + response = workflowService.workflowTransition(rootOrg, org, wfRequest); + if (HttpStatus.OK.compareTo((HttpStatus) response.getResult().get(Constants.STATUS)) == 0) { + WfDomainLookup wfDomainLookup = new WfDomainLookup(); + Map dataObject = (Map) response.getResult().getOrDefault(Constants.DATA, new HashMap()); + List wfIdList = (List) dataObject.getOrDefault(Constants.WF_IDS_CONSTANT, new ArrayList()); + wfDomainLookup.setWfId(wfIdList.get(0)); + wfDomainLookup.setDomainName(domainValue); + wfDomainLookupRepo.save(wfDomainLookup); + WfStatusEntity wfStatusEntity = wfStatusRepo.findByWfId(wfIdList.get(0)); + updateWfStatusEntity(wfStatusEntity, 1); + } + } else { response.put(Constants.MESSAGE, Constants.DOMAIN_NAME_REQUEST_EXIST_MSG + ": " + domainValue); response.put(Constants.STATUS, HttpStatus.ACCEPTED); - return response; - } - response = workflowService.workflowTransition(rootOrg, org, wfRequest); - if (HttpStatus.OK.compareTo((HttpStatus) response.getResult().get(Constants.STATUS)) == 0) { - WfDomainLookup wfDomainLookup = new WfDomainLookup(); - Map dataObject = (Map) response.getResult().getOrDefault(Constants.DATA, new HashMap()); - List wfIdList = (List) dataObject.getOrDefault(Constants.WF_IDS_CONSTANT, new ArrayList()); - wfDomainLookup.setWfId(wfIdList.get(0)); - wfDomainLookup.setDomainName(domainValue); - wfDomainLookupRepo.save(wfDomainLookup); } } catch (Exception e) { String errMsg = String.format("Failed to get the stats for course. Exception: ", e.getMessage()); @@ -178,4 +204,22 @@ private Boolean isAlreadyApprovedDomains(String emailDomain) { Constants.KEYSPACE_SUNBIRD, Constants.TABLE_MASTER_DATA, propertyMap, Arrays.asList(Constants.CONTEXT_TYPE, Constants.CONTEXT_NAME)); return CollectionUtils.isNotEmpty(listOfDomains); } + + private void addWfDomainUserInfo(String email, String domain, String mobile, String description, String firstName) { + WfDomainUserInfo wfDomainUserInfo = new WfDomainUserInfo(); + wfDomainUserInfo.setDomainName(domain); + wfDomainUserInfo.setDescription(description); + wfDomainUserInfo.setEmail(email); + wfDomainUserInfo.setFirstName(firstName); + wfDomainUserInfo.setMobile(mobile); + wfDomainUserInfoRepo.save(wfDomainUserInfo); + } + + private void updateWfStatusEntity(WfStatusEntity wfStatusEntity, int updatedCountValueForDomainRequest) throws JsonProcessingException { + Map additionalFieldInfo = new HashMap<>(); + additionalFieldInfo.put("noOfRequest", updatedCountValueForDomainRequest); + wfStatusEntity.setAdditionalProperties(mapper.writeValueAsString(additionalFieldInfo)); + wfStatusEntity.setLastUpdatedOn(new Date()); + wfStatusRepo.save(wfStatusEntity); + } } From 9df2af8f9d520919acc7694ebcb9c9fdfaf497cb Mon Sep 17 00:00:00 2001 From: Ravi Saurav Date: Thu, 26 Oct 2023 23:19:54 +0530 Subject: [PATCH 14/18] 107261:changes related to notification to PC and MDO --- .../workflow/config/Configuration.java | 44 ++++ .../sunbird/workflow/config/Constants.java | 5 + .../service/impl/BPWorkFlowServiceImpl.java | 38 ++- .../service/impl/NotificationServiceImpl.java | 218 ++++++++++++------ src/main/resources/application.properties | 9 +- 5 files changed, 233 insertions(+), 81 deletions(-) diff --git a/src/main/java/org/sunbird/workflow/config/Configuration.java b/src/main/java/org/sunbird/workflow/config/Configuration.java index d62fce87..e987bbb5 100644 --- a/src/main/java/org/sunbird/workflow/config/Configuration.java +++ b/src/main/java/org/sunbird/workflow/config/Configuration.java @@ -173,6 +173,18 @@ public class Configuration { @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; } @@ -629,4 +641,36 @@ public String getApprovedMailBody() { 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; + } } diff --git a/src/main/java/org/sunbird/workflow/config/Constants.java b/src/main/java/org/sunbird/workflow/config/Constants.java index 4d9e17e2..14b557db 100644 --- a/src/main/java/org/sunbird/workflow/config/Constants.java +++ b/src/main/java/org/sunbird/workflow/config/Constants.java @@ -243,4 +243,9 @@ private Constants() { 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"; } diff --git a/src/main/java/org/sunbird/workflow/service/impl/BPWorkFlowServiceImpl.java b/src/main/java/org/sunbird/workflow/service/impl/BPWorkFlowServiceImpl.java index b0d54296..88bbbfa5 100644 --- a/src/main/java/org/sunbird/workflow/service/impl/BPWorkFlowServiceImpl.java +++ b/src/main/java/org/sunbird/workflow/service/impl/BPWorkFlowServiceImpl.java @@ -11,12 +11,15 @@ import java.util.Map; import java.util.stream.Collectors; +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; import org.apache.commons.collections.CollectionUtils; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.commons.collections.MapUtils; +import org.apache.commons.collections.map.HashedMap; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -98,6 +101,10 @@ public Response enrolBPWorkFlow(String rootOrg, String org, WfRequest wfRequest) response.put(Constants.STATUS, HttpStatus.BAD_REQUEST); return response; } + Map courseAttributes = getCourseAttributes(wfRequest.getCourseId()); + wfRequest.setCourseName((String) courseAttributes.get(Constants.COURSE_NAME)); + wfRequest.setBatchName((String) courseBatchDetails.get(Constants.BATCH_NAME)); + wfRequest.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); @@ -109,9 +116,10 @@ public Response updateBPWorkFlow(String rootOrg, String org, WfRequest wfRequest Response response = new Response(); Map batchDetailsMap = new HashMap<>(); String validationError = validateBatchUserRequestAccess(wfRequest, batchDetailsMap); - wfRequest.setCourseName((String) batchDetailsMap.get(Constants.COURSE_NAME)); wfRequest.setBatchName((String) batchDetailsMap.get(Constants.BATCH_NAME)); wfRequest.setBatchStartDate((Date) batchDetailsMap.get(Constants.BATCH_START_DATE)); + Map courseAttributes = getCourseAttributes(wfRequest.getCourseId()); + wfRequest.setCourseName((String) courseAttributes.get(Constants.COURSE_NAME)); if (Constants.BATCH_START_DATE_ERROR.equals(validationError)) { response.put(Constants.ERROR_MESSAGE, configuration.getBatchInProgressMessage()); response.put(Constants.STATUS, HttpStatus.BAD_REQUEST); @@ -225,19 +233,14 @@ private Map getCurrentBatchAttributes(String batchId, String cou Date batchStartDate = courseBatch.containsKey(Constants.START_DATE) ? (Date) courseBatch.get(Constants.START_DATE) : null; - String courseName = batchAttributes != null + String batchName = batchAttributes != null && courseBatch.containsKey(Constants.NAME) ? (String) courseBatch.get(Constants.NAME) : ""; - String batchName = batchAttributes != null - && courseBatch.containsKey(Constants.DESCRIPTION) - ? (String) courseBatch.get(Constants.DESCRIPTION) - : ""; Map 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.COURSE_NAME, courseName); result.put(Constants.BATCH_NAME, batchName); return result; } catch (Exception e) { @@ -514,6 +517,10 @@ 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 { + Map courseAttributes = getCourseAttributes(wfRequest.getCourseId()); + wfRequest.setCourseName((String) courseAttributes.get(Constants.COURSE_NAME)); + wfRequest.setBatchName((String) courseBatchDetails.get(Constants.NAME)); + wfRequest.setBatchStartDate((Date) courseBatchDetails.get(Constants.BATCH_START_DATE)); response = saveAdminEnrollUserIntoWfStatus(rootOrg, org, wfRequest); // producer.push(configuration.getWorkFlowNotificationTopic(), wfRequest); wfRequest.setAction(Constants.INITIATE); @@ -584,6 +591,10 @@ 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()); + Map getCourseAttributes = getCourseAttributes(wfRequest.getCourseId()); + wfRequest.setBatchName((String) courseBatchDetails.get(Constants.BATCH_NAME)); + wfRequest.setBatchStartDate((Date) courseBatchDetails.get(Constants.BATCH_START_DATE)); + wfRequest.setCourseName((String) getCourseAttributes.get(Constants.COURSE_NAME)); response = workflowService.workflowTransition(rootOrg, org, wfRequest,userId,role); response.put(Constants.STATUS, HttpStatus.OK); @@ -1013,7 +1024,18 @@ private void handleApprovalRequest(WfRequest wfRequest) { } catch (IOException e) { throw new ApplicationException(Constants.WORKFLOW_PARSING_ERROR_MESSAGE, e); } + } - + public Map getCourseAttributes(String courseId){ + Map propertiesMap = new HashMap<>(); + Map courseDetails = new HashMap<>(); + propertiesMap.put(Constants.IDENTIFIER, courseId); + List> coursesDataList = cassandraOperation.getRecordsByProperties(Constants.DEV_HIERARCHY_STORE, + Constants.CONTENT_HIERARCHY, + propertiesMap, + Arrays.asList(Constants.IDENTIFIER, Constants.HIERARCHY)); + Map hierarchy = new Gson().fromJson((String) coursesDataList.get(0).get("hierarchy"), new TypeToken>(){}.getType()); + courseDetails.put(Constants.COURSE_NAME, (String) hierarchy.get(Constants.NAME)); + return courseDetails; } } diff --git a/src/main/java/org/sunbird/workflow/service/impl/NotificationServiceImpl.java b/src/main/java/org/sunbird/workflow/service/impl/NotificationServiceImpl.java index 4fac023b..8f0bc655 100644 --- a/src/main/java/org/sunbird/workflow/service/impl/NotificationServiceImpl.java +++ b/src/main/java/org/sunbird/workflow/service/impl/NotificationServiceImpl.java @@ -94,6 +94,12 @@ public class NotificationServiceImpl { private static final String BP_MDO_PC_SUBJECT_LINE = "Enrollment Request Forwarded to #role"; + private static final String USERNAMAE_TAG = "#username"; + + private static final String BLENDED_PROGRAME_NAME_TAG = "#blended_programme_name"; + + private static final String ROLE_TAG = "#role"; + /** * Send notification to the user based on state of application * @@ -131,81 +137,62 @@ public void sendNotification(WfRequest wfRequest) { recipientInfo = (Map)usersObj.get(wfStatusEntity.getApplicationId()); } Map senderInfo = (Map)usersObj.get(wfRequest.getUserId()); - Map params = new HashMap<>(); - NotificationRequest request = new NotificationRequest(); - request.setDeliveryType("message"); - request.setIds(Arrays.asList((String)recipientInfo.get("email"))); - request.setMode("email"); - Template template = new Template(); - template.setId(EMAILTEMPLATE); Optional> updatedFieldValue = wfRequest.getUpdateFieldValues().stream().findFirst(); String subjectLine = ""; + String body = ""; if (updatedFieldValue.isPresent()) { if (blendedProgrammeServiceNames.contains(wfRequest.getServiceName())) { + String forwardedMailBody = configuration.getLearnerForwardedMailBody() + .replace(COURSE_NAME_TAG, wfRequest.getCourseName()) + .replace(BATCH_NAME_TAG, wfRequest.getBatchName()) + .replace(BATCH_START_DATE_TAG, wfRequest.getBatchStartDate().toString()); switch (wfStatusEntity.getCurrentStatus()){ case Constants.SEND_FOR_PC_APPROVAL: subjectLine = BP_MDO_PC_SUBJECT_LINE.replace(Role_TAG,Constants.PROGRAM_COORDINATOR.replace("_"," ")); - params.put("body",configuration.getLearnerForwardedMailBody() - .replace(COURSE_NAME_TAG, wfRequest.getCourseName()) - .replace(BATCH_NAME_TAG, wfRequest.getBatchName()) - .replace(BATCH_START_DATE_TAG, wfRequest.getBatchStartDate().toString()) - .replace(Role_TAG,Constants.PROGRAM_COORDINATOR.replace("_"," "))); + body = forwardedMailBody.replace(Role_TAG,Constants.PROGRAM_COORDINATOR.replace("_"," ")); break; case Constants.SEND_FOR_MDO_APPROVAL: subjectLine = BP_MDO_PC_SUBJECT_LINE.replace(Role_TAG,Constants.MDO_ADMIN.split("_")[0]); - params.put("body",configuration.getApprovedMailBody() - .replace(COURSE_NAME_TAG, wfRequest.getCourseName()) - .replace(BATCH_NAME_TAG, wfRequest.getBatchName()) - .replace(BATCH_START_DATE_TAG, wfRequest.getBatchStartDate().toString()) - .replace(Role_TAG,Constants.MDO_ADMIN.split("_")[0])); + body = forwardedMailBody.replace(Role_TAG,Constants.MDO_ADMIN.split("_")[0]); break; case Constants.APPROVED: subjectLine = ENROLMENT_ACTION_SUBJECT.replace(ACT_TAG, wfStatusEntity.getCurrentStatus()); - params.put("body", configuration.getApprovedMailBody() + body = configuration.getApprovedMailBody() .replace(BATCH_NAME_TAG, wfRequest.getBatchName()) .replace(COURSE_NAME_TAG, wfRequest.getCourseName()) - .replace(BATCH_START_DATE_TAG, wfRequest.getBatchStartDate().toString())); + .replace(BATCH_START_DATE_TAG, wfRequest.getBatchStartDate().toString()); break; case Constants.REJECTED: case Constants.REMOVED: subjectLine = ENROLMENT_ACTION_SUBJECT.replace(ACT_TAG, wfStatusEntity.getCurrentStatus()); - params.put("body",configuration.getRejectedOrRemovedMailBody() + body = configuration.getRejectedOrRemovedMailBody() .replace(BATCH_NAME_TAG, wfRequest.getBatchName()) .replace(COURSE_NAME_TAG, wfRequest.getCourseName()) .replace(ACT_TAG,wfStatusEntity.getCurrentStatus()) - .replace(BATCH_START_DATE_TAG, wfRequest.getBatchStartDate().toString())); + .replace(BATCH_START_DATE_TAG, wfRequest.getBatchStartDate().toString()); break; default: subjectLine = MAIL_SUBJECT.replace(STATE_NAME_TAG, wfStatusEntity.getCurrentStatus()); - params.put("body", BP_MAIL_BODY.replace(STATE_NAME_TAG, wfStatusEntity.getCurrentStatus())); + body = BP_MAIL_BODY.replace(STATE_NAME_TAG, wfStatusEntity.getCurrentStatus()); break; } } else { HashMap toValue = (HashMap) updatedFieldValue.get().get(TO_VALUE_CONST); - params.put("body", MAIL_BODY.replace(STATE_NAME_TAG, wfStatusEntity.getCurrentStatus()) - .replace(FIELD_KEY_TAG, toValue.entrySet().iterator().next().getKey()).replace(TO_VALUE_TAG, (String) toValue.entrySet().iterator().next().getValue())); + body = MAIL_BODY.replace(STATE_NAME_TAG, wfStatusEntity.getCurrentStatus()) + .replace(FIELD_KEY_TAG, toValue.entrySet().iterator().next().getKey()).replace(TO_VALUE_TAG, (String) toValue.entrySet().iterator().next().getValue()); subjectLine = MAIL_SUBJECT.replace(STATE_NAME_TAG, wfStatusEntity.getCurrentStatus()); } } if (StringUtils.isNotBlank(wfRequest.getComment())) { - String body = (String) params.get("body"); - body = body.substring(0, body.length() - 1); - body = body + ", due to " + wfRequest.getComment() + "."; - params.put("body", body); + body = body + ", due to " + wfRequest.getComment() + "."; } - params.put("orgImageUrl", null); - template.setParams(params); - Config config = new Config(); - config.setSubject(subjectLine); - config.setSender((String)senderInfo.get("email")); - Map req = new HashMap<>(); - request.setTemplate(template); - request.setConfig(config); - Map> notificationMap = new HashMap<>(); - notificationMap.put("notifications", Arrays.asList(request)); - req.put("request", notificationMap); - sendNotification(req); + Map mailNotificationDetails = new HashMap<>(); + mailNotificationDetails.put("emailTo", senderInfo.get(Constants.FIRST_NAME)); + mailNotificationDetails.put("body", body); + mailNotificationDetails.put("subject", subjectLine); + mailNotificationDetails.put("emailList", Collections.singletonList(senderInfo.get(Constants.EMAIL))); + sendNotificationEmail(mailNotificationDetails); } } @@ -328,39 +315,128 @@ public void sendNotificationToMdoAdminAndPC(WfRequest wfRequest) { && !Arrays.asList(Constants.REJECTED, Constants.APPROVED).contains(wfStatus.getState())) { logger.info("Enter in the sendNotificationToMdoAdminAndPC block"); List emailToSend = new ArrayList<>(); - emailToSend.add(Constants.SEND_FOR_MDO_APPROVAL.equalsIgnoreCase(wfStatusEntity.getCurrentStatus()) ? Constants.MDO_ADMIN : - Constants.SEND_FOR_PC_APPROVAL.equalsIgnoreCase(wfStatusEntity.getCurrentStatus()) ? Constants.PROGRAM_COORDINATOR : null); - logger.info("current role to send notification "+emailToSend); - List mdoAdminList = userProfileWfService.getMdoAdminAndPCDetails(wfRequest.getRootOrgId(), emailToSend); - Map params = new HashMap<>(); - NotificationRequest request = new NotificationRequest(); - request.setDeliveryType("message"); - List mdoMailList = mdoAdminList.stream().collect(Collectors.toList()); - if (!CollectionUtils.isEmpty(mdoMailList)) { - request.setIds(mdoMailList); - request.setMode("email"); - Template template = new Template(); - template.setId(configuration.getMdoEmailTemplate()); - HashMap usersObj = userProfileWfService.getUsersResult(Collections.singleton(wfRequest.getUserId())); - Map recipientInfo = (Map) usersObj.get(wfStatusEntity.getUserId()); - params.put(Constants.USER_NAME, recipientInfo.get(Constants.FIRST_NAME)); - params.put(Constants.SUPPORT_EMAIL, configuration.getSenderMail()); - String constructedEmailTemplate = constructEmailTemplate(configuration.getBpAprroveAndRejectEmailTemplate(), params); - if (StringUtils.isNotEmpty(constructedEmailTemplate)) { - template.setData(constructedEmailTemplate); + List pcEmailList = userProfileWfService.getMdoAdminAndPCDetails(wfRequest.getRootOrgId(), Collections.singletonList(Constants.PROGRAM_COORDINATOR)); + List mdoEmailList = userProfileWfService.getMdoAdminAndPCDetails(wfRequest.getRootOrgId(), Collections.singletonList(Constants.MDO_ADMIN)); + HashMap usersObj = userProfileWfService.getUsersResult(Collections.singleton(wfRequest.getUserId())); + Map recipientInfo = (Map) usersObj.get(wfStatusEntity.getUserId()); + String userName = (String) recipientInfo.get(Constants.FIRST_NAME); + Map mailNotificationDetails = new HashMap<>(); + String subjectLine = ""; + String body = ""; + String enrolmentStateSubject = "Enrolment #state"; + String approvalRequestSubject = "Enrollment Approval Request"; + String requestForwardedSubject = "Enrollment Request Forwarded to #role"; + String date = wfRequest.getBatchStartDate().toString(); + String nominationRequestMailBody = configuration.getNominationRequestMailBody().replace(USERNAMAE_TAG, userName) + .replace(BATCH_NAME_TAG, wfRequest.getBatchName()) + .replace(BLENDED_PROGRAME_NAME_TAG, wfRequest.getCourseName()); + nominationRequestMailBody = nominationRequestMailBody.replace(BATCH_START_DATE_TAG, wfRequest.getBatchStartDate().toString()); + String approvalRequestMailBody = configuration.getApprovalRequetMailBody().replace(USERNAMAE_TAG, userName) + .replace(BATCH_NAME_TAG, wfRequest.getBatchName()) + .replace(BLENDED_PROGRAME_NAME_TAG, wfRequest.getCourseName()); + approvalRequestMailBody = approvalRequestMailBody.replace(BATCH_START_DATE_TAG, date); + String requestForwardedMailBody = configuration.getRequestForwardedMailBody().replace(USERNAMAE_TAG, userName) + .replace(BATCH_NAME_TAG, wfRequest.getBatchName()) + .replace(BLENDED_PROGRAME_NAME_TAG, wfRequest.getCourseName()) + .replace(BATCH_START_DATE_TAG, wfRequest.getBatchStartDate().toString()); + mailNotificationDetails.put("subject", approvalRequestSubject); + mailNotificationDetails.put("body", approvalRequestMailBody); + if(Constants.INITIATE.equalsIgnoreCase(wfRequest.getState()) && Constants.SEND_FOR_PC_APPROVAL.equalsIgnoreCase(wfStatusEntity.getCurrentStatus())){ + mailNotificationDetails.put("emailList", pcEmailList); + mailNotificationDetails.put("emailTo", Constants.PROGRAM_COORDINATOR.replace("_", " ")); + sendNotificationEmail(mailNotificationDetails); + } else if(Constants.INITIATE.equalsIgnoreCase(wfRequest.getState()) && Constants.SEND_FOR_MDO_APPROVAL.equalsIgnoreCase(wfStatusEntity.getCurrentStatus())){ + mailNotificationDetails.put("emailList", mdoEmailList); + mailNotificationDetails.put("emailTo", Constants.MDO_ADMIN.replace("_", " ")); + sendNotificationEmail(mailNotificationDetails); + } else if(Constants.SEND_FOR_MDO_APPROVAL.equalsIgnoreCase(wfRequest.getState()) && Constants.SEND_FOR_PC_APPROVAL.equalsIgnoreCase(wfStatusEntity.getCurrentStatus())){ + mailNotificationDetails.put("emailList", pcEmailList); + mailNotificationDetails.put("emailTo", Constants.PROGRAM_COORDINATOR.replace("_", " ")); + sendNotificationEmail(mailNotificationDetails); + + subjectLine = requestForwardedSubject.replace(ROLE_TAG,Constants.PROGRAM_COORDINATOR.replace("_", " ")); + body = requestForwardedMailBody.replace(ROLE_TAG,Constants.PROGRAM_COORDINATOR.replace("_", " ")); + mailNotificationDetails.put("subject", subjectLine); + mailNotificationDetails.put("body", body); + mailNotificationDetails.put("emailList", mdoEmailList); + mailNotificationDetails.put("emailTo", Constants.MDO_ADMIN.replace("_", " ")); + sendNotificationEmail(mailNotificationDetails); + + } else if(Constants.SEND_FOR_PC_APPROVAL.equalsIgnoreCase(wfRequest.getState()) && Constants.SEND_FOR_MDO_APPROVAL.equalsIgnoreCase(wfStatusEntity.getCurrentStatus())){ + mailNotificationDetails.put("emailList", mdoEmailList); + mailNotificationDetails.put("emailTo", Constants.MDO_ADMIN.replace("_", " ")); + sendNotificationEmail(mailNotificationDetails); + + subjectLine = requestForwardedSubject.replace(ROLE_TAG,Constants.MDO_ADMIN.split("_")[0]); + body = requestForwardedMailBody.replace(ROLE_TAG,Constants.MDO_ADMIN.split("_")[0]); + mailNotificationDetails.put("subject", subjectLine); + mailNotificationDetails.put("body", body); + mailNotificationDetails.put("emailList", pcEmailList); + mailNotificationDetails.put("emailTo", Constants.PROGRAM_COORDINATOR.replace("_", " ")); + sendNotificationEmail(mailNotificationDetails); + + } + if(Constants.INITIATE.equalsIgnoreCase(wfRequest.getState()) && Constants.ADMIN_ENROLL_IS_IN_PROGRESS.equalsIgnoreCase(wfStatusEntity.getCurrentStatus())) { + mailNotificationDetails.put("emailList", pcEmailList); + mailNotificationDetails.put("emailTo", Constants.PROGRAM_COORDINATOR.replace("_", " ")); + sendNotificationEmail(mailNotificationDetails); + } + if(Constants.ADMIN_ENROLL_IS_IN_PROGRESS.equalsIgnoreCase(wfRequest.getState())){ + if (Constants.APPROVED.equalsIgnoreCase(wfStatusEntity.getCurrentStatus())) { + subjectLine = enrolmentStateSubject.replace("#state", Constants.APPROVED); + body = nominationRequestMailBody.replace("#state", Constants.APPROVED); + mailNotificationDetails.put("emailList", mdoEmailList); + mailNotificationDetails.put("subject", subjectLine); + mailNotificationDetails.put("body", body); + mailNotificationDetails.put("emailTo", Constants.MDO_ADMIN.replace("_", " ")); + sendNotificationEmail(mailNotificationDetails); + } else if (Constants.REJECTED.equalsIgnoreCase(wfStatusEntity.getCurrentStatus())) { + subjectLine = enrolmentStateSubject.replace("#state", Constants.APPROVED); + body = nominationRequestMailBody.replace("#state", Constants.APPROVED); + if (StringUtils.isNotBlank(wfRequest.getComment())) { + body = body + ", due to " + wfRequest.getComment() + "."; + } + mailNotificationDetails.put("emailList", mdoEmailList); + mailNotificationDetails.put("subject", subjectLine); + mailNotificationDetails.put("body", body); + mailNotificationDetails.put("emailTo", Constants.MDO_ADMIN.replace("_", " ")); + sendNotificationEmail(mailNotificationDetails); } - template.setParams(params); - Config config = new Config(); - config.setSubject(MDO_MAIL_SUBJECT); - config.setSender(configuration.getSenderMail()); - Map req = new HashMap<>(); - request.setTemplate(template); - request.setConfig(config); - Map> notificationMap = new HashMap<>(); - notificationMap.put("notifications", Arrays.asList(request)); - req.put("request", notificationMap); - sendNotification(req); } + logger.info("current role to send notification "+emailToSend); + + } + } + + private void sendNotificationEmail(Map mailNotificationDetails){ + Map params = new HashMap<>(); + NotificationRequest request = new NotificationRequest(); + List emailList = (List) mailNotificationDetails.get("emailList"); + request.setDeliveryType("message"); + if (!CollectionUtils.isEmpty(emailList)) { + request.setIds(emailList); + request.setMode("email"); + Template template = new Template(); + template.setId(configuration.getNotificationEmailTemplate()); + params.put(Constants.NAME, mailNotificationDetails.get("emailTo")); + params.put("body", mailNotificationDetails.get("body")); + params.put(Constants.ORG_NAME, "Karmyogi Bharat"); + params.put(Constants.FROM_EMAIL, configuration.getSenderMail()); + String constructedEmailTemplate = constructEmailTemplate(configuration.getNotificationEmailTemplate(), params); + if (StringUtils.isNotEmpty(constructedEmailTemplate)) { + template.setData(constructedEmailTemplate); + } + template.setParams(params); + Config config = new Config(); + config.setSubject((String) mailNotificationDetails.get("subject")); + config.setSender(configuration.getSenderMail()); + Map req = new HashMap<>(); + request.setTemplate(template); + request.setConfig(config); + Map> notificationMap = new HashMap<>(); + notificationMap.put("notifications", Arrays.asList(request)); + req.put("request", notificationMap); + sendNotification(req); } } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index a236f4e4..0e7ed00c 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -109,5 +109,10 @@ blended.program.batch.in.progress.message=This batch is already in progress #blended_mail_subject_body bp.mail.body.forwarded.to=Your enrollment request for #batch_name of the #course_name Program, starting on #batch_start_date has been forwarded to the #role for approval. -bp.mail.body.rejected.or.remove=We regret to inform you that your enrollment request for #batch_name of the #course_name Program, starting on #batch_start_date has been #action -bp.mail.body.approve="We are pleased to inform you that your enrollment request for #batch_name of the #course_name Program, starting on #batch_start_date has been approved. +bp.mail.body.rejected.or.remove=We regret to inform you that your enrollment request for #batch_name of the #course_name Program, starting on #batch_start_date has been #action. +bp.mail.body.approve=We are pleased to inform you that your enrollment request for #batch_name of the #course_name Program, starting on #batch_start_date has been approved. + +notify.email.template=notificationEmailTemplate +bp.approval.request.mail.body=You have received a request for enrollment for #username in #batch_name of the #blended_programme_name starting on #batch_start_date, which requires your approval. +bp.request.forwarded.mail.body=The enrollment request for #username in #batch_name of the #blended_programme_name Program, starting on #batch_start_date , has been forwarded to the #role for approval. +bp.nomination.request.mail.body=The enrollment request for #username in #batch_name of the #blended_programme_name Program, starting on #batch_start_date , has been #state. \ No newline at end of file From 5f1a8a2d2c7ac4758381461d4efdc559972d1b77 Mon Sep 17 00:00:00 2001 From: Ravi Saurav Date: Thu, 26 Oct 2023 23:26:52 +0530 Subject: [PATCH 15/18] 107261:created constant for KArmyogi bharat --- src/main/java/org/sunbird/workflow/config/Constants.java | 1 + .../sunbird/workflow/service/impl/NotificationServiceImpl.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/sunbird/workflow/config/Constants.java b/src/main/java/org/sunbird/workflow/config/Constants.java index 14b557db..5f57681c 100644 --- a/src/main/java/org/sunbird/workflow/config/Constants.java +++ b/src/main/java/org/sunbird/workflow/config/Constants.java @@ -248,4 +248,5 @@ private Constants() { 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"; } diff --git a/src/main/java/org/sunbird/workflow/service/impl/NotificationServiceImpl.java b/src/main/java/org/sunbird/workflow/service/impl/NotificationServiceImpl.java index 8f0bc655..b5152dcf 100644 --- a/src/main/java/org/sunbird/workflow/service/impl/NotificationServiceImpl.java +++ b/src/main/java/org/sunbird/workflow/service/impl/NotificationServiceImpl.java @@ -420,7 +420,7 @@ private void sendNotificationEmail(Map mailNotificationDetails){ template.setId(configuration.getNotificationEmailTemplate()); params.put(Constants.NAME, mailNotificationDetails.get("emailTo")); params.put("body", mailNotificationDetails.get("body")); - params.put(Constants.ORG_NAME, "Karmyogi Bharat"); + params.put(Constants.ORG_NAME, Constants.KARMYOGI_BHARAT); params.put(Constants.FROM_EMAIL, configuration.getSenderMail()); String constructedEmailTemplate = constructEmailTemplate(configuration.getNotificationEmailTemplate(), params); if (StringUtils.isNotEmpty(constructedEmailTemplate)) { From 3a59c9b5864c90981210761832c7f5501e66767e Mon Sep 17 00:00:00 2001 From: tarentomaheshvakkund <139739142+tarentomaheshvakkund@users.noreply.github.com> Date: Fri, 27 Oct 2023 11:41:15 +0530 Subject: [PATCH 16/18] Bug Fix for verifiedKarmayogi. (#123) Bug Fix for verifiedKarmayogi. --- .../sunbird/workflow/service/impl/UserProfileWfServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/sunbird/workflow/service/impl/UserProfileWfServiceImpl.java b/src/main/java/org/sunbird/workflow/service/impl/UserProfileWfServiceImpl.java index 57efcebc..3cf1541f 100644 --- a/src/main/java/org/sunbird/workflow/service/impl/UserProfileWfServiceImpl.java +++ b/src/main/java/org/sunbird/workflow/service/impl/UserProfileWfServiceImpl.java @@ -147,7 +147,7 @@ public Map updateRequestWithWF(String uuid, List toValueMap = (Map) wfRequestParamObj.get(Constants.TO_VALUE); existingProfileDetail.put((String) wfRequestParamObj.get(Constants.FIELD_KEY), (Boolean) toValueMap.get(Constants.VERIFIED_KARMAYOGI)); - } else if (Constants.PROFILE_DETAILS.equalsIgnoreCase((String) wfRequestParamObj.get(Constants.FIELD_KEY))) { + } else if (Constants.PROFESSIONAL_DETAILS.equalsIgnoreCase((String) wfRequestParamObj.get(Constants.FIELD_KEY))) { List> detailsList = new ArrayList<>(); Map detailsMap = new HashMap<>(); detailsMap = (Map) wfRequestParamObj.get(Constants.TO_VALUE); From 01bab3e95c2831e647cad89a6360fe29646b7ec4 Mon Sep 17 00:00:00 2001 From: Ravi Saurav Date: Mon, 30 Oct 2023 11:34:14 +0530 Subject: [PATCH 17/18] 107261:Added constant formatted to adrress the recepient in the mail notification --- .../org/sunbird/workflow/config/Constants.java | 2 ++ .../service/impl/NotificationServiceImpl.java | 18 +++++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/sunbird/workflow/config/Constants.java b/src/main/java/org/sunbird/workflow/config/Constants.java index 5c96eee2..587be740 100644 --- a/src/main/java/org/sunbird/workflow/config/Constants.java +++ b/src/main/java/org/sunbird/workflow/config/Constants.java @@ -255,4 +255,6 @@ private Constants() { public static final String CONTEXT_NAME = "contextName"; public static final String USER_REGISTRATION_PRE_APPROVED_DOMAIN = "userRegistrationPreApprovedDomain"; public static final String DOMAIN_NAME_REQUEST_EXIST_MSG = "Already a request is raised for domain"; + public static final String TO_PROGRAMME_COORDINATOR = "Programme Coordinator"; + public static final String TO_MDO_ADMIN = "MDO Admin"; } \ No newline at end of file diff --git a/src/main/java/org/sunbird/workflow/service/impl/NotificationServiceImpl.java b/src/main/java/org/sunbird/workflow/service/impl/NotificationServiceImpl.java index b5152dcf..2d046da8 100644 --- a/src/main/java/org/sunbird/workflow/service/impl/NotificationServiceImpl.java +++ b/src/main/java/org/sunbird/workflow/service/impl/NotificationServiceImpl.java @@ -343,15 +343,15 @@ public void sendNotificationToMdoAdminAndPC(WfRequest wfRequest) { mailNotificationDetails.put("body", approvalRequestMailBody); if(Constants.INITIATE.equalsIgnoreCase(wfRequest.getState()) && Constants.SEND_FOR_PC_APPROVAL.equalsIgnoreCase(wfStatusEntity.getCurrentStatus())){ mailNotificationDetails.put("emailList", pcEmailList); - mailNotificationDetails.put("emailTo", Constants.PROGRAM_COORDINATOR.replace("_", " ")); + mailNotificationDetails.put("emailTo", Constants.TO_PROGRAMME_COORDINATOR); sendNotificationEmail(mailNotificationDetails); } else if(Constants.INITIATE.equalsIgnoreCase(wfRequest.getState()) && Constants.SEND_FOR_MDO_APPROVAL.equalsIgnoreCase(wfStatusEntity.getCurrentStatus())){ mailNotificationDetails.put("emailList", mdoEmailList); - mailNotificationDetails.put("emailTo", Constants.MDO_ADMIN.replace("_", " ")); + mailNotificationDetails.put("emailTo", Constants.TO_MDO_ADMIN); sendNotificationEmail(mailNotificationDetails); } else if(Constants.SEND_FOR_MDO_APPROVAL.equalsIgnoreCase(wfRequest.getState()) && Constants.SEND_FOR_PC_APPROVAL.equalsIgnoreCase(wfStatusEntity.getCurrentStatus())){ mailNotificationDetails.put("emailList", pcEmailList); - mailNotificationDetails.put("emailTo", Constants.PROGRAM_COORDINATOR.replace("_", " ")); + mailNotificationDetails.put("emailTo", Constants.TO_PROGRAMME_COORDINATOR); sendNotificationEmail(mailNotificationDetails); subjectLine = requestForwardedSubject.replace(ROLE_TAG,Constants.PROGRAM_COORDINATOR.replace("_", " ")); @@ -359,12 +359,12 @@ public void sendNotificationToMdoAdminAndPC(WfRequest wfRequest) { mailNotificationDetails.put("subject", subjectLine); mailNotificationDetails.put("body", body); mailNotificationDetails.put("emailList", mdoEmailList); - mailNotificationDetails.put("emailTo", Constants.MDO_ADMIN.replace("_", " ")); + mailNotificationDetails.put("emailTo", Constants.TO_MDO_ADMIN); sendNotificationEmail(mailNotificationDetails); } else if(Constants.SEND_FOR_PC_APPROVAL.equalsIgnoreCase(wfRequest.getState()) && Constants.SEND_FOR_MDO_APPROVAL.equalsIgnoreCase(wfStatusEntity.getCurrentStatus())){ mailNotificationDetails.put("emailList", mdoEmailList); - mailNotificationDetails.put("emailTo", Constants.MDO_ADMIN.replace("_", " ")); + mailNotificationDetails.put("emailTo", Constants.TO_MDO_ADMIN); sendNotificationEmail(mailNotificationDetails); subjectLine = requestForwardedSubject.replace(ROLE_TAG,Constants.MDO_ADMIN.split("_")[0]); @@ -372,13 +372,13 @@ public void sendNotificationToMdoAdminAndPC(WfRequest wfRequest) { mailNotificationDetails.put("subject", subjectLine); mailNotificationDetails.put("body", body); mailNotificationDetails.put("emailList", pcEmailList); - mailNotificationDetails.put("emailTo", Constants.PROGRAM_COORDINATOR.replace("_", " ")); + mailNotificationDetails.put("emailTo", Constants.TO_PROGRAMME_COORDINATOR); sendNotificationEmail(mailNotificationDetails); } if(Constants.INITIATE.equalsIgnoreCase(wfRequest.getState()) && Constants.ADMIN_ENROLL_IS_IN_PROGRESS.equalsIgnoreCase(wfStatusEntity.getCurrentStatus())) { mailNotificationDetails.put("emailList", pcEmailList); - mailNotificationDetails.put("emailTo", Constants.PROGRAM_COORDINATOR.replace("_", " ")); + mailNotificationDetails.put("emailTo", Constants.TO_PROGRAMME_COORDINATOR); sendNotificationEmail(mailNotificationDetails); } if(Constants.ADMIN_ENROLL_IS_IN_PROGRESS.equalsIgnoreCase(wfRequest.getState())){ @@ -388,7 +388,7 @@ public void sendNotificationToMdoAdminAndPC(WfRequest wfRequest) { mailNotificationDetails.put("emailList", mdoEmailList); mailNotificationDetails.put("subject", subjectLine); mailNotificationDetails.put("body", body); - mailNotificationDetails.put("emailTo", Constants.MDO_ADMIN.replace("_", " ")); + mailNotificationDetails.put("emailTo", Constants.TO_MDO_ADMIN); sendNotificationEmail(mailNotificationDetails); } else if (Constants.REJECTED.equalsIgnoreCase(wfStatusEntity.getCurrentStatus())) { subjectLine = enrolmentStateSubject.replace("#state", Constants.APPROVED); @@ -399,7 +399,7 @@ public void sendNotificationToMdoAdminAndPC(WfRequest wfRequest) { mailNotificationDetails.put("emailList", mdoEmailList); mailNotificationDetails.put("subject", subjectLine); mailNotificationDetails.put("body", body); - mailNotificationDetails.put("emailTo", Constants.MDO_ADMIN.replace("_", " ")); + mailNotificationDetails.put("emailTo", Constants.TO_MDO_ADMIN); sendNotificationEmail(mailNotificationDetails); } } From e73bc1be66faaaaa8922e18f4e22c19fec746fb3 Mon Sep 17 00:00:00 2001 From: Ravi Saurav Date: Mon, 30 Oct 2023 15:00:31 +0530 Subject: [PATCH 18/18] 107261:Created a new model class for batch name, batch start date, course name --- .../consumer/NotificationConsumer.java | 48 ++++++++-- .../workflow/models/WfNotification.java | 36 ++++++++ .../sunbird/workflow/models/WfRequest.java | 30 ------ .../service/impl/BPWorkFlowServiceImpl.java | 61 +++++++------ .../service/impl/NotificationServiceImpl.java | 91 ++++++++++--------- 5 files changed, 152 insertions(+), 114 deletions(-) create mode 100644 src/main/java/org/sunbird/workflow/models/WfNotification.java diff --git a/src/main/java/org/sunbird/workflow/consumer/NotificationConsumer.java b/src/main/java/org/sunbird/workflow/consumer/NotificationConsumer.java index 9579aa59..f6aa8538 100644 --- a/src/main/java/org/sunbird/workflow/consumer/NotificationConsumer.java +++ b/src/main/java/org/sunbird/workflow/consumer/NotificationConsumer.java @@ -1,5 +1,7 @@ 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; @@ -7,10 +9,16 @@ import org.springframework.kafka.annotation.KafkaListener; import org.springframework.stereotype.Service; import org.sunbird.workflow.config.Constants; -import org.sunbird.workflow.models.WfRequest; +import org.sunbird.workflow.models.WfNotification; 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 { @@ -22,30 +30,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 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 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 @@ -58,4 +71,19 @@ public void processMessage(ConsumerRecord data) { logger.error("Error while deserialization the object value", ex); } } + + public Map getCourseAttributes(String courseId){ + Map propertiesMap = new HashMap<>(); + Map courseDetails = new HashMap<>(); + propertiesMap.put(Constants.IDENTIFIER, courseId); + List> coursesDataList = cassandraOperation.getRecordsByProperties(Constants.DEV_HIERARCHY_STORE, + Constants.CONTENT_HIERARCHY, + propertiesMap, + Arrays.asList(Constants.IDENTIFIER, Constants.HIERARCHY)); + Map hierarchy = new Gson().fromJson((String) coursesDataList.get(0).get("hierarchy"), new TypeToken>(){}.getType()); + courseDetails.put(Constants.COURSE_NAME, (String) hierarchy.get(Constants.NAME)); + return courseDetails; + } + + } diff --git a/src/main/java/org/sunbird/workflow/models/WfNotification.java b/src/main/java/org/sunbird/workflow/models/WfNotification.java new file mode 100644 index 00000000..15fea886 --- /dev/null +++ b/src/main/java/org/sunbird/workflow/models/WfNotification.java @@ -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; + } +} diff --git a/src/main/java/org/sunbird/workflow/models/WfRequest.java b/src/main/java/org/sunbird/workflow/models/WfRequest.java index 962dae09..5a4443af 100644 --- a/src/main/java/org/sunbird/workflow/models/WfRequest.java +++ b/src/main/java/org/sunbird/workflow/models/WfRequest.java @@ -30,12 +30,6 @@ public class WfRequest { private String courseId; - private String courseName; - - private String batchName; - - private Date batchStartDate; - public String getState() { return state; } @@ -132,28 +126,4 @@ public void setCourseId(String courseId) { this.courseId = courseId; } - 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; - } - } diff --git a/src/main/java/org/sunbird/workflow/service/impl/BPWorkFlowServiceImpl.java b/src/main/java/org/sunbird/workflow/service/impl/BPWorkFlowServiceImpl.java index 88bbbfa5..e267a1bd 100644 --- a/src/main/java/org/sunbird/workflow/service/impl/BPWorkFlowServiceImpl.java +++ b/src/main/java/org/sunbird/workflow/service/impl/BPWorkFlowServiceImpl.java @@ -101,13 +101,12 @@ public Response enrolBPWorkFlow(String rootOrg, String org, WfRequest wfRequest) response.put(Constants.STATUS, HttpStatus.BAD_REQUEST); return response; } - Map courseAttributes = getCourseAttributes(wfRequest.getCourseId()); - wfRequest.setCourseName((String) courseAttributes.get(Constants.COURSE_NAME)); - wfRequest.setBatchName((String) courseBatchDetails.get(Constants.BATCH_NAME)); - wfRequest.setBatchStartDate((Date) courseBatchDetails.get(Constants.START_DATE)); + 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); + producer.push(configuration.getWorkflowApplicationTopic(), wfNotification); return response; } @@ -115,11 +114,10 @@ public Response enrolBPWorkFlow(String rootOrg, String org, WfRequest wfRequest) public Response updateBPWorkFlow(String rootOrg, String org, WfRequest wfRequest,String userId,String role) { Response response = new Response(); Map batchDetailsMap = new HashMap<>(); + WfNotification wfNotification = getWorkFlowNotificationRequest(wfRequest); String validationError = validateBatchUserRequestAccess(wfRequest, batchDetailsMap); - wfRequest.setBatchName((String) batchDetailsMap.get(Constants.BATCH_NAME)); - wfRequest.setBatchStartDate((Date) batchDetailsMap.get(Constants.BATCH_START_DATE)); - Map courseAttributes = getCourseAttributes(wfRequest.getCourseId()); - wfRequest.setCourseName((String) courseAttributes.get(Constants.COURSE_NAME)); + wfNotification.setBatchName((String) batchDetailsMap.get(Constants.BATCH_NAME)); + wfNotification.setBatchStartDate((Date) batchDetailsMap.get(Constants.BATCH_START_DATE)); if (Constants.BATCH_START_DATE_ERROR.equals(validationError)) { response.put(Constants.ERROR_MESSAGE, configuration.getBatchInProgressMessage()); response.put(Constants.STATUS, HttpStatus.BAD_REQUEST); @@ -517,10 +515,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 { - Map courseAttributes = getCourseAttributes(wfRequest.getCourseId()); - wfRequest.setCourseName((String) courseAttributes.get(Constants.COURSE_NAME)); - wfRequest.setBatchName((String) courseBatchDetails.get(Constants.NAME)); - wfRequest.setBatchStartDate((Date) courseBatchDetails.get(Constants.BATCH_START_DATE)); + WfNotification wfNotification = getWorkFlowNotificationRequest(wfRequest); + wfNotification.setBatchName((String) courseBatchDetails.get(Constants.NAME)); + wfNotification.setBatchStartDate((Date) courseBatchDetails.get(Constants.BATCH_START_DATE)); response = saveAdminEnrollUserIntoWfStatus(rootOrg, org, wfRequest); // producer.push(configuration.getWorkFlowNotificationTopic(), wfRequest); wfRequest.setAction(Constants.INITIATE); @@ -591,11 +588,10 @@ 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()); - Map getCourseAttributes = getCourseAttributes(wfRequest.getCourseId()); - wfRequest.setBatchName((String) courseBatchDetails.get(Constants.BATCH_NAME)); - wfRequest.setBatchStartDate((Date) courseBatchDetails.get(Constants.BATCH_START_DATE)); - wfRequest.setCourseName((String) getCourseAttributes.get(Constants.COURSE_NAME)); - 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.BATCH_START_DATE)); + response = workflowService.workflowTransition(rootOrg, org, wfNotification, userId,role); response.put(Constants.STATUS, HttpStatus.OK); return response; @@ -1026,16 +1022,23 @@ private void handleApprovalRequest(WfRequest wfRequest) { } } - public Map getCourseAttributes(String courseId){ - Map propertiesMap = new HashMap<>(); - Map courseDetails = new HashMap<>(); - propertiesMap.put(Constants.IDENTIFIER, courseId); - List> coursesDataList = cassandraOperation.getRecordsByProperties(Constants.DEV_HIERARCHY_STORE, - Constants.CONTENT_HIERARCHY, - propertiesMap, - Arrays.asList(Constants.IDENTIFIER, Constants.HIERARCHY)); - Map hierarchy = new Gson().fromJson((String) coursesDataList.get(0).get("hierarchy"), new TypeToken>(){}.getType()); - courseDetails.put(Constants.COURSE_NAME, (String) hierarchy.get(Constants.NAME)); - return courseDetails; + 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; } + + } diff --git a/src/main/java/org/sunbird/workflow/service/impl/NotificationServiceImpl.java b/src/main/java/org/sunbird/workflow/service/impl/NotificationServiceImpl.java index 2d046da8..2d4ad866 100644 --- a/src/main/java/org/sunbird/workflow/service/impl/NotificationServiceImpl.java +++ b/src/main/java/org/sunbird/workflow/service/impl/NotificationServiceImpl.java @@ -14,6 +14,7 @@ import org.sunbird.workflow.config.Configuration; import org.sunbird.workflow.config.Constants; import org.sunbird.workflow.consumer.ApplicationProcessingConsumer; +import org.sunbird.workflow.models.WfNotification; import org.sunbird.workflow.models.WfRequest; import org.sunbird.workflow.models.WfStatus; import org.sunbird.workflow.models.notification.Config; @@ -103,11 +104,11 @@ public class NotificationServiceImpl { /** * Send notification to the user based on state of application * - * @param wfRequest workflow request + * @param wfNotification workflow request */ - public void sendNotification(WfRequest wfRequest) { - WfStatusEntity wfStatusEntity = wfStatusRepo.findByApplicationIdAndWfId(wfRequest.getApplicationId(), - wfRequest.getWfId()); + public void sendNotification(WfNotification wfNotification) { + WfStatusEntity wfStatusEntity = wfStatusRepo.findByApplicationIdAndWfId(wfNotification.getApplicationId(), + wfNotification.getWfId()); WfStatus wfStatus = workflowservice.getWorkflowStates(wfStatusEntity.getRootOrg(), wfStatusEntity.getOrg(), wfStatusEntity.getServiceName(), wfStatusEntity.getCurrentStatus()); try { @@ -119,33 +120,33 @@ public void sendNotification(WfRequest wfRequest) { if (!ObjectUtils.isEmpty(wfStatus.getNotificationEnable()) && wfStatus.getNotificationEnable()) { logger.info("Enter's in the notification block"); Set usersId = new HashSet<>(); - usersId.add(wfRequest.getUserId()); + usersId.add(wfNotification.getUserId()); Set blendedProgrammeServiceNames = new HashSet<>(); blendedProgrammeServiceNames.addAll(Arrays.asList(Constants.BLENDED_PROGRAM_SERVICE_NAME, Constants.ONE_STEP_MDO_APPROVAL, Constants.ONE_STEP_PC_APPROVAL, Constants.TWO_STEP_MDO_AND_PC_APPROVAL, Constants.TWO_STEP_PC_AND_MDO_APPROVAL)); - if(!blendedProgrammeServiceNames.contains(wfRequest.getServiceName())){ + if(!blendedProgrammeServiceNames.contains(wfNotification.getServiceName())){ usersId.add(wfStatusEntity.getApplicationId()); } HashMap usersObj = userProfileWfService.getUsersResult(usersId); Map recipientInfo; - if (blendedProgrammeServiceNames.contains(wfRequest.getServiceName())) { - recipientInfo = (Map)usersObj.get(wfRequest.getUserId()); + if (blendedProgrammeServiceNames.contains(wfNotification.getServiceName())) { + recipientInfo = (Map)usersObj.get(wfNotification.getUserId()); } else { recipientInfo = (Map)usersObj.get(wfStatusEntity.getApplicationId()); } - Map senderInfo = (Map)usersObj.get(wfRequest.getUserId()); - Optional> updatedFieldValue = wfRequest.getUpdateFieldValues().stream().findFirst(); + Map senderInfo = (Map)usersObj.get(wfNotification.getUserId()); + Optional> updatedFieldValue = wfNotification.getUpdateFieldValues().stream().findFirst(); String subjectLine = ""; String body = ""; if (updatedFieldValue.isPresent()) { - if (blendedProgrammeServiceNames.contains(wfRequest.getServiceName())) { + if (blendedProgrammeServiceNames.contains(wfNotification.getServiceName())) { String forwardedMailBody = configuration.getLearnerForwardedMailBody() - .replace(COURSE_NAME_TAG, wfRequest.getCourseName()) - .replace(BATCH_NAME_TAG, wfRequest.getBatchName()) - .replace(BATCH_START_DATE_TAG, wfRequest.getBatchStartDate().toString()); + .replace(COURSE_NAME_TAG, wfNotification.getCourseName()) + .replace(BATCH_NAME_TAG, wfNotification.getBatchName()) + .replace(BATCH_START_DATE_TAG, wfNotification.getBatchStartDate().toString()); switch (wfStatusEntity.getCurrentStatus()){ case Constants.SEND_FOR_PC_APPROVAL: subjectLine = BP_MDO_PC_SUBJECT_LINE.replace(Role_TAG,Constants.PROGRAM_COORDINATOR.replace("_"," ")); @@ -158,18 +159,18 @@ public void sendNotification(WfRequest wfRequest) { case Constants.APPROVED: subjectLine = ENROLMENT_ACTION_SUBJECT.replace(ACT_TAG, wfStatusEntity.getCurrentStatus()); body = configuration.getApprovedMailBody() - .replace(BATCH_NAME_TAG, wfRequest.getBatchName()) - .replace(COURSE_NAME_TAG, wfRequest.getCourseName()) - .replace(BATCH_START_DATE_TAG, wfRequest.getBatchStartDate().toString()); + .replace(BATCH_NAME_TAG, wfNotification.getBatchName()) + .replace(COURSE_NAME_TAG, wfNotification.getCourseName()) + .replace(BATCH_START_DATE_TAG, wfNotification.getBatchStartDate().toString()); break; case Constants.REJECTED: case Constants.REMOVED: subjectLine = ENROLMENT_ACTION_SUBJECT.replace(ACT_TAG, wfStatusEntity.getCurrentStatus()); body = configuration.getRejectedOrRemovedMailBody() - .replace(BATCH_NAME_TAG, wfRequest.getBatchName()) - .replace(COURSE_NAME_TAG, wfRequest.getCourseName()) + .replace(BATCH_NAME_TAG, wfNotification.getBatchName()) + .replace(COURSE_NAME_TAG, wfNotification.getCourseName()) .replace(ACT_TAG,wfStatusEntity.getCurrentStatus()) - .replace(BATCH_START_DATE_TAG, wfRequest.getBatchStartDate().toString()); + .replace(BATCH_START_DATE_TAG, wfNotification.getBatchStartDate().toString()); break; default: subjectLine = MAIL_SUBJECT.replace(STATE_NAME_TAG, wfStatusEntity.getCurrentStatus()); @@ -184,8 +185,8 @@ public void sendNotification(WfRequest wfRequest) { subjectLine = MAIL_SUBJECT.replace(STATE_NAME_TAG, wfStatusEntity.getCurrentStatus()); } } - if (StringUtils.isNotBlank(wfRequest.getComment())) { - body = body + ", due to " + wfRequest.getComment() + "."; + if (StringUtils.isNotBlank(wfNotification.getComment())) { + body = body + ", due to " + wfNotification.getComment() + "."; } Map mailNotificationDetails = new HashMap<>(); mailNotificationDetails.put("emailTo", senderInfo.get(Constants.FIRST_NAME)); @@ -306,18 +307,18 @@ public void sendNotificationToMdoAdmin(WfRequest wfRequest) { } } - public void sendNotificationToMdoAdminAndPC(WfRequest wfRequest) { - WfStatusEntity wfStatusEntity = wfStatusRepo.findByApplicationIdAndWfId(wfRequest.getApplicationId(), - wfRequest.getWfId()); + public void sendNotificationToMdoAdminAndPC(WfNotification wfNotification) { + WfStatusEntity wfStatusEntity = wfStatusRepo.findByApplicationIdAndWfId(wfNotification.getApplicationId(), + wfNotification.getWfId()); WfStatus wfStatus = workflowservice.getWorkflowStates(wfStatusEntity.getRootOrg(), wfStatusEntity.getOrg(), wfStatusEntity.getServiceName(), wfStatusEntity.getCurrentStatus()); if (!ObjectUtils.isEmpty(wfStatus.getNotificationEnable()) && wfStatus.getNotificationEnable() && !Arrays.asList(Constants.REJECTED, Constants.APPROVED).contains(wfStatus.getState())) { logger.info("Enter in the sendNotificationToMdoAdminAndPC block"); List emailToSend = new ArrayList<>(); - List pcEmailList = userProfileWfService.getMdoAdminAndPCDetails(wfRequest.getRootOrgId(), Collections.singletonList(Constants.PROGRAM_COORDINATOR)); - List mdoEmailList = userProfileWfService.getMdoAdminAndPCDetails(wfRequest.getRootOrgId(), Collections.singletonList(Constants.MDO_ADMIN)); - HashMap usersObj = userProfileWfService.getUsersResult(Collections.singleton(wfRequest.getUserId())); + List pcEmailList = userProfileWfService.getMdoAdminAndPCDetails(wfNotification.getRootOrgId(), Collections.singletonList(Constants.PROGRAM_COORDINATOR)); + List mdoEmailList = userProfileWfService.getMdoAdminAndPCDetails(wfNotification.getRootOrgId(), Collections.singletonList(Constants.MDO_ADMIN)); + HashMap usersObj = userProfileWfService.getUsersResult(Collections.singleton(wfNotification.getUserId())); Map recipientInfo = (Map) usersObj.get(wfStatusEntity.getUserId()); String userName = (String) recipientInfo.get(Constants.FIRST_NAME); Map mailNotificationDetails = new HashMap<>(); @@ -326,30 +327,30 @@ public void sendNotificationToMdoAdminAndPC(WfRequest wfRequest) { String enrolmentStateSubject = "Enrolment #state"; String approvalRequestSubject = "Enrollment Approval Request"; String requestForwardedSubject = "Enrollment Request Forwarded to #role"; - String date = wfRequest.getBatchStartDate().toString(); + String date = wfNotification.getBatchStartDate().toString(); String nominationRequestMailBody = configuration.getNominationRequestMailBody().replace(USERNAMAE_TAG, userName) - .replace(BATCH_NAME_TAG, wfRequest.getBatchName()) - .replace(BLENDED_PROGRAME_NAME_TAG, wfRequest.getCourseName()); - nominationRequestMailBody = nominationRequestMailBody.replace(BATCH_START_DATE_TAG, wfRequest.getBatchStartDate().toString()); + .replace(BATCH_NAME_TAG, wfNotification.getBatchName()) + .replace(BLENDED_PROGRAME_NAME_TAG, wfNotification.getCourseName()); + nominationRequestMailBody = nominationRequestMailBody.replace(BATCH_START_DATE_TAG, wfNotification.getBatchStartDate().toString()); String approvalRequestMailBody = configuration.getApprovalRequetMailBody().replace(USERNAMAE_TAG, userName) - .replace(BATCH_NAME_TAG, wfRequest.getBatchName()) - .replace(BLENDED_PROGRAME_NAME_TAG, wfRequest.getCourseName()); + .replace(BATCH_NAME_TAG, wfNotification.getBatchName()) + .replace(BLENDED_PROGRAME_NAME_TAG, wfNotification.getCourseName()); approvalRequestMailBody = approvalRequestMailBody.replace(BATCH_START_DATE_TAG, date); String requestForwardedMailBody = configuration.getRequestForwardedMailBody().replace(USERNAMAE_TAG, userName) - .replace(BATCH_NAME_TAG, wfRequest.getBatchName()) - .replace(BLENDED_PROGRAME_NAME_TAG, wfRequest.getCourseName()) - .replace(BATCH_START_DATE_TAG, wfRequest.getBatchStartDate().toString()); + .replace(BATCH_NAME_TAG, wfNotification.getBatchName()) + .replace(BLENDED_PROGRAME_NAME_TAG, wfNotification.getCourseName()) + .replace(BATCH_START_DATE_TAG, wfNotification.getBatchStartDate().toString()); mailNotificationDetails.put("subject", approvalRequestSubject); mailNotificationDetails.put("body", approvalRequestMailBody); - if(Constants.INITIATE.equalsIgnoreCase(wfRequest.getState()) && Constants.SEND_FOR_PC_APPROVAL.equalsIgnoreCase(wfStatusEntity.getCurrentStatus())){ + if(Constants.INITIATE.equalsIgnoreCase(wfNotification.getState()) && Constants.SEND_FOR_PC_APPROVAL.equalsIgnoreCase(wfStatusEntity.getCurrentStatus())){ mailNotificationDetails.put("emailList", pcEmailList); mailNotificationDetails.put("emailTo", Constants.TO_PROGRAMME_COORDINATOR); sendNotificationEmail(mailNotificationDetails); - } else if(Constants.INITIATE.equalsIgnoreCase(wfRequest.getState()) && Constants.SEND_FOR_MDO_APPROVAL.equalsIgnoreCase(wfStatusEntity.getCurrentStatus())){ + } else if(Constants.INITIATE.equalsIgnoreCase(wfNotification.getState()) && Constants.SEND_FOR_MDO_APPROVAL.equalsIgnoreCase(wfStatusEntity.getCurrentStatus())){ mailNotificationDetails.put("emailList", mdoEmailList); mailNotificationDetails.put("emailTo", Constants.TO_MDO_ADMIN); sendNotificationEmail(mailNotificationDetails); - } else if(Constants.SEND_FOR_MDO_APPROVAL.equalsIgnoreCase(wfRequest.getState()) && Constants.SEND_FOR_PC_APPROVAL.equalsIgnoreCase(wfStatusEntity.getCurrentStatus())){ + } else if(Constants.SEND_FOR_MDO_APPROVAL.equalsIgnoreCase(wfNotification.getState()) && Constants.SEND_FOR_PC_APPROVAL.equalsIgnoreCase(wfStatusEntity.getCurrentStatus())){ mailNotificationDetails.put("emailList", pcEmailList); mailNotificationDetails.put("emailTo", Constants.TO_PROGRAMME_COORDINATOR); sendNotificationEmail(mailNotificationDetails); @@ -362,7 +363,7 @@ public void sendNotificationToMdoAdminAndPC(WfRequest wfRequest) { mailNotificationDetails.put("emailTo", Constants.TO_MDO_ADMIN); sendNotificationEmail(mailNotificationDetails); - } else if(Constants.SEND_FOR_PC_APPROVAL.equalsIgnoreCase(wfRequest.getState()) && Constants.SEND_FOR_MDO_APPROVAL.equalsIgnoreCase(wfStatusEntity.getCurrentStatus())){ + } else if(Constants.SEND_FOR_PC_APPROVAL.equalsIgnoreCase(wfNotification.getState()) && Constants.SEND_FOR_MDO_APPROVAL.equalsIgnoreCase(wfStatusEntity.getCurrentStatus())){ mailNotificationDetails.put("emailList", mdoEmailList); mailNotificationDetails.put("emailTo", Constants.TO_MDO_ADMIN); sendNotificationEmail(mailNotificationDetails); @@ -376,12 +377,12 @@ public void sendNotificationToMdoAdminAndPC(WfRequest wfRequest) { sendNotificationEmail(mailNotificationDetails); } - if(Constants.INITIATE.equalsIgnoreCase(wfRequest.getState()) && Constants.ADMIN_ENROLL_IS_IN_PROGRESS.equalsIgnoreCase(wfStatusEntity.getCurrentStatus())) { + if(Constants.INITIATE.equalsIgnoreCase(wfNotification.getState()) && Constants.ADMIN_ENROLL_IS_IN_PROGRESS.equalsIgnoreCase(wfStatusEntity.getCurrentStatus())) { mailNotificationDetails.put("emailList", pcEmailList); mailNotificationDetails.put("emailTo", Constants.TO_PROGRAMME_COORDINATOR); sendNotificationEmail(mailNotificationDetails); } - if(Constants.ADMIN_ENROLL_IS_IN_PROGRESS.equalsIgnoreCase(wfRequest.getState())){ + if(Constants.ADMIN_ENROLL_IS_IN_PROGRESS.equalsIgnoreCase(wfNotification.getState())){ if (Constants.APPROVED.equalsIgnoreCase(wfStatusEntity.getCurrentStatus())) { subjectLine = enrolmentStateSubject.replace("#state", Constants.APPROVED); body = nominationRequestMailBody.replace("#state", Constants.APPROVED); @@ -393,8 +394,8 @@ public void sendNotificationToMdoAdminAndPC(WfRequest wfRequest) { } else if (Constants.REJECTED.equalsIgnoreCase(wfStatusEntity.getCurrentStatus())) { subjectLine = enrolmentStateSubject.replace("#state", Constants.APPROVED); body = nominationRequestMailBody.replace("#state", Constants.APPROVED); - if (StringUtils.isNotBlank(wfRequest.getComment())) { - body = body + ", due to " + wfRequest.getComment() + "."; + if (StringUtils.isNotBlank(wfNotification.getComment())) { + body = body + ", due to " + wfNotification.getComment() + "."; } mailNotificationDetails.put("emailList", mdoEmailList); mailNotificationDetails.put("subject", subjectLine);