Add Content and Package URI changes

master
Lasantha Dharmakeerthi 7 months ago
commit 92f7e0c2fa

@ -509,6 +509,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
}
ApplicationManagementUtil.addInstallerPathToMetadata(releaseDTO);
applicationDTO.getApplicationReleaseDTOs().clear();
applicationDTO.getApplicationReleaseDTOs().add(releaseDTO);
return applicationDTO;

@ -496,7 +496,6 @@ public class APIUtil {
List<String> screenshotPaths = new ArrayList<>();
ApplicationRelease applicationRelease = new ApplicationRelease();
UrlValidator urlValidator = new UrlValidator();
applicationRelease.setDescription(applicationReleaseDTO.getDescription());
applicationRelease.setVersion(applicationReleaseDTO.getVersion());
@ -519,13 +518,8 @@ public class APIUtil {
.getBannerName());
}
if (urlValidator.isValid(applicationReleaseDTO.getInstallerName())) {
applicationRelease.setInstallerPath(applicationReleaseDTO.getInstallerName());
} else {
applicationRelease.setInstallerPath(
basePath + Constants.APP_ARTIFACT + Constants.FORWARD_SLASH + applicationReleaseDTO
.getInstallerName());
}
applicationRelease.setInstallerPath(constructInstallerPath(applicationReleaseDTO.getInstallerName(),
applicationReleaseDTO.getAppHashValue()));
if (!StringUtils.isEmpty(applicationReleaseDTO.getScreenshotName1())) {
screenshotPaths
@ -546,6 +540,21 @@ public class APIUtil {
return applicationRelease;
}
/**
* Construct installer path
* @param installerName Installer name
* @param appHash Application hash
* @return Constructed installer path value
* @throws ApplicationManagementException Throws when error encountered while constructing installer path
*/
public static String constructInstallerPath(String installerName, String appHash) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
UrlValidator urlValidator = new UrlValidator();
String basePath = getArtifactDownloadBaseURL() + tenantId + Constants.FORWARD_SLASH + appHash + Constants.FORWARD_SLASH;
return urlValidator.isValid(installerName) ? installerName
: basePath + Constants.APP_ARTIFACT + Constants.FORWARD_SLASH + installerName;
}
public static String getArtifactDownloadBaseURL() throws ApplicationManagementException {
String host = System.getProperty(Constants.IOT_CORE_HOST);
MDMConfig mdmConfig = ConfigurationManager.getInstance().getConfiguration().getMdmConfig();

@ -17,11 +17,16 @@
*/
package io.entgra.device.mgt.core.application.mgt.core.util;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import io.entgra.device.mgt.core.application.mgt.common.ApplicationArtifact;
import io.entgra.device.mgt.core.application.mgt.common.FileDataHolder;
import io.entgra.device.mgt.core.application.mgt.common.FileDescriptor;
import io.entgra.device.mgt.core.application.mgt.common.LifecycleChanger;
import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationReleaseDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.ItuneAppDTO;
import io.entgra.device.mgt.core.application.mgt.common.exception.ApplicationManagementException;
import io.entgra.device.mgt.core.application.mgt.common.exception.FileDownloaderServiceException;
@ -60,6 +65,7 @@ import io.entgra.device.mgt.core.device.mgt.core.common.util.FileUtil;
import io.entgra.device.mgt.core.device.mgt.core.metadata.mgt.MetadataManagementServiceImpl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jetbrains.annotations.NotNull;
import java.io.ByteArrayOutputStream;
import java.io.File;
@ -80,6 +86,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.TreeMap;
/**
@ -649,4 +656,62 @@ public class ApplicationManagementUtil {
}
return releaseWrappers;
}
/**
* Add installer path metadata value to windows applications
* @param applicationReleaseDTO {@link ApplicationReleaseDTO}
* @throws ApplicationManagementException Throws when error encountered while updating the app metadata
*/
public static void addInstallerPathToMetadata(ApplicationReleaseDTO applicationReleaseDTO)
throws ApplicationManagementException {
if (applicationReleaseDTO.getMetaData() == null) return;
Gson gson = new Gson();
String installerPath = APIUtil.constructInstallerPath(applicationReleaseDTO.getInstallerName(), applicationReleaseDTO.getAppHashValue());
String[] fileNameSegments = extractNameSegments(applicationReleaseDTO, installerPath);
String extension = fileNameSegments[fileNameSegments.length - 1];
if (!Objects.equals(extension, "appx") && !Objects.equals(extension, "msi")) {
return;
}
String installerPaths = "[ {" +
"\"key\": \"Content_Uri\", " +
"\"value\" : \"" + installerPath + "\"" +
"}]";
if (Objects.equals(extension, "appx")) {
installerPaths = "[ {" +
"\"key\": \"Package_Uri\", " +
"\"value\" : \"" + installerPath + "\"" +
"}]";
}
JsonArray parsedMetadataList = gson.fromJson(applicationReleaseDTO.getMetaData(), JsonArray.class);
JsonArray installerPathsArray = gson.fromJson(installerPaths, JsonArray.class);
parsedMetadataList.addAll(installerPathsArray);
applicationReleaseDTO.setMetaData(gson.toJson(parsedMetadataList));
}
/**
* Extract name segments from installer path
* @param applicationReleaseDTO {@link ApplicationReleaseDTO}
* @param installerPath Installer path
* @return Extracted file name segments
* @throws ApplicationManagementException Throws when error encountered while extracting name segments from installer path
*/
private static String[] extractNameSegments(ApplicationReleaseDTO applicationReleaseDTO, String installerPath)
throws ApplicationManagementException {
String []installerPathSegments = installerPath.split("/");
if (installerPathSegments.length == 0) {
throw new ApplicationManagementException("Received malformed url for installer path of the app : "
+ applicationReleaseDTO.getInstallerName());
}
String fullQualifiedName = installerPathSegments[installerPathSegments.length - 1];
String []fileNameSegments = fullQualifiedName.split("\\.(?=[^.]+$)");
if (fileNameSegments.length != 2) {
throw new ApplicationManagementException("Received malformed url for installer path of the app : "
+ applicationReleaseDTO.getInstallerName());
}
return fileNameSegments;
}
}

@ -107,7 +107,7 @@ public class ApplicationManagementTest extends BaseTestCase {
EntAppReleaseWrapper releaseWrapper = new EntAppReleaseWrapper();
releaseWrapper.setDescription("First release");
releaseWrapper.setIsSharedWithAllTenants(false);
releaseWrapper.setMetaData("Just meta data");
releaseWrapper.setMetaData("[{\"key\": \"Just a metadata\"}]");
releaseWrapper.setReleaseType("free");
releaseWrapper.setPrice(5.7);
releaseWrapper.setSupportedOsVersions("4.0-7.0");

Loading…
Cancel
Save