From 2aafde8f351bfc6bab488e87d2d66000937ac915 Mon Sep 17 00:00:00 2001 From: Rajitha Kumara Date: Tue, 30 Jan 2024 07:55:17 +0530 Subject: [PATCH] Add multipart form data uploading --- .../wrapper/CustomAppReleaseWrapper.java | 23 ++++++++++++++++ .../common/wrapper/EntAppReleaseWrapper.java | 23 ++++++++++++++++ .../mgt/core/impl/ApplicationManagerImpl.java | 27 +++++++++++++++---- .../management/ApplicationManagementTest.java | 5 ++-- 4 files changed, 71 insertions(+), 7 deletions(-) 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/wrapper/CustomAppReleaseWrapper.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/wrapper/CustomAppReleaseWrapper.java index af4d6b6dbd..75ffa1f687 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/wrapper/CustomAppReleaseWrapper.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/wrapper/CustomAppReleaseWrapper.java @@ -22,6 +22,7 @@ import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import javax.validation.constraints.NotNull; +import java.io.InputStream; import java.util.List; @ApiModel(value = "CustomAppReleaseWrapper", description = "This class holds the details when releasing an Custom app release to application store") @@ -84,6 +85,28 @@ public class CustomAppReleaseWrapper { value = "banner of the application") private Base64File banner; + @ApiModelProperty(name = "installerStream", value = "custom apk's stream") + private InputStream installerStream; + + @ApiModelProperty(name = "installerName", value = "custom apk's name") + private String installerName; + + public InputStream getInstallerStream() { + return installerStream; + } + + public void setInstallerStream(InputStream installerStream) { + this.installerStream = installerStream; + } + + public String getInstallerName() { + return installerName; + } + + public void setInstallerName(String installerName) { + this.installerName = installerName; + } + public String getReleaseType() { return releaseType; } 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/wrapper/EntAppReleaseWrapper.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/wrapper/EntAppReleaseWrapper.java index 91ad28aae5..f700512198 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/wrapper/EntAppReleaseWrapper.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/wrapper/EntAppReleaseWrapper.java @@ -22,6 +22,7 @@ import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import javax.validation.constraints.NotNull; +import java.io.InputStream; import java.util.List; @ApiModel(value = "ApplicationReleaseDTO", description = "This class holds the details when releasing an ApplicationDTO to application store") @@ -87,6 +88,28 @@ public class EntAppReleaseWrapper { value = "banner of the application") private Base64File banner; + @ApiModelProperty(name = "installerStream", value = "release apk's stream") + private InputStream installerStream; + + @ApiModelProperty(name = "installerName", value = "release apk's name") + private String installerName; + + public String getInstallerName() { + return installerName; + } + + public void setInstallerName(String installerName) { + this.installerName = installerName; + } + + public InputStream getInstallerStream() { + return installerStream; + } + + public void setInstallerStream(InputStream installerStream) { + this.installerStream = installerStream; + } + public String getReleaseType() { return releaseType; } 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/ApplicationManagerImpl.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/ApplicationManagerImpl.java index c897fcf65c..211064ab13 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/ApplicationManagerImpl.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/ApplicationManagerImpl.java @@ -177,7 +177,9 @@ public class ApplicationManagerImpl implements ApplicationManager { throws ApplicationManagementException { ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationArtifact artifact = ApplicationManagementUtil.constructApplicationArtifact(releaseWrapper.getIcon(), releaseWrapper.getScreenshots(), - releaseWrapper.getBinaryFile(), releaseWrapper.getBanner()); + null, releaseWrapper.getBanner()); + artifact.setInstallerStream(releaseWrapper.getInstallerStream()); + artifact.setInstallerName(releaseWrapper.getInstallerName()); ApplicationDTO applicationDTO = applicationManager.getApplication(appId); DeviceType deviceType = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId()); ApplicationReleaseDTO releaseDTO = APIUtil.releaseWrapperToReleaseDTO(releaseWrapper); @@ -280,7 +282,9 @@ public class ApplicationManagerImpl implements ApplicationManager { ApplicationWrapper wrapper = (ApplicationWrapper) app; EntAppReleaseWrapper releaseWrapper = wrapper.getEntAppReleaseWrappers().get(0); artifact = ApplicationManagementUtil.constructApplicationArtifact(releaseWrapper.getIcon(), - releaseWrapper.getScreenshots(), releaseWrapper.getBinaryFile(), releaseWrapper.getBanner()); + releaseWrapper.getScreenshots(), null, releaseWrapper.getBanner()); + artifact.setInstallerName(releaseWrapper.getInstallerName()); + artifact.setInstallerStream(releaseWrapper.getInstallerStream()); releaseDTO = uploadEntAppReleaseArtifacts(releaseDTO, artifact, wrapper.getDeviceType(), false); } else if (app instanceof PublicAppWrapper) { @@ -299,7 +303,9 @@ public class ApplicationManagerImpl implements ApplicationManager { CustomAppWrapper wrapper = (CustomAppWrapper) app; CustomAppReleaseWrapper releaseWrapper = wrapper.getCustomAppReleaseWrappers().get(0); artifact = ApplicationManagementUtil.constructApplicationArtifact(releaseWrapper.getIcon(), - releaseWrapper.getScreenshots(), releaseWrapper.getBinaryFile(), releaseWrapper.getBanner()); + releaseWrapper.getScreenshots(), null, releaseWrapper.getBanner()); + artifact.setInstallerName(releaseWrapper.getInstallerName()); + artifact.setInstallerStream(releaseWrapper.getInstallerStream()); try { releaseDTO = uploadCustomAppReleaseArtifacts(releaseDTO, artifact, wrapper.getDeviceType()); } catch (ResourceManagementException e) { @@ -3894,7 +3900,8 @@ public class ApplicationManagerImpl implements ApplicationManager { public void validateEntAppReleaseCreatingRequest(EntAppReleaseWrapper releaseWrapper, String deviceType) throws RequestValidatingException, ApplicationManagementException { validateReleaseCreatingRequest(releaseWrapper, deviceType); - validateBinaryArtifact(releaseWrapper.getBinaryFile()); + //validateBinaryArtifact(releaseWrapper.getBinaryFile()); + validateInstallerName(releaseWrapper.getInstallerName()); validateImageArtifacts(releaseWrapper.getIcon(), releaseWrapper.getScreenshots()); } @@ -3902,7 +3909,8 @@ public class ApplicationManagerImpl implements ApplicationManager { public void validateCustomAppReleaseCreatingRequest(CustomAppReleaseWrapper releaseWrapper, String deviceType) throws RequestValidatingException, ApplicationManagementException { validateReleaseCreatingRequest(releaseWrapper, deviceType); - validateBinaryArtifact(releaseWrapper.getBinaryFile()); + //validateBinaryArtifact(releaseWrapper.getBinaryFile()); + validateInstallerName(releaseWrapper.getInstallerName()); validateImageArtifacts(releaseWrapper.getIcon(), releaseWrapper.getScreenshots()); } @@ -3971,6 +3979,15 @@ public class ApplicationManagerImpl implements ApplicationManager { } } + public void validateInstallerName(String installerName) throws RequestValidatingException { + if (installerName == null) { + String msg = "Installer name is not found with the application release creating request for ENTERPRISE app " + + "creating request."; + log.error(msg); + throw new RequestValidatingException(msg); + } + } + @Override public void validateBinaryArtifact(Attachment binaryFile) throws RequestValidatingException { if (binaryFile == null) { diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/test/java/io/entgra/device/mgt/core/application/mgt/core/management/ApplicationManagementTest.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/test/java/io/entgra/device/mgt/core/application/mgt/core/management/ApplicationManagementTest.java index 9eac36785e..1922721d80 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/test/java/io/entgra/device/mgt/core/application/mgt/core/management/ApplicationManagementTest.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/test/java/io/entgra/device/mgt/core/application/mgt/core/management/ApplicationManagementTest.java @@ -52,6 +52,7 @@ import io.entgra.device.mgt.core.device.mgt.core.dto.DeviceTypeVersion; import io.entgra.device.mgt.core.device.mgt.core.service.DeviceManagementProviderServiceImpl; import java.io.File; +import java.nio.file.Files; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -117,12 +118,12 @@ public class ApplicationManagementTest extends BaseTestCase { Base64File ss3Base64 = new Base64File("ss3", FileUtil.fileToBase64String(ss3)); File apk = new File("src/test/resources/samples/app1/sample.apk"); - Base64File apkBase64 = new Base64File("apk", FileUtil.fileToBase64String(apk)); + releaseWrapper.setInstallerName(apk.getName()); + releaseWrapper.setInstallerStream(Files.newInputStream(apk.toPath())); releaseWrapper.setBanner(bannerBase64); releaseWrapper.setIcon(iconBase64); - releaseWrapper.setBinaryFile(apkBase64); releaseWrapper.setScreenshots(Arrays.asList(ss1Base64, ss2Base64, ss3Base64)); entAppReleaseWrappers.add(releaseWrapper);