diff --git a/admin/admin-service/src/main/java/io/mosip/admin/packetstatusupdater/util/RestClient.java b/admin/admin-service/src/main/java/io/mosip/admin/packetstatusupdater/util/RestClient.java index 23187f4162e..83357fc9fea 100644 --- a/admin/admin-service/src/main/java/io/mosip/admin/packetstatusupdater/util/RestClient.java +++ b/admin/admin-service/src/main/java/io/mosip/admin/packetstatusupdater/util/RestClient.java @@ -1,10 +1,7 @@ package io.mosip.admin.packetstatusupdater.util; -import java.io.IOException; -import java.util.Iterator; -import java.util.List; - import io.mosip.admin.constant.ApplicantDetailErrorCode; +import io.mosip.admin.packetstatusupdater.constant.ApiName; import io.mosip.admin.packetstatusupdater.exception.MasterDataServiceException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.Environment; @@ -16,7 +13,9 @@ import org.springframework.web.util.UriComponents; import org.springframework.web.util.UriComponentsBuilder; -import io.mosip.admin.packetstatusupdater.constant.ApiName; +import java.io.IOException; +import java.util.Iterator; +import java.util.List; @@ -202,9 +201,10 @@ public T getApi(String url, T result = null; try { - ResponseEntity responseEntity= (ResponseEntity) restTemplate + ResponseEntity responseEntity= restTemplate .exchange(url, HttpMethod.GET, setRequestHeader(null, null), responseType); - if(url.contains("datashare") && responseEntity.getHeaders().getContentType().equals(MediaType.APPLICATION_JSON)){ + if(url != null && url.contains("datashare") && responseEntity != null && responseEntity.getHeaders() != null && + responseEntity.getHeaders().getContentType().equals(MediaType.APPLICATION_JSON)){ throw new MasterDataServiceException(ApplicantDetailErrorCode.DATA_SHARE_EXPIRED_EXCEPTION.getErrorCode(), ApplicantDetailErrorCode.DATA_SHARE_EXPIRED_EXCEPTION.getErrorMessage()); } diff --git a/admin/admin-service/src/main/java/io/mosip/admin/service/impl/ApplicantDetailServiceImpl.java b/admin/admin-service/src/main/java/io/mosip/admin/service/impl/ApplicantDetailServiceImpl.java index b37790e84ed..316e7ff91ca 100644 --- a/admin/admin-service/src/main/java/io/mosip/admin/service/impl/ApplicantDetailServiceImpl.java +++ b/admin/admin-service/src/main/java/io/mosip/admin/service/impl/ApplicantDetailServiceImpl.java @@ -8,7 +8,6 @@ import io.mosip.admin.dto.ApplicantUserDetailsDto; import io.mosip.admin.dto.DigitalCardStatusResponseDto; import io.mosip.admin.packetstatusupdater.constant.ApiName; - import io.mosip.admin.packetstatusupdater.exception.DataNotFoundException; import io.mosip.admin.packetstatusupdater.exception.MasterDataServiceException; import io.mosip.admin.packetstatusupdater.exception.RequestException; @@ -26,6 +25,8 @@ import org.json.JSONException; import org.json.simple.JSONArray; import org.json.simple.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.security.core.context.SecurityContextHolder; @@ -42,6 +43,8 @@ public class ApplicantDetailServiceImpl implements ApplicantDetailService { private static final String FACE = "Face"; + private static final Logger log = LoggerFactory.getLogger(ApplicantDetailServiceImpl.class); + @Autowired RestClient restClient; @@ -69,7 +72,7 @@ public class ApplicantDetailServiceImpl implements ApplicantDetailService { private static final String DOCUMENTS="documents"; - private static final String ApplicantPhoto = "applicantPhoto"; + private static final String APPLICANTPHOTO = "applicantPhoto"; private static final String VALUE = "value"; private static final String DOB = "dob"; @@ -110,11 +113,17 @@ public ApplicantDetailsDto getApplicantDetails(String rid) throws Exception { JSONObject mapperIdentity=utility.getJSONObject(idenitityJsonObject,IDENTITY); List mapperJsonKeys = new ArrayList<>(mapperIdentity.keySet()); for(String valueObj: applicantDetails){ - if(valueObj!=null && !valueObj.equalsIgnoreCase(ApplicantPhoto)){ + if (valueObj == null) { + log.warn("Encountered null value in applicantDetails list"); + continue; + } + if(!valueObj.equalsIgnoreCase(APPLICANTPHOTO)){ LinkedHashMap jsonObject = utility.getJSONValue(mapperIdentity, valueObj); - String value = jsonObject.get(VALUE); - applicantDataMap.put(value,identityObj.get(value).toString()); - } else if (valueObj.equalsIgnoreCase(ApplicantPhoto)) { + if (jsonObject != null && VALUE != null && jsonObject.containsKey(VALUE)) { + String value = jsonObject.get(VALUE); + applicantDataMap.put(value, identityObj.get(value).toString()); + } + } else { getImageData(documents,applicantDataMap); } } @@ -187,7 +196,7 @@ private void getImageData(JSONArray documents, Map applicantData byte[] data = FaceDecoder.convertFaceISOToImageBytes(convertRequestDto); String encodedBytes = StringUtils.newStringUtf8(Base64.encodeBase64(data, false)); String imageData = "data:image/png;base64," + encodedBytes; - applicantDataMap.put(ApplicantPhoto, imageData); + applicantDataMap.put(APPLICANTPHOTO, imageData); } else { throw new DataNotFoundException(ApplicantDetailErrorCode.DATA_NOT_FOUND.getErrorCode(), ApplicantDetailErrorCode.DATA_NOT_FOUND.getErrorMessage()); } diff --git a/admin/kernel-syncdata-service/src/main/java/io/mosip/kernel/syncdata/service/helper/ClientSettingsHelper.java b/admin/kernel-syncdata-service/src/main/java/io/mosip/kernel/syncdata/service/helper/ClientSettingsHelper.java index 25cdceb711b..72aee885c62 100644 --- a/admin/kernel-syncdata-service/src/main/java/io/mosip/kernel/syncdata/service/helper/ClientSettingsHelper.java +++ b/admin/kernel-syncdata-service/src/main/java/io/mosip/kernel/syncdata/service/helper/ClientSettingsHelper.java @@ -65,7 +65,7 @@ private boolean hasURLDetails(Class clazz, boolean isV2API, boolean deltaSync) { public Map getInitiateDataFetch(String machineId, String regCenterId, LocalDateTime lastUpdated, LocalDateTime currentTimestamp, boolean isV2API, boolean deltaSync, String fullSyncEntities) { - List entities = (fullSyncEntities != null && !fullSyncEntities.isBlank()) ? Arrays.asList(fullSyncEntities.split("\\s*,\\s*")) : new ArrayList<>(); + List entities = (fullSyncEntities != null && !fullSyncEntities.isBlank()) ? Arrays.asList(fullSyncEntities.split("\\s*,\\s*",-1)) : new ArrayList<>(); Map futuresMap = new HashMap<>(); futuresMap.put(AppAuthenticationMethod.class, @@ -201,10 +201,10 @@ public List retrieveData(Map futures, } private void handleDynamicData(List entities, List list, RegistrationCenterMachineDto registrationCenterMachineDto, boolean isV2) { - Map> data = new HashMap>(); + Map> data = new HashMap<>(); entities.forEach(dto -> { if (!data.containsKey(((DynamicFieldDto) dto).getName())) { - List langBasedData = new ArrayList(); + List langBasedData = new ArrayList<>(); langBasedData.add(((DynamicFieldDto) dto)); data.put(((DynamicFieldDto) dto).getName(), langBasedData); } else diff --git a/admin/kernel-syncdata-service/src/main/java/io/mosip/kernel/syncdata/service/helper/SyncJobHelperService.java b/admin/kernel-syncdata-service/src/main/java/io/mosip/kernel/syncdata/service/helper/SyncJobHelperService.java index 411b8170987..4276a1a7560 100644 --- a/admin/kernel-syncdata-service/src/main/java/io/mosip/kernel/syncdata/service/helper/SyncJobHelperService.java +++ b/admin/kernel-syncdata-service/src/main/java/io/mosip/kernel/syncdata/service/helper/SyncJobHelperService.java @@ -81,13 +81,23 @@ public LocalDateTime getFullSyncCurrentTimestamp() { public LocalDateTime getDeltaSyncCurrentTimestamp() { CronExpression cronExpression = CronExpression.parse(deltaCacheEvictCron); - LocalDateTime nextTrigger1 = cronExpression.next(LocalDateTime.now().atZone(ZoneOffset.UTC).toLocalDateTime()); - LocalDateTime nextTrigger2 = cronExpression.next(nextTrigger1); - long minutes = ChronoUnit.MINUTES.between(nextTrigger1.toInstant(ZoneOffset.UTC).atZone(ZoneOffset.UTC).toLocalDateTime(), - nextTrigger2.toInstant(ZoneOffset.UTC).atZone(ZoneOffset.UTC).toLocalDateTime()); + LocalDateTime immediateNextTrigger = cronExpression.next(LocalDateTime.now().atZone(ZoneOffset.UTC).toLocalDateTime()); + if (immediateNextTrigger == null) { + logger.error("Cron expression might be invalid or has no upcoming triggers."); + return null; + } + + LocalDateTime nextTrigger = cronExpression.next(immediateNextTrigger); + if (nextTrigger == null) { + logger.error("No upcoming triggers after {}", immediateNextTrigger); + return null; + } + + long minutes = ChronoUnit.MINUTES.between(immediateNextTrigger.toInstant(ZoneOffset.UTC).atZone(ZoneOffset.UTC).toLocalDateTime(), + nextTrigger.toInstant(ZoneOffset.UTC).atZone(ZoneOffset.UTC).toLocalDateTime()); - LocalDateTime previousTrigger = nextTrigger1.toInstant(ZoneOffset.UTC).atZone(ZoneOffset.UTC).toLocalDateTime().minus(minutes, ChronoUnit.MINUTES); + LocalDateTime previousTrigger = immediateNextTrigger.toInstant(ZoneOffset.UTC).atZone(ZoneOffset.UTC).toLocalDateTime().minus(minutes, ChronoUnit.MINUTES); logger.debug("Identified previous trigger : {}", previousTrigger); return previousTrigger; @@ -177,10 +187,10 @@ private void retrieveAndCreateSnapshot(Map futures) { } private void handleDynamicFields(List entities) { - Map> data = new HashMap>(); + Map> data = new HashMap<>(); entities.forEach(dto -> { if(!data.containsKey(((DynamicFieldDto)dto).getName())) { - List langBasedData = new ArrayList(); + List langBasedData = new ArrayList<>(); langBasedData.add(((DynamicFieldDto)dto)); data.put(((DynamicFieldDto)dto).getName(), langBasedData); }