diff --git a/.github/workflows/push-trigger.yml b/.github/workflows/push-trigger.yml index c3ef6f3e..5f5f49e7 100644 --- a/.github/workflows/push-trigger.yml +++ b/.github/workflows/push-trigger.yml @@ -20,6 +20,7 @@ on: - develop - MOSIP* - release* + - mc2026 jobs: build-maven-mock-plugin: diff --git a/mock-plugin/pom.xml b/mock-plugin/pom.xml index 19489856..d2854f22 100644 --- a/mock-plugin/pom.xml +++ b/mock-plugin/pom.xml @@ -5,7 +5,7 @@ io.mosip.esignet mock-plugin - 1.4.0-SNAPSHOT + 1.4.0-mc2026-SNAPSHOT mock-plugin jar Mockup of a wrapper implementation that is used to showcase the integration with e-Signet diff --git a/mock-plugin/src/main/java/io/mosip/signup/plugin/mock/verifier/DemoIdentityVerifierPluginImpl.java b/mock-plugin/src/main/java/io/mosip/signup/plugin/mock/verifier/DemoIdentityVerifierPluginImpl.java new file mode 100644 index 00000000..324abd5e --- /dev/null +++ b/mock-plugin/src/main/java/io/mosip/signup/plugin/mock/verifier/DemoIdentityVerifierPluginImpl.java @@ -0,0 +1,136 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ +package io.mosip.signup.plugin.mock.verifier; + +import com.fasterxml.jackson.databind.ObjectMapper; +import io.mosip.signup.api.dto.*; +import io.mosip.signup.api.exception.IdentityVerifierException; +import io.mosip.signup.api.spi.IdentityVerifierPlugin; +import io.mosip.signup.api.util.ProcessType; +import io.mosip.signup.api.util.VerificationStatus; +import io.mosip.signup.plugin.mock.dto.MockScene; +import io.mosip.signup.plugin.mock.dto.MockUserStory; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.core.io.Resource; +import org.springframework.core.io.ResourceLoader; +import org.springframework.stereotype.Component; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; +import java.util.*; +import java.util.stream.Collectors; + +import static io.mosip.signup.api.util.ProcessType.VIDEO; + +@Slf4j +@Component +public class DemoIdentityVerifierPluginImpl extends IdentityVerifierPlugin { + + @Value("${mosip.signup.test.identity-verification.story-name}") + private String storyName; + + @Value("${mosip.signup.mock.config-server-url}") + private String configServerUrl; + + @Autowired + private ResourceLoader resourceLoader; + + @Autowired + private ObjectMapper objectMapper; + + @Override + public String getVerifierId() { + return "demo-identity-verifier"; + } + + @Override + public List getSupportedProcessTypes() { + return List.of(VIDEO); + } + + @Override + public void initialize(String transactionId, IdentityVerificationInitDto identityVerificationInitDto) { + log.info("Transaction is initialized for transactionId : {} and disabilityType: {}", + transactionId, identityVerificationInitDto.getDisabilityType()); + log.info("**** Nothing to initialize as its mock identity verification plugin ****"); + } + + @Override + public void verify(String transactionId, IdentityVerificationDto identityVerificationDto) throws IdentityVerifierException { + MockUserStory mockUserStory = getResource(configServerUrl+storyName, MockUserStory.class); + log.info("Loaded user story : {} for transaction: {}", storyName, transactionId); + + IdentityVerificationResult identityVerificationResult = new IdentityVerificationResult(); + identityVerificationResult.setId(transactionId); + identityVerificationResult.setVerifierId(getVerifierId()); + + log.info("input message step code : {} for transaction: {}", identityVerificationDto.getStepCode(), transactionId); + if(isStartStep(identityVerificationDto.getStepCode())) { + Optional result = Objects.requireNonNull(mockUserStory).getScenes().stream() + .filter(scene -> scene.getFrameNumber() == 0 && scene.getStepCode().equals(identityVerificationDto.getStepCode())) + .findFirst(); + + if(result.isPresent()) { + identityVerificationResult.setStep(result.get().getStep()); + identityVerificationResult.setFeedback(result.get().getFeedback()); + publishAnalysisResult(identityVerificationResult); + } + } + + if(identityVerificationDto.getFrames() == null || identityVerificationDto.getFrames().isEmpty()) { + log.info("No Frames found in the request {}, nothing to do", transactionId); + return; + } + + for(FrameDetail frameDetail : identityVerificationDto.getFrames()) { + Optional matchedScene = Objects.requireNonNull(mockUserStory).getScenes().stream() + .filter(scene -> scene.getFrameNumber() == frameDetail.getOrder() && + scene.getStepCode().equals(identityVerificationDto.getStepCode())) + .findFirst(); + log.info("{} Search match for current frame {} in the story for transaction: {}", identityVerificationDto.getStepCode(), + frameDetail.getOrder(), transactionId); + if(matchedScene.isPresent()) { + log.info("Match found in the story : {} for transaction: {}", matchedScene.get(), transactionId); + identityVerificationResult.setStep(matchedScene.get().getStep()); + identityVerificationResult.setFeedback(matchedScene.get().getFeedback()); + publishAnalysisResult(identityVerificationResult); + } + } + } + + @Override + public VerificationResult getVerificationResult(String transactionId) throws IdentityVerifierException { + MockUserStory mockUserStory = getResource(configServerUrl+storyName, MockUserStory.class); + if(mockUserStory != null && mockUserStory.getVerificationResult() != null) { + try { + return objectMapper.treeToValue(mockUserStory.getVerificationResult(), VerificationResult.class); + } catch (Exception e) { + log.error("Failed to parse verified attributes in the mock user story: {}", storyName, e); + } + } + VerificationResult verificationResult = new VerificationResult(); + verificationResult.setStatus(VerificationStatus.FAILED); + verificationResult.setErrorCode("mock_verification_failed"); + return verificationResult; + } + + private T getResource(String url, Class clazz) { + Resource resource = resourceLoader.getResource(url); + try (BufferedReader reader = new BufferedReader( + new InputStreamReader(resource.getInputStream(), StandardCharsets.UTF_8))) { + String content = reader.lines().collect(Collectors.joining("\n")); + return objectMapper.readValue(content, clazz); + } catch (IOException e) { + log.error("Failed to parse data: {}", url, e); + } + throw new IdentityVerifierException("invalid_configuration"); + } + +} \ No newline at end of file