Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mosip 22874 authtype lock websub issue 3 #853

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public enum ServiceType {
ID_MANAGEMENT_REQUEST(List.of(RequestType.GENERATE_VID, RequestType.REVOKE_VID,
RequestType.VALIDATE_OTP, RequestType.AUTH_TYPE_LOCK_UNLOCK)),
DATA_SHARE_REQUEST(List.of(RequestType.SHARE_CRED_WITH_PARTNER)),
ASYNC(List.of(RequestType.VID_CARD_DOWNLOAD,RequestType.ORDER_PHYSICAL_CARD,RequestType.SHARE_CRED_WITH_PARTNER,RequestType.UPDATE_MY_UIN)),
ASYNC(List.of(RequestType.VID_CARD_DOWNLOAD, RequestType.ORDER_PHYSICAL_CARD, RequestType.SHARE_CRED_WITH_PARTNER,
RequestType.UPDATE_MY_UIN, RequestType.AUTH_TYPE_LOCK_UNLOCK)),
ALL(List.of(RequestType.VALIDATE_OTP, RequestType.DOWNLOAD_PERSONALIZED_CARD, RequestType.ORDER_PHYSICAL_CARD,
RequestType.GET_MY_ID, RequestType.BOOK_AN_APPOINTMENT, RequestType.VID_CARD_DOWNLOAD, RequestType.UPDATE_MY_UIN,
RequestType.GENERATE_VID, RequestType.REVOKE_VID, RequestType.AUTH_TYPE_LOCK_UNLOCK,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

/**
Expand All @@ -28,10 +29,12 @@
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
public class ResidentTransactionEntity {

@Id
@Column(name = "event_id")
@EqualsAndHashCode.Include
private String eventId;

@Column(name = "request_trn_id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
public interface ResidentTransactionRepository extends JpaRepository<ResidentTransactionEntity, String> {
List<ResidentTransactionEntity> findByRequestTrnIdAndRefIdOrderByCrDtimesDesc(String requestTrnId, String refId);

List<ResidentTransactionEntity> findByCredentialRequestId(String credentialRequestId);
List<ResidentTransactionEntity> findByRequestTrnId(String requestTrnId);

ResidentTransactionEntity findTopByRequestTrnIdAndTokenIdAndStatusCodeOrderByCrDtimesDesc
(String requestTrnId, String tokenId, String statusCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public class BaseWebSubInitializer implements ApplicationListener<ApplicationRea
@Override
public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent) {
logger.info("onApplicationEvent", "BaseWebSubInitializer", "Application is ready");
logger.info("Scheduling event subscriptions after (milliseconds): " + taskSubscriptionInitialDelay);
taskScheduler.schedule(() -> {
//Invoke topic registrations. This is done only once.
//Note: With authenticated websub, only register topics which are only published by IDA
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
package io.mosip.resident.service.impl;

import static io.mosip.resident.constant.ResidentConstants.RESIDENT;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import io.mosip.kernel.core.logger.spi.Logger;
import io.mosip.kernel.core.util.DateUtils;
import io.mosip.kernel.core.websub.model.EventModel;
import io.mosip.resident.config.LoggerConfiguration;
import io.mosip.resident.constant.EventStatusSuccess;
import io.mosip.resident.constant.LoggerFileConstant;
import io.mosip.resident.constant.RequestType;
import io.mosip.resident.constant.ResidentConstants;
Expand Down Expand Up @@ -56,14 +61,14 @@ public void updateAuthTypeStatus(EventModel eventModel) throws ResidentServiceCh
auditUtil.setAuditRequestDto(EventEnum.UPDATE_AUTH_TYPE_STATUS);
try{
logger.info("WebSubUpdateAuthTypeServiceImpl::updateAuthTypeStatus()::partnerId");
Tuple2<String, String> tupleResponse = updateInResidentTransactionTable(eventModel, "COMPLETED");
Tuple2<String, String> tupleResponse = updateInResidentTransactionTable(eventModel, EventStatusSuccess.COMPLETED.name());
sendNotificationV2(TemplateType.SUCCESS, tupleResponse.getT1(), tupleResponse.getT2());
}
catch (Exception e) {
logger.error(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.APPLICATIONID.toString(),
LoggerFileConstant.APPLICATIONID.toString(),
"WebSubUpdateAuthTypeServiceImpl::updateAuthTypeStatus()::exception");
Tuple2<String, String> tupleResponse = updateInResidentTransactionTable(eventModel, "FAILED");
Tuple2<String, String> tupleResponse = updateInResidentTransactionTable(eventModel, EventStatusSuccess.COMPLETED.name());
sendNotificationV2(TemplateType.FAILURE, tupleResponse.getT1(), tupleResponse.getT2());
throw new ResidentServiceCheckedException(
ResidentErrorCode.RESIDENT_WEBSUB_UPDATE_AUTH_TYPE_FAILED.getErrorCode(),
Expand All @@ -77,20 +82,16 @@ private Tuple2<String, String> updateInResidentTransactionTable(EventModel event
LoggerFileConstant.APPLICATIONID.toString(), "WebSubUpdateAuthTypeServiceImpl::insertInResidentTransactionTable()::entry");
String eventId = "";
String individualId = "";
List<ResidentTransactionEntity> residentTransactionEntities = new ArrayList<>();
List<ResidentTransactionEntity> residentTransactionEntities = List.of();
try {
List<Map<String, Object>> authTypeStatusList = (List<Map<String, Object>>) eventModel.getEvent().getData().get(AUTH_TYPES);
for(Map<String, Object> authType:authTypeStatusList){
residentTransactionEntities = residentTransactionRepository.findByCredentialRequestId((String)authType.get(REQUEST_ID));
if(residentTransactionEntities!=null){
residentTransactionEntities.stream().forEach(residentTransactionEntity -> {
residentTransactionEntity.setStatusCode(status);
residentTransactionEntity.setReadStatus(false);
});
}
}
residentTransactionRepository.saveAll(residentTransactionEntities);
if (residentTransactionEntities != null && !residentTransactionEntities.isEmpty()) {

residentTransactionEntities = authTypeStatusList.stream()
.flatMap(authTypeStatus -> residentTransactionRepository.findByRequestTrnId((String)authTypeStatus.get(REQUEST_ID)).stream())
.distinct()
.collect(Collectors.toList());
//Get the values before saving, otherwise individual ID will be updated in encrypted format in the entity
if (residentTransactionEntities != null && !residentTransactionEntities.isEmpty()) {
eventId = residentTransactionEntities.stream()
.filter(entity -> entity.getOlvPartnerId().equals(onlineVerificationPartnerId))
.map(entity -> entity.getEventId())
Expand All @@ -103,6 +104,15 @@ private Tuple2<String, String> updateInResidentTransactionTable(EventModel event
.findAny()
.orElse(ResidentConstants.NOT_AVAILABLE);
}

//Update status
residentTransactionEntities.stream().forEach(residentTransactionEntity -> {
residentTransactionEntity.setStatusCode(status);
residentTransactionEntity.setReadStatus(false);
residentTransactionEntity.setUpdBy(RESIDENT);
residentTransactionEntity.setUpdDtimes(DateUtils.getUTCCurrentDateTime());
});
residentTransactionRepository.saveAll(residentTransactionEntities);
}
catch (Exception e) {
logger.error(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.APPLICATIONID.toString(),
Expand Down