Skip to content

Commit

Permalink
Dev 4.8.4 (#61)
Browse files Browse the repository at this point in the history
Enhancements w.r.t. Blended program feature
  • Loading branch information
karthik-tarento authored Jul 7, 2023
1 parent cde4bd4 commit c4e551f
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ public abstract class CourseJsonKey {
"sunbird_send_email_notifictaion_api";
public static final String NOTIFY_TEMPLATE="notifyTemplate";
public static final String CERT_TEMPLATES = "certTemplates";
public static final String ADDITIONAL_PROPS = "additionalProps";
public static final String ADDITIONAL_PROPS = "additionalProps";
public static final String BATCH_ATTRIBUTES = "batchAttributes";
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,22 @@ public static String contentCall(String baseURL, String apiURL, String authKey,
"BaseMetricsActor:makePostRequest: Response from analytics store for metrics", null, new HashMap<>(){{put("result", result);}});
return result;
}

public static Map<String, Object> getContent(String courseId, List<String> fields) {
return getContent(courseId, fields, new HashMap<String, String>());
}

public static Map<String, Object> getContent(String courseId, List<String> fields, Map<String, String> incomingHeaders) {
Map<String, Object> resMap = new HashMap<>();
Map<String, String> headers = new HashMap<>();
try {
String fieldsStr = StringUtils.join(fields, ",");
String baseContentreadUrl = ProjectUtil.getConfigValue(JsonKey.EKSTEP_BASE_URL) + "/content/v3/read/" + courseId + "?fields=" + fieldsStr;
headers.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
headers.put(JsonKey.AUTHORIZATION, PropertiesCache.getInstance().getProperty(JsonKey.EKSTEP_AUTHORIZATION));
if (incomingHeaders.containsKey(JsonKey.X_AUTH_USER_ORG_ID)) {
headers.put(JsonKey.X_AUTH_USER_ORG_ID, incomingHeaders.get(JsonKey.X_AUTH_USER_ORG_ID));
}

logger.info(null, "making call for content read ==" + courseId);
String response = HttpUtil.sendGetRequest(baseContentreadUrl, headers);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class CourseBatch implements Serializable {
private Integer status;

private Map<String, Object> certTemplates;
private Map<String, Object> batchAttributes;

public String getCourseCreator() {
return courseCreator;
Expand Down Expand Up @@ -213,4 +214,13 @@ public String getOldUpdatedDate() {
public void setOldUpdatedDate(String updatedDate) {
this.oldUpdatedDate = updatedDate;
}

public Map<String, Object> getBatchAttributes() {
return batchAttributes;
}

public void setBatchAttributes(Map<String, Object> batchAttributes) {
this.batchAttributes = batchAttributes;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ private void createCourseBatch(Request actorMessage) throws Throwable {
validateContentOrg(actorMessage.getRequestContext(), courseBatch.getCreatedFor());
validateMentors(courseBatch, (String) actorMessage.getContext().getOrDefault(JsonKey.X_AUTH_TOKEN, ""), actorMessage.getRequestContext());
courseBatch.setBatchId(courseBatchId);
String primaryCategory = (String) contentDetails.getOrDefault(JsonKey.PRIMARYCATEGORY, "");
if (JsonKey.PRIMARY_CATEGORY_BLENDED_PROGRAM.equalsIgnoreCase(primaryCategory) && (courseBatch.getBatchAttributes().get(JsonKey.CURRENT_BATCH_SIZE) == null || Integer.parseInt((String) courseBatch.getBatchAttributes().get(JsonKey.CURRENT_BATCH_SIZE)) < 1)) {
ProjectCommonException.throwClientErrorException(
ResponseCode.currentBatchSizeInvalid, ResponseCode.currentBatchSizeInvalid.getErrorMessage());
}
Response result = courseBatchDao.create(actorMessage.getRequestContext(), courseBatch);
result.put(JsonKey.BATCH_ID, courseBatchId);

Expand Down Expand Up @@ -269,6 +274,9 @@ private CourseBatch getUpdateCourseBatch(RequestContext requestContext, Map<Stri
if (request.containsKey(JsonKey.MENTORS))
courseBatch.setMentors((List<String>) request.get(JsonKey.MENTORS));

if (request.containsKey(CourseJsonKey.BATCH_ATTRIBUTES))
courseBatch.setBatchAttributes((Map<String, Object>) request.get(CourseJsonKey.BATCH_ATTRIBUTES));

updateCourseBatchDate(requestContext, courseBatch, request);

return courseBatch;
Expand Down Expand Up @@ -592,7 +600,7 @@ private boolean isOrgValid(RequestContext requestContext, String orgId) {
}

private Map<String, Object> getContentDetails(RequestContext requestContext, String courseId, Map<String, String> headers) {
Map<String, Object> ekStepContent = ContentUtil.getContent(courseId, Arrays.asList("status", "batches", "leafNodesCount"));
Map<String, Object> ekStepContent = ContentUtil.getContent(courseId, Arrays.asList("status", "batches", "leafNodesCount", "primaryCategory"));
logger.info(requestContext, "CourseBatchManagementActor:getEkStepContent: courseId: " + courseId, null,
ekStepContent);
String status = (String) ((Map<String, Object>)ekStepContent.getOrDefault("content", new HashMap<>())).getOrDefault("status", "");
Expand Down Expand Up @@ -691,6 +699,7 @@ private void updateCollection(RequestContext requestContext, Map<String, Object>
data.put("endDate", courseBatch.getOrDefault(JsonKey.END_DATE, null));
data.put("enrollmentType", courseBatch.getOrDefault(JsonKey.ENROLLMENT_TYPE, ""));
data.put("status", courseBatch.getOrDefault(JsonKey.STATUS, ""));
data.put("batchAttributes", courseBatch.getOrDefault(CourseJsonKey.BATCH_ATTRIBUTES, new HashMap<String, Object>()));
data.put("enrollmentEndDate", getEnrollmentEndDate((String) courseBatch.getOrDefault(JsonKey.ENROLLMENT_END_DATE, null), (String) courseBatch.getOrDefault(JsonKey.END_DATE, null)));
batches.removeIf(map -> StringUtils.equalsIgnoreCase((String) courseBatch.getOrDefault(JsonKey.BATCH_ID, ""), (String) map.get("batchId")));
batches.add(data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1078,5 +1078,8 @@ public final class JsonKey {
public static final String CURRENT_OFFSET = "currentOffSet";
public static final String SECURE_SETTINGS = "secureSettings";
public static final String X_AUTH_USER_ORG_ID = "x-authenticated-user-orgid";
public static final String CURRENT_BATCH_SIZE = "currentBatchSize";
public static final String PRIMARYCATEGORY = "primaryCategory";
public static final String PRIMARY_CATEGORY_BLENDED_PROGRAM = "Blended Program";
private JsonKey() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,11 @@ public enum ResponseCode {
cannotUpdateEventSetHavingEnrollments(
ResponseMessage.Key.CANNOT_UPDATE_EVENT_SET_HAVING_ENROLLMENTS,
ResponseMessage.Message.CANNOT_UPDATE_EVENT_SET_HAVING_ENROLLMENTS),

currentBatchSizeInvalid(
ResponseMessage.Key.CURRENT_BATCH_SIZE_INVALID,
ResponseMessage.Message.CURRENT_BATCH_SIZE_PARAMETER),

accessDeniedToEnrolOrUnenrolCourse(ResponseMessage.Key.USER_DOES_NOT_HAVE_ACCESS,ResponseMessage.Message.USER_DOES_NOT_HAVE_ACCESS),
OK(200),
CLIENT_ERROR(400),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ interface Message {
String MISSING_FIXED_BATCH_ID = "Missing Fixed Batch Id.";
String CANNOT_UPDATE_EVENT_SET_HAVING_ENROLLMENTS = "Cannot update event set having enrollments.";
String USER_DOES_NOT_HAVE_ACCESS = "User doesn't have access to this Course Id";
String CURRENT_BATCH_SIZE_PARAMETER = "Request body has invalid/missing parameter 'currentBatchSize' in batchAttributes.";
}

interface Key {
Expand Down Expand Up @@ -848,5 +849,6 @@ interface Key {
String MISSING_FIXED_BATCH_ID = "MISSING_FIXED_BATCH_ID";
String CANNOT_UPDATE_EVENT_SET_HAVING_ENROLLMENTS = "CANNOT_UPDATE_EVENT_SET_HAVING_ENROLLMENTS";
String USER_DOES_NOT_HAVE_ACCESS = "USER_DOES_NOT_HAVE_ACCESS";
String CURRENT_BATCH_SIZE_INVALID = "INVALID_FIELD_CURRENT_BATCH_SIZE";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -261,4 +261,5 @@ enrolled_date=enrolledDate
last_access_time=lastAccessTime
last_completed_time=lastCompletedTime
last_updated_time=lastUpdatedTime
cert_templates=certTemplates
cert_templates=certTemplates
batchattributes=batchAttributes
2 changes: 2 additions & 0 deletions service/app/util/RequestInterceptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ private RequestInterceptor() {}
apiHeaderIgnoreMap.put("/v1/course/create", var);
apiHeaderIgnoreMap.put("/v2/user/courses/list", var);
apiHeaderIgnoreMap.put("/v1/collection/summary", var);
apiHeaderIgnoreMap.put("/v1/course/admin/enroll", var);
apiHeaderIgnoreMap.put("/v1/course/admin/unenroll", var);
}

/**
Expand Down

0 comments on commit c4e551f

Please sign in to comment.