|
|
|
@ -88,6 +88,7 @@ import org.wso2.carbon.device.application.mgt.core.util.StorageManagementUtil;
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
|
|
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
|
|
|
|
import org.wso2.carbon.user.api.UserRealm;
|
|
|
|
|
import org.wso2.carbon.user.api.UserStoreException;
|
|
|
|
|
import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
|
|
|
|
@ -135,17 +136,16 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
* The responsbility of this method is the creating an application.
|
|
|
|
|
* @param applicationWrapper ApplicationDTO that need to be created.
|
|
|
|
|
* @return {@link ApplicationDTO}
|
|
|
|
|
* @throws RequestValidatingException if application creating request is invalid,
|
|
|
|
|
* @throws ApplicationManagementException Catch all other throwing exceptions and throw {@link ApplicationManagementException}
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public Application createApplication(ApplicationWrapper applicationWrapper,
|
|
|
|
|
ApplicationArtifact applicationArtifact) throws RequestValidatingException, ApplicationManagementException {
|
|
|
|
|
ApplicationArtifact applicationArtifact) throws ApplicationManagementException {
|
|
|
|
|
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
|
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
log.debug("Application create request is received for the tenant : " + tenantId + " From" + " the user : "
|
|
|
|
|
log.debug("Application create request is received for the tenant : " + tenantId + " and" + " the user : "
|
|
|
|
|
+ userName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -154,6 +154,13 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
//uploading application artifacts
|
|
|
|
|
try {
|
|
|
|
|
ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0);
|
|
|
|
|
if (!isValidOsVersions(applicationReleaseDTO.getSupportedOsVersions(), applicationWrapper.getDeviceType())){
|
|
|
|
|
String msg = "You are trying to create application which has an application release contains invalid or "
|
|
|
|
|
+ "unsupported OS versions in the supportedOsVersions section. Hence, please re-evaluate the "
|
|
|
|
|
+ "request payload.";
|
|
|
|
|
log.error(msg);
|
|
|
|
|
throw new BadRequestException(msg);
|
|
|
|
|
}
|
|
|
|
|
applicationReleaseDTO = addApplicationReleaseArtifacts(applicationDTO.getType(),
|
|
|
|
|
applicationWrapper.getDeviceType(), applicationReleaseDTO, applicationArtifact, false);
|
|
|
|
|
applicationReleaseDTO = addImageArtifacts(applicationReleaseDTO, applicationArtifact);
|
|
|
|
@ -425,7 +432,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
ApplicationDTO applicationDTO = APIUtil.convertToAppDTO(webAppWrapper);
|
|
|
|
|
ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0);
|
|
|
|
|
String uuid = UUID.randomUUID().toString();
|
|
|
|
|
//todo check installer name exists or not, do it in the validation method
|
|
|
|
|
String md5 = DigestUtils.md5Hex(applicationReleaseDTO.getInstallerName());
|
|
|
|
|
applicationReleaseDTO.setUuid(uuid);
|
|
|
|
|
applicationReleaseDTO.setAppHashValue(md5);
|
|
|
|
@ -455,6 +461,14 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
+ userName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!isValidOsVersions(publicAppWrapper.getPublicAppReleaseWrappers().get(0).getSupportedOsVersions(),
|
|
|
|
|
publicAppWrapper.getDeviceType())) {
|
|
|
|
|
String msg = "You are trying to add application release which has invalid or unsupported OS versions in "
|
|
|
|
|
+ "the supportedOsVersions section. Hence, please re-evaluate the request payload.";
|
|
|
|
|
log.error(msg);
|
|
|
|
|
throw new BadRequestException(msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (DeviceTypes.ANDROID.toString().equals(publicAppWrapper.getDeviceType())) {
|
|
|
|
|
publicAppStorePath = Constants.GOOGLE_PLAY_STORE_URL;
|
|
|
|
|
} else if (DeviceTypes.IOS.toString().equals(publicAppWrapper.getDeviceType())) {
|
|
|
|
@ -758,8 +772,15 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
log.error(msg);
|
|
|
|
|
throw new BadRequestException(msg);
|
|
|
|
|
}
|
|
|
|
|
DeviceType deviceType = getDeviceTypeData(applicationDTO.getDeviceTypeId());
|
|
|
|
|
if (!isValidOsVersions(applicationReleaseWrapper.getSupportedOsVersions(), deviceType.getName())){
|
|
|
|
|
String msg = "You are trying to add application release which has invalid or unsupported OS versions in "
|
|
|
|
|
+ "the supportedOsVersions section. Hence, please re-evaluate the request payload.";
|
|
|
|
|
log.error(msg);
|
|
|
|
|
throw new BadRequestException(msg);
|
|
|
|
|
}
|
|
|
|
|
ApplicationReleaseDTO applicationReleaseDTO = uploadReleaseArtifacts(applicationReleaseWrapper,
|
|
|
|
|
applicationDTO, applicationArtifact);
|
|
|
|
|
applicationDTO, applicationArtifact, deviceType.getName());
|
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
|
String initialstate = lifecycleStateManager.getInitialState();
|
|
|
|
|
applicationReleaseDTO.setCurrentState(initialstate);
|
|
|
|
@ -818,12 +839,11 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ApplicationReleaseDTO uploadReleaseArtifacts(ApplicationReleaseWrapper applicationReleaseWrapper,
|
|
|
|
|
ApplicationDTO applicationDTO, ApplicationArtifact applicationArtifact)
|
|
|
|
|
ApplicationDTO applicationDTO, ApplicationArtifact applicationArtifact, String deviceTypeName)
|
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
|
try {
|
|
|
|
|
DeviceType deviceType = getDeviceTypeData(applicationDTO.getDeviceTypeId());
|
|
|
|
|
ApplicationReleaseDTO applicationReleaseDTO = addApplicationReleaseArtifacts(applicationDTO.getType(),
|
|
|
|
|
deviceType.getName(), APIUtil.releaseWrapperToReleaseDTO(applicationReleaseWrapper), applicationArtifact,
|
|
|
|
|
deviceTypeName, APIUtil.releaseWrapperToReleaseDTO(applicationReleaseWrapper), applicationArtifact,
|
|
|
|
|
true);
|
|
|
|
|
return addImageArtifacts(applicationReleaseDTO, applicationArtifact);
|
|
|
|
|
} catch (ResourceManagementException e) {
|
|
|
|
@ -834,6 +854,30 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean isValidOsVersions(String osRange, String deviceTypeName)
|
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
|
String lowestSupportingOsVersion;
|
|
|
|
|
String highestSupportingOsVersion = null;
|
|
|
|
|
String[] supportedOsVersionValues = osRange.split("-");
|
|
|
|
|
lowestSupportingOsVersion = supportedOsVersionValues[0].trim();
|
|
|
|
|
if (!"ALL".equals(supportedOsVersionValues[1].trim())) {
|
|
|
|
|
highestSupportingOsVersion = supportedOsVersionValues[1].trim();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
DeviceManagementProviderService deviceManagementProviderService = DAOUtil.getDeviceManagementService();
|
|
|
|
|
return deviceManagementProviderService.getDeviceTypeVersion(deviceTypeName, lowestSupportingOsVersion)
|
|
|
|
|
!= null && (highestSupportingOsVersion == null
|
|
|
|
|
|| deviceManagementProviderService.getDeviceTypeVersion(deviceTypeName, highestSupportingOsVersion)
|
|
|
|
|
!= null);
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
String msg =
|
|
|
|
|
"Error occurred while getting supported device type versions for device type : " + deviceTypeName;
|
|
|
|
|
log.error(msg);
|
|
|
|
|
throw new ApplicationManagementException(msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Application getApplicationById(int appId, String state) throws ApplicationManagementException {
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
@ -2451,7 +2495,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
List<CategoryDTO> registeredCategories = this.applicationDAO.getAllCategories(tenantId);
|
|
|
|
|
|
|
|
|
|
if (registeredCategories.isEmpty()) {
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
String msg = "Registered application category set is empty. Since it is mandatory to add application "
|
|
|
|
|
+ "category when adding new application, registered application category list shouldn't be null.";
|
|
|
|
|
log.error(msg);
|
|
|
|
@ -2482,7 +2525,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
log.error(msg);
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
String msg = "Error occurred when validating the unrestricted roles given for the web clip";
|
|
|
|
|
log.error(msg);
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
|