diff --git a/pre-registration/pre-registration-application-service/pom.xml b/pre-registration/pre-registration-application-service/pom.xml index 31d3bf9c1db..703b4e5c557 100644 --- a/pre-registration/pre-registration-application-service/pom.xml +++ b/pre-registration/pre-registration-application-service/pom.xml @@ -16,8 +16,9 @@ UTF-8 1.1.5.3 - 1.1.5.3 + 1.1.5.4 1.1.5.3 + 1.1.4 1.1.5.3 1.1.5.3 diff --git a/pre-registration/pre-registration-application-service/src/main/java/io/mosip/preregistration/application/service/DocumentService.java b/pre-registration/pre-registration-application-service/src/main/java/io/mosip/preregistration/application/service/DocumentService.java index d24ec7d2106..2f548439c6e 100644 --- a/pre-registration/pre-registration-application-service/src/main/java/io/mosip/preregistration/application/service/DocumentService.java +++ b/pre-registration/pre-registration-application-service/src/main/java/io/mosip/preregistration/application/service/DocumentService.java @@ -26,6 +26,7 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; +import io.mosip.commons.khazana.exception.ObjectStoreAdapterException; import io.mosip.commons.khazana.spi.ObjectStoreAdapter; import io.mosip.kernel.core.authmanager.authadapter.model.AuthUserDetails; import io.mosip.kernel.core.logger.spi.Logger; @@ -405,8 +406,15 @@ public void copyFile(DocumentEntity copyDocumentEntity, String sourceBucketName, if (copyDocumentEntity != null) { destinationBucketName = copyDocumentEntity.getDemographicEntity().getPreRegistrationId(); destinationKey = copyDocumentEntity.getDocCatCode() + "_" + copyDocumentEntity.getDocumentId(); - InputStream sourcefile = objectStore.getObject(objectStoreAccountName, sourceBucketName, null, null, + InputStream sourcefile = null; + try { + sourcefile = objectStore.getObject(objectStoreAccountName, sourceBucketName, null, null, sourceKey); + }catch (Exception e) { + // for backward compatibility(by force sending 'object.store.s3.use.account.as.bucketname' as false) + sourcefile = objectStore.getObject(objectStoreAccountName, sourceBucketName, null, null, sourceKey, + false); + } boolean isStoreSuccess = objectStore.putObject(objectStoreAccountName, destinationBucketName, null, null, destinationKey, sourcefile); if (!isStoreSuccess) { @@ -499,11 +507,25 @@ public MainResponseDTO getDocumentForDocId(String docId, String pre DocumentErrorMessages.INVALID_DOCUMENT_ID.getMessage()); } String key = documentEntity.getDocCatCode() + "_" + documentEntity.getDocumentId(); - InputStream sourcefile = objectStore.getObject(objectStoreAccountName, - documentEntity.getDemographicEntity().getPreRegistrationId(), null, null, key); - if (sourcefile == null) { - throw new FSServerException(DocumentErrorCodes.PRG_PAM_DOC_005.toString(), - DocumentErrorMessages.DOCUMENT_FAILED_TO_FETCH.getMessage()); + InputStream sourcefile = null; + try { + sourcefile = objectStore.getObject(objectStoreAccountName, + documentEntity.getDemographicEntity().getPreRegistrationId(), null, null, key); + } catch (Exception e) { + if (e instanceof ObjectStoreAdapterException) { + // for backward compatibility(by force sending + // 'object.store.s3.use.account.as.bucketname' as false) + sourcefile = objectStore.getObject(objectStoreAccountName, + documentEntity.getDemographicEntity().getPreRegistrationId(), null, null, key, false); + }else { + new DocumentExceptionCatcher().handle(e, responseDto); + } + } + if (sourcefile == null) { + if (sourcefile == null) { + throw new FSServerException(DocumentErrorCodes.PRG_PAM_DOC_005.toString(), + DocumentErrorMessages.DOCUMENT_FAILED_TO_FETCH.getMessage()); + } } byte[] cephBytes = IOUtils.toByteArray(sourcefile); if (documentEntity.getDocHash().equals(HashUtill.hashUtill(cephBytes))) { diff --git a/pre-registration/pre-registration-application-service/src/main/java/io/mosip/preregistration/application/service/util/DocumentServiceUtil.java b/pre-registration/pre-registration-application-service/src/main/java/io/mosip/preregistration/application/service/util/DocumentServiceUtil.java index 7d3d143a659..6285c256f75 100644 --- a/pre-registration/pre-registration-application-service/src/main/java/io/mosip/preregistration/application/service/util/DocumentServiceUtil.java +++ b/pre-registration/pre-registration-application-service/src/main/java/io/mosip/preregistration/application/service/util/DocumentServiceUtil.java @@ -265,8 +265,16 @@ public DocumentEntity documentEntitySetter(String destinationPreId, DocumentEnti copyDocumentEntity.setDemographicEntity(demographicEntity); copyDocumentEntity.setDocId(sourceEntity.getDocId()); String key = sourceEntity.getDocCatCode() + "_" + sourceEntity.getDocumentId(); - InputStream file = objectStore.getObject(objectStoreAccountName, - sourceEntity.getDemographicEntity().getPreRegistrationId(), null, null, key); + InputStream file = null; + try { + file = objectStore.getObject(objectStoreAccountName, + sourceEntity.getDemographicEntity().getPreRegistrationId(), null, null, key); + } catch (Exception e) { + // for backward compatibility(by force sending + // 'object.store.s3.use.account.as.bucketname' as false) + file = objectStore.getObject(objectStoreAccountName, + sourceEntity.getDemographicEntity().getPreRegistrationId(), null, null, key, false); + } copyDocumentEntity.setDocHash(HashUtill.hashUtill(IOUtils.toByteArray(file))); copyDocumentEntity.setDocName(sourceEntity.getDocName()); copyDocumentEntity.setDocTypeCode(sourceEntity.getDocTypeCode());