Skip to content

#000 fix: Pre-render certificate SVG (printUri) so RC serves the filled template - #2

Open
likhithThammegowda wants to merge 2 commits into
spark-v1.0.2-workfrom
spark-v1.0.3-work
Open

#000 fix: Pre-render certificate SVG (printUri) so RC serves the filled template#2
likhithThammegowda wants to merge 2 commits into
spark-v1.0.2-workfrom
spark-v1.0.3-work

Conversation

@likhithThammegowda

Copy link
Copy Markdown

Problem

Generated certificates render with unsubstituted ${…} placeholders (${recipientName}, ${courseName}, ${maxScore}, ${rmNumber}, ${issuedDate}, ${qrCodeImage}) instead of the actual values.

Root cause

CertificateGeneratorFunction.generateRequest sends only the raw templateUrl + a thin credential (recipientName/trainingName/trainingId). sunbird-rc-certificate-api re-renders the raw template and leaves the variables unfilled. The incredible renderer SvgGenerator.generate (resolves all vars via VarResolver#getCertMetaData, incl. Aastrika fields) was never called in the RC flow.

Fix

  • Added generatePrintUri(certModel, templateUrl): builds CertificateExtension, generates QR, calls SvgGenerator.generate for the fully-substituted SVG.
  • generateRequest sends it as printUri in the RC create request so RC stores/serves the filled cert.
  • Fail-safe: any render/QR error returns empty and degrades to the previous templateUrl-only behaviour.

Verify before merge

  • Build + run a real completion; cert should show real name/course/date (no ${…}).
  • Confirm RC download serves the stored printUri (method getPrintUri); compare vs a working prod cert record.

Single file: collection-certificate-generator/.../certgen/functions/CertificateGeneratorFunction.scala.

…rves the filled template

The RC create flow (generateRequest) only sent the raw templateUrl + a thin
credential (recipientName/trainingName/trainingId). The RC certificate-api
then re-rendered the raw SVG and left every ${...} template variable
unsubstituted (recipientName, courseName, maxScore, rmNumber, issuedDate,
qrCodeImage). The incredible SvgGenerator (which correctly resolves all these
vars via VarResolver#getCertMetaData, including the Aastrika-specific fields)
was never wired into the RC path.

Fix: render the fully-substituted SVG on the generator side and send it as
printUri in the RC create request. Fail-safe: any render/QR error returns ""
and the request degrades to the previous templateUrl-only behaviour.
…ves the filled printUri

The RC-only generator never wrote new certificates to sunbird.cert_registry, so
cert-registry downloadV2 fell to its fallback branch and re-rendered the raw
templateUrl (which cannot fill the incredible ${..} placeholders) -> blank cert.

Restore the old-format write: render the SVG once, reuse it for the RC create
request and POST it to cert-registry /certs/v2/registry/add (id, jsonData.printUri,
accessCode, recipient, related). Download then hits Branch 1 and returns the stored
filled printUri, matching prod. The registry write is non-fatal so issuance is not
blocked on failure. generatePrintUri now also returns the QR accessCode.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant