Skip to content

Commit

Permalink
Merge branch 'course-batch-refactoring' into lms-service
Browse files Browse the repository at this point in the history
  • Loading branch information
rahul-tarento authored Jul 22, 2019
2 parents e8bbe03 + 84b83d9 commit 08d7738
Show file tree
Hide file tree
Showing 44 changed files with 1,895 additions and 4,008 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[submodule "actors/sunbird-lms-mw/sunbird-utils"]
path = actors/sunbird-lms-mw/sunbird-utils
url = https://github.com/project-sunbird/sunbird-utils
branch = release-2.2.0
branch = course-batch-refactoring
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ node('build-slave') {
}

stage('Unit Tests') {
sh "mvn test '-Dtest=!%regex[io.opensaber.registry.client.*]' -DfailIfNoTests=false"

}

stage('Package') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.sunbird.cassandra.CassandraOperation;
Expand Down Expand Up @@ -94,8 +93,6 @@ private void addUserToUserCourseTable(List<Map<String, Object>> batchList) {
ProjectLogger.log("Adding participants to user course table started", LoggerEnum.INFO.name());
Util.DbInfo courseEnrollmentdbInfo = Util.dbInfoMap.get(JsonKey.LEARNER_COURSE_DB);
for (Map<String, Object> batch : batchList) {
Map<String, String> additionalCourseInfo =
(Map<String, String>) batch.get(JsonKey.COURSE_ADDITIONAL_INFO);
if ((int) batch.get(JsonKey.STATUS) != ProjectUtil.ProgressStatus.COMPLETED.getValue()) {
Map<String, Boolean> participants = (Map<String, Boolean>) batch.get(JsonKey.PARTICIPANT);
if (participants == null) {
Expand All @@ -115,16 +112,7 @@ private void addUserToUserCourseTable(List<Map<String, Object>> batchList) {
userCourses.put(JsonKey.STATUS, ProjectUtil.ProgressStatus.NOT_STARTED.getValue());
userCourses.put(JsonKey.DATE_TIME, ts);
userCourses.put(JsonKey.COURSE_PROGRESS, 0);
userCourses.put(
JsonKey.COURSE_LOGO_URL, additionalCourseInfo.get(JsonKey.COURSE_LOGO_URL));
userCourses.put(JsonKey.COURSE_NAME, additionalCourseInfo.get(JsonKey.COURSE_NAME));
userCourses.put(JsonKey.DESCRIPTION, additionalCourseInfo.get(JsonKey.DESCRIPTION));
if (!StringUtils.isBlank(additionalCourseInfo.get(JsonKey.LEAF_NODE_COUNT))) {
userCourses.put(
JsonKey.LEAF_NODE_COUNT,
Integer.parseInt("" + additionalCourseInfo.get(JsonKey.LEAF_NODE_COUNT)));
}
userCourses.put(JsonKey.TOC_URL, additionalCourseInfo.get(JsonKey.TOC_URL));

try {
cassandraOperation.insertRecord(
courseEnrollmentdbInfo.getKeySpace(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONException;
Expand All @@ -16,15 +20,14 @@
import org.sunbird.common.inf.ElasticSearchService;
import org.sunbird.common.models.response.Response;
import org.sunbird.common.models.util.ActorOperations;
import org.sunbird.common.models.util.HttpUtil;
import org.sunbird.common.models.util.JsonKey;
import org.sunbird.common.models.util.LoggerEnum;
import org.sunbird.common.models.util.ProjectLogger;
import org.sunbird.common.models.util.ProjectUtil;
import org.sunbird.common.models.util.PropertiesCache;
import org.sunbird.common.request.Request;
import org.sunbird.common.responsecode.ResponseCode;
import org.sunbird.helper.ServiceFactory;
import org.sunbird.learner.actors.coursebatch.service.UserCoursesService;
import org.sunbird.learner.util.CourseBatchSchedulerUtil;
import org.sunbird.learner.util.Util;
import org.sunbird.learner.util.Util.DbInfo;
Expand Down Expand Up @@ -80,9 +83,7 @@ public void onReceive(Request request) throws Throwable {
}
String operation = request.getOperation();
ProjectLogger.log("Operation name is ==" + operation);
if (operation.equalsIgnoreCase(ActorOperations.PUBLISH_COURSE.getValue())) {
// manageBackgroundJob(request);
} else if (operation.equalsIgnoreCase(ActorOperations.UPDATE_USER_INFO_ELASTIC.getValue())) {
if (operation.equalsIgnoreCase(ActorOperations.UPDATE_USER_INFO_ELASTIC.getValue())) {
ProjectLogger.log("Update user info to ES called.", LoggerEnum.INFO.name());
updateUserInfoToEs(request);
} else if (operation.equalsIgnoreCase(
Expand Down Expand Up @@ -214,10 +215,13 @@ private void insertUserCourseInfoToEs(Request actorMessage) {

Map<String, Object> batch =
(Map<String, Object>) actorMessage.getRequest().get(JsonKey.USER_COURSES);
String userId = (String) batch.get(JsonKey.USER_ID);
String batchId = (String) batch.get(JsonKey.BATCH_ID);
String identifier = UserCoursesService.generateUserCourseESId(batchId, userId);
insertDataToElastic(
ProjectUtil.EsIndex.sunbird.getIndexName(),
ProjectUtil.EsType.usercourses.getTypeName(),
(String) batch.get(JsonKey.ID),
identifier,
batch);
}

Expand Down Expand Up @@ -410,74 +414,6 @@ private void updateUserCount(Request actorMessage) {
}
}

/**
* @param request
* @return boolean
*/
@SuppressWarnings("unchecked")
private boolean manageBackgroundJob(Request request) {
Map<String, Object> data = null;
if (request.getRequest() == null) {
return false;
} else {
data = request.getRequest();
}

List<Map<String, Object>> list = (List<Map<String, Object>>) data.get(JsonKey.RESPONSE);
Map<String, Object> content = list.get(0);
String contentId = (String) content.get(JsonKey.CONTENT_ID);
if (!StringUtils.isBlank(contentId)) {
String contentData = getCourseData(contentId);
if (!StringUtils.isBlank(contentData)) {
Map<String, Object> map = getContentDetails(contentData);
map.put(JsonKey.ID, content.get(JsonKey.COURSE_ID));
updateCourseManagement(map);
List<String> createdForValue = null;
Object obj = content.get(JsonKey.COURSE_CREATED_FOR);
if (obj != null) {
createdForValue = (List<String>) obj;
}
content.remove(JsonKey.COURSE_CREATED_FOR);
content.put(JsonKey.APPLICABLE_FOR, createdForValue);
Map<String, Object> finalResponseMap = (Map<String, Object>) map.get(JsonKey.RESULT);
finalResponseMap.putAll(content);
finalResponseMap.put(JsonKey.OBJECT_TYPE, ProjectUtil.EsType.course.getTypeName());
insertDataToElastic(
ProjectUtil.EsIndex.sunbird.getIndexName(),
ProjectUtil.EsType.course.getTypeName(),
(String) map.get(JsonKey.ID),
finalResponseMap);
}
}
return true;
}

/**
* Method to get the course data.
*
* @param contnetId String
* @return String
*/
private String getCourseData(String contnetId) {
String responseData = null;
try {
String ekStepBaseUrl = System.getenv(JsonKey.EKSTEP_BASE_URL);
if (StringUtils.isBlank(ekStepBaseUrl)) {
ekStepBaseUrl = PropertiesCache.getInstance().getProperty(JsonKey.EKSTEP_BASE_URL);
}

responseData =
HttpUtil.sendGetRequest(
ekStepBaseUrl
+ PropertiesCache.getInstance().getProperty(JsonKey.EKSTEP_CONTENT_URL)
+ contnetId,
headerMap);
} catch (IOException e) {
ProjectLogger.log(e.getMessage(), e);
}
return responseData;
}

/**
* Method to get the content details of the given content id.
*
Expand Down
Loading

0 comments on commit 08d7738

Please sign in to comment.