From f9bd9e1156fecbe4b4a90f27445b4b328a596423 Mon Sep 17 00:00:00 2001 From: Rajitha Kumara Date: Wed, 30 Oct 2024 11:32:50 +0530 Subject: [PATCH] Add stream base file download support --- .../mgt/common/services/AppmDataHandler.java | 12 ++++++++++++ .../mgt/core/impl/AppmDataHandlerImpl.java | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/services/AppmDataHandler.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/services/AppmDataHandler.java index 4b15b3f660..36d25baa42 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/services/AppmDataHandler.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/services/AppmDataHandler.java @@ -50,4 +50,16 @@ public interface AppmDataHandler { * @throws ApplicationManagementException throws if an error occurs when accessing the file. */ InputStream getAgentStream(String tenantDomain, String deviceType) throws ApplicationManagementException; + + /** + * Check if the artifact is existing in the file system + * + * @param hashVal Hash Value of the application + * @param folderName Folder name + * @param fileName Artifact file name + * @param tenantId Tenant id + * @return true if the artifact exists, otherwise false + * @throws ApplicationManagementException if error occurred while checking the existence of the artifact + */ + boolean isArtifactExists(String hashVal, String folderName, String fileName, int tenantId) throws ApplicationManagementException; } diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/impl/AppmDataHandlerImpl.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/impl/AppmDataHandlerImpl.java index 73bb748c23..952c3ad1ea 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/impl/AppmDataHandlerImpl.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/impl/AppmDataHandlerImpl.java @@ -35,6 +35,7 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import java.io.File; import java.io.InputStream; import java.util.Map; @@ -136,4 +137,11 @@ public class AppmDataHandlerImpl implements AppmDataHandler { throw new ApplicationManagementException(msg, e); } } + + @Override + public boolean isArtifactExists(String hashVal, String folderName, String fileName, int tenantId) throws BadRequestException { + validateArtifactDownloadRequest(tenantId, hashVal, folderName, fileName); + return new File(APIUtil. + getApplicationStorageManager().getAbsolutePathOfFile(hashVal, folderName, fileName, tenantId)).exists(); + } }