Skip to content

Commit

Permalink
update code to publish event
Browse files Browse the repository at this point in the history
Signed-off-by: Ritik Jain (IN74108) <[email protected]>
  • Loading branch information
Ritik Jain (IN74108) committed May 17, 2024
1 parent 6027bd1 commit 4e83c34
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
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;

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;
Expand Down Expand Up @@ -75,6 +79,14 @@ static interface ConsumerWithBusinessException<T,R> {

@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)
Expand Down Expand Up @@ -183,11 +195,19 @@ private void handleRemoveId(EventModel eventModel) throws IdAuthenticationBusine
Event event = eventModel.getEvent();
Map<String, Object> additionalData = event.getData();
String idHash = (String) additionalData.get(ID_HASH);
Optional<IdentityEntity> 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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, Object> data;

}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit 4e83c34

Please sign in to comment.