From 4e83c346e6ed40fe4b3011c8364c5bb31c2c675d Mon Sep 17 00:00:00 2001 From: "Ritik Jain (IN74108)" Date: Fri, 17 May 2024 19:09:34 +0530 Subject: [PATCH] update code to publish event Signed-off-by: Ritik Jain (IN74108) --- .../IdChangeEventHandlerServiceImpl.java | 26 ++++++++++++++++--- .../impl/idevent/RemoveIdStatusEvent.java | 25 ++++++++++++++++++ .../constant/IdAuthConfigKeyConstants.java | 1 + 3 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/impl/idevent/RemoveIdStatusEvent.java diff --git a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/impl/idevent/IdChangeEventHandlerServiceImpl.java b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/impl/idevent/IdChangeEventHandlerServiceImpl.java index d1b9a9077d6..1eaa5aad8af 100644 --- a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/impl/idevent/IdChangeEventHandlerServiceImpl.java +++ b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/impl/idevent/IdChangeEventHandlerServiceImpl.java @@ -1,5 +1,7 @@ package io.mosip.authentication.common.service.impl.idevent; +import static io.mosip.authentication.core.constant.IdAuthConfigKeyConstants.REMOVE_ID_STATUS_TOPIC; + import java.time.LocalDateTime; import java.util.Map; import java.util.Optional; @@ -7,10 +9,12 @@ import javax.transaction.Transactional; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import io.mosip.authentication.common.service.entity.IdentityEntity; import io.mosip.authentication.common.service.helper.AuditHelper; +import io.mosip.authentication.common.service.helper.WebSubHelper; import io.mosip.authentication.common.service.repository.IdentityCacheRepository; import io.mosip.authentication.common.service.spi.idevent.CredentialStoreService; import io.mosip.authentication.core.constant.AuditEvents; @@ -75,6 +79,14 @@ static interface ConsumerWithBusinessException { @Autowired private CredentialStoreService credStorService; + + /** The web sub event publish helper. */ + @Autowired + private WebSubHelper webSubHelper; + + /** The remove id status topic. */ + @Value("${" + REMOVE_ID_STATUS_TOPIC + "}") + private String removeIdStatusTopic; /* (non-Javadoc) * @see io.mosip.authentication.core.spi.idevent.service.IdChangeEventHandlerService#handleIdEvent(java.util.List) @@ -183,11 +195,19 @@ private void handleRemoveId(EventModel eventModel) throws IdAuthenticationBusine Event event = eventModel.getEvent(); Map additionalData = event.getData(); String idHash = (String) additionalData.get(ID_HASH); - Optional identityEntityOpt = identityCacheRepo.findById(idHash); - if(identityEntityOpt.isPresent()) { - identityCacheRepo.delete(identityEntityOpt.get()); + if (idHash != null && !idHash.isEmpty()) { + identityCacheRepo.deleteById(idHash); + publishRemoveIdStatusEvent(idHash); } } + + public void publishRemoveIdStatusEvent(String idHash) { + RemoveIdStatusEvent removeIdStatusEvent = new RemoveIdStatusEvent(); + removeIdStatusEvent.setData(Map.of(ID_HASH, idHash)); + removeIdStatusEvent.setTimestamp(DateUtils.formatToISOString(DateUtils.getUTCCurrentDateTime())); + webSubHelper.publishEvent(removeIdStatusTopic, + webSubHelper.createEventModel(removeIdStatusTopic, removeIdStatusEvent)); + } private void handleDeactivateId(EventModel eventModel) throws IdAuthenticationBusinessException { updateIdentityMetadata(eventModel); diff --git a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/impl/idevent/RemoveIdStatusEvent.java b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/impl/idevent/RemoveIdStatusEvent.java new file mode 100644 index 00000000000..d4b2f284f01 --- /dev/null +++ b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/impl/idevent/RemoveIdStatusEvent.java @@ -0,0 +1,25 @@ +package io.mosip.authentication.common.service.impl.idevent; + +import java.util.Map; + +import io.mosip.authentication.common.service.websub.dto.EventInterface; +import lombok.Data; + +/** + * Instantiates a new remove id status event. + * + * @author Ritik Jain + */ +@Data +public class RemoveIdStatusEvent implements EventInterface { + + /** The id. */ + private String id; + + /** The timestamp. */ + private String timestamp; + + /** The data. */ + private Map data; + +} diff --git a/authentication/authentication-core/src/main/java/io/mosip/authentication/core/constant/IdAuthConfigKeyConstants.java b/authentication/authentication-core/src/main/java/io/mosip/authentication/core/constant/IdAuthConfigKeyConstants.java index 79f48e37800..9b69469d879 100644 --- a/authentication/authentication-core/src/main/java/io/mosip/authentication/core/constant/IdAuthConfigKeyConstants.java +++ b/authentication/authentication-core/src/main/java/io/mosip/authentication/core/constant/IdAuthConfigKeyConstants.java @@ -135,6 +135,7 @@ private IdAuthConfigKeyConstants() { public static final String AUTH_ANONYMOUS_PROFILE_TOPIC = "ida-topic-auth-anonymous-profile"; public static final String AUTH_FRAUD_ANALYSIS_TOPIC = "ida-topic-fraud-analysis"; public static final String AUTHENTICATION_ERROR_EVENTING_TOPIC = "ida-topic-authentication-error-eventing"; + public static final String REMOVE_ID_STATUS_TOPIC = "ida-topic-remove-id-status"; public static final String IDA_MAX_CREDENTIAL_PULL_WINDOW_DAYS = "ida-max-credential-pull-window-days";