Skip to content

Commit

Permalink
4.8.16 dev (#70)
Browse files Browse the repository at this point in the history
* Added New Flink Job for the Certificate Generation Utility

* KB-5880 | Content creator cant see the details when clicked on  Edit live Assessment (#66)

1. Hardcoded value of the compatibility level is removed.

* Added new certificate generator utility

* Modified the Kafka Topic for common certificate

Modified the Kafka Topic for common certificate

* Modified the conf file

* Remove Conflict

* Common Certificate Utility Folder Changes

* Fixed the compilation issue

* Added Troubleshooting Log

* Added entry for common-certificate-generator-utility

Added entry for common-certificate-generator-utility

* Renamed TaskFile

* Renamed the TaskName to Unique Identification

* Added Troubleshooting Logging

* Added different package

* NulPointer Exception

* Added New Parameter for the Certificate

* Conventional Correction

* Modified table to convention conf table

* remove un-wanted commits

---------

Co-authored-by: saipradeep_ravipati <[email protected]>
Co-authored-by: tarentomaheshvakkund <[email protected]>
  • Loading branch information
3 people authored Aug 9, 2024
1 parent 1ae5d56 commit 51c2d95
Show file tree
Hide file tree
Showing 16 changed files with 33 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ object CertificateFactory {
if (StringUtils.isNotEmpty(certModel.courseName)) {
val trainingEvidence: TrainingEvidence = TrainingEvidence(certificateConfig.contextUrl,
id = certificateConfig.evidenceUrl,
name = certModel.courseName)
name = certModel.courseName,
extendedName=certModel.courseExtendedName)
certificateExtension.evidence = Option.apply(trainingEvidence)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ object JsonKeys {
val CERTIFICATE: String = "certificate"
val RECIPIENT_NAME: String = "recipientName"
val COURSE_NAME: String = "courseName"
val COURSE_NAME_EXTENDED: String = "courseNameExtended"
val NAME: String = "name"
val HTML_TEMPLATE: String = "htmlTemplate"
val ISSUER: String = "issuer"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ case class SignatoryExtension(@JsonProperty("@context") context: String, related
case class TrainingEvidence(@JsonProperty("@context") context: String, related: Option[Array[String]] = None,
version: Option[String] = None, endorsement: Option[Endorsement] = None, id: String,
`type`: Array[String] = Array("Evidence", "Extension", "extensions:TrainingEvidence"),
narrative: Option[String] = None, name: String, description: Option[String] = None,
narrative: Option[String] = None, name: String,extendedName: String, description: Option[String] = None,
genre: Option[String] = None, audience: Option[String] = None, subject: Option[String] = None
, trainedBy: Option[String] = None, duration: Option[Duration] = None, session: Option[String] = None)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package org.sunbird.incredible.processor

import org.sunbird.incredible.pojos.ob.{Criteria, Issuer, SignatoryExtension}

case class CertModel(courseName: String, recipientName: String, recipientId: Option[String] = None, recipientEmail: Option[String] = None, recipientPhone: Option[String] = None
case class CertModel(courseName: String,courseExtendedName:String, recipientName: String, recipientId: Option[String] = None, recipientEmail: Option[String] = None, recipientPhone: Option[String] = None
, certificateName: String, certificateDescription: Option[String] = None, certificateLogo: Option[String] = None, issuedDate: String, issuer: Issuer,
validFrom: Option[String] = None, expiry: Option[String] = None, signatoryList: Array[SignatoryExtension], assessedOn: Option[String] = None, identifier: String, criteria: Criteria,
keyId: String = "", tag: String = "", providerName: String)
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class VarResolver(certificateExtension: CertificateExtension) {
def getCourseName: String = if (certificateExtension.evidence.nonEmpty && StringUtils.isNotBlank(certificateExtension.evidence.get.name)) certificateExtension.evidence.get.name
else ""

def getCourseExtendedName: String = if (certificateExtension.evidence.nonEmpty && StringUtils.isNotBlank(certificateExtension.evidence.get.extendedName)) certificateExtension.evidence.get.extendedName
else ""

def getQrCodeImage: String = try {
val uri = new URI(certificateExtension.id)
val path = uri.getPath
Expand Down Expand Up @@ -77,6 +80,7 @@ class VarResolver(certificateExtension: CertificateExtension) {
put(JsonKeys.CERT_NAME, urlEncode(getCertificateName))
put(JsonKeys.CERTIFICATE_DESCIPTION, urlEncode(getCertificateDescription))
put(JsonKeys.COURSE_NAME, urlEncode(getCourseName))
put(JsonKeys.COURSE_NAME_EXTENDED, urlEncode(getCourseExtendedName))
put(JsonKeys.ISSUE_DATE, urlEncode(getIssuedDate))
put(JsonKeys.RECIPIENT_ID, urlEncode(getRecipientId))
put(JsonKeys.RECIPIENT_NAME, urlEncode(getRecipientName))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class CertificateGeneratorTest extends BaseTestSpec {
val map: util.HashMap[String, AnyRef] = new util.HashMap[String, AnyRef]()
val issuerIn: Issuer = Issuer(context = "https://staging.sunbirded.org/certs/v1/context.json", name = "issuer name", url = "url")
val signatory: SignatoryExtension = SignatoryExtension(context = "", identity = "CEO", name = "signatory name", designation = "CEO", image = "https://cdn.pixabay.com/photo/2014/11/09/08/06/signature-523237__340.jpg")
val certModel: CertModel = CertModel(courseName = "java", recipientName = "Test", certificateName = "100PercentCompletionCertificate", issuedDate = "2019-08-21",
val certModel: CertModel = CertModel(courseName = "java", courseExtendedName = "courseExtendedName", recipientName = "Test", certificateName = "100PercentCompletionCertificate", issuedDate = "2019-08-21",
issuer = issuerIn, signatoryList = Array(signatory), identifier = "8e57723e-4541-11eb-b378-0242ac130002", providerName = "Test Provider", criteria = Criteria(narrative = "Course Completion"), tag = "0131685518070087685")
val certificateGenerator = new CertificateGenerator
val certificateExtension = certificateGenerator.getCertificateExtension(certModel)
Expand All @@ -33,7 +33,7 @@ class CertificateGeneratorTest extends BaseTestSpec {
when(mockHttpUtil.post(endsWith("/sign/256"), any[String])).thenReturn(HTTPResponse(200, """{"signatureValue":"Yul8hVc3+ShzEQU/u1og7f8b0xVf2N4WyMdFgELdz74dpfMWBhZ8snsvit3JKMptyA4JKSywqUoNeAMcEmtgurqAaS7oMwMulPJnvAsx2xDCOxq/UVPZGi63zPsItP2dTahLsEJQjPyQOEoEW5KW3oefRJO066Fr/L/Y5XNg2goDhvYHoHdAkpfr/IFsQqG0hWPzKglKOwd0R+LIuv13MIywBjYg9qY6cWs9BtTSMwXyayBhm6YkLgdb0LiBD/","keyId":"256"}"""))
val issuerIn: Issuer = Issuer(context = "https://staging.sunbirded.org/certs/v1/context.json", name = "issuer name", url = "url")
val signatory: SignatoryExtension = SignatoryExtension(context = "", identity = "CEO", name = "signatory name", designation = "CEO", image = "https://cdn.pixabay.com/photo/2014/11/09/08/06/signature-523237__340.jpg")
val certModel: CertModel = CertModel(courseName = "java", recipientName = "Test", certificateName = "100PercentCompletionCertificate", issuedDate = "2019-08-21",
val certModel: CertModel = CertModel(courseName = "java", courseExtendedName = "courseExtendedName",recipientName = "Test", certificateName = "100PercentCompletionCertificate", issuedDate = "2019-08-21",
issuer = issuerIn, signatoryList = Array(signatory), identifier = "8e57723e-4541-11eb-b378-0242ac130002", providerName = "Test Provider", criteria = Criteria(narrative = "Course Completion"), keyId = "256", tag = "0131685518070087685")
val certificateGenerator = new CertificateGenerator
val certificateExtension = certificateGenerator.getCertificateExtension(certModel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class SvgGeneratorTest extends BaseTestSpec {
val map: util.HashMap[String, AnyRef] = new util.HashMap[String, AnyRef]()
val issuerIn: Issuer = Issuer(context = "https://staging.sunbirded.org/certs/v1/context.json", name = "issuer name", url = "url")
val signatory: SignatoryExtension = SignatoryExtension(context = "", identity = "CEO", name = "signatory name", designation = "CEO", image = "https://cdn.pixabay.com/photo/2014/11/09/08/06/signature-523237__340.jpg")
val certModel: CertModel = CertModel(courseName = "java", recipientName = "Test", certificateName = "100PercentCompletionCertificate", issuedDate = "2019-08-21",
val certModel: CertModel = CertModel(courseName = "java", courseExtendedName = "courseExtendedName" ,recipientName = "Test", certificateName = "100PercentCompletionCertificate", issuedDate = "2019-08-21",
issuer = issuerIn, signatoryList = Array(signatory), identifier = "8e57723e-4541-11eb-b378-0242ac130002", providerName = "Test Provider", criteria = Criteria(narrative = "Course Completion"), tag = "0131685518070087685")
val certificateGenerator = new CertificateGenerator
val certificateExtension = certificateGenerator.getCertificateExtension(certModel)
Expand All @@ -27,7 +27,7 @@ class SvgGeneratorTest extends BaseTestSpec {
val map: util.HashMap[String, AnyRef] = new util.HashMap[String, AnyRef]()
val issuerIn: Issuer = Issuer(context = "https://staging.sunbirded.org/certs/v1/context.json", name = "issuer name", url = "url")
val signatory: SignatoryExtension = SignatoryExtension(context = "", identity = "CEO", name = "signatory name", designation = "CEO", image = "https://cdn.pixabay.com/photo/2014/11/09/08/06/signature-523237__340.jpg")
val certModel: CertModel = CertModel(courseName = "java", recipientName = "Test", certificateName = "100PercentCompletionCertificate", issuedDate = "2019-08-21",
val certModel: CertModel = CertModel(courseName = "java", courseExtendedName = "courseExtendedName" , recipientName = "Test", certificateName = "100PercentCompletionCertificate", issuedDate = "2019-08-21",
issuer = issuerIn, signatoryList = Array(signatory), identifier = "8e57723e-4541-11eb-b378-0242ac130002", providerName = "Test Provider", criteria = Criteria(narrative = "Course Completion"), tag = "0131685518070087685")
val certificateGenerator = new CertificateGenerator
val certificateExtension = certificateGenerator.getCertificateExtension(certModel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class CertMapper(certConfig: CertificateConfig) {
validFrom = Option.apply(data.getOrElse(JsonKeys.VALID_FROM, null).asInstanceOf[String]),
issuer = getIssuer(certReq),
courseName = certReq.courseName,
courseExtendedName="",
issuedDate = issuedDate,
certificateLogo = Option.apply(certReq.logo),
certificateDescription = Option.apply(certReq.certificateDescription),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ class CertificateGeneratorFunction(config: CertificateGeneratorConfig, httpUtil:
override def processElement(event: Event,
context: KeyedProcessFunction[String, Event, String]#Context,
metrics: Metrics): Unit = {
println("I am ****** OLD Collection Certificate Generator ****SAI-OLD**** Certificate data: " + event)
metrics.incCounter(config.totalEventsCount)
try {
val certValidator = new CertValidator()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ service {

lms-cassandra {
keyspace = "sunbird_courses"
user_enrolments.table = "user_external_enrolments_t1"
course_batch.table = "course_batch"
user_enrolments.table = "user_external_enrolments"
course_batch.table = "ext_config"
ext_config.table = "ext_config"
sbkeyspace = "sunbird"
certreg.table ="cert_registry"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class Event(eventMap: java.util.Map[String, Any], partition: Int, offset: Long)

def courseName: String = readOrDefault[String]("edata.courseName", "")

def courseExtendedName: String = readOrDefault[String]("edata.courseNameExtended", "")

def name: String = readOrDefault[String]("edata.name", "")

def issuedDate: String = readOrDefault[String]("edata.issuedDate", "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class CertMapper(certConfig: CertificateConfig) {
validFrom = Option.apply(data.getOrElse(JsonKeys.VALID_FROM, null).asInstanceOf[String]),
issuer = getIssuer(certReq),
courseName = certReq.courseName,
courseExtendedName = certReq.courseExtendedName,
issuedDate = issuedDate,
certificateLogo = Option.apply(certReq.logo),
certificateDescription = Option.apply(certReq.certificateDescription),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ class CertValidator() {
}

def isNotIssued(event: Event)(config: CertificateGeneratorConfig, metrics: Metrics, cassandraUtil: CassandraUtil):Boolean = {
logger.info("Troubleshooting log SAI : 1234")
val query = QueryBuilder.select( "issued_certificates").from(config.dbKeyspace, config.dbEnrollmentTable)
.where(QueryBuilder.eq(config.dbUserId, event.eData.getOrElse("userId", "")))
.and(QueryBuilder.eq(config.dbCourseId, event.related.getOrElse("courseId", "")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import org.sunbird.job.certutil.domain._
import org.sunbird.job.certutil.exceptions.ServerException
import org.sunbird.job.certutil.task.CertificateGeneratorConfig
import org.sunbird.job.exception.InvalidEventException
import org.sunbird.job.util.{CassandraUtil, ElasticSearchUtil, HttpUtil, ScalaJsonUtil, JSONUtil}
import org.sunbird.job.util.{CassandraUtil, ElasticSearchUtil, HttpUtil, JSONUtil, ScalaJsonUtil}

import org.sunbird.job.{BaseProcessKeyedFunction, Metrics}

import java.io.{File, IOException}
Expand All @@ -29,7 +30,8 @@ import java.util
import java.util.stream.Collectors
import java.util.{Base64, Date, UUID}
import scala.collection.JavaConverters._
import org.sunbird.job.certutil.domain.{ BEJobRequestEvent, EventObjectCourseCertificate}
import org.sunbird.job.certutil.domain.{BEJobRequestEvent, EventObjectCourseCertificate}


class CertificateGeneratorFunction(config: CertificateGeneratorConfig, httpUtil: HttpUtil, storageService: StorageService, @transient var cassandraUtil: CassandraUtil = null)
extends BaseProcessKeyedFunction[String, Event, String](config) {
Expand Down Expand Up @@ -64,7 +66,7 @@ class CertificateGeneratorFunction(config: CertificateGeneratorConfig, httpUtil:
override def processElement(event: Event,
context: KeyedProcessFunction[String, Event, String]#Context,
metrics: Metrics): Unit = {
println("I am ****** NEW Common Collection Certificate Generator ***SAI-NEW***** Certificate data: " + event)

metrics.incCounter(config.totalEventsCount)
try {
val certValidator = new CertValidator()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ class NotifierFunction(config: CertificateGeneratorConfig, httpUtil: HttpUtil, @
try {
val userResponse: Map[String, AnyRef] = getUserDetails(metaData.userId)(metrics) // call user Service
if (null != userResponse && userResponse.nonEmpty) {
val primaryFields = Map(config.courseId.toLowerCase() -> "DEFAULT")
val primaryFields = Map(config.id.toLowerCase() -> "common_cert_req")
val row = getNotificationTemplates(primaryFields, metrics)
val certTemplate = row.getMap(config.cert_templates, com.google.common.reflect.TypeToken.of(classOf[String]),
TypeTokens.mapOf(classOf[String], classOf[String]))
val certTemplate = row.getMap(config.value, com.google.common.reflect.TypeToken.of(classOf[String]),
TypeTokens.mapOf(classOf[String], classOf[String]))
val url = config.learnerServiceBaseUrl + config.newEmailTemplateNotificationEndPoint
if (certTemplate != null && StringUtils.isNotBlank(metaData.templateId) &&
certTemplate.containsKey(metaData.templateId) &&
Expand Down Expand Up @@ -126,7 +126,7 @@ class NotifierFunction(config: CertificateGeneratorConfig, httpUtil: HttpUtil, @
*/
private def getNotificationTemplates(columns: Map[String, AnyRef], metrics: Metrics): Row = {
val selectWhere: Select.Where = QueryBuilder.select().all()
.from(config.dbKeyspace, config.dbCourseBatchTable).
.from(config.dbKeyspace, config.extConfTable).
where()
columns.map(col => {
col._2 match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class CertificateGeneratorConfig(override val config: Config) extends BaseJobCon
val dbUserId = "userid"
val active: String = "active"
val issuedCertificates: String = "issued_certificates"
val extConfTable: String = config.getString("lms-cassandra.ext_config.table")


// Metric List
val totalEventsCount = "total-events-count"
Expand Down Expand Up @@ -145,6 +147,8 @@ class CertificateGeneratorConfig(override val config: Config) extends BaseJobCon
val courseName = "courseName"
val templateId = "templateId"
val cert_templates = "cert_templates"
val value = "value"

val courseBatch = "CourseBatch"
val l1 = "l1"
val id = "id"
Expand Down

0 comments on commit 51c2d95

Please sign in to comment.