diff --git a/src/main/java/org/sunbird/digilocker/model/CertificateAddInfoDTO.java b/src/main/java/org/sunbird/digilocker/model/CertificateAddInfoDTO.java index 6ff78803e..99daa8886 100644 --- a/src/main/java/org/sunbird/digilocker/model/CertificateAddInfoDTO.java +++ b/src/main/java/org/sunbird/digilocker/model/CertificateAddInfoDTO.java @@ -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; @@ -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; } diff --git a/src/main/java/org/sunbird/digilocker/model/CertificateInfo.java b/src/main/java/org/sunbird/digilocker/model/CertificateInfo.java index 3aa7f61c7..fcd8f3017 100644 --- a/src/main/java/org/sunbird/digilocker/model/CertificateInfo.java +++ b/src/main/java/org/sunbird/digilocker/model/CertificateInfo.java @@ -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; @@ -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; } diff --git a/src/main/java/org/sunbird/digilocker/model/certificateMetaData/CertificateData.java b/src/main/java/org/sunbird/digilocker/model/certificateMetaData/CertificateData.java index 50117d073..14b632846 100644 --- a/src/main/java/org/sunbird/digilocker/model/certificateMetaData/CertificateData.java +++ b/src/main/java/org/sunbird/digilocker/model/certificateMetaData/CertificateData.java @@ -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; } @@ -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; } diff --git a/src/main/java/org/sunbird/digilocker/model/certificateMetaData/CertificateIssuedBy.java b/src/main/java/org/sunbird/digilocker/model/certificateMetaData/CertificateIssuedBy.java index 39eb7915c..fc1460d02 100644 --- a/src/main/java/org/sunbird/digilocker/model/certificateMetaData/CertificateIssuedBy.java +++ b/src/main/java/org/sunbird/digilocker/model/certificateMetaData/CertificateIssuedBy.java @@ -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; } diff --git a/src/main/java/org/sunbird/digilocker/model/certificateMetaData/CertificateIssuedTo.java b/src/main/java/org/sunbird/digilocker/model/certificateMetaData/CertificateIssuedTo.java index 138ca9c13..ad31c3953 100644 --- a/src/main/java/org/sunbird/digilocker/model/certificateMetaData/CertificateIssuedTo.java +++ b/src/main/java/org/sunbird/digilocker/model/certificateMetaData/CertificateIssuedTo.java @@ -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; } diff --git a/src/main/java/org/sunbird/digilocker/model/certificateMetaData/CertificateMetaData.java b/src/main/java/org/sunbird/digilocker/model/certificateMetaData/CertificateMetaData.java index 3312b9289..9f27848a0 100644 --- a/src/main/java/org/sunbird/digilocker/model/certificateMetaData/CertificateMetaData.java +++ b/src/main/java/org/sunbird/digilocker/model/certificateMetaData/CertificateMetaData.java @@ -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; @@ -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; @@ -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; } @@ -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; } @@ -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; } @@ -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; } @@ -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; } diff --git a/src/main/java/org/sunbird/digilocker/model/certificateMetaData/Organization.java b/src/main/java/org/sunbird/digilocker/model/certificateMetaData/Organization.java index eab57f605..56739a699 100644 --- a/src/main/java/org/sunbird/digilocker/model/certificateMetaData/Organization.java +++ b/src/main/java/org/sunbird/digilocker/model/certificateMetaData/Organization.java @@ -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; } diff --git a/src/main/java/org/sunbird/digilocker/model/certificateMetaData/ParticipationCertificate.java b/src/main/java/org/sunbird/digilocker/model/certificateMetaData/ParticipationCertificate.java index 756f0999e..d7ed43212 100644 --- a/src/main/java/org/sunbird/digilocker/model/certificateMetaData/ParticipationCertificate.java +++ b/src/main/java/org/sunbird/digilocker/model/certificateMetaData/ParticipationCertificate.java @@ -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; } @@ -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; } diff --git a/src/main/java/org/sunbird/digilocker/model/certificateMetaData/PersonInfo.java b/src/main/java/org/sunbird/digilocker/model/certificateMetaData/PersonInfo.java index db2572dc2..31f13d704 100644 --- a/src/main/java/org/sunbird/digilocker/model/certificateMetaData/PersonInfo.java +++ b/src/main/java/org/sunbird/digilocker/model/certificateMetaData/PersonInfo.java @@ -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; } @@ -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; } diff --git a/src/main/java/org/sunbird/digilocker/service/DigiLockerIntegrationServiceImpl.java b/src/main/java/org/sunbird/digilocker/service/DigiLockerIntegrationServiceImpl.java index 5c8f37283..43971ef7d 100644 --- a/src/main/java/org/sunbird/digilocker/service/DigiLockerIntegrationServiceImpl.java +++ b/src/main/java/org/sunbird/digilocker/service/DigiLockerIntegrationServiceImpl.java @@ -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; } @@ -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 dockerLookUpInfo = new HashMap<>(); dockerLookUpInfo.put(Constants.DOC_ID, docId); dockerLookUpInfo.put(Constants.DIGI_LOCKER_ID, request.getDocDetails().getDigiLockerId()); @@ -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"); @@ -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); @@ -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; } @@ -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; } @@ -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 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 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"); @@ -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; } @@ -334,7 +345,7 @@ 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()); @@ -342,7 +353,7 @@ private CertificateInfo addCertificateInfo(CertificateAddInfoDTO certificateAddI 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; }