Add multipart form data uploading

pull/329/head
Rajitha Kumara 10 months ago
parent d62e671a5c
commit 2aafde8f35

@ -22,6 +22,7 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.io.InputStream;
import java.util.List; import java.util.List;
@ApiModel(value = "CustomAppReleaseWrapper", description = "This class holds the details when releasing an Custom app release to application store") @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") value = "banner of the application")
private Base64File banner; 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() { public String getReleaseType() {
return releaseType; return releaseType;
} }

@ -22,6 +22,7 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.io.InputStream;
import java.util.List; import java.util.List;
@ApiModel(value = "ApplicationReleaseDTO", description = "This class holds the details when releasing an ApplicationDTO to application store") @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") value = "banner of the application")
private Base64File banner; 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() { public String getReleaseType() {
return releaseType; return releaseType;
} }

@ -177,7 +177,9 @@ public class ApplicationManagerImpl implements ApplicationManager {
throws ApplicationManagementException { throws ApplicationManagementException {
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
ApplicationArtifact artifact = ApplicationManagementUtil.constructApplicationArtifact(releaseWrapper.getIcon(), releaseWrapper.getScreenshots(), 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); ApplicationDTO applicationDTO = applicationManager.getApplication(appId);
DeviceType deviceType = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId()); DeviceType deviceType = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId());
ApplicationReleaseDTO releaseDTO = APIUtil.releaseWrapperToReleaseDTO(releaseWrapper); ApplicationReleaseDTO releaseDTO = APIUtil.releaseWrapperToReleaseDTO(releaseWrapper);
@ -280,7 +282,9 @@ public class ApplicationManagerImpl implements ApplicationManager {
ApplicationWrapper wrapper = (ApplicationWrapper) app; ApplicationWrapper wrapper = (ApplicationWrapper) app;
EntAppReleaseWrapper releaseWrapper = wrapper.getEntAppReleaseWrappers().get(0); EntAppReleaseWrapper releaseWrapper = wrapper.getEntAppReleaseWrappers().get(0);
artifact = ApplicationManagementUtil.constructApplicationArtifact(releaseWrapper.getIcon(), 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, releaseDTO = uploadEntAppReleaseArtifacts(releaseDTO,
artifact, wrapper.getDeviceType(), false); artifact, wrapper.getDeviceType(), false);
} else if (app instanceof PublicAppWrapper) { } else if (app instanceof PublicAppWrapper) {
@ -299,7 +303,9 @@ public class ApplicationManagerImpl implements ApplicationManager {
CustomAppWrapper wrapper = (CustomAppWrapper) app; CustomAppWrapper wrapper = (CustomAppWrapper) app;
CustomAppReleaseWrapper releaseWrapper = wrapper.getCustomAppReleaseWrappers().get(0); CustomAppReleaseWrapper releaseWrapper = wrapper.getCustomAppReleaseWrappers().get(0);
artifact = ApplicationManagementUtil.constructApplicationArtifact(releaseWrapper.getIcon(), 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 { try {
releaseDTO = uploadCustomAppReleaseArtifacts(releaseDTO, artifact, wrapper.getDeviceType()); releaseDTO = uploadCustomAppReleaseArtifacts(releaseDTO, artifact, wrapper.getDeviceType());
} catch (ResourceManagementException e) { } catch (ResourceManagementException e) {
@ -3894,7 +3900,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
public void validateEntAppReleaseCreatingRequest(EntAppReleaseWrapper releaseWrapper, String deviceType) public void validateEntAppReleaseCreatingRequest(EntAppReleaseWrapper releaseWrapper, String deviceType)
throws RequestValidatingException, ApplicationManagementException { throws RequestValidatingException, ApplicationManagementException {
validateReleaseCreatingRequest(releaseWrapper, deviceType); validateReleaseCreatingRequest(releaseWrapper, deviceType);
validateBinaryArtifact(releaseWrapper.getBinaryFile()); //validateBinaryArtifact(releaseWrapper.getBinaryFile());
validateInstallerName(releaseWrapper.getInstallerName());
validateImageArtifacts(releaseWrapper.getIcon(), releaseWrapper.getScreenshots()); validateImageArtifacts(releaseWrapper.getIcon(), releaseWrapper.getScreenshots());
} }
@ -3902,7 +3909,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
public void validateCustomAppReleaseCreatingRequest(CustomAppReleaseWrapper releaseWrapper, String deviceType) public void validateCustomAppReleaseCreatingRequest(CustomAppReleaseWrapper releaseWrapper, String deviceType)
throws RequestValidatingException, ApplicationManagementException { throws RequestValidatingException, ApplicationManagementException {
validateReleaseCreatingRequest(releaseWrapper, deviceType); validateReleaseCreatingRequest(releaseWrapper, deviceType);
validateBinaryArtifact(releaseWrapper.getBinaryFile()); //validateBinaryArtifact(releaseWrapper.getBinaryFile());
validateInstallerName(releaseWrapper.getInstallerName());
validateImageArtifacts(releaseWrapper.getIcon(), releaseWrapper.getScreenshots()); 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 @Override
public void validateBinaryArtifact(Attachment binaryFile) throws RequestValidatingException { public void validateBinaryArtifact(Attachment binaryFile) throws RequestValidatingException {
if (binaryFile == null) { if (binaryFile == null) {

@ -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 io.entgra.device.mgt.core.device.mgt.core.service.DeviceManagementProviderServiceImpl;
import java.io.File; import java.io.File;
import java.nio.file.Files;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -117,12 +118,12 @@ public class ApplicationManagementTest extends BaseTestCase {
Base64File ss3Base64 = new Base64File("ss3", FileUtil.fileToBase64String(ss3)); Base64File ss3Base64 = new Base64File("ss3", FileUtil.fileToBase64String(ss3));
File apk = new File("src/test/resources/samples/app1/sample.apk"); 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.setBanner(bannerBase64);
releaseWrapper.setIcon(iconBase64); releaseWrapper.setIcon(iconBase64);
releaseWrapper.setBinaryFile(apkBase64);
releaseWrapper.setScreenshots(Arrays.asList(ss1Base64, ss2Base64, ss3Base64)); releaseWrapper.setScreenshots(Arrays.asList(ss1Base64, ss2Base64, ss3Base64));
entAppReleaseWrappers.add(releaseWrapper); entAppReleaseWrappers.add(releaseWrapper);

Loading…
Cancel
Save