Skip to content

Commit

Permalink
4.8.14 dev v2 (#560)
Browse files Browse the repository at this point in the history
* changes added for user create (#555)

* User Create Filed mapping change

* update the filed values

* update the property field

* Doing the mapping update (#559)
  • Loading branch information
Sahil-tarento authored May 16, 2024
1 parent 1fb43d7 commit b5ab25d
Show file tree
Hide file tree
Showing 6 changed files with 204 additions and 31 deletions.
11 changes: 11 additions & 0 deletions src/main/java/org/sunbird/common/util/CbExtServerProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,9 @@ public void setRedisWheeboxKey(String redisWheeboxKey) {
@Value("#{${organisation.insights.redis.key.mapping}}")
private Map<String, String> organisationInsightRedisKeyMapping;

@Value("${bulk.upload.allowed.roles.creation}")
private String bulkUploadAllowedRolesCreation;

public boolean qListFromCacheEnabled() {
return qListFromCacheEnabled;
}
Expand Down Expand Up @@ -2652,4 +2655,12 @@ public Map<String, String> getOrganisationInsightRedisKeyMapping() {
public void setOrganisationInsightRedisKeyMapping(Map<String, String> organisationInsightRedisKeyMapping) {
this.organisationInsightRedisKeyMapping = organisationInsightRedisKeyMapping;
}

public List<String> getBulkUploadAllowedRolesCreation() {
return Arrays.asList(bulkUploadAllowedRolesCreation.split(",", -1));
}

public void setBulkUploadAllowedRolesCreation(String bulkUploadAllowedRolesCreation) {
this.bulkUploadAllowedRolesCreation = bulkUploadAllowedRolesCreation;
}
}
3 changes: 3 additions & 0 deletions src/main/java/org/sunbird/common/util/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,9 @@ public class Constants {
public static final String TOTAL_COUNT = "totalCount";
public static final String MICROSITE_TOP_CONTENT_API = "api.microsite.top.content";
public static final String ICON = "icon";
public static final String DOMICILE_MEDIUM = "domicileMedium";
public static final String PINCODE = "pinCode";
public static final String EMPLOYEE_CODE = "employeeCode";

private Constants() {
throw new IllegalStateException("Utility class");
Expand Down
131 changes: 102 additions & 29 deletions src/main/java/org/sunbird/profile/service/UserBulkUploadService.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@ private void processBulkUpload(HashMap<String, String> 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(15);
Cell errorDetails = firstRow.getCell(16);
if (statusCell == null) {
statusCell = firstRow.createCell(7);
statusCell = firstRow.createCell(15);
}
if (errorDetails == null) {
errorDetails = firstRow.createCell(8);
errorDetails = firstRow.createCell(16);
}
statusCell.setCellValue("Status");
errorDetails.setCellValue("Error Details");
Expand Down Expand Up @@ -183,59 +183,132 @@ private void processBulkUpload(HashMap<String, String> inputDataMap) throws IOEx
invalidErrList.add("Invalid column type. Expecting string format");
}
}
if (nextRow.getCell(4) != null && nextRow.getCell(4).getCellType() != CellType.BLANK) {
if (nextRow.getCell(4) == null || nextRow.getCell(4).getCellType() == CellType.BLANK) {
errList.add("Designation");
} else {
if (nextRow.getCell(4).getCellType() == CellType.STRING) {
String tagStr = nextRow.getCell(4).getStringCellValue().trim();
List<String> tagList = new ArrayList<String>();
if (!StringUtils.isEmpty(tagStr)) {
String[] tagStrList = tagStr.split(",", -1);
for(String tag : tagStrList) {
tagList.add(tag.trim());
}
}
userRegistration.setTag(tagList);
if (!ProjectUtil.validateTag(userRegistration.getTag())) {
invalidErrList.add("Invalid Tag : Tags are comma seperated string values. A Tag can contain only alphabets with spaces. eg: Bihar Circle, Patna Division");
}
userRegistration.setPosition(nextRow.getCell(4).getStringCellValue().trim());
} else {
invalidErrList.add("Invalid column type. Expecting string format");
}
}
if (nextRow.getCell(5) != null && nextRow.getCell(5).getCellType() != CellType.BLANK) {
if (nextRow.getCell(5).getCellType() == CellType.NUMERIC) {
userRegistration.setExternalSystemId(NumberToTextConverter.toText(nextRow.getCell(5).getNumericCellValue()).trim());
userRegistration.setEmployeeId(NumberToTextConverter.toText(nextRow.getCell(5).getNumericCellValue()).trim());
} else if (nextRow.getCell(5).getCellType() == CellType.STRING) {
userRegistration.setEmployeeId(nextRow.getCell(5).getStringCellValue().trim());
} else {
invalidErrList.add("Invalid column type. Expecting string/number format");
}
}
if (nextRow.getCell(6) != null && nextRow.getCell(6).getCellType() != CellType.BLANK) {
if (nextRow.getCell(6).getCellType() == CellType.STRING) {
userRegistration.setGender(nextRow.getCell(6).getStringCellValue().trim());
} else {
invalidErrList.add("Invalid column type. Expecting string format");
}
}
if (nextRow.getCell(7) != null && nextRow.getCell(7).getCellType() != CellType.BLANK) {
if (nextRow.getCell(7).getCellType() == CellType.STRING) {
userRegistration.setDob(nextRow.getCell(7).getStringCellValue().trim());
} else {
invalidErrList.add("Invalid column type. Expecting string format");
}
}
if (nextRow.getCell(8) != null && nextRow.getCell(8).getCellType() != CellType.BLANK) {
if (nextRow.getCell(8).getCellType() == CellType.STRING) {
userRegistration.setDomicileMedium(nextRow.getCell(8).getStringCellValue().trim());
} else {
invalidErrList.add("Invalid column type. Expecting string format");
}
}
if (nextRow.getCell(9) != null && nextRow.getCell(9).getCellType() != CellType.BLANK) {
if (nextRow.getCell(9).getCellType() == CellType.STRING) {
userRegistration.setCategory(nextRow.getCell(9).getStringCellValue().trim());
} else {
invalidErrList.add("Invalid column type. Expecting string format");
}
}
if (nextRow.getCell(10) != null && nextRow.getCell(10).getCellType() != CellType.BLANK) {
if (nextRow.getCell(10).getCellType() == CellType.NUMERIC) {
userRegistration.setPincode(NumberToTextConverter.toText(nextRow.getCell(10).getNumericCellValue()));
} else if (nextRow.getCell(10).getCellType() == CellType.STRING) {
userRegistration.setPincode(nextRow.getCell(10).getStringCellValue().trim());
} else {
invalidErrList.add("Invalid column type. Expecting number/string format");
}
}
if (nextRow.getCell(11) != null && nextRow.getCell(11).getCellType() != CellType.BLANK) {
if (nextRow.getCell(11).getCellType() == CellType.NUMERIC) {
userRegistration.setExternalSystemId(NumberToTextConverter.toText(nextRow.getCell(11).getNumericCellValue()).trim());
if (!ProjectUtil.validateExternalSystemId(userRegistration.getExternalSystemId())) {
invalidErrList.add("Invalid External System ID : External System Id can contain alphanumeric characters and have a max length of 30");
}
} else if (nextRow.getCell(5).getCellType() == CellType.STRING) {
userRegistration.setExternalSystemId(nextRow.getCell(5).getStringCellValue().trim());
} else if (nextRow.getCell(11).getCellType() == CellType.STRING) {
userRegistration.setExternalSystemId(nextRow.getCell(11).getStringCellValue().trim());
if (!ProjectUtil.validateExternalSystemId(userRegistration.getExternalSystemId())) {
invalidErrList.add("Invalid External System ID : External System Id can contain alphanumeric characters and have a max length of 30");
}
} else {
invalidErrList.add("Invalid column type. Expecting string/number format");
}
}
if (nextRow.getCell(6) != null && !StringUtils.isBlank(nextRow.getCell(6).toString())) {
if (nextRow.getCell(6).getCellType() == CellType.STRING) {
userRegistration.setExternalSystem(nextRow.getCell(6).getStringCellValue().trim());
if (nextRow.getCell(12) != null && !StringUtils.isBlank(nextRow.getCell(12).toString())) {
if (nextRow.getCell(12).getCellType() == CellType.STRING) {
userRegistration.setExternalSystem(nextRow.getCell(12).getStringCellValue().trim());
if (!ProjectUtil.validateExternalSystem(userRegistration.getExternalSystem())) {
invalidErrList.add("Invalid External System : External System can contain only alphabets and can have a max length of 255");
}
} else {
invalidErrList.add("Invalid column type. Expecting string format");
}
}
if (nextRow.getCell(13) != null && nextRow.getCell(13).getCellType() != CellType.BLANK) {
if (nextRow.getCell(13).getCellType() == CellType.STRING) {
String tagStr = nextRow.getCell(13).getStringCellValue().trim();
List<String> tagList = new ArrayList<String>();
if (!StringUtils.isEmpty(tagStr)) {
String[] tagStrList = tagStr.split(",", -1);
for(String tag : tagStrList) {
tagList.add(tag.trim());
}
}
userRegistration.setTag(tagList);
if (!ProjectUtil.validateTag(userRegistration.getTag())) {
invalidErrList.add("Invalid Tag : Tags are comma seperated string values. A Tag can contain only alphabets with spaces. eg: Bihar Circle, Patna Division");
}
} else {
invalidErrList.add("Invalid column type. Expecting string format");
}
}
if (nextRow.getCell(14) != null && nextRow.getCell(14).getCellType() != CellType.BLANK) {
if (nextRow.getCell(14).getCellType() == CellType.STRING) {
String rolesStr = nextRow.getCell(14).getStringCellValue().trim();
List<String> rolesList = new ArrayList<String>();
if (!StringUtils.isEmpty(rolesStr)) {
String[] rolesStrList = rolesStr.split(",", -1);
for (String role : rolesStrList) {
rolesList.add(role.trim());
if (!serverProperties.getBulkUploadAllowedRolesCreation().contains(role.trim())) {
invalidErrList.add("Invalid userRoles, allowed Roles are: " + serverProperties.getBulkUploadAllowedRolesCreation());
}
}
}
userRegistration.setRoles(rolesList);
} else {
invalidErrList.add("Invalid column type. Expecting string format");
}
}
userRegistration.setOrgName(inputDataMap.get(Constants.ORG_NAME));
userRegistration.setChannel(inputDataMap.get(Constants.ORG_NAME));
userRegistration.setSbOrgId(inputDataMap.get(Constants.ROOT_ORG_ID));
Cell statusCell = nextRow.getCell(7);
Cell errorDetails = nextRow.getCell(8);
Cell statusCell = nextRow.getCell(15);
Cell errorDetails = nextRow.getCell(16);
if (statusCell == null) {
statusCell = nextRow.createCell(7);
statusCell = nextRow.createCell(15);
}
if (errorDetails == null) {
errorDetails = nextRow.createCell(8);
errorDetails = nextRow.createCell(16);
}
if (totalRecordsCount == 0 && errList.size() == 4) {
setErrorDetails(str, errList, statusCell, errorDetails);
Expand Down Expand Up @@ -274,8 +347,8 @@ private void processBulkUpload(HashMap<String, String> inputDataMap) throws IOEx
}
if (totalRecordsCount == 0) {
XSSFRow row = sheet.createRow(sheet.getLastRowNum() + 1);
Cell statusCell = row.createCell(7);
Cell errorDetails = row.createCell(8);
Cell statusCell = row.createCell(15);
Cell errorDetails = row.createCell(16);
statusCell.setCellValue(Constants.FAILED_UPPERCASE);
errorDetails.setCellValue(Constants.EMPTY_FILE_FAILED);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ public class UserRegistrationInfo {
private List<String> tag;
private String externalSystemId;
private String externalSystem;
private String employeeId;
private String gender;
private String dob;
private String domicileMedium;
private String category;
private String pincode;
private List<String> roles;

public String getRegistrationCode() {
return registrationCode;
Expand Down Expand Up @@ -177,4 +184,60 @@ public String getGroup() {
public void setGroup(String group) {
this.group = group;
}

public String getEmployeeId() {
return employeeId;
}

public void setEmployeeId(String employeeId) {
this.employeeId = employeeId;
}

public String getGender() {
return gender;
}

public void setGender(String gender) {
this.gender = gender;
}

public String getDob() {
return dob;
}

public void setDob(String dob) {
this.dob = dob;
}

public String getDomicileMedium() {
return domicileMedium;
}

public void setDomicileMedium(String domicileMedium) {
this.domicileMedium = domicileMedium;
}

public String getCategory() {
return category;
}

public void setCategory(String category) {
this.category = category;
}

public String getPincode() {
return pincode;
}

public void setPincode(String pincode) {
this.pincode = pincode;
}

public List<String> getRoles() {
return roles;
}

public void setRoles(List<String> roles) {
this.roles = roles;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,11 @@ public String createBulkUploadUser(UserRegistration userRegistration) {
requestBody.put(Constants.EMAIL_VERIFIED, true);
requestBody.put(Constants.PHONE, userRegistration.getPhone());
requestBody.put(Constants.PHONE_VERIFIED, true);
requestBody.put(Constants.ROLES, Arrays.asList(Constants.PUBLIC));
if (CollectionUtils.isEmpty(userRegistration.getRoles())) {
requestBody.put(Constants.ROLES, Arrays.asList(Constants.PUBLIC));
} else {
requestBody.put(Constants.ROLES, userRegistration.getRoles());
}
request.put(Constants.REQUEST, requestBody);
Map<String, String> headerValues = ProjectUtil.getDefaultHeaders();
if (StringUtils.isNotEmpty(userRegistration.getUserAuthToken())) {
Expand Down Expand Up @@ -622,12 +626,30 @@ public String updateBulkUploadUser(UserRegistration userRegistration) {
profileDetails.put(Constants.MANDATORY_FIELDS_EXISTS, false);
Map<String, Object> employementDetails = new HashMap<String, Object>();
employementDetails.put(Constants.DEPARTMENTNAME, userRegistration.getOrgName());
if (StringUtils.isNotEmpty(userRegistration.getEmployeeId())) {
employementDetails.put(Constants.EMPLOYEE_CODE, userRegistration.getEmployeeId());
}
profileDetails.put(Constants.EMPLOYMENTDETAILS, employementDetails);
Map<String, Object> personalDetails = new HashMap<String, Object>();
personalDetails.put(Constants.FIRSTNAME.toLowerCase(), userRegistration.getFirstName());
personalDetails.put(Constants.PRIMARY_EMAIL, userRegistration.getEmail());
personalDetails.put(Constants.MOBILE, userRegistration.getPhone());
personalDetails.put(Constants.PHONE_VERIFIED, true);
if (StringUtils.isNotEmpty(userRegistration.getDob())) {
personalDetails.put(Constants.DOB, userRegistration.getDob());
}
if (StringUtils.isNotEmpty(userRegistration.getCategory())) {
personalDetails.put(Constants.CATEGORY, userRegistration.getCategory());
}
if (StringUtils.isNotEmpty(userRegistration.getDomicileMedium())) {
personalDetails.put(Constants.DOMICILE_MEDIUM, userRegistration.getDomicileMedium());
}
if (StringUtils.isNotEmpty(userRegistration.getPincode())) {
personalDetails.put(Constants.PINCODE, userRegistration.getPincode());
}
if (StringUtils.isNotEmpty(userRegistration.getGender())) {
personalDetails.put(Constants.GENDER, userRegistration.getGender());
}
profileDetails.put(Constants.PERSONAL_DETAILS, personalDetails);
Map<String, Object> professionDetailObj = new HashMap<String, Object>();
professionDetailObj.put(Constants.ORGANIZATION_TYPE, Constants.GOVERNMENT);
Expand Down
Loading

0 comments on commit b5ab25d

Please sign in to comment.