|
|
@ -48,6 +48,8 @@ import org.apache.commons.validator.routines.UrlValidator;
|
|
|
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
|
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.ws.rs.core.Response;
|
|
|
|
import javax.ws.rs.core.Response;
|
|
|
|
|
|
|
|
import java.net.URLEncoder;
|
|
|
|
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
@ -481,6 +483,12 @@ public class APIUtil {
|
|
|
|
return application;
|
|
|
|
return application;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static String encodeURI(String value) {
|
|
|
|
|
|
|
|
return URLEncoder.encode(value, StandardCharsets.UTF_8);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final String FILE_NAME_PARAM = "?fileName=";
|
|
|
|
|
|
|
|
|
|
|
|
public static ApplicationRelease releaseDtoToRelease(ApplicationReleaseDTO applicationReleaseDTO)
|
|
|
|
public static ApplicationRelease releaseDtoToRelease(ApplicationReleaseDTO applicationReleaseDTO)
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
@ -503,31 +511,29 @@ public class APIUtil {
|
|
|
|
applicationRelease.setSupportedOsVersions(applicationReleaseDTO.getSupportedOsVersions());
|
|
|
|
applicationRelease.setSupportedOsVersions(applicationReleaseDTO.getSupportedOsVersions());
|
|
|
|
applicationRelease.setRating(applicationReleaseDTO.getRating());
|
|
|
|
applicationRelease.setRating(applicationReleaseDTO.getRating());
|
|
|
|
applicationRelease.setIconPath(
|
|
|
|
applicationRelease.setIconPath(
|
|
|
|
basePath + Constants.ICON_ARTIFACT + Constants.FORWARD_SLASH + applicationReleaseDTO.getIconName());
|
|
|
|
basePath + Constants.ICON_ARTIFACT + FILE_NAME_PARAM +
|
|
|
|
|
|
|
|
encodeURI(applicationReleaseDTO.getIconName()));
|
|
|
|
if (!StringUtils.isEmpty(applicationReleaseDTO.getBannerName())){
|
|
|
|
if (!StringUtils.isEmpty(applicationReleaseDTO.getBannerName())) {
|
|
|
|
applicationRelease.setBannerPath(
|
|
|
|
applicationRelease.setBannerPath(
|
|
|
|
basePath + Constants.BANNER_ARTIFACT + Constants.FORWARD_SLASH + applicationReleaseDTO
|
|
|
|
basePath + Constants.BANNER_ARTIFACT + FILE_NAME_PARAM +
|
|
|
|
.getBannerName());
|
|
|
|
encodeURI(applicationReleaseDTO.getBannerName()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
applicationRelease.setInstallerPath(
|
|
|
|
applicationRelease.setInstallerPath(constructInstallerPath(applicationReleaseDTO.getInstallerName(),
|
|
|
|
constructInstallerPath(applicationReleaseDTO.getInstallerName(), applicationReleaseDTO.getAppHashValue()));
|
|
|
|
applicationReleaseDTO.getAppHashValue()));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!StringUtils.isEmpty(applicationReleaseDTO.getScreenshotName1())) {
|
|
|
|
if (!StringUtils.isEmpty(applicationReleaseDTO.getScreenshotName1())) {
|
|
|
|
screenshotPaths
|
|
|
|
screenshotPaths.add(
|
|
|
|
.add(basePath + Constants.SCREENSHOT_ARTIFACT + 1 + Constants.FORWARD_SLASH + applicationReleaseDTO
|
|
|
|
basePath + Constants.SCREENSHOT_ARTIFACT + 1 + FILE_NAME_PARAM +
|
|
|
|
.getScreenshotName1());
|
|
|
|
encodeURI(applicationReleaseDTO.getScreenshotName1()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!StringUtils.isEmpty(applicationReleaseDTO.getScreenshotName2())) {
|
|
|
|
if (!StringUtils.isEmpty(applicationReleaseDTO.getScreenshotName2())) {
|
|
|
|
screenshotPaths
|
|
|
|
screenshotPaths.add(
|
|
|
|
.add(basePath + Constants.SCREENSHOT_ARTIFACT + 2 + Constants.FORWARD_SLASH + applicationReleaseDTO
|
|
|
|
basePath + Constants.SCREENSHOT_ARTIFACT + 2 + FILE_NAME_PARAM +
|
|
|
|
.getScreenshotName2());
|
|
|
|
encodeURI(applicationReleaseDTO.getScreenshotName2()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!StringUtils.isEmpty(applicationReleaseDTO.getScreenshotName3())) {
|
|
|
|
if (!StringUtils.isEmpty(applicationReleaseDTO.getScreenshotName3())) {
|
|
|
|
screenshotPaths
|
|
|
|
screenshotPaths.add(
|
|
|
|
.add(basePath + Constants.SCREENSHOT_ARTIFACT + 3 + Constants.FORWARD_SLASH + applicationReleaseDTO
|
|
|
|
basePath + Constants.SCREENSHOT_ARTIFACT + 3 + FILE_NAME_PARAM +
|
|
|
|
.getScreenshotName3());
|
|
|
|
encodeURI(applicationReleaseDTO.getScreenshotName3()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
applicationRelease.setScreenshots(screenshotPaths);
|
|
|
|
applicationRelease.setScreenshots(screenshotPaths);
|
|
|
|
return applicationRelease;
|
|
|
|
return applicationRelease;
|
|
|
@ -543,9 +549,11 @@ public class APIUtil {
|
|
|
|
public static String constructInstallerPath(String installerName, String appHash) throws ApplicationManagementException {
|
|
|
|
public static String constructInstallerPath(String installerName, String appHash) throws ApplicationManagementException {
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
UrlValidator urlValidator = new UrlValidator();
|
|
|
|
UrlValidator urlValidator = new UrlValidator();
|
|
|
|
String basePath = getArtifactDownloadBaseURL() + tenantId + Constants.FORWARD_SLASH + appHash + Constants.FORWARD_SLASH;
|
|
|
|
String basePath = getArtifactDownloadBaseURL() + tenantId + Constants.FORWARD_SLASH +
|
|
|
|
return urlValidator.isValid(installerName) ? installerName
|
|
|
|
appHash + Constants.FORWARD_SLASH;
|
|
|
|
: basePath + Constants.APP_ARTIFACT + Constants.FORWARD_SLASH + installerName;
|
|
|
|
return urlValidator.isValid(installerName)
|
|
|
|
|
|
|
|
? installerName
|
|
|
|
|
|
|
|
: basePath + Constants.APP_ARTIFACT + FILE_NAME_PARAM + encodeURI(installerName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static String getArtifactDownloadBaseURL() throws ApplicationManagementException {
|
|
|
|
public static String getArtifactDownloadBaseURL() throws ApplicationManagementException {
|
|
|
|