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 7c404d5da7a..f0ee07acee0 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 @@ -551,12 +551,12 @@ public class ApplicationManagerImpl implements ApplicationManager { if (application == null) { - throw new ApplicationManagementException("Invalid Application"); + throw new NotFoundException("Couldn't found an application for Application ID: " + applicationId); } if (!isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION) && !application .getUnrestrictedRoles().isEmpty() && isRoleExists(application.getUnrestrictedRoles(), userName)) { - throw new ApplicationManagementException( + throw new ForbiddenException( "You don't have permission to delete this application. In order to delete an application you " + "need to have required permission. Application ID: " + applicationId); } @@ -723,7 +723,7 @@ public class ApplicationManagerImpl implements ApplicationManager { ConnectionManagerUtil.rollbackDBTransaction(); throw new ApplicationManagementException( "Can't delete the application release, You have to move the " - + "lifecycle state from " + currentState + " to acceptable state"); + + "lifecycle state from " + currentState + " to " + nextState); } currentState = nextState; } @@ -740,7 +740,6 @@ public class ApplicationManagerImpl implements ApplicationManager { 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) { ConnectionManagerUtil.rollbackDBTransaction(); throw new ApplicationManagementException( @@ -1123,7 +1122,6 @@ public class ApplicationManagerImpl implements ApplicationManager { isExistingAppRestricted = true; } - //todo check whether user is application owner if (!isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION) && !( isExistingAppRestricted && isRoleExists(existingApplication.getUnrestrictedRoles(), userName))) { ConnectionManagerUtil.rollbackDBTransaction(); 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/ApplicationManagementAPIImpl.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/ApplicationManagementAPIImpl.java index 6f63200fac0..0d9b0e4e382 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/ApplicationManagementAPIImpl.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/ApplicationManagementAPIImpl.java @@ -499,11 +499,16 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { String msg = "Invalid request to update application release for application release UUID " + applicationUUID; log.error(msg, e); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); - } catch(NotFoundException e){ + } catch (NotFoundException e) { String msg = "Couldn't found application or application release for application id: " + applicationId + " and application release UUID " + applicationUUID; - log.error(msg,e); + 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 update the application release which has UUID " + + applicationUUID; + log.error(msg, e); + return Response.status(Response.Status.FORBIDDEN).entity(msg).build(); } catch (ApplicationManagementException e) { String msg = "Error while updating the application release of the application with UUID " + applicationUUID; @@ -527,14 +532,23 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { applicationStorageManager.deleteAllApplicationReleaseArtifacts(storedLocations); String responseMsg = "Successfully deleted the application and application releases: " + applicationId; return Response.status(Response.Status.OK).entity(responseMsg).build(); + } catch (NotFoundException e) { + String msg = + "Couldn't found application for application id: " + applicationId + " to delete the application"; + 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 " + applicationId; + 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; log.error(msg, e); - return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR); + 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 APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } } @@ -550,14 +564,25 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { applicationStorageManager.deleteApplicationReleaseArtifacts(storedLocation); String responseMsg = "Successfully deleted the application release of: " + applicationId + ""; return Response.status(Response.Status.OK).entity(responseMsg).build(); - } catch (ApplicationManagementException e) { + } catch (NotFoundException e) { + String msg = "Couldn't found application release which is having application id: " + applicationId + + " and 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; + 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; log.error(msg, e); - return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR); + 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 APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } }