|
|
@ -101,6 +101,7 @@ import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.UUID;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import java.util.stream.Stream;
|
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
|
|
|
|
|
@ -275,11 +276,13 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
.getAppInstallerData(binary, deviceType);
|
|
|
|
.getAppInstallerData(binary, deviceType);
|
|
|
|
String packagename = applicationInstaller.getPackageName();
|
|
|
|
String packagename = applicationInstaller.getPackageName();
|
|
|
|
|
|
|
|
|
|
|
|
ConnectionManagerUtil.getDBConnection();
|
|
|
|
try {
|
|
|
|
if (!isNewRelease && applicationReleaseDAO.isActiveReleaseExisitForPackageName(packagename, tenantId,
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
|
|
|
|
if (!isNewRelease && applicationReleaseDAO
|
|
|
|
|
|
|
|
.isActiveReleaseExisitForPackageName(packagename, tenantId,
|
|
|
|
lifecycleStateManager.getEndState())) {
|
|
|
|
lifecycleStateManager.getEndState())) {
|
|
|
|
String msg = "Application release is already exist for the package name: " + packagename +
|
|
|
|
String msg = "Application release is already exist for the package name: " + packagename
|
|
|
|
". Either you can delete all application releases for package " + packagename + " or "
|
|
|
|
+ ". Either you can delete all application releases for package " + packagename + " or "
|
|
|
|
+ "you can add this app release as an new application release, under the existing "
|
|
|
|
+ "you can add this app release as an new application release, under the existing "
|
|
|
|
+ "application.";
|
|
|
|
+ "application.";
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
@ -295,37 +298,38 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
throw new ApplicationStorageManagementException(msg);
|
|
|
|
throw new ApplicationStorageManagementException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (this.applicationReleaseDAO
|
|
|
|
if (this.applicationReleaseDAO.verifyReleaseExistenceByHash(md5OfApp, tenantId)) {
|
|
|
|
.verifyReleaseExistenceByHash(md5OfApp, tenantId)) {
|
|
|
|
String msg =
|
|
|
|
throw new BadRequestException(
|
|
|
|
"Application release exists for the uploaded binary file. Device Type: " + deviceType;
|
|
|
|
"Application release exists for the uploaded binary file. Device Type: " + deviceType);
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new BadRequestException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
applicationReleaseDTO.setAppHashValue(md5OfApp);
|
|
|
|
applicationReleaseDTO.setAppHashValue(md5OfApp);
|
|
|
|
|
|
|
|
|
|
|
|
try (ByteArrayInputStream binaryDuplicate = new ByteArrayInputStream(content)) {
|
|
|
|
try (ByteArrayInputStream binaryDuplicate = new ByteArrayInputStream(content)) {
|
|
|
|
applicationReleaseDTO = applicationStorageManager
|
|
|
|
applicationReleaseDTO = applicationStorageManager
|
|
|
|
.uploadReleaseArtifact(applicationReleaseDTO, deviceType, binaryDuplicate);
|
|
|
|
.uploadReleaseArtifact(applicationReleaseDTO, deviceType, binaryDuplicate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} 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) {
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
String msg = "Error occurred when getting database connection for verifying application package existence.";
|
|
|
|
String msg = "Error occurred when getting database connection for verifying app release data.";
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
String msg = "Error occurred when executing the query for verifying application release existence for "
|
|
|
|
String msg =
|
|
|
|
|
|
|
|
"Error occurred when executing the query for verifying application release existence for "
|
|
|
|
+ "the package.";
|
|
|
|
+ "the package.";
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|
return applicationReleaseDTO;
|
|
|
|
return applicationReleaseDTO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -749,31 +753,30 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
public ApplicationRelease createEntAppRelease(int applicationId, EntAppReleaseWrapper entAppReleaseWrapper,
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Application release creating request is received for the application id: " + applicationId);
|
|
|
|
log.debug("Application release creating request is received for the application id: " + applicationId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ApplicationDTO applicationDTO = getApplication(applicationId);
|
|
|
|
ApplicationDTO applicationDTO = getApplication(applicationId);
|
|
|
|
try {
|
|
|
|
|
|
|
|
if (!ApplicationType.ENTERPRISE.toString().equals(applicationDTO.getType())) {
|
|
|
|
if (!ApplicationType.ENTERPRISE.toString().equals(applicationDTO.getType())) {
|
|
|
|
String msg =
|
|
|
|
String msg = "It is possible to add new application release for " + ApplicationType.ENTERPRISE.toString()
|
|
|
|
"It is possible to add new application release for " + ApplicationType.ENTERPRISE.toString()
|
|
|
|
+ " app type. But you are requesting to add new application release for " + applicationDTO.getType()
|
|
|
|
+ " app type. But you are requesting to add new application release for "
|
|
|
|
+ " app type.";
|
|
|
|
+ applicationDTO.getType() + " app type.";
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
throw new BadRequestException(msg);
|
|
|
|
throw new BadRequestException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DeviceType deviceType = getDeviceTypeData(applicationDTO.getDeviceTypeId());
|
|
|
|
DeviceType deviceType = getDeviceTypeData(applicationDTO.getDeviceTypeId());
|
|
|
|
if (!isValidOsVersions(entAppReleaseWrapper.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 = uploadEntAppReleaseArtifacts(
|
|
|
|
ApplicationReleaseDTO applicationReleaseDTO = uploadEntAppReleaseArtifacts(
|
|
|
|
APIUtil.releaseWrapperToReleaseDTO(entAppReleaseWrapper),
|
|
|
|
APIUtil.releaseWrapperToReleaseDTO(entAppReleaseWrapper), applicationArtifact, deviceType.getName(),
|
|
|
|
applicationArtifact, deviceType.getName(), true);
|
|
|
|
true);
|
|
|
|
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
String initialstate = lifecycleStateManager.getInitialState();
|
|
|
|
String initialstate = lifecycleStateManager.getInitialState();
|
|
|
|
applicationReleaseDTO.setCurrentState(initialstate);
|
|
|
|
applicationReleaseDTO.setCurrentState(initialstate);
|
|
|
@ -782,7 +785,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
.createRelease(applicationReleaseDTO, applicationDTO.getId(), tenantId);
|
|
|
|
.createRelease(applicationReleaseDTO, applicationDTO.getId(), tenantId);
|
|
|
|
this.lifecycleStateDAO
|
|
|
|
this.lifecycleStateDAO
|
|
|
|
.addLifecycleState(lifecycleState, applicationReleaseDTO.getId(), tenantId);
|
|
|
|
.addLifecycleState(lifecycleState, applicationReleaseDTO.getId(), tenantId);
|
|
|
|
applicationRelease = APIUtil.releaseDtoToRelease(applicationReleaseDTO);
|
|
|
|
ApplicationRelease applicationRelease = APIUtil.releaseDtoToRelease(applicationReleaseDTO);
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
return applicationRelease;
|
|
|
|
return applicationRelease;
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
@ -2132,67 +2135,145 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
ApplicationDTO applicationDTO = this.applicationDAO.getApplicationByUUID(releaseUuid, tenantId);
|
|
|
|
ApplicationDTO applicationDTO = this.applicationDAO.getApplicationByUUID(releaseUuid, tenantId);
|
|
|
|
|
|
|
|
|
|
|
|
if (applicationDTO == null) {
|
|
|
|
AtomicReference<ApplicationReleaseDTO> applicationReleaseDTO = new AtomicReference<>(
|
|
|
|
String msg = "Couldn't found an application which has application release for UUID: " + releaseUuid;
|
|
|
|
applicationDTO.getApplicationReleaseDTOs().get(0));
|
|
|
|
log.error(msg);
|
|
|
|
validateAppReleaseUpdating(applicationDTO, ApplicationType.ENTERPRISE.toString());
|
|
|
|
throw new NotFoundException(msg);
|
|
|
|
applicationReleaseDTO.get().setPrice(entAppReleaseWrapper.getPrice());
|
|
|
|
|
|
|
|
applicationReleaseDTO.get().setIsSharedWithAllTenants(applicationReleaseDTO.get().getIsSharedWithAllTenants());
|
|
|
|
|
|
|
|
if (!StringUtils.isEmpty(entAppReleaseWrapper.getSupportedOsVersions())) {
|
|
|
|
|
|
|
|
applicationReleaseDTO.get().setSupportedOsVersions(entAppReleaseWrapper.getSupportedOsVersions());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!ApplicationType.ENTERPRISE.toString().equals(applicationDTO.getType())) {
|
|
|
|
if (!StringUtils.isEmpty(entAppReleaseWrapper.getDescription())) {
|
|
|
|
String msg = "You trying to perform enterprise app release update on non-enterprise app release.";
|
|
|
|
applicationReleaseDTO.get().setDescription(entAppReleaseWrapper.getDescription());
|
|
|
|
log.error(msg);
|
|
|
|
}
|
|
|
|
throw new ForbiddenException(msg);
|
|
|
|
if (!StringUtils.isEmpty(entAppReleaseWrapper.getReleaseType())) {
|
|
|
|
|
|
|
|
applicationReleaseDTO.get().setReleaseType(entAppReleaseWrapper.getReleaseType());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!StringUtils.isEmpty(entAppReleaseWrapper.getMetaData())) {
|
|
|
|
|
|
|
|
applicationReleaseDTO.get().setMetaData(entAppReleaseWrapper.getMetaData());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0);
|
|
|
|
if (!StringUtils.isEmpty(applicationArtifact.getInstallerName())&& applicationArtifact.getInstallerStream() != null){
|
|
|
|
if (!lifecycleStateManager.isUpdatableState(applicationReleaseDTO.getCurrentState())) {
|
|
|
|
DeviceType deviceTypeObj = getDeviceTypeData(applicationDTO.getDeviceTypeId());
|
|
|
|
String msg = "Application release in " + applicationReleaseDTO.getCurrentState()
|
|
|
|
applicationReleaseDTO
|
|
|
|
+ " state. Therefore you are not allowed to update the application release. Hence, "
|
|
|
|
.set(updateEntAppReleaseArtifact(deviceTypeObj.getName(), applicationReleaseDTO.get(),
|
|
|
|
+ "please move application release from " + applicationReleaseDTO.getCurrentState()
|
|
|
|
applicationArtifact));
|
|
|
|
+ " to updatable state.";
|
|
|
|
}
|
|
|
|
|
|
|
|
applicationReleaseDTO.set(updateImageArtifacts(applicationReleaseDTO.get(), applicationArtifact));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boolean updateStatus = applicationReleaseDAO.updateRelease(applicationReleaseDTO.get(), tenantId) != null;
|
|
|
|
|
|
|
|
if (!updateStatus) {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
|
|
|
|
return updateStatus;
|
|
|
|
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
|
|
|
String msg = "Error occured when updating Ent Application release of UUID: " + releaseUuid;
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
throw new ForbiddenException(msg);
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
|
|
|
|
} catch (ResourceManagementException e) {
|
|
|
|
|
|
|
|
String msg = "Error occured when updating application release artifact in the file system. Ent App release "
|
|
|
|
|
|
|
|
+ "UUID:" + releaseUuid;
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DeviceType deviceTypeObj = getDeviceTypeData(deviceType);
|
|
|
|
@Override
|
|
|
|
Double price = entAppReleaseWrapper.getPrice();
|
|
|
|
public boolean updatePubAppRelease(String deviceType, String releaseUuid,
|
|
|
|
|
|
|
|
PublicAppReleaseWrapper publicAppReleaseWrapper, ApplicationArtifact applicationArtifact)
|
|
|
|
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
|
|
|
|
|
|
|
|
String applicationSubType = applicationDTO.getSubType();
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
if (price < 0.0 || (price == 0.0 && ApplicationSubscriptionType.PAID.toString().equals(applicationSubType))
|
|
|
|
try {
|
|
|
|
|| (price > 0.0 && ApplicationSubscriptionType.FREE.toString().equals(applicationSubType))) {
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
throw new BadRequestException(
|
|
|
|
ApplicationDTO applicationDTO = this.applicationDAO.getApplicationByUUID(releaseUuid, tenantId);
|
|
|
|
"Invalid app release payload for updating application release. ApplicationDTO price is " + price
|
|
|
|
validateAppReleaseUpdating(applicationDTO, ApplicationType.PUBLIC.toString());
|
|
|
|
+ " for " + applicationSubType + " application., Application Release UUID "
|
|
|
|
AtomicReference<ApplicationReleaseDTO> applicationReleaseDTO = new AtomicReference<>(
|
|
|
|
+ releaseUuid + " and supported device type is " + deviceType);
|
|
|
|
applicationDTO.getApplicationReleaseDTOs().get(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
applicationReleaseDTO.setPrice(price);
|
|
|
|
applicationReleaseDTO.get().setPrice(publicAppReleaseWrapper.getPrice());
|
|
|
|
applicationReleaseDTO.setIsSharedWithAllTenants(applicationReleaseDTO.getIsSharedWithAllTenants());
|
|
|
|
applicationReleaseDTO.get().setIsSharedWithAllTenants(applicationReleaseDTO.get().getIsSharedWithAllTenants());
|
|
|
|
|
|
|
|
|
|
|
|
String supportedOSVersions = entAppReleaseWrapper.getSupportedOsVersions();
|
|
|
|
if (!StringUtils.isEmpty(publicAppReleaseWrapper.getPackageName())) {
|
|
|
|
if (!StringUtils.isEmpty(supportedOSVersions)) {
|
|
|
|
applicationReleaseDTO.get().setVersion(publicAppReleaseWrapper.getVersion());
|
|
|
|
if (!isValidOsVersions(supportedOSVersions, deviceType)){
|
|
|
|
|
|
|
|
String msg = "You are trying to update 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.setSupportedOsVersions(supportedOSVersions);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!StringUtils.isEmpty(entAppReleaseWrapper.getDescription())) {
|
|
|
|
if (!StringUtils.isEmpty(publicAppReleaseWrapper.getVersion())) {
|
|
|
|
applicationReleaseDTO.setDescription(entAppReleaseWrapper.getDescription());
|
|
|
|
applicationReleaseDTO.get().setVersion(publicAppReleaseWrapper.getVersion());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!StringUtils.isEmpty(entAppReleaseWrapper.getReleaseType())) {
|
|
|
|
if (!StringUtils.isEmpty(publicAppReleaseWrapper.getSupportedOsVersions())) {
|
|
|
|
applicationReleaseDTO.setReleaseType(entAppReleaseWrapper.getReleaseType());
|
|
|
|
applicationReleaseDTO.get().setSupportedOsVersions(publicAppReleaseWrapper.getSupportedOsVersions());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!StringUtils.isEmpty(entAppReleaseWrapper.getMetaData())) {
|
|
|
|
if (!StringUtils.isEmpty(publicAppReleaseWrapper.getDescription())) {
|
|
|
|
applicationReleaseDTO.setMetaData(entAppReleaseWrapper.getMetaData());
|
|
|
|
applicationReleaseDTO.get().setDescription(publicAppReleaseWrapper.getDescription());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!StringUtils.isEmpty(publicAppReleaseWrapper.getReleaseType())) {
|
|
|
|
|
|
|
|
applicationReleaseDTO.get().setReleaseType(publicAppReleaseWrapper.getReleaseType());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!StringUtils.isEmpty(publicAppReleaseWrapper.getMetaData())) {
|
|
|
|
|
|
|
|
applicationReleaseDTO.get().setMetaData(publicAppReleaseWrapper.getMetaData());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!StringUtils.isEmpty(applicationArtifact.getInstallerName())&& applicationArtifact.getInstallerStream() != null){
|
|
|
|
applicationReleaseDTO.set(updateImageArtifacts(applicationReleaseDTO.get(), applicationArtifact));
|
|
|
|
applicationReleaseDTO = updateEntAppReleaseArtifact(deviceTypeObj.getName(),
|
|
|
|
|
|
|
|
applicationReleaseDTO, applicationArtifact);
|
|
|
|
boolean updateStatus = applicationReleaseDAO.updateRelease(applicationReleaseDTO.get(), tenantId) != null;
|
|
|
|
|
|
|
|
if (!updateStatus) {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
applicationReleaseDTO = updateImageArtifacts(applicationReleaseDTO, applicationArtifact);
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
|
|
|
|
return updateStatus;
|
|
|
|
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
|
|
|
String msg = "Error occured when updating public app release of UUID: " + releaseUuid;
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
|
|
|
|
} catch (ResourceManagementException e) {
|
|
|
|
|
|
|
|
String msg = "Error occured when updating public app release artifact in the file system. Public app "
|
|
|
|
|
|
|
|
+ "release UUID:" + releaseUuid;
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public boolean updateWebAppRelease(String deviceType, String releaseUuid,
|
|
|
|
|
|
|
|
WebAppReleaseWrapper webAppReleaseWrapper, ApplicationArtifact applicationArtifact)
|
|
|
|
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
|
|
|
|
ApplicationDTO applicationDTO = this.applicationDAO.getApplicationByUUID(releaseUuid, tenantId);
|
|
|
|
|
|
|
|
validateAppReleaseUpdating(applicationDTO, ApplicationType.WEB_CLIP.toString());
|
|
|
|
|
|
|
|
AtomicReference<ApplicationReleaseDTO> applicationReleaseDTO = new AtomicReference<>(
|
|
|
|
|
|
|
|
applicationDTO.getApplicationReleaseDTOs().get(0));
|
|
|
|
|
|
|
|
|
|
|
|
boolean updateStatus = applicationReleaseDAO.updateRelease(applicationReleaseDTO, tenantId) != null;
|
|
|
|
applicationReleaseDTO.get().setPrice(webAppReleaseWrapper.getPrice());
|
|
|
|
|
|
|
|
applicationReleaseDTO.get().setIsSharedWithAllTenants(applicationReleaseDTO.get().getIsSharedWithAllTenants());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!StringUtils.isEmpty(webAppReleaseWrapper.getVersion())) {
|
|
|
|
|
|
|
|
applicationReleaseDTO.get().setVersion(webAppReleaseWrapper.getVersion());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!StringUtils.isEmpty(webAppReleaseWrapper.getVersion())) {
|
|
|
|
|
|
|
|
applicationReleaseDTO.get().setVersion(webAppReleaseWrapper.getVersion());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!StringUtils.isEmpty(webAppReleaseWrapper.getDescription())) {
|
|
|
|
|
|
|
|
applicationReleaseDTO.get().setDescription(webAppReleaseWrapper.getDescription());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!StringUtils.isEmpty(webAppReleaseWrapper.getReleaseType())) {
|
|
|
|
|
|
|
|
applicationReleaseDTO.get().setReleaseType(webAppReleaseWrapper.getReleaseType());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!StringUtils.isEmpty(webAppReleaseWrapper.getMetaData())) {
|
|
|
|
|
|
|
|
applicationReleaseDTO.get().setMetaData(webAppReleaseWrapper.getMetaData());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
applicationReleaseDTO.set(updateImageArtifacts(applicationReleaseDTO.get(), applicationArtifact));
|
|
|
|
|
|
|
|
boolean updateStatus = applicationReleaseDAO.updateRelease(applicationReleaseDTO.get(), tenantId) != null;
|
|
|
|
if (!updateStatus) {
|
|
|
|
if (!updateStatus) {
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -2200,12 +2281,11 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
return updateStatus;
|
|
|
|
return updateStatus;
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
String msg = "Error occured when updating Application release. ApplicationDTO ID ApplicationDTO Release "
|
|
|
|
String msg = "Error occured when updating web app release for web app Release UUID: " + releaseUuid;
|
|
|
|
+ "UUID: " + releaseUuid;
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
} catch (ResourceManagementException e) {
|
|
|
|
} catch (ResourceManagementException e) {
|
|
|
|
String msg = "Error occured when updating application release artifact in the file system. Application "
|
|
|
|
String msg = "Error occured when updating web app release artifact in the file system. Web app "
|
|
|
|
+ "release UUID:" + releaseUuid;
|
|
|
|
+ "release UUID:" + releaseUuid;
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
@ -2214,6 +2294,50 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void validateAppReleaseUpdating(ApplicationDTO applicationDTO, String appType) throws ApplicationManagementException {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (applicationDTO == null) {
|
|
|
|
|
|
|
|
String msg = "Couldn't found an application for requested UUID.";
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new NotFoundException(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!appType.equals(applicationDTO.getType())) {
|
|
|
|
|
|
|
|
String msg = "You trying to perform " + appType + " app release update on " + applicationDTO.getType()
|
|
|
|
|
|
|
|
+ " app release.";
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ForbiddenException(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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String applicationSubType = applicationDTO.getSubType();
|
|
|
|
|
|
|
|
double price = applicationReleaseDTO.getPrice();
|
|
|
|
|
|
|
|
if (price < 0.0 || (price == 0.0 && ApplicationSubscriptionType.PAID.toString().equals(applicationSubType)) || (
|
|
|
|
|
|
|
|
price > 0.0 && ApplicationSubscriptionType.FREE.toString().equals(applicationSubType))) {
|
|
|
|
|
|
|
|
throw new BadRequestException("Invalid app release payload for updating application release. Application "
|
|
|
|
|
|
|
|
+ "price is " + price + " for " + applicationSubType + " application.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DeviceType deviceTypeObj = getDeviceTypeData(applicationDTO.getDeviceTypeId());
|
|
|
|
|
|
|
|
String supportedOSVersions = applicationReleaseDTO.getSupportedOsVersions();
|
|
|
|
|
|
|
|
if (!ApplicationType.WEB_CLIP.toString().equals(appType) && !ApplicationType.WEB_APP.toString().equals(appType)
|
|
|
|
|
|
|
|
&& !StringUtils.isEmpty(supportedOSVersions) && !isValidOsVersions(
|
|
|
|
|
|
|
|
supportedOSVersions, deviceTypeObj.getName())) {
|
|
|
|
|
|
|
|
String msg = "You are trying to update 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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public <T> void validateAppCreatingRequest(T param) throws ApplicationManagementException {
|
|
|
|
public <T> void validateAppCreatingRequest(T param) throws ApplicationManagementException {
|
|
|
@ -2232,7 +2356,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
throw new BadRequestException(msg);
|
|
|
|
throw new BadRequestException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
appCategories = applicationWrapper.getAppCategories();
|
|
|
|
appCategories = applicationWrapper.getCategories();
|
|
|
|
if (appCategories == null) {
|
|
|
|
if (appCategories == null) {
|
|
|
|
String msg = "Application category can't be null.";
|
|
|
|
String msg = "Application category can't be null.";
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|