From 7278408b44a0c9efba4993c4ea1bb4b440420bc2 Mon Sep 17 00:00:00 2001 From: lasantha Date: Mon, 19 Feb 2018 04:41:03 +0530 Subject: [PATCH] Refactored the source code --- .../mgt/common/AppLifecycleState.java | 2 +- .../application/mgt/common/SortingOrder.java | 2 +- .../mgt/core/impl/ApplicationManagerImpl.java | 18 ++++++++++-------- .../impl/ApplicationManagementAPIImpl.java | 9 +++------ 4 files changed, 15 insertions(+), 16 deletions(-) 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 3d44c6b54b0..8c0c1cbc872 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 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * * WSO2 Inc. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/SortingOrder.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/SortingOrder.java index 88738dd9535..3dd314de962 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/SortingOrder.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/SortingOrder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * * WSO2 Inc. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except 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 f79c1d1d05a..b2bcac32017 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 @@ -175,7 +175,10 @@ public class ApplicationManagerImpl implements ApplicationManager { } catch (UserStoreException e) { throw new ApplicationManagementException( "User-store exception while checking whether the user " + userName + " of tenant " + tenantId - + " has the publisher permission"); + + " has the publisher permission", e); + } catch (ApplicationManagementDAOException e) { + throw new ApplicationManagementException( + "DAO exception while getting applications for the user " + userName + " of tenant " + tenantId, e); } finally { ConnectionManagerUtil.closeDBConnection(); } @@ -526,14 +529,15 @@ public class ApplicationManagerImpl implements ApplicationManager { ApplicationRelease applicationRelease = DataHolder.getInstance().getApplicationReleaseManager() .getReleaseByUuid(applicationUuid); if (applicationRelease == null) { - throw new NotFoundException( + throw new ApplicationManagementException( "Application with UUID " + applicationUuid + " does not exist."); } return applicationRelease; } @Override - public ApplicationRelease updateRelease(int appId, ApplicationRelease applicationRelease) throws ApplicationManagementException { + public ApplicationRelease updateRelease(int appId, ApplicationRelease applicationRelease) throws + ApplicationManagementException { return null; } @@ -787,17 +791,15 @@ public class ApplicationManagerImpl implements ApplicationManager { !SortingOrder.DESC.toString().equals(filter.getSortBy())) { return null; } - - if (filter.getAppType() != null) { Boolean isValidRequest = false; - for (ApplicationType applicationType: ApplicationType.values()){ - if(applicationType.toString().equals(filter.getAppType())){ + for (ApplicationType applicationType : ApplicationType.values()) { + if (applicationType.toString().equals(filter.getAppType())) { isValidRequest = true; break; } } - if (!isValidRequest){ + if (!isValidRequest) { return null; } } 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 3786381cfca..5f8f2bbc312 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 @@ -24,6 +24,7 @@ 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.exception.ApplicationStorageManagementException; +import org.wso2.carbon.device.application.mgt.core.exception.ValidationException; import org.wso2.carbon.device.application.mgt.publisher.api.APIUtil; import org.wso2.carbon.device.application.mgt.publisher.api.services.ApplicationManagementAPI; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; @@ -58,12 +59,10 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { private static Log log = LogFactory.getLog(ApplicationManagementAPIImpl.class); - @GET @Override @Consumes("application/json") - public Response getApplications( - @Valid Filter filter) { + public Response getApplications(@Valid Filter filter) { ApplicationManager applicationManager = APIUtil.getApplicationManager(); try { @@ -73,9 +72,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { ("Couldn't find any application for requested query.").build(); } return Response.status(Response.Status.OK).entity(applications).build(); - } catch (NotFoundException e) { - return Response.status(Response.Status.NOT_FOUND).build(); - } catch (ApplicationManagementException e) { + } catch (ApplicationManagementException e) { String msg = "Error occurred while getting the application list for publisher "; log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();