From bc023aa45aa9b66bdb33bf6f45cdf860c1ec3a2d 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 +++++++++++++++---- 3 files changed, 68 insertions(+), 5 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 b7fd8f23b5..ef35bf7000 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 @@ -172,7 +172,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); @@ -275,7 +277,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) { @@ -294,7 +298,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) { @@ -3820,7 +3826,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()); } @@ -3828,7 +3835,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()); } @@ -3897,6 +3905,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) {