|
|
@ -56,7 +56,7 @@ import org.wso2.carbon.device.application.mgt.common.response.Category;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.response.Tag;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.response.Tag;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationReleaseWrapper;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.wrapper.EntAppReleaseWrapper;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationUpdateWrapper;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationUpdateWrapper;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationWrapper;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationWrapper;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.wrapper.PublicAppReleaseWrapper;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.wrapper.PublicAppReleaseWrapper;
|
|
|
@ -131,7 +131,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Application createApplication(ApplicationWrapper applicationWrapper,
|
|
|
|
public Application createEntApp(ApplicationWrapper applicationWrapper,
|
|
|
|
ApplicationArtifact applicationArtifact) throws ApplicationManagementException {
|
|
|
|
ApplicationArtifact applicationArtifact) throws ApplicationManagementException {
|
|
|
|
|
|
|
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
@ -143,26 +143,101 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
|
|
|
|
|
|
|
ApplicationDTO applicationDTO = APIUtil.convertToAppDTO(applicationWrapper);
|
|
|
|
ApplicationDTO applicationDTO = APIUtil.convertToAppDTO(applicationWrapper);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//uploading application artifacts
|
|
|
|
|
|
|
|
applicationReleaseDTO = uploadEntAppReleaseArtifacts(applicationReleaseDTO, applicationArtifact,
|
|
|
|
|
|
|
|
applicationWrapper.getDeviceType(), false);
|
|
|
|
|
|
|
|
applicationDTO.getApplicationReleaseDTOs().clear();
|
|
|
|
|
|
|
|
applicationDTO.getApplicationReleaseDTOs().add(applicationReleaseDTO);
|
|
|
|
|
|
|
|
return addAppDataIntoDB(applicationDTO, tenantId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public Application createWebClip(WebAppWrapper webAppWrapper, ApplicationArtifact applicationArtifact)
|
|
|
|
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
|
|
|
|
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("Web clip create request is received for the tenant : " + tenantId + " From" + " the user : "
|
|
|
|
|
|
|
|
+ userName);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ApplicationDTO applicationDTO = APIUtil.convertToAppDTO(webAppWrapper);
|
|
|
|
|
|
|
|
ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0);
|
|
|
|
|
|
|
|
String uuid = UUID.randomUUID().toString();
|
|
|
|
|
|
|
|
String md5 = DigestUtils.md5Hex(applicationReleaseDTO.getInstallerName());
|
|
|
|
|
|
|
|
applicationReleaseDTO.setUuid(uuid);
|
|
|
|
|
|
|
|
applicationReleaseDTO.setAppHashValue(md5);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//uploading application artifacts
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
applicationDTO.getApplicationReleaseDTOs().clear();
|
|
|
|
|
|
|
|
applicationDTO.getApplicationReleaseDTOs().add(addImageArtifacts(applicationReleaseDTO, applicationArtifact));
|
|
|
|
|
|
|
|
} catch (ResourceManagementException e) {
|
|
|
|
|
|
|
|
String msg = "Error Occured when uploading artifacts of the web clip: " + webAppWrapper.getName();
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//insert application data into database
|
|
|
|
|
|
|
|
return addAppDataIntoDB(applicationDTO, tenantId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public Application createPublicApp(PublicAppWrapper publicAppWrapper, ApplicationArtifact applicationArtifact)
|
|
|
|
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
|
|
|
|
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
|
|
|
|
String publicAppStorePath = "";
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("Public app creating request is received for the tenant : " + tenantId + " From" + " the user : "
|
|
|
|
|
|
|
|
+ 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())) {
|
|
|
|
|
|
|
|
publicAppStorePath = Constants.APPLE_STORE_URL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ApplicationDTO applicationDTO = APIUtil.convertToAppDTO(publicAppWrapper);
|
|
|
|
|
|
|
|
ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0);
|
|
|
|
|
|
|
|
String uuid = UUID.randomUUID().toString();
|
|
|
|
|
|
|
|
String appInstallerUrl = publicAppStorePath + applicationReleaseDTO.getPackageName();
|
|
|
|
|
|
|
|
//todo check app package name exist or not, do it in validation method
|
|
|
|
|
|
|
|
applicationReleaseDTO.setInstallerName(appInstallerUrl);
|
|
|
|
|
|
|
|
String md5 = DigestUtils.md5Hex(appInstallerUrl);
|
|
|
|
|
|
|
|
applicationReleaseDTO.setUuid(uuid);
|
|
|
|
|
|
|
|
applicationReleaseDTO.setAppHashValue(md5);
|
|
|
|
|
|
|
|
|
|
|
|
//uploading application artifacts
|
|
|
|
//uploading application artifacts
|
|
|
|
try {
|
|
|
|
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);
|
|
|
|
|
|
|
|
applicationDTO.getApplicationReleaseDTOs().clear();
|
|
|
|
applicationDTO.getApplicationReleaseDTOs().clear();
|
|
|
|
applicationDTO.getApplicationReleaseDTOs().add(applicationReleaseDTO);
|
|
|
|
applicationDTO.getApplicationReleaseDTOs()
|
|
|
|
|
|
|
|
.add(addImageArtifacts(applicationReleaseDTO, applicationArtifact));
|
|
|
|
} catch (ResourceManagementException e) {
|
|
|
|
} catch (ResourceManagementException e) {
|
|
|
|
String msg = "Error Occured when uploading artifacts of the application: " + applicationWrapper.getName();
|
|
|
|
String msg = "Error Occured when uploading artifacts of the public app: " + publicAppWrapper.getName();
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//insert application data into database
|
|
|
|
return addAppDataIntoDB(applicationDTO, tenantId);
|
|
|
|
return addAppDataIntoDB(applicationDTO, tenantId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -178,7 +253,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private ApplicationReleaseDTO addApplicationReleaseArtifacts(String applicationType, String deviceType,
|
|
|
|
private ApplicationReleaseDTO addApplicationReleaseArtifacts(String deviceType,
|
|
|
|
ApplicationReleaseDTO applicationReleaseDTO, ApplicationArtifact applicationArtifact, boolean isNewRelease)
|
|
|
|
ApplicationReleaseDTO applicationReleaseDTO, ApplicationArtifact applicationArtifact, boolean isNewRelease)
|
|
|
|
throws ResourceManagementException, ApplicationManagementException {
|
|
|
|
throws ResourceManagementException, ApplicationManagementException {
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
@ -188,7 +263,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
applicationReleaseDTO.setUuid(uuid);
|
|
|
|
applicationReleaseDTO.setUuid(uuid);
|
|
|
|
|
|
|
|
|
|
|
|
// The application executable artifacts such as apks are uploaded.
|
|
|
|
// The application executable artifacts such as apks are uploaded.
|
|
|
|
if (ApplicationType.ENTERPRISE.toString().equals(applicationType)) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
byte[] content = IOUtils.toByteArray(applicationArtifact.getInstallerStream());
|
|
|
|
byte[] content = IOUtils.toByteArray(applicationArtifact.getInstallerStream());
|
|
|
|
|
|
|
|
|
|
|
@ -222,16 +296,14 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
if (this.applicationReleaseDAO
|
|
|
|
if (this.applicationReleaseDAO
|
|
|
|
.verifyReleaseExistenceByHash(md5OfApp, tenantId)) {
|
|
|
|
.verifyReleaseExistenceByHash(md5OfApp, tenantId)) {
|
|
|
|
throw new BadRequestException(
|
|
|
|
throw new BadRequestException(
|
|
|
|
"Application release exists for the uploaded binary file. Application Type: "
|
|
|
|
"Application release exists for the uploaded binary file. Device Type: " + deviceType);
|
|
|
|
+ applicationType + " Device Type: " + deviceType);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
applicationReleaseDTO.setAppHashValue(md5OfApp);
|
|
|
|
applicationReleaseDTO.setAppHashValue(md5OfApp);
|
|
|
|
|
|
|
|
|
|
|
|
try (ByteArrayInputStream binaryDuplicate = new ByteArrayInputStream(content)) {
|
|
|
|
try (ByteArrayInputStream binaryDuplicate = new ByteArrayInputStream(content)) {
|
|
|
|
applicationReleaseDTO = applicationStorageManager
|
|
|
|
applicationReleaseDTO = applicationStorageManager
|
|
|
|
.uploadReleaseArtifact(applicationReleaseDTO,applicationType,
|
|
|
|
.uploadReleaseArtifact(applicationReleaseDTO, deviceType, binaryDuplicate);
|
|
|
|
deviceType, binaryDuplicate);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (IOException e) {
|
|
|
|
} catch (IOException e) {
|
|
|
@ -251,98 +323,92 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (ApplicationType.WEB_CLIP.toString().equals(applicationType)) {
|
|
|
|
|
|
|
|
applicationReleaseDTO.setVersion(Constants.DEFAULT_VERSION);
|
|
|
|
|
|
|
|
applicationReleaseDTO.setInstallerName(applicationReleaseDTO.getUrl());
|
|
|
|
|
|
|
|
// Since WEB CLIP doesn't have an installer, set uuid as has value for WEB CLIP
|
|
|
|
|
|
|
|
applicationReleaseDTO.setAppHashValue(uuid);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return applicationReleaseDTO;
|
|
|
|
return applicationReleaseDTO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private ApplicationReleaseDTO updateApplicationReleaseArtifacts(String applicationType, String deviceType,
|
|
|
|
private ApplicationReleaseDTO updateEntAppReleaseArtifact(String deviceType,
|
|
|
|
ApplicationReleaseDTO applicationReleaseDTO, ApplicationArtifact applicationArtifact)
|
|
|
|
ApplicationReleaseDTO applicationReleaseDTO, ApplicationArtifact applicationArtifact)
|
|
|
|
throws ResourceManagementException, ApplicationManagementException {
|
|
|
|
throws ResourceManagementException, ApplicationManagementException {
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager();
|
|
|
|
ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager();
|
|
|
|
|
|
|
|
|
|
|
|
// The application executable artifacts such as apks are uploaded.
|
|
|
|
// The application executable artifacts such as apks are uploaded.
|
|
|
|
if (ApplicationType.ENTERPRISE.toString().equals(applicationType)) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
byte[] content = IOUtils.toByteArray(applicationArtifact.getInstallerStream());
|
|
|
|
byte[] content = IOUtils.toByteArray(applicationArtifact.getInstallerStream());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try(ByteArrayInputStream binaryClone = new ByteArrayInputStream(content)){
|
|
|
|
try (ByteArrayInputStream binaryClone = new ByteArrayInputStream(content)) {
|
|
|
|
String md5OfApp = StorageManagementUtil.getMD5(binaryClone);
|
|
|
|
String md5OfApp = StorageManagementUtil.getMD5(binaryClone);
|
|
|
|
|
|
|
|
|
|
|
|
if (md5OfApp == null) {
|
|
|
|
if (md5OfApp == null) {
|
|
|
|
String msg = "Error occurred while md5sum value retrieving process: application UUID "
|
|
|
|
String msg = "Error occurred while retrieving md5sum value from the binary file for application "
|
|
|
|
+ applicationReleaseDTO.getUuid();
|
|
|
|
+ "release UUID " + applicationReleaseDTO.getUuid();
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
throw new ApplicationStorageManagementException(msg);
|
|
|
|
throw new ApplicationStorageManagementException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!applicationReleaseDTO.getAppHashValue().equals(md5OfApp)){
|
|
|
|
if (!applicationReleaseDTO.getAppHashValue().equals(md5OfApp)) {
|
|
|
|
applicationReleaseDTO.setInstallerName(applicationArtifact.getInstallerName());
|
|
|
|
applicationReleaseDTO.setInstallerName(applicationArtifact.getInstallerName());
|
|
|
|
|
|
|
|
|
|
|
|
try (ByteArrayInputStream binary = new ByteArrayInputStream(content)) {
|
|
|
|
try (ByteArrayInputStream binary = new ByteArrayInputStream(content)) {
|
|
|
|
ApplicationInstaller applicationInstaller = applicationStorageManager
|
|
|
|
ApplicationInstaller applicationInstaller = applicationStorageManager
|
|
|
|
.getAppInstallerData(binary, deviceType);
|
|
|
|
.getAppInstallerData(binary, deviceType);
|
|
|
|
String packagename = applicationInstaller.getPackageName();
|
|
|
|
String packageName = applicationInstaller.getPackageName();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.getDBConnection();
|
|
|
|
ConnectionManagerUtil.getDBConnection();
|
|
|
|
if (applicationReleaseDAO.isActiveReleaseExisitForPackageName(packagename, tenantId,
|
|
|
|
if (this.applicationReleaseDAO.verifyReleaseExistenceByHash(md5OfApp, tenantId)) {
|
|
|
|
lifecycleStateManager.getEndState())) {
|
|
|
|
String msg = "Same binary file is in the server. Hence you can't add same file into the "
|
|
|
|
String msg = "Application release is already exist for the package name: " + packagename +
|
|
|
|
+ "server. Device Type: " + deviceType + " and package name: " + packageName;
|
|
|
|
". Either you can delete all application releases for package " + packagename + " or "
|
|
|
|
log.error(msg);
|
|
|
|
+ "you can add this app release as an new application release, under the existing "
|
|
|
|
throw new BadRequestException(msg);
|
|
|
|
+ "application.";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (applicationReleaseDTO.getPackageName() == null){
|
|
|
|
|
|
|
|
String msg = "Found null value for application release package name for application "
|
|
|
|
|
|
|
|
+ "release which has UUID: " + applicationReleaseDTO.getUuid();
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
throw new ApplicationManagementException(msg);
|
|
|
|
throw new ApplicationManagementException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
applicationReleaseDTO.setVersion(applicationInstaller.getVersion());
|
|
|
|
if (!applicationReleaseDTO.getPackageName().equals(packageName)){
|
|
|
|
applicationReleaseDTO.setPackageName(packagename);
|
|
|
|
String msg = "Package name of the new artifact does not match with the package name of "
|
|
|
|
|
|
|
|
+ "the exiting application release. Package name of the existing app release "
|
|
|
|
if (this.applicationReleaseDAO
|
|
|
|
+ applicationReleaseDTO.getPackageName() + " and package name of the new "
|
|
|
|
.verifyReleaseExistenceByHash(md5OfApp, tenantId)) {
|
|
|
|
+ "application release " + packageName;
|
|
|
|
throw new BadRequestException(
|
|
|
|
log.error(msg);
|
|
|
|
"Application release exists for the uploaded binary file. Application Type: "
|
|
|
|
throw new BadRequestException(msg);
|
|
|
|
+ applicationType + " Device Tyep: " + deviceType);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
applicationReleaseDTO.setAppHashValue(md5OfApp);
|
|
|
|
applicationReleaseDTO.setVersion(applicationInstaller.getVersion());
|
|
|
|
|
|
|
|
applicationReleaseDTO.setPackageName(packageName);
|
|
|
|
String deletingAppHashValue = applicationReleaseDTO.getAppHashValue();
|
|
|
|
String deletingAppHashValue = applicationReleaseDTO.getAppHashValue();
|
|
|
|
|
|
|
|
applicationReleaseDTO.setAppHashValue(md5OfApp);
|
|
|
|
try (ByteArrayInputStream binaryDuplicate = new ByteArrayInputStream(content)) {
|
|
|
|
try (ByteArrayInputStream binaryDuplicate = new ByteArrayInputStream(content)) {
|
|
|
|
applicationReleaseDTO = applicationStorageManager
|
|
|
|
applicationReleaseDTO = applicationStorageManager
|
|
|
|
.uploadReleaseArtifact(applicationReleaseDTO,applicationType,
|
|
|
|
.uploadReleaseArtifact(applicationReleaseDTO, deviceType, binaryDuplicate);
|
|
|
|
deviceType, binaryDuplicate);
|
|
|
|
|
|
|
|
applicationStorageManager.copyImageArtifactsAndDeleteInstaller(deletingAppHashValue,
|
|
|
|
applicationStorageManager.copyImageArtifactsAndDeleteInstaller(deletingAppHashValue,
|
|
|
|
applicationReleaseDTO);
|
|
|
|
applicationReleaseDTO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred when getting database connection for verifying application "
|
|
|
|
|
|
|
|
+ "release existing for new app hash value.";
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred when executing the query for verifying application release "
|
|
|
|
|
|
|
|
+ "existence for the new app hash value.";
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
|
|
|
String msg =
|
|
|
|
|
|
|
|
"Error occurred when getting byte array of binary file. Installer name: " + applicationArtifact
|
|
|
|
|
|
|
|
.getInstallerName();
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ApplicationStorageManagementException(msg);
|
|
|
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred when getting database connection for verifying application package existence.";
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred when executing the query for verifying application release existence for "
|
|
|
|
|
|
|
|
+ "the package.";
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (ApplicationType.WEB_CLIP.toString().equals(applicationType)) {
|
|
|
|
} catch (IOException e) {
|
|
|
|
applicationReleaseDTO.setVersion(Constants.DEFAULT_VERSION);
|
|
|
|
String msg = "Error occurred when getting byte array of binary file. Installer name: " + applicationArtifact
|
|
|
|
applicationReleaseDTO.setInstallerName(applicationReleaseDTO.getUrl());
|
|
|
|
.getInstallerName();
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ApplicationStorageManagementException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return applicationReleaseDTO;
|
|
|
|
return applicationReleaseDTO;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -380,13 +446,15 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
ApplicationArtifact applicationArtifact) throws ResourceManagementException{
|
|
|
|
ApplicationArtifact applicationArtifact) throws ResourceManagementException{
|
|
|
|
ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager();
|
|
|
|
ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//todo check again
|
|
|
|
applicationStorageManager.deleteImageArtifacts(applicationReleaseDTO);
|
|
|
|
applicationStorageManager.deleteImageArtifacts(applicationReleaseDTO);
|
|
|
|
|
|
|
|
|
|
|
|
applicationReleaseDTO.setIconName(applicationArtifact.getIconName());
|
|
|
|
if (!StringUtils.isEmpty(applicationArtifact.getIconName())) {
|
|
|
|
applicationReleaseDTO.setBannerName(applicationArtifact.getBannerName());
|
|
|
|
applicationReleaseDTO.setIconName(applicationArtifact.getIconName());
|
|
|
|
applicationReleaseDTO.setScreenshotName1(null);
|
|
|
|
}
|
|
|
|
applicationReleaseDTO.setScreenshotName2(null);
|
|
|
|
if (!StringUtils.isEmpty(applicationArtifact.getBannerName())){
|
|
|
|
applicationReleaseDTO.setScreenshotName3(null);
|
|
|
|
applicationReleaseDTO.setBannerName(applicationArtifact.getBannerName());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, InputStream> screenshots = applicationArtifact.getScreenshots();
|
|
|
|
Map<String, InputStream> screenshots = applicationArtifact.getScreenshots();
|
|
|
|
List<String> screenshotNames = new ArrayList<>(screenshots.keySet());
|
|
|
|
List<String> screenshotNames = new ArrayList<>(screenshots.keySet());
|
|
|
@ -410,87 +478,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
return applicationReleaseDTO;
|
|
|
|
return applicationReleaseDTO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public Application createWebClip(WebAppWrapper webAppWrapper, ApplicationArtifact applicationArtifact)
|
|
|
|
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
|
|
|
|
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("Web clip create request is received for the tenant : " + tenantId + " From" + " the user : "
|
|
|
|
|
|
|
|
+ userName);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ApplicationDTO applicationDTO = APIUtil.convertToAppDTO(webAppWrapper);
|
|
|
|
|
|
|
|
ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0);
|
|
|
|
|
|
|
|
String uuid = UUID.randomUUID().toString();
|
|
|
|
|
|
|
|
String md5 = DigestUtils.md5Hex(applicationReleaseDTO.getInstallerName());
|
|
|
|
|
|
|
|
applicationReleaseDTO.setUuid(uuid);
|
|
|
|
|
|
|
|
applicationReleaseDTO.setAppHashValue(md5);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//uploading application artifacts
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
applicationDTO.getApplicationReleaseDTOs().clear();
|
|
|
|
|
|
|
|
applicationDTO.getApplicationReleaseDTOs().add(addImageArtifacts(applicationReleaseDTO, applicationArtifact));
|
|
|
|
|
|
|
|
} catch (ResourceManagementException e) {
|
|
|
|
|
|
|
|
String msg = "Error Occured when uploading artifacts of the web clip: " + webAppWrapper.getName();
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//insert application data into database
|
|
|
|
|
|
|
|
return addAppDataIntoDB(applicationDTO, tenantId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public Application createPublicApp(PublicAppWrapper publicAppWrapper, ApplicationArtifact applicationArtifact)
|
|
|
|
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
|
|
|
|
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
|
|
|
|
String publicAppStorePath = "";
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("Public app creating request is received for the tenant : " + tenantId + " From" + " the user : "
|
|
|
|
|
|
|
|
+ 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())) {
|
|
|
|
|
|
|
|
publicAppStorePath = Constants.APPLE_STORE_URL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ApplicationDTO applicationDTO = APIUtil.convertToAppDTO(publicAppWrapper);
|
|
|
|
|
|
|
|
ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0);
|
|
|
|
|
|
|
|
String uuid = UUID.randomUUID().toString();
|
|
|
|
|
|
|
|
String appInstallerUrl = publicAppStorePath + applicationReleaseDTO.getPackageName();
|
|
|
|
|
|
|
|
//todo check app package name exist or not, do it in validation method
|
|
|
|
|
|
|
|
applicationReleaseDTO.setInstallerName(appInstallerUrl);
|
|
|
|
|
|
|
|
String md5 = DigestUtils.md5Hex(appInstallerUrl);
|
|
|
|
|
|
|
|
applicationReleaseDTO.setUuid(uuid);
|
|
|
|
|
|
|
|
applicationReleaseDTO.setAppHashValue(md5);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//uploading application artifacts
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
applicationDTO.getApplicationReleaseDTOs().clear();
|
|
|
|
|
|
|
|
applicationDTO.getApplicationReleaseDTOs()
|
|
|
|
|
|
|
|
.add(addImageArtifacts(applicationReleaseDTO, applicationArtifact));
|
|
|
|
|
|
|
|
} catch (ResourceManagementException e) {
|
|
|
|
|
|
|
|
String msg = "Error Occured when uploading artifacts of the public app: " + publicAppWrapper.getName();
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//insert application data into database
|
|
|
|
|
|
|
|
return addAppDataIntoDB(applicationDTO, tenantId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public ApplicationList getApplications(Filter filter) throws ApplicationManagementException {
|
|
|
|
public ApplicationList getApplications(Filter filter) throws ApplicationManagementException {
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
@ -745,7 +732,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public ApplicationRelease createEntAppRelease(int applicationId, ApplicationReleaseWrapper applicationReleaseWrapper,
|
|
|
|
public ApplicationRelease createEntAppRelease(int applicationId, EntAppReleaseWrapper entAppReleaseWrapper,
|
|
|
|
ApplicationArtifact applicationArtifact) throws ApplicationManagementException {
|
|
|
|
ApplicationArtifact applicationArtifact) throws ApplicationManagementException {
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
ApplicationRelease applicationRelease;
|
|
|
|
ApplicationRelease applicationRelease;
|
|
|
@ -764,14 +751,15 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
throw new BadRequestException(msg);
|
|
|
|
throw new BadRequestException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DeviceType deviceType = getDeviceTypeData(applicationDTO.getDeviceTypeId());
|
|
|
|
DeviceType deviceType = getDeviceTypeData(applicationDTO.getDeviceTypeId());
|
|
|
|
if (!isValidOsVersions(applicationReleaseWrapper.getSupportedOsVersions(), deviceType.getName())){
|
|
|
|
if (!isValidOsVersions(entAppReleaseWrapper.getSupportedOsVersions(), deviceType.getName())){
|
|
|
|
String msg = "You are trying to add application release which has invalid or unsupported OS versions in "
|
|
|
|
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.";
|
|
|
|
+ "the supportedOsVersions section. Hence, please re-evaluate the request payload.";
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
throw new BadRequestException(msg);
|
|
|
|
throw new BadRequestException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ApplicationReleaseDTO applicationReleaseDTO = uploadReleaseArtifacts(applicationReleaseWrapper,
|
|
|
|
ApplicationReleaseDTO applicationReleaseDTO = uploadEntAppReleaseArtifacts(
|
|
|
|
applicationDTO, applicationArtifact, deviceType.getName());
|
|
|
|
APIUtil.releaseWrapperToReleaseDTO(entAppReleaseWrapper),
|
|
|
|
|
|
|
|
applicationArtifact, deviceType.getName(), true);
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
String initialstate = lifecycleStateManager.getInitialState();
|
|
|
|
String initialstate = lifecycleStateManager.getInitialState();
|
|
|
|
applicationReleaseDTO.setCurrentState(initialstate);
|
|
|
|
applicationReleaseDTO.setCurrentState(initialstate);
|
|
|
@ -829,18 +817,16 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private ApplicationReleaseDTO uploadReleaseArtifacts(ApplicationReleaseWrapper applicationReleaseWrapper,
|
|
|
|
private ApplicationReleaseDTO uploadEntAppReleaseArtifacts(ApplicationReleaseDTO releaseDTO,
|
|
|
|
ApplicationDTO applicationDTO, ApplicationArtifact applicationArtifact, String deviceTypeName)
|
|
|
|
ApplicationArtifact applicationArtifact, String deviceTypeName, boolean isNewRelease)
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ApplicationReleaseDTO applicationReleaseDTO = addApplicationReleaseArtifacts(applicationDTO.getType(),
|
|
|
|
ApplicationReleaseDTO applicationReleaseDTO = addApplicationReleaseArtifacts(deviceTypeName, releaseDTO,
|
|
|
|
deviceTypeName, APIUtil.releaseWrapperToReleaseDTO(applicationReleaseWrapper), applicationArtifact,
|
|
|
|
applicationArtifact, isNewRelease);
|
|
|
|
true);
|
|
|
|
|
|
|
|
return addImageArtifacts(applicationReleaseDTO, applicationArtifact);
|
|
|
|
return addImageArtifacts(applicationReleaseDTO, applicationArtifact);
|
|
|
|
} catch (ResourceManagementException e) {
|
|
|
|
} catch (ResourceManagementException e) {
|
|
|
|
String msg =
|
|
|
|
String msg = "Error occurred while uploading application release artifacts.";
|
|
|
|
"Error occurred while uploading application release artifacts. Application ID: " + applicationDTO
|
|
|
|
log.error(msg);
|
|
|
|
.getId();
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1310,7 +1296,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void updateApplicationArtifact(String deviceType, String appType, String uuid,
|
|
|
|
public void updateApplicationArtifact(String deviceType, String uuid,
|
|
|
|
ApplicationArtifact applicationArtifact) throws ApplicationManagementException {
|
|
|
|
ApplicationArtifact applicationArtifact) throws ApplicationManagementException {
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
boolean isValidDeviceType = false;
|
|
|
|
boolean isValidDeviceType = false;
|
|
|
@ -1338,15 +1324,31 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
ApplicationReleaseDTO applicationReleaseDTO = this.applicationReleaseDAO.getReleaseByUUID(uuid, tenantId);
|
|
|
|
ApplicationDTO applicationDTO = this.applicationDAO.getApplicationByUUID(uuid, tenantId);
|
|
|
|
if (applicationReleaseDTO == null) {
|
|
|
|
if (applicationDTO == null) {
|
|
|
|
String msg = "Couldn't found an application release for UUID: " + uuid;
|
|
|
|
String msg = "Couldn't found an application which has application release for UUID: " + uuid;
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
throw new NotFoundException(msg);
|
|
|
|
throw new NotFoundException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ApplicationType.ENTERPRISE.toString().equals(applicationDTO.getType())) {
|
|
|
|
|
|
|
|
String msg = "If Application type is " + applicationDTO.getType() + ", then you don't have application "
|
|
|
|
|
|
|
|
+ "release artifact to update for application release UUID: " + uuid;
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0);
|
|
|
|
|
|
|
|
if (!lifecycleStateManager.isUpdatableState(applicationReleaseDTO.getCurrentState())) {
|
|
|
|
|
|
|
|
String msg = "Application release in " + applicationReleaseDTO.getCurrentState()
|
|
|
|
|
|
|
|
+ " state. Therefore you are not allowed to update the application release. Hence, "
|
|
|
|
|
|
|
|
+ "please move application release from " + applicationReleaseDTO.getCurrentState()
|
|
|
|
|
|
|
|
+ " to updatable state.";
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ForbiddenException(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
applicationReleaseDTO = updateApplicationReleaseArtifacts(appType, deviceType, applicationReleaseDTO,
|
|
|
|
applicationReleaseDTO = updateEntAppReleaseArtifact(deviceType,applicationReleaseDTO
|
|
|
|
applicationArtifact);
|
|
|
|
, applicationArtifact);
|
|
|
|
applicationReleaseDTO = this.applicationReleaseDAO.updateRelease(applicationReleaseDTO, tenantId);
|
|
|
|
applicationReleaseDTO = this.applicationReleaseDAO.updateRelease(applicationReleaseDTO, tenantId);
|
|
|
|
if (applicationReleaseDTO == null) {
|
|
|
|
if (applicationReleaseDTO == null) {
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
@ -2105,22 +2107,21 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean updateRelease(String deviceType, String applicationType, String releaseUuid,
|
|
|
|
public boolean updateEntAppRelease(String deviceType, String releaseUuid, EntAppReleaseWrapper entAppReleaseWrapper,
|
|
|
|
ApplicationReleaseWrapper applicationReleaseWrapper, ApplicationArtifact applicationArtifact)
|
|
|
|
ApplicationArtifact applicationArtifact) throws ApplicationManagementException {
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
ApplicationReleaseDTO applicationReleaseDTO = this.applicationReleaseDAO
|
|
|
|
ApplicationDTO applicationDTO = this.applicationDAO.getApplicationByUUID(releaseUuid, tenantId);
|
|
|
|
.getReleaseByUUID(releaseUuid, tenantId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (applicationReleaseDTO == null) {
|
|
|
|
if (applicationDTO == null) {
|
|
|
|
String msg = "Couldn't found an application release for updating. Application release UUID: " + releaseUuid;
|
|
|
|
String msg = "Couldn't found an application which has application release for UUID: " + releaseUuid;
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
throw new NotFoundException(msg);
|
|
|
|
throw new NotFoundException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0);
|
|
|
|
if (!lifecycleStateManager.isUpdatableState(applicationReleaseDTO.getCurrentState())) {
|
|
|
|
if (!lifecycleStateManager.isUpdatableState(applicationReleaseDTO.getCurrentState())) {
|
|
|
|
String msg = "Application release in " + applicationReleaseDTO.getCurrentState()
|
|
|
|
String msg = "Application release in " + applicationReleaseDTO.getCurrentState()
|
|
|
|
+ " state. Therefore you are not allowed to update the application release. Hence, "
|
|
|
|
+ " state. Therefore you are not allowed to update the application release. Hence, "
|
|
|
@ -2131,15 +2132,9 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DeviceType deviceTypeObj = getDeviceTypeData(deviceType);
|
|
|
|
DeviceType deviceTypeObj = getDeviceTypeData(deviceType);
|
|
|
|
Double price = applicationReleaseWrapper.getPrice();
|
|
|
|
Double price = entAppReleaseWrapper.getPrice();
|
|
|
|
|
|
|
|
|
|
|
|
String applicationSubType = this.applicationDAO.getApplicationSubTypeByUUID(releaseUuid, tenantId);
|
|
|
|
|
|
|
|
if (applicationSubType == null) {
|
|
|
|
|
|
|
|
String msg = "Couldn't find an application subscription type for the application release UUID: " + releaseUuid;
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String applicationSubType = applicationDTO.getSubType();
|
|
|
|
if (price < 0.0 || (price == 0.0 && ApplicationSubscriptionType.PAID.toString().equals(applicationSubType))
|
|
|
|
if (price < 0.0 || (price == 0.0 && ApplicationSubscriptionType.PAID.toString().equals(applicationSubType))
|
|
|
|
|| (price > 0.0 && ApplicationSubscriptionType.FREE.toString().equals(applicationSubType))) {
|
|
|
|
|| (price > 0.0 && ApplicationSubscriptionType.FREE.toString().equals(applicationSubType))) {
|
|
|
|
throw new BadRequestException(
|
|
|
|
throw new BadRequestException(
|
|
|
@ -2150,7 +2145,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
applicationReleaseDTO.setPrice(price);
|
|
|
|
applicationReleaseDTO.setPrice(price);
|
|
|
|
applicationReleaseDTO.setIsSharedWithAllTenants(applicationReleaseDTO.getIsSharedWithAllTenants());
|
|
|
|
applicationReleaseDTO.setIsSharedWithAllTenants(applicationReleaseDTO.getIsSharedWithAllTenants());
|
|
|
|
|
|
|
|
|
|
|
|
String supportedOSVersions = applicationReleaseWrapper.getSupportedOsVersions();
|
|
|
|
String supportedOSVersions = entAppReleaseWrapper.getSupportedOsVersions();
|
|
|
|
if (!StringUtils.isEmpty(supportedOSVersions)) {
|
|
|
|
if (!StringUtils.isEmpty(supportedOSVersions)) {
|
|
|
|
if (!isValidOsVersions(supportedOSVersions, deviceType)){
|
|
|
|
if (!isValidOsVersions(supportedOSVersions, deviceType)){
|
|
|
|
String msg = "You are trying to update application release which has invalid or unsupported OS "
|
|
|
|
String msg = "You are trying to update application release which has invalid or unsupported OS "
|
|
|
@ -2159,18 +2154,20 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
throw new BadRequestException(msg); }
|
|
|
|
throw new BadRequestException(msg); }
|
|
|
|
applicationReleaseDTO.setSupportedOsVersions(supportedOSVersions);
|
|
|
|
applicationReleaseDTO.setSupportedOsVersions(supportedOSVersions);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!StringUtils.isEmpty(applicationReleaseWrapper.getDescription())) {
|
|
|
|
if (!StringUtils.isEmpty(entAppReleaseWrapper.getDescription())) {
|
|
|
|
applicationReleaseDTO.setDescription(applicationReleaseWrapper.getDescription());
|
|
|
|
applicationReleaseDTO.setDescription(entAppReleaseWrapper.getDescription());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!StringUtils.isEmpty(applicationReleaseWrapper.getReleaseType())) {
|
|
|
|
if (!StringUtils.isEmpty(entAppReleaseWrapper.getReleaseType())) {
|
|
|
|
applicationReleaseDTO.setReleaseType(applicationReleaseWrapper.getReleaseType());
|
|
|
|
applicationReleaseDTO.setReleaseType(entAppReleaseWrapper.getReleaseType());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!StringUtils.isEmpty(applicationReleaseWrapper.getMetaData())) {
|
|
|
|
if (!StringUtils.isEmpty(entAppReleaseWrapper.getMetaData())) {
|
|
|
|
applicationReleaseDTO.setMetaData(applicationReleaseWrapper.getMetaData());
|
|
|
|
applicationReleaseDTO.setMetaData(entAppReleaseWrapper.getMetaData());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
applicationReleaseDTO = updateApplicationReleaseArtifacts(applicationType, deviceTypeObj.getName(),
|
|
|
|
if (!StringUtils.isEmpty(applicationArtifact.getInstallerName())&& applicationArtifact.getInstallerStream() != null){
|
|
|
|
applicationReleaseDTO, applicationArtifact);
|
|
|
|
applicationReleaseDTO = updateEntAppReleaseArtifact(deviceTypeObj.getName(),
|
|
|
|
|
|
|
|
applicationReleaseDTO, applicationArtifact);
|
|
|
|
|
|
|
|
}
|
|
|
|
applicationReleaseDTO = updateImageArtifacts(applicationReleaseDTO, applicationArtifact);
|
|
|
|
applicationReleaseDTO = updateImageArtifacts(applicationReleaseDTO, applicationArtifact);
|
|
|
|
|
|
|
|
|
|
|
|
boolean updateStatus = applicationReleaseDAO.updateRelease(applicationReleaseDTO, tenantId) != null;
|
|
|
|
boolean updateStatus = applicationReleaseDAO.updateRelease(applicationReleaseDTO, tenantId) != null;
|
|
|
@ -2232,10 +2229,10 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
DeviceType deviceType = getDeviceTypeData(applicationWrapper.getDeviceType());
|
|
|
|
DeviceType deviceType = getDeviceTypeData(applicationWrapper.getDeviceType());
|
|
|
|
deviceTypeId = deviceType.getId();
|
|
|
|
deviceTypeId = deviceType.getId();
|
|
|
|
|
|
|
|
|
|
|
|
List<ApplicationReleaseWrapper> applicationReleaseWrappers;
|
|
|
|
List<EntAppReleaseWrapper> entAppReleaseWrappers;
|
|
|
|
applicationReleaseWrappers = applicationWrapper.getApplicationReleaseWrappers();
|
|
|
|
entAppReleaseWrappers = applicationWrapper.getEntAppReleaseWrappers();
|
|
|
|
|
|
|
|
|
|
|
|
if (applicationReleaseWrappers == null || applicationReleaseWrappers.size() != 1) {
|
|
|
|
if (entAppReleaseWrappers == null || entAppReleaseWrappers.size() != 1) {
|
|
|
|
String msg = "Invalid application creating request. Application creating request must have single "
|
|
|
|
String msg = "Invalid application creating request. Application creating request must have single "
|
|
|
|
+ "application release. Application name:" + applicationWrapper.getName() + ".";
|
|
|
|
+ "application release. Application name:" + applicationWrapper.getName() + ".";
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
@ -2402,9 +2399,9 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
throw new BadRequestException(msg);
|
|
|
|
throw new BadRequestException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (param instanceof ApplicationReleaseWrapper) {
|
|
|
|
if (param instanceof EntAppReleaseWrapper) {
|
|
|
|
ApplicationReleaseWrapper applicationReleaseWrapper = (ApplicationReleaseWrapper) param;
|
|
|
|
EntAppReleaseWrapper entAppReleaseWrapper = (EntAppReleaseWrapper) param;
|
|
|
|
if (StringUtils.isEmpty(applicationReleaseWrapper.getSupportedOsVersions())) {
|
|
|
|
if (StringUtils.isEmpty(entAppReleaseWrapper.getSupportedOsVersions())) {
|
|
|
|
String msg = "Supported OS Version shouldn't be null or empty.";
|
|
|
|
String msg = "Supported OS Version shouldn't be null or empty.";
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
throw new BadRequestException(msg);
|
|
|
|
throw new BadRequestException(msg);
|
|
|
|