Skip to content

Commit

Permalink
Added New Parameter for the Certificate
Browse files Browse the repository at this point in the history
  • Loading branch information
saipradeep_ravipati committed Aug 7, 2024
1 parent c3b0168 commit d872fb4
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 11 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 @@ -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 @@ -2,7 +2,6 @@ package org.sunbird.job.certutil.functions

import java.time.LocalDateTime
import java.time.format.DateTimeFormatter

import org.apache.commons.lang3.StringUtils
import org.sunbird.incredible.pojos.ob.{Criteria, Issuer, SignatoryExtension}
import org.sunbird.incredible.pojos.valuator.{ExpiryDateValuator, IssuedDateValuator}
Expand All @@ -28,6 +27,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 @@ -19,7 +19,7 @@ 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 +29,7 @@ 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

0 comments on commit d872fb4

Please sign in to comment.