From d9d0d0a5b8634c69f2ac2533ff278d8544fd9bf0 Mon Sep 17 00:00:00 2001 From: inoshperera Date: Sat, 29 Sep 2018 12:21:23 +0530 Subject: [PATCH] add getLifecycleState check --- .../application/mgt/core/impl/ApplicationManagerImpl.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java index fc27224669..7c20c984eb 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java @@ -46,6 +46,7 @@ import org.wso2.carbon.device.application.mgt.core.dao.VisibilityDAO; import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOFactory; import org.wso2.carbon.device.application.mgt.core.dao.common.Util; import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; +import org.wso2.carbon.device.application.mgt.core.exception.ForbiddenException; import org.wso2.carbon.device.application.mgt.core.exception.LifeCycleManagementDAOException; import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException; import org.wso2.carbon.device.application.mgt.core.exception.ValidationException; @@ -733,6 +734,13 @@ public class ApplicationManagerImpl implements ApplicationManager { if (applicationRelease == null) { throw new NotFoundException("No App release associated with the app Id " + appId + "and UUID "+ uuid); } + LifecycleState lifecycleState = getLifecycleState(appId, applicationRelease.getUuid()); + if (AppLifecycleState.PUBLISHED.toString().equals(lifecycleState.getCurrentState()) || + AppLifecycleState.DEPRECATED.toString().equals(lifecycleState.getCurrentState())) { + throw new ForbiddenException("Can't Update the application release in " + + "PUBLISHED or DEPRECATED state. Hence please demote the application and update " + + "the application release"); + } ApplicationRelease updatedRelease = applicationStorageManager .updateImageArtifacts(applicationRelease, iconFileStream, bannerFileStream, attachments); return updateRelease(appId, updatedRelease);