Skip to content

Commit

Permalink
Merge pull request #151 from tarentomaheshvakkund/4.816-batchScheduling
Browse files Browse the repository at this point in the history
KB-5718 | DEV|Assessment |BE| Capturing the starttime and endtime of the Batches while creating the batch for Assessment
  • Loading branch information
SaipradeepR authored Jul 2, 2024
2 parents cf8b6a9 + bb7f32f commit 4191245
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
import org.sunbird.learner.util.Util;
import org.sunbird.models.course.batch.CourseBatch;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import org.sunbird.common.models.util.ProjectUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class CourseBatchDaoImpl implements CourseBatchDao {
private CassandraOperation cassandraOperation = ServiceFactory.getInstance();
Expand All @@ -27,13 +30,25 @@ public class CourseBatchDaoImpl implements CourseBatchDao {
CassandraPropertyReader.getInstance();
private ObjectMapper mapper = new ObjectMapper();
private String dateFormat = "yyyy-MM-dd";

private static final Logger log = LoggerFactory.getLogger(CourseBatchDaoImpl.class);

@Override
public Response create(RequestContext requestContext, CourseBatch courseBatch) {
Map<String, Object> map = CourseBatchUtil.cassandraCourseMapping(courseBatch, dateFormat);
map = CassandraUtil.changeCassandraColumnMapping(map);
CassandraUtil.convertMaptoJsonString(map, JsonKey.BATCH_ATTRIBUTES_KEY);
if(map.get(JsonKey.START_TIME) != null) {
String dateType=JsonKey.START_DATE_BATCH ;
String timeType=JsonKey.START_TIME;
processStartEndDate(map, timeType, dateType);
map.remove(JsonKey.START_TIME);
}
if(map.get(JsonKey.END_TIME) != null) {
String dateType=JsonKey.END_DATE_BATCH;
String timeType=JsonKey.END_TIME;
processStartEndDate(map, timeType, dateType);
map.remove(JsonKey.END_TIME);
}
return cassandraOperation.insertRecord(
requestContext, courseBatchDb.getKeySpace(), courseBatchDb.getTableName(), map);
}
Expand Down Expand Up @@ -150,4 +165,37 @@ public CourseBatch readFirstAvailableBatch(String courseId, RequestContext reque
ResponseCode.CLIENT_ERROR.getResponseCode());
}
}


/**
* This method processes the start and end date by merging the time part from the given map
* into the date part from the given map and setting it to the specified timezone.
*
* @param map The map containing the time and date information.
* @param timeType The key in the map for the time string.
* @param dateType The key in the map for the date object.
*/
private static void processStartEndDate(Map<String, Object> map, String timeType, String dateType) {
String timeStr = (String) map.get(timeType);
SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");
Date time;
try {
time = timeFormat.parse(timeStr);
} catch (ParseException e) {
log.error("Failed to parse time string: " + timeStr, e);
return;
}
Calendar calendar = Calendar.getInstance();
calendar.setTime((Date) map.get(dateType));
Calendar timeCalendar = Calendar.getInstance();
timeCalendar.setTime(time);
String timeZone = ProjectUtil.getConfigValue(JsonKey.SUNBIRD_TIMEZONE);
calendar.setTimeZone(TimeZone.getTimeZone(timeZone));
log.info("Merging time part {} into date {} with timezone {}", timeStr, map.get(dateType), timeZone);
calendar.set(Calendar.HOUR_OF_DAY, timeCalendar.get(Calendar.HOUR_OF_DAY));
calendar.set(Calendar.MINUTE, timeCalendar.get(Calendar.MINUTE));
calendar.set(Calendar.SECOND, timeCalendar.get(Calendar.SECOND));
map.put(dateType, calendar.getTime());
log.info("Updated date in map with key {}: {}", dateType, calendar.getTime());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1139,5 +1139,8 @@ public final class JsonKey {
public static final String LRC_PROGRESS_DETAILS = "lrcProgressDetails";
public static final String USERS_COUNT = "system.count(userid)";
public static final String COURSE_ENROLL_ALLOWED_PRIMARY_CATEGORY = "course_enroll_allowed_primary_category";
public static final String START_DATE_BATCH = "start_date";
public static final String END_DATE_BATCH = "end_date";

private JsonKey() {}
}

0 comments on commit 4191245

Please sign in to comment.