From 12bad78ac6ca193faaa70d787400220613d56af3 Mon Sep 17 00:00:00 2001 From: SaipradeepR <53404427+SaipradeepR@users.noreply.github.com> Date: Mon, 9 Dec 2024 18:53:12 +0530 Subject: [PATCH] coursera progress implementation added. (#58) (#59) Co-authored-by: Arpitha --- .../cios/CiosContentServiceApplication.java | 2 + .../cios/consumer/OnboardContentConsumer.java | 4 +- .../com/igot/cios/dto/RequestBodyDTO.java | 3 +- .../com/igot/cios/kafka/KafkaProducer.java | 4 +- .../cios/plugins/DataTransformUtility.java | 32 +++- ...vice.java => CornellSchedulerService.java} | 70 +++----- .../igot/cios/scheduler/CourseScheduler.java | 22 ++- .../scheduler/CourseraSchedulerService.java | 151 ++++++++++++++++++ .../cios/scheduler/SchedulerInterface.java | 9 ++ .../igot/cios/util/CbServerProperties.java | 18 +++ .../Transformation/CourseraApiProgress.json | 10 ++ .../Transformation/UpgradApiProgress.json | 10 ++ .../Transformation/cornellApiProgress.json | 10 ++ .../Transformation/courseraApiContent.json | 40 +++++ src/main/resources/Transformation/upgrad.json | 2 +- src/main/resources/application.properties | 11 +- 16 files changed, 330 insertions(+), 68 deletions(-) rename src/main/java/com/igot/cios/scheduler/{CourseSchedulerService.java => CornellSchedulerService.java} (70%) create mode 100644 src/main/java/com/igot/cios/scheduler/CourseraSchedulerService.java create mode 100644 src/main/java/com/igot/cios/scheduler/SchedulerInterface.java create mode 100644 src/main/resources/Transformation/CourseraApiProgress.json create mode 100644 src/main/resources/Transformation/UpgradApiProgress.json create mode 100644 src/main/resources/Transformation/cornellApiProgress.json create mode 100644 src/main/resources/Transformation/courseraApiContent.json diff --git a/src/main/java/com/igot/cios/CiosContentServiceApplication.java b/src/main/java/com/igot/cios/CiosContentServiceApplication.java index 2fe1400..80a11e6 100644 --- a/src/main/java/com/igot/cios/CiosContentServiceApplication.java +++ b/src/main/java/com/igot/cios/CiosContentServiceApplication.java @@ -2,8 +2,10 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.scheduling.annotation.EnableScheduling; @SpringBootApplication +@EnableScheduling public class CiosContentServiceApplication { public static void main(String[] args) { diff --git a/src/main/java/com/igot/cios/consumer/OnboardContentConsumer.java b/src/main/java/com/igot/cios/consumer/OnboardContentConsumer.java index 9cfd3e4..e9c4bd4 100644 --- a/src/main/java/com/igot/cios/consumer/OnboardContentConsumer.java +++ b/src/main/java/com/igot/cios/consumer/OnboardContentConsumer.java @@ -166,12 +166,12 @@ public void processReceivedData(String partnerCode, List> pr JsonNode partnerInfo = dataTransformUtility.fetchPartnerInfoUsingApi(partnerCode); // Extract and cache contentJson cachedContentJson = objectMapper.convertValue( - partnerInfo.path(Constants.RESULT).path("trasformContentJson"), + partnerInfo.path("trasformContentJson"), new TypeReference>() { } ); if (cachedContentJson == null || cachedContentJson.isEmpty()) { - log.error("trasformContentJson is missing, please update in contentPartner"); + log.error("trasformContentJson is missing, please update in contentPartner for partner {}",partnerCode); throw new CiosContentException( "ERROR", "trasformContentJson is missing, please update in contentPartner", diff --git a/src/main/java/com/igot/cios/dto/RequestBodyDTO.java b/src/main/java/com/igot/cios/dto/RequestBodyDTO.java index 7b83217..73a601d 100644 --- a/src/main/java/com/igot/cios/dto/RequestBodyDTO.java +++ b/src/main/java/com/igot/cios/dto/RequestBodyDTO.java @@ -12,5 +12,6 @@ public class RequestBodyDTO { private String serviceCode; private Map urlMap; - private String partnerCode; + private Map headerMap; + private Map requestBody; } diff --git a/src/main/java/com/igot/cios/kafka/KafkaProducer.java b/src/main/java/com/igot/cios/kafka/KafkaProducer.java index c6f1b82..c4a7562 100644 --- a/src/main/java/com/igot/cios/kafka/KafkaProducer.java +++ b/src/main/java/com/igot/cios/kafka/KafkaProducer.java @@ -19,9 +19,9 @@ public class KafkaProducer { public void push(String topic, Object data) { try { String message = objectMapper.writeValueAsString(data); - log.info("KafkaProducer::sendCornellData: topic: {}", topic); + log.info("KafkaProducer::sendData: topic: {}", topic); this.kafkaTemplate.send(topic, message); - log.info("Data sent to kafka topic {} and message is {}", topic); + log.debug("Data sent to kafka topic {} and message is {}", topic,message); } catch (Exception e) { throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.getMessage()); } diff --git a/src/main/java/com/igot/cios/plugins/DataTransformUtility.java b/src/main/java/com/igot/cios/plugins/DataTransformUtility.java index 04a771d..7791ab3 100644 --- a/src/main/java/com/igot/cios/plugins/DataTransformUtility.java +++ b/src/main/java/com/igot/cios/plugins/DataTransformUtility.java @@ -214,11 +214,7 @@ public String updatingPartnerInfo(JsonNode jsonNode) { String url = cbServerProperties.getCbPoresbaseUrl() + cbServerProperties.getPartnerCreateEndPoint(); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); - - // Create the request entity with body and headers HttpEntity entity = new HttpEntity<>(jsonNode, headers); - - // Make the POST request ResponseEntity response = restTemplate.postForEntity(url, entity, String.class); if (response.getStatusCode().is2xxSuccessful()) { return response.getBody(); @@ -229,7 +225,7 @@ public String updatingPartnerInfo(JsonNode jsonNode) { public JsonNode fetchPartnerInfoUsingApi(String partnerCode) { - log.info("CiosContentServiceImpl::fetchPartnerInfoUsingApi:fetching partner data by partnerCode"); + log.info("CiosContentServiceImpl::fetchPartnerInfoUsingApi:fetching partner data by partnerCode {}",partnerCode); String getApiUrl = cbServerProperties.getCbPoresbaseUrl() + cbServerProperties.getPartnerReadEndPoint() + partnerCode; Map headers = new HashMap<>(); Map readData = (Map) fetchResultUsingGet(getApiUrl, headers); @@ -238,7 +234,7 @@ public JsonNode fetchPartnerInfoUsingApi(String partnerCode) { throw new RuntimeException("Failed to get data from API: Response is null"); } ObjectMapper objectMapper = new ObjectMapper(); - return objectMapper.convertValue(readData, JsonNode.class); + return objectMapper.convertValue(readData.get("result"), JsonNode.class); } public Object fetchResultUsingGet(String uri, Map headersValues) { @@ -461,4 +457,28 @@ public void flattenContentData(Map entityMap) { } } } + + public JsonNode callCiosReadApi(String extCourseId,String partnerId) { + log.info("CourseScheduler :: callCiosReadApi"); + try { + String url = cbServerProperties.getCbPoresbaseUrl() + cbServerProperties.getFixedUrl() + extCourseId + "/" + partnerId; + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + HttpEntity entity = new HttpEntity<>(headers); + ResponseEntity response = restTemplate.exchange( + url, + HttpMethod.GET, + entity, + Object.class + ); + if (response.getStatusCode().is2xxSuccessful()) { + JsonNode jsonNode = objectMapper.valueToTree(response.getBody()); + return jsonNode; + } else { + throw new CiosContentException(Constants.ERROR, "Failed to retrieve externalId. Status code: " + response.getStatusCodeValue()); + } + } catch (Exception e) { + throw new CiosContentException(Constants.ERROR, e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); + } + } } diff --git a/src/main/java/com/igot/cios/scheduler/CourseSchedulerService.java b/src/main/java/com/igot/cios/scheduler/CornellSchedulerService.java similarity index 70% rename from src/main/java/com/igot/cios/scheduler/CourseSchedulerService.java rename to src/main/java/com/igot/cios/scheduler/CornellSchedulerService.java index ef5e9c0..6de4113 100644 --- a/src/main/java/com/igot/cios/scheduler/CourseSchedulerService.java +++ b/src/main/java/com/igot/cios/scheduler/CornellSchedulerService.java @@ -20,15 +20,18 @@ import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import org.springframework.web.client.RestTemplate; - +import com.fasterxml.jackson.core.type.TypeReference; import java.text.SimpleDateFormat; import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.*; +import java.io.UnsupportedEncodingException; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; @Slf4j @Service -public class CourseSchedulerService { +public class CornellSchedulerService implements SchedulerInterface { @Autowired private ObjectMapper objectMapper; @@ -45,14 +48,15 @@ public class CourseSchedulerService { @Autowired private DataTransformUtility dataTransformUtility; - private void callCornellEnrollmentAPI(String partnerCode, JsonNode rawContentData) { + public void callEnrollmentAPI(String partnerCode, JsonNode rawContentData) { try { - log.info("CourseSchedulerService::callCornellEnrollmentAPI"); + log.info("CornellSchedulerService::callEnrollmentAPI"); JsonNode entity = dataTransformUtility.fetchPartnerInfoUsingApi(partnerCode); - List contentJson = Collections.singletonList(entity.path("result").get("transformProgressJson").toString()); + List contentJson = objectMapper.convertValue(entity.get("transformProgressViaApi"), new TypeReference>() {}); JsonNode transformData = dataTransformUtility.transformData(rawContentData, contentJson); String extCourseId = transformData.get("courseid").asText(); - JsonNode result = callCiosReadApi(extCourseId); + String partnerId = entity.get("id").asText(); + JsonNode result = dataTransformUtility.callCiosReadApi(extCourseId,partnerId); String courseId = result.path("content").get("contentId").asText(); String[] parts = transformData.get("userid").asText().split("@"); ((ObjectNode) transformData).put("userid", parts[0]); @@ -87,51 +91,17 @@ private String updateDateFormatFromTimestamp(Long completedon) { return sdf.format(date); } - private JsonNode callCiosReadApi(String extCourseId) { - log.info("CourseScheduler :: callCiosReadApi"); - try { - String url = cbServerProperties.getCbPoresbaseUrl() + cbServerProperties.getFixedUrl() + extCourseId; - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_JSON); - HttpEntity entity = new HttpEntity<>(headers); - ResponseEntity response = restTemplate.exchange( - url, - HttpMethod.GET, - entity, - Object.class - ); - if (response.getStatusCode().is2xxSuccessful()) { - JsonNode jsonNode = objectMapper.valueToTree(response.getBody()); - return jsonNode; - } else { - throw new CiosContentException(Constants.ERROR, "Failed to retrieve externalId. Status code: " + response.getStatusCodeValue()); - } - } catch (Exception e) { - throw new CiosContentException(Constants.ERROR, e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); - } - - } - - private JsonNode transformData(Object sourceObject, List specJson) { - log.debug("CiosContentServiceImpl::transformData"); - try { - String inputJson = objectMapper.writeValueAsString(sourceObject); - Chainr chainr = Chainr.fromSpec(specJson); - Object transformedOutput = chainr.transform(JsonUtils.jsonToObject(inputJson)); - return objectMapper.convertValue(transformedOutput, JsonNode.class); - } catch (JsonProcessingException e) { - log.error("Error transforming data", e); - return null; - } - } - - public JsonNode loadCornellEnrollment() throws JsonProcessingException { + public JsonNode loadEnrollment() { RequestBodyDTO requestBodyDTO = new RequestBodyDTO(); requestBodyDTO.setServiceCode(cbServerProperties.getCornellEnrollmentServiceCode()); requestBodyDTO.setUrlMap(formUrlMapForEnrollment()); - requestBodyDTO.setPartnerCode("CORNELL"); - String requestBody = objectMapper.writeValueAsString(requestBodyDTO); - return performEnrollmentCall(requestBodyDTO.getPartnerCode(), requestBody); + String payload = null; + try { + payload = objectMapper.writeValueAsString(requestBodyDTO); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + return performEnrollmentCall(cbServerProperties.cornellPartnerCode,payload); } private Map formUrlMapForEnrollment() { @@ -148,7 +118,7 @@ private Map formUrlMapForEnrollment() { return urlMap; } - private JsonNode performEnrollmentCall(String partnerCode, String requestBody) { + public JsonNode performEnrollmentCall(String partnerCode, String requestBody) { log.info("calling service locator for getting {} enrollment list", partnerCode); String url = cbServerProperties.getServiceLocatorHost() + cbServerProperties.getServiceLocatorFixedUrl(); HttpHeaders headers = new HttpHeaders(); @@ -165,7 +135,7 @@ private JsonNode performEnrollmentCall(String partnerCode, String requestBody) { JsonNode jsonData = jsonNode.path("responseData").get("enrollments"); jsonData.forEach( eachContentData -> { - callCornellEnrollmentAPI(partnerCode, eachContentData); + callEnrollmentAPI(partnerCode, eachContentData); }); return jsonData; } else { diff --git a/src/main/java/com/igot/cios/scheduler/CourseScheduler.java b/src/main/java/com/igot/cios/scheduler/CourseScheduler.java index 3dce78b..ca6820f 100644 --- a/src/main/java/com/igot/cios/scheduler/CourseScheduler.java +++ b/src/main/java/com/igot/cios/scheduler/CourseScheduler.java @@ -13,16 +13,30 @@ public class CourseScheduler { @Autowired - CourseSchedulerService courseSchedulerService; + CornellSchedulerService cornellSchedulerService; + + @Autowired + CourseraSchedulerService courseraSchedulerService; @Value("${scheduler.enabled}") private boolean schedulerEnabled; + @Value("${coursera.scheduler.enabled}") + private boolean courseraSchedulerEnabled; + @Scheduled(cron = "${scheduler.cron}") - private void callEnrollmentApi() throws JsonProcessingException { + private void callCornellEnrollmentApi() throws JsonProcessingException{ if (schedulerEnabled) { - log.info("CourseScheduler :: callEnrollmentApi"); - courseSchedulerService.loadCornellEnrollment(); + log.info("CourseScheduler :: callCornellEnrollmentApi"); + cornellSchedulerService.loadEnrollment(); + } + } + + @Scheduled(cron = "${coursera.scheduler.cron}") + private void callCourseraEnrollmentApi() throws JsonProcessingException { + if (courseraSchedulerEnabled) { + log.info("CourseScheduler :: callCourseraEnrollmentApi"); + courseraSchedulerService.loadEnrollment(); } } } diff --git a/src/main/java/com/igot/cios/scheduler/CourseraSchedulerService.java b/src/main/java/com/igot/cios/scheduler/CourseraSchedulerService.java new file mode 100644 index 0000000..500caad --- /dev/null +++ b/src/main/java/com/igot/cios/scheduler/CourseraSchedulerService.java @@ -0,0 +1,151 @@ +package com.igot.cios.scheduler; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; +import com.igot.cios.dto.RequestBodyDTO; +import com.igot.cios.exception.CiosContentException; +import com.igot.cios.kafka.KafkaProducer; +import com.igot.cios.plugins.DataTransformUtility; +import com.igot.cios.util.CbServerProperties; +import com.igot.cios.util.Constants; +import com.igot.cios.util.PayloadValidation; +import com.igot.cios.util.transactional.cassandrautils.CassandraOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.*; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; +import org.springframework.web.client.RestTemplate; + +import java.text.SimpleDateFormat; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.util.*; + +@Slf4j +@Service +public class CourseraSchedulerService implements SchedulerInterface { + @Autowired + private ObjectMapper objectMapper; + @Autowired + KafkaProducer kafkaProducer; + @Autowired + PayloadValidation payloadValidation; + @Autowired + RestTemplate restTemplate; + @Autowired + private CbServerProperties cbServerProperties; + @Autowired + private CassandraOperation cassandraOperation; + @Autowired + private DataTransformUtility dataTransformUtility; + + @Override + public JsonNode loadEnrollment() { + RequestBodyDTO requestBodyDTO = new RequestBodyDTO(); + requestBodyDTO.setServiceCode(cbServerProperties.getCourseraEnrollmentServiceCode()); + requestBodyDTO.setUrlMap(formUrlMapForEnrollment()); + String payload = null; + try { + payload = objectMapper.writeValueAsString(requestBodyDTO); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + return performEnrollmentCall(cbServerProperties.courseraPartnerCode, payload); + } + + private Map formUrlMapForEnrollment() { + LocalDateTime currentDateTime = LocalDateTime.now(); + LocalDateTime previousDate = currentDateTime.minusDays(cbServerProperties.getCourseraDateRange()); + ZonedDateTime zonedDateTime = previousDate.atZone(ZoneId.of("UTC")); + long timestamp = zonedDateTime.toInstant().getEpochSecond(); + long currentMillis = System.currentTimeMillis(); + long timestampWithoutMillis = (currentMillis / 1000) * 1000; + Map urlMap = new HashMap<>(); + urlMap.put("limit", cbServerProperties.getCourseraEnrollmentListLimit()); + urlMap.put("start", "0"); + urlMap.put("completedAtBefore", String.valueOf(timestampWithoutMillis)); + urlMap.put("completedAtAfter", String.valueOf(timestamp)); + return urlMap; + } + + @Override + public JsonNode performEnrollmentCall(String partnerCode, String requestBody) { + log.info("calling service locator for getting {} enrollment list", partnerCode); + String url = cbServerProperties.getServiceLocatorHost() + cbServerProperties.getServiceLocatorFixedUrl(); + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + HttpEntity entity = new HttpEntity<>(requestBody, headers); + ResponseEntity response = restTemplate.exchange( + url, + HttpMethod.POST, + entity, + Object.class + ); + if (response.getStatusCode().is2xxSuccessful()) { + JsonNode jsonNode = objectMapper.valueToTree(response.getBody()); + JsonNode jsonData = jsonNode.path("responseData").get("elements"); + jsonData.forEach( + eachContentData -> { + callEnrollmentAPI(partnerCode, eachContentData); + }); + return jsonData; + } else { + throw new RuntimeException("Failed to retrieve externalId. Status code: " + response.getStatusCodeValue()); + } + } + + @Override + public void callEnrollmentAPI(String partnerCode, JsonNode rawContentData) { + try { + log.info("CourseSchedulerService::callCourseraEnrollmentAPI"); + if (rawContentData.get("contentType").asText().equalsIgnoreCase("Specialization") && rawContentData.get("isCompleted").asBoolean()) { + JsonNode entity = dataTransformUtility.fetchPartnerInfoUsingApi(partnerCode); + if (!entity.path("transformProgressViaApi").isMissingNode()) { + List contentJson = objectMapper.convertValue(entity.get("transformProgressViaApi"), new TypeReference>() { + }); + JsonNode transformData = dataTransformUtility.transformData(rawContentData, contentJson); + String extCourseId = transformData.get("courseid").asText(); + String partnerId = entity.get("id").asText(); + JsonNode result = dataTransformUtility.callCiosReadApi(extCourseId, partnerId); + String courseId = result.path("content").get("contentId").asText(); + String[] parts = transformData.get("userid").asText().split("@"); + ((ObjectNode) transformData).put("userid", parts[0]); + String userId = transformData.get("userid").asText(); + log.info("courseId and userid {} {}", courseId, userId); + Map propertyMap = new HashMap<>(); + propertyMap.put("userid", userId); + propertyMap.put("courseid", courseId); + propertyMap.put("progress", 100); + List> listOfMasterData = cassandraOperation.getRecordsByProperties(Constants.KEYSPACE_SUNBIRD_COURSES, Constants.TABLE_USER_EXTERNAL_ENROLMENTS, propertyMap, null); + if (CollectionUtils.isEmpty(listOfMasterData)) { + Long date = Long.valueOf(transformData.get("completedon").asText()); + String formatedDate = updateDateFormatFromTimestamp(date); + ((ObjectNode) transformData).put("completedon", formatedDate); + ((ObjectNode) transformData).put("partnerCode", partnerCode); + ((ObjectNode) transformData).put("partnerId", entity.get("id").asText()); + payloadValidation.validatePayload(Constants.PROGRESS_DATA_VALIDATION_FILE, transformData); + kafkaProducer.push(cbServerProperties.getTopic(), transformData); + } else { + log.info("Progress updated 100 for user {}", userId); + } + } else { + throw new CiosContentException(Constants.ERROR, "please update transformProgressJson in content partner db for partnerCode " + partnerCode, HttpStatus.INTERNAL_SERVER_ERROR); + } + } + } catch (Exception e) { + log.error("error while processing", e); + throw new CiosContentException(Constants.ERROR, e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); + } + } + + private String updateDateFormatFromTimestamp(Long completedon) { + Date date = new Date(completedon); + SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); + return sdf.format(date); + } +} diff --git a/src/main/java/com/igot/cios/scheduler/SchedulerInterface.java b/src/main/java/com/igot/cios/scheduler/SchedulerInterface.java new file mode 100644 index 0000000..02fde57 --- /dev/null +++ b/src/main/java/com/igot/cios/scheduler/SchedulerInterface.java @@ -0,0 +1,9 @@ +package com.igot.cios.scheduler; + +import com.fasterxml.jackson.databind.JsonNode; + +public interface SchedulerInterface { + JsonNode loadEnrollment(); + JsonNode performEnrollmentCall(String partnerCode,String requestBody); + void callEnrollmentAPI(String partnerCode, JsonNode rawContentData); +} diff --git a/src/main/java/com/igot/cios/util/CbServerProperties.java b/src/main/java/com/igot/cios/util/CbServerProperties.java index 5e1ff91..1ff6cc3 100644 --- a/src/main/java/com/igot/cios/util/CbServerProperties.java +++ b/src/main/java/com/igot/cios/util/CbServerProperties.java @@ -73,4 +73,22 @@ public class CbServerProperties { @Value("${cios.content.cloud.folder.name}") private String ciosContentFileCloudFolderName; + + @Value("${cornell.partner.code}") + public String cornellPartnerCode; + + @Value("${coursera.partner.code}") + public String courseraPartnerCode; + + @Value("${coursera.enrollment.service.code}") + private String courseraEnrollmentServiceCode; + + @Value("${coursera.enrollment.list.limit}") + private String courseraEnrollmentListLimit; + + @Value("${coursera.enrollment.list.course_type}") + private String courseraEnrollmentListCourseType; + + @Value("${coursera.date.range}") + private Long courseraDateRange; } diff --git a/src/main/resources/Transformation/CourseraApiProgress.json b/src/main/resources/Transformation/CourseraApiProgress.json new file mode 100644 index 0000000..a6552e5 --- /dev/null +++ b/src/main/resources/Transformation/CourseraApiProgress.json @@ -0,0 +1,10 @@ +[ + { + "operation": "shift", + "spec": { + "email": "userid", + "contentId": "courseid", + "completedAt": "completedon" + } + } +] \ No newline at end of file diff --git a/src/main/resources/Transformation/UpgradApiProgress.json b/src/main/resources/Transformation/UpgradApiProgress.json new file mode 100644 index 0000000..e835bbb --- /dev/null +++ b/src/main/resources/Transformation/UpgradApiProgress.json @@ -0,0 +1,10 @@ +[ + { + "operation": "shift", + "spec": { + "student": "userid", + "course": "courseid", + "completion_date": "completedon" + } + } +] \ No newline at end of file diff --git a/src/main/resources/Transformation/cornellApiProgress.json b/src/main/resources/Transformation/cornellApiProgress.json new file mode 100644 index 0000000..13e8c07 --- /dev/null +++ b/src/main/resources/Transformation/cornellApiProgress.json @@ -0,0 +1,10 @@ +[ + { + "operation": "shift", + "spec": { + "StudentId": "userid", + "LessonId": "courseid", + "completion_date": "completedon" + } + } +] \ No newline at end of file diff --git a/src/main/resources/Transformation/courseraApiContent.json b/src/main/resources/Transformation/courseraApiContent.json new file mode 100644 index 0000000..5e0a6d8 --- /dev/null +++ b/src/main/resources/Transformation/courseraApiContent.json @@ -0,0 +1,40 @@ +[ + { + "spec": { + "responseData": { + "paging": { + "total": "totalCount" + }, + "elements": { + "*": { + "name": "data[&1].name", + "programs": { + "*": { + "contentUrl": "data[&3].redirectUrl" + } + }, + "contentId": "data[&1].externalId", + "description": "data[&1].description", + "extraMetadata": { + "definition": { + "tagline": "data[&3].topic", + "promoPhoto": "data[&3].appIcon" + } + } + } + } + } + }, + "operation": "shift" + }, + { + "spec": { + "data": { + "*": { + "redirectUrl": "=concat('https://www.coursera.org/programs/learning-program-4spdd?productId=', @(1,externalId), '&productType=Specialization&showMiniModal=true&attemptSSOLogin=true')" + } + } + }, + "operation": "modify-overwrite-beta" + } +] \ No newline at end of file diff --git a/src/main/resources/Transformation/upgrad.json b/src/main/resources/Transformation/upgrad.json index 02d0ce0..545b9d6 100644 --- a/src/main/resources/Transformation/upgrad.json +++ b/src/main/resources/Transformation/upgrad.json @@ -8,7 +8,7 @@ "Duration": "content.duration", "long description": "content.description", "imageUrl": "content.appIcon", - "redirectUrl": "content.redirectUrl" + "Redirection URL": "content.redirectUrl" } } ] diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index f12a1fa..94872f8 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -51,11 +51,11 @@ cassandra.config.host= #---------------Service registry configuration-------------- service.locator.host=http://localhost:8096 -service.locator.fixedurl=/serviceregistry/api/v1/callExternalApi +service.locator.fixedurl=/serviceregistry/v1/callExternalApi #---------------cornell configuration---------------- cornell.enrollment.service.code=cornell-enrollment-list -scheduler.enabled=true +scheduler.enabled=false scheduler.fixedRate=600000 scheduler.cron=0 13 17 * * * cornell.enrollment.list.limit=10 @@ -97,3 +97,10 @@ content.onboarding.consumer.group=cios.content.onboard_group spring.main.allow-circular-references=true +coursera.enrollment.list.limit=1000 +coursera.enrollment.list.course_type=lesson +coursera.date.range=10 +coursera.enrollment.service.code=coursera-enrollment-api +coursera.scheduler.cron=0 */2 * * * * +coursera.scheduler.enabled=false +