diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/exception/ApplicationCategoryManagementException.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/exception/ApplicationCategoryManagementException.java new file mode 100644 index 00000000000..522d08086db --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/exception/ApplicationCategoryManagementException.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2017, 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 + * 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.exception; + +/** + * Exception that will be thrown during Application Category Management. + */ +public class ApplicationCategoryManagementException extends ApplicationManagementException { + public ApplicationCategoryManagementException(String message, Throwable throwable) { + super(message, throwable); + setMessage(message); + } + + public ApplicationCategoryManagementException(String message) { + super(message); + setMessage(message); + } + +} 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 b5b4e20b6dd..0b5083adc4b 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 @@ -20,6 +20,7 @@ package org.wso2.carbon.device.application.mgt.common.services; 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.ApplicationCategoryManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; import java.util.List; @@ -29,11 +30,37 @@ import java.util.List; */ public interface CategoryManager { - public Category createCategory(Category application) throws ApplicationManagementException; + /** + * To create an application category. + * + * @param category Category that need to be created. + * @return the created Category. + * @throws ApplicationManagementException Application Management Exception + */ + Category createCategory(Category category) throws ApplicationManagementException; - public List getCategories() throws ApplicationManagementException; + /** + * To get all the current categories. + * + * @return list of Application categories. + * @throws ApplicationManagementException Application Management Exception. + */ + List getCategories() throws ApplicationManagementException; - public Category getCategory(String name) throws ApplicationManagementException; + /** + * To get the category with the given name. + * + * @param name Name of the category to retrieve. + * @return the category with the given name. + * @throws ApplicationManagementException Application Management Exception. + */ + Category getCategory(String name) throws ApplicationManagementException; - public void deleteCategory(String name) throws ApplicationManagementException; + /** + * To delete the category with the given name. + * + * @param name Name of the category to be deleted. + * @throws ApplicationManagementException Application Management Exception. + */ + void deleteCategory(String name) 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 cf58565b1d4..4d5c09b0319 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 @@ -32,8 +32,23 @@ import java.util.List; */ public interface ApplicationDAO { + /** + * To create an application. + * + * @param application Application that need to be created. + * @return Created Application. + * @throws ApplicationManagementDAOException Application Management DAO Exception. + */ Application createApplication(Application application) throws ApplicationManagementDAOException; + /** + * To get the applications that satisfy the given criteria. + * + * @param filter Filter criteria. + * @param tenantId Id of the tenant. + * @return Application list + * @throws ApplicationManagementDAOException Application Management DAO Exception. + */ ApplicationList getApplications(Filter filter, int tenantId) throws ApplicationManagementDAOException; Application getApplication(String uuid, int tenantId, String userName) 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/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 1fb9f026441..6bd1b201993 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 @@ -14,10 +14,11 @@ * specific language governing permissions and limitations * under the License. * -s*/ +*/ 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.exception.ApplicationCategoryManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; import org.wso2.carbon.device.application.mgt.common.services.CategoryManager; import org.wso2.carbon.device.application.mgt.core.dao.common.DAOFactory; @@ -36,14 +37,14 @@ public class CategoryManagerImpl implements CategoryManager { @Override public Category createCategory(Category category) throws ApplicationManagementException { if (category == null) { - throw new ApplicationManagementException("Category is null. Cannot create a category."); + throw new ApplicationCategoryManagementException("Category is null. Cannot create a category."); } if (category.getName() == null) { - throw new ApplicationManagementException( + throw new ApplicationCategoryManagementException( "Application category name cannot be null. Application category creation failed."); } if (getCategory(category.getName()) != null) { - throw new ApplicationManagementException("Application category wth the name " + category.getName() + " " + throw new ApplicationCategoryManagementException("Application category wth the name " + category.getName() + " " + "exists already. Please select a different name"); } try { @@ -72,7 +73,7 @@ public class CategoryManagerImpl implements CategoryManager { @Override public Category getCategory(String name) throws ApplicationManagementException { if (name == null || name.isEmpty()) { - throw new ApplicationManagementException("Name cannot be empty or null. Cannot get category"); + throw new ApplicationCategoryManagementException("Name cannot be empty or null. Cannot get category"); } try { ConnectionManagerUtil.openDBConnection(); @@ -95,7 +96,7 @@ public class CategoryManagerImpl implements CategoryManager { if (isApplicationExistForCategory) { ConnectionManagerUtil.rollbackDBTransaction(); - throw new ApplicationManagementException( + throw new ApplicationCategoryManagementException( "Cannot delete the the category " + name + ". Applications " + "exists for this category"); }