From ba6a54fbdea761971431d4b4fdc24b08d6bc5c7f Mon Sep 17 00:00:00 2001 From: Juhi Date: Mon, 29 May 2023 12:45:27 +0530 Subject: [PATCH 1/3] changes for group and external system --- .../common/util/CbExtServerProperties.java | 12 +++ .../org/sunbird/common/util/Constants.java | 4 + .../org/sunbird/common/util/ProjectUtil.java | 18 ++++ .../service/UserBulkUploadService.java | 83 +++++++++++++------ .../registration/model/UserRegistration.java | 3 + .../model/UserRegistrationInfo.java | 41 +++++++++ .../user/service/UserUtilityService.java | 4 + .../user/service/UserUtilityServiceImpl.java | 31 +++++++ src/main/resources/application.properties | 3 +- 9 files changed, 174 insertions(+), 25 deletions(-) diff --git a/src/main/java/org/sunbird/common/util/CbExtServerProperties.java b/src/main/java/org/sunbird/common/util/CbExtServerProperties.java index 7e2635a58..0f2da9cb1 100644 --- a/src/main/java/org/sunbird/common/util/CbExtServerProperties.java +++ b/src/main/java/org/sunbird/common/util/CbExtServerProperties.java @@ -443,6 +443,10 @@ public class CbExtServerProperties { @Value("${org.search.response.default.limit}") private Integer orgSearchResponseDefaultLimit; + @Value("${user.bulk.upload.group.value}") + private String bulkUploadGroupValue; + + public String getAssessmentSubmitTopic() { return assessmentSubmitTopic; } @@ -1617,4 +1621,12 @@ public Integer getOrgSearchResponseDefaultLimit() { public void setOrgSearchResponseDefaultLimit(Integer orgSearchResponseDefaultLimit) { this.orgSearchResponseDefaultLimit = orgSearchResponseDefaultLimit; } + + public List getBulkUploadGroupValue() { + return Arrays.asList(bulkUploadGroupValue.split(",", -1)); + } + + public void setBulkUploadGroupValue(String bulkUploadGroupValue) { + this.bulkUploadGroupValue = bulkUploadGroupValue; + } } \ No newline at end of file diff --git a/src/main/java/org/sunbird/common/util/Constants.java b/src/main/java/org/sunbird/common/util/Constants.java index 1e9e80ec8..6c5f64e81 100644 --- a/src/main/java/org/sunbird/common/util/Constants.java +++ b/src/main/java/org/sunbird/common/util/Constants.java @@ -676,6 +676,10 @@ public class Constants { public static final String SUCCESS_UPPERCASE = "SUCCESS"; public static final String EMPTY_FILE_FAILED = "The uploaded file is empty"; public static final String PARENT_TYPE = "parentType"; + public static final String TAG = "tag"; + public static final String EXTERNAL_SYSTEM_ID = "externalSystemId"; + public static final String EXTERNAL_SYSTEM = "externalSystem"; + public static final String GROUP = "group"; private Constants() { throw new IllegalStateException("Utility class"); } diff --git a/src/main/java/org/sunbird/common/util/ProjectUtil.java b/src/main/java/org/sunbird/common/util/ProjectUtil.java index 6396aab60..00fab57e4 100644 --- a/src/main/java/org/sunbird/common/util/ProjectUtil.java +++ b/src/main/java/org/sunbird/common/util/ProjectUtil.java @@ -1,6 +1,7 @@ package org.sunbird.common.util; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -149,4 +150,21 @@ public static Boolean validateFirstName( String firstName ) { public static Boolean validateLastName( String lastName ) { return lastName.matches( "[a-zA-Z]*" ); } + + public static Boolean validateTag(List tags) { + for (String tag : tags) { + if (!tag.matches("[a-zA-Z]*")) { + return false; + } + } + return true; + } + + public static Boolean validateExternalSystemId(String externalSystemId) { + return externalSystemId.matches("[a-zA-Z0-9]{0,30}$"); + } + + public static Boolean validateExternalSystem(String externalSystem) { + return externalSystem.matches("[a-zA-Z ]{0,255}$"); + } } \ No newline at end of file diff --git a/src/main/java/org/sunbird/profile/service/UserBulkUploadService.java b/src/main/java/org/sunbird/profile/service/UserBulkUploadService.java index db8f45ab1..53be572c9 100644 --- a/src/main/java/org/sunbird/profile/service/UserBulkUploadService.java +++ b/src/main/java/org/sunbird/profile/service/UserBulkUploadService.java @@ -117,11 +117,22 @@ private void processBulkUpload(HashMap inputDataMap) throws IOEx Iterator rowIterator = sheet.iterator(); // incrementing the iterator inorder to skip the headers in the first row if (rowIterator.hasNext()) { - rowIterator.next(); + Row firstRow = rowIterator.next(); + Cell statusCell = firstRow.getCell(7); + Cell errorDetails = firstRow.getCell(8); + if (statusCell == null) { + statusCell = firstRow.createCell(7); + } + if (errorDetails == null) { + errorDetails = firstRow.createCell(8); + } + statusCell.setCellValue("Status"); + errorDetails.setCellValue("Error Details"); } while (rowIterator.hasNext()) { StringBuffer str = new StringBuffer(); List errList = new ArrayList<>(); + List invalidErrList = new ArrayList<>(); Row nextRow = rowIterator.next(); UserRegistration userRegistration = new UserRegistration(); if (nextRow.getCell(0) == null || StringUtils.isBlank(nextRow.getCell(0).toString())) { @@ -129,7 +140,7 @@ private void processBulkUpload(HashMap inputDataMap) throws IOEx } else { userRegistration.setFirstName(nextRow.getCell(0).getStringCellValue()); if (!ProjectUtil.validateFirstName(userRegistration.getFirstName())) { - errList.add("Invalid First Name"); + invalidErrList.add("Invalid First Name"); } } if (nextRow.getCell(1) == null || StringUtils.isBlank(nextRow.getCell(1).toString())) { @@ -137,7 +148,7 @@ private void processBulkUpload(HashMap inputDataMap) throws IOEx } else { userRegistration.setLastName(nextRow.getCell(1).getStringCellValue()); if (!ProjectUtil.validateLastName(userRegistration.getLastName())) { - errList.add("Invalid Last Name"); + invalidErrList.add("Invalid Last Name"); } } if (nextRow.getCell(2) == null || StringUtils.isBlank(nextRow.getCell(2).toString())) { @@ -153,20 +164,51 @@ private void processBulkUpload(HashMap inputDataMap) throws IOEx userRegistration.setPhone(phone); } } + if (nextRow.getCell(4) == null || StringUtils.isBlank(nextRow.getCell(4).toString())) { + errList.add("Group"); + } else { + userRegistration.setGroup(nextRow.getCell(4).getStringCellValue()); + if (!userUtilityService.validateGroup(userRegistration.getGroup())) { + invalidErrList.add("Invalid Group"); + } + } + if (nextRow.getCell(5) != null && !StringUtils.isBlank(nextRow.getCell(5).toString())) { + String tagStr = nextRow.getCell(5).getStringCellValue(); + List tagList = new ArrayList(); + if (!StringUtils.isEmpty(tagStr)) { + tagList = Arrays.asList(tagStr.split(",", -1)); + } + userRegistration.setTag(tagList); + if (!ProjectUtil.validateTag(userRegistration.getTag())) { + invalidErrList.add("Invalid Tag"); + } + } + if (nextRow.getCell(6) != null && !StringUtils.isBlank(nextRow.getCell(6).toString())) { + userRegistration.setExternalSystemId(nextRow.getCell(6).getStringCellValue()); + if (!ProjectUtil.validateExternalSystemId(userRegistration.getExternalSystemId())) { + invalidErrList.add("Invalid External System ID"); + } + } + if (nextRow.getCell(7) != null && !StringUtils.isBlank(nextRow.getCell(7).toString())) { + userRegistration.setExternalSystem(nextRow.getCell(7).getStringCellValue()); + if (!ProjectUtil.validateExternalSystem(userRegistration.getExternalSystem())) { + invalidErrList.add("Invalid External System"); + } + } userRegistration.setOrgName(inputDataMap.get(Constants.ORG_NAME)); - Cell statusCell = nextRow.getCell(4); - Cell errorDetails = nextRow.getCell(5); + Cell statusCell = nextRow.getCell(8); + Cell errorDetails = nextRow.getCell(9); if (statusCell == null) { - statusCell = nextRow.createCell(4); + statusCell = nextRow.createCell(8); } if (errorDetails == null) { - errorDetails = nextRow.createCell(5); + errorDetails = nextRow.createCell(9); } - if (totalRecordsCount == 0 && errList.size() == 4) { + if (totalRecordsCount == 0 && errList.size() == 5) { setErrorDetails(str, errList, statusCell, errorDetails); failedRecordsCount++; break; - } else if (totalRecordsCount > 0 && errList.size() == 4) { + } else if (totalRecordsCount > 0 && errList.size() == 5) { break; } totalRecordsCount++; @@ -174,8 +216,8 @@ private void processBulkUpload(HashMap inputDataMap) throws IOEx setErrorDetails(str, errList, statusCell, errorDetails); failedRecordsCount++; } else { - errList = validateEmailContactAndDomain(userRegistration); - if (errList.isEmpty()) { + invalidErrList = validateEmailContactAndDomain(userRegistration); + if (invalidErrList.isEmpty()) { boolean isUserCreated = userUtilityService.createUser(userRegistration); if (isUserCreated) { noOfSuccessfulRecords++; @@ -189,14 +231,14 @@ private void processBulkUpload(HashMap inputDataMap) throws IOEx } else { failedRecordsCount++; statusCell.setCellValue(Constants.FAILED_UPPERCASE); - errorDetails.setCellValue(errList.toString()); + errorDetails.setCellValue(invalidErrList.toString()); } } } if (totalRecordsCount == 0) { XSSFRow row = sheet.createRow(sheet.getLastRowNum() + 1); - Cell statusCell = row.createCell(4); - Cell errorDetails = row.createCell(5); + Cell statusCell = row.createCell(8); + Cell errorDetails = row.createCell(9); statusCell.setCellValue(Constants.FAILED_UPPERCASE); errorDetails.setCellValue(Constants.EMPTY_FILE_FAILED); @@ -252,14 +294,10 @@ private List validateEmailContactAndDomain(UserRegistration userRegistra List errList = new ArrayList<>(); if (!ProjectUtil.validateEmailPattern(userRegistration.getEmail())) { errList.add("Invalid Email Id"); - } - else - { + } else { if (!userUtilityService.isDomainAccepted(userRegistration.getEmail())) { errList.add("Invalid Email Domain"); - } - else - { + } else { if (userUtilityService.isUserExist(Constants.EMAIL, userRegistration.getEmail())) { errList.add(Constants.EMAIL_EXIST_ERROR); } @@ -267,14 +305,11 @@ private List validateEmailContactAndDomain(UserRegistration userRegistra } if (!ProjectUtil.validateContactPattern(userRegistration.getPhone())) { errList.add("Invalid Mobile Number"); - } - else - { + } else { if (userUtilityService.isUserExist(Constants.PHONE, String.valueOf(userRegistration.getPhone()))) { errList.add(Constants.MOBILE_NUMBER_EXIST_ERROR); } } - if (!errList.isEmpty()) { str.append("Failed to Validate User Details. Error Details - [").append(errList).append("]"); } diff --git a/src/main/java/org/sunbird/user/registration/model/UserRegistration.java b/src/main/java/org/sunbird/user/registration/model/UserRegistration.java index 0ee0f8910..462d923c0 100644 --- a/src/main/java/org/sunbird/user/registration/model/UserRegistration.java +++ b/src/main/java/org/sunbird/user/registration/model/UserRegistration.java @@ -1,11 +1,14 @@ package org.sunbird.user.registration.model; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + /** * Model to store user registration details in ES server * * @author karthik * */ +@JsonIgnoreProperties(ignoreUnknown = true) public class UserRegistration extends UserRegistrationInfo { private String wfId; private String priviousStatus; diff --git a/src/main/java/org/sunbird/user/registration/model/UserRegistrationInfo.java b/src/main/java/org/sunbird/user/registration/model/UserRegistrationInfo.java index 16e26826b..181dadca8 100644 --- a/src/main/java/org/sunbird/user/registration/model/UserRegistrationInfo.java +++ b/src/main/java/org/sunbird/user/registration/model/UserRegistrationInfo.java @@ -1,11 +1,16 @@ package org.sunbird.user.registration.model; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +import java.util.List; + /** * Model object to store user registration details. * * @author karthik * */ +@JsonIgnoreProperties(ignoreUnknown = true) public class UserRegistrationInfo { private String registrationCode; private String firstName; @@ -21,6 +26,10 @@ public class UserRegistrationInfo { private String sbRootOrgId; private String sbOrgId; private String phone; + private String group; + private List tag; + private String externalSystemId; + private String externalSystem; public String getRegistrationCode() { return registrationCode; @@ -133,4 +142,36 @@ public String getPhone() { public void setPhone(String phone) { this.phone = phone; } + + public String getGroup() { + return group; + } + + public void setGroup(String group) { + this.group = group; + } + + public List getTag() { + return tag; + } + + public void setTag(List tag) { + this.tag = tag; + } + + public String getExternalSystemId() { + return externalSystemId; + } + + public void setExternalSystemId(String externalSystemId) { + this.externalSystemId = externalSystemId; + } + + public String getExternalSystem() { + return externalSystem; + } + + public void setExternalSystem(String externalSystem) { + this.externalSystem = externalSystem; + } } diff --git a/src/main/java/org/sunbird/user/service/UserUtilityService.java b/src/main/java/org/sunbird/user/service/UserUtilityService.java index 058471c27..73e1c5c61 100644 --- a/src/main/java/org/sunbird/user/service/UserUtilityService.java +++ b/src/main/java/org/sunbird/user/service/UserUtilityService.java @@ -40,4 +40,8 @@ public void getUserDetailsFromDB(List userIds, List fields, boolean isUserExist(String key, String value); Boolean isDomainAccepted(String email); + + boolean validatePosition(String position); + + boolean validateGroup(String group); } \ No newline at end of file diff --git a/src/main/java/org/sunbird/user/service/UserUtilityServiceImpl.java b/src/main/java/org/sunbird/user/service/UserUtilityServiceImpl.java index 6fb6fffab..9374d4fc5 100644 --- a/src/main/java/org/sunbird/user/service/UserUtilityServiceImpl.java +++ b/src/main/java/org/sunbird/user/service/UserUtilityServiceImpl.java @@ -271,10 +271,24 @@ public boolean updateUser(UserRegistration userRegistration) { if (StringUtils.isNotEmpty(userRegistration.getPosition())) { professionDetailObj.put(Constants.DESIGNATION, userRegistration.getPosition()); } + if (!StringUtils.isEmpty(userRegistration.getGroup())) { + professionDetailObj.put(Constants.GROUP, userRegistration.getGroup()); + } List> professionalDetailsList = new ArrayList>(); professionalDetailsList.add(professionDetailObj); profileDetails.put(Constants.PROFESSIONAL_DETAILS, professionalDetailsList); + Map additionalProperties = new HashMap(); + if (!CollectionUtils.isEmpty(userRegistration.getTag())) { + additionalProperties.put(Constants.TAG, userRegistration.getTag()); + } + if (!StringUtils.isEmpty(userRegistration.getExternalSystemId())) { + additionalProperties.put(Constants.EXTERNAL_SYSTEM_ID, userRegistration.getExternalSystemId()); + } + if (!StringUtils.isEmpty(userRegistration.getExternalSystem())) { + additionalProperties.put(Constants.EXTERNAL_SYSTEM, userRegistration.getExternalSystem()); + } + profileDetails.put(Constants.ADDITIONAL_PROPERTIES, additionalProperties); requestBody.put(Constants.PROFILE_DETAILS, profileDetails); request.put(Constants.REQUEST, requestBody); Map readData = (Map) outboundRequestHandlerService.fetchResultUsingPatch( @@ -551,5 +565,22 @@ public Boolean isDomainAccepted(String email) { String emailDomain = email.split("@")[1]; return props.getUserRegistrationDomain().contains(emailDomain); } + + @Override + public boolean validatePosition(String position) { + Map propertyMap = new HashMap<>(); + propertyMap.put(Constants.CONTEXT_TYPE, Constants.POSITION); + propertyMap.put(Constants.CONTEXT_NAME, position); + List> positionsList = cassandraOperation + .getRecordsByProperties(Constants.KEYSPACE_SUNBIRD, Constants.TABLE_MASTER_DATA, propertyMap, null); + return positionsList.size() > 0; + } + + @Override + public boolean validateGroup(String group) { + return (!CollectionUtils.isEmpty(serverConfig.getBulkUploadGroupValue())) ? serverConfig.getBulkUploadGroupValue().stream().anyMatch(group::equalsIgnoreCase) : false; + } + + } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 50ca87596..3134b21f3 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -282,4 +282,5 @@ kafka.topics.user.bulk.upload=user.bulk.upload.final kafka.topics.user.bulk.upload.group=userBulkUpload org.channel.delimitter=_ -org.search.response.default.limit=100 \ No newline at end of file +org.search.response.default.limit=100 +user.bulk.upload.group.value=GROUP A,GROUP B,GROUP C,GROUP D,Contractual Staff,Others \ No newline at end of file From 1334a6bc42ea39371718a4e7204a801c8620d07e Mon Sep 17 00:00:00 2001 From: Juhi Date: Mon, 29 May 2023 13:56:10 +0530 Subject: [PATCH 2/3] changes for group and external system --- .../org/sunbird/user/service/UserUtilityService.java | 2 -- .../sunbird/user/service/UserUtilityServiceImpl.java | 10 ---------- 2 files changed, 12 deletions(-) diff --git a/src/main/java/org/sunbird/user/service/UserUtilityService.java b/src/main/java/org/sunbird/user/service/UserUtilityService.java index 73e1c5c61..0760eabef 100644 --- a/src/main/java/org/sunbird/user/service/UserUtilityService.java +++ b/src/main/java/org/sunbird/user/service/UserUtilityService.java @@ -41,7 +41,5 @@ public void getUserDetailsFromDB(List userIds, List fields, Boolean isDomainAccepted(String email); - boolean validatePosition(String position); - boolean validateGroup(String group); } \ No newline at end of file diff --git a/src/main/java/org/sunbird/user/service/UserUtilityServiceImpl.java b/src/main/java/org/sunbird/user/service/UserUtilityServiceImpl.java index 9374d4fc5..1fa644a1b 100644 --- a/src/main/java/org/sunbird/user/service/UserUtilityServiceImpl.java +++ b/src/main/java/org/sunbird/user/service/UserUtilityServiceImpl.java @@ -566,16 +566,6 @@ public Boolean isDomainAccepted(String email) { return props.getUserRegistrationDomain().contains(emailDomain); } - @Override - public boolean validatePosition(String position) { - Map propertyMap = new HashMap<>(); - propertyMap.put(Constants.CONTEXT_TYPE, Constants.POSITION); - propertyMap.put(Constants.CONTEXT_NAME, position); - List> positionsList = cassandraOperation - .getRecordsByProperties(Constants.KEYSPACE_SUNBIRD, Constants.TABLE_MASTER_DATA, propertyMap, null); - return positionsList.size() > 0; - } - @Override public boolean validateGroup(String group) { return (!CollectionUtils.isEmpty(serverConfig.getBulkUploadGroupValue())) ? serverConfig.getBulkUploadGroupValue().stream().anyMatch(group::equalsIgnoreCase) : false; From ccb9db963693da63b810f1b6d36056c1a0e7c721 Mon Sep 17 00:00:00 2001 From: Juhi Date: Mon, 29 May 2023 15:55:18 +0530 Subject: [PATCH 3/3] changes for group and external system --- .../sunbird/profile/service/UserBulkUploadService.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/sunbird/profile/service/UserBulkUploadService.java b/src/main/java/org/sunbird/profile/service/UserBulkUploadService.java index 53be572c9..cd1282d4a 100644 --- a/src/main/java/org/sunbird/profile/service/UserBulkUploadService.java +++ b/src/main/java/org/sunbird/profile/service/UserBulkUploadService.java @@ -118,13 +118,13 @@ private void processBulkUpload(HashMap inputDataMap) throws IOEx // incrementing the iterator inorder to skip the headers in the first row if (rowIterator.hasNext()) { Row firstRow = rowIterator.next(); - Cell statusCell = firstRow.getCell(7); - Cell errorDetails = firstRow.getCell(8); + Cell statusCell = firstRow.getCell(8); + Cell errorDetails = firstRow.getCell(9); if (statusCell == null) { - statusCell = firstRow.createCell(7); + statusCell = firstRow.createCell(8); } if (errorDetails == null) { - errorDetails = firstRow.createCell(8); + errorDetails = firstRow.createCell(9); } statusCell.setCellValue("Status"); errorDetails.setCellValue("Error Details");