Skip to content

Commit

Permalink
Feedback Impl by DL team (#514)
Browse files Browse the repository at this point in the history
* Updated the digiLocker Impl for metaData

* DigiLocker Impl for Updated code
  • Loading branch information
Sahil-tarento authored Mar 21, 2024
1 parent 54628ba commit f86fc18
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package org.sunbird.digilocker.model;

import java.util.Date;

public class CertificateAddInfoDTO {

private String certificateName;
private String documentName;
private String documentInfo;
private String certificateId;
private Date certificateIssueOn;
private String certificateIssueOn;

private String userName;

Expand Down Expand Up @@ -58,11 +56,11 @@ public void setCertificateId(String certificateId) {
this.certificateId = certificateId;
}

public Date getCertificateIssueOn() {
public String getCertificateIssueOn() {
return certificateIssueOn;
}

public void setCertificateIssueOn(Date certificateIssueOn) {
public void setCertificateIssueOn(String certificateIssueOn) {
this.certificateIssueOn = certificateIssueOn;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package org.sunbird.digilocker.model;

import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import org.sunbird.digilocker.model.certificateMetaData.CertificateMetaData;

import java.io.Serializable;

@JacksonXmlRootElement(localName = "CertificateInfo")
public class CertificateInfo implements Serializable {

private CertificateMetaData certificateMetaData;
Expand All @@ -13,7 +15,7 @@ public CertificateInfo() {
this.certificateMetaData = new CertificateMetaData();
}

@JacksonXmlProperty(localName = "Certificate", namespace = "http://tempuri.org/")
@JacksonXmlProperty(localName = "Certificate")
public CertificateMetaData getCertificateMetaData() {
return certificateMetaData;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public CertificateData() {
this.certificate = new Certificate();
this.participationCertificate = new ParticipationCertificate();
}
@JacksonXmlProperty(localName = "Certificate", namespace = "http://tempuri.org/")
@JacksonXmlProperty(localName = "Certificate")
public Certificate getCertificate() {
return certificate;
}
Expand All @@ -21,7 +21,7 @@ public void setCertificate(Certificate certificate) {
this.certificate = certificate;
}

@JacksonXmlProperty(localName = "ParticipationCertificate", namespace = "http://tempuri.org/")
@JacksonXmlProperty(localName = "ParticipationCertificate")
public ParticipationCertificate getParticipationCertificate() {
return participationCertificate;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class CertificateIssuedBy {
public CertificateIssuedBy() {
this.organization = new Organization();
}
@JacksonXmlProperty(localName = "Organization", namespace = "http://tempuri.org/")
@JacksonXmlProperty(localName = "Organization")
public Organization getOrganization() {
return organization;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class CertificateIssuedTo {
public CertificateIssuedTo() {
this.personInfo = new PersonInfo();
}
@JacksonXmlProperty(localName = "Person", namespace = "http://tempuri.org/")
@JacksonXmlProperty(localName = "Person")
public PersonInfo getPersonInfo() {
return personInfo;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;

import java.util.Date;

@JacksonXmlRootElement(localName = "Certificate", namespace = "http://tempuri.org/")
@JacksonXmlRootElement(localName = "Certificate")
public class CertificateMetaData {
private String language;
private String name;
Expand All @@ -15,7 +13,7 @@ public class CertificateMetaData {
private String expiryDate;
private String validFromDate;
private String issuedAt;
private Date issueDate;
private String issueDate;
private String status;
private CertificateIssuedBy issuedBy;
private CertificateIssuedTo issuedTo;
Expand Down Expand Up @@ -112,11 +110,11 @@ public void setIssuedAt(String issuedAt) {
}

@JacksonXmlProperty(isAttribute = true)
public Date getIssueDate() {
public String getIssueDate() {
return issueDate;
}

public void setIssueDate(Date issueDate) {
public void setIssueDate(String issueDate) {
this.issueDate = issueDate;
}

Expand All @@ -129,7 +127,7 @@ public void setStatus(String status) {
this.status = status;
}

@JacksonXmlProperty(localName = "IssuedBy", namespace = "http://tempuri.org/")
@JacksonXmlProperty(localName = "IssuedBy")
public CertificateIssuedBy getIssuedBy() {
return issuedBy;
}
Expand All @@ -138,7 +136,7 @@ public void setIssuedBy(CertificateIssuedBy issuedBy) {
this.issuedBy = issuedBy;
}

@JacksonXmlProperty(localName = "IssuedTo", namespace = "http://tempuri.org/")
@JacksonXmlProperty(localName = "IssuedTo")
public CertificateIssuedTo getIssuedTo() {
return issuedTo;
}
Expand All @@ -147,7 +145,7 @@ public void setIssuedTo(CertificateIssuedTo issuedTo) {
this.issuedTo = issuedTo;
}

@JacksonXmlProperty(localName = "CertificateData", namespace = "http://tempuri.org/")
@JacksonXmlProperty(localName = "CertificateData")
public CertificateData getCertificateData() {
return certificateData;
}
Expand All @@ -156,7 +154,7 @@ public void setCertificateData(CertificateData certificateData) {
this.certificateData = certificateData;
}

@JacksonXmlProperty(localName = "Signature", namespace = "http://tempuri.org/")
@JacksonXmlProperty(localName = "Signature")
public String getSignature() {
return signature;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void setType(String type) {
this.type = type;
}

@JacksonXmlProperty(localName = "Address", namespace = "http://tempuri.org/")
@JacksonXmlProperty(localName = "Address")
public Address getAddress() {
return address;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void setTournamentName(String tournamentName) {
this.tournamentName = tournamentName;
}

@JacksonXmlProperty(localName = "Participant", namespace = "http://tempuri.org/")
@JacksonXmlProperty(localName = "Participant")
public Participant getParticipant() {
return participant;
}
Expand All @@ -54,7 +54,7 @@ public void setParticipant(Participant participant) {
this.participant = participant;
}

@JacksonXmlProperty(localName = "Tournament", namespace = "http://tempuri.org/")
@JacksonXmlProperty(localName = "Tournament")
public Tournament getTournament() {
return tournament;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public void setEmail(String email) {
this.email = email;
}

@JacksonXmlProperty(localName = "Address", namespace = "http://tempuri.org/")
@JacksonXmlProperty(localName = "Address")
public Address getAddress() {
return address;
}
Expand All @@ -197,7 +197,7 @@ public void setAddress(Address address) {
this.address = address;
}

@JacksonXmlProperty(localName = "Photo", namespace = "http://tempuri.org/")
@JacksonXmlProperty(localName = "Photo")
public Photo getPhoto() {
return photo;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public PullURIResponse generateURIResponse(String digiLockerHmac, String request
responseStatus.setTs(dateFormat.format(new Date()));
if (!validateRequest(digiLockerHmac, requestBody)) {
responseStatus.setStatus("0");
response.getDocDetails().setDocContent("Document is not available.");
logger.error("Not able to validate the request for hmac: " + digiLockerHmac + " requestBody:" + requestBody);
return response;
}
Expand Down Expand Up @@ -124,7 +125,6 @@ public PullURIResponse generateURIResponse(String digiLockerHmac, String request
issuedTo.setPersons(persons);
docDetails.setIssuedTo(issuedTo);
String docId = request.getDocDetails().getCertificateAccessCode() + StringUtils.substring(userId, 0, 4);
docDetails.setURI(serverProperties.getDigiLockerIssuerId() + "-" + request.getDocDetails().getDocType() + "-" + docId);
Map<String, Object> dockerLookUpInfo = new HashMap<>();
dockerLookUpInfo.put(Constants.DOC_ID, docId);
dockerLookUpInfo.put(Constants.DIGI_LOCKER_ID, request.getDocDetails().getDigiLockerId());
Expand All @@ -134,7 +134,7 @@ public PullURIResponse generateURIResponse(String digiLockerHmac, String request
userEnrollment = userEnrollment.stream().filter(enroll -> ((String) enroll.get("token")).equalsIgnoreCase(certificateAccessCode)).collect(Collectors.toList());
dockerLookUpInfo.put(Constants.CERTIFICATE_ID, userEnrollment.get(0).get(Constants.IDENTIFIER));
try {
dockerLookUpInfo.put(Constants.LAST_ISSUED_ON, dateFormat.parse((String) userEnrollment.get(0).get(Constants.LAST_ISSUED_ON)));
dockerLookUpInfo.put(Constants.LAST_ISSUED_ON, simpleDateFormat.format(dateFormat.parse((String) userEnrollment.get(0).get(Constants.LAST_ISSUED_ON))));
} catch (ParseException e) {
responseStatus.setStatus("0");
logger.error("Not able to parse date");
Expand All @@ -147,20 +147,21 @@ public PullURIResponse generateURIResponse(String digiLockerHmac, String request
String content = getCertificate((String) dockerLookUpInfo.get(Constants.CERTIFICATE_ID));
if (StringUtils.isNotEmpty(content)) {
docDetails.setDocContent(content.toString());
certificateAddInfoDTO.setCertificateId((String)dockerLookUpInfo.get(Constants.CERTIFICATE_ID));
certificateAddInfoDTO.setCertificateId(certificateAccessCode);
certificateAddInfoDTO.setDocumentInfo(request.getDocDetails().getDocType());
certificateAddInfoDTO.setCertificateName((String)dockerLookUpInfo.get(Constants.CERTIFICATE_NAME));
certificateAddInfoDTO.setDocumentName(DocumentType.getValueForKey(request.getDocDetails().getDocType()));
certificateAddInfoDTO.setCertificateIssueOn((Date)dockerLookUpInfo.get(Constants.LAST_ISSUED_ON));
certificateAddInfoDTO.setCertificateIssueOn((String)dockerLookUpInfo.get(Constants.LAST_ISSUED_ON));
certificateAddInfoDTO.setUserName((String)getUserInfo.get(Constants.FIRSTNAME));
certificateAddInfoDTO.setSwd((String)getUserInfo.get(Constants.CHANNEL));
certificateAddInfoDTO.setSwdIndicator(String.valueOf(((String)getUserInfo.get(Constants.CHANNEL)).charAt(0)));
docDetails.setDataContent(encodeBytesToBase64((convertObjectToJsonBytes(addCertificateInfo(certificateAddInfoDTO)))));
docDetails.setURI(serverProperties.getDigiLockerIssuerId() + "-" + request.getDocDetails().getDocType() + "-" + docId);
responseStatus.setStatus("1");
} else {
logger.error("Not able to generate Pdf certificate for URI: " + docDetails.getURI());
responseStatus.setStatus("0");
}
responseStatus.setStatus("1");
response.setDocDetails(docDetails);
} else {
logger.error("Error while updating the document lookup table for userId: " + userId + " for request: " + request);
Expand All @@ -183,6 +184,9 @@ public PullURIResponse generateURIResponse(String digiLockerHmac, String request
logger.error("Some exception while processing the request: ", e);
responseStatus.setStatus("0");
}
if (responseStatus.getStatus().equals("0")) {
response.getDocDetails().setDocContent("Document is not available.");
}
response.setResponseStatus(responseStatus);
return response;
}
Expand All @@ -193,6 +197,7 @@ public PullDocResponse generateDocResponse(String digiLockerHmac, String request
ResponseStatus responseStatus = response.getResponseStatus();
if (!validateRequest(digiLockerHmac, requestBody)) {
responseStatus.setStatus("0");
response.getDocDetails().setDocContent("Document is not available.");
logger.error("Not able to validate the request for hmac: " + digiLockerHmac + " requestBody:" + requestBody);
return response;
}
Expand All @@ -217,24 +222,27 @@ public PullDocResponse generateDocResponse(String digiLockerHmac, String request
String content = getCertificate((String) digiLockerDocInfo.get(Constants.CERTIFICATE_ID));
if (StringUtils.isNotEmpty(content)) {
docDetails.setDocContent(content.toString());
responseStatus.setStatus("1");
Map<String, Object> getUserInfo = userUtilityService.getUserDetails(Constants.IDENTIFIER, (String)digiLockerDocInfo.get(Constants.USER_ID));
if (MapUtils.isNotEmpty(getUserInfo)) {
certificateAddInfoDTO.setCertificateId((String)digiLockerDocInfo.get(Constants.ACCESS_TOKEN));
certificateAddInfoDTO.setDocumentInfo(uri[1]);
certificateAddInfoDTO.setCertificateName((String)digiLockerDocInfo.get(Constants.CERTIFICATE_NAME));
certificateAddInfoDTO.setDocumentName(DocumentType.getValueForKey(uri[1]));
certificateAddInfoDTO.setCertificateIssueOn(simpleDateFormat.format((Date)digiLockerDocInfo.get(Constants.LAST_ISSUED_ON)));
certificateAddInfoDTO.setUserName((String)getUserInfo.get(Constants.FIRSTNAME));
certificateAddInfoDTO.setSwd((String)getUserInfo.get(Constants.CHANNEL));
certificateAddInfoDTO.setSwdIndicator(String.valueOf(((String)getUserInfo.get(Constants.CHANNEL)).charAt(0)));
docDetails.setDataContent(encodeBytesToBase64((convertObjectToJsonBytes(addCertificateInfo(certificateAddInfoDTO)))));
response.setDocDetails(docDetails);
responseStatus.setStatus("1");
} else {
logger.error("Error while getting the user Info request:" + request);
responseStatus.setStatus("0");
}
} else {
logger.error("Not able to generate Pdf certificate for URI: " + request.getDocDetails().getURI());
responseStatus.setStatus("0");
}
Map<String, Object> getUserInfo = userUtilityService.getUserDetails(Constants.IDENTIFIER, (String)digiLockerDocInfo.get(Constants.USER_ID));
if (MapUtils.isNotEmpty(getUserInfo)) {
certificateAddInfoDTO.setCertificateId((String)digiLockerDocInfo.get(Constants.CERTIFICATE_ID));
certificateAddInfoDTO.setDocumentInfo(uri[1]);
certificateAddInfoDTO.setCertificateName((String)digiLockerDocInfo.get(Constants.CERTIFICATE_NAME));
certificateAddInfoDTO.setDocumentName(DocumentType.getValueForKey(uri[1]));
certificateAddInfoDTO.setCertificateIssueOn((Date)digiLockerDocInfo.get(Constants.LAST_ISSUED_ON));
certificateAddInfoDTO.setUserName((String)getUserInfo.get(Constants.FIRSTNAME));
certificateAddInfoDTO.setSwd((String)getUserInfo.get(Constants.CHANNEL));
certificateAddInfoDTO.setSwdIndicator(String.valueOf(((String)getUserInfo.get(Constants.CHANNEL)).charAt(0)));
docDetails.setDataContent(encodeBytesToBase64((convertObjectToJsonBytes(addCertificateInfo(certificateAddInfoDTO)))));
response.setDocDetails(docDetails);
}
} else {
logger.error("Not able to find info at lookup for URI: " + request.getDocDetails().getURI());
responseStatus.setStatus("0");
Expand All @@ -243,6 +251,9 @@ public PullDocResponse generateDocResponse(String digiLockerHmac, String request
logger.error("Some exception while processing the request: ", e);
responseStatus.setStatus("0");
}
if (responseStatus.getStatus().equals("0")) {
response.getDocDetails().setDocContent("Document is not available.");
}
response.setResponseStatus(responseStatus);
return response;
}
Expand Down Expand Up @@ -334,15 +345,15 @@ private CertificateInfo addCertificateInfo(CertificateAddInfoDTO certificateAddI
CertificateInfo certificateInfo = new CertificateInfo();
certificateInfo.getCertificateMetaData().setName(certificateAddInfoDTO.getDocumentName());
certificateInfo.getCertificateMetaData().setNumber(certificateAddInfoDTO.getCertificateId());
certificateInfo.getCertificateMetaData().setIssueDate(simpleDateFormat.parse(simpleDateFormat.format(certificateAddInfoDTO.getCertificateIssueOn())));
certificateInfo.getCertificateMetaData().setIssueDate(certificateAddInfoDTO.getCertificateIssueOn());
certificateInfo.getCertificateMetaData().setType(certificateAddInfoDTO.getDocumentInfo());
certificateInfo.getCertificateMetaData().getCertificateData().getCertificate().setNumber(certificateAddInfoDTO.getCertificateId());
certificateInfo.getCertificateMetaData().getIssuedTo().getPersonInfo().setName(certificateAddInfoDTO.getUserName());
certificateInfo.getCertificateMetaData().getIssuedTo().getPersonInfo().setSwd(certificateAddInfoDTO.getSwd());
certificateInfo.getCertificateMetaData().getIssuedTo().getPersonInfo().setSwdIndicator(certificateAddInfoDTO.getSwdIndicator());
certificateInfo.getCertificateMetaData().getIssuedTo().getPersonInfo().setName(certificateAddInfoDTO.getUserName());
certificateInfo.getCertificateMetaData().getCertificateData().getCertificate().setPlace("iGOT");
certificateInfo.getCertificateMetaData().getCertificateData().getCertificate().setDate(simpleDateFormat.format(certificateAddInfoDTO.getCertificateIssueOn()));
certificateInfo.getCertificateMetaData().getCertificateData().getCertificate().setDate(certificateAddInfoDTO.getCertificateIssueOn());
return certificateInfo;
}

Expand Down

0 comments on commit f86fc18

Please sign in to comment.