From 179e34aa9253d15be8e1497160ecc1eab96d4a00 Mon Sep 17 00:00:00 2001 From: megala21 Date: Mon, 9 Oct 2017 14:24:04 +0530 Subject: [PATCH 1/8] Adding support for application category --- .../device/application/mgt/api/APIUtil.java | 33 +++- .../services/ApplicationManagementAPI.java | 124 +++++++++++++ .../impl/ApplicationManagementAPIImpl.java | 53 +++++- .../application/mgt/common/Category.java | 3 + .../mgt/common/services/CategoryManager.java | 8 +- .../mgt/core/dao/ApplicationDAO.java | 21 ++- .../GenericApplicationDAOImpl.java | 166 +++++++++++++++--- .../mgt/core/impl/ApplicationManagerImpl.java | 42 +++-- .../mgt/core/impl/CategoryManagerImpl.java | 78 ++++++-- .../dbscripts/cdm/application-mgt/h2.sql | 10 +- .../dbscripts/cdm/application-mgt/mysql.sql | 10 +- 11 files changed, 465 insertions(+), 83 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 7755a77af94..aa0e74b2296 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 @@ -22,13 +22,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.application.mgt.api.beans.ErrorResponse; -import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager; -import org.wso2.carbon.device.application.mgt.common.services.ApplicationReleaseManager; -import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager; -import org.wso2.carbon.device.application.mgt.common.services.LifecycleStateManager; -import org.wso2.carbon.device.application.mgt.common.services.PlatformManager; -import org.wso2.carbon.device.application.mgt.common.services.PlatformStorageManager; -import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager; +import org.wso2.carbon.device.application.mgt.common.services.*; import javax.ws.rs.core.Response; @@ -47,6 +41,7 @@ public class APIUtil { private static ApplicationStorageManager applicationStorageManager; private static SubscriptionManager subscriptionManager; private static PlatformStorageManager platformStorageManager; + private static CategoryManager categoryManager; public static ApplicationManager getApplicationManager() { if (applicationManager == null) { @@ -171,6 +166,30 @@ public class APIUtil { return platformStorageManager; } + + /** + * To get the Category Manager from the osgi context. + * + * @return CategoryManager instance in the current osgi context. + */ + public static CategoryManager getCategoryManager() { + if (categoryManager == null) { + synchronized (APIUtil.class) { + if (categoryManager == null) { + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + categoryManager = (CategoryManager) ctx + .getOSGiService(CategoryManager.class, null); + if (categoryManager == null) { + String msg = "Category Manager service has not initialized."; + log.error(msg); + throw new IllegalStateException(msg); + } + } + } + } + return categoryManager; + } + public static Response getResponse(Exception ex, Response.Status status) { return getResponse(ex.getMessage(), status); } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/ApplicationManagementAPI.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/ApplicationManagementAPI.java index 1a8cca69e75..65c1b7d4686 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/ApplicationManagementAPI.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/ApplicationManagementAPI.java @@ -36,6 +36,7 @@ import org.wso2.carbon.device.application.mgt.api.beans.ErrorResponse; 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.ApplicationRelease; +import org.wso2.carbon.device.application.mgt.common.Category; import java.util.List; import javax.validation.Valid; @@ -101,8 +102,21 @@ import javax.ws.rs.core.Response; description = "Delete an application", key = "perm:application:delete", permissions = {"/device-mgt/application/delete"} + ), + @Scope( + name = "Create an application category", + description = "Create an application category", + key = "perm:application-category:create", + permissions = {"/device-mgt/application/category/create"} + ), + @Scope( + name = "Delete an Application", + description = "Delete an application", + key = "perm:application-category:delete", + permissions = {"/device-mgt/application/category/delete"} ) + } ) @Path("/applications") @@ -747,4 +761,114 @@ public interface ApplicationManagementAPI { value = "Whether to make it default or not", required = false) @QueryParam("isDefault") boolean isDefault); + + + @POST + @Path("/category") + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Create an application category", + notes = "This will create a new category", + tags = "Application Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = SCOPE, value = "perm:application-category:create") + }) + } + ) + @ApiResponses( + value = { + @ApiResponse( + code = 201, + message = "OK. \n Successfully created a new category.", + response = Category.class), + @ApiResponse( + code = 400, + message = "Bad request. Required parameters are not provided"), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Error occurred while creating application category.", + response = ErrorResponse.class) + }) + Response createCategory( + @ApiParam( + name = "category", + value = "The category that need to be created.", + required = true) + @Valid Category category); + + @GET + @Path("/category") + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "GET", + value = "Get existing application categories", + notes = "This will retrieve the existing categories", + tags = "Application Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = SCOPE, value = "perm:application:create") + }) + } + ) + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully retrieved existing categories.", + response = Application.class), + @ApiResponse( + code = 400, + message = "Bad request. Required parameters are not provided"), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Error occurred while getting the application list.", + response = ErrorResponse.class) + }) + Response getCategories(); + + @DELETE + @Path("/category/{name}") + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "DELETE", + value = "Delete application category with the given name", + notes = "This will delete the application category with the given name", + tags = "Application Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = SCOPE, value = "perm:application-category:delete") + }) + } + ) + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully retrieved existing categories.", + response = Application.class), + @ApiResponse( + code = 400, + message = "Bad request. Required parameters are not provided"), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Error occurred while getting the application list.", + response = ErrorResponse.class) + }) + Response deleteCategory( + @ApiParam( + name = "Name", + value = "Name of the application category", + required = true) + @PathParam("name") String name); } 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 2043014fc08..aa16e889d1d 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 @@ -25,11 +25,7 @@ import org.apache.cxf.jaxrs.ext.multipart.Multipart; import org.wso2.carbon.device.application.mgt.api.APIUtil; import org.wso2.carbon.device.application.mgt.api.FileStreamingOutput; import org.wso2.carbon.device.application.mgt.api.services.ApplicationManagementAPI; -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.ApplicationRelease; -import org.wso2.carbon.device.application.mgt.common.Filter; -import org.wso2.carbon.device.application.mgt.common.ImageArtifact; +import org.wso2.carbon.device.application.mgt.common.*; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ResourceManagementException; @@ -542,4 +538,51 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR); } } + + @Override + @POST + @Path("/category") + public Response createCategory(@Valid Category category) { + if (category == null) { + return Response.status(Response.Status.BAD_REQUEST).entity("Category is null. cannot create the " + + "category").build(); + } + try { + Category createdCategory = APIUtil.getCategoryManager().createCategory(category); + return Response.status(Response.Status.CREATED).entity(createdCategory).build(); + } catch (ApplicationManagementException e) { + log.error("Application Management Exception while trying to create the application category", e); + return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR); + } + } + + @Override + @GET + @Path("/category") + public Response getCategories() { + List categories; + try { + categories = APIUtil.getCategoryManager().getCategories(); + return Response.status(Response.Status.OK).entity(categories).build(); + } catch (ApplicationManagementException e) { + log.error("Application Management Exception while trying to get application categories", e); + return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR); + } + } + + @Override + @DELETE + @Path("/category/{name}") + public Response deleteCategory(@PathParam("name") String name) { + if (name == null || name.isEmpty()) { + return Response.status(Response.Status.BAD_REQUEST).entity("Name cannot be null or empty.").build(); + } + try { + APIUtil.getCategoryManager().deleteCategory(name); + return Response.status(Response.Status.OK).entity("Successfully deleted the category.").build(); + } catch (ApplicationManagementException e) { + log.error("Application Management Exception while trying to delete category", e); + return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR); + } + } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Category.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Category.java index f4fc5a0721e..84d8a4edd74 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Category.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Category.java @@ -18,11 +18,14 @@ */ package org.wso2.carbon.device.application.mgt.common; +import org.wso2.carbon.device.application.mgt.common.jaxrs.Exclude; + /** * Represents the category a particular {@link Application} belongs to. */ public class Category { + @Exclude private int id; private String name; 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 824ac9ca426..b5b4e20b6dd 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 @@ -22,6 +22,8 @@ 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 java.util.List; + /** * CategoryManager is responsible for handling add, delete, update opertaions related with {@link Category} */ @@ -29,9 +31,9 @@ public interface CategoryManager { public Category createCategory(Category application) throws ApplicationManagementException; - public Category editCategory(int applicationId, Category category) throws ApplicationManagementException; + public List getCategories() throws ApplicationManagementException; - public void deleteCategory(int applicationId) throws ApplicationManagementException; + public Category getCategory(String name) throws ApplicationManagementException; - public Category getCategory(Filter filter) throws ApplicationManagementException; + public 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 f49a2d3f4bb..80174015d67 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 @@ -18,11 +18,7 @@ */ package org.wso2.carbon.device.application.mgt.core.dao; -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.ApplicationRelease; -import org.wso2.carbon.device.application.mgt.common.Filter; -import org.wso2.carbon.device.application.mgt.common.LifecycleStateTransition; +import org.wso2.carbon.device.application.mgt.common.*; import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; import java.util.List; @@ -47,16 +43,10 @@ public interface ApplicationDAO { int getApplicationCount(Filter filter) throws ApplicationManagementDAOException; - void addProperties(Map properties) throws ApplicationManagementDAOException; - - void editProperties(Map properties) throws ApplicationManagementDAOException; - void deleteProperties(int applicationId) throws ApplicationManagementDAOException; void deleteTags(int applicationId) throws ApplicationManagementDAOException; - void addRelease(ApplicationRelease release) throws ApplicationManagementDAOException; - void changeLifecycle(String applicationUUID, String lifecycleIdentifier, String username, int tenantId) throws ApplicationManagementDAOException; @@ -66,4 +56,13 @@ public interface ApplicationDAO { void updateScreenShotCount(String applicationUUID, int tenantId, int count) throws ApplicationManagementDAOException; + Category addCategory(Category category) throws ApplicationManagementDAOException; + + List getCategories() throws ApplicationManagementDAOException; + + Category getCategory(String name) throws ApplicationManagementDAOException; + + boolean isApplicationExistForCategory(String name) throws ApplicationManagementDAOException; + + void deleteCategory(String name) 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/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 98d5bcf4d31..b79dca2017f 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 @@ -21,12 +21,7 @@ package org.wso2.carbon.device.application.mgt.core.dao.impl.application; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.json.JSONException; -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.ApplicationRelease; -import org.wso2.carbon.device.application.mgt.common.Filter; -import org.wso2.carbon.device.application.mgt.common.LifecycleStateTransition; -import org.wso2.carbon.device.application.mgt.common.Pagination; +import org.wso2.carbon.device.application.mgt.common.*; import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException; import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO; import org.wso2.carbon.device.application.mgt.core.dao.common.Util; @@ -445,6 +440,148 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic } + @Override + public Category addCategory(Category category) throws ApplicationManagementDAOException { + Connection connection; + PreparedStatement statement = null; + String sql = "INSERT INTO APPM_APPLICATION_CATEGORY (NAME, DESCRIPTION) VALUES (?, ?)"; + String[] generatedColumns = { "ID" }; + ResultSet rs = null; + + try { + connection = this.getDBConnection(); + statement = connection.prepareStatement(sql, generatedColumns); + statement.setString(1, category.getName()); + statement.setString(2, category.getDescription()); + statement.executeUpdate(); + rs = statement.getGeneratedKeys(); + if (rs.next()) { + category.setId(rs.getInt(1)); + } + return category; + } catch (DBConnectionException e) { + throw new ApplicationManagementDAOException( + "Database connection while trying to update the categroy " + category.getName()); + } catch (SQLException e) { + throw new ApplicationManagementDAOException("SQL exception while executing the query '" + sql + "' .", e); + } finally { + Util.cleanupResources(statement, rs); + } + } + + @Override + public List getCategories() throws ApplicationManagementDAOException { + Connection conn; + PreparedStatement stmt = null; + ResultSet rs = null; + String sql = "SELECT * FROM APPM_APPLICATION_CATEGORY"; + List categories = new ArrayList<>(); + + try { + conn = this.getDBConnection(); + stmt = conn.prepareStatement(sql); + rs = stmt.executeQuery(); + while (rs.next()) { + Category category = new Category(); + category.setId(rs.getInt("ID")); + category.setName(rs.getString("NAME")); + category.setDescription(rs.getString("DESCRIPTION")); + categories.add(category); + } + return categories; + } catch (DBConnectionException e) { + throw new ApplicationManagementDAOException("Database Connection Exception while trying to get the " + + "application categories", e); + } catch (SQLException e) { + throw new ApplicationManagementDAOException("SQL Exception while trying to get the application " + + "categories, while executing " + sql, e); + } finally { + Util.cleanupResources(stmt, rs); + } + + } + + @Override + public Category getCategory(String name) throws ApplicationManagementDAOException { + Connection conn; + PreparedStatement stmt = null; + ResultSet rs = null; + String sql = "SELECT * FROM APPM_APPLICATION_CATEGORY WHERE NAME = ?"; + + try { + conn = this.getDBConnection(); + stmt = conn.prepareStatement(sql); + stmt.setString(1, name); + rs = stmt.executeQuery(); + if (rs.next()) { + Category category = new Category(); + category.setId(rs.getInt("ID")); + category.setName(rs.getString("NAME")); + category.setDescription(rs.getString("DESCRIPTION")); + return category; + } + return null; + } catch (DBConnectionException e) { + throw new ApplicationManagementDAOException("Database Connection Exception while trying to get the " + + "application categories", e); + } catch (SQLException e) { + throw new ApplicationManagementDAOException("SQL Exception while trying to get the application " + + "categories, while executing " + sql, e); + } finally { + Util.cleanupResources(stmt, rs); + } + } + + @Override + public boolean isApplicationExistForCategory(String name) throws ApplicationManagementDAOException { + Connection conn; + PreparedStatement stmt = null; + ResultSet rs = null; + String sql = "SELECT * FROM APPM_APPLICATION WHERE APPLICATION_CATEGORY_ID = (ID FROM " + + "APPM_APPLICATION_CATEGORY WHERE NAME = ?)"; + + try { + conn = this.getDBConnection(); + stmt = conn.prepareStatement(sql); + stmt.setString(1, name); + rs = stmt.executeQuery(); + return rs.next(); + } catch (DBConnectionException e) { + throw new ApplicationManagementDAOException( + "Database Connection Exception while trying to check the " + "applications for teh category " + + name, e); + } catch (SQLException e) { + throw new ApplicationManagementDAOException( + "SQL Exception while trying to get the application related with categories, while executing " + + sql, e); + } finally { + Util.cleanupResources(stmt, rs); + } + } + + @Override + public void deleteCategory(String name) throws ApplicationManagementDAOException { + Connection conn; + PreparedStatement stmt = null; + String sql = "DELETE FROM APPM_APPLICATION_CATEGORY WHERE NAME = ?"; + + try { + conn = this.getDBConnection(); + stmt = conn.prepareStatement(sql); + stmt.setString(1, name); + stmt.executeUpdate(); + } catch (DBConnectionException e) { + throw new ApplicationManagementDAOException( + "Database Connection Exception while trying to delete the category " + name, e); + } catch (SQLException e) { + throw new ApplicationManagementDAOException( + "SQL Exception while trying to delete the category " + name + " while executing the query " + + sql, e); + } finally { + Util.cleanupResources(stmt, null); + } + } + @Override public Application editApplication(Application application, int tenantId) throws ApplicationManagementDAOException { Connection conn; @@ -661,21 +798,4 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic return id; } - - @Override - public void addProperties(Map properties) throws ApplicationManagementDAOException { - - } - - @Override - public void editProperties(Map properties) throws ApplicationManagementDAOException { - - } - - @Override - public void addRelease(ApplicationRelease release) 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/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 4d87356ce70..31da0f4ff55 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 @@ -22,15 +22,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.CarbonConstants; import org.wso2.carbon.context.PrivilegedCarbonContext; -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.Lifecycle; -import org.wso2.carbon.device.application.mgt.common.LifecycleState; -import org.wso2.carbon.device.application.mgt.common.LifecycleStateTransition; -import org.wso2.carbon.device.application.mgt.common.Platform; -import org.wso2.carbon.device.application.mgt.common.User; -import org.wso2.carbon.device.application.mgt.common.Visibility; +import org.wso2.carbon.device.application.mgt.common.*; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager; import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO; @@ -75,8 +67,17 @@ public class ApplicationManagerImpl implements ApplicationManager { .getTenantId(), application.getPlatform().getIdentifier()); if (platform == null) { - throw new NotFoundException("Invalid platform"); + throw new NotFoundException( + "Invalid platform is provided for the application " + application.getUuid()); } + + Category category = DataHolder.getInstance().getCategoryManager() + .getCategory(application.getCategory().getName()); + if (category == null) { + throw new NotFoundException( + "Invalid Category is provided for the application " + application.getUuid()); + } + application.setCategory(category); ConnectionManagerUtil.beginDBTransaction(); // Validating the platform @@ -131,6 +132,22 @@ public class ApplicationManagerImpl implements ApplicationManager { "Platform specified by identifier " + application.getPlatform().getIdentifier() + " is not found. Please give a valid platform identifier."); } + + if (application.getCategory() != null) { + String applicationCategoryName = application.getCategory().getName(); + if (applicationCategoryName == null || applicationCategoryName.isEmpty()) { + throw new ApplicationManagementException("Application category name cannot be null or " + + "empty. Cannot edit the application."); + } + Category category = DataHolder.getInstance().getCategoryManager() + .getCategory(application.getCategory().getName()); + if (category == null) { + throw new NotFoundException( + "Invalid Category is provided for the application " + application.getUuid() + ". " + + "Cannot edit application"); + } + application.setCategory(category); + } application.setPlatform(platform); ConnectionManagerUtil.beginDBTransaction(); ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO(); @@ -388,8 +405,9 @@ public class ApplicationManagerImpl implements ApplicationManager { throw new ValidationException("Username and tenant Id cannot be empty"); } - if (application.getCategory() == null || application.getCategory().getId() == 0) { - throw new ValidationException("Category id cannot be empty"); + if (application.getCategory() == null || application.getCategory().getName() == null || application + .getCategory().getName().isEmpty()) { + throw new ValidationException("Category name cannot be empty"); } if (application.getPlatform() == null || application.getPlatform().getIdentifier() == null) { 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 58089fa3008..064bd6ef2f3 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,13 +14,18 @@ * 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.Filter; 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; +import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; +import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException; +import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; + +import java.util.List; /** * This class is the default implementation for the CategoryManager. @@ -29,22 +34,75 @@ 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; + public Category createCategory(Category category) throws ApplicationManagementException { + if (category == null) { + throw new ApplicationManagementException("Category is null. Cannot create a category."); + } + if (category.getName() == null) { + throw new ApplicationManagementException( + "Application category name cannot be null. Application " + "category creation failed"); + } + try { + ConnectionManagerUtil.beginDBTransaction(); + Category createdCategory = DAOFactory.getApplicationDAO().addCategory(category); + ConnectionManagerUtil.commitDBTransaction(); + return createdCategory; + } catch (ApplicationManagementDAOException e) { + ConnectionManagerUtil.rollbackDBTransaction(); + throw e; + } finally { + ConnectionManagerUtil.closeDBConnection(); + } } @Override - public Category editCategory(int applicationId, Category category) throws ApplicationManagementException { - return null; + public List getCategories() throws ApplicationManagementException { + try { + ConnectionManagerUtil.openDBConnection(); + return DAOFactory.getApplicationDAO().getCategories(); + } finally { + ConnectionManagerUtil.closeDBConnection(); + } } @Override - public void deleteCategory(int applicationId) throws ApplicationManagementException { - + public Category getCategory(String name) throws ApplicationManagementException { + if (name == null || name.isEmpty()) { + throw new ApplicationManagementException("Name cannot be empty or null. Cannot get category"); + } + try { + ConnectionManagerUtil.openDBConnection(); + return DAOFactory.getApplicationDAO().getCategory(name); + } finally { + ConnectionManagerUtil.closeDBConnection(); + } } @Override - public Category getCategory(Filter filter) throws ApplicationManagementException { - return null; + public void deleteCategory(String name) throws ApplicationManagementException { + Category category = getCategory(name); + if (category == null) { + throw new NotFoundException( + "Category with the name '" + name + "' not found. Cannot delete the " + "non-existing category"); + } + try { + ConnectionManagerUtil.beginDBTransaction(); + boolean isApplicationExistForCategory = DAOFactory.getApplicationDAO().isApplicationExistForCategory(name); + + if (isApplicationExistForCategory) { + ConnectionManagerUtil.rollbackDBTransaction(); + throw new ApplicationManagementException( + "Cannot delete the the category " + name + ". Applications " + "exists for this category"); + } + + DAOFactory.getApplicationDAO().deleteCategory(name); + ConnectionManagerUtil.commitDBTransaction(); + } catch (ApplicationManagementDAOException e) { + ConnectionManagerUtil.rollbackDBTransaction(); + throw e; + } finally { + ConnectionManagerUtil.closeDBConnection(); + } } + } diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql index 21855a963ba..ad3d082962c 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql @@ -44,15 +44,13 @@ CREATE INDEX IF NOT EXISTS FK_PLATFROM_TENANT_MAPPING_PLATFORM ON APPM_PLATFORM_ -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS APPM_APPLICATION_CATEGORY ( ID INT NOT NULL AUTO_INCREMENT, - NAME VARCHAR(100) NOT NULL, + NAME VARCHAR(100) NOT NULL UNIQUE, DESCRIPTION TEXT NULL, - PUBLISHED TINYINT NULL, PRIMARY KEY (ID)); -INSERT INTO APPM_APPLICATION_CATEGORY (NAME, DESCRIPTION, PUBLISHED) VALUES ('Enterprise', 'Enterprise level -applications which the artifacts need to be provided', 1); -INSERT INTO APPM_APPLICATION_CATEGORY (NAME, DESCRIPTION, PUBLISHED) VALUES ('Public', 'Public category in which the -application need to be downloaded from the public application store', 1); +INSERT INTO APPM_APPLICATION_CATEGORY (NAME, DESCRIPTION) VALUES ('Sports', 'Applications that involve sports.'); +INSERT INTO APPM_APPLICATION_CATEGORY (NAME, DESCRIPTION) VALUES ('Education', 'Application related with education'); +INSERT INTO APPM_APPLICATION_CATEGORY (NAME, DESCRIPTION) VALUES ('News', 'Applications involving news'); -- ----------------------------------------------------- -- Table `APPM_LIFECYCLE_STATE` diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql index e680b9c65d3..14b21ad7f8d 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql @@ -60,17 +60,15 @@ CREATE TABLE IF NOT EXISTS `APPM_PLATFORM_TENANT_MAPPING` ( -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `APPM_APPLICATION_CATEGORY` ( `ID` INT NOT NULL AUTO_INCREMENT, - `NAME` VARCHAR(100) NOT NULL, + `NAME` VARCHAR(100) NOT NULL UNIQUE, `DESCRIPTION` TEXT NULL, - `PUBLISHED` TINYINT(1) NULL, PRIMARY KEY (`ID`)) ENGINE = InnoDB COMMENT = 'This table contains the data related to the application category'; -INSERT INTO APPM_APPLICATION_CATEGORY (NAME, DESCRIPTION, PUBLISHED) VALUES ('Enterprise', -'Enterprise level applications which the artifacts need to be provided', 1); -INSERT INTO APPM_APPLICATION_CATEGORY (NAME, DESCRIPTION, PUBLISHED) VALUES ('Public', -'Public category in which the application need to be downloaded from the public application store', 1); +INSERT INTO APPM_APPLICATION_CATEGORY (NAME, DESCRIPTION) VALUES ('Sports', 'Applications that involve sports.'); +INSERT INTO APPM_APPLICATION_CATEGORY (NAME, DESCRIPTION) VALUES ('Education', 'Application related with education'); +INSERT INTO APPM_APPLICATION_CATEGORY (NAME, DESCRIPTION) VALUES ('News', 'Applications involving news'); -- ----------------------------------------------------- -- Table `APPM_LIFECYCLE_STATE` From 7a8f3c64dccbc4e234e9a58a024a7346a3de994d Mon Sep 17 00:00:00 2001 From: megala21 Date: Mon, 9 Oct 2017 15:50:44 +0530 Subject: [PATCH 2/8] Refactoring --- .../services/ApplicationManagementAPI.java | 13 +- .../GenericApplicationDAOImpl.java | 2 +- .../mgt/core/impl/ApplicationManagerImpl.java | 114 ++++++++++-------- 3 files changed, 69 insertions(+), 60 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/ApplicationManagementAPI.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/ApplicationManagementAPI.java index 65c1b7d4686..573e13f458d 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/ApplicationManagementAPI.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/ApplicationManagementAPI.java @@ -110,8 +110,8 @@ import javax.ws.rs.core.Response; permissions = {"/device-mgt/application/category/create"} ), @Scope( - name = "Delete an Application", - description = "Delete an application", + name = "Delete an Application category", + description = "Delete an application category", key = "perm:application-category:delete", permissions = {"/device-mgt/application/category/delete"} ) @@ -823,13 +823,14 @@ public interface ApplicationManagementAPI { @ApiResponse( code = 200, message = "OK. \n Successfully retrieved existing categories.", - response = Application.class), + response = List.class), @ApiResponse( code = 400, message = "Bad request. Required parameters are not provided"), @ApiResponse( code = 500, - message = "Internal Server Error. \n Error occurred while getting the application list.", + message = "Internal Server Error. \n Error occurred while getting the application " + + "categories.", response = ErrorResponse.class) }) Response getCategories(); @@ -855,14 +856,14 @@ public interface ApplicationManagementAPI { value = { @ApiResponse( code = 200, - message = "OK. \n Successfully retrieved existing categories.", + message = "OK. \n Successfully deleted the application with the given name.", response = Application.class), @ApiResponse( code = 400, message = "Bad request. Required parameters are not provided"), @ApiResponse( code = 500, - message = "Internal Server Error. \n Error occurred while getting the application list.", + message = "Internal Server Error. \n Error occurred while deleting applcation category.", response = ErrorResponse.class) }) Response deleteCategory( 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 b79dca2017f..a6da6d77281 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 @@ -537,7 +537,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic Connection conn; PreparedStatement stmt = null; ResultSet rs = null; - String sql = "SELECT * FROM APPM_APPLICATION WHERE APPLICATION_CATEGORY_ID = (ID FROM " + String sql = "SELECT * FROM APPM_APPLICATION WHERE APPLICATION_CATEGORY_ID = (SELECT ID FROM " + "APPM_APPLICATION_CATEGORY WHERE NAME = ?)"; 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 31da0f4ff55..f5e7c84f3c9 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 @@ -22,7 +22,16 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.CarbonConstants; import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.device.application.mgt.common.*; +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.Lifecycle; +import org.wso2.carbon.device.application.mgt.common.LifecycleState; +import org.wso2.carbon.device.application.mgt.common.LifecycleStateTransition; +import org.wso2.carbon.device.application.mgt.common.Platform; +import org.wso2.carbon.device.application.mgt.common.User; +import org.wso2.carbon.device.application.mgt.common.Visibility; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager; import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO; @@ -62,22 +71,20 @@ public class ApplicationManagerImpl implements ApplicationManager { application.setUuid(HelperUtil.generateApplicationUuid()); application.setCreatedAt(new Date()); application.setModifiedAt(new Date()); - try { - Platform platform = DataHolder.getInstance().getPlatformManager().getPlatform(application.getUser() - .getTenantId(), application.getPlatform().getIdentifier()); + Platform platform = DataHolder.getInstance().getPlatformManager() + .getPlatform(application.getUser().getTenantId(), application.getPlatform().getIdentifier()); - if (platform == null) { - throw new NotFoundException( - "Invalid platform is provided for the application " + application.getUuid()); - } + if (platform == null) { + throw new NotFoundException("Invalid platform is provided for the application " + application.getUuid()); + } - Category category = DataHolder.getInstance().getCategoryManager() - .getCategory(application.getCategory().getName()); - if (category == null) { - throw new NotFoundException( - "Invalid Category is provided for the application " + application.getUuid()); - } - application.setCategory(category); + Category category = DataHolder.getInstance().getCategoryManager() + .getCategory(application.getCategory().getName()); + if (category == null) { + throw new NotFoundException("Invalid Category is provided for the application " + application.getUuid()); + } + application.setCategory(category); + try { ConnectionManagerUtil.beginDBTransaction(); // Validating the platform @@ -119,48 +126,49 @@ public class ApplicationManagerImpl implements ApplicationManager { } if (!isApplicationOwnerOrAdmin(application.getUuid(), userName, tenantId)) { - throw new ApplicationManagementException("User " + userName + " does not have permissions to edit the " - + "application with the UUID " + application.getUuid()); + throw new ApplicationManagementException( + "User " + userName + " does not have permissions to edit the " + "application with the UUID " + + application.getUuid()); } if (this.getApplication(application.getUuid()) != null) { - try { - if (application.getPlatform() != null && application.getPlatform().getIdentifier() != null) { - Platform platform = DataHolder.getInstance().getPlatformManager() - .getPlatform(tenantId, application.getPlatform().getIdentifier()); - if (platform == null) { - throw new NotFoundException( - "Platform specified by identifier " + application.getPlatform().getIdentifier() - + " is not found. Please give a valid platform identifier."); - } + if (application.getPlatform() == null || application.getPlatform().getIdentifier() == null) { + throw new NotFoundException("Platform information not available with the application!"); + } + Platform platform = DataHolder.getInstance().getPlatformManager() + .getPlatform(tenantId, application.getPlatform().getIdentifier()); + if (platform == null) { + throw new NotFoundException( + "Platform specified by identifier " + application.getPlatform().getIdentifier() + + " is not found. Please give a valid platform identifier."); + } + application.setPlatform(platform); - if (application.getCategory() != null) { - String applicationCategoryName = application.getCategory().getName(); - if (applicationCategoryName == null || applicationCategoryName.isEmpty()) { - throw new ApplicationManagementException("Application category name cannot be null or " - + "empty. Cannot edit the application."); - } - Category category = DataHolder.getInstance().getCategoryManager() - .getCategory(application.getCategory().getName()); - if (category == null) { - throw new NotFoundException( - "Invalid Category is provided for the application " + application.getUuid() + ". " - + "Cannot edit application"); - } - application.setCategory(category); - } - application.setPlatform(platform); - ConnectionManagerUtil.beginDBTransaction(); - ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO(); - application.setModifiedAt(new Date()); - Application modifiedApplication = applicationDAO.editApplication(application, tenantId); - Visibility visibility = DataHolder.getInstance().getVisibilityManager().put(application.getId(), - application.getVisibility()); - modifiedApplication.setVisibility(visibility); - ConnectionManagerUtil.commitDBTransaction(); - return modifiedApplication; - } else { - throw new NotFoundException("Platform information not available with the application!"); + if (application.getCategory() != null) { + String applicationCategoryName = application.getCategory().getName(); + if (applicationCategoryName == null || applicationCategoryName.isEmpty()) { + throw new ApplicationManagementException( + "Application category name cannot be null or " + "empty. Cannot edit the application."); + } + Category category = DataHolder.getInstance().getCategoryManager() + .getCategory(application.getCategory().getName()); + if (category == null) { + throw new NotFoundException( + "Invalid Category is provided for the application " + application.getUuid() + ". " + + "Cannot edit application"); } + application.setCategory(category); + } + + try { + ConnectionManagerUtil.beginDBTransaction(); + ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO(); + application.setModifiedAt(new Date()); + Application modifiedApplication = applicationDAO.editApplication(application, tenantId); + Visibility visibility = DataHolder.getInstance().getVisibilityManager() + .put(application.getId(), application.getVisibility()); + modifiedApplication.setVisibility(visibility); + ConnectionManagerUtil.commitDBTransaction(); + return modifiedApplication; } catch (ApplicationManagementDAOException e) { ConnectionManagerUtil.rollbackDBTransaction(); throw e; From 0fefa094a718122ffc4206411a796a9a74af67e1 Mon Sep 17 00:00:00 2001 From: megala21 Date: Mon, 9 Oct 2017 16:00:08 +0530 Subject: [PATCH 3/8] Refactoring --- .../wso2/carbon/device/application/mgt/api/APIUtil.java | 9 ++++++++- .../api/services/impl/ApplicationManagementAPIImpl.java | 7 ++++++- .../device/application/mgt/core/dao/ApplicationDAO.java | 7 +++++-- .../dao/impl/application/GenericApplicationDAOImpl.java | 9 +++++++-- .../application/mgt/core/impl/CategoryManagerImpl.java | 6 +++++- 5 files changed, 31 insertions(+), 7 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 aa0e74b2296..6f75524df8e 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 @@ -22,7 +22,14 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.application.mgt.api.beans.ErrorResponse; -import org.wso2.carbon.device.application.mgt.common.services.*; +import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager; +import org.wso2.carbon.device.application.mgt.common.services.ApplicationReleaseManager; +import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager; +import org.wso2.carbon.device.application.mgt.common.services.CategoryManager; +import org.wso2.carbon.device.application.mgt.common.services.LifecycleStateManager; +import org.wso2.carbon.device.application.mgt.common.services.PlatformManager; +import org.wso2.carbon.device.application.mgt.common.services.PlatformStorageManager; +import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager; import javax.ws.rs.core.Response; 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 aa16e889d1d..34edd4c5d8a 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 @@ -25,7 +25,12 @@ import org.apache.cxf.jaxrs.ext.multipart.Multipart; import org.wso2.carbon.device.application.mgt.api.APIUtil; import org.wso2.carbon.device.application.mgt.api.FileStreamingOutput; import org.wso2.carbon.device.application.mgt.api.services.ApplicationManagementAPI; -import org.wso2.carbon.device.application.mgt.common.*; +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.ApplicationRelease; +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.ImageArtifact; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ResourceManagementException; 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 80174015d67..cf58565b1d4 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 @@ -18,11 +18,14 @@ */ package org.wso2.carbon.device.application.mgt.core.dao; -import org.wso2.carbon.device.application.mgt.common.*; +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.LifecycleStateTransition; import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; import java.util.List; -import java.util.Map; /** * ApplicationDAO is responsible for handling all the Database related operations related with Application Management. 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 a6da6d77281..8b04eeaa78a 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 @@ -21,7 +21,12 @@ package org.wso2.carbon.device.application.mgt.core.dao.impl.application; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.json.JSONException; -import org.wso2.carbon.device.application.mgt.common.*; +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.LifecycleStateTransition; +import org.wso2.carbon.device.application.mgt.common.Pagination; import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException; import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO; import org.wso2.carbon.device.application.mgt.core.dao.common.Util; @@ -461,7 +466,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic return category; } catch (DBConnectionException e) { throw new ApplicationManagementDAOException( - "Database connection while trying to update the categroy " + category.getName()); + "Database connection while trying to update the categroy " + category.getName(), e); } catch (SQLException e) { throw new ApplicationManagementDAOException("SQL exception while executing the query '" + sql + "' .", e); } finally { 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 064bd6ef2f3..1fb9f026441 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 @@ -40,7 +40,11 @@ public class CategoryManagerImpl implements CategoryManager { } if (category.getName() == null) { throw new ApplicationManagementException( - "Application category name cannot be null. Application " + "category creation failed"); + "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() + " " + + "exists already. Please select a different name"); } try { ConnectionManagerUtil.beginDBTransaction(); From e26d859236c1754ad2d1e2e7818efeec9287b205 Mon Sep 17 00:00:00 2001 From: megala21 Date: Mon, 9 Oct 2017 17:18:45 +0530 Subject: [PATCH 4/8] Adding initiail changes --- ...pplicationCategoryManagementException.java | 36 +++++++++++++++++++ .../mgt/common/services/CategoryManager.java | 35 +++++++++++++++--- .../mgt/core/dao/ApplicationDAO.java | 15 ++++++++ .../mgt/core/impl/CategoryManagerImpl.java | 13 +++---- 4 files changed, 89 insertions(+), 10 deletions(-) create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/exception/ApplicationCategoryManagementException.java 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"); } From d8ff31b628835e7fd40a0a4b3c1eb4fffed840f7 Mon Sep 17 00:00:00 2001 From: megala21 Date: Mon, 9 Oct 2017 21:09:50 +0530 Subject: [PATCH 5/8] Adding remaining changes --- ...pplicationCategoryManagementException.java | 6 - .../mgt/core/dao/ApplicationDAO.java | 106 ++++++++++-- .../application/mgt/core/dao/CategoryDAO.java | 39 +++++ .../mgt/core/dao/common/DAOFactory.java | 25 ++- .../GenericApplicationDAOImpl.java | 135 ++-------------- .../impl/category/GenericCategoryDAOImpl.java | 151 ++++++++++++++++++ .../mgt/core/impl/CategoryManagerImpl.java | 18 +-- 7 files changed, 316 insertions(+), 164 deletions(-) create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/category/GenericCategoryDAOImpl.java 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 index 522d08086db..5cf73b868da 100644 --- 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 @@ -23,14 +23,8 @@ 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.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 4d5c09b0319..1e4874dd6f5 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 @@ -20,7 +20,6 @@ package org.wso2.carbon.device.application.mgt.core.dao; 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.LifecycleStateTransition; import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; @@ -51,36 +50,111 @@ public interface ApplicationDAO { */ ApplicationList getApplications(Filter filter, int tenantId) throws ApplicationManagementDAOException; + /** + * To get the application with the given uuid + * + * @param uuid UUID of the application to be retrieved. + * @param tenantId ID of the tenant. + * @param userName Name of the user. + * @return the application + * @throws ApplicationManagementDAOException Application Management DAO Exception. + */ Application getApplication(String uuid, int tenantId, String userName) throws ApplicationManagementDAOException; + /** + * To get the application id of the application specified by the UUID + * + * @param uuid UUID of the application. + * @param tenantId ID of the tenant. + * @return ID of the Application. + * @throws ApplicationManagementDAOException Application Management DAO Exception. + */ int getApplicationId(String uuid, int tenantId) throws ApplicationManagementDAOException; + /** + * To edit the given application. + * + * @param application Application that need to be edited. + * @param tenantId Tenant ID of the Application. + * @return Updated Application. + * @throws ApplicationManagementDAOException Application Management DAO Exception. + */ Application editApplication(Application application, int tenantId) throws ApplicationManagementDAOException; + /** + * To delete the application identified by the UUID + * + * @param uuid UUID of the application. + * @param tenantId ID of tenant which the Application belongs to. + * @throws ApplicationManagementDAOException Application Management DAO Exception. + */ void deleteApplication(String uuid, int tenantId) throws ApplicationManagementDAOException; + /** + * To get the application count that satisfies gives search query. + * + * @param filter Application Filter. + * @return count of the applications + * @throws ApplicationManagementDAOException Application Management DAO Exception. + */ int getApplicationCount(Filter filter) throws ApplicationManagementDAOException; + /** + * To delete the properties of a application. + * + * @param applicationId ID of the application to delete the properties. + * @throws ApplicationManagementDAOException Application Management DAO Exception. + */ void deleteProperties(int applicationId) throws ApplicationManagementDAOException; + /** + * To delete the tags of a application. + * + * @param applicationId ID of the application to delete the tags. + * @throws ApplicationManagementDAOException Application Management DAO Exception. + */ void deleteTags(int applicationId) throws ApplicationManagementDAOException; - void changeLifecycle(String applicationUUID, String lifecycleIdentifier, String username, int tenantId) throws - ApplicationManagementDAOException; - - List getNextLifeCycleStates(String applicationUUID, int tenantId) throws - ApplicationManagementDAOException; - - void updateScreenShotCount(String applicationUUID, int tenantId, int count) throws - ApplicationManagementDAOException; - - Category addCategory(Category category) throws ApplicationManagementDAOException; - - List getCategories() throws ApplicationManagementDAOException; + /** + * To change the lifecycle state of the application. + * + * @param applicationUUID UUID of the application. + * @param lifecycleIdentifier New lifecycle state. + * @param username Name of the user. + * @param tenantId ID of the tenant. + * @throws ApplicationManagementDAOException Application Management DAO Exception. + */ + void changeLifecycle(String applicationUUID, String lifecycleIdentifier, String username, int tenantId) + throws ApplicationManagementDAOException; - Category getCategory(String name) throws ApplicationManagementDAOException; + /** + * To get the next possible lifecycle states for the application. + * + * @param applicationUUID UUID of the application. + * @param tenantId ID of the tenant. + * @return Next possible lifecycle states. + * @throws ApplicationManagementDAOException Application Management DAO Exception. + */ + List getNextLifeCycleStates(String applicationUUID, int tenantId) + throws ApplicationManagementDAOException; - boolean isApplicationExistForCategory(String name) throws ApplicationManagementDAOException; + /** + * To update the screen-shot count of a application. + * + * @param applicationUUID UUID of the application. + * @param tenantId ID of the tenant. + * @param count New count of the screen-shots. + * @throws ApplicationManagementDAOException Application Management DAO Exception. + */ + void updateScreenShotCount(String applicationUUID, int tenantId, int count) + throws ApplicationManagementDAOException; - void deleteCategory(String name) throws ApplicationManagementDAOException; + /** + * To check whether atleast one application exist under category. + * + * @param categoryName Name of the category. + * @return true if atleast one application exist under the given category, otherwise false. + * @throws ApplicationManagementDAOException Application Management DAO Exception. + */ + boolean isApplicationExist(String categoryName) 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/CategoryDAO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/CategoryDAO.java index 856a3f96286..d003552af3d 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/CategoryDAO.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/CategoryDAO.java @@ -18,8 +18,47 @@ */ package org.wso2.carbon.device.application.mgt.core.dao; +import org.wso2.carbon.device.application.mgt.common.Category; +import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; + +import java.util.List; + /** * This is responsible for Application Category related DAO operations. */ public interface CategoryDAO { + + /** + * To add a new category. + * + * @param category Category that need to be added. + * @return Newly added category. + * @throws ApplicationManagementDAOException Application Management DAO Exception. + */ + Category addCategory(Category category) throws ApplicationManagementDAOException; + + /** + * To get the existing categories. + * + * @return Existing categories. + * @throws ApplicationManagementDAOException Application Management DAO Exception. + */ + List getCategories() throws ApplicationManagementDAOException; + + /** + * To get the category with the given name. + * + * @param name Name of the Application category. + * @return Application Category. + * @throws ApplicationManagementDAOException Application Management DAO Exception. + */ + Category getCategory(String name) throws ApplicationManagementDAOException; + + /** + * To delete a particular category. + * + * @param name Name of the category that need to be deleted. + * @throws ApplicationManagementDAOException Application Management DAO Exception. + */ + void deleteCategory(String name) 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/common/DAOFactory.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/DAOFactory.java index 4016192d141..fa2e94b45dd 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/DAOFactory.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/DAOFactory.java @@ -22,15 +22,11 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.application.mgt.common.exception.UnsupportedDatabaseEngineException; import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager; -import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO; -import org.wso2.carbon.device.application.mgt.core.dao.ApplicationReleaseDAO; -import org.wso2.carbon.device.application.mgt.core.dao.LifecycleStateDAO; -import org.wso2.carbon.device.application.mgt.core.dao.PlatformDAO; -import org.wso2.carbon.device.application.mgt.core.dao.SubscriptionDAO; -import org.wso2.carbon.device.application.mgt.core.dao.VisibilityDAO; +import org.wso2.carbon.device.application.mgt.core.dao.*; import org.wso2.carbon.device.application.mgt.core.dao.impl.application.GenericApplicationDAOImpl; import org.wso2.carbon.device.application.mgt.core.dao.impl.application.release.GenericApplicationReleaseDAOImpl; import org.wso2.carbon.device.application.mgt.core.dao.impl.application.release.OracleApplicationDAOImpl; +import org.wso2.carbon.device.application.mgt.core.dao.impl.category.GenericCategoryDAOImpl; import org.wso2.carbon.device.application.mgt.core.dao.impl.lifecyclestate.GenericLifecycleStateImpl; import org.wso2.carbon.device.application.mgt.core.dao.impl.platform.GenericPlatformDAOImpl; import org.wso2.carbon.device.application.mgt.core.dao.impl.platform.OracleMsSQLPlatformDAOImpl; @@ -164,6 +160,23 @@ public class DAOFactory { throw new IllegalStateException("Database engine has not initialized properly."); } + /** + * To get the instance of CategoryDAOImplementation of the particular database engine. + * @return {@link org.wso2.carbon.device.application.mgt.core.dao.impl.category.GenericCategoryDAOImpl} + */ + public static CategoryDAO getCategoryDAO() { + if (databaseEngine != null) { + switch (databaseEngine) { + case Constants.DataBaseTypes.DB_TYPE_H2: + case Constants.DataBaseTypes.DB_TYPE_MYSQL: + return new GenericCategoryDAOImpl(); + default: + throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine); + } + } + throw new IllegalStateException("Database engine has not initialized properly."); + } + /** * This method initializes the databases by creating the database. * 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 8b04eeaa78a..1ce1444d2fc 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 @@ -23,7 +23,6 @@ import org.apache.commons.logging.LogFactory; import org.json.JSONException; 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.LifecycleStateTransition; import org.wso2.carbon.device.application.mgt.common.Pagination; @@ -58,7 +57,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic log.debug("UUID : " + application.getUuid() + " Name : " + application.getName() + " User name : " + application.getUser().getUserName()); } - Connection conn = null; + Connection conn; PreparedStatement stmt = null; ResultSet rs = null; String sql = ""; @@ -114,7 +113,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic log.debug(String.format("Filter: limit=%s, offset=%", filter.getLimit(), filter.getOffset())); } - Connection conn = null; + Connection conn; PreparedStatement stmt = null; ResultSet rs = null; String sql = ""; @@ -384,7 +383,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic @Override public List getNextLifeCycleStates(String applicationUUID, int tenantId) throws ApplicationManagementDAOException { - Connection connection = null; + Connection connection; PreparedStatement preparedStatement = null; ResultSet resultSet = null; @@ -446,147 +445,31 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic } @Override - public Category addCategory(Category category) throws ApplicationManagementDAOException { - Connection connection; - PreparedStatement statement = null; - String sql = "INSERT INTO APPM_APPLICATION_CATEGORY (NAME, DESCRIPTION) VALUES (?, ?)"; - String[] generatedColumns = { "ID" }; - ResultSet rs = null; - - try { - connection = this.getDBConnection(); - statement = connection.prepareStatement(sql, generatedColumns); - statement.setString(1, category.getName()); - statement.setString(2, category.getDescription()); - statement.executeUpdate(); - rs = statement.getGeneratedKeys(); - if (rs.next()) { - category.setId(rs.getInt(1)); - } - return category; - } catch (DBConnectionException e) { - throw new ApplicationManagementDAOException( - "Database connection while trying to update the categroy " + category.getName(), e); - } catch (SQLException e) { - throw new ApplicationManagementDAOException("SQL exception while executing the query '" + sql + "' .", e); - } finally { - Util.cleanupResources(statement, rs); - } - } - - @Override - public List getCategories() throws ApplicationManagementDAOException { - Connection conn; - PreparedStatement stmt = null; - ResultSet rs = null; - String sql = "SELECT * FROM APPM_APPLICATION_CATEGORY"; - List categories = new ArrayList<>(); - - try { - conn = this.getDBConnection(); - stmt = conn.prepareStatement(sql); - rs = stmt.executeQuery(); - while (rs.next()) { - Category category = new Category(); - category.setId(rs.getInt("ID")); - category.setName(rs.getString("NAME")); - category.setDescription(rs.getString("DESCRIPTION")); - categories.add(category); - } - return categories; - } catch (DBConnectionException e) { - throw new ApplicationManagementDAOException("Database Connection Exception while trying to get the " - + "application categories", e); - } catch (SQLException e) { - throw new ApplicationManagementDAOException("SQL Exception while trying to get the application " - + "categories, while executing " + sql, e); - } finally { - Util.cleanupResources(stmt, rs); - } - - } - - @Override - public Category getCategory(String name) throws ApplicationManagementDAOException { - Connection conn; - PreparedStatement stmt = null; - ResultSet rs = null; - String sql = "SELECT * FROM APPM_APPLICATION_CATEGORY WHERE NAME = ?"; - - try { - conn = this.getDBConnection(); - stmt = conn.prepareStatement(sql); - stmt.setString(1, name); - rs = stmt.executeQuery(); - if (rs.next()) { - Category category = new Category(); - category.setId(rs.getInt("ID")); - category.setName(rs.getString("NAME")); - category.setDescription(rs.getString("DESCRIPTION")); - return category; - } - return null; - } catch (DBConnectionException e) { - throw new ApplicationManagementDAOException("Database Connection Exception while trying to get the " - + "application categories", e); - } catch (SQLException e) { - throw new ApplicationManagementDAOException("SQL Exception while trying to get the application " - + "categories, while executing " + sql, e); - } finally { - Util.cleanupResources(stmt, rs); - } - } - - @Override - public boolean isApplicationExistForCategory(String name) throws ApplicationManagementDAOException { + public boolean isApplicationExist(String categoryName) throws ApplicationManagementDAOException { Connection conn; PreparedStatement stmt = null; ResultSet rs = null; String sql = "SELECT * FROM APPM_APPLICATION WHERE APPLICATION_CATEGORY_ID = (SELECT ID FROM " + "APPM_APPLICATION_CATEGORY WHERE NAME = ?)"; - try { conn = this.getDBConnection(); stmt = conn.prepareStatement(sql); - stmt.setString(1, name); + stmt.setString(1, categoryName); rs = stmt.executeQuery(); return rs.next(); } catch (DBConnectionException e) { throw new ApplicationManagementDAOException( "Database Connection Exception while trying to check the " + "applications for teh category " - + name, e); + + categoryName, e); } catch (SQLException e) { throw new ApplicationManagementDAOException( - "SQL Exception while trying to get the application related with categories, while executing " - + sql, e); + "SQL Exception while trying to get the application related with categories, while executing " + sql, + e); } finally { Util.cleanupResources(stmt, rs); } } - @Override - public void deleteCategory(String name) throws ApplicationManagementDAOException { - Connection conn; - PreparedStatement stmt = null; - String sql = "DELETE FROM APPM_APPLICATION_CATEGORY WHERE NAME = ?"; - - try { - conn = this.getDBConnection(); - stmt = conn.prepareStatement(sql); - stmt.setString(1, name); - stmt.executeUpdate(); - } catch (DBConnectionException e) { - throw new ApplicationManagementDAOException( - "Database Connection Exception while trying to delete the category " + name, e); - } catch (SQLException e) { - throw new ApplicationManagementDAOException( - "SQL Exception while trying to delete the category " + name + " while executing the query " + - sql, e); - } finally { - Util.cleanupResources(stmt, null); - } - } - @Override public Application editApplication(Application application, int tenantId) throws ApplicationManagementDAOException { Connection conn; @@ -778,7 +661,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic @Override public int getApplicationId(String uuid, int tenantId) throws ApplicationManagementDAOException { - Connection conn = null; + Connection conn; PreparedStatement stmt = null; ResultSet rs = null; String sql; 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/category/GenericCategoryDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/category/GenericCategoryDAOImpl.java new file mode 100644 index 00000000000..75b3766cb30 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/category/GenericCategoryDAOImpl.java @@ -0,0 +1,151 @@ +/* + * 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.core.dao.impl.category; + +import org.wso2.carbon.device.application.mgt.common.Category; +import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException; +import org.wso2.carbon.device.application.mgt.core.dao.CategoryDAO; +import org.wso2.carbon.device.application.mgt.core.dao.common.Util; +import org.wso2.carbon.device.application.mgt.core.dao.impl.AbstractDAOImpl; +import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +/** + * This is the concrete implementation of {@link CategoryDAO}. + */ +public class GenericCategoryDAOImpl extends AbstractDAOImpl implements CategoryDAO { + @Override + public Category addCategory(Category category) throws ApplicationManagementDAOException { + Connection connection; + PreparedStatement statement = null; + String sql = "INSERT INTO APPM_APPLICATION_CATEGORY (NAME, DESCRIPTION) VALUES (?, ?)"; + String[] generatedColumns = { "ID" }; + ResultSet rs = null; + try { + connection = this.getDBConnection(); + statement = connection.prepareStatement(sql, generatedColumns); + statement.setString(1, category.getName()); + statement.setString(2, category.getDescription()); + statement.executeUpdate(); + rs = statement.getGeneratedKeys(); + if (rs.next()) { + category.setId(rs.getInt(1)); + } + return category; + } catch (DBConnectionException e) { + throw new ApplicationManagementDAOException( + "Database connection while trying to update the categroy " + category.getName(), e); + } catch (SQLException e) { + throw new ApplicationManagementDAOException("SQL exception while executing the query '" + sql + "' .", e); + } finally { + Util.cleanupResources(statement, rs); + } + } + + @Override + public List getCategories() throws ApplicationManagementDAOException { + Connection conn; + PreparedStatement stmt = null; + ResultSet rs = null; + String sql = "SELECT * FROM APPM_APPLICATION_CATEGORY"; + List categories = new ArrayList<>(); + try { + conn = this.getDBConnection(); + stmt = conn.prepareStatement(sql); + rs = stmt.executeQuery(); + while (rs.next()) { + Category category = new Category(); + category.setId(rs.getInt("ID")); + category.setName(rs.getString("NAME")); + category.setDescription(rs.getString("DESCRIPTION")); + categories.add(category); + } + return categories; + } catch (DBConnectionException e) { + throw new ApplicationManagementDAOException("Database Connection Exception while trying to get the " + + "application categories", e); + } catch (SQLException e) { + throw new ApplicationManagementDAOException("SQL Exception while trying to get the application " + + "categories, while executing " + sql, e); + } finally { + Util.cleanupResources(stmt, rs); + } + + } + + @Override + public Category getCategory(String name) throws ApplicationManagementDAOException { + Connection conn; + PreparedStatement stmt = null; + ResultSet rs = null; + String sql = "SELECT * FROM APPM_APPLICATION_CATEGORY WHERE NAME = ?"; + try { + conn = this.getDBConnection(); + stmt = conn.prepareStatement(sql); + stmt.setString(1, name); + rs = stmt.executeQuery(); + if (rs.next()) { + Category category = new Category(); + category.setId(rs.getInt("ID")); + category.setName(rs.getString("NAME")); + category.setDescription(rs.getString("DESCRIPTION")); + return category; + } + return null; + } catch (DBConnectionException e) { + throw new ApplicationManagementDAOException("Database Connection Exception while trying to get the " + + "application categories", e); + } catch (SQLException e) { + throw new ApplicationManagementDAOException("SQL Exception while trying to get the application " + + "categories, while executing " + sql, e); + } finally { + Util.cleanupResources(stmt, rs); + } + } + + @Override + public void deleteCategory(String name) throws ApplicationManagementDAOException { + Connection conn; + PreparedStatement stmt = null; + String sql = "DELETE FROM APPM_APPLICATION_CATEGORY WHERE NAME = ?"; + try { + conn = this.getDBConnection(); + stmt = conn.prepareStatement(sql); + stmt.setString(1, name); + stmt.executeUpdate(); + } catch (DBConnectionException e) { + throw new ApplicationManagementDAOException( + "Database Connection Exception while trying to delete the category " + name, e); + } catch (SQLException e) { + throw new ApplicationManagementDAOException( + "SQL Exception while trying to delete the category " + name + " while executing the query " + + sql, e); + } finally { + Util.cleanupResources(stmt, null); + } + } + +} 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 6bd1b201993..632ac600e67 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 @@ -44,12 +44,13 @@ public class CategoryManagerImpl implements CategoryManager { "Application category name cannot be null. Application category creation failed."); } if (getCategory(category.getName()) != null) { - throw new ApplicationCategoryManagementException("Application category wth the name " + category.getName() + " " - + "exists already. Please select a different name"); + throw new ApplicationCategoryManagementException( + "Application category wth the name " + category.getName() + " " + + "exists already. Please select a different name"); } try { ConnectionManagerUtil.beginDBTransaction(); - Category createdCategory = DAOFactory.getApplicationDAO().addCategory(category); + Category createdCategory = DAOFactory.getCategoryDAO().addCategory(category); ConnectionManagerUtil.commitDBTransaction(); return createdCategory; } catch (ApplicationManagementDAOException e) { @@ -64,7 +65,7 @@ public class CategoryManagerImpl implements CategoryManager { public List getCategories() throws ApplicationManagementException { try { ConnectionManagerUtil.openDBConnection(); - return DAOFactory.getApplicationDAO().getCategories(); + return DAOFactory.getCategoryDAO().getCategories(); } finally { ConnectionManagerUtil.closeDBConnection(); } @@ -77,7 +78,7 @@ public class CategoryManagerImpl implements CategoryManager { } try { ConnectionManagerUtil.openDBConnection(); - return DAOFactory.getApplicationDAO().getCategory(name); + return DAOFactory.getCategoryDAO().getCategory(name); } finally { ConnectionManagerUtil.closeDBConnection(); } @@ -92,15 +93,13 @@ public class CategoryManagerImpl implements CategoryManager { } try { ConnectionManagerUtil.beginDBTransaction(); - boolean isApplicationExistForCategory = DAOFactory.getApplicationDAO().isApplicationExistForCategory(name); - + boolean isApplicationExistForCategory = DAOFactory.getApplicationDAO().isApplicationExist(name); if (isApplicationExistForCategory) { ConnectionManagerUtil.rollbackDBTransaction(); throw new ApplicationCategoryManagementException( "Cannot delete the the category " + name + ". Applications " + "exists for this category"); } - - DAOFactory.getApplicationDAO().deleteCategory(name); + DAOFactory.getCategoryDAO().deleteCategory(name); ConnectionManagerUtil.commitDBTransaction(); } catch (ApplicationManagementDAOException e) { ConnectionManagerUtil.rollbackDBTransaction(); @@ -109,5 +108,4 @@ public class CategoryManagerImpl implements CategoryManager { ConnectionManagerUtil.closeDBConnection(); } } - } From a1806eb87e722d89ef63df87b9583001348c9fc4 Mon Sep 17 00:00:00 2001 From: megala21 Date: Mon, 9 Oct 2017 21:15:03 +0530 Subject: [PATCH 6/8] Refactoring --- .../application/mgt/core/dao/common/DAOFactory.java | 8 +++++++- .../mgt/core/impl/ApplicationManagerImpl.java | 9 +-------- .../application/mgt/core/impl/CategoryManagerImpl.java | 5 ++--- 3 files changed, 10 insertions(+), 12 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/common/DAOFactory.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/DAOFactory.java index fa2e94b45dd..88e7bb9f1e2 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/DAOFactory.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/DAOFactory.java @@ -22,7 +22,13 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.application.mgt.common.exception.UnsupportedDatabaseEngineException; import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager; -import org.wso2.carbon.device.application.mgt.core.dao.*; +import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO; +import org.wso2.carbon.device.application.mgt.core.dao.ApplicationReleaseDAO; +import org.wso2.carbon.device.application.mgt.core.dao.CategoryDAO; +import org.wso2.carbon.device.application.mgt.core.dao.LifecycleStateDAO; +import org.wso2.carbon.device.application.mgt.core.dao.PlatformDAO; +import org.wso2.carbon.device.application.mgt.core.dao.SubscriptionDAO; +import org.wso2.carbon.device.application.mgt.core.dao.VisibilityDAO; import org.wso2.carbon.device.application.mgt.core.dao.impl.application.GenericApplicationDAOImpl; import org.wso2.carbon.device.application.mgt.core.dao.impl.application.release.GenericApplicationReleaseDAOImpl; import org.wso2.carbon.device.application.mgt.core.dao.impl.application.release.OracleApplicationDAOImpl; 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 f5e7c84f3c9..a9d5117942d 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 @@ -73,11 +73,10 @@ public class ApplicationManagerImpl implements ApplicationManager { application.setModifiedAt(new Date()); Platform platform = DataHolder.getInstance().getPlatformManager() .getPlatform(application.getUser().getTenantId(), application.getPlatform().getIdentifier()); - if (platform == null) { throw new NotFoundException("Invalid platform is provided for the application " + application.getUuid()); } - + application.setPlatform(platform); Category category = DataHolder.getInstance().getCategoryManager() .getCategory(application.getCategory().getName()); if (category == null) { @@ -86,9 +85,6 @@ public class ApplicationManagerImpl implements ApplicationManager { application.setCategory(category); try { ConnectionManagerUtil.beginDBTransaction(); - - // Validating the platform - application.setPlatform(platform); if (log.isDebugEnabled()) { log.debug("Application creation pre-conditions are met and the platform mentioned by identifier " + platform.getIdentifier() + " is found"); @@ -104,7 +100,6 @@ public class ApplicationManagerImpl implements ApplicationManager { lifecycle.setLifecycleStateModifiedAt(new Date()); lifecycle.setGetLifecycleStateModifiedBy(application.getUser().getUserName()); application.setCurrentLifecycle(lifecycle); - application = DAOFactory.getApplicationDAO().createApplication(application); DataHolder.getInstance().getVisibilityManager().put(application.getId(), application.getVisibility()); ConnectionManagerUtil.commitDBTransaction(); @@ -142,7 +137,6 @@ public class ApplicationManagerImpl implements ApplicationManager { + " is not found. Please give a valid platform identifier."); } application.setPlatform(platform); - if (application.getCategory() != null) { String applicationCategoryName = application.getCategory().getName(); if (applicationCategoryName == null || applicationCategoryName.isEmpty()) { @@ -158,7 +152,6 @@ public class ApplicationManagerImpl implements ApplicationManager { } application.setCategory(category); } - try { ConnectionManagerUtil.beginDBTransaction(); ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO(); 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 632ac600e67..2d547b7bb86 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 @@ -44,9 +44,8 @@ public class CategoryManagerImpl implements CategoryManager { "Application category name cannot be null. Application category creation failed."); } if (getCategory(category.getName()) != null) { - throw new ApplicationCategoryManagementException( - "Application category wth the name " + category.getName() + " " - + "exists already. Please select a different name"); + throw new ApplicationCategoryManagementException("Application category wth the name " + category.getName() + + "exists already. Please select a different name"); } try { ConnectionManagerUtil.beginDBTransaction(); From b32c59b840a6842abc726ec9ea26f59fd51f702a Mon Sep 17 00:00:00 2001 From: megala21 Date: Mon, 9 Oct 2017 21:17:59 +0530 Subject: [PATCH 7/8] Refactoring --- .../org/wso2/carbon/device/application/mgt/api/APIUtil.java | 3 +-- 1 file changed, 1 insertion(+), 2 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 6f75524df8e..8be02fc146e 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 @@ -184,8 +184,7 @@ public class APIUtil { synchronized (APIUtil.class) { if (categoryManager == null) { PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); - categoryManager = (CategoryManager) ctx - .getOSGiService(CategoryManager.class, null); + categoryManager = (CategoryManager) ctx.getOSGiService(CategoryManager.class, null); if (categoryManager == null) { String msg = "Category Manager service has not initialized."; log.error(msg); From 300e7a710ec61873404c4ff62bb1654f3d475685 Mon Sep 17 00:00:00 2001 From: megala21 Date: Mon, 9 Oct 2017 22:03:36 +0530 Subject: [PATCH 8/8] Changes according maven check style plugin --- .../services/ApplicationManagementAPI.java | 2 +- .../api/services/PlatformManagementAPI.java | 5 ++- .../impl/ApplicationManagementAPIImpl.java | 4 +-- .../application/mgt/common/Application.java | 1 - .../services/ApplicationReleaseManager.java | 32 +++++++++--------- .../services/ApplicationStorageManager.java | 33 ++++++++++--------- .../mgt/common/services/CategoryManager.java | 2 -- .../mgt/common/services/PlatformManager.java | 26 +++++++-------- .../services/PlatformStorageManager.java | 11 ++++--- .../mgt/core/dao/common/DAOFactory.java | 2 +- .../impl/platform/GenericPlatformDAOImpl.java | 3 +- .../impl/ApplicationStorageManagerImpl.java | 5 ++- .../mgt/core/util/StorageManagementUtil.java | 7 ++-- 13 files changed, 66 insertions(+), 67 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/ApplicationManagementAPI.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/ApplicationManagementAPI.java index 573e13f458d..acdd989b894 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/ApplicationManagementAPI.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/ApplicationManagementAPI.java @@ -214,7 +214,7 @@ public interface ApplicationManagementAPI { name = "isWithImages", value = "Whether to return application with images", required = false) - @QueryParam("isWithImages") Boolean IsWithImages + @QueryParam("isWithImages") Boolean isWithImages ); @PUT diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/PlatformManagementAPI.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/PlatformManagementAPI.java index ace466cdd83..3a30c15e555 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/PlatformManagementAPI.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/PlatformManagementAPI.java @@ -32,7 +32,6 @@ import org.apache.cxf.jaxrs.ext.multipart.Attachment; import org.apache.cxf.jaxrs.ext.multipart.Multipart; import org.wso2.carbon.apimgt.annotations.api.Scopes; import org.wso2.carbon.device.application.mgt.api.beans.ErrorResponse; -import org.wso2.carbon.device.application.mgt.common.ApplicationRelease; import org.wso2.carbon.device.application.mgt.common.Platform; import javax.validation.constraints.Size; @@ -211,7 +210,7 @@ public interface PlatformManagementAPI { response = ErrorResponse.class) }) Response addPlatform( - @Multipart(value = "Platform", type = "application/json" ) Platform platform, + @Multipart(value = "Platform", type = "application/json") Platform platform, @Multipart(value = "icon", required = false) Attachment iconFile ); @@ -371,7 +370,7 @@ public interface PlatformManagementAPI { response = ErrorResponse.class) }) Response getPlatformTags( - @ApiParam(name = "name", value ="The initial part of the name of platform tags that we need to retrieve", + @ApiParam(name = "name", value = "The initial part of the name of platform tags that we need to retrieve", required = true) @PathParam("name") @Size(min = 3) String name ); 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 34edd4c5d8a..47743b4f728 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 @@ -217,8 +217,8 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { @POST @Path("/upload-image-artifacts/{uuid}") public Response uploadApplicationArtifacts(@PathParam("uuid") String applicationUUID, - @Multipart("icon") Attachment iconFile, @Multipart("banner") Attachment bannerFile, @Multipart - ("screenshot") List attachmentList) { + @Multipart("icon") Attachment iconFile, @Multipart("banner") Attachment bannerFile, + @Multipart("screenshot") List attachmentList) { ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager(); try { InputStream iconFileStream; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Application.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Application.java index a6468de326e..427bceee256 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Application.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Application.java @@ -21,7 +21,6 @@ package org.wso2.carbon.device.application.mgt.common; import org.wso2.carbon.device.application.mgt.common.jaxrs.Exclude; -import java.awt.*; import java.util.ArrayList; import java.util.Date; import java.util.List; 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 a97050d19f0..2f5231d6711 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 @@ -27,46 +27,48 @@ import java.util.List; * ApplicationReleaseManager is responsible for handling all the operations related with * {@link org.wso2.carbon.device.application.mgt.common.ApplicationRelease} which involving addition, updating , * deletion and viewing. - * */ public interface ApplicationReleaseManager { /** * To create an application release for an Application. * - * @param appicationUuid UUID of the Application + * @param appicationUuid UUID of the Application * @param applicationRelease ApplicatonRelease that need to be be created. * @return the unique id of the application release, if the application release succeeded else -1 */ - public ApplicationRelease createRelease(String appicationUuid, ApplicationRelease applicationRelease) throws - ApplicationManagementException; + ApplicationRelease createRelease(String appicationUuid, ApplicationRelease applicationRelease) + throws ApplicationManagementException; /** * To get the application release of the Application/ + * * @param applicationUuid UUID of the Application. - * @param version Version of the ApplicationRelease that need to be retrieved. + * @param version Version of the ApplicationRelease that need to be retrieved. * @return ApplicationRelease related with particular Application UUID and version. * @throws ApplicationManagementException ApplicationManagementException */ - public ApplicationRelease getRelease(String applicationUuid, String version) throws ApplicationManagementException; + ApplicationRelease getRelease(String applicationUuid, String version) throws ApplicationManagementException; /** * To get all the releases of a particular Application. + * * @param applicationUuid UUID of the Application to get all the releases. * @return the List of the Application releases related with the particular Application. * @throws ApplicationManagementException Application Management Exception. */ - public List getReleases(String applicationUuid) throws ApplicationManagementException; + List getReleases(String applicationUuid) throws ApplicationManagementException; /** * To make a particular application release as the default / not default-one - * @param uuid UUID of the application - * @param version Version of the application - * @param isDefault is default or not. + * + * @param uuid UUID of the application + * @param version Version of the application + * @param isDefault is default or not. * @param releaseChannel Release channel to make the * @throws ApplicationManagementException Application Management Exception. */ - public void changeDefaultRelease(String uuid, String version, boolean isDefault, String releaseChannel) + void changeDefaultRelease(String uuid, String version, boolean isDefault, String releaseChannel) throws ApplicationManagementException; /** @@ -77,8 +79,8 @@ public interface ApplicationReleaseManager { * @return Updated Application Release. * @throws ApplicationManagementException Application Management Exception. */ - public ApplicationRelease updateRelease(String applicationUuid, ApplicationRelease applicationRelease) throws - ApplicationManagementException; + ApplicationRelease updateRelease(String applicationUuid, ApplicationRelease applicationRelease) + throws ApplicationManagementException; /** * To delete a particular release @@ -87,7 +89,7 @@ public interface ApplicationReleaseManager { * @param version Version of the ApplicationRelease that need to be deleted. * @throws ApplicationManagementException Application Management Exception. */ - public void deleteApplicationRelease(String applicationUuid, String version) throws ApplicationManagementException; + void deleteApplicationRelease(String applicationUuid, String version) throws ApplicationManagementException; /** * To delete all the application releases related with the the particular application. @@ -95,5 +97,5 @@ public interface ApplicationReleaseManager { * @param applicationUuid UUID of the application. * @throws ApplicationManagementException Application Management Exception. */ - public void deleteApplicationReleases(String applicationUuid) throws ApplicationManagementException; + void deleteApplicationReleases(String applicationUuid) 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/ApplicationStorageManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationStorageManager.java index e1597f87867..e6f60f6bf50 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationStorageManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationStorageManager.java @@ -36,37 +36,40 @@ public interface ApplicationStorageManager { * @param applicationUUID UUID of the application * @param iconFile Icon File input stream * @param bannerFile Banner File input stream - * @throws ApplicationStorageManagementException Application Storage Management Exception. + * @throws ResourceManagementException Resource Management Exception. */ - public void uploadImageArtifacts(String applicationUUID, InputStream iconFile, InputStream bannerFile, + void uploadImageArtifacts(String applicationUUID, InputStream iconFile, InputStream bannerFile, List screenshots) throws ResourceManagementException; /** * To upload release artifacts for an Application. + * * @param applicationUUID UUID of the application related with the release. - * @param versionName Name of version of the Applcation Release. - * @param binaryFile Binary File for the release. - * @throws ApplicationStorageManagementException Application Storage Management Exception. + * @param versionName Name of version of the Applcation Release. + * @param binaryFile Binary File for the release. + * @throws ResourceManagementException Resource Management Exception. */ - public void uploadReleaseArtifacts(String applicationUUID, String versionName, InputStream binaryFile) + void uploadReleaseArtifacts(String applicationUUID, String versionName, InputStream binaryFile) throws ResourceManagementException; /** * To get released artifacts for the particular version of the application. + * * @param applicationUUID UUID of the Application - * @param versionName Version of the release to be retrieved + * @param versionName Version of the release to be retrieved * @return the artifact related with the Application Release. * @throws ApplicationStorageManagementException Application Storage Management Exception. */ - public InputStream getReleasedArtifacts(String applicationUUID, String versionName) throws - ApplicationStorageManagementException; + InputStream getReleasedArtifacts(String applicationUUID, String versionName) + throws ApplicationStorageManagementException; /** * To delete all the artifacts related with a particular Application. + * * @param applicationUUID UUID of the Application. * @throws ApplicationStorageManagementException Application Storage Management Exception. */ - public void deleteApplicationArtifacts(String applicationUUID) throws ApplicationStorageManagementException; + void deleteApplicationArtifacts(String applicationUUID) throws ApplicationStorageManagementException; /** * To delete the artifacts related with particular Application Release. @@ -75,16 +78,16 @@ public interface ApplicationStorageManager { * @param version Version of ApplicationRelease that need to be deleted. * @throws ApplicationStorageManagementException Application Storage Management Exception. */ - public void deleteApplicationReleaseArtifacts(String applicationUUID, String version) + void deleteApplicationReleaseArtifacts(String applicationUUID, String version) throws ApplicationStorageManagementException; /** * To delete all release artifacts related with particular Application Release. + * * @param applicationUUID UUID of the Application. * @throws ApplicationStorageManagementException Application Storage Management Exception */ - public void deleteAllApplicationReleaseArtifacts(String applicationUUID) throws - ApplicationStorageManagementException; + void deleteAllApplicationReleaseArtifacts(String applicationUUID) throws ApplicationStorageManagementException; /** * To get particular image artifact of the application. @@ -95,6 +98,6 @@ public interface ApplicationStorageManager { * @return the relevant image artifact. * @throws ApplicationStorageManagementException Application Storage Management Exception. */ - public ImageArtifact getImageArtifact(String applicationUUID, String name, int count) throws - ApplicationStorageManagementException; + ImageArtifact getImageArtifact(String applicationUUID, String name, int count) + throws ApplicationStorageManagementException; } 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 0b5083adc4b..4bc3d662892 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 @@ -19,8 +19,6 @@ 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; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/PlatformManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/PlatformManager.java index 467be428442..ab7babb5b01 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/PlatformManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/PlatformManager.java @@ -35,7 +35,7 @@ public interface PlatformManager { * @param tenantId ID of the tenant * @throws PlatformManagementException Platform Management Exception */ - public void initialize(int tenantId) throws PlatformManagementException; + void initialize(int tenantId) throws PlatformManagementException; /** * To get platforms of the specific tenant. @@ -44,7 +44,7 @@ public interface PlatformManager { * @return List of platforms * @throws PlatformManagementException Platform Management Exception */ - public List getPlatforms(int tenantId) throws PlatformManagementException; + List getPlatforms(int tenantId) throws PlatformManagementException; /** * To get platform with the given platform identifier and tenant ID. @@ -54,7 +54,7 @@ public interface PlatformManager { * @return the Specific platform with the platform identifier and tenant * @throws PlatformManagementException Platform Management Exception */ - public Platform getPlatform(int tenantId, String platformIdentifier) throws PlatformManagementException; + Platform getPlatform(int tenantId, String platformIdentifier) throws PlatformManagementException; /** * To register a platform under particular tenant. @@ -63,7 +63,7 @@ public interface PlatformManager { * @param platform Platform to be registered * @throws PlatformManagementException Platform Management Exception */ - public void register(int tenantId, Platform platform) throws PlatformManagementException; + void register(int tenantId, Platform platform) throws PlatformManagementException; /** * To update a platform. @@ -73,8 +73,7 @@ public interface PlatformManager { * @param platform Platform to be updated * @throws PlatformManagementException Platform Management Exception */ - public void update(int tenantId, String oldPlatformIdentifier, Platform platform) - throws PlatformManagementException; + void update(int tenantId, String oldPlatformIdentifier, Platform platform) throws PlatformManagementException; /** * To un-register the platform. @@ -84,8 +83,7 @@ public interface PlatformManager { * @param isFileBased To indicate whether a file based or not. * @throws PlatformManagementException Platform Management Exception. */ - public void unregister(int tenantId, String platformIdentifier, boolean isFileBased) - throws PlatformManagementException; + void unregister(int tenantId, String platformIdentifier, boolean isFileBased) throws PlatformManagementException; /** * To add mapping to platform identifiers with the tenant ID. @@ -94,7 +92,7 @@ public interface PlatformManager { * @param platformIdentifiers Platform Identifiers * @throws PlatformManagementException Platform Management Exception */ - public void addMapping(int tenantId, List platformIdentifiers) throws PlatformManagementException; + void addMapping(int tenantId, List platformIdentifiers) throws PlatformManagementException; /** * To add mapping to a platform for a tenant. @@ -103,7 +101,7 @@ public interface PlatformManager { * @param platformIdentifier ID of the platform, the mapping should be added. * @throws PlatformManagementException Platform Management Exception. */ - public void addMapping(int tenantId, String platformIdentifier) throws PlatformManagementException; + void addMapping(int tenantId, String platformIdentifier) throws PlatformManagementException; /** * To remove a mapping of a platform to a tenant. @@ -112,7 +110,7 @@ public interface PlatformManager { * @param platformIdentifier ID of the platform. * @throws PlatformManagementException Platform Management Exception. */ - public void removeMapping(int tenantId, String platformIdentifier) throws PlatformManagementException; + void removeMapping(int tenantId, String platformIdentifier) throws PlatformManagementException; /** * To update the platform status(ENABLED / DISABLED). @@ -122,7 +120,7 @@ public interface PlatformManager { * @param status Status to be updated. * @throws PlatformManagementException Platform Management Exception. */ - public void updatePlatformStatus(int tenantId, String platformIdentifier, String status) + void updatePlatformStatus(int tenantId, String platformIdentifier, String status) throws PlatformManagementException; /** @@ -131,7 +129,7 @@ public interface PlatformManager { * @param tenantId ID of the tenant. * @throws PlatformManagementException Platform Management Exception. */ - public void removePlatforms(int tenantId) throws PlatformManagementException; + void removePlatforms(int tenantId) throws PlatformManagementException; /** * To get the platform tags. @@ -140,5 +138,5 @@ public interface PlatformManager { * @return list of the platform tags that start with the character sequence. * @throws PlatformManagementException PlatformManagement Exception */ - public List getPlatformTags(String name) throws PlatformManagementException; + List getPlatformTags(String name) throws PlatformManagementException; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/PlatformStorageManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/PlatformStorageManager.java index 5b3f373221d..3777086cc5a 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/PlatformStorageManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/PlatformStorageManager.java @@ -33,18 +33,19 @@ public interface PlatformStorageManager { * To upload image artifacts related with an Application. * * @param platformIdentifier Identifier of the platform - * @param iconFile Icon File input stream - * @throws PlatformStorageManagementException Platform Storage Management Exception. + * @param iconFile Icon File input stream + * @throws ResourceManagementException Resource Management Exception. */ - public void uploadIcon(String platformIdentifier, InputStream iconFile) throws ResourceManagementException; + void uploadIcon(String platformIdentifier, InputStream iconFile) throws ResourceManagementException; /** * To get the icon for a particular platform. * * @param platformIdentifier Identifier of the platform. * @return the icon for the given platform. + * @throws PlatformStorageManagementException Platform Storage Management Exception. */ - public ImageArtifact getIcon(String platformIdentifier) throws PlatformStorageManagementException; + ImageArtifact getIcon(String platformIdentifier) throws PlatformStorageManagementException; /** * To delete the icon of a particular platform @@ -52,5 +53,5 @@ public interface PlatformStorageManager { * @param platformIdentifier Identifier of the platform to which delete icon. * @throws PlatformStorageManagementException PlatformStorageManagement Exception. */ - public void deleteIcon(String platformIdentifier) throws PlatformStorageManagementException; + void deleteIcon(String platformIdentifier) throws PlatformStorageManagementException; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/DAOFactory.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/DAOFactory.java index 88e7bb9f1e2..8c63e99cc0c 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/DAOFactory.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/DAOFactory.java @@ -36,8 +36,8 @@ import org.wso2.carbon.device.application.mgt.core.dao.impl.category.GenericCate import org.wso2.carbon.device.application.mgt.core.dao.impl.lifecyclestate.GenericLifecycleStateImpl; import org.wso2.carbon.device.application.mgt.core.dao.impl.platform.GenericPlatformDAOImpl; import org.wso2.carbon.device.application.mgt.core.dao.impl.platform.OracleMsSQLPlatformDAOImpl; -import org.wso2.carbon.device.application.mgt.core.dao.impl.visibility.GenericVisibilityDAOImpl; import org.wso2.carbon.device.application.mgt.core.dao.impl.subscription.GenericSubscriptionDAOImpl; +import org.wso2.carbon.device.application.mgt.core.dao.impl.visibility.GenericVisibilityDAOImpl; import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; import org.wso2.carbon.device.application.mgt.core.util.ApplicationMgtDatabaseCreator; import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; 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/platform/GenericPlatformDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/platform/GenericPlatformDAOImpl.java index 3625a90eaf8..892403abccb 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/platform/GenericPlatformDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/platform/GenericPlatformDAOImpl.java @@ -90,8 +90,7 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD if (isBatchExecutionSupported) { preparedStatement.addBatch(); - } - else { + } else { preparedStatement.execute(); } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationStorageManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationStorageManagerImpl.java index 5ee902e0d63..60cea3d56e3 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationStorageManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationStorageManagerImpl.java @@ -157,10 +157,10 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager throws ResourceManagementException { Application application = validateApplication(applicationUUID); String artifactDirectoryPath = storagePath + application.getId(); - if (log.isDebugEnabled()) + if (log.isDebugEnabled()) { log.debug("Artifact Directory Path for saving the application release related artifacts related with " + "application " + applicationUUID + " is " + artifactDirectoryPath); - + } StorageManagementUtil.createArtifactDirectory(artifactDirectoryPath); if (binaryFile != null) { try { @@ -171,7 +171,6 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager + applicationUUID, e); } } - } @Override diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/StorageManagementUtil.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/StorageManagementUtil.java index 4c8f01250d2..94b05a69ee6 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/StorageManagementUtil.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/StorageManagementUtil.java @@ -21,7 +21,6 @@ package org.wso2.carbon.device.application.mgt.core.util; import org.apache.commons.codec.binary.Base64; import org.apache.commons.io.IOUtils; import org.wso2.carbon.device.application.mgt.common.ImageArtifact; -import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ResourceManagementException; import java.io.File; @@ -32,12 +31,15 @@ import java.io.InputStream; import java.io.OutputStream; import java.nio.file.Files; +/** + * This is a util class that handles Storage Management related tasks. + */ public class StorageManagementUtil { /** * This method is responsible for creating artifact parent directories in the given path. * * @param artifactDirectoryPath Path for the artifact directory. - * @throws ApplicationStorageManagementException Application Storage Management Exception. + * @throws ResourceManagementException Resource Management Exception. */ public static void createArtifactDirectory(String artifactDirectoryPath) throws ResourceManagementException { File artifactDirectory = new File(artifactDirectoryPath); @@ -65,7 +67,6 @@ public class StorageManagementUtil { artifactDirectory.delete(); } - /** * To save a file in a given location. *