Unverified Commit ce0a33d1 authored by Reshmi V Nair's avatar Reshmi V Nair Committed by GitHub
Browse files

Merge pull request #506 from Sunbird-Lern/release-5.0.1

Release 5.0.1 changes applying on master.
Showing with 46 additions and 12 deletions
+46 -12
...@@ -18,14 +18,14 @@ import org.sunbird.common.models.util.TelemetryEnvKey; ...@@ -18,14 +18,14 @@ import org.sunbird.common.models.util.TelemetryEnvKey;
import org.sunbird.common.request.Request; import org.sunbird.common.request.Request;
import org.sunbird.common.request.RequestContext; import org.sunbird.common.request.RequestContext;
import org.sunbird.common.responsecode.ResponseCode; import org.sunbird.common.responsecode.ResponseCode;
import org.sunbird.common.util.CloudStorageUtil;
import org.sunbird.learner.actors.coursebatch.dao.CourseBatchDao; import org.sunbird.learner.actors.coursebatch.dao.CourseBatchDao;
import org.sunbird.learner.actors.coursebatch.dao.impl.CourseBatchDaoImpl; import org.sunbird.learner.actors.coursebatch.dao.impl.CourseBatchDaoImpl;
import org.sunbird.learner.constants.CourseJsonKey; import org.sunbird.learner.constants.CourseJsonKey;
import org.sunbird.learner.util.CourseBatchUtil; import org.sunbird.learner.util.CourseBatchUtil;
import org.sunbird.learner.util.Util; import org.sunbird.learner.util.Util;
import static org.sunbird.common.models.util.JsonKey.CLOUD_STORE_BASE_PATH; import static org.sunbird.common.models.util.JsonKey.*;
import static org.sunbird.common.models.util.JsonKey.CLOUD_STORE_BASE_PATH_PLACEHOLDER;
import static org.sunbird.common.models.util.ProjectUtil.getConfigValue; import static org.sunbird.common.models.util.ProjectUtil.getConfigValue;
public class CourseBatchCertificateActor extends BaseActor { public class CourseBatchCertificateActor extends BaseActor {
...@@ -123,6 +123,7 @@ public class CourseBatchCertificateActor extends BaseActor { ...@@ -123,6 +123,7 @@ public class CourseBatchCertificateActor extends BaseActor {
if (MapUtils.isNotEmpty((Map<String,Object>)template.get(CourseJsonKey.NOTIFY_TEMPLATE))) { if (MapUtils.isNotEmpty((Map<String,Object>)template.get(CourseJsonKey.NOTIFY_TEMPLATE))) {
// 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); Map<String, Object> notifyData = (Map<String, Object>) template.get(CourseJsonKey.NOTIFY_TEMPLATE);
//TODO cross check the data in environments and remove this check if not required
String notifyTemplateUrl = getPlaceholderUrl(notifyData,JsonKey.stateImgUrl); String notifyTemplateUrl = getPlaceholderUrl(notifyData,JsonKey.stateImgUrl);
notifyData.replace(JsonKey.stateImgUrl,notifyTemplateUrl); notifyData.replace(JsonKey.stateImgUrl,notifyTemplateUrl);
template.put( template.put(
...@@ -146,8 +147,8 @@ public class CourseBatchCertificateActor extends BaseActor { ...@@ -146,8 +147,8 @@ public class CourseBatchCertificateActor extends BaseActor {
if (MapUtils.isNotEmpty(templateDetails) && templateDetails.containsKey(key)) { if (MapUtils.isNotEmpty(templateDetails) && templateDetails.containsKey(key)) {
// replace the actual cloud url with the template value // replace the actual cloud url with the template value
templateUrl = (String) templateDetails.get(key); templateUrl = (String) templateDetails.get(key);
if (templateUrl.contains(getConfigValue(CLOUD_STORE_BASE_PATH))) if (templateUrl.contains(CloudStorageUtil.getBaseUrl() +"/"+getConfigValue(CONTENT_CLOUD_STORAGE_CONTAINER)))
templateUrl = templateUrl.replace(getConfigValue(CLOUD_STORE_BASE_PATH), getConfigValue(CLOUD_STORE_BASE_PATH_PLACEHOLDER)); templateUrl = templateUrl.replace(CloudStorageUtil.getBaseUrl()+"/"+getConfigValue(CONTENT_CLOUD_STORAGE_CONTAINER), getConfigValue(CLOUD_STORE_BASE_PATH_PLACEHOLDER));
} }
return templateUrl; return templateUrl;
} }
...@@ -196,7 +197,7 @@ public class CourseBatchCertificateActor extends BaseActor { ...@@ -196,7 +197,7 @@ public class CourseBatchCertificateActor extends BaseActor {
String notifyTemplateData = (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 //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))) if (notifyTemplateData.contains(getConfigValue(CLOUD_STORE_BASE_PATH_PLACEHOLDER)))
notifyTemplateData = notifyTemplateData.replace(getConfigValue(CLOUD_STORE_BASE_PATH_PLACEHOLDER), getConfigValue(CLOUD_STORE_BASE_PATH)); notifyTemplateData = notifyTemplateData.replace(getConfigValue(CLOUD_STORE_BASE_PATH_PLACEHOLDER), CloudStorageUtil.getBaseUrl()+"/"+getConfigValue(CONTENT_CLOUD_STORAGE_CONTAINER));
template.put( template.put(
CourseJsonKey.NOTIFY_TEMPLATE, CourseJsonKey.NOTIFY_TEMPLATE,
mapper.readValue(notifyTemplateData, mapper.readValue(notifyTemplateData,
......
...@@ -232,11 +232,10 @@ public class QRCodeDownloadManagementActor extends BaseActor { ...@@ -232,11 +232,10 @@ public class QRCodeDownloadManagementActor extends BaseActor {
if (null != obj && obj instanceof List) { if (null != obj && obj instanceof List) {
List<Map<String, Object>> listOfMap = (List<Map<String, Object>>) obj; List<Map<String, Object>> listOfMap = (List<Map<String, Object>>) obj;
if (CollectionUtils.isNotEmpty(listOfMap)) { if (CollectionUtils.isNotEmpty(listOfMap)) {
//TODO Resolve it and store. Assuming dial code db will have the template url with data migration script //check if template url contains dail storage base path placeholder,if yes then append it with cname url and dial bucket name
String templateUrl = (String) listOfMap.get(0).get("url"); String templateUrl = (String) listOfMap.get(0).get("url");
//replace template url with the actual cloud url String dailStorageBasePathPlaceHolder = getConfigValue(DIAL_STORAGE_BASE_PATH_PLACEHOLDER);
if (templateUrl.contains(getConfigValue(CLOUD_STORE_BASE_PATH_PLACEHOLDER))) templateUrl = resolvePlaceholder(templateUrl, dailStorageBasePathPlaceHolder,getConfigValue(CLOUD_STORAGE_DIAL_BUCKET_NAME));
templateUrl = templateUrl.replace(getConfigValue(CLOUD_STORE_BASE_PATH_PLACEHOLDER), getConfigValue(CLOUD_STORE_BASE_PATH));
return templateUrl; return templateUrl;
} }
} }
...@@ -244,6 +243,14 @@ public class QRCodeDownloadManagementActor extends BaseActor { ...@@ -244,6 +243,14 @@ public class QRCodeDownloadManagementActor extends BaseActor {
return ""; return "";
} }
private String resolvePlaceholder(String templateUrl, String placeHolder,String containerName) {
if (templateUrl.contains(placeHolder))
templateUrl = templateUrl.replace(placeHolder, CloudStorageUtil.getBaseUrl()
+ "/" + containerName);
return templateUrl;
}
/** /**
* Uploading the generated csv to aws * Uploading the generated csv to aws
* *
......
...@@ -789,6 +789,9 @@ public final class JsonKey { ...@@ -789,6 +789,9 @@ public final class JsonKey {
public static final String CLOUD_FOLDER_CONTENT = "sunbird_cloud_content_folder"; public static final String CLOUD_FOLDER_CONTENT = "sunbird_cloud_content_folder";
public static final String CLOUD_STORE_BASE_PATH = "cloud_storage_base_url"; public static final String CLOUD_STORE_BASE_PATH = "cloud_storage_base_url";
public static final String CLOUD_STORAGE_CNAME_URL= "cloud_storage_cname_url";
public static final String CLOUD_STORAGE_DIAL_BUCKET_NAME = "cloud_storage_dial_bucketname";
public static final String DIAL_STORAGE_BASE_PATH_PLACEHOLDER="cloud_storage_path_prefix_dial";
public static final String CLOUD_STORE_BASE_PATH_PLACEHOLDER = "cloud_store_base_path_placeholder"; public static final String CLOUD_STORE_BASE_PATH_PLACEHOLDER = "cloud_store_base_path_placeholder";
public static final String TO_URL = "toUrl"; public static final String TO_URL = "toUrl";
public static final String TTL = "ttl"; public static final String TTL = "ttl";
......
...@@ -2,6 +2,8 @@ package org.sunbird.common.util; ...@@ -2,6 +2,8 @@ package org.sunbird.common.util;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.sunbird.cloud.storage.BaseStorageService; import org.sunbird.cloud.storage.BaseStorageService;
import org.sunbird.cloud.storage.factory.StorageConfig; import org.sunbird.cloud.storage.factory.StorageConfig;
import org.sunbird.cloud.storage.factory.StorageServiceFactory; import org.sunbird.cloud.storage.factory.StorageServiceFactory;
...@@ -11,6 +13,10 @@ import org.sunbird.common.models.util.PropertiesCache; ...@@ -11,6 +13,10 @@ import org.sunbird.common.models.util.PropertiesCache;
import scala.Option; import scala.Option;
import scala.Some; import scala.Some;
import static org.sunbird.common.models.util.JsonKey.CLOUD_STORAGE_CNAME_URL;
import static org.sunbird.common.models.util.JsonKey.CLOUD_STORE_BASE_PATH;
import static org.sunbird.common.models.util.ProjectUtil.getConfigValue;
public class CloudStorageUtil { public class CloudStorageUtil {
private static final int STORAGE_SERVICE_API_RETRY_COUNT = 3; private static final int STORAGE_SERVICE_API_RETRY_COUNT = 3;
...@@ -76,4 +82,11 @@ public class CloudStorageUtil { ...@@ -76,4 +82,11 @@ public class CloudStorageUtil {
BaseStorageService storageService = getStorageService(storageType); BaseStorageService storageService = getStorageService(storageType);
return storageService.getUri(container, prefix, Option.apply(isDirectory)); return storageService.getUri(container, prefix, Option.apply(isDirectory));
} }
public static String getBaseUrl() {
String baseUrl = getConfigValue(CLOUD_STORAGE_CNAME_URL);
if(StringUtils.isEmpty(baseUrl))
baseUrl = getConfigValue(CLOUD_STORE_BASE_PATH);
return baseUrl;
}
} }
...@@ -80,7 +80,7 @@ sunbird_otp_allowed_attempt=2 ...@@ -80,7 +80,7 @@ sunbird_otp_allowed_attempt=2
#Telemetry producer related info #Telemetry producer related info
telemetry_pdata_id=local.sunbird.learning.service telemetry_pdata_id=local.sunbird.learning.service
telemetry_pdata_pid=learning-service telemetry_pdata_pid=learning-service
telemetry_pdata_ver=5.0.0 telemetry_pdata_ver=5.0.1
#elastic search top n result count for telemetry #elastic search top n result count for telemetry
searchTopN=5 searchTopN=5
telemetry_queue_threshold_value=200 telemetry_queue_threshold_value=200
...@@ -207,4 +207,6 @@ sunbird_msg_91_auth= ...@@ -207,4 +207,6 @@ sunbird_msg_91_auth=
sunbird_api_mgr_base_url=https://dev.sunbirded.org/api sunbird_api_mgr_base_url=https://dev.sunbirded.org/api
enrollment_list_size=1000 enrollment_list_size=1000
cloud_storage_base_url=https://sunbirddev.blob.core.windows.net cloud_storage_base_url=https://sunbirddev.blob.core.windows.net
cloud_store_base_path_placeholder=$CLOUD_STORE_BASE_PATH cloud_store_base_path_placeholder=CLOUD_BASE_PATH
\ No newline at end of file cloud_storage_dial_bucketname=dial
cloud_storage_path_prefix_dial=DIAL_STORAGE_BASE_PATH
\ No newline at end of file
...@@ -2,7 +2,9 @@ package filters ...@@ -2,7 +2,9 @@ package filters
import akka.stream.Materializer import akka.stream.Materializer
import akka.util.ByteString import akka.util.ByteString
import org.apache.commons.lang.StringUtils
import org.sunbird.common.models.util.JsonKey import org.sunbird.common.models.util.JsonKey
import org.sunbird.common.models.util.JsonKey.{CLOUD_STORAGE_CNAME_URL, CLOUD_STORE_BASE_PATH, CONTENT_CLOUD_STORAGE_CONTAINER}
import play.api.http.HttpEntity.Strict import play.api.http.HttpEntity.Strict
import play.api.mvc.{Filter, RequestHeader, Result} import play.api.mvc.{Filter, RequestHeader, Result}
import org.sunbird.common.models.util.ProjectUtil.getConfigValue import org.sunbird.common.models.util.ProjectUtil.getConfigValue
...@@ -18,7 +20,7 @@ class ResponseFilter @Inject()(implicit val mat: Materializer, ec: ExecutionCon ...@@ -18,7 +20,7 @@ class ResponseFilter @Inject()(implicit val mat: Materializer, ec: ExecutionCon
if (null != result.body && !result.body.isKnownEmpty){ if (null != result.body && !result.body.isKnownEmpty){
val contentType = result.body.contentType val contentType = result.body.contentType
val updatedBody = result.body.consumeData.map { x => val updatedBody = result.body.consumeData.map { x =>
val y = x.utf8String.replaceAll(getConfigValue(JsonKey.CLOUD_STORE_BASE_PATH_PLACEHOLDER),getConfigValue(JsonKey.CLOUD_STORE_BASE_PATH)) val y = x.utf8String.replaceAll(getConfigValue(JsonKey.CLOUD_STORE_BASE_PATH_PLACEHOLDER), getBaseUrl + "/" + getConfigValue(CONTENT_CLOUD_STORAGE_CONTAINER))
logger.info("updated body: " + y) logger.info("updated body: " + y)
y y
} }
...@@ -29,4 +31,10 @@ class ResponseFilter @Inject()(implicit val mat: Materializer, ec: ExecutionCon ...@@ -29,4 +31,10 @@ class ResponseFilter @Inject()(implicit val mat: Materializer, ec: ExecutionCon
Future(result) Future(result)
} }
} }
def getBaseUrl: String = {
var baseUrl = getConfigValue(CLOUD_STORAGE_CNAME_URL)
if (StringUtils.isEmpty(baseUrl)) baseUrl = getConfigValue(CLOUD_STORE_BASE_PATH)
baseUrl
}
} }
\ 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