From f95f872732dc9c018fb258e0e3c2a309dfe90ad7 Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Thu, 2 May 2019 18:38:15 +0530 Subject: [PATCH 1/6] Add application release deleting API --- .../mgt/common/dto/DeviceSubscriptionDTO.java | 68 ++++++++ .../common/services/ApplicationManager.java | 2 +- .../mgt/core/dao/SubscriptionDAO.java | 5 + .../application/mgt/core/dao/common/Util.java | 26 +++ .../GenericSubscriptionDAOImpl.java | 53 ++++++- .../mgt/core/impl/ApplicationManagerImpl.java | 149 ++++++++++-------- ...pplicationManagementPublisherAdminAPI.java | 33 ++-- ...cationManagementPublisherAdminAPIImpl.java | 14 +- 8 files changed, 244 insertions(+), 106 deletions(-) create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/dto/DeviceSubscriptionDTO.java diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/dto/DeviceSubscriptionDTO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/dto/DeviceSubscriptionDTO.java new file mode 100644 index 0000000000..c523c66a53 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/dto/DeviceSubscriptionDTO.java @@ -0,0 +1,68 @@ +/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.application.mgt.common.dto; + +import java.sql.Timestamp; + +public class DeviceSubscriptionDTO { + + private int id; + private String subscribedBy; + private Timestamp subscribedTimestamp; + private boolean isUnsubscribed; + private String unsubscribedBy; + private Timestamp unsubscribedTimestapm; + private String subscribedFrom; + private int deviceId; + + public int getId() { return id; } + + public void setId(int id) { this.id = id; } + + public String getSubscribedBy() { return subscribedBy; } + + public void setSubscribedBy(String subscribedBy) { this.subscribedBy = subscribedBy; } + + public Timestamp getSubscribedTimestamp() { return subscribedTimestamp; } + + public void setSubscribedTimestamp(Timestamp subscribedTimestamp) { + this.subscribedTimestamp = subscribedTimestamp; + } + + public boolean isUnsubscribed() { return isUnsubscribed; } + + public void setUnsubscribed(boolean unsubscribed) { isUnsubscribed = unsubscribed; } + + public String getUnsubscribedBy() { return unsubscribedBy; } + + public void setUnsubscribedBy(String unsubscribedBy) { this.unsubscribedBy = unsubscribedBy; } + + public Timestamp getUnsubscribedTimestapm() { return unsubscribedTimestapm; } + + public void setUnsubscribedTimestapm(Timestamp unsubscribedTimestapm) { + this.unsubscribedTimestapm = unsubscribedTimestapm; + } + + public String getSubscribedFrom() { return subscribedFrom; } + + public void setSubscribedFrom(String subscribedFrom) { this.subscribedFrom = subscribedFrom; } + + public int getDeviceId() { return deviceId; } + + public void setDeviceId(int deviceId) { this.deviceId = deviceId; } +} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java index 5daff08cf7..ad6f457be6 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java @@ -76,7 +76,7 @@ public interface ApplicationManager { * @param releaseUuid UUID of tha application release * @throws ApplicationManagementException ApplicationDTO Management Exception */ - String deleteApplicationRelease(int applicationId, String releaseUuid) throws ApplicationManagementException; + void deleteApplicationRelease(int applicationId, String releaseUuid) throws ApplicationManagementException; /** * To get the applications based on the search filter. diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/SubscriptionDAO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/SubscriptionDAO.java index 2045bf62ca..cd46b6a8b3 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/SubscriptionDAO.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/SubscriptionDAO.java @@ -20,6 +20,7 @@ package org.wso2.carbon.device.application.mgt.core.dao; import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO; import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO; +import org.wso2.carbon.device.application.mgt.common.dto.DeviceSubscriptionDTO; import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; @@ -86,4 +87,8 @@ public interface SubscriptionDAO { */ void subscribeGroupToApplication(int tenantId, String subscribedBy, List groupList, int appId, int releaseId) throws ApplicationManagementDAOException; + + public List getDeviceSubscriptions(int appReleaseId, int tenantId) throws + ApplicationManagementDAOException; + } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/Util.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/Util.java index 08d7738b14..2a5031f843 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/Util.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/Util.java @@ -26,6 +26,7 @@ import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO; import org.wso2.carbon.device.application.mgt.common.PaginationRequest; import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO; +import org.wso2.carbon.device.application.mgt.common.dto.DeviceSubscriptionDTO; import org.wso2.carbon.device.application.mgt.common.exception.ReviewManagementException; import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager; import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager; @@ -94,6 +95,31 @@ public class Util { return applications; } + /** + * To create list of device subscription objects from the result set retrieved from the Database. + * + * @param rs ResultSet + * @return List of device subscriptions that is retrieved from the Database. + * @throws SQLException SQL Exception + * @throws JSONException JSONException. + */ + public static List loadDeviceSubscriptions(ResultSet rs) throws SQLException { + List deviceSubscriptionDTOS = new ArrayList<>(); + while (rs.next()) { + DeviceSubscriptionDTO deviceSubscriptionDTO = new DeviceSubscriptionDTO(); + deviceSubscriptionDTO.setId(rs.getInt("ID")); + deviceSubscriptionDTO.setSubscribedBy(rs.getString("SUBSCRIBED_BY")); + deviceSubscriptionDTO.setSubscribedTimestamp(rs.getTimestamp("SUBSCRIBED_AT")); + deviceSubscriptionDTO.setUnsubscribed(rs.getBoolean("IS_UNSUBSCRIBED")); + deviceSubscriptionDTO.setUnsubscribedBy(rs.getString("UNSUBSCRIBED_BY")); + deviceSubscriptionDTO.setUnsubscribedTimestapm(rs.getTimestamp("UNSUBSCRIBED_AT")); + deviceSubscriptionDTO.setSubscribedFrom(rs.getString("SUBSCRIBED_FROM")); + deviceSubscriptionDTO.setDeviceId(rs.getInt("DEVICE_ID")); + deviceSubscriptionDTOS.add(deviceSubscriptionDTO); + } + return deviceSubscriptionDTOS; + } + /** * Populates {@link ApplicationReleaseDTO} object with the result obtained from the database. * diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java index e5e4253691..7eeb71046c 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java @@ -19,16 +19,21 @@ package org.wso2.carbon.device.application.mgt.core.dao.impl.subscription; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.json.JSONException; +import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO; +import org.wso2.carbon.device.application.mgt.common.dto.DeviceSubscriptionDTO; import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException; import org.wso2.carbon.device.application.mgt.core.dao.SubscriptionDAO; import org.wso2.carbon.device.application.mgt.core.dao.common.Util; import org.wso2.carbon.device.application.mgt.core.dao.impl.AbstractDAOImpl; import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; +import org.wso2.carbon.device.application.mgt.core.exception.UnexpectedServerErrorException; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; import java.sql.Connection; import java.sql.PreparedStatement; +import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; @@ -44,7 +49,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc conn = this.getDBConnection(); long time = System.currentTimeMillis() / 1000; String sql = "INSERT INTO AP_DEVICE_SUBSCRIPTION(TENANT_ID, SUBSCRIBED_BY, SUBSCRIBED_TIMESTAMP, " - + "DM_DEVICE_ID, AP_APP_RELEASE_ID, AP_APP_ID, INSTALL_STATUS) VALUES (?, ?, ?, ?, ?, ?)"; + + "DM_DEVICE_ID, AP_APP_RELEASE_ID, AP_APP_ID, INSTALL_STATUS) VALUES (?, ?, ?, ?, ?, ?, ?)"; stmt = conn.prepareStatement(sql); for (Device device : deviceList) { stmt.setInt(1, tenantId); @@ -168,4 +173,50 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc Util.cleanupResources(stmt, null); } } + + @Override + public List getDeviceSubscriptions(int appReleaseId, int tenantId) throws + ApplicationManagementDAOException { + if (log.isDebugEnabled()) { + log.debug("Getting device subscriptions for the application release id " + appReleaseId + + " from the database"); + } + Connection conn; + try { + conn = this.getDBConnection(); + String sql = "SELECT " + + "DS.ID AS ID, " + + "DS.SUBSCRIBED_BY AS SUBSCRIBED_BY, " + + "DS.SUBSCRIBED_TIMESTAMP AS SUBSCRIBED_AT, " + + "DS.UNSUBSCRIBED AS IS_UNSUBSCRIBED, " + + "DS.UNSUBSCRIBED_BY AS UNSUBSCRIBED_BY, " + + "DS.UNSUBSCRIBED_TIMESTAMP AS UNSUBSCRIBED_AT, " + + "DS.SUBSCRIBED_FROM AS SUBSCRIBED_FROM, " + + "DS.DM_DEVICE_ID AS DEVICE_ID " + + "FROM AP_DEVICE_SUBSCRIPTION DS " + + "WHERE DS.AP_APP_RELEASE_ID = ? AND DS.TENANT_ID=?"; + try (PreparedStatement stmt = conn.prepareStatement(sql)) { + stmt.setInt(1, appReleaseId); + stmt.setInt(2, tenantId); + try (ResultSet rs = stmt.executeQuery()) { + if (log.isDebugEnabled()) { + log.debug("Successfully retrieved device subscriptions for application release id " + + appReleaseId); + } + return Util.loadDeviceSubscriptions(rs); + } + } + } catch (SQLException e) { + String msg = + "Error occurred while getting device subscription data for application ID: " + appReleaseId + "."; + log.error(msg); + throw new ApplicationManagementDAOException(msg, e); + } catch (DBConnectionException e) { + String msg = + "Error occurred while obtaining the DB connection for getting device subscription for applicationID: " + + appReleaseId + "."; + log.error(msg); + throw new ApplicationManagementDAOException(msg, e); + } + } } 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 75afd8132c..95a5a17807 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 @@ -39,6 +39,7 @@ import org.wso2.carbon.device.application.mgt.common.ApplicationSubscriptionType import org.wso2.carbon.device.application.mgt.common.ApplicationType; import org.wso2.carbon.device.application.mgt.common.dto.CategoryDTO; import org.wso2.carbon.device.application.mgt.common.Filter; +import org.wso2.carbon.device.application.mgt.common.dto.DeviceSubscriptionDTO; import org.wso2.carbon.device.application.mgt.common.dto.LifecycleStateDTO; import org.wso2.carbon.device.application.mgt.common.dto.TagDTO; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; @@ -59,6 +60,7 @@ import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager; import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO; import org.wso2.carbon.device.application.mgt.core.dao.ApplicationReleaseDAO; import org.wso2.carbon.device.application.mgt.core.dao.LifecycleStateDAO; +import org.wso2.carbon.device.application.mgt.core.dao.SubscriptionDAO; 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; @@ -109,6 +111,7 @@ public class ApplicationManagerImpl implements ApplicationManager { private ApplicationDAO applicationDAO; private ApplicationReleaseDAO applicationReleaseDAO; private LifecycleStateDAO lifecycleStateDAO; + private SubscriptionDAO subscriptionDAO; private LifecycleStateManager lifecycleStateManager; public ApplicationManagerImpl() { @@ -121,6 +124,7 @@ public class ApplicationManagerImpl implements ApplicationManager { this.applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO(); this.lifecycleStateDAO = ApplicationManagementDAOFactory.getLifecycleStateDAO(); this.applicationReleaseDAO = ApplicationManagementDAOFactory.getApplicationReleaseDAO(); + this.subscriptionDAO = ApplicationManagementDAOFactory.getSubscriptionDAO(); } /*** @@ -1230,86 +1234,91 @@ public class ApplicationManagerImpl implements ApplicationManager { } @Override - public String deleteApplicationRelease(int applicationId, String releaseUuid) + public void deleteApplicationRelease(int applicationId, String releaseUuid) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); - String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); - ApplicationDTO application; + ApplicationStorageManager applicationStorageManager = Util.getApplicationStorageManager(); try { ConnectionManagerUtil.beginDBTransaction(); - application = this.applicationDAO.getApplicationById(applicationId, tenantId); - if (application == null) { - throw new NotFoundException("Couldn't find an application for application ID: " + applicationId); + ApplicationReleaseDTO applicationReleaseDTO = this.applicationReleaseDAO + .getReleaseByUUID(releaseUuid, tenantId); + if (applicationReleaseDTO == null) { + String msg = "Couldn't find an application release for application release UUID: " + releaseUuid; + log.error(msg); + throw new NotFoundException(msg); } - if (!isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION) && !application - .getUnrestrictedRoles().isEmpty() && hasUserRole(application.getUnrestrictedRoles(), userName)) { - throw new ForbiddenException( - "You don't have permission for deleting application release. ApplicationDTO id: " + applicationId - + " and release UUID: " + releaseUuid); - } - - ApplicationReleaseDTO applicationRelease = this.applicationReleaseDAO - .getReleaseByIds(applicationId, releaseUuid, tenantId); - if (applicationRelease == null) { - throw new NotFoundException("Couldn't find an application release for application ID: " + applicationId - + " and release UUID: " + releaseUuid); - } - LifecycleStateDTO appLifecycleState = this.lifecycleStateDAO - .getLatestLifeCycleState(applicationId, releaseUuid); - if (appLifecycleState == null) { - throw new NotFoundException( - "Couldn't find an lifecycle sate for application ID: " + applicationId + " and UUID: " - + releaseUuid); - } - String currentState = appLifecycleState.getCurrentState(); - if (AppLifecycleState.DEPRECATED.toString().equals(currentState) || AppLifecycleState.REJECTED.toString() - .equals(currentState) || AppLifecycleState.UNPUBLISHED.toString().equals(currentState)) { - LifecycleStateDTO newAppLifecycleState = getLifecycleStateInstance(AppLifecycleState.REMOVED.toString(), - appLifecycleState.getCurrentState()); - if (lifecycleStateManager.isValidStateChange(newAppLifecycleState.getPreviousState(), - newAppLifecycleState.getCurrentState(), userName, tenantId)) { - this.lifecycleStateDAO - .addLifecycleState(newAppLifecycleState, applicationId, applicationRelease.getUuid(), - tenantId); - ConnectionManagerUtil.commitDBTransaction(); - } else { - List lifecycleFlow = searchLifecycleStateFlow(currentState, - AppLifecycleState.REMOVED.toString()); - for (String nextState : lifecycleFlow) { - LifecycleStateDTO lifecycleState = getLifecycleStateInstance(nextState, currentState); - if (lifecycleStateManager.isValidStateChange(currentState, nextState, userName, tenantId)) { - this.lifecycleStateDAO - .addLifecycleState(lifecycleState, applicationId, applicationRelease.getUuid(), - tenantId); - } else { - ConnectionManagerUtil.rollbackDBTransaction(); - throw new ApplicationManagementException( - "Can't delete the application release, You have to move the " - + "lifecycle state from " + currentState + " to " + nextState); - } - currentState = nextState; - } + + if (!applicationReleaseDTO.getCurrentState().equals(lifecycleStateManager.getInitialState())) { + String msg = "Application state is not in the initial state: " + lifecycleStateManager.getInitialState() + + ". Therefore you are not permitted to delete the application release."; + log.error(msg); + throw new ForbiddenException(msg); + } + List deviceSubscriptionDTOS = subscriptionDAO + .getDeviceSubscriptions(applicationReleaseDTO.getId(), tenantId); + for (DeviceSubscriptionDTO deviceSubscriptionDTO : deviceSubscriptionDTOS) { + if (!deviceSubscriptionDTO.isUnsubscribed()) { + String msg = "This application is subscribed to device/s. Therefore you are not permitted to delete " + + "the application release."; + log.error(msg); + throw new ForbiddenException(msg); } - } else { - throw new ApplicationManagementException( - "Can't delete the application release, You have to move the " + "lifecycle state from " - + currentState + " to acceptable " + "state"); } - return applicationRelease.getAppHashValue(); + //todo delete application release data ON delete cascade + applicationStorageManager.deleteApplicationReleaseArtifacts(applicationReleaseDTO.getAppHashValue()); + + // LifecycleStateDTO appLifecycleState = this.lifecycleStateDAO +// .getLatestLifeCycleState(applicationId, releaseUuid); +// if (appLifecycleState == null) { +// throw new NotFoundException( +// "Couldn't find an lifecycle sate for application ID: " + applicationId + " and UUID: " +// + releaseUuid); +// } +// String currentState = appLifecycleState.getCurrentState(); +// if (AppLifecycleState.DEPRECATED.toString().equals(currentState) || AppLifecycleState.REJECTED.toString() +// .equals(currentState) || AppLifecycleState.UNPUBLISHED.toString().equals(currentState)) { +// LifecycleStateDTO newAppLifecycleState = getLifecycleStateInstance(AppLifecycleState.REMOVED.toString(), +// appLifecycleState.getCurrentState()); +// if (lifecycleStateManager.isValidStateChange(newAppLifecycleState.getPreviousState(), +// newAppLifecycleState.getCurrentState(), userName, tenantId)) { +// this.lifecycleStateDAO +// .addLifecycleState(newAppLifecycleState, applicationId, applicationRelease.getUuid(), +// tenantId); +// ConnectionManagerUtil.commitDBTransaction(); +// } else { +// List lifecycleFlow = searchLifecycleStateFlow(currentState, +// AppLifecycleState.REMOVED.toString()); +// for (String nextState : lifecycleFlow) { +// LifecycleStateDTO lifecycleState = getLifecycleStateInstance(nextState, currentState); +// if (lifecycleStateManager.isValidStateChange(currentState, nextState, userName, tenantId)) { +// this.lifecycleStateDAO +// .addLifecycleState(lifecycleState, applicationId, applicationRelease.getUuid(), +// tenantId); +// } else { +// ConnectionManagerUtil.rollbackDBTransaction(); +// throw new ApplicationManagementException( +// "Can't delete the application release, You have to move the " +// + "lifecycle state from " + currentState + " to " + nextState); +// } +// currentState = nextState; +// } +// } +// } else { +// throw new ApplicationManagementException( +// "Can't delete the application release, You have to move the " + "lifecycle state from " +// + currentState + " to acceptable " + "state"); +// } +// return applicationReleaseDTO.getAppHashValue(); } catch (ApplicationManagementDAOException e) { ConnectionManagerUtil.rollbackDBTransaction(); - throw new ApplicationManagementDAOException( - "Error ocured when getting application data or application release data for application id of " - + applicationId + " application release UUID of the " + releaseUuid); - } catch (LifeCycleManagementDAOException e) { + String msg = "Error ocured when getting application data or application release data for application id of " + + applicationId + " application release UUID of the " + releaseUuid; + throw new ApplicationManagementDAOException(msg, e); + } catch (ApplicationStorageManagementException e) { ConnectionManagerUtil.rollbackDBTransaction(); - throw new ApplicationManagementException( - "Error occured when deleting application release for application ID of " + applicationId - + " and application release UUID of " + releaseUuid, e); - } catch (UserStoreException e) { - throw new ApplicationManagementException( - "Error occured when checking permission for executing application release update. ApplicationDTO ID: " - + applicationId + " and ApplicationDTO UUID: " + releaseUuid); + String msg = "Error occured when deleteing the application release artifact from the file system. Application release UUID: " + releaseUuid; + log.error(msg); + throw new ApplicationManagementException(msg, e); } finally { ConnectionManagerUtil.closeDBConnection(); } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/admin/ApplicationManagementPublisherAdminAPI.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/admin/ApplicationManagementPublisherAdminAPI.java index b8b973d582..2f2979d39e 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/admin/ApplicationManagementPublisherAdminAPI.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/admin/ApplicationManagementPublisherAdminAPI.java @@ -28,33 +28,18 @@ import io.swagger.annotations.ExtensionProperty; import io.swagger.annotations.Info; import io.swagger.annotations.SwaggerDefinition; import io.swagger.annotations.Tag; -import org.apache.cxf.jaxrs.ext.multipart.Attachment; -import org.apache.cxf.jaxrs.ext.multipart.Multipart; import org.wso2.carbon.apimgt.annotations.api.Scope; import org.wso2.carbon.apimgt.annotations.api.Scopes; import org.wso2.carbon.device.application.mgt.common.ApplicationList; import org.wso2.carbon.device.application.mgt.common.ErrorResponse; -import org.wso2.carbon.device.application.mgt.common.Filter; -import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO; -import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO; -import org.wso2.carbon.device.application.mgt.common.response.ApplicationRelease; -import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationReleaseWrapper; -import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationUpdateWrapper; -import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationWrapper; -import javax.validation.Valid; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import java.util.List; /** * APIs to handle application management related tasks. @@ -92,19 +77,19 @@ public interface ApplicationManagementPublisherAdminAPI { String SCOPE = "scope"; @DELETE - @Path("/{appid}/{uuid}") + @Path("/release/{appId}/{uuid}") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @ApiOperation( consumes = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON, - httpMethod = "GET", - value = "get all applications", - notes = "This will get all applications", - tags = "ApplicationDTO Management", + httpMethod = "DELETE", + value = "Delete application release.", + notes = "This will delete application release for given UUID", + tags = "Application Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "perm:app:publisher:view") + @ExtensionProperty(name = SCOPE, value = "perm:admin:app:publisher:update") }) } ) @@ -112,11 +97,11 @@ public interface ApplicationManagementPublisherAdminAPI { value = { @ApiResponse( code = 200, - message = "OK. \n Successfully delete application releaset.", + message = "OK. \n Successfully delete application release.", response = ApplicationList.class), @ApiResponse( code = 404, - message = "Not Found. There doesn't have an application release with UUID" + + message = "Not Found. There doesn't have an application release for UUID" + "query."), @ApiResponse( code = 500, @@ -127,7 +112,7 @@ public interface ApplicationManagementPublisherAdminAPI { name = "appId", value = "application Id", required = true) - @PathParam("appid") int applicationId, + @PathParam("appId") int applicationId, @ApiParam( name = "uuid", value = "application release UUID", diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/admin/ApplicationManagementPublisherAdminAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/admin/ApplicationManagementPublisherAdminAPIImpl.java index f360f9b01b..56270db7e9 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/admin/ApplicationManagementPublisherAdminAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/admin/ApplicationManagementPublisherAdminAPIImpl.java @@ -74,16 +74,14 @@ public class ApplicationManagementPublisherAdminAPIImpl implements ApplicationMa private static Log log = LogFactory.getLog(ApplicationManagementPublisherAdminAPIImpl.class); @DELETE - @Path("/{appid}/{uuid}") + @Path("/release/{appId}/{uuid}") public Response deleteApplicationRelease( - @PathParam("appid") int applicationId, + @PathParam("appId") int applicationId, @PathParam("uuid") String releaseUuid) { ApplicationManager applicationManager = APIUtil.getApplicationManager(); - ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager(); try { - String storedLocation = applicationManager.deleteApplicationRelease(applicationId, releaseUuid); - applicationStorageManager.deleteApplicationReleaseArtifacts(storedLocation); - String responseMsg = "Successfully deleted the application release of: " + applicationId + ""; + applicationManager.deleteApplicationRelease(applicationId, releaseUuid); + String responseMsg = "Successfully deleted the application release for uuid: " + releaseUuid + ""; return Response.status(Response.Status.OK).entity(responseMsg).build(); } catch (NotFoundException e) { String msg = "Couldn't found application release which is having application id: " + applicationId @@ -100,10 +98,6 @@ public class ApplicationManagementPublisherAdminAPIImpl implements ApplicationMa String msg = "Error occurred while deleting the application: " + applicationId; log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); - } catch (ApplicationStorageManagementException e) { - String msg = "Error occurred while deleting the application storage: " + applicationId; - log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } } From 1100db4d6763712c891c4a312eac18ca631d005f Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Fri, 3 May 2019 17:01:40 +0530 Subject: [PATCH 2/6] Add lifecycle retrieving API --- .../mgt/api/services/ConfigRetrieveAPI.java | 28 ++++++ .../services/impl/ConfigRetrieveAPIImpl.java | 25 +++++ .../mgt/common/config/LifecycleGraph.java | 70 ++++++++++++++ .../common/config/LifecycleStateVertex.java | 91 +++++++++++++++++++ .../mgt/common/services/AppmDataHandler.java | 4 + .../mgt/core/impl/AppmDataHandlerImpl.java | 15 ++- .../core/lifecycle/LifecycleStateManager.java | 33 +++++++ 7 files changed, 265 insertions(+), 1 deletion(-) create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/config/LifecycleGraph.java create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/config/LifecycleStateVertex.java diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/ConfigRetrieveAPI.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/ConfigRetrieveAPI.java index 15c76d251e..f4e3130c97 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/ConfigRetrieveAPI.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/ConfigRetrieveAPI.java @@ -81,4 +81,32 @@ public interface ConfigRetrieveAPI { }) Response getUiConfig(); + @GET + @Path("/lifecycle-config") + @Produces(MediaType.APPLICATION_JSON) + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "GET", + value = "get application management UI configuration", + notes = "This will get all UI configuration of application management" + ) + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully got Lifecycle Config.", + response = ApplicationList.class), + @ApiResponse( + code = 404, + message = "Not Found. There doesn't have an defined in app management " + + "configuration file." + + "query."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Error occurred while getting the lifecycle config.", + response = ErrorResponse.class) + }) + Response getLifecycleConfig(); + } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/ConfigRetrieveAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/ConfigRetrieveAPIImpl.java index fe7c97ef64..b00ee9a9b9 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/ConfigRetrieveAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/ConfigRetrieveAPIImpl.java @@ -20,7 +20,9 @@ package org.wso2.carbon.device.application.mgt.api.services.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.application.mgt.api.services.ConfigRetrieveAPI; +import org.wso2.carbon.device.application.mgt.common.config.LifecycleStateVertex; import org.wso2.carbon.device.application.mgt.common.config.UIConfiguration; +import org.wso2.carbon.device.application.mgt.common.exception.LifecycleManagementException; import org.wso2.carbon.device.application.mgt.common.services.AppmDataHandler; import org.wso2.carbon.device.application.mgt.core.util.APIUtil; @@ -29,6 +31,9 @@ import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.Response; +import java.util.HashMap; +import java.util.List; +import java.util.Map; /** * Implementation of ApplicationDTO Management related APIs. @@ -49,4 +54,24 @@ public class ConfigRetrieveAPIImpl implements ConfigRetrieveAPI { return Response.status(Response.Status.OK).entity(uiConfiguration).build(); } + @GET + @Override + @Consumes("application/json") + @Path("/lifecycle-config") + public Response getLifecycleConfig() { + AppmDataHandler dataHandler = APIUtil.getDataHandler(); + Map> verticesObject = new HashMap<>(); + Map> vertices = null; + try { + vertices = dataHandler.getLifecycleConfiguration().getAdjVertices(); + for (LifecycleStateVertex vt : vertices.keySet()) { + verticesObject.put(vt.getLabel(), vertices.get(vt)); + } + return Response.status(Response.Status.OK).entity(verticesObject).build(); + } catch (LifecycleManagementException e) { + String msg = "Error Occurred while accessing lifecycle manager."; + log.error(msg); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } + } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/config/LifecycleGraph.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/config/LifecycleGraph.java new file mode 100644 index 0000000000..9b3116c7a7 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/config/LifecycleGraph.java @@ -0,0 +1,70 @@ +package org.wso2.carbon.device.application.mgt.common.config;/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +public class LifecycleGraph { + + private Map> adjVertices; + + public LifecycleGraph() { + this.adjVertices = new HashMap<>() ; + } + + public void addVertex(String label) { + adjVertices.putIfAbsent(new LifecycleStateVertex(label), new ArrayList<>()); + } + + public void addVertex(LifecycleStateVertex vertext) { + adjVertices.putIfAbsent(vertext, new ArrayList<>()); + } + + void removeVertex(String label) { + LifecycleStateVertex v = new LifecycleStateVertex(label); + adjVertices.values() + .stream() + .map(e -> e.remove(v)) + .collect(Collectors.toList()); + adjVertices.remove(new LifecycleStateVertex(label)); + } + + public void addEdge(String label1, String label2) { + LifecycleStateVertex v1 = new LifecycleStateVertex(label1); + LifecycleStateVertex v2 = new LifecycleStateVertex(label2); + adjVertices.get(v1).add(v2); +// adjVertices.get(v2).add(v1); + } + + public void removeEdge(String label1, String label2) { + LifecycleStateVertex v1 = new LifecycleStateVertex(label1); + LifecycleStateVertex v2 = new LifecycleStateVertex(label2); + List eV1 = adjVertices.get(v1); + List eV2 = adjVertices.get(v2); + if (eV1 != null) + eV1.remove(v2); + if (eV2 != null) + eV2.remove(v1); + } + + public Map> getAdjVertices() { + return adjVertices; + } +} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/config/LifecycleStateVertex.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/config/LifecycleStateVertex.java new file mode 100644 index 0000000000..17743db9d8 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/config/LifecycleStateVertex.java @@ -0,0 +1,91 @@ +package org.wso2.carbon.device.application.mgt.common.config;/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +public class LifecycleStateVertex { + private String label; + private boolean isAppUpdatable; + private boolean isAppInstallable; + private boolean isInitialState; + private boolean isEndState; + + public LifecycleStateVertex(String label) { + this.label = label; + } + + public String getLabel() { + return label; + } + + public boolean isAppUpdatable() { + return isAppUpdatable; + } + + public void setAppUpdatable(boolean appUpdatable) { + isAppUpdatable = appUpdatable; + } + + public boolean isAppInstallable() { + return isAppInstallable; + } + + public void setAppInstallable(boolean appInstallable) { + isAppInstallable = appInstallable; + } + + public boolean isInitialState() { + return isInitialState; + } + + public void setInitialState(boolean initialState) { + isInitialState = initialState; + } + + public boolean isEndState() { + return isEndState; + } + + public void setEndState(boolean endState) { + isEndState = endState; + } + + @Override + public int hashCode(){ + return label == null ? 0 : label.hashCode(); + } + + // Overriding equals() to compare two LifecycleStateVertex objects + @Override + public boolean equals(Object o) { + + // If the object is compared with itself then return true + if (o == this) { + return true; + } + + /* Check if o is an instance of LifecycleStateVertex or not + "null instanceof [type]" also returns false */ + if (!(o instanceof LifecycleStateVertex)) { + return false; + } + + // typecast o to Complex so that we can compare data members + LifecycleStateVertex c = (LifecycleStateVertex) o; + + // Compare the equality of label name and return accordingly + return label.equals(c.label); + } +} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/AppmDataHandler.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/AppmDataHandler.java index 508d7afa3b..f633c2e359 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/AppmDataHandler.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/AppmDataHandler.java @@ -17,8 +17,10 @@ package org.wso2.carbon.device.application.mgt.common.services; +import org.wso2.carbon.device.application.mgt.common.config.LifecycleGraph; import org.wso2.carbon.device.application.mgt.common.config.UIConfiguration; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; +import org.wso2.carbon.device.application.mgt.common.exception.LifecycleManagementException; import java.io.InputStream; @@ -30,5 +32,7 @@ public interface AppmDataHandler { */ UIConfiguration getUIConfiguration(); + LifecycleGraph getLifecycleConfiguration() throws LifecycleManagementException; + InputStream getArtifactStream(String uuid, String artifactName) throws ApplicationManagementException; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/AppmDataHandlerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/AppmDataHandlerImpl.java index 9a0aee2efe..5de4f7f134 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/AppmDataHandlerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/AppmDataHandlerImpl.java @@ -20,8 +20,10 @@ package org.wso2.carbon.device.application.mgt.core.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.application.mgt.common.config.LifecycleGraph; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException; +import org.wso2.carbon.device.application.mgt.common.exception.LifecycleManagementException; import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager; import org.wso2.carbon.device.application.mgt.common.services.AppmDataHandler; import org.wso2.carbon.device.application.mgt.common.config.UIConfiguration; @@ -30,6 +32,8 @@ import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagem 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.NotFoundException; +import org.wso2.carbon.device.application.mgt.core.internal.DataHolder; +import org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManager; import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; import org.wso2.carbon.device.application.mgt.core.util.Constants; @@ -37,12 +41,16 @@ import java.io.InputStream; public class AppmDataHandlerImpl implements AppmDataHandler { - private UIConfiguration uiConfiguration; private static final Log log = LogFactory.getLog(AppmDataHandlerImpl.class); + private UIConfiguration uiConfiguration; + private LifecycleStateManager lifecycleStateManager; + public AppmDataHandlerImpl(UIConfiguration config) { this.uiConfiguration = config; + lifecycleStateManager = DataHolder.getInstance().getLifecycleStateManager(); + } @Override @@ -50,6 +58,11 @@ public class AppmDataHandlerImpl implements AppmDataHandler { return this.uiConfiguration; } + @Override + public LifecycleGraph getLifecycleConfiguration() throws LifecycleManagementException { + return lifecycleStateManager.getLifecyccleStateGraph(); + } + @Override public InputStream getArtifactStream(String uuid, String artifactName) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/LifecycleStateManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/LifecycleStateManager.java index 03598a7f43..a33eaedab1 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/LifecycleStateManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/LifecycleStateManager.java @@ -19,6 +19,8 @@ package org.wso2.carbon.device.application.mgt.core.lifecycle; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.application.mgt.common.config.LifecycleGraph; +import org.wso2.carbon.device.application.mgt.common.config.LifecycleStateVertex; import org.wso2.carbon.device.application.mgt.common.exception.LifecycleManagementException; import org.wso2.carbon.device.application.mgt.core.internal.DataHolder; import org.wso2.carbon.device.application.mgt.core.lifecycle.config.LifecycleState; @@ -62,6 +64,37 @@ public class LifecycleStateManager { } } + public LifecycleGraph getLifecyccleStateGraph() throws LifecycleManagementException { + LifecycleGraph lifecycleGraph = new LifecycleGraph(); + Map lifecycleStatesDup = lifecycleStates; + + for (State state : lifecycleStatesDup.values()) { + Set proceedingStateNames = state.getProceedingStates(); + String stateName = state.getState(); + LifecycleStateVertex lifecycleStateVertex = new LifecycleStateVertex(stateName); + if (isInitialState(stateName)) { + lifecycleStateVertex.setInitialState(true); + } + if (isUpdatableState(stateName)) { + lifecycleStateVertex.setAppUpdatable(true); + } + if (isEndState(stateName)) { + lifecycleStateVertex.setEndState(true); + } + if (isInstallableState(stateName)) { + lifecycleStateVertex.setAppInstallable(true); + } + lifecycleGraph.addVertex(lifecycleStateVertex); + if (proceedingStateNames != null) { + proceedingStateNames.forEach(proceedingStateName -> { + lifecycleGraph.addVertex(proceedingStateName); + lifecycleGraph.addEdge(stateName, proceedingStateName); + }); + } + } + return lifecycleGraph; + } + public Set getNextLifecycleStates(String currentLifecycleState) { return lifecycleStates.get(currentLifecycleState.toUpperCase()).getProceedingStates(); From 7ef9485b7d8ee5bd5a401240f4a7db44e27f2734 Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Fri, 3 May 2019 21:05:46 +0530 Subject: [PATCH 3/6] Fix issues in lifecycle retrieving API --- .../services/impl/ConfigRetrieveAPIImpl.java | 17 +++----- .../device/application/mgt/common}/State.java | 2 +- .../mgt/common}/config/LifecycleState.java | 2 +- .../mgt/common/services/AppmDataHandler.java | 5 ++- .../mgt/core/config/Configuration.java | 2 +- .../mgt/core/impl/AppmDataHandlerImpl.java | 7 ++-- ...ApplicationManagementServiceComponent.java | 2 +- .../core/lifecycle/LifecycleStateManager.java | 39 ++++--------------- .../ConfigurationTest.java | 2 +- .../LifeCycleStateManagerTest.java | 4 +- .../LifecycleManagementTest.java | 2 +- 11 files changed, 29 insertions(+), 55 deletions(-) rename components/application-mgt/{org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle => org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common}/State.java (95%) rename components/application-mgt/{org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle => org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common}/config/LifecycleState.java (96%) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/ConfigRetrieveAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/ConfigRetrieveAPIImpl.java index b00ee9a9b9..65269f512a 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/ConfigRetrieveAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/ConfigRetrieveAPIImpl.java @@ -20,7 +20,6 @@ package org.wso2.carbon.device.application.mgt.api.services.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.application.mgt.api.services.ConfigRetrieveAPI; -import org.wso2.carbon.device.application.mgt.common.config.LifecycleStateVertex; import org.wso2.carbon.device.application.mgt.common.config.UIConfiguration; import org.wso2.carbon.device.application.mgt.common.exception.LifecycleManagementException; import org.wso2.carbon.device.application.mgt.common.services.AppmDataHandler; @@ -31,9 +30,6 @@ import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.Response; -import java.util.HashMap; -import java.util.List; -import java.util.Map; /** * Implementation of ApplicationDTO Management related APIs. @@ -51,6 +47,11 @@ public class ConfigRetrieveAPIImpl implements ConfigRetrieveAPI { public Response getUiConfig() { AppmDataHandler dataHandler = APIUtil.getDataHandler(); UIConfiguration uiConfiguration = dataHandler.getUIConfiguration(); + if (uiConfiguration == null){ + String msg = "UI configuration is not initiated."; + log.error(msg); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } return Response.status(Response.Status.OK).entity(uiConfiguration).build(); } @@ -60,14 +61,8 @@ public class ConfigRetrieveAPIImpl implements ConfigRetrieveAPI { @Path("/lifecycle-config") public Response getLifecycleConfig() { AppmDataHandler dataHandler = APIUtil.getDataHandler(); - Map> verticesObject = new HashMap<>(); - Map> vertices = null; try { - vertices = dataHandler.getLifecycleConfiguration().getAdjVertices(); - for (LifecycleStateVertex vt : vertices.keySet()) { - verticesObject.put(vt.getLabel(), vertices.get(vt)); - } - return Response.status(Response.Status.OK).entity(verticesObject).build(); + return Response.status(Response.Status.OK).entity(dataHandler.getLifecycleConfiguration()).build(); } catch (LifecycleManagementException e) { String msg = "Error Occurred while accessing lifecycle manager."; log.error(msg); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/State.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/State.java similarity index 95% rename from components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/State.java rename to components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/State.java index 17aefa5147..cec1555baf 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/State.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/State.java @@ -1,4 +1,4 @@ -package org.wso2.carbon.device.application.mgt.core.lifecycle; +package org.wso2.carbon.device.application.mgt.common; import java.util.HashSet; import java.util.List; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/config/LifecycleState.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/config/LifecycleState.java similarity index 96% rename from components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/config/LifecycleState.java rename to components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/config/LifecycleState.java index 7e97175470..298ec1c57a 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/config/LifecycleState.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/config/LifecycleState.java @@ -1,4 +1,4 @@ -package org.wso2.carbon.device.application.mgt.core.lifecycle.config; +package org.wso2.carbon.device.application.mgt.common.config; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/AppmDataHandler.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/AppmDataHandler.java index f633c2e359..7b8a49d177 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/AppmDataHandler.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/AppmDataHandler.java @@ -17,12 +17,13 @@ package org.wso2.carbon.device.application.mgt.common.services; -import org.wso2.carbon.device.application.mgt.common.config.LifecycleGraph; +import org.wso2.carbon.device.application.mgt.common.State; import org.wso2.carbon.device.application.mgt.common.config.UIConfiguration; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; import org.wso2.carbon.device.application.mgt.common.exception.LifecycleManagementException; import java.io.InputStream; +import java.util.Map; public interface AppmDataHandler { /** @@ -32,7 +33,7 @@ public interface AppmDataHandler { */ UIConfiguration getUIConfiguration(); - LifecycleGraph getLifecycleConfiguration() throws LifecycleManagementException; + Map getLifecycleConfiguration() throws LifecycleManagementException; InputStream getArtifactStream(String uuid, String artifactName) throws ApplicationManagementException; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/Configuration.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/Configuration.java index 364dd81ac4..bc4b706fed 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/Configuration.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/Configuration.java @@ -20,7 +20,7 @@ package org.wso2.carbon.device.application.mgt.core.config; import org.wso2.carbon.device.application.mgt.common.config.RatingConfiguration; import org.wso2.carbon.device.application.mgt.common.config.UIConfiguration; -import org.wso2.carbon.device.application.mgt.core.lifecycle.config.LifecycleState; +import org.wso2.carbon.device.application.mgt.common.config.LifecycleState; import java.util.List; import javax.xml.bind.annotation.XmlElement; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/AppmDataHandlerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/AppmDataHandlerImpl.java index 5de4f7f134..9ea7d644f7 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/AppmDataHandlerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/AppmDataHandlerImpl.java @@ -20,7 +20,7 @@ package org.wso2.carbon.device.application.mgt.core.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.device.application.mgt.common.config.LifecycleGraph; +import org.wso2.carbon.device.application.mgt.common.State; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException; import org.wso2.carbon.device.application.mgt.common.exception.LifecycleManagementException; @@ -38,6 +38,7 @@ import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; import org.wso2.carbon.device.application.mgt.core.util.Constants; import java.io.InputStream; +import java.util.Map; public class AppmDataHandlerImpl implements AppmDataHandler { @@ -59,8 +60,8 @@ public class AppmDataHandlerImpl implements AppmDataHandler { } @Override - public LifecycleGraph getLifecycleConfiguration() throws LifecycleManagementException { - return lifecycleStateManager.getLifecyccleStateGraph(); + public Map getLifecycleConfiguration() throws LifecycleManagementException { + return lifecycleStateManager.getLifecycleConfig(); } @Override diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/ApplicationManagementServiceComponent.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/ApplicationManagementServiceComponent.java index ecf8280eb0..15810529f9 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/ApplicationManagementServiceComponent.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/ApplicationManagementServiceComponent.java @@ -32,7 +32,7 @@ import org.wso2.carbon.device.application.mgt.common.config.UIConfiguration; import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOFactory; import org.wso2.carbon.device.application.mgt.core.impl.AppmDataHandlerImpl; import org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManager; -import org.wso2.carbon.device.application.mgt.core.lifecycle.config.LifecycleState; +import org.wso2.carbon.device.application.mgt.common.config.LifecycleState; import org.wso2.carbon.device.application.mgt.core.util.ApplicationManagementUtil; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.ndatasource.core.DataSourceService; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/LifecycleStateManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/LifecycleStateManager.java index a33eaedab1..078fce37e4 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/LifecycleStateManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/LifecycleStateManager.java @@ -19,11 +19,10 @@ package org.wso2.carbon.device.application.mgt.core.lifecycle; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.application.mgt.common.config.LifecycleGraph; -import org.wso2.carbon.device.application.mgt.common.config.LifecycleStateVertex; +import org.wso2.carbon.device.application.mgt.common.State; import org.wso2.carbon.device.application.mgt.common.exception.LifecycleManagementException; import org.wso2.carbon.device.application.mgt.core.internal.DataHolder; -import org.wso2.carbon.device.application.mgt.core.lifecycle.config.LifecycleState; +import org.wso2.carbon.device.application.mgt.common.config.LifecycleState; import org.wso2.carbon.device.mgt.common.permission.mgt.PermissionManagementException; import org.wso2.carbon.device.mgt.core.permission.mgt.PermissionUtils; import org.wso2.carbon.device.mgt.core.search.mgt.Constants; @@ -64,35 +63,13 @@ public class LifecycleStateManager { } } - public LifecycleGraph getLifecyccleStateGraph() throws LifecycleManagementException { - LifecycleGraph lifecycleGraph = new LifecycleGraph(); - Map lifecycleStatesDup = lifecycleStates; - - for (State state : lifecycleStatesDup.values()) { - Set proceedingStateNames = state.getProceedingStates(); - String stateName = state.getState(); - LifecycleStateVertex lifecycleStateVertex = new LifecycleStateVertex(stateName); - if (isInitialState(stateName)) { - lifecycleStateVertex.setInitialState(true); - } - if (isUpdatableState(stateName)) { - lifecycleStateVertex.setAppUpdatable(true); - } - if (isEndState(stateName)) { - lifecycleStateVertex.setEndState(true); - } - if (isInstallableState(stateName)) { - lifecycleStateVertex.setAppInstallable(true); - } - lifecycleGraph.addVertex(lifecycleStateVertex); - if (proceedingStateNames != null) { - proceedingStateNames.forEach(proceedingStateName -> { - lifecycleGraph.addVertex(proceedingStateName); - lifecycleGraph.addEdge(stateName, proceedingStateName); - }); - } + public Map getLifecycleConfig() throws LifecycleManagementException { + if (lifecycleStates == null){ + String msg = "Lifecycle configuration in not initialized."; + log.error(msg); + throw new LifecycleManagementException(msg); } - return lifecycleGraph; + return lifecycleStates; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/ConfigurationTest.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/ConfigurationTest.java index cd6803a1cb..8d982de616 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/ConfigurationTest.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/ConfigurationTest.java @@ -21,7 +21,7 @@ import org.junit.Assert; import org.testng.annotations.Test; import org.wso2.carbon.device.application.mgt.core.config.Configuration; import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager; -import org.wso2.carbon.device.application.mgt.core.lifecycle.config.LifecycleState; +import org.wso2.carbon.device.application.mgt.common.config.LifecycleState; import java.util.List; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/LifeCycleStateManagerTest.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/LifeCycleStateManagerTest.java index 7dbbfe3304..95069938af 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/LifeCycleStateManagerTest.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/LifeCycleStateManagerTest.java @@ -1,8 +1,8 @@ package org.wso2.carbon.device.application.mgt.core; import org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManager; -import org.wso2.carbon.device.application.mgt.core.lifecycle.State; -import org.wso2.carbon.device.application.mgt.core.lifecycle.config.LifecycleState; +import org.wso2.carbon.device.application.mgt.common.State; +import org.wso2.carbon.device.application.mgt.common.config.LifecycleState; import java.util.HashMap; import java.util.List; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/LifecycleManagementTest.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/LifecycleManagementTest.java index 4d610fe62a..496b231818 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/LifecycleManagementTest.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/LifecycleManagementTest.java @@ -7,7 +7,7 @@ import org.wso2.carbon.device.application.mgt.common.exception.LifecycleManageme import org.wso2.carbon.device.application.mgt.core.config.Configuration; import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager; import org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManager; -import org.wso2.carbon.device.application.mgt.core.lifecycle.config.LifecycleState; +import org.wso2.carbon.device.application.mgt.common.config.LifecycleState; import java.util.List; import java.util.Set; From d0f48a2c72ce719133a763c601515575f040667b Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Fri, 3 May 2019 21:10:03 +0530 Subject: [PATCH 4/6] Remove lifecycle graph classes --- .../mgt/common/config/LifecycleGraph.java | 70 -------------- .../common/config/LifecycleStateVertex.java | 91 ------------------- 2 files changed, 161 deletions(-) delete mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/config/LifecycleGraph.java delete mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/config/LifecycleStateVertex.java diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/config/LifecycleGraph.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/config/LifecycleGraph.java deleted file mode 100644 index 9b3116c7a7..0000000000 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/config/LifecycleGraph.java +++ /dev/null @@ -1,70 +0,0 @@ -package org.wso2.carbon.device.application.mgt.common.config;/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. - * - * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -public class LifecycleGraph { - - private Map> adjVertices; - - public LifecycleGraph() { - this.adjVertices = new HashMap<>() ; - } - - public void addVertex(String label) { - adjVertices.putIfAbsent(new LifecycleStateVertex(label), new ArrayList<>()); - } - - public void addVertex(LifecycleStateVertex vertext) { - adjVertices.putIfAbsent(vertext, new ArrayList<>()); - } - - void removeVertex(String label) { - LifecycleStateVertex v = new LifecycleStateVertex(label); - adjVertices.values() - .stream() - .map(e -> e.remove(v)) - .collect(Collectors.toList()); - adjVertices.remove(new LifecycleStateVertex(label)); - } - - public void addEdge(String label1, String label2) { - LifecycleStateVertex v1 = new LifecycleStateVertex(label1); - LifecycleStateVertex v2 = new LifecycleStateVertex(label2); - adjVertices.get(v1).add(v2); -// adjVertices.get(v2).add(v1); - } - - public void removeEdge(String label1, String label2) { - LifecycleStateVertex v1 = new LifecycleStateVertex(label1); - LifecycleStateVertex v2 = new LifecycleStateVertex(label2); - List eV1 = adjVertices.get(v1); - List eV2 = adjVertices.get(v2); - if (eV1 != null) - eV1.remove(v2); - if (eV2 != null) - eV2.remove(v1); - } - - public Map> getAdjVertices() { - return adjVertices; - } -} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/config/LifecycleStateVertex.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/config/LifecycleStateVertex.java deleted file mode 100644 index 17743db9d8..0000000000 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/config/LifecycleStateVertex.java +++ /dev/null @@ -1,91 +0,0 @@ -package org.wso2.carbon.device.application.mgt.common.config;/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. - * - * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -public class LifecycleStateVertex { - private String label; - private boolean isAppUpdatable; - private boolean isAppInstallable; - private boolean isInitialState; - private boolean isEndState; - - public LifecycleStateVertex(String label) { - this.label = label; - } - - public String getLabel() { - return label; - } - - public boolean isAppUpdatable() { - return isAppUpdatable; - } - - public void setAppUpdatable(boolean appUpdatable) { - isAppUpdatable = appUpdatable; - } - - public boolean isAppInstallable() { - return isAppInstallable; - } - - public void setAppInstallable(boolean appInstallable) { - isAppInstallable = appInstallable; - } - - public boolean isInitialState() { - return isInitialState; - } - - public void setInitialState(boolean initialState) { - isInitialState = initialState; - } - - public boolean isEndState() { - return isEndState; - } - - public void setEndState(boolean endState) { - isEndState = endState; - } - - @Override - public int hashCode(){ - return label == null ? 0 : label.hashCode(); - } - - // Overriding equals() to compare two LifecycleStateVertex objects - @Override - public boolean equals(Object o) { - - // If the object is compared with itself then return true - if (o == this) { - return true; - } - - /* Check if o is an instance of LifecycleStateVertex or not - "null instanceof [type]" also returns false */ - if (!(o instanceof LifecycleStateVertex)) { - return false; - } - - // typecast o to Complex so that we can compare data members - LifecycleStateVertex c = (LifecycleStateVertex) o; - - // Compare the equality of label name and return accordingly - return label.equals(c.label); - } -} From 1900d1d1efe098da305ce287703f72a4283bbc67 Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Sat, 4 May 2019 08:48:56 +0530 Subject: [PATCH 5/6] Add frontend-maven-plugin --- .gitignore | 2 + .../mgt/handler/util/HandlerConstants.java | 2 +- .../pom.xml | 92 ++++++++++++++----- .../pom.xml | 92 ++++++++++++++----- pom.xml | 3 + 5 files changed, 142 insertions(+), 49 deletions(-) diff --git a/.gitignore b/.gitignore index 206f9cee2d..5f3192e51f 100644 --- a/.gitignore +++ b/.gitignore @@ -29,7 +29,9 @@ components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/r components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/package-lock.json components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/npm-debug.log components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/dist/ +components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/tmp/ components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/node_modules/ components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/dist/ components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/package-lock.json +components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/tmp/ diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.handler/src/main/java/org/wso2/carbon/device/application/mgt/handler/util/HandlerConstants.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.handler/src/main/java/org/wso2/carbon/device/application/mgt/handler/util/HandlerConstants.java index 4ff23c4077..d8804ca834 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.handler/src/main/java/org/wso2/carbon/device/application/mgt/handler/util/HandlerConstants.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.handler/src/main/java/org/wso2/carbon/device/application/mgt/handler/util/HandlerConstants.java @@ -40,5 +40,5 @@ public class HandlerConstants { public static final String TOKEN_IS_EXPIRED = "ACCESS_TOKEN_IS_EXPIRED"; public static final int INTERNAL_ERROR_CODE = 500; - public static final long TIMEOUT = 300; + public static final long TIMEOUT = 1200; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/pom.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/pom.xml index 4f0db31d01..e20c85c95b 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/pom.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/pom.xml @@ -51,45 +51,88 @@ - org.codehaus.mojo - exec-maven-plugin - 1.5.0 + com.github.eirslett + frontend-maven-plugin + ${frontend.mave.version} + + ${npm.working.dir} + + ${npm.install.dir} + - npm install (initialize) + install node and npm + + install-node-and-npm + + generate-resources + + ${node.version} + ${npm.version} + + + + npm install - exec + npm - initialize + - react-app - ${npm.executable} - - install - --silent - + install - npm run build (compile) + prod - exec + npm - compile - react-app - ${npm.executable} - - run - ${npm.build.command} - + run-script ${npm.build.command} + generate-resources - - ${npm.working.dir} - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -111,6 +154,7 @@ npm build_prod ./react-app + ./react-app/tmp UTF-8 react-app diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/pom.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/pom.xml index 1ca50ca6d3..7aa43d7f6a 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/pom.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/pom.xml @@ -54,45 +54,88 @@ - org.codehaus.mojo - exec-maven-plugin - 1.5.0 + com.github.eirslett + frontend-maven-plugin + ${frontend.mave.version} + + ${npm.working.dir} + + ${npm.install.dir} + - npm install (initialize) + install node and npm + + install-node-and-npm + + generate-resources + + ${node.version} + ${npm.version} + + + + npm install - exec + npm - initialize + - react-app - ${npm.executable} - - install - --silent - + install - npm run build (compile) + prod - exec + npm - compile - react-app - ${npm.executable} - - run - ${npm.build.command} - + run-script ${npm.build.command} + generate-resources - - ${npm.working.dir} - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -114,6 +157,7 @@ npm build_prod ./react-app + ./react-app/tmp UTF-8 react-app diff --git a/pom.xml b/pom.xml index 502fa2c3dd..e761f5ec6d 100644 --- a/pom.xml +++ b/pom.xml @@ -2230,6 +2230,9 @@ 1.21 2.6.5 + 1.7.6 + v10.15.3 + 6.9.0 7.0.85 From 018d078e1b924394253743e1759562905456fd5d Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Mon, 6 May 2019 00:03:07 +0530 Subject: [PATCH 6/6] Improve life cycle manager --- .../mgt/api/services/ConfigRetrieveAPI.java | 29 ---- .../services/impl/ConfigRetrieveAPIImpl.java | 15 -- .../mgt/common/AppLifecycleState.java | 2 +- .../device/application/mgt/common/State.java | 51 ------- .../mgt/common/config/LifecycleState.java | 5 + .../mgt/common/dto/ApplicationDTO.java | 2 +- .../common/services/ApplicationManager.java | 11 +- .../mgt/common/services/AppmDataHandler.java | 4 +- .../mgt/core/dao/ApplicationDAO.java | 2 +- .../mgt/core/dao/ApplicationReleaseDAO.java | 4 +- .../mgt/core/dao/LifecycleStateDAO.java | 6 +- .../mgt/core/dao/SubscriptionDAO.java | 2 +- .../GenericApplicationDAOImpl.java | 6 +- .../GenericApplicationReleaseDAOImpl.java | 21 +-- .../GenericLifecycleStateDAOImpl.java | 23 ++- .../ApplicationManagementDAOException.java | 2 +- .../mgt/core/impl/ApplicationManagerImpl.java | 139 +++++++++++------- .../mgt/core/impl/AppmDataHandlerImpl.java | 4 +- .../core/impl/SubscriptionManagerImpl.java | 13 ++ .../core/lifecycle/LifecycleStateManager.java | 122 +++++++-------- .../LifeCycleStateManagerTest.java | 19 +-- .../LifecycleManagementTest.java | 22 +-- .../src/test/resources/application-mgt.xml | 37 ++--- .../ApplicationManagementPublisherAPI.java | 51 +++++-- ...pplicationManagementPublisherAdminAPI.java | 7 +- ...ApplicationManagementPublisherAPIImpl.java | 29 +++- ...cationManagementPublisherAdminAPIImpl.java | 21 ++- .../main/resources/conf/application-mgt.xml | 37 ++--- .../dbscripts/cdm/application-mgt/oracle.sql | 2 +- .../cdm/application-mgt/postgresql.sql | 2 +- 30 files changed, 335 insertions(+), 355 deletions(-) delete mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/State.java diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/ConfigRetrieveAPI.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/ConfigRetrieveAPI.java index f4e3130c97..51ea56ef63 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/ConfigRetrieveAPI.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/ConfigRetrieveAPI.java @@ -80,33 +80,4 @@ public interface ConfigRetrieveAPI { response = ErrorResponse.class) }) Response getUiConfig(); - - @GET - @Path("/lifecycle-config") - @Produces(MediaType.APPLICATION_JSON) - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - produces = MediaType.APPLICATION_JSON, - httpMethod = "GET", - value = "get application management UI configuration", - notes = "This will get all UI configuration of application management" - ) - @ApiResponses( - value = { - @ApiResponse( - code = 200, - message = "OK. \n Successfully got Lifecycle Config.", - response = ApplicationList.class), - @ApiResponse( - code = 404, - message = "Not Found. There doesn't have an defined in app management " - + "configuration file." + - "query."), - @ApiResponse( - code = 500, - message = "Internal Server Error. \n Error occurred while getting the lifecycle config.", - response = ErrorResponse.class) - }) - Response getLifecycleConfig(); - } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/ConfigRetrieveAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/ConfigRetrieveAPIImpl.java index 65269f512a..a01dba4e7c 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/ConfigRetrieveAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/ConfigRetrieveAPIImpl.java @@ -54,19 +54,4 @@ public class ConfigRetrieveAPIImpl implements ConfigRetrieveAPI { } return Response.status(Response.Status.OK).entity(uiConfiguration).build(); } - - @GET - @Override - @Consumes("application/json") - @Path("/lifecycle-config") - public Response getLifecycleConfig() { - AppmDataHandler dataHandler = APIUtil.getDataHandler(); - try { - return Response.status(Response.Status.OK).entity(dataHandler.getLifecycleConfiguration()).build(); - } catch (LifecycleManagementException e) { - String msg = "Error Occurred while accessing lifecycle manager."; - log.error(msg); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); - } - } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/AppLifecycleState.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/AppLifecycleState.java index 8c0c1cbc87..eadafefe7d 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/AppLifecycleState.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/AppLifecycleState.java @@ -23,6 +23,6 @@ package org.wso2.carbon.device.application.mgt.common; * States of the Application. */ public enum AppLifecycleState { - CREATED, IN_REVIEW, PUBLISHED, APPROVED, UNPUBLISHED, REJECTED, DEPRECATED, REMOVED + CREATED, IN_REVIEW, PUBLISHED, APPROVED, BLOCKED, REJECTED, DEPRECATED, RETIRED } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/State.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/State.java deleted file mode 100644 index cec1555baf..0000000000 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/State.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.wso2.carbon.device.application.mgt.common; - -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -/** - * This class represents the state of the lifecycle - */ -public class State { - - private Set proceedingStates; - private String stateName; - private String permission; - private boolean isAppUpdatable; - private boolean isAppInstallable; - private boolean isInitialState; - private boolean isEndState; - - public State(String stateName, List states, String permission, boolean isAppUpdatable, - boolean isAppInstallable, boolean isInitialState, boolean isEndState) { - this.stateName = stateName; - this.permission = permission; - this.isAppUpdatable=isAppUpdatable; - this.isAppInstallable=isAppInstallable; - this.isInitialState=isInitialState; - this.isEndState=isEndState; - if (states != null && !states.isEmpty()) { - proceedingStates = new HashSet<>(states); - } - } - - public String getState() { - return stateName; - } - - public Set getProceedingStates() { - return proceedingStates; - } - - public String getPermission(){ return permission;} - - public boolean isAppUpdatable(){ return isAppUpdatable;} - - public boolean isAppInstallable(){ return isAppInstallable;} - - public boolean isInitialState(){ return isInitialState;} - - public boolean isEndState(){ return isEndState;} - -} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/config/LifecycleState.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/config/LifecycleState.java index 298ec1c57a..b3459ab451 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/config/LifecycleState.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/config/LifecycleState.java @@ -19,6 +19,7 @@ public class LifecycleState { private boolean isAppUpdatable; private boolean isInitialState; private boolean isEndState; + private boolean isDeletableState; @XmlAttribute(name = "name") public String getName() { @@ -84,4 +85,8 @@ public class LifecycleState { this.isEndState = isEndState; } + @XmlElement(name = "IsDeletableState") + public boolean isDeletableState() { return isDeletableState; } + + public void setDeletableState(boolean deletableState) { isDeletableState = deletableState; } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/dto/ApplicationDTO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/dto/ApplicationDTO.java index a058e430eb..d6eceeb30c 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/dto/ApplicationDTO.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/dto/ApplicationDTO.java @@ -86,7 +86,7 @@ public class ApplicationDTO { @ApiModelProperty(name = "status", value = "Application status", required = true, - example = "REMOVED, ACTIVE") + example = "RETIRED, ACTIVE") private String status; @ApiModelProperty(name = "applicationReleaseDTOs", diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java index ad6f457be6..7b82727d70 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java @@ -69,14 +69,21 @@ public interface ApplicationManager { */ void deleteApplication(int applicationId) throws ApplicationManagementException; + /** + * Retire an application identified by the unique ID. + * + * @param applicationId ID for tha application + * @throws ApplicationManagementException ApplicationDTO Management Exception + */ + void retireApplication(int applicationId) throws ApplicationManagementException; + /** * Delete an application identified by the unique ID. * - * @param applicationId ID of tha application * @param releaseUuid UUID of tha application release * @throws ApplicationManagementException ApplicationDTO Management Exception */ - void deleteApplicationRelease(int applicationId, String releaseUuid) throws ApplicationManagementException; + void deleteApplicationRelease(String releaseUuid) throws ApplicationManagementException; /** * To get the applications based on the search filter. diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/AppmDataHandler.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/AppmDataHandler.java index 7b8a49d177..960196389a 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/AppmDataHandler.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/AppmDataHandler.java @@ -17,7 +17,7 @@ package org.wso2.carbon.device.application.mgt.common.services; -import org.wso2.carbon.device.application.mgt.common.State; +import org.wso2.carbon.device.application.mgt.common.config.LifecycleState; import org.wso2.carbon.device.application.mgt.common.config.UIConfiguration; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; import org.wso2.carbon.device.application.mgt.common.exception.LifecycleManagementException; @@ -33,7 +33,7 @@ public interface AppmDataHandler { */ UIConfiguration getUIConfiguration(); - Map getLifecycleConfiguration() throws LifecycleManagementException; + Map getLifecycleConfiguration() throws LifecycleManagementException; InputStream getArtifactStream(String uuid, String artifactName) throws ApplicationManagementException; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationDAO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationDAO.java index d43819d949..76a12d9226 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationDAO.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationDAO.java @@ -176,7 +176,7 @@ public interface ApplicationDAO { * @param appId ID of the application. * @throws ApplicationManagementDAOException ApplicationDTO Management DAO Exception. */ - void deleteApplication(int appId) throws ApplicationManagementDAOException; + void retireApplication(int appId) throws ApplicationManagementDAOException; /** * To get the application count that satisfies gives search query. diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationReleaseDAO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationReleaseDAO.java index 0bc1b13580..1793b764b1 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationReleaseDAO.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationReleaseDAO.java @@ -19,7 +19,6 @@ package org.wso2.carbon.device.application.mgt.core.dao; import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO; -import org.wso2.carbon.device.application.mgt.common.ApplicationReleaseArtifactPaths; import org.wso2.carbon.device.application.mgt.common.Rating; import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; @@ -112,10 +111,9 @@ public interface ApplicationReleaseDAO { * To delete a particular release. * * @param id ID of the ApplicationDTO which the release need to be deleted. - * @param version Version of the ApplicationDTO Release * @throws ApplicationManagementDAOException ApplicationDTO Management DAO Exception. */ - void deleteRelease(int id, String version) throws ApplicationManagementDAOException; + void deleteRelease(int id) throws ApplicationManagementDAOException; /** * To get release details of a specific application. diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/LifecycleStateDAO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/LifecycleStateDAO.java index 4c8494e9e6..df8d819b0e 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/LifecycleStateDAO.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/LifecycleStateDAO.java @@ -69,12 +69,12 @@ public interface LifecycleStateDAO { throws LifeCycleManagementDAOException; /** - * To delete a specific lifecycle state for application release. - * @param identifier Id of the LifecycleStateDTO. + * To delete lifecycle state data of specific application release. + * @param releaseId Id of the LifecycleStateDTO. * * @throws LifeCycleManagementDAOException Lifecycle Management DAO Exception. */ - void deleteLifecycleState(int identifier) throws LifeCycleManagementDAOException; + void deleteLifecycleStateByReleaseId(int releaseId) throws LifeCycleManagementDAOException; /*** * diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/SubscriptionDAO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/SubscriptionDAO.java index cd46b6a8b3..a4183eb4b3 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/SubscriptionDAO.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/SubscriptionDAO.java @@ -88,7 +88,7 @@ public interface SubscriptionDAO { void subscribeGroupToApplication(int tenantId, String subscribedBy, List groupList, int appId, int releaseId) throws ApplicationManagementDAOException; - public List getDeviceSubscriptions(int appReleaseId, int tenantId) throws + List getDeviceSubscriptions(int appReleaseId, int tenantId) throws ApplicationManagementDAOException; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java index 5565eb43b8..81bb1eaa28 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java @@ -456,7 +456,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic stmt = conn.prepareStatement(sql); stmt.setString(1, releaseUuid); stmt.setInt(2, tenantId); - stmt.setString(3, AppLifecycleState.REMOVED.toString()); + stmt.setString(3, AppLifecycleState.RETIRED.toString()); rs = stmt.executeQuery(); if (log.isDebugEnabled()) { @@ -619,14 +619,14 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic } @Override - public void deleteApplication(int appId) throws ApplicationManagementDAOException { + public void retireApplication(int appId) throws ApplicationManagementDAOException { Connection conn; PreparedStatement stmt = null; try { conn = this.getDBConnection(); String sql = "UPDATE AP_APP SET STATUS = ? WHERE ID = ? "; stmt = conn.prepareStatement(sql); - stmt.setString(1, AppLifecycleState.REMOVED.toString()); + stmt.setString(1, AppLifecycleState.RETIRED.toString()); stmt.setInt(2, appId); stmt.executeUpdate(); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/release/GenericApplicationReleaseDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/release/GenericApplicationReleaseDAOImpl.java index f7c9c634c9..bd8441a068 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/release/GenericApplicationReleaseDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/release/GenericApplicationReleaseDAOImpl.java @@ -490,30 +490,25 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements return applicationReleaseDTO; } - /** - * To delete an application release. - * - * @param id Id of the application Release. - * @param version version name of the application release. - * @throws ApplicationManagementDAOException ApplicationDTO Management DAO Exception. - */ - @Override public void deleteRelease(int id, String version) throws ApplicationManagementDAOException { + @Override + public void deleteRelease(int id) throws ApplicationManagementDAOException { Connection connection; PreparedStatement statement = null; - String sql = "DELETE FROM AP_APP_RELEASE WHERE ID = ? AND VERSION = ?"; + String sql = "DELETE " + + "FROM AP_APP_RELEASE " + + "WHERE ID = ?"; try { connection = this.getDBConnection(); statement = connection.prepareStatement(sql); statement.setInt(1, id); - statement.setString(2, version); statement.executeUpdate(); } catch (DBConnectionException e) { throw new ApplicationManagementDAOException( - "Database connection exception while trying to delete the release with version " + version, e); + "Database connection exception while trying to delete the release fore release ID: " + id, e); } catch (SQLException e) { throw new ApplicationManagementDAOException( - "SQL exception while deleting the release with version " + version + ",while executing the query " - + "sql", e); + "SQL exception while deleting the release for release ID: " + id + ",while executing the query sql" + , e); } finally { Util.cleanupResources(statement, null); } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/GenericLifecycleStateDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/GenericLifecycleStateDAOImpl.java index b3bc877e8e..0db4362fd4 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/GenericLifecycleStateDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/GenericLifecycleStateDAOImpl.java @@ -193,23 +193,22 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif } @Override - public void deleteLifecycleState(int identifier) throws LifeCycleManagementDAOException { - Connection conn = null; - PreparedStatement stmt = null; - ResultSet rs = null; + public void deleteLifecycleStateByReleaseId(int releaseId) throws LifeCycleManagementDAOException { + Connection conn; try { conn = this.getDBConnection(); - String sql = "DELETE FROM AP_APP_LIFECYCLE_STATE WHERE ID = ?"; - stmt = conn.prepareStatement(sql); - stmt.setInt(1, identifier); - stmt.executeUpdate(); - + String sql = "DELETE FROM " + + "AP_APP_LIFECYCLE_STATE " + + "WHERE AP_APP_RELEASE_ID = ?"; + try (PreparedStatement stmt = conn.prepareStatement(sql)) { + stmt.setInt(1, releaseId); + stmt.executeUpdate(); + } } catch (DBConnectionException e) { throw new LifeCycleManagementDAOException("Error occurred while obtaining the DB connection.", e); } catch (SQLException e) { - throw new LifeCycleManagementDAOException("Error occurred while deleting lifecycle: " + identifier, e); - } finally { - Util.cleanupResources(stmt, rs); + throw new LifeCycleManagementDAOException("Error occurred while deleting lifecycle for application " + + "release ID: " + releaseId, e); } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/exception/ApplicationManagementDAOException.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/exception/ApplicationManagementDAOException.java index c9059f3ea9..ccadcab072 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/exception/ApplicationManagementDAOException.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/exception/ApplicationManagementDAOException.java @@ -21,7 +21,7 @@ import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManage /** * Exception thrown during the ApplicationDTO Management DAO operations. */ -public class ApplicationManagementDAOException extends ApplicationManagementException { +public class ApplicationManagementDAOException extends Exception { public ApplicationManagementDAOException(String message, Throwable throwable) { super(message, throwable); 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 95a5a17807..f10c9b566a 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 @@ -27,7 +27,6 @@ import org.apache.commons.logging.LogFactory; import org.wso2.carbon.CarbonConstants; import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.device.application.mgt.common.AppLifecycleState; import org.wso2.carbon.device.application.mgt.common.ApplicationArtifact; import org.wso2.carbon.device.application.mgt.common.ApplicationInstaller; import org.wso2.carbon.device.application.mgt.common.Pagination; @@ -873,6 +872,10 @@ public class ApplicationManagerImpl implements ApplicationManager { String msg = "User-store exception while getting application with the application id " + appId; log.error(msg); throw new ApplicationManagementException(msg, e); + } catch (ApplicationManagementDAOException e) { + String msg = "Error occured when getting, either application tags or application categories"; + log.error(msg); + throw new ApplicationManagementException(msg); } finally { ConnectionManagerUtil.closeDBConnection(); } @@ -919,6 +922,9 @@ public class ApplicationManagerImpl implements ApplicationManager { String msg = "User-store exception while getting application with the application release UUID: " + uuid; log.error(msg); throw new ApplicationManagementException(msg, e); + } catch (ApplicationManagementDAOException e) { + //todo + throw new ApplicationManagementException(""); } finally { ConnectionManagerUtil.closeDBConnection(); } @@ -961,6 +967,9 @@ public class ApplicationManagerImpl implements ApplicationManager { } catch (UserStoreException e) { throw new ApplicationManagementException( "User-store exception while getting application with the application release UUID " + uuid); + } catch (ApplicationManagementDAOException e) { + //todo + throw new ApplicationManagementException(""); } finally { ConnectionManagerUtil.closeDBConnection(); } @@ -1057,6 +1066,9 @@ public class ApplicationManagerImpl implements ApplicationManager { } catch (UserStoreException e) { throw new ApplicationManagementException( "User-store exception while getting application with the " + "application name " + appName); + } catch (ApplicationManagementDAOException e) { + //todo + throw new ApplicationManagementException(""); } finally { ConnectionManagerUtil.closeDBConnection(); } @@ -1078,6 +1090,9 @@ public class ApplicationManagerImpl implements ApplicationManager { } catch (UserStoreException e) { throw new ApplicationManagementException( "User-store exception while getting application with the application UUID " + appReleaseUUID); + } catch (ApplicationManagementDAOException e) { + //todo + throw new ApplicationManagementException(""); } finally { ConnectionManagerUtil.closeDBConnection(); } @@ -1092,7 +1107,14 @@ public class ApplicationManagerImpl implements ApplicationManager { log.debug("Request is received to retrieve all the releases related with the application " + application .toString()); } - applicationReleases = this.applicationReleaseDAO.getReleases(application.getId(), tenantId); + //todo + applicationReleases = null; + try { + applicationReleases = this.applicationReleaseDAO.getReleases(application.getId(), tenantId); + } catch (ApplicationManagementDAOException e) { + //todo + throw new ApplicationManagementException(""); + } for (ApplicationReleaseDTO applicationRelease : applicationReleases) { LifecycleStateDTO lifecycleState = null; try { @@ -1169,7 +1191,7 @@ public class ApplicationManagerImpl implements ApplicationManager { log.error(msg); throw new ForbiddenException(msg); } - this.applicationDAO.deleteApplication(applicationId); + this.applicationDAO.retireApplication(applicationId); ConnectionManagerUtil.commitDBTransaction(); applicationStorageManager.deleteAllApplicationReleaseArtifacts(storedLocations); } catch (ApplicationManagementDAOException e) { @@ -1186,6 +1208,45 @@ public class ApplicationManagerImpl implements ApplicationManager { } } + @Override + public void retireApplication(int applicationId) throws ApplicationManagementException { + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); + ApplicationDTO applicationDTO; + if (log.isDebugEnabled()) { + log.debug("Request is received to delete applications which are related with the application id " + + applicationId); + } + try { + ConnectionManagerUtil.beginDBTransaction(); + applicationDTO = this.applicationDAO.getApplicationById(applicationId, tenantId); + + if (applicationDTO == null) { + throw new NotFoundException("Couldn't found an application for Application ID: " + applicationId); + } + List applicationReleaseDTOs = applicationDTO.getApplicationReleaseDTOs(); + List activeApplicationReleaseDTOs = new ArrayList<>(); + for (ApplicationReleaseDTO applicationReleaseDTO : applicationReleaseDTOs) { + if (!applicationReleaseDTO.getCurrentState().equals(lifecycleStateManager.getEndState())) { + activeApplicationReleaseDTOs.add(applicationReleaseDTO); + } + } + if (!activeApplicationReleaseDTOs.isEmpty()) { + String msg = "There are application releases which are not in the state " + lifecycleStateManager + .getEndState() + ". Hence you are not allowed to delete the application"; + log.error(msg); + throw new ForbiddenException(msg); + } + this.applicationDAO.retireApplication(applicationId); + ConnectionManagerUtil.commitDBTransaction(); + } catch (ApplicationManagementDAOException e) { + String msg = "Error occurred when getting application data for application id: " + applicationId; + log.error(msg); + throw new ApplicationManagementException(msg, e); + } finally { + ConnectionManagerUtil.closeDBConnection(); + } + } + private List searchLifecycleStateFlow(String start, String finish) throws ApplicationManagementException { Map nextNodeMap = new HashMap<>(); List directions = new LinkedList<>(); @@ -1201,7 +1262,7 @@ public class ApplicationManagerImpl implements ApplicationManager { if (currentNode.equals(finish)) { break; } else { - Set nextStates = lifecycleStateManager.getNextLifecycleStates(currentNode); + List nextStates = lifecycleStateManager.getNextLifecycleStates(currentNode); if (nextStates.contains(finish)) { queue = new LinkedList<>(); queue.add(finish); @@ -1234,7 +1295,7 @@ public class ApplicationManagerImpl implements ApplicationManager { } @Override - public void deleteApplicationRelease(int applicationId, String releaseUuid) + public void deleteApplicationRelease(String releaseUuid) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); ApplicationStorageManager applicationStorageManager = Util.getApplicationStorageManager(); @@ -1248,9 +1309,9 @@ public class ApplicationManagerImpl implements ApplicationManager { throw new NotFoundException(msg); } - if (!applicationReleaseDTO.getCurrentState().equals(lifecycleStateManager.getInitialState())) { - String msg = "Application state is not in the initial state: " + lifecycleStateManager.getInitialState() - + ". Therefore you are not permitted to delete the application release."; + if (!lifecycleStateManager.isDeletableState(applicationReleaseDTO.getCurrentState())) { + String msg = "Application state is not in the deletable state. Therefore you are not permitted to " + + "delete the application release."; log.error(msg); throw new ForbiddenException(msg); } @@ -1264,61 +1325,22 @@ public class ApplicationManagerImpl implements ApplicationManager { throw new ForbiddenException(msg); } } - //todo delete application release data ON delete cascade applicationStorageManager.deleteApplicationReleaseArtifacts(applicationReleaseDTO.getAppHashValue()); - - // LifecycleStateDTO appLifecycleState = this.lifecycleStateDAO -// .getLatestLifeCycleState(applicationId, releaseUuid); -// if (appLifecycleState == null) { -// throw new NotFoundException( -// "Couldn't find an lifecycle sate for application ID: " + applicationId + " and UUID: " -// + releaseUuid); -// } -// String currentState = appLifecycleState.getCurrentState(); -// if (AppLifecycleState.DEPRECATED.toString().equals(currentState) || AppLifecycleState.REJECTED.toString() -// .equals(currentState) || AppLifecycleState.UNPUBLISHED.toString().equals(currentState)) { -// LifecycleStateDTO newAppLifecycleState = getLifecycleStateInstance(AppLifecycleState.REMOVED.toString(), -// appLifecycleState.getCurrentState()); -// if (lifecycleStateManager.isValidStateChange(newAppLifecycleState.getPreviousState(), -// newAppLifecycleState.getCurrentState(), userName, tenantId)) { -// this.lifecycleStateDAO -// .addLifecycleState(newAppLifecycleState, applicationId, applicationRelease.getUuid(), -// tenantId); -// ConnectionManagerUtil.commitDBTransaction(); -// } else { -// List lifecycleFlow = searchLifecycleStateFlow(currentState, -// AppLifecycleState.REMOVED.toString()); -// for (String nextState : lifecycleFlow) { -// LifecycleStateDTO lifecycleState = getLifecycleStateInstance(nextState, currentState); -// if (lifecycleStateManager.isValidStateChange(currentState, nextState, userName, tenantId)) { -// this.lifecycleStateDAO -// .addLifecycleState(lifecycleState, applicationId, applicationRelease.getUuid(), -// tenantId); -// } else { -// ConnectionManagerUtil.rollbackDBTransaction(); -// throw new ApplicationManagementException( -// "Can't delete the application release, You have to move the " -// + "lifecycle state from " + currentState + " to " + nextState); -// } -// currentState = nextState; -// } -// } -// } else { -// throw new ApplicationManagementException( -// "Can't delete the application release, You have to move the " + "lifecycle state from " -// + currentState + " to acceptable " + "state"); -// } -// return applicationReleaseDTO.getAppHashValue(); + lifecycleStateDAO.deleteLifecycleStateByReleaseId(applicationReleaseDTO.getId()); + applicationReleaseDAO.deleteRelease(applicationReleaseDTO.getId()); } catch (ApplicationManagementDAOException e) { ConnectionManagerUtil.rollbackDBTransaction(); - String msg = "Error ocured when getting application data or application release data for application id of " - + applicationId + " application release UUID of the " + releaseUuid; - throw new ApplicationManagementDAOException(msg, e); + String msg = "Error occurred when application release data for application release UUID: " + releaseUuid; + throw new ApplicationManagementException(msg, e); } catch (ApplicationStorageManagementException e) { - ConnectionManagerUtil.rollbackDBTransaction(); - String msg = "Error occured when deleteing the application release artifact from the file system. Application release UUID: " + releaseUuid; + String msg = "Error occurred when deleting the application release artifact from the file system. " + + "Application release UUID: " + releaseUuid; log.error(msg); throw new ApplicationManagementException(msg, e); + } catch (LifeCycleManagementDAOException e) { + ConnectionManagerUtil.rollbackDBTransaction(); + String msg = "Error occurred when dleting lifecycle data for application release UUID: " + releaseUuid; + throw new ApplicationManagementException(msg, e); } finally { ConnectionManagerUtil.closeDBConnection(); } @@ -1596,6 +1618,9 @@ public class ApplicationManagerImpl implements ApplicationManager { throw new ApplicationManagementException( "Failed to add lifecycle state. ApplicationDTO Id: " + applicationId + " ApplicationDTO release UUID: " + releaseUuid, e); + } catch (ApplicationManagementDAOException e) { + //todo + throw new ApplicationManagementException(""); } finally { ConnectionManagerUtil.closeDBConnection(); } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/AppmDataHandlerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/AppmDataHandlerImpl.java index 9ea7d644f7..71570221af 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/AppmDataHandlerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/AppmDataHandlerImpl.java @@ -20,7 +20,7 @@ package org.wso2.carbon.device.application.mgt.core.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.device.application.mgt.common.State; +import org.wso2.carbon.device.application.mgt.common.config.LifecycleState; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException; import org.wso2.carbon.device.application.mgt.common.exception.LifecycleManagementException; @@ -60,7 +60,7 @@ public class AppmDataHandlerImpl implements AppmDataHandler { } @Override - public Map getLifecycleConfiguration() throws LifecycleManagementException { + public Map getLifecycleConfiguration() throws LifecycleManagementException { return lifecycleStateManager.getLifecycleConfig(); } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java index cc228f9d1f..355fb24193 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java @@ -28,6 +28,7 @@ import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager; import org.wso2.carbon.device.application.mgt.core.dao.SubscriptionDAO; import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOFactory; +import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; import org.wso2.carbon.device.application.mgt.core.internal.DataHolder; import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; import org.wso2.carbon.device.application.mgt.core.util.HelperUtil; @@ -109,6 +110,9 @@ public class SubscriptionManagerImpl implements SubscriptionManager { ConnectionManagerUtil.openDBConnection(); subscriptionDAO.subscribeUserToApplication(tenantId, subscriber, userList, application.getId(), applicationReleaseId); + } catch (ApplicationManagementDAOException e) { + //todo + throw new ApplicationManagementException(""); } finally { ConnectionManagerUtil.closeDBConnection(); } @@ -150,6 +154,9 @@ public class SubscriptionManagerImpl implements SubscriptionManager { ConnectionManagerUtil.openDBConnection(); subscriptionDAO.subscribeRoleToApplication(tenantId, subscriber, roleList, application.getId(), applicationReleaseId); + } catch (ApplicationManagementDAOException e) { + //todo + throw new ApplicationManagementException(""); } finally { ConnectionManagerUtil.closeDBConnection(); } @@ -194,6 +201,9 @@ public class SubscriptionManagerImpl implements SubscriptionManager { ConnectionManagerUtil.openDBConnection(); subscriptionDAO.subscribeGroupToApplication(tenantId, subscriber, groupList, application.getId(), applicationReleaseId); + } catch (ApplicationManagementDAOException e) { + //todo + throw new ApplicationManagementException(""); } finally { ConnectionManagerUtil.closeDBConnection(); } @@ -252,6 +262,9 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } subscriptionDAO.subscribeDeviceToApplication(tenantId, subscriber, deviceList, application.getId(), applicationReleaseId, String.valueOf(AppOperation.InstallState.UNINSTALLED)); + } catch (ApplicationManagementDAOException e) { + //todo + throw new ApplicationManagementException(""); } finally { ConnectionManagerUtil.closeDBConnection(); } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/LifecycleStateManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/LifecycleStateManager.java index 078fce37e4..0a5d0cb1b6 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/LifecycleStateManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/LifecycleStateManager.java @@ -19,7 +19,6 @@ package org.wso2.carbon.device.application.mgt.core.lifecycle; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.application.mgt.common.State; import org.wso2.carbon.device.application.mgt.common.exception.LifecycleManagementException; import org.wso2.carbon.device.application.mgt.core.internal.DataHolder; import org.wso2.carbon.device.application.mgt.common.config.LifecycleState; @@ -33,38 +32,36 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Set; /** * This class represents the activities related to lifecycle management */ public class LifecycleStateManager { - private Map lifecycleStates; + private Map lifecycleStates; private static Log log = LogFactory.getLog(LifecycleStateManager.class); public void init(List states) throws LifecycleManagementException { lifecycleStates = new HashMap<>(); - for (LifecycleState s : states) { - if (s.getProceedingStates() != null) { - s.getProceedingStates().replaceAll(String::toUpperCase); + for (LifecycleState lifecycleState : states) { + if (lifecycleState.getProceedingStates() != null) { + lifecycleState.getProceedingStates().replaceAll(String::toUpperCase); } - lifecycleStates.put(s.getName().toUpperCase(), new State(s.getName().toUpperCase(), - s.getProceedingStates(), s.getPermission(), s.isAppUpdatable(), s.isAppInstallable(), - s.isInitialState(), s.isEndState())); + lifecycleStates.put(lifecycleState.getName(), lifecycleState); try { - PermissionUtils.putPermission(s.getPermission()); + PermissionUtils.putPermission(lifecycleState.getPermission()); } catch (PermissionManagementException e) { - String msg = "Error when adding permission " + s.getPermission() + " related to the state: " - + s.getName(); + String msg = + "Error when adding permission " + lifecycleState.getPermission() + " related to the state: " + + lifecycleState.getName(); log.error(msg, e); throw new LifecycleManagementException(msg, e); } } } - public Map getLifecycleConfig() throws LifecycleManagementException { - if (lifecycleStates == null){ + public Map getLifecycleConfig() throws LifecycleManagementException { + if (lifecycleStates == null) { String msg = "Lifecycle configuration in not initialized."; log.error(msg); throw new LifecycleManagementException(msg); @@ -72,29 +69,27 @@ public class LifecycleStateManager { return lifecycleStates; } - - public Set getNextLifecycleStates(String currentLifecycleState) { + public List getNextLifecycleStates(String currentLifecycleState) { return lifecycleStates.get(currentLifecycleState.toUpperCase()).getProceedingStates(); } - public boolean isValidStateChange(String currentState, String nextState, String username, int tenantId) throws - LifecycleManagementException { - + public boolean isValidStateChange(String currentState, String nextState, String username, int tenantId) + throws LifecycleManagementException { UserRealm userRealm; String permission = getPermissionForStateChange(nextState); if (permission != null) { try { userRealm = DataHolder.getInstance().getRealmService().getTenantUserRealm(tenantId); - if (userRealm != null && userRealm.getAuthorizationManager() != null && - userRealm.getAuthorizationManager().isUserAuthorized(username, - PermissionUtils.getAbsolutePermissionPath(permission), + if (userRealm != null && userRealm.getAuthorizationManager() != null && userRealm + .getAuthorizationManager() + .isUserAuthorized(username, PermissionUtils.getAbsolutePermissionPath(permission), Constants.UI_EXECUTE)) { if (currentState.equalsIgnoreCase(nextState)) { return true; } - State state = getMatchingState(currentState); - if (state != null) { - return getMatchingNextState(state.getProceedingStates(), nextState); + LifecycleState matchingState = getMatchingState(currentState); + if (matchingState != null) { + return getMatchingNextState(matchingState.getProceedingStates(), nextState); } return false; } @@ -105,24 +100,22 @@ public class LifecycleStateManager { + nextState + " with username : " + username + " and tenant Id : " + tenantId, e); } } else { - throw new LifecycleManagementException( - "Required permissions cannot be found for the state : " + nextState); + throw new LifecycleManagementException("Required permissions cannot be found for the state : " + nextState); } } - private State getMatchingState(String currentState) { - for (Map.Entry stringStateEntry : lifecycleStates.entrySet()) { - if (stringStateEntry.getKey().equalsIgnoreCase(currentState)) { - return lifecycleStates.get(stringStateEntry.getKey()); + private LifecycleState getMatchingState(String currentState) { + for (Map.Entry lifecycyleState : lifecycleStates.entrySet()) { + if (lifecycyleState.getKey().equalsIgnoreCase(currentState)) { + return lifecycyleState.getValue(); } } return null; } - - private boolean getMatchingNextState(Set proceedingStates, String nextState) { - for (String state : proceedingStates) { - if (state.equalsIgnoreCase(nextState)) { + private boolean getMatchingNextState(List proceedingStates, String nextState) { + for (String stateName : proceedingStates) { + if (stateName.equalsIgnoreCase(nextState)) { return true; } } @@ -131,7 +124,7 @@ public class LifecycleStateManager { private String getPermissionForStateChange(String nextState) { Iterator it = lifecycleStates.entrySet().iterator(); - State nextLifecycleState; + LifecycleState nextLifecycleState; while (it.hasNext()) { Map.Entry pair = (Map.Entry) it.next(); if (pair.getKey().toString().equalsIgnoreCase(nextState)) { @@ -143,8 +136,19 @@ public class LifecycleStateManager { return null; } + public boolean isDeletableState(String state) throws LifecycleManagementException { + LifecycleState currentState = getMatchingState(state); + if (currentState != null) { + return currentState.isDeletableState(); + } else { + String msg = "Couldn't find a lifecycle state that matches with " + state + " state."; + log.error(msg); + throw new LifecycleManagementException(msg); + } + } + public boolean isUpdatableState(String state) throws LifecycleManagementException { - State currentState = getMatchingState(state); + LifecycleState currentState = getMatchingState(state); if (currentState != null) { return currentState.isAppUpdatable(); } else { @@ -155,7 +159,7 @@ public class LifecycleStateManager { } public boolean isInstallableState(String state) throws LifecycleManagementException { - State currentState = getMatchingState(state); + LifecycleState currentState = getMatchingState(state); if (currentState != null) { return currentState.isAppInstallable(); } else { @@ -166,7 +170,7 @@ public class LifecycleStateManager { } public boolean isInitialState(String state) throws LifecycleManagementException { - State currentState = getMatchingState(state); + LifecycleState currentState = getMatchingState(state); if (currentState != null) { return currentState.isInitialState(); } else { @@ -177,7 +181,7 @@ public class LifecycleStateManager { } public boolean isEndState(String state) throws LifecycleManagementException { - State currentState = getMatchingState(state); + LifecycleState currentState = getMatchingState(state); if (currentState != null) { return currentState.isEndState(); } else { @@ -188,58 +192,55 @@ public class LifecycleStateManager { } public String getInitialState() throws LifecycleManagementException { - String initialState = null; - for (Map.Entry stringStateEntry : lifecycleStates.entrySet()) { - if (stringStateEntry.getValue().isInitialState()) { - initialState = stringStateEntry.getKey(); - break; + String initialState; + for (Map.Entry lifecycleState : lifecycleStates.entrySet()) { + if (lifecycleState.getValue().isInitialState()) { + initialState = lifecycleState.getKey(); + return initialState; } } - if (initialState == null){ - String msg = "Haven't defined the initial state in the application-manager.xml. Please add initial state " - + "to the section in the app-manager.xml"; - log.error(msg); - throw new LifecycleManagementException(msg); - } - return initialState; + String msg = "Haven't defined the initial state in the application-manager.xml. Please add initial state " + + "to the section in the app-manager.xml"; + log.error(msg); + throw new LifecycleManagementException(msg); } public String getEndState() throws LifecycleManagementException { String endState = null; - for (Map.Entry stringStateEntry : lifecycleStates.entrySet()) { + for (Map.Entry stringStateEntry : lifecycleStates.entrySet()) { if (stringStateEntry.getValue().isEndState()) { endState = stringStateEntry.getKey(); break; } } - if (endState == null){ + if (endState == null) { String msg = "Haven't defined the end state in the application-manager.xml. Please add end state " + "to the section in the app-manager.xml"; log.error(msg); - throw new LifecycleManagementException(msg); + throw new LifecycleManagementException(msg); } return endState; } public String getInstallableState() throws LifecycleManagementException { String installableState = null; - for (Map.Entry stringStateEntry : lifecycleStates.entrySet()) { + for (Map.Entry stringStateEntry : lifecycleStates.entrySet()) { if (stringStateEntry.getValue().isAppInstallable()) { installableState = stringStateEntry.getKey(); break; } } - if (installableState == null){ + if (installableState == null) { String msg = "Haven't defined the installable state in the application-manager.xml. Please add installable " + "state to the section in the app-manager.xml"; log.error(msg); - throw new LifecycleManagementException(msg); + throw new LifecycleManagementException(msg); } return installableState; } public boolean isStateExist(String currentState) { - for (Map.Entry stringStateEntry : lifecycleStates.entrySet()) { + for (Map.Entry stringStateEntry : lifecycleStates.entrySet()) { if (stringStateEntry.getKey().equalsIgnoreCase(currentState)) { return true; } @@ -247,8 +248,7 @@ public class LifecycleStateManager { return false; } - - public void setLifecycleStates(Map lifecycleStates) { + public void setLifecycleStates(Map lifecycleStates) { this.lifecycleStates = lifecycleStates; } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/LifeCycleStateManagerTest.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/LifeCycleStateManagerTest.java index 95069938af..1c0132f251 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/LifeCycleStateManagerTest.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/LifeCycleStateManagerTest.java @@ -1,25 +1,22 @@ package org.wso2.carbon.device.application.mgt.core; import org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManager; -import org.wso2.carbon.device.application.mgt.common.State; import org.wso2.carbon.device.application.mgt.common.config.LifecycleState; import java.util.HashMap; import java.util.List; -public class LifeCycleStateManagerTest extends LifecycleStateManager { +class LifeCycleStateManagerTest extends LifecycleStateManager { - public void initializeLifeCycleDetails(List states) { - HashMap lifecycleStates = new HashMap<>(); - for (LifecycleState s : states) { - if (s.getProceedingStates() != null) { - s.getProceedingStates().replaceAll(String::toUpperCase); + void initializeLifeCycleDetails(List lifecycleStates) { + HashMap lifecycleStatesMap = new HashMap<>(); + for (LifecycleState lifecycleState : lifecycleStates) { + if (lifecycleState.getProceedingStates() != null) { + lifecycleState.getProceedingStates().replaceAll(String::toUpperCase); } - lifecycleStates.put(s.getName().toUpperCase(), new State(s.getName().toUpperCase(), - s.getProceedingStates(), s.getPermission(), s.isAppUpdatable(), s.isAppInstallable(), - s.isInitialState(), s.isEndState())); + lifecycleStatesMap.put(lifecycleState.getName().toUpperCase(), lifecycleState); } - setLifecycleStates(lifecycleStates); + setLifecycleStates(lifecycleStatesMap); } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/LifecycleManagementTest.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/LifecycleManagementTest.java index 496b231818..a938d9537e 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/LifecycleManagementTest.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/LifecycleManagementTest.java @@ -10,7 +10,6 @@ import org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManag import org.wso2.carbon.device.application.mgt.common.config.LifecycleState; import java.util.List; -import java.util.Set; public class LifecycleManagementTest { @@ -19,17 +18,16 @@ public class LifecycleManagementTest { private final String CURRENT_STATE = "Approved"; private final String NEXT_STATE = "Published"; - private final String BOGUS_STATE = "Removed"; + private final String BOGUS_STATE = "Retired"; private final String UPDATABLE_STATE = "Created"; - private final String NON_UPDATABLE_STATE = "Removed"; + private final String NON_UPDATABLE_STATE = "Retired"; private final String INSTALLABLE_STATE = "Published"; - private final String UNINSTALlABLE_STATE = "Removed"; private final String INITIAL_STATE = "Created"; - private final String END_STATE = "Removed"; + private final String END_STATE = "Retired"; @BeforeClass - public void init() throws LifecycleManagementException { + public void init() { ConfigurationManager configurationManager = ConfigurationManager.getInstance(); Configuration configuration = configurationManager.getConfiguration(); lifecycleStates = configuration.getLifecycleStates(); @@ -39,14 +37,14 @@ public class LifecycleManagementTest { @Test public void checkValidNextLifecycleState() { - Set proceedingStates = lifecycleStateManager.getNextLifecycleStates(CURRENT_STATE); + List proceedingStates = lifecycleStateManager.getNextLifecycleStates(CURRENT_STATE); Assert.assertTrue("Invalid proceeding state of: " + CURRENT_STATE, proceedingStates.contains(NEXT_STATE.toUpperCase())); } @Test public void checkInvalidNextLifecycleState() { - Set proceedingStates = lifecycleStateManager.getNextLifecycleStates(CURRENT_STATE); + List proceedingStates = lifecycleStateManager.getNextLifecycleStates(CURRENT_STATE); Assert.assertFalse("Invalid proceeding state of: " + CURRENT_STATE, proceedingStates.contains(BOGUS_STATE.toUpperCase())); } @@ -70,12 +68,6 @@ public class LifecycleManagementTest { Assert.assertTrue("Installable state: " + INSTALLABLE_STATE, isInstallable); } - @Test - public void CheckUnInstallableState() throws LifecycleManagementException { - boolean isInstallable = lifecycleStateManager.isInstallableState(UNINSTALlABLE_STATE); - Assert.assertFalse("UnInstallable state: " + UNINSTALlABLE_STATE, isInstallable); - } - @Test public void CheckGetInitialState() throws LifecycleManagementException { boolean isInitialState = lifecycleStateManager.getInitialState().equalsIgnoreCase(INITIAL_STATE); @@ -126,7 +118,7 @@ public class LifecycleManagementTest { @Test public void check() { - Set proceedingStates = lifecycleStateManager.getNextLifecycleStates(CURRENT_STATE); + List proceedingStates = lifecycleStateManager.getNextLifecycleStates(CURRENT_STATE); Assert.assertFalse("Invalid proceeding state of: " + CURRENT_STATE, proceedingStates.contains(BOGUS_STATE.toUpperCase())); } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/resources/application-mgt.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/resources/application-mgt.xml index be9209ee92..5af3ccc567 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/resources/application-mgt.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/resources/application-mgt.xml @@ -76,58 +76,59 @@ true true - /device-mgt/applications/life-cycle/create + true + /app-mgt/life-cycle/application/create In-Review - /device-mgt/applications/life-cycle/in-review + /app-mgt/life-cycle/application/review Rejected Approved + Created - /device-mgt/applications/life-cycle/approve + /app-mgt/life-cycle/application/approve + In-Review Published - Created - /device-mgt/applications/life-cycle/reject + true + /app-mgt/life-cycle/application/reject - Created - Removed + In-Review true - /device-mgt/applications/life-cycle/publish + /app-mgt/life-cycle/application/publish - Unpublished + Blocked Deprecated - - /device-mgt/applications/life-cycle/unpublish + + /app-mgt/life-cycle/application/block Published - In-Review - Removed + Deprecated - /device-mgt/applications/life-cycle/deprecate + /app-mgt/life-cycle/application/deprecate - Removed - In-Review + Published + Retired - + true - /device-mgt/applications/life-cycle/remove + /app-mgt/life-cycle/application/retire diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementPublisherAPI.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementPublisherAPI.java index 47f2f64c1a..3d3d0fa08d 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementPublisherAPI.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementPublisherAPI.java @@ -45,7 +45,6 @@ import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationWrapper; import java.util.List; import javax.validation.Valid; import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.PUT; @@ -416,15 +415,15 @@ public interface ApplicationManagementPublisherAPI { @Multipart(value = "screenshot3") Attachment screenshot3 ); - @DELETE + @PUT @Consumes("application/json") - @Path("/{appId}") + @Path("/retire/{appId}") @ApiOperation( consumes = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON, - httpMethod = "DELETE", - value = "Delete the application with the given UUID", - notes = "This will delete the application with the given UUID", + httpMethod = "PUT", + value = "Retire the application with the given UUID", + notes = "This will retire the application with the given UUID", tags = "ApplicationDTO Management", extensions = { @Extension(properties = { @@ -449,8 +448,7 @@ public interface ApplicationManagementPublisherAPI { code = 404, message = "Application not found"), }) - //todo add new scope and permission - Response deleteApplication( + Response retireApplication( @ApiParam( name = "UUID", value = "Unique identifier of the ApplicationDTO", @@ -592,7 +590,7 @@ public interface ApplicationManagementPublisherAPI { httpMethod = "PUT", value = "Update an application release", notes = "This will update a new application release", - tags = "ApplicationDTO Management", + tags = "Application Management", extensions = { @Extension(properties = { @ExtensionProperty(name = SCOPE, value = "perm:app:publisher:update") @@ -750,4 +748,39 @@ public interface ApplicationManagementPublisherAPI { required = true) @QueryParam("action") String action ); + + @GET + @Path("/lifecycle-config") + @Produces(MediaType.APPLICATION_JSON) + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "GET", + value = "get application management UI configuration", + notes = "This will get all UI configuration of application management", + tags = "Application Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = SCOPE, value = "perm:app:publisher:update") + }) + } + ) + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully got Lifecycle Config.", + response = ApplicationList.class), + @ApiResponse( + code = 404, + message = "Not Found. There doesn't have an defined in app management " + + "configuration file." + + "query."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Error occurred while getting the lifecycle config.", + response = ErrorResponse.class) + }) + Response getLifecycleConfig(); + } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/admin/ApplicationManagementPublisherAdminAPI.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/admin/ApplicationManagementPublisherAdminAPI.java index 2f2979d39e..16ad79e848 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/admin/ApplicationManagementPublisherAdminAPI.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/admin/ApplicationManagementPublisherAdminAPI.java @@ -77,7 +77,7 @@ public interface ApplicationManagementPublisherAdminAPI { String SCOPE = "scope"; @DELETE - @Path("/release/{appId}/{uuid}") + @Path("/release/{uuid}") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @ApiOperation( @@ -108,11 +108,6 @@ public interface ApplicationManagementPublisherAdminAPI { message = "Internal Server Error. \n Error occurred while deleting application release.", response = ErrorResponse.class) }) Response deleteApplicationRelease( - @ApiParam( - name = "appId", - value = "application Id", - required = true) - @PathParam("appId") int applicationId, @ApiParam( name = "uuid", value = "application release UUID", diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementPublisherAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementPublisherAPIImpl.java index a38e0880ba..15f7568e84 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementPublisherAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementPublisherAPIImpl.java @@ -24,10 +24,11 @@ import org.apache.cxf.jaxrs.ext.multipart.Attachment; import org.apache.cxf.jaxrs.ext.multipart.Multipart; import org.wso2.carbon.device.application.mgt.common.*; import org.wso2.carbon.device.application.mgt.common.dto.LifecycleStateDTO; -import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException; +import org.wso2.carbon.device.application.mgt.common.exception.LifecycleManagementException; import org.wso2.carbon.device.application.mgt.common.exception.RequestValidatingException; import org.wso2.carbon.device.application.mgt.common.response.Application; import org.wso2.carbon.device.application.mgt.common.response.ApplicationRelease; +import org.wso2.carbon.device.application.mgt.common.services.AppmDataHandler; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationReleaseWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationUpdateWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationWrapper; @@ -37,7 +38,6 @@ import org.wso2.carbon.device.application.mgt.core.util.APIUtil; import org.wso2.carbon.device.application.mgt.publisher.api.services.ApplicationManagementPublisherAPI; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; 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.core.exception.NotFoundException; import java.io.IOException; @@ -49,7 +49,6 @@ import java.util.Map; import javax.activation.DataHandler; import javax.validation.Valid; import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.PUT; @@ -433,12 +432,13 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem } - @DELETE - @Path("/{appId}") - public Response deleteApplication(@PathParam("appId") int applicationId) { + @PUT + @Path("/retire/{appId}") + public Response retireApplication( + @PathParam("appId") int applicationId) { ApplicationManager applicationManager = APIUtil.getApplicationManager(); try { - applicationManager.deleteApplication(applicationId); + applicationManager.retireApplication(applicationId); return Response.status(Response.Status.OK) .entity("Successfully deleted the application for application ID: " + applicationId).build(); } catch (NotFoundException e) { @@ -513,6 +513,21 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem return Response.status(Response.Status.CREATED).entity("Lifecycle state added successfully.").build(); } + @GET + @Override + @Consumes("application/json") + @Path("/lifecycle-config") + public Response getLifecycleConfig() { + AppmDataHandler dataHandler = APIUtil.getDataHandler(); + try { + return Response.status(Response.Status.OK).entity(dataHandler.getLifecycleConfiguration()).build(); + } catch (LifecycleManagementException e) { + String msg = "Error Occurred while accessing lifecycle manager."; + log.error(msg); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } + } + /*** * * @param binaryFile binary file of the application release diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/admin/ApplicationManagementPublisherAdminAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/admin/ApplicationManagementPublisherAdminAPIImpl.java index 56270db7e9..2416f6a61f 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/admin/ApplicationManagementPublisherAdminAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/admin/ApplicationManagementPublisherAdminAPIImpl.java @@ -74,28 +74,27 @@ public class ApplicationManagementPublisherAdminAPIImpl implements ApplicationMa private static Log log = LogFactory.getLog(ApplicationManagementPublisherAdminAPIImpl.class); @DELETE - @Path("/release/{appId}/{uuid}") + @Path("/release/{uuid}") public Response deleteApplicationRelease( - @PathParam("appId") int applicationId, @PathParam("uuid") String releaseUuid) { ApplicationManager applicationManager = APIUtil.getApplicationManager(); try { - applicationManager.deleteApplicationRelease(applicationId, releaseUuid); + applicationManager.deleteApplicationRelease(releaseUuid); String responseMsg = "Successfully deleted the application release for uuid: " + releaseUuid + ""; return Response.status(Response.Status.OK).entity(responseMsg).build(); - } catch (NotFoundException e) { - String msg = "Couldn't found application release which is having application id: " + applicationId - + " and application release UUID:" + releaseUuid; + } catch (NotFoundException e) { + String msg = + "Couldn't found application release which is having application release UUID:" + releaseUuid; log.error(msg, e); return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); } catch (ForbiddenException e) { - String msg = - "You don't have require permission to delete the application release which has UUID " + releaseUuid - + " and application ID " + applicationId; + String msg = "You don't have require permission to delete the application release which has UUID " + + releaseUuid; log.error(msg, e); return Response.status(Response.Status.FORBIDDEN).entity(msg).build(); - }catch (ApplicationManagementException e) { - String msg = "Error occurred while deleting the application: " + applicationId; + } catch (ApplicationManagementException e) { + String msg = "Error occurred while deleting the application release for application release UUID:: " + + releaseUuid; log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml index b20305e30b..2d6dc36c31 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml @@ -76,58 +76,59 @@ true true - /device-mgt/applications/life-cycle/create + true + /app-mgt/life-cycle/application/create In-Review - /device-mgt/applications/life-cycle/in-review + /app-mgt/life-cycle/application/review Rejected Approved + Created - /device-mgt/applications/life-cycle/approve + /app-mgt/life-cycle/application/approve + In-Review Published - Created - /device-mgt/applications/life-cycle/reject + true + /app-mgt/life-cycle/application/reject - Created - Removed + In-Review true - /device-mgt/applications/life-cycle/publish + /app-mgt/life-cycle/application/publish - Unpublished + Blocked Deprecated - - /device-mgt/applications/life-cycle/unpublish + + /app-mgt/life-cycle/application/block Published - In-Review - Removed + Deprecated - /device-mgt/applications/life-cycle/deprecate + /app-mgt/life-cycle/application/deprecate - Removed - In-Review + Published + Retired - + true - /device-mgt/applications/life-cycle/remove + /app-mgt/life-cycle/application/retire diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/oracle.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/oracle.sql index b1b0e88842..39f8aba3d9 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/oracle.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/oracle.sql @@ -157,7 +157,7 @@ VALUES ('PUBLISHED', 'PUBLISHED', 'State in which Application is in published st / INSERT INTO APPM_LIFECYCLE_STATE (NAME, IDENTIFIER, DESCRIPTION) -VALUES ('UNPUBLISHED', 'UNPUBLISHED', 'State in which Application is in un published state.') +VALUES ('BLOCKED', 'BLOCKED', 'State in which Application is in un published state.') / INSERT INTO APPM_LIFECYCLE_STATE (NAME, IDENTIFIER, DESCRIPTION) diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/postgresql.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/postgresql.sql index 5937f68d08..cfe8495940 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/postgresql.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/postgresql.sql @@ -87,7 +87,7 @@ VALUES ('REJECTED', 'REJECTED', 'State in which Application is rejected after re INSERT INTO APPM_LIFECYCLE_STATE (NAME, IDENTIFIER, DESCRIPTION) VALUES ('PUBLISHED', 'PUBLISHED', 'State in which Application is in published state.'); INSERT INTO APPM_LIFECYCLE_STATE (NAME, IDENTIFIER, DESCRIPTION) -VALUES ('UNPUBLISHED', 'UNPUBLISHED', 'State in which Application is in un published state.'); +VALUES ('BLOCKED', 'BLOCKED', 'State in which Application is in un published state.'); INSERT INTO APPM_LIFECYCLE_STATE (NAME, IDENTIFIER, DESCRIPTION) VALUES ('RETIRED', 'RETIRED', 'Retiring an application to indicate end of life state,');