From e293a236c5eea38e733ff18220072bc1ac10fba3 Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Mon, 6 May 2019 15:01:22 +0530 Subject: [PATCH] Add application delete admin API --- .../mgt/core/dao/ApplicationDAO.java | 9 +- .../mgt/core/dao/ApplicationReleaseDAO.java | 3 + .../mgt/core/dao/LifecycleStateDAO.java | 3 + .../GenericApplicationDAOImpl.java | 85 +++++++++++++++++- .../GenericApplicationReleaseDAOImpl.java | 25 ++++++ .../GenericLifecycleStateDAOImpl.java | 25 ++++++ .../mgt/core/impl/ApplicationManagerImpl.java | 90 +++++++++---------- ...pplicationManagementPublisherAdminAPI.java | 38 ++++++++ ...cationManagementPublisherAdminAPIImpl.java | 25 ++++++ 9 files changed, 256 insertions(+), 47 deletions(-) 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 76a12d9226f..25e6b575ade 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 @@ -59,14 +59,18 @@ public interface ApplicationDAO { void deleteTagMapping (List tagIds, int applicationId, int tenantId) throws ApplicationManagementDAOException; + void deleteTagMapping (int applicationId, int tenantId) throws ApplicationManagementDAOException; + List getAppCategories (int appId, int tenantId) throws ApplicationManagementDAOException; List getAllCategories(int tenantId) throws ApplicationManagementDAOException; void addCategories(List categories, int tenantId) throws ApplicationManagementDAOException; - void addCategoryMapping (List categoryIds, int applicationId, int tenantId) throws ApplicationManagementDAOException; + void addCategoryMapping(List categoryIds, int applicationId, int tenantId) + throws ApplicationManagementDAOException; + void deleteCategoryMapping (int applicationId, int tenantId) throws ApplicationManagementDAOException; /** * To check application existence. @@ -209,5 +213,8 @@ public interface ApplicationDAO { ApplicationDTO getApplicationByRelease(String appReleaseUUID, int tenantId) throws ApplicationManagementDAOException; String getApplicationSubTypeByUUID(String uuid, int tenantId) throws ApplicationManagementDAOException; + + void deleteApplication(int appId, 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/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 1793b764b16..93ec3d49086 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 @@ -115,6 +115,9 @@ public interface ApplicationReleaseDAO { */ void deleteRelease(int id) throws ApplicationManagementDAOException; + void deleteReleases(List applicationReleaseIds) 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 df8d819b0e5..fe1b3eccc40 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 @@ -76,6 +76,9 @@ public interface LifecycleStateDAO { */ void deleteLifecycleStateByReleaseId(int releaseId) throws LifeCycleManagementDAOException; + void deleteLifecycleStates(List appReleaseIds) throws LifeCycleManagementDAOException; + + /*** * * @param appId ID of the 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/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 81bb1eaa288..2cb7aa2711c 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 @@ -808,6 +808,34 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic } } + @Override + public void deleteCategoryMapping (int applicationId, int tenantId) throws ApplicationManagementDAOException{ + if (log.isDebugEnabled()) { + log.debug("Request received in DAO Layer to delete Category mappings."); + } + Connection conn; + String sql = "DELETE FROM " + + "AP_APP_CATEGORY_MAPPING cm " + + "WHERE " + + "cm.AP_APP_ID = ? AND " + + "cm.TENANT_ID = ?"; + try { + conn = this.getDBConnection(); + try (PreparedStatement stmt = conn.prepareStatement(sql)){ + stmt.setInt(1, applicationId); + stmt.setInt(2, tenantId); + stmt.executeUpdate(); + } + } catch (DBConnectionException e) { + throw new ApplicationManagementDAOException( + "Error occurred while obtaining the DB connection when deleting category mapping of application ID: " + + applicationId , e); + } catch (SQLException e) { + throw new ApplicationManagementDAOException("Error occurred when deleting category mapping of application ID: " + + applicationId, e); + } + } + @Override public List getTagIdsForTagNames(List tagNames, int tenantId) throws ApplicationManagementDAOException { @@ -931,12 +959,40 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic } } catch (DBConnectionException e) { throw new ApplicationManagementDAOException( - "Error occurred while obtaining the DB connection when deleting tag mapppig", e); + "Error occurred while obtaining the DB connection when deleting tag mapping", e); } catch (SQLException e) { throw new ApplicationManagementDAOException("Error occurred when deleting tag mapping", e); } } + @Override + public void deleteTagMapping (int applicationId, int tenantId) throws ApplicationManagementDAOException{ + if (log.isDebugEnabled()) { + log.debug("Request received in DAO Layer to delete Tag mappings."); + } + Connection conn; + String sql = "DELETE FROM " + + "AP_APP_TAG_MAPPING tm " + + "WHERE " + + "tm.AP_APP_ID = ? AND " + + "tm.TENANT_ID = ?"; + try { + conn = this.getDBConnection(); + try (PreparedStatement stmt = conn.prepareStatement(sql)){ + stmt.setInt(1, applicationId); + stmt.setInt(2, tenantId); + stmt.executeUpdate(); + } + } catch (DBConnectionException e) { + throw new ApplicationManagementDAOException( + "Error occurred while obtaining the DB connection when deleting tag mapping of application ID: " + + applicationId , e); + } catch (SQLException e) { + throw new ApplicationManagementDAOException("Error occurred when deleting tag mapping of application ID: " + + applicationId, e); + } + } + @Override public List getAppCategories(int appId, int tenantId) throws ApplicationManagementDAOException { if (log.isDebugEnabled()) { @@ -1132,4 +1188,31 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic } } + @Override + public void deleteApplication(int appId, int tenantId) throws ApplicationManagementDAOException { + Connection conn; + String sql; + try { + conn = this.getDBConnection(); + sql = "DELETE AP_APP ap " + + "WHERE ap.ID = ? AND " + + "ap.TENANT_ID = ?"; + try (PreparedStatement stmt = conn.prepareStatement(sql)){ + stmt.setInt(1, appId); + stmt.setInt(2, tenantId); + stmt.executeUpdate(); + + } + } catch (DBConnectionException e) { + String msg = "Error occurred while obtaining the DB connection to delete application for application id::." + + appId; + log.error(msg); + throw new ApplicationManagementDAOException(msg, e); + } catch (SQLException e) { + String msg = "Error occurred while deleting application for application ID: " + appId; + 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/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 bd8441a0682..2c9a74370f8 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 @@ -514,6 +514,31 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements } } + @Override + public void deleteReleases(List applicationReleaseIds) throws ApplicationManagementDAOException{ + Connection connection; + String sql = "DELETE " + + "FROM AP_APP_RELEASE " + + "WHERE ID = ?"; + try { + connection = this.getDBConnection(); + try (PreparedStatement statement = connection.prepareStatement(sql)){ + for (Integer releaseId : applicationReleaseIds){ + statement.setInt(1, releaseId); + statement.addBatch(); + } + statement.executeBatch(); + } + } catch (DBConnectionException e) { + throw new ApplicationManagementDAOException( + "Database connection exception occurred while trying to delete given application release", e); + } catch (SQLException e) { + throw new ApplicationManagementDAOException( + "SQL exception occurred while execute delete query for deleting given application releases.", e); + } + } + + @Override public boolean verifyReleaseExistenceByHash(String hashVal, int tenantId) throws ApplicationManagementDAOException { if (log.isDebugEnabled()) { 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 0db4362fd41..184fdf13efd 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 @@ -212,6 +212,31 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif } } + @Override + public void deleteLifecycleStates(List appReleaseIds) throws LifeCycleManagementDAOException{ + Connection conn; + try { + conn = this.getDBConnection(); + String sql = "DELETE FROM " + + "AP_APP_LIFECYCLE_STATE " + + "WHERE AP_APP_RELEASE_ID = ?"; + try (PreparedStatement stmt = conn.prepareStatement(sql)) { + for (Integer releaseId : appReleaseIds) { + stmt.setInt(1, releaseId); + stmt.addBatch(); + } + stmt.executeBatch(); + } + } catch (DBConnectionException e) { + throw new LifeCycleManagementDAOException("Error occurred while obtaining the DB connection for deleting " + + "application life-cycle states for given application Ids.", e); + } catch (SQLException e) { + throw new LifeCycleManagementDAOException("Error occurred while deleting life-cycle states for given " + + "application releases.", e); + } + } + + private LifecycleStateDTO constructLifecycle(ResultSet rs) throws LifeCycleManagementDAOException { LifecycleStateDTO lifecycleState = null; try { 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 f10c9b566a1..c4f225c6915 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 @@ -737,8 +737,9 @@ public class ApplicationManagerImpl implements ApplicationManager { if (log.isDebugEnabled()) { log.debug("ApplicationDTO release request is received for the application id: " + applicationId); } + + ApplicationDTO applicationDTO = getApplication(applicationId); try { - ApplicationDTO applicationDTO = getApplication(applicationId); ApplicationReleaseDTO applicationReleaseDTO = uploadReleaseArtifacts(applicationReleaseWrapper, applicationDTO, applicationArtifact); ConnectionManagerUtil.beginDBTransaction(); @@ -819,11 +820,10 @@ public class ApplicationManagerImpl implements ApplicationManager { public Application getApplicationById(int appId, String state) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); - ApplicationDTO applicationDTO; boolean isVisibleApp = false; - try { - applicationDTO = getApplication(appId); + ApplicationDTO applicationDTO = getApplication(appId); + try { ConnectionManagerUtil.openDBConnection(); List filteredApplicationReleaseDTOs = new ArrayList<>(); for (ApplicationReleaseDTO applicationReleaseDTO : applicationDTO.getApplicationReleaseDTOs()) { @@ -1162,39 +1162,49 @@ public class ApplicationManagerImpl implements ApplicationManager { @Override public void deleteApplication(int applicationId) throws ApplicationManagementException { - int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); - ApplicationStorageManager applicationStorageManager = Util.getApplicationStorageManager(); - List storedLocations = new ArrayList<>(); - ApplicationDTO applicationDTO; if (log.isDebugEnabled()) { log.debug("Request is received to delete applications which are related with the application id " + applicationId); } + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); + ApplicationStorageManager applicationStorageManager = Util.getApplicationStorageManager(); + ApplicationDTO applicationDTO = getApplication(applicationId); + List applicationReleaseDTOs = applicationDTO.getApplicationReleaseDTOs(); + for (ApplicationReleaseDTO applicationReleaseDTO : applicationReleaseDTOs) { + if (!lifecycleStateManager.isDeletableState(applicationReleaseDTO.getCurrentState())){ + String msg = "Application release which has application release UUID: " + + applicationReleaseDTO.getUuid() + " is not in a deletable state. Therefore Application " + + "deletion is not permitted. In order to delete the application, all application releases " + + "of the application has to be in a deletable state."; + log.error(msg); + throw new ForbiddenException(msg); + } + } + 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<>(); + List deletingAppReleaseIds = new ArrayList<>(); for (ApplicationReleaseDTO applicationReleaseDTO : applicationReleaseDTOs) { - if (!applicationReleaseDTO.getCurrentState().equals(lifecycleStateManager.getEndState())){ - activeApplicationReleaseDTOs.add(applicationReleaseDTO); + List deviceSubscriptionDTOS = subscriptionDAO + .getDeviceSubscriptions(applicationReleaseDTO.getId(), tenantId); + if (!deviceSubscriptionDTOS.isEmpty()){ + String msg = "Application release which has UUID: " + applicationReleaseDTO.getUuid() + + " either subscribed to device/s or it had subscribed to device/s. Therefore you are not " + + "permitted to delete the application release."; + log.error(msg); + throw new ForbiddenException(msg); } - storedLocations.add(applicationReleaseDTO.getAppHashValue()); - } - 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); + applicationStorageManager.deleteApplicationReleaseArtifacts(applicationReleaseDTO.getAppHashValue()); + deletingAppReleaseIds.add(applicationReleaseDTO.getId()); + } + this.lifecycleStateDAO.deleteLifecycleStates(deletingAppReleaseIds); + this.applicationReleaseDAO.deleteReleases(deletingAppReleaseIds); + this.applicationDAO.deleteTagMapping(applicationId, tenantId); + this.applicationDAO.deleteCategoryMapping(applicationId, tenantId); + this.applicationDAO.deleteApplication(applicationId, tenantId); ConnectionManagerUtil.commitDBTransaction(); - applicationStorageManager.deleteAllApplicationReleaseArtifacts(storedLocations); } catch (ApplicationManagementDAOException e) { + ConnectionManagerUtil.rollbackDBTransaction(); String msg = "Error occurred when getting application data for application id: " + applicationId; log.error(msg); throw new ApplicationManagementException(msg, e); @@ -1203,6 +1213,12 @@ public class ApplicationManagerImpl implements ApplicationManager { + applicationId; log.error(msg); throw new ApplicationManagementException(msg); + } catch (LifeCycleManagementDAOException e) { + ConnectionManagerUtil.rollbackDBTransaction(); + String msg = "Error occured while deleting life-cycle state data of application releases of the application" + + " which has application ID: " + applicationId; + log.error(msg); + throw new ApplicationManagementException(msg); } finally { ConnectionManagerUtil.closeDBConnection(); } @@ -1210,19 +1226,13 @@ 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); } + ApplicationDTO applicationDTO = getApplication(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) { @@ -1655,19 +1665,9 @@ public class ApplicationManagerImpl implements ApplicationManager { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); - ApplicationDTO applicationDTO; - + ApplicationDTO applicationDTO = getApplication(applicationId); try { ConnectionManagerUtil.beginDBTransaction(); - applicationDTO = this.applicationDAO.getApplicationById(applicationId, tenantId); - if (applicationDTO == null) { - ConnectionManagerUtil.rollbackDBTransaction(); - String msg = "Tried to update Application which is not in the publisher. Please verify " - + "application details"; - log.error(msg); - throw new NotFoundException(msg); - } - if (!StringUtils.isEmpty(applicationUpdateWrapper.getName())){ Filter filter = new Filter(); filter.setFullMatch(true); 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 16ad79e848a..69ea2d9cbc8 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 @@ -113,4 +113,42 @@ public interface ApplicationManagementPublisherAdminAPI { value = "application release UUID", required = true) @PathParam("uuid") String releaseUuid); + + @DELETE + @Path("/{appId}") + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + 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:admin:app:publisher:update") + }) + } + ) + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully delete application release.", + response = ApplicationList.class), + @ApiResponse( + code = 404, + message = "Not Found. There doesn't have an application release for UUID" + + "query."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Error occurred while deleting application release.", + response = ErrorResponse.class) + }) Response deleteApplication( + @ApiParam( + name = "appId", + value = "application ID", + required = true) + @PathParam("appId") int applicatioId); } 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 2416f6a61f3..61ace448eb0 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 @@ -100,4 +100,29 @@ public class ApplicationManagementPublisherAdminAPIImpl implements ApplicationMa } } + @DELETE + @Path("/{appId}") + public Response deleteApplication( + @PathParam("appId") int applicatioId) { + ApplicationManager applicationManager = APIUtil.getApplicationManager(); + try { + applicationManager.deleteApplication(applicatioId); + String responseMsg = "Successfully deleted the application which has ID: " + applicatioId + ""; + return Response.status(Response.Status.OK).entity(responseMsg).build(); + } catch (NotFoundException e) { + String msg = + "Couldn't found application release which is having the ID:" + applicatioId; + 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 which has ID: " + applicatioId; + log.error(msg, e); + return Response.status(Response.Status.FORBIDDEN).entity(msg).build(); + } catch (ApplicationManagementException e) { + String msg = "Error occurred while deleting the application which has application ID:: " + applicatioId; + log.error(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } + } + }