diff --git a/pom.xml b/pom.xml
index a857235f..5a68ed2c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,6 +1,6 @@
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
org.springframework.boot
@@ -10,8 +10,10 @@
io.mosip.print
print
- 1.2.0.1
+ 1.2.0.2-test4
print
+ https://github.com/mosip/print
+ MOSIP Print service
MPL 2.0
@@ -26,34 +28,33 @@
https://github.com/mosip/print
-
11
2.9.2
- UTF-8
- 11
+ UTF-8
+ 11
11
3.8.0
2.22.0
3.0.2
- 3.1.0
+ 3.1.0
0.8.5
3.7.0.1746
3.0.1
- 2.0.2.RELEASE
- 2.0.7.RELEASE
- 5.0.5.RELEASE
- 2.0.0.RELEASE
- 1.4.197
- 2.9.8
- 2.9.2
- 2.0.7
+ 2.0.2.RELEASE
+ 2.0.7.RELEASE
+ 5.0.5.RELEASE
+ 2.0.0.RELEASE
+ 1.4.197
+ 2.9.8
+ 2.9.2
+ 2.0.7
2.28.2
- **/constant/**,**/config/**,**/cache/**,**/dto/**,**/model/**,**/exception/**,**/repository/**,**/security/**,**/*Config.java,**/*Application.java,**/*Handler.java
- **/dto/**,**/config/**,**/api/**
- 1.4.2
- 2.8.4
- 1.2.0.1
+ **/constant/**,**/config/**,**/cache/**,**/dto/**,**/model/**,**/exception/**,**/repository/**,**/security/**,**/*Config.java,**/*Application.java,**/*Handler.java
+ **/dto/**,**/config/**,**/api/**
+ 1.4.2
+ 2.8.4
+ 1.2.0.1
7.1.0
2.0.0
5.5.13
@@ -65,7 +66,6 @@
3.8.1
3.3.3
-
org.springframework.boot
@@ -79,9 +79,9 @@
- org.springframework.cloud
- spring-cloud-starter-config
- 2.0.2.RELEASE
+ org.springframework.cloud
+ spring-cloud-starter-config
+ 2.0.2.RELEASE
org.springframework.boot
@@ -106,28 +106,28 @@
- com.googlecode.json-simple
- json-simple
- 1.1.1
+ com.googlecode.json-simple
+ json-simple
+ 1.1.1
com.google.code.gson
gson
- org.json
- json
- 20190722
+ org.json
+ json
+ 20190722
-
+
org.slf4j
slf4j-api
1.7.25
- joda-time
- joda-time
- 2.8.1
+ joda-time
+ joda-time
+ 2.8.1
org.apache.velocity
@@ -207,22 +207,21 @@
${google.zxing.version}
- org.apache.httpcomponents
- httpclient
- 4.5.8
+ org.apache.httpcomponents
+ httpclient
+ 4.5.8
- org.mockito
- mockito-core
- 2.22.0
- test
+ org.mockito
+ mockito-core
+ 2.22.0
+ test
io.mosip.kernel
kernel-websubclient-api
${kernel.websub.version}
-
com.fasterxml.jackson.core
jackson-core
@@ -249,38 +248,40 @@
1.0.0
-
-
-
- ossrh
- CentralRepository
- https://oss.sonatype.org/content/repositories/snapshots
- default
-
- true
-
-
-
- central
- MavenCentral
- default
- https://repo1.maven.org/maven2
-
- false
-
-
-
-
+
+
+ ossrh
+ CentralRepository
+ https://oss.sonatype.org/content/repositories/snapshots
+ default
+
+ true
+
+
+
+ danubetech-maven-public
+ https://repo.danubetech.com/repository/maven-public/
+
+
+ central
+ MavenCentral
+ default
+ https://repo1.maven.org/maven2
+
+ false
+
+
+
-
- ossrh
- https://oss.sonatype.org/content/repositories/snapshots
-
-
- ossrh
- https://oss.sonatype.org/service/local/staging/deploy/maven2/
-
-
+
+ ossrh
+ https://oss.sonatype.org/content/repositories/snapshots
+
+
+ ossrh
+ https://oss.sonatype.org/service/local/staging/deploy/maven2/
+
+
@@ -289,7 +290,7 @@
${maven.surefire.plugin.version}
${skipTests}
- false
+ true
${argLine} --add-opens java.xml/jdk.xml.internal=ALL-UNNAMED --illegal-access=permit
@@ -352,33 +353,15 @@
-
- org.apache.maven.plugins
- maven-compiler-plugin
- ${maven.compiler.version}
-
- ${maven.compiler.source}
- ${maven.compiler.target}
-
-
-
- org.apache.maven.plugins
- maven-javadoc-plugin
- 3.2.0
-
-
- attach-javadocs
-
- jar
-
-
-
-
- true
- none
-
-
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ ${maven.compiler.version}
+
+ ${maven.compiler.source}
+ ${maven.compiler.target}
+
+
org.apache.maven.plugins
maven-jar-plugin
@@ -413,87 +396,78 @@
+
+ org.sonatype.plugins
+ nexus-staging-maven-plugin
+ 1.6.7
+ true
+
+ ossrh
+ https://oss.sonatype.org/
+ false
+
+
org.apache.maven.plugins
- maven-javadoc-plugin
- ${maven.javadoc.version}
+ maven-source-plugin
+ 2.2.1
+
+
+ attach-sources
+
+ jar-no-fork
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-gpg-plugin
+ 1.5
+
+ true
+
+
+
+ sign-artifacts
+ verify
+
+ sign
+
+
+
+ --pinentry-mode
+ loopback
+
+
+
+
+
+
+ pl.project13.maven
+ git-commit-id-plugin
+ 3.0.1
+
+
+ get-the-git-infos
+
+ revision
+
+ validate
+
+
- true
- none
+ true
+ ${project.build.outputDirectory}/git.properties
+
+ ^git.build.(time|version)$
+ ^git.commit.id.(abbrev|full)$
+
+ full
+ ${project.basedir}/.git
+
-
- org.sonatype.plugins
- nexus-staging-maven-plugin
- 1.6.7
- true
-
- ossrh
- https://oss.sonatype.org/
- false
-
-
-
-
- org.apache.maven.plugins
- maven-source-plugin
- 2.2.1
-
-
- attach-sources
-
- jar-no-fork
-
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-gpg-plugin
- 1.5
-
-
- sign-artifacts
- verify
-
- sign
-
-
-
- --pinentry-mode
- loopback
-
-
-
-
-
-
- pl.project13.maven
- git-commit-id-plugin
- 3.0.1
-
-
- get-the-git-infos
-
- revision
-
- validate
-
-
-
- true
- ${project.build.outputDirectory}/git.properties
-
- ^git.build.(time|version)$
- ^git.commit.id.(abbrev|full)$
-
- full
- ${project.basedir}/.git
-
-
-
@@ -527,4 +501,4 @@
-
+
\ No newline at end of file
diff --git a/src/main/java/io/mosip/print/PrintPDFApplication.java b/src/main/java/io/mosip/print/PrintPDFApplication.java
index 0465f1c9..edbd1c13 100644
--- a/src/main/java/io/mosip/print/PrintPDFApplication.java
+++ b/src/main/java/io/mosip/print/PrintPDFApplication.java
@@ -15,36 +15,32 @@
import io.mosip.print.service.impl.CbeffImpl;
import io.mosip.print.spi.CbeffUtil;
-
-@SpringBootApplication(scanBasePackages = { "io.mosip.print.*", "${mosip.auth.adapter.impl.basepackage}" }, exclude = { DataSourceAutoConfiguration.class,
- HibernateJpaAutoConfiguration.class,
- CacheAutoConfiguration.class })
+@SpringBootApplication(scanBasePackages = { "io.mosip.print.*", "${mosip.auth.adapter.impl.basepackage}" },
+ exclude = { DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class, CacheAutoConfiguration.class })
@EnableScheduling
@EnableAsync
public class PrintPDFApplication {
-
- @Bean
- @Primary
- public CbeffUtil getCbeffUtil() {
- return new CbeffImpl();
- }
+ @Bean
+ @Primary
+ public CbeffUtil getCbeffUtil() {
+ return new CbeffImpl();
+ }
@Bean
public CredentialsVerifier credentialsVerifier() {
return new CredentialsVerifier();
}
- @Bean
- public ThreadPoolTaskScheduler taskScheduler() {
- ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
- threadPoolTaskScheduler.setPoolSize(5);
- threadPoolTaskScheduler.setThreadNamePrefix("ThreadPoolTaskScheduler");
- return threadPoolTaskScheduler;
- }
-
- public static void main(String[] args) {
- SpringApplication.run(PrintPDFApplication.class, args);
- }
-
-}
+ @Bean
+ public ThreadPoolTaskScheduler taskScheduler() {
+ ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
+ threadPoolTaskScheduler.setPoolSize(5);
+ threadPoolTaskScheduler.setThreadNamePrefix("ThreadPoolTaskScheduler");
+ return threadPoolTaskScheduler;
+ }
+
+ public static void main(String[] args) {
+ SpringApplication.run(PrintPDFApplication.class, args);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/io/mosip/print/config/PrintConfig.java b/src/main/java/io/mosip/print/config/PrintConfig.java
index c4fb5d7a..1f328d02 100644
--- a/src/main/java/io/mosip/print/config/PrintConfig.java
+++ b/src/main/java/io/mosip/print/config/PrintConfig.java
@@ -4,6 +4,7 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
+import org.springframework.web.client.RestTemplate;
@Configuration
@@ -18,4 +19,9 @@ public TaskScheduler taskScheduler() {
}
+ @Bean
+ public RestTemplate restTemplate() {
+ return new RestTemplate();
+ }
+
}
diff --git a/src/main/java/io/mosip/print/constant/ProcessType.java b/src/main/java/io/mosip/print/constant/ProcessType.java
new file mode 100644
index 00000000..8cf91241
--- /dev/null
+++ b/src/main/java/io/mosip/print/constant/ProcessType.java
@@ -0,0 +1,7 @@
+package io.mosip.print.constant;
+
+public enum ProcessType {
+ NEW,
+ CRVS_NEW,
+ UPDATE,
+}
\ No newline at end of file
diff --git a/src/main/java/io/mosip/print/constant/TemplateType.java b/src/main/java/io/mosip/print/constant/TemplateType.java
new file mode 100644
index 00000000..e3f3e7a6
--- /dev/null
+++ b/src/main/java/io/mosip/print/constant/TemplateType.java
@@ -0,0 +1,20 @@
+package io.mosip.print.constant;
+
+public enum TemplateType {
+ UIN_CARD_TEMPLATE("RPR_UIN_CARD_TEMPLATE"),
+ UIN_CARD_EMAIL_SUB("RPR_UIN_CARD_EMAIL_SUB"),
+ UIN_CARD_EMAIL("RPR_UIN_CARD_EMAIL");
+
+ private final String value;
+
+ TemplateType(String value) {
+ this.value = value;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ @Override
+ public String toString() { return value; }
+}
\ No newline at end of file
diff --git a/src/main/java/io/mosip/print/exception/PlatformErrorMessages.java b/src/main/java/io/mosip/print/exception/PlatformErrorMessages.java
index 3868cfb5..cd3ba686 100644
--- a/src/main/java/io/mosip/print/exception/PlatformErrorMessages.java
+++ b/src/main/java/io/mosip/print/exception/PlatformErrorMessages.java
@@ -50,6 +50,8 @@ public enum PlatformErrorMessages {
PRT_BDD_ABIS_ABORT(PlatformConstants.PRT_PRINT_PREFIX + "002",
"ABIS for the Reference ID and Request ID was Abort"),
/** The PRT tem processing failure. */
+ PRT_TEM_MAPPER_NOT_FOUND(PlatformConstants.PRT_PRINT_PREFIX + "030", "Template mapper could not be mapped for processType = %s"),
+
PRT_TEM_PROCESSING_FAILURE(PlatformConstants.PRT_PRINT_PREFIX + "002", "The Processing of Template Failed "),
PRT_SYS_JSON_PARSING_EXCEPTION(PlatformConstants.PRT_PRINT_PREFIX + "009", "Error while parsing Json"),
PRT_AUT_INVALID_TOKEN(PlatformConstants.PRT_PRINT_PREFIX + "01", "Invalid Token Present"),
diff --git a/src/main/java/io/mosip/print/service/impl/PrintServiceImpl.java b/src/main/java/io/mosip/print/service/impl/PrintServiceImpl.java
index aa7720b2..5b97cb53 100644
--- a/src/main/java/io/mosip/print/service/impl/PrintServiceImpl.java
+++ b/src/main/java/io/mosip/print/service/impl/PrintServiceImpl.java
@@ -22,6 +22,7 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
+import io.mosip.print.constant.*;
import io.mosip.print.dto.*;
import io.mosip.print.exception.*;
import io.mosip.print.util.*;
@@ -30,6 +31,7 @@
import io.mosip.vercred.exception.ProofTypeNotFoundException;
import io.mosip.vercred.exception.PubicKeyNotFoundException;
import io.mosip.vercred.exception.UnknownException;
+import lombok.Getter;
import org.apache.commons.codec.binary.Base64;
import org.joda.time.DateTime;
import org.json.simple.JSONArray;
@@ -42,15 +44,6 @@
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;
-import io.mosip.print.constant.EventId;
-import io.mosip.print.constant.EventName;
-import io.mosip.print.constant.EventType;
-import io.mosip.print.constant.IdType;
-import io.mosip.print.constant.ModuleName;
-import io.mosip.print.constant.PDFGeneratorExceptionCodeConstant;
-import io.mosip.print.constant.PlatformSuccessMessages;
-import io.mosip.print.constant.QrVersion;
-import io.mosip.print.constant.UinCardType;
import io.mosip.print.logger.LogDescription;
import io.mosip.print.logger.PrintLogger;
import io.mosip.print.model.CredentialStatusEvent;
@@ -87,11 +80,6 @@ public class PrintServiceImpl implements PrintService{
/** The Constant VALUE. */
private static final String VALUE = "value";
- /** The Constant UIN_CARD_TEMPLATE. */
- private static final String UIN_CARD_TEMPLATE = "RPR_UIN_CARD_TEMPLATE";
- private static final String UIN_CARD_EMAIL_SUB = "RPR_UIN_CARD_EMAIL_SUB";
- private static final String UIN_CARD_EMAIL = "RPR_UIN_CARD_EMAIL";
-
/** The Constant FACE. */
private static final String FACE = "Face";
@@ -237,7 +225,7 @@ public boolean generateCard(EventModel eventModel) {
private Map getDocuments(String credential, String credentialType, String encryptionPin,
String requestId,
String cardType,
- boolean isPasswordProtected, String refId, String registrationId) {
+ boolean isPasswordProtected, String refId, String registrationId) {
printLogger.debug("PrintServiceImpl::getDocuments()::entry");
String credentialSubject;
Map byteMap = new HashMap<>();
@@ -248,10 +236,8 @@ private Map getDocuments(String credential, String credentialTyp
String individualBio = null;
Map attributes = new LinkedHashMap<>();
boolean isTransactionSuccessful = false;
- String template = UIN_CARD_TEMPLATE;
byte[] pdfbytes = null;
try {
-
credentialSubject = getCrdentialSubject(credential);
org.json.JSONObject credentialSubjectJson = new org.json.JSONObject(credentialSubject);
org.json.JSONObject decryptedJson = decryptAttribute(credentialSubjectJson, encryptionPin, credential);
@@ -272,37 +258,39 @@ private Map getDocuments(String credential, String credentialTyp
if (isPasswordProtected) {
password = getPassword(uin);
}
- if (credentialType.equalsIgnoreCase("qrcode")) {
- boolean isQRcodeSet = setQrCode(decryptedJson.toString(), attributes, isPhotoSet);
- InputStream uinArtifact = templateGenerator.getTemplate(template, attributes, templateLang);
- pdfbytes = uinCardGenerator.generateUinCard(uinArtifact, UinCardType.PDF,
- password);
-
- } else {
-
- if (!isPhotoSet) {
- printLogger.debug(PlatformErrorMessages.PRT_PRT_APPLICANT_PHOTO_NOT_SET.name());
- }
-// byte[] textFileByte = createTextFile(decryptedJson.toString());
-// byteMap.put(UIN_TEXT_FILE, textFileByte);
- boolean isQRcodeSet = setQrCode(decryptedJson.toString(), attributes, isPhotoSet);
+ Optional templateConfigOpt = TemplateMapper.getTemplatesConfig(attributes);
+ if (templateConfigOpt.isEmpty()) {
+ throw new TemplateProcessingFailureException(
+ String.format(
+ PlatformErrorMessages.PRT_TEM_MAPPER_NOT_FOUND.getMessage(),
+ attributes.get(TemplateMapper.PROCESS_TYPE_KEY)
+ )
+ );
+ }
+ TemplateMapper.TemplateMappedConfig templateMappedConfig = templateConfigOpt.get();
+ String template = templateMappedConfig.getDocumentTemplateName().getValue();
+ if (template != null) {
+ boolean isQRcodeSet = setQrCode(decryptedJson.toString(), attributes, isPhotoSet);
if (!isQRcodeSet) {
printLogger.debug(PlatformErrorMessages.PRT_PRT_QRCODE_NOT_SET.name());
}
- printLogger.info("Attributes:{}", JSONObject.toJSONString(attributes));
- // getting template and placing original valuespng
- InputStream uinArtifact = templateGenerator.getTemplate(template, attributes, templateLang);
- if (uinArtifact == null) {
- printLogger.error(PlatformErrorMessages.PRT_TEM_PROCESSING_FAILURE.name());
- throw new TemplateProcessingFailureException(
- PlatformErrorMessages.PRT_TEM_PROCESSING_FAILURE.getCode());
+ if (!isPhotoSet) {
+ printLogger.debug(PlatformErrorMessages.PRT_PRT_APPLICANT_PHOTO_NOT_SET.name());
}
- pdfbytes = uinCardGenerator.generateUinCard(uinArtifact, UinCardType.PDF, password);
+ printLogger.info("Attributes:{}", JSONObject.toJSONString(attributes));
+ pdfbytes = generatePdfFromTemplate(template, attributes, templateLang, password);
+ }
+
+ if (templateMappedConfig.getEmailSubjectTemplate() != null && templateMappedConfig.getEmailTemplate() != null) {
+ TemplateType emailSubject = templateMappedConfig.getEmailSubjectTemplate();
+ TemplateType emailBody = templateMappedConfig.getEmailTemplate();
+ Attachment attachment = pdfbytes != null ? new Attachment(cardType + ".pdf", pdfbytes) : null;
+ sendEmail(residentEmailId, emailSubject, emailBody, attachment, attributes, templateLang);
}
- // Send UIN Card Pdf to Email
+ // leaving it as it is to keep backward compatibility
if (emailUINEnabled) {
sendUINInEmail(residentEmailId, registrationId, attributes, pdfbytes, templateLang);
}
@@ -387,20 +375,87 @@ private Map getDocuments(String credential, String credentialTyp
}
- private void sendUINInEmail(String residentEmailId, String fileName, Map attributes, byte[] pdfbytes, String templateLang) {
- if (pdfbytes != null) {
- try {
- List emailIds = Arrays.asList(residentEmailId, defaultEmailIds);
- List responseDTOs = notificationUtil.emailNotification(emailIds, fileName,
- UIN_CARD_EMAIL, UIN_CARD_EMAIL_SUB, attributes, pdfbytes, templateLang);
- responseDTOs.forEach(responseDTO ->
- printLogger.info("UIN sent successfully via Email, server response..{}", responseDTO)
- );
- } catch (Exception e) {
- printLogger.error("Failed to send pdf UIN via email.{}", residentEmailId, e);
- }
- }
- }
+ @Getter
+ static class Attachment {
+ private final String fileName;
+ private final byte[] data;
+
+ public Attachment(String fileName, byte[] data) {
+ this.fileName = fileName;
+ this.data = data;
+ }
+ }
+
+ private Optional> sendEmail(
+ String residentEmailId,
+ TemplateType emailSubject,
+ TemplateType emailBody,
+ Attachment attachment,
+ Map attributes,
+ String templateLang
+ ) {
+
+ Optional> noResult = Optional.empty();
+ if (residentEmailId == null) {
+ printLogger.error("Resident email ID parameter is null");
+ return noResult;
+ }
+ if (emailSubject == null) {
+ printLogger.error("Email subject parameter is null");
+ return noResult;
+ }
+ if (emailBody == null) {
+ printLogger.error("Email body parameter is null");
+ return noResult;
+ }
+
+ if (attachment != null && (attachment.getFileName() == null || attachment.getData() == null)) {
+ printLogger.error("Both filename and data must be provided for email attachment");
+ return noResult;
+ }
+
+ List emailIds = new ArrayList<>();
+ emailIds.add(residentEmailId);
+ if (defaultEmailIds != null) {
+ emailIds.add(defaultEmailIds);
+ }
+
+ try {
+ List responseDTOs = notificationUtil.emailNotification(
+ emailIds,
+ attachment != null ? attachment.getFileName() : null,
+ emailBody.getValue(),
+ emailSubject.getValue(),
+ attributes,
+ attachment != null ? attachment.getData() : null,
+ templateLang
+ );
+ return Optional.of(responseDTOs);
+ } catch (Exception e) {
+ printLogger.error("Failed to send email to {}: {}", residentEmailId, e.getMessage(), e);
+ return noResult;
+ }
+ }
+
+ private void sendUINInEmail(String residentEmailId, String fileName, Map attributes, byte[] pdfbytes, String templateLang) {
+ if (pdfbytes == null) {
+ return;
+ }
+
+ var responsesDtos = sendEmail(
+ residentEmailId,
+ TemplateType.UIN_CARD_EMAIL_SUB,
+ TemplateType.UIN_CARD_EMAIL,
+ new Attachment(fileName, pdfbytes),
+ attributes,
+ templateLang
+ );
+ responsesDtos.ifPresent(responseDTOs -> {
+ responseDTOs.forEach(responseDTO ->
+ printLogger.info("Email sent successfully, server response: {}", responseDTO)
+ );
+ });
+ }
/**
* Creates the text file.
*
@@ -720,6 +775,34 @@ private void printStatusUpdate(String requestId, byte[] data, String credentialT
webSubSubscriptionHelper.printStatusUpdateEvent(topic, creEvent);
}
+ /**
+ * Processes a template and generates a PDF document.
+ *
+ * @param template the template name
+ * @param attributes the template attributes
+ * @param templateLang the template language
+ * @param password the password for PDF protection (can be null)
+ * @return the generated PDF as byte array
+ * @throws TemplateProcessingFailureException if template processing fails
+ */
+ private byte[] generatePdfFromTemplate(String template, Map attributes, String templateLang, String password) {
+ try {
+ InputStream uinArtifact = templateGenerator.getTemplate(template, attributes, templateLang);
+
+ if (uinArtifact == null) {
+ printLogger.error(PlatformErrorMessages.PRT_TEM_PROCESSING_FAILURE.name());
+ throw new TemplateProcessingFailureException(
+ PlatformErrorMessages.PRT_TEM_PROCESSING_FAILURE.getCode());
+ }
+
+ return uinCardGenerator.generateUinCard(uinArtifact, UinCardType.PDF, password);
+ } catch (Exception e) {
+ printLogger.error("Error in template processing or PDF generation", e);
+ throw new TemplateProcessingFailureException(
+ PlatformErrorMessages.PRT_TEM_PROCESSING_FAILURE.getCode());
+ }
+ }
+
public org.json.JSONObject decryptAttribute(org.json.JSONObject data, String encryptionPin, String credential)
throws ParseException {
diff --git a/src/main/java/io/mosip/print/util/RestApiClient.java b/src/main/java/io/mosip/print/util/RestApiClient.java
index 636020d7..5471643c 100644
--- a/src/main/java/io/mosip/print/util/RestApiClient.java
+++ b/src/main/java/io/mosip/print/util/RestApiClient.java
@@ -40,7 +40,7 @@ public class RestApiClient {
/** The builder. */
@Autowired
- @Qualifier("selfTokenRestTemplate")
+ // @Qualifier("selfTokenRestTemplate")
private RestTemplate restTemplate;
@Autowired
diff --git a/src/main/java/io/mosip/print/util/TemplateMapper.java b/src/main/java/io/mosip/print/util/TemplateMapper.java
new file mode 100644
index 00000000..aca59c8a
--- /dev/null
+++ b/src/main/java/io/mosip/print/util/TemplateMapper.java
@@ -0,0 +1,80 @@
+package io.mosip.print.util;
+
+import io.mosip.print.constant.ProcessType;
+import io.mosip.print.constant.TemplateType;
+import lombok.Getter;
+
+import java.util.Collections;
+import java.util.EnumMap;
+import java.util.Map;
+import java.util.Optional;
+
+public final class TemplateMapper {
+ private static final Map PROCESS_TO_TEMPLATE_TYPE;
+ public static final String PROCESS_TYPE_KEY = "processType";
+
+ static {
+ Map map = new EnumMap<>(ProcessType.class);
+ map.put(ProcessType.NEW, new TemplateMappedConfig(
+ TemplateType.UIN_CARD_TEMPLATE,
+ TemplateType.UIN_CARD_EMAIL_SUB,
+ TemplateType.UIN_CARD_EMAIL
+ ));
+
+ PROCESS_TO_TEMPLATE_TYPE = Collections.unmodifiableMap(map);
+ }
+
+ private TemplateMapper() {
+ // Prevent instantiation
+ }
+
+ /**
+ * Retrieves the template configuration mapped to the specified process type
+ * from the provided attributes map. If the map does not contain a valid
+ * process type or is invalid, an empty {@code Optional} is returned.
+ *
+ * @param attributes a map of attributes where the key "processType" is
+ * expected to represent the process type as a string.
+ * @return an {@code Optional} containing the {@code TemplateMappedConfig}
+ * corresponding to the process type if available; otherwise, an
+ * empty {@code Optional}.
+ */
+ public static Optional getTemplatesConfig(Map attributes) {
+ if (attributes == null || !attributes.containsKey(PROCESS_TYPE_KEY)) {
+ return Optional.empty();
+ }
+
+ try {
+ String processTypeStr = String.valueOf(attributes.get(PROCESS_TYPE_KEY)).toUpperCase();
+ ProcessType processType = ProcessType.valueOf(processTypeStr);
+ return Optional.ofNullable(PROCESS_TO_TEMPLATE_TYPE.get(processType));
+ } catch (IllegalArgumentException e) {
+ return Optional.empty();
+ }
+ }
+
+ @Getter
+ public static class TemplateMappedConfig {
+ private final TemplateType documentTemplateName;
+ private final TemplateType emailSubjectTemplate;
+ private final TemplateType emailTemplate;
+
+ public TemplateMappedConfig(TemplateType documentTemplateName, TemplateType emailSubjectTemplate, TemplateType emailTemplate) {
+ boolean hasEmailTemplate = emailTemplate != null;
+ boolean hasEmailSubject = emailSubjectTemplate != null;
+ boolean hasDocumentTemplate = documentTemplateName != null;
+
+ if (hasEmailTemplate ^ hasEmailSubject) {
+ throw new IllegalArgumentException("Email template and subject must both be present or both be null");
+ }
+
+ if (!hasDocumentTemplate && !hasEmailTemplate & !hasEmailSubject) {
+ throw new IllegalArgumentException("At least one of document template, email template or email subject must be present");
+ }
+
+ this.documentTemplateName = documentTemplateName;
+ this.emailSubjectTemplate = emailSubjectTemplate;
+ this.emailTemplate = emailTemplate;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/main/resources/bootstrap.properties b/src/main/resources/bootstrap.properties
index 2c439ba6..d4722dd6 100644
--- a/src/main/resources/bootstrap.properties
+++ b/src/main/resources/bootstrap.properties
@@ -6,6 +6,6 @@ spring.application.name=print
management.endpoint.health.show-details=always
management.endpoints.web.exposure.include=info,health,refresh
-server.port=8088
+server.port=80881
server.servlet.context-path=/v1/print
health.config.enabled=false
\ No newline at end of file
diff --git a/src/test/java/io/mosip/print/test/util/TemplateMappedConfigTest.java b/src/test/java/io/mosip/print/test/util/TemplateMappedConfigTest.java
new file mode 100644
index 00000000..56240683
--- /dev/null
+++ b/src/test/java/io/mosip/print/test/util/TemplateMappedConfigTest.java
@@ -0,0 +1,83 @@
+package io.mosip.print.test.util;
+
+import io.mosip.print.constant.TemplateType;
+import io.mosip.print.util.TemplateMapper;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+public class TemplateMappedConfigTest {
+
+ @Test
+ public void testValidConfigWithAllTemplates() {
+ TemplateMapper.TemplateMappedConfig config = new TemplateMapper.TemplateMappedConfig(
+ TemplateType.UIN_CARD_TEMPLATE,
+ TemplateType.UIN_CARD_EMAIL_SUB,
+ TemplateType.UIN_CARD_EMAIL
+ );
+
+ assertNotNull(config);
+ assertEquals(TemplateType.UIN_CARD_TEMPLATE, config.getDocumentTemplateName());
+ assertEquals(TemplateType.UIN_CARD_EMAIL_SUB, config.getEmailSubjectTemplate());
+ assertEquals(TemplateType.UIN_CARD_EMAIL, config.getEmailTemplate());
+ }
+
+ @Test
+ public void testValidConfigWithOnlyDocumentTemplate() {
+ TemplateMapper.TemplateMappedConfig config = new TemplateMapper.TemplateMappedConfig(
+ TemplateType.UIN_CARD_TEMPLATE,
+ null,
+ null
+ );
+
+ assertNotNull(config);
+ assertEquals(TemplateType.UIN_CARD_TEMPLATE, config.getDocumentTemplateName());
+ assertNull(config.getEmailSubjectTemplate());
+ assertNull(config.getEmailTemplate());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testInvalidConfigWithEmailTemplateButNoSubject() {
+ new TemplateMapper.TemplateMappedConfig(
+ TemplateType.UIN_CARD_TEMPLATE,
+ null,
+ TemplateType.UIN_CARD_EMAIL
+ );
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testInvalidConfigWithEmailSubjectButNoTemplate() {
+ new TemplateMapper.TemplateMappedConfig(
+ TemplateType.UIN_CARD_TEMPLATE,
+ TemplateType.UIN_CARD_EMAIL_SUB,
+ null
+ );
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testInvalidConfigWithNoTemplates() {
+ new TemplateMapper.TemplateMappedConfig(null, null, null);
+ }
+
+ @Test
+ public void testValidConfigWithOnlyEmailTemplates() {
+ TemplateMapper.TemplateMappedConfig config = new TemplateMapper.TemplateMappedConfig(
+ null,
+ TemplateType.UIN_CARD_EMAIL_SUB,
+ TemplateType.UIN_CARD_EMAIL
+ );
+
+ assertNotNull(config);
+ assertNull(config.getDocumentTemplateName());
+ assertEquals(TemplateType.UIN_CARD_EMAIL_SUB, config.getEmailSubjectTemplate());
+ assertEquals(TemplateType.UIN_CARD_EMAIL, config.getEmailTemplate());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testInvalidConfigWithNullDocumentAndOneEmailComponent() {
+ new TemplateMapper.TemplateMappedConfig(
+ null,
+ TemplateType.UIN_CARD_EMAIL_SUB,
+ null
+ );
+ }
+}
\ No newline at end of file