Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private static Cluster createCluster(String[] hosts, PoolingOptions poolingOptio
}

private static ConsistencyLevel getConsistencyLevel() {
String consistency = ProjectUtil.getConfigValue(Constants.SUNBIRD_CASSANDRA_CONSISTENCY_LEVEL);
String consistency = PropertiesCache.getInstance().readProperty(Constants.SUNBIRD_CASSANDRA_CONSISTENCY_LEVEL);

logger.info("CassandraConnectionManagerImpl:getConsistencyLevel: level = " + consistency);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package org.sunbird.common.model;

import java.io.Serializable;
import java.util.List;

public class SunbirdApiBatchResp {
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

@JsonIgnoreProperties(ignoreUnknown = true)
public class SunbirdApiBatchResp implements Serializable {
private List<String> createdFor;
private String endDate;
private String name;
Expand Down
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 @@ -467,6 +467,9 @@ public class CbExtServerProperties {
@Value("${assessment.ratake.count.verification.enabled}")
private boolean assessmentRetakeCountVerificationEnabled;

@Value("${bulk.upload.tag.verification.regex}")
private String bulkUploadTagVerificationRegex;

public String getAssessmentSubmitTopic() {
return assessmentSubmitTopic;
}
Expand Down Expand Up @@ -1705,4 +1708,12 @@ public boolean isAssessmentRetakeCountVerificationEnabled() {
public void setAssessmentRetakeCountVerificationEnabled(boolean assessmentRetakeCountVerificationEnabled) {
this.assessmentRetakeCountVerificationEnabled = assessmentRetakeCountVerificationEnabled;
}

public String getBulkUploadTagVerificationRegex() {
return bulkUploadTagVerificationRegex;
}

public void setBulkUploadTagVerificationRegex(String bulkUploadTagVerificationRegex) {
this.bulkUploadTagVerificationRegex = bulkUploadTagVerificationRegex;
}
}
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 @@ -681,13 +681,15 @@ public class Constants {
public static final String BULK_USER_UPDATE_API_FAILED = "Bulk User Update API Failed";
public static final String SECURE_SETTINGS = "secureSettings";
public static final String API_USER_ENROLMENT = "user.enrolment";
public static final String USER_REGISTRATION_GROUP_LIST = "api.user.registration.group.list";
public static final String SUBMIT_ASSESSMENT_RESPONSE_KEY = "submitAssessmentResponse";
public static final String API_READ_ASSESSMENT = "api.assessment.read";
public static final String API_READ_ASSESSMENT_RESULT = "api.assessment.read.result";
public static final String STATUS_IS_IN_PROGRESS = "isInProgress";
public static final String ASSESSMENT_SUBMIT_IN_PROGRESS = "SUBMIT_IN_PROGRESS";
public static final String ASSESSMENT_READ_RESPONSE_KEY = "assessmentReadResponse";
public static final String START_TIME_KEY = "startTime";
public static final String BULK_UPLOAD_VERIFICATION_REGEX = "bulk.upload.tag.verification.regex";

private Constants() {
throw new IllegalStateException("Utility class");
Expand Down
21 changes: 6 additions & 15 deletions src/main/java/org/sunbird/common/util/ProjectUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,7 @@
public class ProjectUtil {

public static CbExtLogger logger = new CbExtLogger(ProjectUtil.class.getName());

public static PropertiesCache propertiesCache;

static {
propertiesCache = PropertiesCache.getInstance();
}

public static String getConfigValue(String key) {
if (StringUtils.isNotBlank(System.getenv(key))) {
return System.getenv(key);
}
return propertiesCache.readProperty(key);
}
public static String DEFAULT_BULK_UPLOAD_VERIFICATION_REGEX = "^[a-zA-Z\\s,]+$";

/**
* This method will check incoming value is null or empty it will do empty check
Expand Down Expand Up @@ -119,7 +107,6 @@ public static String firstLetterCapitalWithSingleSpace(final String words) {
public static Boolean validateEmailPattern(String email) {
String emailRegex = "^[a-zA-Z0-9_+&*-]+(?:\\." + "[a-zA-Z0-9_+&*-]+)*@" + "(?:[a-zA-Z0-9-]+\\.)+[a-z"
+ "A-Z]{2,7}$";
Boolean retValue = Boolean.FALSE;
Pattern pat = Pattern.compile(emailRegex);
if (pat.matcher(email).matches()) {
return Boolean.TRUE;
Expand Down Expand Up @@ -148,8 +135,12 @@ public static Boolean validateFullName(String firstName ) {
}

public static Boolean validateTag(List<String> tags) {
String regEx = PropertiesCache.getInstance().getProperty(Constants.BULK_UPLOAD_VERIFICATION_REGEX);
if (StringUtils.isBlank(regEx)) {
regEx = DEFAULT_BULK_UPLOAD_VERIFICATION_REGEX;
}
for (String tag : tags) {
if (!tag.matches("^[a-zA-Z]+(?: [a-zA-Z]+)*$")) {
if (!tag.matches(regEx)) {
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,10 @@ public ResponseEntity<?> generateUserReport() {
public ResponseEntity<?> downloadFile(@PathVariable("fileName") String fileName) {
return profileService.downloadFile(fileName);
}

@GetMapping("/user/v1/groups")
public ResponseEntity<?> getGroupList() throws Exception {
SBApiResponse response = profileService.getGroupList();
return new ResponseEntity<>(response, response.getResponseCode());
}
}
2 changes: 2 additions & 0 deletions src/main/java/org/sunbird/profile/service/ProfileService.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ public interface ProfileService {
SBApiResponse getUserReport();

ResponseEntity<Resource> downloadFile(String fileName);

SBApiResponse getGroupList();
}
14 changes: 14 additions & 0 deletions src/main/java/org/sunbird/profile/service/ProfileServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1582,4 +1582,18 @@ public ResponseEntity<Resource> downloadFile(String fileName) {
}
}
}

@Override
public SBApiResponse getGroupList() {
SBApiResponse response = ProjectUtil.createDefaultResponse(Constants.USER_REGISTRATION_GROUP_LIST);
List<String> groupList = serverConfig.getBulkUploadGroupValue();
if (CollectionUtils.isNotEmpty(groupList)) {
response.getResult().put(Constants.COUNT, groupList.size());
response.getResult().put(Constants.RESPONSE, groupList);
} else {
response.setResponseCode(HttpStatus.INTERNAL_SERVER_ERROR);
response.getParams().setStatus(Constants.FAILED);
}
return response;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,10 @@ private void processBulkUpload(HashMap<String, String> inputDataMap) throws IOEx
String tagStr = nextRow.getCell(4).getStringCellValue().trim();
List<String> tagList = new ArrayList<String>();
if (!StringUtils.isEmpty(tagStr)) {
tagList = Arrays.asList(tagStr.split(",", -1));
String[] tagStrList = tagStr.split(",", -1);
for(String tag : tagStrList) {
tagList.add(tag.trim());
}
}
userRegistration.setTag(tagList);
if (!ProjectUtil.validateTag(userRegistration.getTag())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ private String validateRegisterationPayload(UserRegistrationInfo userRegInfo) {
if (StringUtils.isBlank(userRegInfo.getOrgName())) {
errList.add("OrgName");
}
if (StringUtils.isBlank(userRegInfo.getPosition())) {
errList.add("Position");
if (StringUtils.isBlank(userRegInfo.getGroup())) {
errList.add("group");
}
if (StringUtils.isBlank(userRegInfo.getSource())) {
errList.add("Source");
Expand All @@ -302,6 +302,11 @@ private String validateRegisterationPayload(UserRegistrationInfo userRegInfo) {
str.setLength(0);
str.append("Invalid phone number");
}
//group validation
if (StringUtils.isNotBlank(userRegInfo.getGroup()) && !serverProperties.getBulkUploadGroupValue().contains(userRegInfo.getGroup())) {
str.setLength(0);
str.append("Invalid Group : Group can be only among one of these ").append(serverProperties.getBulkUploadGroupValue());
}
return str.toString();
}

Expand Down Expand Up @@ -331,6 +336,7 @@ private UserRegistration getRegistrationObject(UserRegistrationInfo userRegInfo)
userRegistration.setOrganisationType(userRegInfo.getOrganisationType());
userRegistration.setOrganisationSubType(userRegInfo.getOrganisationSubType());
userRegistration.setPhone(userRegInfo.getPhone());
userRegistration.setGroup(userRegInfo.getGroup());

if (StringUtils.isBlank(userRegInfo.getRegistrationCode())) {
userRegistration.setRegistrationCode(serverProperties.getUserRegCodePrefix() + "-"
Expand Down