Skip to content

Commit

Permalink
Added master org list retrieval for user registration
Browse files Browse the repository at this point in the history
  • Loading branch information
karthik-tarento committed Jun 7, 2022
1 parent de947d5 commit 0f10f3f
Show file tree
Hide file tree
Showing 6 changed files with 807 additions and 12 deletions.
53 changes: 43 additions & 10 deletions src/main/java/org/sunbird/common/util/CbExtServerProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class CbExtServerProperties {

@Value("${sb.service.user.create.path}")
private String lmsUserCreatePath;

@Value("${sunbird.user.search.endpoint}")
private String userSearchEndPoint;

Expand Down Expand Up @@ -239,7 +239,7 @@ public class CbExtServerProperties {

@Value("${kafka.topics.user.registration.register.event}")
private String userRegistrationTopic;

@Value("${kafka.topics.user.registration.auto.createUser}")
private String userRegistrationAutoCreateUserTopic;

Expand Down Expand Up @@ -275,28 +275,37 @@ public class CbExtServerProperties {

@Value("${user.registeration.route.button.name}")
private String userRegisterationButtonName;

@Value("${user.registration.domain.name}")
private String userRegistrationDomainName;

@Value("${user.registration.preApproved.domain}")
private String userRegistrationPreApprovedDomainList;

@Value("${sb.discussion.hub.host}")
private String discussionHubHost;

@Value("${sb.node.bb.user.create.path}")
private String discussionHubCreateUserPath;

@Value("${sb.service.reset.password.path}")
private String sbResetPasswordPath;

@Value("${sb.service.send.notify.email.path}")
private String sbSendNotificationEmailPath;

@Value("${sb.service.assign.role.path}")
private String sbAssignRolePath;


@Value("${user.registration.dept.master.list.file}")
private String masterOrgListFileName;

@Value("${user.registration.custodian.orgId}")
private String custodianOrgId;

@Value("${user.registration.custodian.orgName}")
private String custodianOrgName;

public String getUserAssessmentSubmissionDuration() {
return userAssessmentSubmissionDuration;
}
Expand Down Expand Up @@ -931,7 +940,7 @@ public String getUserRegistrationTopic() {
public void setUserRegistrationTopic(String userRegistrationTopic) {
this.userRegistrationTopic = userRegistrationTopic;
}

public String getUserRegistrationAutoCreateUserTopic() {
return userRegistrationAutoCreateUserTopic;
}
Expand Down Expand Up @@ -1083,4 +1092,28 @@ public String getSbAssignRolePath() {
public void setSbAssignRolePath(String sbAssignRolePath) {
this.sbAssignRolePath = sbAssignRolePath;
}

public String getMasterOrgListFileName() {
return masterOrgListFileName;
}

public void setMasterOrgListFileName(String masterOrgListFileName) {
this.masterOrgListFileName = masterOrgListFileName;
}

public String getCustodianOrgId() {
return custodianOrgId;
}

public void setCustodianOrgId(String custodianOrgId) {
this.custodianOrgId = custodianOrgId;
}

public String getCustodianOrgName() {
return custodianOrgName;
}

public void setCustodianOrgName(String custodianOrgName) {
this.custodianOrgName = custodianOrgName;
}
}
2 changes: 2 additions & 0 deletions src/main/java/org/sunbird/common/util/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,8 @@ public class Constants {
public static final String ORGANIZATION_ID = "organisationId";
public static final String ROLES = "roles";
public static final String PUBLIC = "PUBLIC";
public static final String ASC_ORDER = "asc";
public static final String SORT_BY = "sort_by";

private Constants() {
throw new IllegalStateException("Utility class");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class UserRegistration extends UserRegistrationInfo {
private String updatedBy;
private String userId;
private String userName;
private String proposedDeptName;

public String getWfId() {
return wfId;
Expand Down Expand Up @@ -89,6 +90,14 @@ public void setUserName(String userName) {
this.userName = userName;
}

public String getProposedDeptName() {
return proposedDeptName;
}

public void setProposedDeptName(String proposedDeptName) {
this.proposedDeptName = proposedDeptName;
}

public String toMininumString() {
StringBuilder strBuilder = new StringBuilder("[ UserRegistrationCode : ");
strBuilder.append(this.getRegistrationCode()).append(", UserId : ").append(this.getUserId()).append("]");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package org.sunbird.user.registration.service;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;

import org.apache.commons.lang.RandomStringUtils;
Expand Down Expand Up @@ -153,6 +158,7 @@ public SBApiResponse getDeptDetails() {
SBApiResponse response = createDefaultResponse(Constants.USER_REGISTRATION_DEPT_INFO_API);

try {
Set<String> orgNameList = new HashSet<String>();
List<DeptPublicInfo> orgList = new ArrayList<>();
int count = 0;
int iterateCount = 0;
Expand All @@ -163,6 +169,9 @@ public SBApiResponse getDeptDetails() {
requestMap.put(Constants.LIMIT, 1000);
requestMap.put(Constants.FIELDS,
new ArrayList<>(Arrays.asList(Constants.CHANNEL, Constants.IDENTIFIER)));
Map<String, Object> sortByMap = new HashMap<String, Object>();
sortByMap.put(Constants.CHANNEL, Constants.ASC_ORDER);
requestMap.put(Constants.SORT_BY, sortByMap);
requestMap.put(Constants.FILTERS, new HashMap<String, Object>() {
{
put(Constants.IS_TENANT, Boolean.TRUE);
Expand All @@ -184,6 +193,14 @@ public SBApiResponse getDeptDetails() {
for (SunbirdApiRespContent content : resultResp.getContent()) {
if (!excludeList.isEmpty() && !excludeList.contains(content.getIdentifier())) {
orgList.add(new DeptPublicInfo(content.getIdentifier(), content.getChannel()));
orgNameList.add(content.getChannel());
}
}

List<String> masterOrgList = getMasterOrgList();
for (String orgName : masterOrgList) {
if (!orgNameList.contains(orgName)) {
orgList.add(new DeptPublicInfo(serverProperties.getCustodianOrgId(), orgName));
}
}
} while (count != iterateCount);
Expand Down Expand Up @@ -302,16 +319,22 @@ private UserRegistration getRegistrationObject(UserRegistrationInfo userRegInfo)
userRegistration.setDeptName(userRegInfo.getDeptName());
userRegistration.setPosition(userRegInfo.getPosition());
userRegistration.setSource(userRegInfo.getSource());

if (userRegInfo.getDeptId().equalsIgnoreCase(serverProperties.getCustodianOrgId())) {
userRegistration.setProposedDeptName(userRegInfo.getDeptName());
userRegistration.setDeptName(serverProperties.getCustodianOrgName());
}

if (StringUtils.isBlank(userRegInfo.getRegistrationCode())) {
userRegistration.setRegistrationCode(serverProperties.getUserRegCodePrefix() + "-"
+ userRegInfo.getDeptName() + "-" + RandomStringUtils.random(8, Boolean.TRUE, Boolean.TRUE));
+ userRegistration.getDeptName() + "-" + RandomStringUtils.random(8, Boolean.TRUE, Boolean.TRUE));
userRegistration.setCreatedOn(new Date().getTime());
} else {
userRegistration.setUpdatedOn(new Date().getTime());
}
userRegistration.setStatus(UserRegistrationStatus.CREATED.name());



return userRegistration;
}

Expand Down Expand Up @@ -400,4 +423,22 @@ private UserRegistration getUserRegistrationForRegCode(String registrationCode)
}
return null;
}

private List<String> getMasterOrgList() {
List<String> orgList = new ArrayList<String>();
// read file into stream, try-with-resources

InputStream in = this.getClass().getClassLoader()
.getResourceAsStream(serverProperties.getMasterOrgListFileName());
try (BufferedReader br = new BufferedReader(new InputStreamReader(in))) {
String line;
while ((line = br.readLine()) != null) {
orgList.add(line.trim());
}
} catch (Exception e) {
LOGGER.error("Failed to read the master org list. Exception: ", e);
}

return orgList;
}
}
Loading

0 comments on commit 0f10f3f

Please sign in to comment.