Skip to content

Commit

Permalink
Merge pull request #545 from NagarjunaKuchi/1.1.5.3
Browse files Browse the repository at this point in the history
[MOSIP-21469] Added backward compatibility for document fetch
  • Loading branch information
ckm007 authored May 10, 2022
2 parents 6b0c222 + 7af3227 commit 797e2ed
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<kernel.core.version>1.1.5.2</kernel.core.version>
<kernel.khazana.version>1.1.5.2</kernel.khazana.version>
<kernel.khazana.version>1.1.5.4-SNAPSHOT</kernel.khazana.version>
<kernel.idgenerator.prid.version>1.1.5.2</kernel.idgenerator.prid.version>
<kernel.virusscanner.clamav.version>1.1.4</kernel.virusscanner.clamav.version>
<kernel.idobjectvalidator.version>1.1.5.2</kernel.idobjectvalidator.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -499,11 +507,25 @@ public MainResponseDTO<DocumentDTO> 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))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 797e2ed

Please sign in to comment.