Commit 9c260e4e authored by PrasadMoka's avatar PrasadMoka
Browse files

LR-265 template variable changes

Showing with 24 additions and 12 deletions
+24 -12
......@@ -102,10 +102,7 @@ public class CourseBatchCertificateActor extends BaseActor {
String certName = (String) templateData.getOrDefault(JsonKey.TITLE , (String)templateDetails.getOrDefault(JsonKey.NAME, ""));
template.put(JsonKey.NAME, certName);
// replace the actual cloud url with the template value
String templateUrl = (String) templateDetails.getOrDefault("artifactUrl", "");
if (templateUrl.contains(getConfigValue(CLOUD_STORE_BASE_PATH)))
templateUrl = templateUrl.replace(getConfigValue(CLOUD_STORE_BASE_PATH), CLOUD_STORE_BASE_PATH_PLACEHOLDER);
String templateUrl = getPlaceholderUrl(templateDetails,"artifactUrl");
template.put(JsonKey.URL, templateUrl);
template.put(JsonKey.CRITERIA, mapper.writeValueAsString(template.get(JsonKey.CRITERIA)));
if (null != template.get(CourseJsonKey.ISSUER)) {
......@@ -124,10 +121,13 @@ public class CourseBatchCertificateActor extends BaseActor {
CourseJsonKey.ISSUER, mapper.writeValueAsString(templateDetails.get(CourseJsonKey.SIGNATORY_LIST)));
}
if (MapUtils.isNotEmpty((Map<String,Object>)template.get(CourseJsonKey.NOTIFY_TEMPLATE))) {
//TODO Do we need to change stateImgUrl in notifyTemplate??
// We need to change stateImgUrl in notifyTemplate
Map<String, Object> notifyData = (Map<String, Object>) template.get(CourseJsonKey.NOTIFY_TEMPLATE);
String notifyTemplateUrl = getPlaceholderUrl(notifyData,JsonKey.stateImgUrl);
notifyData.replace(JsonKey.stateImgUrl,notifyTemplateUrl);
template.put(
CourseJsonKey.NOTIFY_TEMPLATE,
mapper.writeValueAsString(template.get(CourseJsonKey.NOTIFY_TEMPLATE)));
mapper.writeValueAsString(notifyData));
}
if (MapUtils.isNotEmpty((Map<String,Object>)template.get(CourseJsonKey.ADDITIONAL_PROPS))) {
template.put(
......@@ -141,6 +141,17 @@ public class CourseBatchCertificateActor extends BaseActor {
}
}
private String getPlaceholderUrl(Map<String, Object> templateDetails, String key) {
String templateUrl = "";
if (MapUtils.isNotEmpty(templateDetails) && templateDetails.containsKey(key)) {
// replace the actual cloud url with the template value
templateUrl = (String) templateDetails.get(key);
if (templateUrl.contains(getConfigValue(CLOUD_STORE_BASE_PATH)))
templateUrl = templateUrl.replace(getConfigValue(CLOUD_STORE_BASE_PATH), getConfigValue(CLOUD_STORE_BASE_PATH_PLACEHOLDER));
}
return templateUrl;
}
private Map<String, Object> mapESFieldsToObject(Map<String, Object> courseBatch) {
Map<String, Map<String, Object>> certificateTemplates =
(Map<String, Map<String, Object>>)
......@@ -181,11 +192,14 @@ public class CourseBatchCertificateActor extends BaseActor {
new TypeReference<HashMap<String, Object>>() {
}));
}
if(StringUtils.isNotEmpty((String)template.get(CourseJsonKey.NOTIFY_TEMPLATE))) {
if (StringUtils.isNotEmpty((String) template.get(CourseJsonKey.NOTIFY_TEMPLATE))) {
String notifyTemplateData = (String) template.get(CourseJsonKey.NOTIFY_TEMPLATE);
//Modify the placeholder with the actual configured cloud base path as ES should have the actual cloud path
if (notifyTemplateData.contains(getConfigValue(CLOUD_STORE_BASE_PATH_PLACEHOLDER)))
notifyTemplateData = notifyTemplateData.replace(getConfigValue(CLOUD_STORE_BASE_PATH_PLACEHOLDER), getConfigValue(CLOUD_STORE_BASE_PATH));
template.put(
CourseJsonKey.NOTIFY_TEMPLATE,
mapper.readValue(
(String) template.get(CourseJsonKey.NOTIFY_TEMPLATE),
mapper.readValue(notifyTemplateData,
new TypeReference<HashMap<String, Object>>() {
}));
}
......
......@@ -1071,8 +1071,6 @@ public final class JsonKey {
public static final String OLD_CREATED_DATE = "oldCreatedDate";
public static final String X_LOGGING_HEADERS = "X_LOGGING_HEADERS";
public static final String LAST_CONTENT_ACCESS_TIME = "lastcontentaccesstime";
public static final String CLOUD_STORE_BASE_PATH_PLACEHOLDER = "cloud_store_base_path_placeholder";
public static final String CLOUD_STORE_BASE_PATH = "cloud_store_base_path";
public static final String GCP="gcloud";
public static final String TEMPLATE_URL = "templateUrl";
......
......@@ -206,5 +206,5 @@ sunbird_msg_sender=
sunbird_msg_91_auth=
sunbird_api_mgr_base_url=https://dev.sunbirded.org/api
enrollment_list_size=1000
cloud_store_base_path=https://sunbirddev.blob.core.windows.net/
cloud_store_base_path=https://sunbirddev.blob.core.windows.net
cloud_store_base_path_placeholder=$CLOUD_STORE_BASE_PATH
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment