Skip to content

Commit

Permalink
4.8.4 bug fixes (#67)
Browse files Browse the repository at this point in the history
* bug #99529 bug #99530  (#63)
* Fix for batch create issue due to column type change
* Fix for parse issue in enrol API

---------

Co-authored-by: Sahil-tarento <140611066+Sahil-tarento@users.noreply.github.com>
Co-authored-by: SaipradeepR <53404427+SaipradeepR@users.noreply.github.com>
Co-authored-by: saipradeep_ravipati <saipradeep.ravipati@tarento.com>
  • Loading branch information
4 people authored Aug 24, 2023
1 parent 2642889 commit 9eeac62
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class CourseBatchDaoImpl implements CourseBatchDao {
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);
return cassandraOperation.insertRecord(
requestContext, courseBatchDb.getKeySpace(), courseBatchDb.getTableName(), map);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
Expand Down Expand Up @@ -223,4 +226,13 @@ public void setBatchAttributes(Map<String, Object> batchAttributes) {
this.batchAttributes = batchAttributes;
}

public void setBatchAttributes(String batchAttributesStr) {
try {
this.batchAttributes = (new ObjectMapper()).readValue(batchAttributesStr,
new TypeReference<Map<String, Object>>() {
});
} catch (Exception e) {
e.printStackTrace();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.sunbird.cassandraannotation.ClusteringKey;
import org.sunbird.cassandraannotation.PartitioningKey;
import org.sunbird.common.exception.ProjectCommonException;
Expand Down Expand Up @@ -347,4 +350,15 @@ public static Map<String, Object> changeCassandraColumnMapping(Map<String, Objec
map.entrySet().forEach(entry -> newMap.put(propertiesCache.readPropertyValue(entry.getKey()), entry.getValue()));
return newMap;
}

public static void convertMaptoJsonString(Map<String, Object> map, String field) {
try {
if (map.containsKey(field)) {
map.put(field, (new ObjectMapper()).writeValueAsString(map.get(field)));
}
} catch (JsonProcessingException e) {
logger.error(null,"Exception occurred - convertMaptoJsonString", e);
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1081,5 +1081,8 @@ public final class JsonKey {
public static final String CURRENT_BATCH_SIZE = "currentBatchSize";
public static final String PRIMARYCATEGORY = "primaryCategory";
public static final String PRIMARY_CATEGORY_BLENDED_PROGRAM = "Blended Program";
public static final String COURSE_BATCH_ENROLL_END_DATE_LESS = "enrol_end_date_allow_lesser_value";
public static final String BATCH_ATTRIBUTES_KEY = "batch_attributes";

private JsonKey() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -262,4 +262,5 @@ last_access_time=lastAccessTime
last_completed_time=lastCompletedTime
last_updated_time=lastUpdatedTime
cert_templates=certTemplates
batchattributes=batchAttributes
batch_attributes=batchAttributes
batchAttributes=batch_attributes
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,4 @@ sunbird_api_mgr_base_url=https://dev.sunbirded.org/api
enrollment_list_size=1000
sunbird_course_batch_path=/app/toc/{courseId}/overview?batchId={batchId}
enrolment_list_include_retired_courses=false
enrol_end_date_allow_lesser_value=true
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.sunbird.common.models.util.JsonKey;
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.BaseRequestValidator;
import org.sunbird.common.request.Request;
import org.sunbird.common.responsecode.ResponseCode;
Expand Down Expand Up @@ -171,7 +172,7 @@ private static void validateEndDate(String startDate, String endDate) {
ResponseCode.dateFormatError.getErrorMessage(),
ResponseCode.CLIENT_ERROR.getResponseCode());
}
if (StringUtils.isNotEmpty(endDate) && batchStartDate.getTime() >= batchEndDate.getTime()) {
if (StringUtils.isNotEmpty(endDate) && batchStartDate.getTime() > batchEndDate.getTime()) {
throw new ProjectCommonException(
ResponseCode.endDateError.getErrorCode(),
ResponseCode.endDateError.getErrorMessage(),
Expand Down Expand Up @@ -201,7 +202,7 @@ private static void validateEnrollmentEndDate(
ResponseCode.dateFormatError.getErrorMessage(),
ResponseCode.CLIENT_ERROR.getResponseCode());
}
if (StringUtils.isNotEmpty(enrollmentEndDate)
if (courseBatchEnrolLessDateEnabled() && StringUtils.isNotEmpty(enrollmentEndDate)
&& batchStartDate.getTime() > batchenrollmentEndDate.getTime()) {
throw new ProjectCommonException(
ResponseCode.enrollmentEndDateStartError.getErrorCode(),
Expand Down Expand Up @@ -339,4 +340,10 @@ public void validateGetParticipantsRequest(Request request) {
ResponseCode.mandatoryParamsMissing,
JsonKey.BATCH_ID);
}

private static boolean courseBatchEnrolLessDateEnabled() {
return Boolean.parseBoolean(
PropertiesCache.getInstance()
.getProperty(JsonKey.COURSE_BATCH_ENROLL_END_DATE_LESS));
}
}

0 comments on commit 9eeac62

Please sign in to comment.