From 352c881c24bd18f3c3b8873459d7d7a1b29fa2f1 Mon Sep 17 00:00:00 2001 From: Chatura Dilan Date: Wed, 7 Jun 2017 17:22:31 +0530 Subject: [PATCH] Refactor code --- .../device/application/mgt/api/APIUtil.java | 6 ++++- .../impl/ApplicationManagementAPIImpl.java | 2 +- .../common/services/ApplicationManager.java | 8 +++++-- .../services/ApplicationReleaseManager.java | 6 +++++ .../mgt/common/services/CategoryManager.java | 14 +++++++++++ .../mgt/core/impl/ApplicationManagerImpl.java | 15 +++++++++++- .../mgt/core/impl/CategoryManagerImpl.java | 23 +++++++++++++++++++ 7 files changed, 69 insertions(+), 5 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/APIUtil.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/APIUtil.java index c9dfbb057a..917c35bbf5 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/APIUtil.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/APIUtil.java @@ -37,7 +37,8 @@ public class APIUtil { private static ApplicationManager applicationManager; - public static ApplicationManager getApplicationManagemer() { + public static ApplicationManager getApplicationManager() { + if (applicationManager == null) { synchronized (APIUtil.class) { if (applicationManager == null) { @@ -52,10 +53,12 @@ public class APIUtil { } } } + return applicationManager; } public static Response getResponse(ApplicationManagementException ex, Response.Status status) { + //TODO: check for exception type and set the response code. ErrorResponse errorMessage = new ErrorResponse(); errorMessage.setMessage(ex.getMessage()); @@ -64,5 +67,6 @@ public class APIUtil { } errorMessage.setCode(status.getStatusCode()); return Response.status(status).entity(errorMessage).build(); + } } 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/ApplicationManagementAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/ApplicationManagementAPIImpl.java index 06e95af7b0..f45883c46e 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/ApplicationManagementAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/ApplicationManagementAPIImpl.java @@ -44,7 +44,7 @@ public class ApplicationManagementAPIImpl { @Path("applications") public Response getApplications(@QueryParam("offset") int offset, @QueryParam("limit") int limit, @QueryParam("query") String searchQuery) { - ApplicationManager applicationManager = APIUtil.getApplicationManagemer(); + ApplicationManager applicationManager = APIUtil.getApplicationManager(); try { if (limit == 0) { limit = DEFAULT_LIMIT; 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 ae1752b8d8..0642aef21c 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 @@ -25,7 +25,11 @@ import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManage public interface ApplicationManager{ - void createApplication(Application application) throws ApplicationManagementException; + public Application createApplication(Application application) throws ApplicationManagementException; - ApplicationList getApplications(Filter filter) throws ApplicationManagementException; + public Application editApplication(int applicationId, Application application) throws ApplicationManagementException; + + public void deleteApplication(int applicationId) throws ApplicationManagementException; + + public ApplicationList getApplications(Filter filter) throws ApplicationManagementException; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationReleaseManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationReleaseManager.java index 00c5855b6d..7760d6205e 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationReleaseManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationReleaseManager.java @@ -18,5 +18,11 @@ */ package org.wso2.carbon.device.application.mgt.common.services; +import org.wso2.carbon.device.application.mgt.common.Application; +import org.wso2.carbon.device.application.mgt.common.ApplicationList; +import org.wso2.carbon.device.application.mgt.common.Filter; +import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; + public interface ApplicationReleaseManager{ + } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/CategoryManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/CategoryManager.java index 4781299677..32082c865b 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/CategoryManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/CategoryManager.java @@ -18,5 +18,19 @@ */ package org.wso2.carbon.device.application.mgt.common.services; +import org.wso2.carbon.device.application.mgt.common.Application; +import org.wso2.carbon.device.application.mgt.common.ApplicationList; +import org.wso2.carbon.device.application.mgt.common.Category; +import org.wso2.carbon.device.application.mgt.common.Filter; +import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; + public interface CategoryManager{ + + public Category createCategory(Category application) throws ApplicationManagementException; + + public Category editCategory(int applicationId, Category category) throws ApplicationManagementException; + + public void deleteCategory(int applicationId) throws ApplicationManagementException; + + public Category getCategory(Filter filter) 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/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 baa915ee9c..0e538b4d6c 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 @@ -28,13 +28,25 @@ import org.wso2.carbon.device.application.mgt.core.dao.common.DAOFactory; import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; public class ApplicationManagerImpl implements ApplicationManager { + @Override - public void createApplication(Application application) throws ApplicationManagementException { + public Application createApplication(Application application) throws ApplicationManagementException { + return null; + } + + @Override + public Application editApplication(int applicationId, Application application) throws ApplicationManagementException { + return null; + } + + @Override + public void deleteApplication(int applicationId) throws ApplicationManagementException { } @Override public ApplicationList getApplications(Filter filter) throws ApplicationManagementException { + try { ConnectionManagerUtil.openConnection(); ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO(); @@ -42,5 +54,6 @@ public class ApplicationManagerImpl implements ApplicationManager { } finally { ConnectionManagerUtil.closeConnection(); } + } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CategoryManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CategoryManagerImpl.java index e245186b1a..c165a58fc0 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CategoryManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CategoryManagerImpl.java @@ -17,7 +17,30 @@ */ package org.wso2.carbon.device.application.mgt.core.impl; +import org.wso2.carbon.device.application.mgt.common.Category; +import org.wso2.carbon.device.application.mgt.common.Filter; +import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; import org.wso2.carbon.device.application.mgt.common.services.CategoryManager; public class CategoryManagerImpl implements CategoryManager { + + @Override + public Category createCategory(Category application) throws ApplicationManagementException { + return null; + } + + @Override + public Category editCategory(int applicationId, Category category) throws ApplicationManagementException { + return null; + } + + @Override + public void deleteCategory(int applicationId) throws ApplicationManagementException { + + } + + @Override + public Category getCategory(Filter filter) throws ApplicationManagementException { + return null; + } }