From df65b685976cba80c2dd8668f201e0104be2caec Mon Sep 17 00:00:00 2001 From: Inosh Perara Date: Mon, 24 Sep 2018 02:15:28 +0000 Subject: [PATCH 01/11] app get by ID --- .../common/services/ApplicationManager.java | 7 ++- .../mgt/core/dao/ApplicationDAO.java | 11 +++++ .../GenericApplicationDAOImpl.java | 44 ++++++++++++++++++- .../mgt/core/impl/ApplicationManagerImpl.java | 43 +++++++++++++++++- .../services/ApplicationManagementAPI.java | 11 ++--- .../impl/ApplicationManagementAPIImpl.java | 12 ++--- 6 files changed, 107 insertions(+), 21 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java index 28203e646e..7d5af46875 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java @@ -87,14 +87,13 @@ public interface ApplicationManager { String getUuidOfLatestRelease(int appId) throws ApplicationManagementException; /** - * To get Application with the given UUID. + * To get Application with the given Id. * - * @param appType type of the Application - * @param appName name of the Application + * @param id id of the Application * @return the Application identified by the UUID * @throws ApplicationManagementException Application Management Exception. */ - Application getApplication(String appType, String appName) throws ApplicationManagementException; + Application getApplicationById(int id) throws ApplicationManagementException; /** * To get an application associated with the release. 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 b65a266c32..2556238e61 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 @@ -84,6 +84,17 @@ public interface ApplicationDAO { */ Application getApplication(String appName, String appType, int tenantId) throws ApplicationManagementDAOException; + /** + * To get the application with the given id + * + * @param id ID of the application. + * @param tenantId ID of the tenant. + * @return the application + * @throws ApplicationManagementDAOException Application Management DAO Exception. + */ + Application getApplicationById(String id, int tenantId) throws + ApplicationManagementDAOException; + /** * To get the application with the given uuid * 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 70248a15ad..ab294dc15f 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 @@ -337,6 +337,48 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic } } + @Override + public Application getApplicationById(String id, int tenantId) throws + ApplicationManagementDAOException { + if (log.isDebugEnabled()) { + log.debug("Getting application with the id:" + id); + } + Connection conn; + PreparedStatement stmt = null; + ResultSet rs = null; + try { + conn = this.getDBConnection(); + String sql = + "SELECT AP_APP.ID AS APP_ID, AP_APP.NAME AS APP_NAME, AP_APP.TYPE AS APP_TYPE, AP_APP.APP_CATEGORY " + + "AS APP_CATEGORY, AP_APP.SUB_TYPE AS SUB_TYPE ,AP_APP.CURRENCY AS CURRENCY," + + " AP_APP.RESTRICTED AS RESTRICTED, AP_APP_TAG.TAG AS APP_TAG, AP_UNRESTRICTED_ROLE.ROLE " + + "AS ROLE FROM AP_APP, AP_APP_TAG, AP_UNRESTRICTED_ROLE WHERE AP_APP.NAME=? AND " + + "AP_APP.APP_ID= ? AND AP_APP.TENANT_ID=?;"; + + stmt = conn.prepareStatement(sql); + stmt.setString(1, id); + stmt.setInt(2, tenantId); + rs = stmt.executeQuery(); + + if (log.isDebugEnabled()) { + log.debug("Successfully retrieved basic details of the application with the id:" + id); + } + + return Util.loadApplication(rs); + + } catch (SQLException e) { + throw new ApplicationManagementDAOException( + "Error occurred while getting application details with app id " + id + + " While executing query ", e); + } catch (JSONException e) { + throw new ApplicationManagementDAOException("Error occurred while parsing JSON", e); + } catch (DBConnectionException e) { + throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e); + } finally { + Util.cleanupResources(stmt, rs); + } + } + @Override public Application getApplicationById(int applicationId, int tenantId) throws ApplicationManagementDAOException { @@ -420,7 +462,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic int paramIndex = 1; Connection conn; PreparedStatement stmt = null; - Application existingApplication = this.getApplication(application.getName(), application.getType(), tenantId); + Application existingApplication = this.getApplicationById(application.getId(), tenantId); if (existingApplication == null) { throw new ApplicationManagementException("There doesn't have an application for updating"); 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 58099ba071..d8c7706972 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 @@ -276,6 +276,46 @@ public class ApplicationManagerImpl implements ApplicationManager { } + @Override + public Application getApplicationById(int id) throws ApplicationManagementException { + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); + String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); + Application application; + boolean isAppAllowed = false; + List applicationReleases; + try { + ConnectionManagerUtil.openDBConnection(); + application = ApplicationManagementDAOFactory.getApplicationDAO() + .getApplicationById(id, tenantId); + if (isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) { + applicationReleases = getReleases(application.getId()); + application.setApplicationReleases(applicationReleases); + return application; + } + + if (!application.getUnrestrictedRoles().isEmpty()) { + if (isRoleExists(application.getUnrestrictedRoles(), userName)) { + isAppAllowed = true; + } + } else { + isAppAllowed = true; + } + + if (!isAppAllowed) { + return null; + } + + applicationReleases = getReleases(application.getId()); + application.setApplicationReleases(applicationReleases); + return application; + } catch (UserStoreException e) { + throw new ApplicationManagementException( + "User-store exception while getting application with the application id " + id); + } finally { + ConnectionManagerUtil.closeDBConnection(); + } + } + private boolean isRoleExists(Collection unrestrictedRoleList, String userName) throws UserStoreException { String[] roleList; @@ -301,7 +341,6 @@ public class ApplicationManagerImpl implements ApplicationManager { return roleList; } - @Override public Application getApplication(String appType, String appName) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); @@ -311,7 +350,7 @@ public class ApplicationManagerImpl implements ApplicationManager { try { ConnectionManagerUtil.openDBConnection(); application = ApplicationManagementDAOFactory.getApplicationDAO() - .getApplication(appType, appName, tenantId); + .getApplication(appName, appType, tenantId); if (isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) { applicationReleases = getReleases(application.getId()); application.setApplicationReleases(applicationReleases); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementAPI.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementAPI.java index 1dec91b98b..35b70eeba5 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementAPI.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementAPI.java @@ -174,15 +174,10 @@ public interface ApplicationManagementAPI { }) Response getApplication( @ApiParam( - name = "appType", - value = "Type of the application", + name = "appId", + value = "application Id", required = true) - @PathParam("appType") String appType, - @ApiParam( - name = "appName", - value = "Application name", - required = true) - @QueryParam("isWithImages") String appName + @PathParam("appId") int appId ); @PUT diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementAPIImpl.java index 9e27fa77a6..6f16e1dc0f 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementAPIImpl.java @@ -85,23 +85,23 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { } } + @GET @Consumes("application/json") - @Path("/{appType}") + @Path("/{appId}") public Response getApplication( - @PathParam("appType") String appType, - @QueryParam("appName") String appName) { + @PathParam("appId") int appId) { ApplicationManager applicationManager = APIUtil.getApplicationManager(); try { - Application application = applicationManager.getApplication(appType, appName); + Application application = applicationManager.getApplicationById(appId); if (application == null) { return Response.status(Response.Status.NOT_FOUND).entity - ("Application with application type: " + appType + " not found").build(); + ("Application with application id: " + appId + " not found").build(); } return Response.status(Response.Status.OK).entity(application).build(); } catch (ApplicationManagementException e) { - log.error("Error occurred while getting application with the uuid " + appType, e); + log.error("Error occurred while getting application with the id " + appId, e); return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR); } } From 23e3732ac178ad75fe2507a8035a18efa8f40909 Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Mon, 24 Sep 2018 14:03:11 +0530 Subject: [PATCH 02/11] Fix build failure --- .../impl/ApplicationManagementAPIImpl.java | 45 +++++++++++-------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/impl/ApplicationManagementAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/impl/ApplicationManagementAPIImpl.java index cb92a22e13..a5d62ea604 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/impl/ApplicationManagementAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/impl/ApplicationManagementAPIImpl.java @@ -98,32 +98,41 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { @GET @Consumes("application/json") @Path("/{appType}") - public Response getApplication( - @PathParam("appType") String appType, + public Response getApplication(@PathParam("appType") String appType, @QueryParam("appName") String appName) { ApplicationManager applicationManager = APIUtil.getApplicationManager(); - List publishedApplicationRelease = new ArrayList<>(); + List filteredApps = new ArrayList<>(); + Filter filter; try { - Application application = applicationManager.getApplication(appType, appName); - if (application == null) { + filter = new Filter(); + filter.setOffset(0); + filter.setLimit(20); + filter.setAppType(appType); + filter.setAppName(appName); + ApplicationList applications = applicationManager.getApplications(filter); + if (applications.getApplications().isEmpty()) { return Response.status(Response.Status.NOT_FOUND) .entity("Application with application type: " + appType + " not found").build(); } - - for (ApplicationRelease appRelease : application.getApplicationReleases()) { - if (AppLifecycleState.PUBLISHED.toString().equals(appRelease.getLifecycleState().getCurrentState())){ - publishedApplicationRelease.add(appRelease); + for (Application application : applications.getApplications()) { + List publishedApplicationRelease = new ArrayList<>(); + for (ApplicationRelease appRelease : application.getApplicationReleases()) { + if (AppLifecycleState.PUBLISHED.toString() + .equals(appRelease.getLifecycleState().getCurrentState())) { + publishedApplicationRelease.add(appRelease); + } } + if (publishedApplicationRelease.size() > 1) { + String msg = "Application " + application.getName() + + " has more than one PUBLISHED application releases"; + log.error(msg); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } + application.setApplicationReleases(publishedApplicationRelease); + filteredApps.add(application); } - if (publishedApplicationRelease.size() > 1) { - String msg = - "Application " + application.getName() + " has more than one PUBLISHED application releases"; - log.error(msg); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); - } - application.setApplicationReleases(publishedApplicationRelease); - - return Response.status(Response.Status.OK).entity(application).build(); + applications.setApplications(filteredApps); + return Response.status(Response.Status.OK).entity(applications).build(); } catch (NotFoundException e) { return Response.status(Response.Status.NOT_FOUND).build(); } catch (ApplicationManagementException e) { From 7ecaf232f531883233fe1ba4082b02db0839cdaa Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Tue, 25 Sep 2018 08:08:27 +0530 Subject: [PATCH 03/11] Fix store API deploying issue --- .../application/mgt/core/dao/common/Util.java | 15 --- .../core/dao/impl/Review/ReviewDAOImpl.java | 17 ++- .../mgt/core/impl/ReviewManagerImpl.java | 3 +- .../pom.xml | 2 +- .../mgt/publisher/api/ApiOriginFilter.java | 41 ++++++ .../src/main/webapp/WEB-INF/cxf-servlet.xml | 2 +- .../src/main/webapp/WEB-INF/web.xml | 29 ++-- .../pom.xml | 5 +- .../mgt/store/api/ApiOriginFilter.java | 46 +++++++ .../mgt/store/api/ValidationInterceptor.java | 124 ++++++++++++++++++ .../api/services/ReviewManagementAPI.java | 17 ++- .../impl/ReviewManagementAPIImpl.java | 5 +- .../src/main/webapp/WEB-INF/cxf-servlet.xml | 44 +++++-- .../src/main/webapp/WEB-INF/web.xml | 39 +++--- pom.xml | 2 +- 15 files changed, 308 insertions(+), 83 deletions(-) create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/ApiOriginFilter.java create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/ApiOriginFilter.java create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/ValidationInterceptor.java 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/Util.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/Util.java index b3c0e40120..41e635ef51 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/Util.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/Util.java @@ -202,19 +202,4 @@ public class Util { } } } - - public static PaginationRequest validateCommentListPageSize(PaginationRequest paginationRequest) throws - ReviewManagementException { - if (paginationRequest.getLimit() == 0) { - Configuration commentManagementConfig = ConfigurationManager.getInstance().getConfiguration(); - if (commentManagementConfig != null) { - paginationRequest.setLimit( - commentManagementConfig.getPaginationConfiguration().getCommentListPageSize()); - } else { - throw new ReviewManagementException( - "Application Management configuration has not initialized. Please check the application-mgt.xml file."); - } - } - return paginationRequest; - } } 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/Review/ReviewDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/Review/ReviewDAOImpl.java index c1a7a39273..5223207374 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/Review/ReviewDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/Review/ReviewDAOImpl.java @@ -205,11 +205,11 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO { try { conn = this.getDBConnection(); sql = "SELECT AP_APP_REVIEW.ID AS ID, AP_APP_REVIEW.COMMENT AS COMMENT, " - + "AP_APP_REVIEW.CREATED_BY AS CREATED_BY, AP_APP_REVIEW.MODIFIED_BY AS MODIFIED_BY, " - + "AP_APP_REVIEW.PARENT_ID AS PARENT_ID FROM AP_APP_REVIEW, AP_APP_RELEASE WHERE " - + "AP_APP_REVIEW.AP_APP_RELEASE_ID=AP_APP_RELEASE.ID AND AP_APP_RELEASE.UUID =? AND " - + "AP_APP_REVIEW.TENANT_ID = ? AND AP_APP_REVIEW.TENANT_ID = AP_APP_RELEASE.TENANT_ID " - + "LIMIT ? OFFSET ?;"; + + "AP_APP_REVIEW.CREATED_AT AS CREATED_AT, AP_APP_REVIEW.MODIFIED_AT AS MODIFIED_AT, " + + "AP_APP_REVIEW.USERNAME AS USERNAME AP_APP_REVIEW.PARENT_ID AS PARENT_ID " + + "FROM AP_APP_REVIEW, AP_APP_RELEASE WHERE AP_APP_REVIEW.AP_APP_RELEASE_ID=AP_APP_RELEASE.ID AND " + + "AP_APP_RELEASE.UUID =? AND AP_APP_REVIEW.TENANT_ID = ? AND " + + "AP_APP_REVIEW.TENANT_ID = AP_APP_RELEASE.TENANT_ID LIMIT ? OFFSET ?;"; statement = conn.prepareStatement(sql); statement.setString(1, uuid); statement.setInt(2, tenantId); @@ -219,8 +219,11 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO { while (rs.next()) { Review review = new Review(); review.setId(rs.getInt("ID")); - review.setComment(rs.getString("COMMENT_TEXT")); - review.setUsername(rs.getString("CREATED_BY")); + review.setComment(rs.getString("COMMENT")); + review.setCreatedAt(rs.getTimestamp("CREATED_AT")); + review.setModifiedAt(rs.getTimestamp("MODIFIED_AT")); + review.setParentId(rs.getInt("PARENT_ID")); + review.setUsername(rs.getString("USERNAME")); reviews.add(review); } } catch (DBConnectionException e) { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ReviewManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ReviewManagerImpl.java index 11ed6d8cf1..b46c56eb1d 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ReviewManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ReviewManagerImpl.java @@ -34,7 +34,6 @@ import org.wso2.carbon.device.application.mgt.common.services.*; import org.wso2.carbon.device.application.mgt.core.dao.ApplicationReleaseDAO; import org.wso2.carbon.device.application.mgt.core.dao.ReviewDAO; import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOFactory; -import org.wso2.carbon.device.application.mgt.core.dao.common.Util; import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; import org.wso2.carbon.device.application.mgt.core.exception.ReviewManagementDAOException; import org.wso2.carbon.device.application.mgt.core.internal.DataHolder; @@ -176,7 +175,7 @@ public class ReviewManagerImpl implements ReviewManager { } try { ConnectionManagerUtil.openDBConnection(); - reviews = this.reviewDAO.getAllReviews(uuid, Util.validateCommentListPageSize(request), tenantId); + reviews = this.reviewDAO.getAllReviews(uuid, request, tenantId); for (Review review : reviews) { if (hierarchicalReviewSet.containsKey(review.getParentId())) { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/pom.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/pom.xml index f32092e155..201d0eec77 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/pom.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/pom.xml @@ -55,7 +55,7 @@ org.apache.maven.plugins maven-antrun-plugin - 1.7 + 1.8 compile diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/ApiOriginFilter.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/ApiOriginFilter.java new file mode 100644 index 0000000000..65c521244c --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/ApiOriginFilter.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * 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.publisher.api; + +import javax.servlet.*; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +public class ApiOriginFilter implements Filter { + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) + throws IOException, ServletException { + HttpServletResponse res = (HttpServletResponse) response; + res.addHeader("Access-Control-Allow-Origin", "*"); + res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT"); + res.addHeader("Access-Control-Allow-Headers", "Content-Type"); + chain.doFilter(request, response); + } + + public void destroy() { + //do nothing + } + + public void init(FilterConfig filterConfig) throws ServletException { + //do nothing + } +} \ No newline at end of file diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/webapp/WEB-INF/cxf-servlet.xml index 92d7f20330..a75863915b 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -36,7 +36,7 @@ - + diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/webapp/WEB-INF/web.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/webapp/WEB-INF/web.xml index be302ea7ad..a5426c66e9 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/webapp/WEB-INF/web.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/webapp/WEB-INF/web.xml @@ -46,6 +46,17 @@ true + + + + ApplicationMgt-Admin + /* + + + CONFIDENTIAL + + + managed-api-enabled @@ -61,20 +72,8 @@ - CorsFilter - org.apache.catalina.filters.CorsFilter - - cors.allowed.origins - * - - - cors.allowed.methods - GET,POST,DELETE,PUT - - - cors.allowed.headers - Content-Type - + ApiOriginFilter + org.wso2.carbon.device.application.mgt.publisher.api.ApiOriginFilter @@ -114,7 +113,7 @@ - CorsFilter + ApiOriginFilter /* diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/pom.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/pom.xml index f87d02d27c..eac65f0923 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/pom.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/pom.xml @@ -55,7 +55,7 @@ org.apache.maven.plugins maven-antrun-plugin - 1.7 + 1.8 compile @@ -85,7 +85,7 @@ org.codehaus.mojo exec-maven-plugin - 1.2.1 + 1.5.0 test @@ -176,6 +176,7 @@ org.wso2.carbon.devicemgt org.wso2.carbon.device.mgt.common + provided io.swagger diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/ApiOriginFilter.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/ApiOriginFilter.java new file mode 100644 index 0000000000..5c5158c51f --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/ApiOriginFilter.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * 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.store.api; + +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +public class ApiOriginFilter implements Filter { + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) + throws IOException, ServletException { + HttpServletResponse res = (HttpServletResponse) response; + res.addHeader("Access-Control-Allow-Origin", "*"); + res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT"); + res.addHeader("Access-Control-Allow-Headers", "Content-Type"); + chain.doFilter(request, response); + } + + public void destroy() { + //do nothing + } + + public void init(FilterConfig filterConfig) throws ServletException { + //do nothing + } +} \ No newline at end of file diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/ValidationInterceptor.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/ValidationInterceptor.java new file mode 100644 index 0000000000..61b0a0200b --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/ValidationInterceptor.java @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * 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.store.api; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.cxf.interceptor.Fault; +import org.apache.cxf.jaxrs.lifecycle.ResourceProvider; +import org.apache.cxf.jaxrs.model.ClassResourceInfo; +import org.apache.cxf.jaxrs.model.OperationResourceInfo; +import org.apache.cxf.message.Message; +import org.apache.cxf.message.MessageContentsList; +import org.apache.cxf.phase.AbstractPhaseInterceptor; +import org.apache.cxf.phase.Phase; + +import javax.validation.ConstraintViolation; +import javax.validation.ConstraintViolationException; +import javax.validation.Validation; +import javax.validation.Validator; +import javax.validation.ValidatorFactory; +import javax.validation.executable.ExecutableValidator; +import java.lang.reflect.Method; +import java.util.List; +import java.util.Set; + +public class ValidationInterceptor extends AbstractPhaseInterceptor { + private Log log = LogFactory.getLog(getClass()); + private Validator validator = null; //validator interface is thread-safe + + public ValidationInterceptor() { + super(Phase.PRE_INVOKE); + ValidatorFactory defaultFactory = Validation.buildDefaultValidatorFactory(); + validator = defaultFactory.getValidator(); + if (validator == null) { + log.warn("Bean Validation provider could not be found, no validation will be performed"); + } else { + log.debug("Validation In-Interceptor initialized successfully"); + } + } + + @Override + public void handleMessage(Message message) throws Fault { + final OperationResourceInfo operationResource = message.getExchange().get(OperationResourceInfo.class); + if (operationResource == null) { + log.info("OperationResourceInfo is not available, skipping validation"); + return; + } + + final ClassResourceInfo classResource = operationResource.getClassResourceInfo(); + if (classResource == null) { + log.info("ClassResourceInfo is not available, skipping validation"); + return; + } + + final ResourceProvider resourceProvider = classResource.getResourceProvider(); + if (resourceProvider == null) { + log.info("ResourceProvider is not available, skipping validation"); + return; + } + + final List arguments = MessageContentsList.getContentsList(message); + final Method method = operationResource.getAnnotatedMethod(); + final Object instance = resourceProvider.getInstance(message); + if (method != null && arguments != null) { + //validate the parameters(arguments) over the invoked method + validate(method, arguments.toArray(), instance); + + //validate the fields of each argument + for (Object arg : arguments) { + if (arg != null) + validate(arg); + } + } + + } + + public void validate(final Method method, final Object[] arguments, final T instance) { + if (validator == null) { + log.warn("Bean Validation provider could not be found, no validation will be performed"); + return; + } + + ExecutableValidator methodValidator = validator.forExecutables(); + Set> violations = methodValidator.validateParameters(instance, + method, arguments); + + if (!violations.isEmpty()) { + throw new ConstraintViolationException(violations); + } + } + + public void validate(final T object) { + if (validator == null) { + log.warn("Bean Validation provider could be found, no validation will be performed"); + return; + } + + Set> violations = validator.validate(object); + + if (!violations.isEmpty()) { + throw new ConstraintViolationException(violations); + } + } + + public void handleFault(Message messageParam) { + } +} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/ReviewManagementAPI.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/ReviewManagementAPI.java index 1ad57f6f9c..8aa9d305fc 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/ReviewManagementAPI.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/ReviewManagementAPI.java @@ -124,18 +124,17 @@ public interface ReviewManagementAPI { name="uuid", value="uuid of the application release.", required = true) - @PathParam("uuid") - String uuid, + @PathParam("uuid") String uuid, @ApiParam( - name="offSet", - value="Starting review number.",defaultValue = "0") - @QueryParam("offSet") - int offSet, + name="offset", + value="Starting review number.", + defaultValue = "0") + @QueryParam("offSet") int offSet, @ApiParam( name="limit", - value = "Limit of paginated reviews",defaultValue = "20") - @QueryParam("limit") - int limit); + value = "Limit of paginated reviews", + defaultValue = "20") + @QueryParam("limit") int limit); @POST @Path("/{uuid}") diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/impl/ReviewManagementAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/impl/ReviewManagementAPIImpl.java index 202e9a220b..91609bc91b 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/impl/ReviewManagementAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/impl/ReviewManagementAPIImpl.java @@ -35,6 +35,7 @@ import org.wso2.carbon.device.application.mgt.common.PaginationRequest; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ReviewManagementException; +import javax.ws.rs.DefaultValue; import javax.ws.rs.Path; import javax.ws.rs.Consumes; import javax.ws.rs.PathParam; @@ -58,8 +59,8 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI { @Path("/{uuid}") public Response getAllReviews( @PathParam("uuid") String uuid, - @QueryParam("offset") int offSet, - @QueryParam("limit") int limit) { + @DefaultValue("0") @QueryParam("offset") int offSet, + @DefaultValue("20") @QueryParam("limit") int limit) { ReviewManager reviewManager = APIUtil.getReviewManager(); PaginationRequest request = new PaginationRequest(offSet, limit); try { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/webapp/WEB-INF/cxf-servlet.xml index 8e0452c6b3..accba127ed 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -18,29 +18,51 @@ --> + xmlns:jaxrs="http://cxf.apache.org/jaxrs" xmlns:cxf="http://cxf.apache.org/core" + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd + http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd"> - + + + - - - - - + + + + + + + + + + + + - + + + + + + + + + + + + + + + diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/webapp/WEB-INF/web.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/webapp/WEB-INF/web.xml index 7574e19e4c..40fb62988f 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/webapp/WEB-INF/web.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/webapp/WEB-INF/web.xml @@ -19,14 +19,20 @@ - Application Management Webapp + App Store Management Webapp - JAX-WS/JAX-RS Application Management Endpoint + JAX-WS/JAX-RS App Store Management Endpoint JAX-WS/JAX-RS Servlet CXFServlet org.apache.cxf.transport.servlet.CXFServlet + + + swagger.security.filter + ApiAuthorizationFilterImpl + + 1 CXFServlet @@ -40,6 +46,17 @@ true + + + + ApplicationMgt-Admin + /* + + + CONFIDENTIAL + + + managed-api-enabled @@ -55,20 +72,8 @@ - CorsFilter - org.apache.catalina.filters.CorsFilter - - cors.allowed.origins - * - - - cors.allowed.methods - GET,POST,DELETE,PUT - - - cors.allowed.headers - Content-Type - + ApiOriginFilter + org.wso2.carbon.device.application.mgt.store.api.ApiOriginFilter @@ -108,7 +113,7 @@ - CorsFilter + ApiOriginFilter /* diff --git a/pom.xml b/pom.xml index b96ebfe0fc..95948b8f61 100644 --- a/pom.xml +++ b/pom.xml @@ -2100,7 +2100,7 @@ 1.9 - 2.0.4 + 3.1.1 2.0.4.wso2v4 From ea6a64468252ed4b97f714b8f7e6c859c9b22ecb Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Tue, 25 Sep 2018 18:31:54 +0530 Subject: [PATCH 04/11] Improve app manager functionalities --- .../mgt/common/ApplicationRelease.java | 12 --- .../application/mgt/core/dao/common/Util.java | 1 - .../core/dao/impl/Review/ReviewDAOImpl.java | 31 ++++--- .../GenericApplicationDAOImpl.java | 3 +- .../GenericApplicationReleaseDAOImpl.java | 81 +++++++------------ .../GenericLifecycleStateDAOImpl.java | 10 +-- .../mgt/core/impl/ReviewManagerImpl.java | 15 ++-- .../dbscripts/cdm/application-mgt/h2.sql | 14 ++-- .../dbscripts/cdm/application-mgt/mysql.sql | 6 +- 9 files changed, 76 insertions(+), 97 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationRelease.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationRelease.java index 379ef0f691..a2113daf16 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationRelease.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationRelease.java @@ -60,10 +60,6 @@ public class ApplicationRelease { value = "icon file storing location") private String iconLoc; - @ApiModelProperty(name = "applicationCreator", - value = "Application release creator") - private String applicationCreator; - @ApiModelProperty(name = "releaseType", value = "Release type of the application release", required = true, @@ -229,14 +225,6 @@ public class ApplicationRelease { this.screenshotLoc3 = screenshotLoc3; } - public String getApplicationCreator() { - return applicationCreator; - } - - public void setApplicationCreator(String applicationCreator) { - this.applicationCreator = applicationCreator; - } - public String getIconLoc() { return iconLoc; } 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/Util.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/Util.java index 41e635ef51..3ee7b01b2b 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/Util.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/Util.java @@ -169,7 +169,6 @@ public class Util { appRelease.setAppHashValue(rs.getString("APP_HASH_VALUE")); appRelease.setAppStoredLoc(rs.getString("STORED_LOCATION")); appRelease.setBannerLoc(rs.getString("BANNER_LOCATION")); - appRelease.setApplicationCreator(rs.getString("CREATED_BY")); appRelease.setRating(rs.getDouble("RATING")); appRelease.setIsSharedWithAllTenants(rs.getInt("SHARED_WITH_ALL_TENANTS")); appRelease.setMetaData(rs.getString("APP_META_INFO")); 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/Review/ReviewDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/Review/ReviewDAOImpl.java index 5223207374..5d005d4837 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/Review/ReviewDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/Review/ReviewDAOImpl.java @@ -34,7 +34,9 @@ import java.sql.SQLException; import java.sql.ResultSet; import java.sql.Connection; import java.sql.PreparedStatement; +import java.sql.Timestamp; import java.util.ArrayList; +import java.util.Calendar; import java.util.List; /** @@ -53,18 +55,23 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO { } PreparedStatement statement = null; ResultSet rs = null; - sql = "INSERT INTO AP_APP_REVIEW (TENANT_ID, COMMENT, PARENT_ID, USERNAME, AP_APP_RELEASE_ID, AP_APP_ID) " - + "VALUES (?,?,?,?,(SELECT ID FROM AP_APP_RELEASE WHERE UUID= ?)," + sql = "INSERT INTO AP_APP_REVIEW (TENANT_ID, COMMENT, PARENT_ID, USERNAME,CREATED_AT, MODIFIES_AT," + + " AP_APP_RELEASE_ID, AP_APP_ID) VALUES (?,?,?,?,?,?,(SELECT ID FROM AP_APP_RELEASE WHERE UUID= ?)," + "(SELECT AP_APP_ID FROM AP_APP_RELEASE WHERE UUID=?));"; try { + Calendar calendar = Calendar.getInstance(); + Timestamp timestamp = new Timestamp(calendar.getTime().getTime()); + Connection conn = this.getDBConnection(); statement = conn.prepareStatement(sql, new String[] { "id" }); statement.setInt(1, tenantId); statement.setString(2, review.getComment()); statement.setInt(3, review.getParentId()); statement.setString(4, review.getUsername()); - statement.setString(5,uuid); - statement.setString(6,uuid); + statement.setTimestamp(5,timestamp); + statement.setTimestamp(6,timestamp); + statement.setString(7,uuid); + statement.setString(8,uuid); statement.executeUpdate(); rs = statement.getGeneratedKeys(); return rs.next(); @@ -134,15 +141,19 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO { Connection connection; PreparedStatement statement = null; ResultSet rs = null; - sql = "UPDATE AP_APP_REVIEW SET COMMENT=?, RATING=? WHERE ID=? AND USERNAME=? AND TENANT_ID=?;"; + sql = "UPDATE AP_APP_REVIEW SET COMMENT=?, RATING=?, MODIFIED_AT=? WHERE ID=? AND USERNAME=? AND TENANT_ID=?;"; try { + Calendar calendar = Calendar.getInstance(); + Timestamp timestamp = new Timestamp(calendar.getTime().getTime()); + connection = this.getDBConnection(); statement = connection.prepareStatement(sql); statement.setString(1, review.getComment()); statement.setInt(2, review.getRating()); - statement.setInt(3, reviewId); - statement.setString(4, username); - statement.setInt(5, tenantId); + statement.setTimestamp(3, timestamp); + statement.setInt(4, reviewId); + statement.setString(5, username); + statement.setInt(6, tenantId); return statement.executeUpdate(); } catch (SQLException e) { throw new ReviewManagementDAOException("Error occurred while executing review updating query"); @@ -206,7 +217,7 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO { conn = this.getDBConnection(); sql = "SELECT AP_APP_REVIEW.ID AS ID, AP_APP_REVIEW.COMMENT AS COMMENT, " + "AP_APP_REVIEW.CREATED_AT AS CREATED_AT, AP_APP_REVIEW.MODIFIED_AT AS MODIFIED_AT, " - + "AP_APP_REVIEW.USERNAME AS USERNAME AP_APP_REVIEW.PARENT_ID AS PARENT_ID " + + "AP_APP_REVIEW.USERNAME AS USERNAME, AP_APP_REVIEW.PARENT_ID AS PARENT_ID " + "FROM AP_APP_REVIEW, AP_APP_RELEASE WHERE AP_APP_REVIEW.AP_APP_RELEASE_ID=AP_APP_RELEASE.ID AND " + "AP_APP_RELEASE.UUID =? AND AP_APP_REVIEW.TENANT_ID = ? AND " + "AP_APP_REVIEW.TENANT_ID = AP_APP_RELEASE.TENANT_ID LIMIT ? OFFSET ?;"; @@ -230,7 +241,7 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO { throw new ReviewManagementDAOException( "Error occurred while obtaining the DB connection when verifying application existence", e); } catch (SQLException e) { - throw new ReviewManagementDAOException("Error occurred while adding unrestricted roles", e); + throw new ReviewManagementDAOException("DB connection error occurred while getting all reviews", e); }finally { Util.cleanupResources(statement, rs); } 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 ab294dc15f..d66c7e7dc1 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 @@ -116,7 +116,8 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic throw new ApplicationManagementDAOException( "Error occurred while obtaining the DB connection when verifying application existence", e); } catch (SQLException e) { - throw new ApplicationManagementDAOException("Error occurred while adding unrestricted roles", e); + throw new ApplicationManagementDAOException( + "DB connection error occured while checking whether application exist or not.", e); } finally { Util.cleanupResources(stmt, rs); } 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/release/GenericApplicationReleaseDAOImpl.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/release/GenericApplicationReleaseDAOImpl.java index f01753a53b..085c6e3eb2 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/release/GenericApplicationReleaseDAOImpl.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/release/GenericApplicationReleaseDAOImpl.java @@ -21,22 +21,18 @@ package org.wso2.carbon.device.application.mgt.core.dao.impl.application.release 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.ApplicationRelease; import org.wso2.carbon.device.application.mgt.common.Rating; import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException; import org.wso2.carbon.device.application.mgt.core.dao.ApplicationReleaseDAO; 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.dao.impl.application.GenericApplicationDAOImpl; 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.sql.Timestamp; import java.util.ArrayList; import java.util.List; @@ -65,8 +61,8 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements String sql = "INSERT INTO AP_APP_RELEASE (VERSION,TENANT_ID,UUID,RELEASE_TYPE, PACKAGE_NAME, APP_PRICE," + "STORED_LOCATION, BANNER_LOCATION, SC_1_LOCATION,SC_2_LOCATION,SC_3_LOCATION, APP_HASH_VALUE," - + "SHARED_WITH_ALL_TENANTS, APP_META_INFO,CREATED_BY,AP_APP_ID) " - + "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, ?);"; + + "SHARED_WITH_ALL_TENANTS, APP_META_INFO,AP_APP_ID) " + + "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);"; int index = 0; String generatedColumns[] = {"ID"}; @@ -87,7 +83,6 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements statement.setString(++index, applicationRelease.getAppHashValue()); statement.setInt(++index, applicationRelease.getIsSharedWithAllTenants()); statement.setString(++index, applicationRelease.getMetaData()); - statement.setString(++index, applicationRelease.getApplicationCreator()); statement.setInt(++index, appId); statement.executeUpdate(); resultSet = statement.getGeneratedKeys(); @@ -107,7 +102,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements } /** - * To get release details of a specific application. + * To get latest updated app release details of a specific application. * * @param applicationName Name of the application. * @param applicationType Type of the application. @@ -123,16 +118,15 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements Connection connection; PreparedStatement statement = null; ResultSet resultSet = null; - String sql = "SELECT AR.ID AS RELESE_ID, AR.VERSION AS RELEASE_VERSION, AR.UUID, AR.RELEASE_TYPE, " - + "AR.PACKAGE_NAME AS PACKAGE_NAME, AR.APP_PRICE, AR.STORED_LOCATION, AR.BANNER_LOCATION, " - + "AR.SC_1_LOCATION AS SCREEN_SHOT_1, AR.SC_2_LOCATION AS SCREEN_SHOT_2, AR.SC_3_LOCATION AS " - + "SCREEN_SHOT_3, AR.APP_HASH_VALUE AS HASH_VALUE, AR.SHARED_WITH_ALL_TENANTS AS SHARED, " - + "AR.APP_META_INFO, AR.CREATED_BY, AR.CREATED_AT, AR.PUBLISHED_BY, AR.PUBLISHED_AT, AR.STARS, " - + "AL.CURRENT_STATE, AL.PREVIOUSE_STATE, AL.UPDATED_BY, AL.UPDATED_AT FROM " - + "AP_APP_RELEASE AS AR, AP_APP_LIFECYCLE_STATE AS AL WHERE " - + "AR.AP_APP_ID=(SELECT ID FROM AP_APP WHERE NAME=? AND TYPE=? AND TENANT_ID=?) " - + "AND AR.VERSION=? AND AR.RELEASE_TYPE=? AND AL.AP_APP_RELEASE_ID=AR.ID " - + "AND AL.TENANT_ID=AR.TENANT_ID ORDER BY AL.UPDATED_AT DESC;"; + String sql = "SELECT AR.ID AS RELESE_ID, AR.VERSION AS RELEASE_VERSION, AR.UUID AS UUID, AR.RELEASE_TYPE AS " + + "RELEASE_TYPE, AR.PACKAGE_NAME AS PACKAGE_NAME, AR.APP_PRICE AS APP_PRICE, AR.STORED_LOCATION AS " + + "STORED_LOCATION, AR.BANNER_LOCATION AS BANNER_LOCATION, AR.SC_1_LOCATION AS SCREEN_SHOT_1, " + + "AR.SC_2_LOCATION AS SCREEN_SHOT_2, AR.SC_3_LOCATION AS SCREEN_SHOT_3, AR.APP_HASH_VALUE AS " + + "HASH_VALUE, AR.SHARED_WITH_ALL_TENANTS AS SHARED, AR.APP_META_INFO AS APP_META_INFO , " + + "AR.RATING AS RATING, AL.CURRENT_STATE, AL.PREVIOUS_STATE, AL.UPDATED_BY, AL.UPDATED_AT FROM " + + "AP_APP_RELEASE AS AR, AP_APP_LIFECYCLE_STATE AS AL WHERE AR.AP_APP_ID=(SELECT ID FROM AP_APP WHERE " + + "NAME=? AND TYPE=? AND TENANT_ID=?) AND AR.VERSION=? AND AR.RELEASE_TYPE=? AND " + + "AL.AP_APP_RELEASE_ID=AR.ID AND AL.TENANT_ID=AR.TENANT_ID ORDER BY AL.UPDATED_AT DESC;"; try { connection = this.getDBConnection(); @@ -179,7 +173,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements + " AR.STORED_LOCATION, AR.BANNER_LOCATION, AR.SC_1_LOCATION AS SCREEN_SHOT_1, " + "AR.SC_2_LOCATION AS SCREEN_SHOT_2, AR.SC_3_LOCATION AS SCREEN_SHOT_3, AR.APP_HASH_VALUE AS " + "HASH_VALUE, AR.SHARED_WITH_ALL_TENANTS AS SHARED, AR.APP_META_INFO, AR.CREATED_BY, AR.CREATED_AT, AR" + - ".PUBLISHED_BY, AR.PUBLISHED_AT, AR.STARS, AL.CURRENT_STATE, AL.PREVIOUSE_STATE, AL.UPDATED_BY, " + + ".PUBLISHED_BY, AR.PUBLISHED_AT, AR.STARS, AL.CURRENT_STATE, AL.PREVIOUS_STATE, AL.UPDATED_BY, " + "AL.UPDATED_AT FROM AP_APP_RELEASE AS AR, AP_APP_LIFECYCLE_STATE AS AL WHERE " + "AR.AP_APP_ID = ? AND AR.UUID = ? AND AR.TENANT_ID = ? AND AL.AP_APP_RELEASE_ID=AR.ID AND " + "AL.TENANT_ID = AR.TENANT_ID ORDER BY AL.UPDATED_AT DESC;"; @@ -226,13 +220,13 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements PreparedStatement statement = null; ResultSet resultSet = null; List applicationReleases = new ArrayList<>(); - String sql = "SELECT AR.ID AS RELESE_ID, AR.VERSION AS RELEASE_VERSION, AR.UUID, AR.RELEASE_TYPE, AR.APP_PRICE," - + " AR.STORED_LOCATION, AR.BANNER_LOCATION, AR.SC_1_LOCATION AS SCREEN_SHOT_1, AR.SC_2_LOCATION AS " - + "SCREEN_SHOT_2, AR.SC_3_LOCATION AS SCREEN_SHOT_3, AR.APP_HASH_VALUE AS HASH_VALUE, " - + "AR.SHARED_WITH_ALL_TENANTS AS SHARED, AR.APP_META_INFO, AR.CREATED_BY, AR.CREATED_AT, " - + "AR.PUBLISHED_BY, AR.PUBLISHED_AT, AR.STARS, AR.RATING FROM AP_APP_RELEASE AS " - + "AR where AR.AP_APP_ID=(SELECT ID FROM AP_APP WHERE NAME = ? AND TYPE = ? " - + "AND TENANT_ID = ?) AND AR.TENANT_ID = ? ;"; + String sql = "SELECT AR.ID AS RELESE_ID, AR.VERSION AS RELEASE_VERSION, AR.UUID, AR.RELEASE_TYPE " + + "AS RELEASE_TYPE, AR.PACKAGE_NAME AS PACKAGE_NAME, AR.APP_PRICE, AR.STORED_LOCATION, " + + "AR.BANNER_LOCATION, AR.SC_1_LOCATION AS SCREEN_SHOT_1, AR.SC_2_LOCATION AS SCREEN_SHOT_2, " + + "AR.SC_3_LOCATION AS SCREEN_SHOT_3, AR.APP_HASH_VALUE AS HASH_VALUE, " + + "AR.SHARED_WITH_ALL_TENANTS AS SHARED, AR.APP_META_INFO AS APP_META_INFO, " + + "AR.RATING AS RATING FROM AP_APP_RELEASE AS AR where AR.AP_APP_ID=(SELECT ID FROM AP_APP " + + "WHERE NAME = ? AND TYPE = ? AND TENANT_ID = ?) AND AR.TENANT_ID = ?;"; try { connection = this.getDBConnection(); @@ -244,22 +238,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements resultSet = statement.executeQuery(); while (resultSet.next()) { - ApplicationRelease applicationRelease = new ApplicationRelease(); - applicationRelease.setId(resultSet.getInt("RELESE_ID")); - applicationRelease.setVersion(resultSet.getString("RELEASE_VERSION")); - applicationRelease.setUuid(resultSet.getString("UUID")); - applicationRelease.setReleaseType(resultSet.getString("RELEASE_TYPE")); - applicationRelease.setPrice(resultSet.getDouble("APP_PRICE")); - applicationRelease.setAppStoredLoc(resultSet.getString("STORED_LOCATION")); - applicationRelease.setBannerLoc(resultSet.getString("BANNER_LOCATION")); - applicationRelease.setScreenshotLoc1(resultSet.getString("SCREEN_SHOT_1")); - applicationRelease.setScreenshotLoc2(resultSet.getString("SCREEN_SHOT_2")); - applicationRelease.setScreenshotLoc3(resultSet.getString("SCREEN_SHOT_3")); - applicationRelease.setAppHashValue(resultSet.getString("HASH_VALUE")); - applicationRelease.setIsSharedWithAllTenants(resultSet.getInt("SHARED")); - applicationRelease.setMetaData(resultSet.getString("APP_META_INFO")); - applicationRelease.setApplicationCreator(resultSet.getString("CREATED_BY")); - applicationRelease.setRating(resultSet.getDouble("RATING")); + ApplicationRelease applicationRelease = constructApplicationRelease(resultSet); applicationReleases.add(applicationRelease); } @@ -287,7 +266,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements public void updateRatingValue(String uuid, double rating, int ratedUsers) throws ApplicationManagementDAOException { Connection connection; PreparedStatement statement = null; - String sql = "UPDATE AP_APP_RELEASE SET RATING = ? AND RATED_USERS = ? WHERE UUID = ?;"; + String sql = "UPDATE AP_APP_RELEASE SET RATING = ?,RATED_USERS = ? WHERE UUID = ?;"; try { connection = this.getDBConnection(); statement = connection.prepareStatement(sql); @@ -354,11 +333,10 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements throws ApplicationManagementDAOException { Connection connection; PreparedStatement statement = null; - String sql = "UPDATE AP_APP_RELEASE SET VERSION = ? AND UUID = ? AND RELEASE_TYPE = ? AND PACKAGE_NAME = ? " - + "AND APP_PRICE = ? AND STORED_LOCATION = ? AND BANNER_LOCATION = ? AND SC_1_LOCATION = ? " - + "AND SC_2_LOCATION = ? AND SC_3_LOCATION = ? AND APP_HASH_VALUE = ? AND SHARED_WITH_ALL_TENANTS = ? " - + "AND APP_META_INFO = ? AND CREATED_BY = ? AND CREATED_AT = ? WHERE AP_APP_ID = ? AND TENANT_ID = ? " - + "AND ID = ?;"; + String sql = "UPDATE AP_APP_RELEASE SET VERSION = ?, UUID = ?, RELEASE_TYPE = ?, PACKAGE_NAME = ?," + + " APP_PRICE = ?, STORED_LOCATION = ?, BANNER_LOCATION = ?, SC_1_LOCATION = ?, SC_2_LOCATION = ?," + + " SC_3_LOCATION = ?, APP_HASH_VALUE = ?, SHARED_WITH_ALL_TENANTS = ?, APP_META_INFO = ? " + + "WHERE AP_APP_ID = ? AND TENANT_ID = ? AND ID = ?;"; try { connection = this.getDBConnection(); statement = connection.prepareStatement(sql); @@ -375,8 +353,10 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements statement.setString(11, applicationRelease.getAppHashValue()); statement.setInt(12, applicationRelease.getIsSharedWithAllTenants()); statement.setString(13, applicationRelease.getMetaData()); - statement.setString(14, applicationRelease.getApplicationCreator()); - statement.setTimestamp(15, new Timestamp(System.currentTimeMillis())); + statement.setInt(14,applicationId); + statement.setInt(15, tenantId); + statement.setInt(16, applicationRelease.getId()); + statement.executeUpdate(); } catch (DBConnectionException e) { throw new ApplicationManagementDAOException( @@ -441,7 +421,6 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements applicationRelease.setAppHashValue(resultSet.getString("HASH_VALUE")); applicationRelease.setIsSharedWithAllTenants(resultSet.getInt("SHARED")); applicationRelease.setMetaData(resultSet.getString("APP_META_INFO")); - applicationRelease.setApplicationCreator(resultSet.getString("CREATED_BY")); applicationRelease.setRating(resultSet.getDouble("RATING")); return applicationRelease; 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/lifecyclestate/GenericLifecycleStateDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/GenericLifecycleStateDAOImpl.java index c9286d0ffc..3103f2f814 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/GenericLifecycleStateDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/GenericLifecycleStateDAOImpl.java @@ -46,7 +46,7 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif ResultSet rs = null; try { conn = this.getDBConnection(); - String sql = "SELECT ID, CURRENT_STATE, PREVIOUSE_STATE, TENANT_ID, UPDATED_AT, UPDATED_BY FROM " + String sql = "SELECT ID, CURRENT_STATE, PREVIOUS_STATE, TENANT_ID, UPDATED_AT, UPDATED_BY FROM " + "AP_APP_LIFECYCLE_STATE WHERE AP_APP_RELEASE_ID=? ORDER BY UPDATED_AT DESC;"; stmt = conn.prepareStatement(sql); @@ -58,7 +58,7 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif lifecycleState = new LifecycleState(); lifecycleState.setId(rs.getInt("ID")); lifecycleState.setCurrentState(rs.getString("CURRENT_STATE")); - lifecycleState.setPreviousState(rs.getString("PREVIOUSE_STATE")); + lifecycleState.setPreviousState(rs.getString("PREVIOUS_STATE")); lifecycleState.setUpdatedAt(rs.getTimestamp("UPDATED_AT")); lifecycleState.setUpdatedBy(rs.getString("UPDATED_BY")); } @@ -82,7 +82,7 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif ResultSet rs = null; try { conn = this.getDBConnection(); - String sql = "SELECT ID, CURRENT_STATE, PREVIOUSE_STATE, TENANT_ID, UPDATED_AT, UPDATED_BY FROM " + String sql = "SELECT ID, CURRENT_STATE, PREVIOUS_STATE, TENANT_ID, UPDATED_AT, UPDATED_BY FROM " + "AP_APP_LIFECYCLE_STATE WHERE AP_APP_RELEASE_ID = ? ORDER BY UPDATED_AT ASC;"; stmt = conn.prepareStatement(sql); stmt.setInt(1,appReleaseId); @@ -91,7 +91,7 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif LifecycleState lifecycleState = new LifecycleState(); lifecycleState.setId(rs.getInt("ID")); lifecycleState.setCurrentState(rs.getString("CURRENT_STATE")); - lifecycleState.setPreviousState(rs.getString("PREVIOUSE_STATE")); + lifecycleState.setPreviousState(rs.getString("PREVIOUS_STATE")); lifecycleState.setUpdatedAt(rs.getTimestamp("UPDATED_AT")); lifecycleState.setUpdatedBy(rs.getString("UPDATED_BY")); lifecycleStates.add(lifecycleState); @@ -113,7 +113,7 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif PreparedStatement stmt = null; try { conn = this.getDBConnection(); - String sql = "INSERT INTO AP_APP_LIFECYCLE_STATE (CURRENT_STATE, PREVIOUSE_STATE, TENANT_ID, UPDATED_BY, " + String sql = "INSERT INTO AP_APP_LIFECYCLE_STATE (CURRENT_STATE, PREVIOUS_STATE, TENANT_ID, UPDATED_BY, " + "AP_APP_RELEASE_ID, AP_APP_ID) VALUES (?,?, ?, ?,?,?);"; stmt = conn.prepareStatement(sql); stmt.setString(1, state.getCurrentState()); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ReviewManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ReviewManagerImpl.java index b46c56eb1d..7d116ea391 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ReviewManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ReviewManagerImpl.java @@ -70,7 +70,7 @@ public class ReviewManagerImpl implements ReviewManager { String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); boolean isSuccess = false; try { - ConnectionManagerUtil.beginDBTransaction(); + ConnectionManagerUtil.openDBConnection(); Review existingReview = reviewDAO.haveUerCommented(uuid, username, tenantId); if (existingReview != null && isAuthorizedUser(username, existingReview.getUsername(), tenantId) && review.getRating() > 0 && review.getRating() != existingReview.getRating()) { @@ -81,12 +81,13 @@ public class ReviewManagerImpl implements ReviewManager { Runnable task = () -> calculateRating(review.getRating(), -12345, uuid); new Thread(task).start(); review.setUsername(username); + ConnectionManagerUtil.beginDBTransaction(); isSuccess = this.reviewDAO.addReview(review, uuid, tenantId); - } - if (isSuccess) { - ConnectionManagerUtil.commitDBTransaction(); - } else { - ConnectionManagerUtil.rollbackDBTransaction(); + if (isSuccess) { + ConnectionManagerUtil.commitDBTransaction(); + } else { + ConnectionManagerUtil.rollbackDBTransaction(); + } } return isSuccess; } catch (DBConnectionException e) { @@ -115,8 +116,8 @@ public class ReviewManagerImpl implements ReviewManager { log.debug("Review updating request is received for the review id " + reviewId); } try { - ConnectionManagerUtil.openDBConnection(); if (existingReview == null) { + ConnectionManagerUtil.openDBConnection(); existingReview = this.reviewDAO.getReview(reviewId); if (existingReview != null && isAuthorizedUser(username, existingReview.getUsername(), tenantId)) { if (review.getRating() > 0 && review.getRating() != existingReview.getRating()) { 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 710182c632..54fe2f0960 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 @@ -51,9 +51,9 @@ CREATE TABLE IF NOT EXISTS AP_APP_REVIEW ( ID INT(11) NOT NULL AUTO_INCREMENT, TENANT_ID VARCHAR(45) NOT NULL, COMMENT VARCHAR(250) NOT NULL, - REPLY_COMMENT VARCHAR(250) NULL, - CREATED_AT TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - MODEFIED_AT TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PARENT_ID INT(11) NULL, + CREATED_AT TIMESTAMP NOT NULL, + MODEFIED_AT TIMESTAMP NOT NULL, RATING INT(11) NULL, USERNAME VARCHAR(45) NOT NULL, AP_APP_RELEASE_ID INT(11) NOT NULL, @@ -75,7 +75,7 @@ CREATE TABLE IF NOT EXISTS AP_APP_LIFECYCLE_STATE ( PREVIOUSE_STATE VARCHAR(45) NOT NULL, TENANT_ID VARCHAR(45) NOT NULL, UPDATED_BY VARCHAR(100) NOT NULL, - UPDATED_AT TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + UPDATED_AT TIMESTAMP NOT NULL, AP_APP_RELEASE_ID INT(11) NOT NULL, AP_APP_ID INT(11) NOT NULL, PRIMARY KEY (ID, AP_APP_RELEASE_ID, AP_APP_ID), @@ -109,7 +109,7 @@ CREATE TABLE IF NOT EXISTS AP_DEVICE_SUBSCRIPTION ( ID INT(11) NOT NULL AUTO_INCREMENT, TENANT_ID VARCHAR(45) NOT NULL, SUBSCRIBED_BY VARCHAR(100) NOT NULL, - SUBSCRIBED_TIMESTAMP TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + SUBSCRIBED_TIMESTAMP TIMESTAMP NOT NULL, UNSUBSCRIBED INT(11) NULL DEFAULT NULL, UNSUBSCRIBED_BY INT(11) NULL DEFAULT NULL, UNSUBSCRIBED_TIMESTAMP TIMESTAMP NULL DEFAULT NULL, @@ -131,7 +131,7 @@ CREATE TABLE IF NOT EXISTS AP_GROUP_SUBSCRIPTION ( ID INT(11) NOT NULL AUTO_INCREMENT, TENANT_ID VARCHAR(45) NOT NULL, SUBSCRIBED_BY VARCHAR(100) NOT NULL, - SUBSCRIBED_TIMESTAMP TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + SUBSCRIBED_TIMESTAMP TIMESTAMP NOT NULL, UNSUBSCRIBED INT(11) NULL DEFAULT NULL, UNSUBSCRIBED_BY INT(11) NULL DEFAULT NULL, UNSUBSCRIBED_TIMESTAMP TIMESTAMP NULL DEFAULT NULL, @@ -154,7 +154,7 @@ CREATE TABLE IF NOT EXISTS AP_ROLE_SUBSCRIPTION ( TENANT_ID VARCHAR(45) NOT NULL, ROLE_NAME VARCHAR(100) NOT NULL, SUBSCRIBED_BY VARCHAR(100) NOT NULL, - SUBSCRIBED_TIMESTAMP TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + SUBSCRIBED_TIMESTAMP TIMESTAMP NOT NULL, UNSUBSCRIBED INT(11) NULL DEFAULT NULL, UNSUBSCRIBED_BY INT(11) NULL DEFAULT NULL, UNSUBSCRIBED_TIMESTAMP TIMESTAMP NULL DEFAULT NULL, 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 641c994660..058feaaa5f 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 @@ -68,9 +68,9 @@ CREATE TABLE IF NOT EXISTS `AP_APP_REVIEW` ( `ID` INT(11) NOT NULL AUTO_INCREMENT, `TENANT_ID` VARCHAR(45) NOT NULL, `COMMENT` VARCHAR(250) NOT NULL, - `REPLY_COMMENT` VARCHAR(250) NULL, + `PARENT_ID` INT(11) NULL, `CREATED_AT` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - `MODEFIED_AT` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `MODIFIED_AT` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `RATING` INT(11) NULL, `USERNAME` VARCHAR(45) NOT NULL, `AP_APP_RELEASE_ID` INT(11) NOT NULL, @@ -93,7 +93,7 @@ CREATE INDEX `fk_AP_APP_COMMENT_AP_APP_RELEASE1_idx` ON `AP_APP_REVIEW` (`AP_APP CREATE TABLE IF NOT EXISTS `AP_APP_LIFECYCLE_STATE` ( `ID` INT(11) NOT NULL AUTO_INCREMENT, `CURRENT_STATE` VARCHAR(45) NOT NULL, - `PREVIOUSE_STATE` VARCHAR(45) NOT NULL, + `PREVIOUS_STATE` VARCHAR(45) NOT NULL, `TENANT_ID` VARCHAR(45) NOT NULL, `UPDATED_BY` VARCHAR(100) NOT NULL, `UPDATED_AT` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, From 6f020076c5a3786792d8b1272e20525892304fe9 Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Wed, 26 Sep 2018 14:22:25 +0530 Subject: [PATCH 05/11] Fix API tags registering issue --- .../apimgt/application/extension/api/util/APIUtil.java | 5 ++--- .../mgt/store/api/services/ReviewManagementAPI.java | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/util/APIUtil.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/util/APIUtil.java index 4aedb87877..ad8d57cfa4 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/util/APIUtil.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/util/APIUtil.java @@ -31,7 +31,6 @@ import org.wso2.carbon.registry.core.exceptions.RegistryException; import org.wso2.carbon.registry.core.service.RegistryService; import org.wso2.carbon.user.core.service.RealmService; -import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; @@ -45,7 +44,7 @@ public class APIUtil { private static final String DEFAULT_AGENT_API_TAG = "device_agent"; private static final String DEFAULT_CERT_API_TAG = "scep_management"; private static final String DEFAULT_APP_MGT_TAG = "application_management"; - private static final String DEFAULT_APP_MGT_LCYCLE_MGT_TAG = "lifecycle_management"; + private static final String DEFAULT_APP_MGT_REVIEW_MGT_TAG = "review_management"; private static final String DEFAULT_APP_MGT_SUB_MGT_TAG = "subscription_management"; public static final String PERMISSION_PROPERTY_NAME = "name"; @@ -112,7 +111,7 @@ public class APIUtil { allowedApisTags.add(DEFAULT_CERT_API_TAG); allowedApisTags.add(DEFAULT_AGENT_API_TAG); allowedApisTags.add(DEFAULT_APP_MGT_TAG); - allowedApisTags.add(DEFAULT_APP_MGT_LCYCLE_MGT_TAG); + allowedApisTags.add(DEFAULT_APP_MGT_REVIEW_MGT_TAG); allowedApisTags.add(DEFAULT_APP_MGT_SUB_MGT_TAG); return allowedApisTags; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/ReviewManagementAPI.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/ReviewManagementAPI.java index 8aa9d305fc..6c8852aba7 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/ReviewManagementAPI.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/ReviewManagementAPI.java @@ -63,7 +63,7 @@ import java.util.List; } ), tags = { - @Tag(name = "store_management", description = "Review Management related APIs") + @Tag(name = "review_management", description = "Review Management related APIs") } ) @Scopes( From 94d3f1b3b1ac0d74a31bdfb61e3be6c2c5e2794a Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Wed, 26 Sep 2018 18:02:03 +0530 Subject: [PATCH 06/11] Fix SQL issues --- .../device/application/mgt/common/Filter.java | 10 +++++++ .../GenericApplicationDAOImpl.java | 17 ++++++++--- .../mgt/core/impl/ApplicationManagerImpl.java | 2 +- .../services/ApplicationManagementAPI.java | 29 +++++++++++++++---- .../impl/ApplicationManagementAPIImpl.java | 23 +++++++++++++-- .../dbscripts/cdm/application-mgt/h2.sql | 15 +++++----- .../dbscripts/cdm/application-mgt/mysql.sql | 15 +++++----- 7 files changed, 83 insertions(+), 28 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Filter.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Filter.java index 144abba320..96ee8e49bd 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Filter.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Filter.java @@ -40,6 +40,8 @@ public class Filter { required = false) private String appType; + private String appCategory; + @ApiModelProperty( name = "isFullMatch", value = "Checking the application name matches fully with given name", @@ -111,4 +113,12 @@ public class Filter { public void setAppType(String appType) { this.appType = appType; } + + public String getAppCategory() { + return appCategory; + } + + public void setAppCategory(String appCategory) { + this.appCategory = appCategory; + } } 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 d66c7e7dc1..5847eda9b8 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 @@ -147,11 +147,17 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic throw new ApplicationManagementDAOException("Filter need to be instantiated"); } - if (filter.getAppType() != null) { + if (filter.getAppType() != null && !filter.getAppType().isEmpty()) { sql += " AND AP_APP.TYPE "; sql += "= ?"; } - if (filter.getAppName() != null) { + + if (filter.getAppCategory() != null && !filter.getAppCategory().isEmpty()) { + sql += " AND AP_APP.APP_CATEGORY "; + sql += "= ?"; + } + + if (filter.getAppName() != null && !filter.getAppName().isEmpty()) { sql += " AND LOWER (AP_APP.NAME) "; if (filter.isFullMatch()) { sql += "= ?"; @@ -175,10 +181,13 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic stmt.setInt(paramIndex++, tenantId); stmt.setString(paramIndex++, AppLifecycleState.REMOVED.toString()); - if (filter.getAppType() != null) { + if (filter.getAppType() != null && !filter.getAppType().isEmpty()) { stmt.setString(paramIndex++, filter.getAppType()); } - if (filter.getAppName() != null) { + if (filter.getAppCategory() != null && !filter.getAppCategory().isEmpty()) { + stmt.setString(paramIndex++, filter.getAppCategory()); + } + if (filter.getAppName() != null && !filter.getAppName().isEmpty()) { if (filter.isFullMatch()) { stmt.setString(paramIndex++, filter.getAppName().toLowerCase()); } else { 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 d8c7706972..52073bdbae 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 @@ -215,7 +215,7 @@ public class ApplicationManagerImpl implements ApplicationManager { ConnectionManagerUtil.getDBConnection(); applicationList = applicationDAO.getApplications(filter, tenantId); if(applicationList != null && applicationList.getApplications() != null && applicationList - .getApplications().size() > 0) { + .getApplications().isEmpty()) { if (!isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) { applicationList = getRoleRestrictedApplicationList(applicationList, userName); } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementAPI.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementAPI.java index 35b70eeba5..3459bd7d81 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementAPI.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementAPI.java @@ -39,6 +39,7 @@ import java.util.List; import javax.validation.Valid; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; +import javax.ws.rs.DefaultValue; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.PUT; @@ -125,10 +126,21 @@ public interface ApplicationManagementAPI { }) Response getApplications( @ApiParam( - name = "filter", - value = "Filter to get application list", - required = true) - @Valid Filter filter, + name = "name", + value = "Name of the application") + @QueryParam("name") String appName, + @ApiParam( + name = "type", + value = "Type of the application") + @QueryParam("type") String appType, + @ApiParam( + name = "category", + value = "Category of the application") + @QueryParam("category") String appCategory, + @ApiParam( + name = "exact-match", + value = "Is it requesting exactly matching application or partially matching application.") + @QueryParam("exact-match") boolean isFullMatch, @ApiParam( name = "offset", value = "offset", @@ -138,11 +150,16 @@ public interface ApplicationManagementAPI { name = "limit", value = "limit", defaultValue = "20") - @QueryParam("limit") int limit + @QueryParam("limit") int limit, + @ApiParam( + name = "sort", + value = "Sorting type", + defaultValue = "AES") + @QueryParam("sort") String sortBy ); @GET - @Path("/{appType}") + @Path("/{appId}") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @ApiOperation( diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementAPIImpl.java index 6f16e1dc0f..eec6282e85 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementAPIImpl.java @@ -41,6 +41,7 @@ import java.util.UUID; import javax.validation.Valid; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; +import javax.ws.rs.DefaultValue; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.PUT; @@ -64,14 +65,30 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { @Override @Consumes("application/json") public Response getApplications( - @Valid Filter filter, - @QueryParam("offset") int offset, - @QueryParam("limit") int limit) { + @QueryParam("name") String appName, + @QueryParam("type") String appType, + @QueryParam("category") String appCategory, + @QueryParam("exact-match") boolean isFullMatch, + @DefaultValue("0") @QueryParam("offset") int offset, + @DefaultValue("20") @QueryParam("limit") int limit, + @DefaultValue("ASC") @QueryParam("sort") String sortBy) { ApplicationManager applicationManager = APIUtil.getApplicationManager(); try { + Filter filter = new Filter(); filter.setOffset(offset); filter.setLimit(limit); + filter.setSortBy(sortBy); + filter.setFullMatch(isFullMatch); + if (appName != null && !appName.isEmpty()) { + filter.setAppName(appName); + } + if (appType != null && !appType.isEmpty()) { + filter.setAppType(appType); + } + if (appCategory != null && !appCategory.isEmpty()) { + filter.setAppCategory(appCategory); + } ApplicationList applications = applicationManager.getApplications(filter); if (applications.getApplications().isEmpty()) { return Response.status(Response.Status.NOT_FOUND).entity 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 54fe2f0960..6bada31a2a 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 @@ -20,17 +20,18 @@ CREATE TABLE IF NOT EXISTS AP_APP ( -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS AP_APP_RELEASE ( ID INT(11) NOT NULL AUTO_INCREMENT, - VERSION VARCHAR(10) NOT NULL, + VERSION VARCHAR(25) NOT NULL, TENANT_ID VARCHAR(45) NOT NULL, UUID VARCHAR(200) NOT NULL, RELEASE_TYPE VARCHAR(45) NOT NULL, + PACKAGE_NAME VARCHAR(45) NOT NULL, APP_PRICE DECIMAL(6,2) NULL DEFAULT NULL, - STORED_LOCATION VARCHAR(45) NOT NULL, - BANNER_LOCATION VARCHAR(45) NOT NULL, - SC_1_LOCATION VARCHAR(45) NOT NULL, - SC_2_LOCATION VARCHAR(45) NULL DEFAULT NULL, - SC_3_LOCATION VARCHAR(45) NULL DEFAULT NULL, - APP_HASH_VALUE VARCHAR(1000) NOT NULL, + STORED_LOCATION VARCHAR(100) NOT NULL, + BANNER_LOCATION VARCHAR(100) NOT NULL, + SC_1_LOCATION VARCHAR(100) NOT NULL, + SC_2_LOCATION VARCHAR(100) NULL DEFAULT NULL, + SC_3_LOCATION VARCHAR(100) NULL DEFAULT NULL, + APP_HASH_VALUE VARCHAR(100) NOT NULL, SHARED_WITH_ALL_TENANTS INT(11) NULL DEFAULT NULL, APP_META_INFO VARCHAR(20000) NULL DEFAULT NULL, RATING DOUBLE NULL DEFAULT NULL, 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 058feaaa5f..eb5d1d5f3f 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 @@ -32,17 +32,18 @@ CREATE TABLE IF NOT EXISTS `AP_APP` ( -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `AP_APP_RELEASE` ( `ID` INT(11) NOT NULL AUTO_INCREMENT, - `VERSION` VARCHAR(10) NOT NULL, + `VERSION` VARCHAR(25) NOT NULL, `TENANT_ID` VARCHAR(45) NOT NULL, `UUID` VARCHAR(200) NOT NULL, `RELEASE_TYPE` VARCHAR(45) NOT NULL, + `PACKAGE_NAME` VARCHAR(45) NOT NULL, `APP_PRICE` DECIMAL(6,2) NULL DEFAULT NULL, - `STORED_LOCATION` VARCHAR(45) NOT NULL, - `BANNER_LOCATION` VARCHAR(45) NOT NULL, - `SC_1_LOCATION` VARCHAR(45) NOT NULL, - `SC_2_LOCATION` VARCHAR(45) NULL DEFAULT NULL, - `SC_3_LOCATION` VARCHAR(45) NULL DEFAULT NULL, - `APP_HASH_VALUE` VARCHAR(1000) NOT NULL, + `STORED_LOCATION` VARCHAR(100) NOT NULL, + `BANNER_LOCATION` VARCHAR(100) NOT NULL, + `SC_1_LOCATION` VARCHAR(100) NOT NULL, + `SC_2_LOCATION` VARCHAR(100) NULL DEFAULT NULL, + `SC_3_LOCATION` VARCHAR(100) NULL DEFAULT NULL, + `APP_HASH_VALUE` VARCHAR(100) NOT NULL, `SHARED_WITH_ALL_TENANTS` INT(11) NULL DEFAULT NULL, `APP_META_INFO` VARCHAR(20000) NULL DEFAULT NULL, `RATING` DOUBLE NULL DEFAULT NULL, From abf9c05f0c909eea95414e63fffe2f8fdb5bc6ad Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Thu, 27 Sep 2018 08:15:19 +0530 Subject: [PATCH 07/11] Improve applications retreving method --- .../common/services/ApplicationManager.java | 17 +++-- .../mgt/core/dao/ApplicationReleaseDAO.java | 5 +- .../GenericApplicationReleaseDAOImpl.java | 24 +++--- .../mgt/core/impl/ApplicationManagerImpl.java | 73 +++++++++++++++---- 4 files changed, 78 insertions(+), 41 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java index 7d5af46875..44733a2f37 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java @@ -121,14 +121,15 @@ public interface ApplicationManager { */ Boolean isUserAllowable(List unrestrictedRoles, String userName) throws ApplicationManagementException; - /** - * To get all the releases of a particular Application. - * - * @param applicationId ID 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. - */ - List getReleases(int applicationId) throws ApplicationManagementException; +// todo +// /** +// * To get all the releases of a particular Application. +// * +// * @param applicationId ID 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. +// */ +// List getinstallableReleases(int applicationId) throws ApplicationManagementException; /** * To get all the releases of a particular Application. diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationReleaseDAO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationReleaseDAO.java index 1add29c835..a62053a377 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationReleaseDAO.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationReleaseDAO.java @@ -58,13 +58,12 @@ public interface ApplicationReleaseDAO { /** * To get all the releases of a particular application. * - * @param applicationName Name of the Application - * @param applicationType Type of the Application + * @param applicationId Id of the Application * @param tenantId tenant id of the application * @return list of the application releases * @throws ApplicationManagementDAOException Application Management DAO Exception. */ - List getReleases(String applicationName, String applicationType, int tenantId) throws + List getReleases(int applicationId, int tenantId) 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/release/GenericApplicationReleaseDAOImpl.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/release/GenericApplicationReleaseDAOImpl.java index 085c6e3eb2..4445bcf717 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/release/GenericApplicationReleaseDAOImpl.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/release/GenericApplicationReleaseDAOImpl.java @@ -118,7 +118,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements Connection connection; PreparedStatement statement = null; ResultSet resultSet = null; - String sql = "SELECT AR.ID AS RELESE_ID, AR.VERSION AS RELEASE_VERSION, AR.UUID AS UUID, AR.RELEASE_TYPE AS " + String sql = "SELECT AR.ID AS RELEASE_ID, AR.VERSION AS RELEASE_VERSION, AR.UUID AS UUID, AR.RELEASE_TYPE AS " + "RELEASE_TYPE, AR.PACKAGE_NAME AS PACKAGE_NAME, AR.APP_PRICE AS APP_PRICE, AR.STORED_LOCATION AS " + "STORED_LOCATION, AR.BANNER_LOCATION AS BANNER_LOCATION, AR.SC_1_LOCATION AS SCREEN_SHOT_1, " + "AR.SC_2_LOCATION AS SCREEN_SHOT_2, AR.SC_3_LOCATION AS SCREEN_SHOT_3, AR.APP_HASH_VALUE AS " @@ -169,7 +169,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements Connection connection; PreparedStatement statement = null; ResultSet resultSet = null; - String sql = "SELECT AR.ID AS RELESE_ID, AR.VERSION AS RELEASE_VERSION, AR.UUID, AR.RELEASE_TYPE, AR.APP_PRICE," + String sql = "SELECT AR.ID AS RELEASE_ID, AR.VERSION AS RELEASE_VERSION, AR.UUID, AR.RELEASE_TYPE, AR.APP_PRICE," + " AR.STORED_LOCATION, AR.BANNER_LOCATION, AR.SC_1_LOCATION AS SCREEN_SHOT_1, " + "AR.SC_2_LOCATION AS SCREEN_SHOT_2, AR.SC_3_LOCATION AS SCREEN_SHOT_3, AR.APP_HASH_VALUE AS " + "HASH_VALUE, AR.SHARED_WITH_ALL_TENANTS AS SHARED, AR.APP_META_INFO, AR.CREATED_BY, AR.CREATED_AT, AR" + @@ -208,33 +208,29 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements /** * To insert the application release properties. * - * @param applicationName Name of the application. - * @param applicationType Type of the application. + * @param applicationId Id of the application. * @param tenantId Tenant Id * @throws ApplicationManagementDAOException Application Management DAO Exception. */ @Override - public List getReleases(String applicationName, String applicationType, int tenantId) + public List getReleases(int applicationId, int tenantId) throws ApplicationManagementDAOException { Connection connection; PreparedStatement statement = null; ResultSet resultSet = null; List applicationReleases = new ArrayList<>(); - String sql = "SELECT AR.ID AS RELESE_ID, AR.VERSION AS RELEASE_VERSION, AR.UUID, AR.RELEASE_TYPE " + String sql = "SELECT AR.ID AS RELEASE_ID, AR.VERSION AS RELEASE_VERSION, AR.UUID, AR.RELEASE_TYPE " + "AS RELEASE_TYPE, AR.PACKAGE_NAME AS PACKAGE_NAME, AR.APP_PRICE, AR.STORED_LOCATION, " + "AR.BANNER_LOCATION, AR.SC_1_LOCATION AS SCREEN_SHOT_1, AR.SC_2_LOCATION AS SCREEN_SHOT_2, " + "AR.SC_3_LOCATION AS SCREEN_SHOT_3, AR.APP_HASH_VALUE AS HASH_VALUE, " + "AR.SHARED_WITH_ALL_TENANTS AS SHARED, AR.APP_META_INFO AS APP_META_INFO, " - + "AR.RATING AS RATING FROM AP_APP_RELEASE AS AR where AR.AP_APP_ID=(SELECT ID FROM AP_APP " - + "WHERE NAME = ? AND TYPE = ? AND TENANT_ID = ?) AND AR.TENANT_ID = ?;"; + + "AR.RATING AS RATING FROM AP_APP_RELEASE AS AR where AR.AP_APP_ID=? AND AR.TENANT_ID = ?;"; try { connection = this.getDBConnection(); statement = connection.prepareStatement(sql); - statement.setString(1, applicationName); - statement.setString(2, applicationType); - statement.setInt(3, tenantId); - statement.setInt(4, tenantId); + statement.setInt(1, applicationId); + statement.setInt(2, tenantId); resultSet = statement.executeQuery(); while (resultSet.next()) { @@ -245,10 +241,10 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements return applicationReleases; } catch (DBConnectionException e) { throw new ApplicationManagementDAOException("Database connection exception while trying to get the " - + "release details of the application with Name " + applicationName, e); + + "release details of the application with app ID: " + applicationId, e); } catch (SQLException e) { throw new ApplicationManagementDAOException( - "Error while getting all the release details of the " + applicationName + " application" + "Error while getting all the release details of the app ID: " + applicationId + ", while executing the query " + sql, e); } finally { Util.cleanupResources(statement, resultSet); 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 52073bdbae..adf98a7c18 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 @@ -31,7 +31,6 @@ import org.wso2.carbon.device.application.mgt.common.ApplicationSubscriptionType import org.wso2.carbon.device.application.mgt.common.ApplicationType; import org.wso2.carbon.device.application.mgt.common.Filter; import org.wso2.carbon.device.application.mgt.common.LifecycleState; -import org.wso2.carbon.device.application.mgt.common.SortingOrder; import org.wso2.carbon.device.application.mgt.common.Tag; import org.wso2.carbon.device.application.mgt.common.UnrestrictedRole; import org.wso2.carbon.device.application.mgt.common.User; @@ -51,7 +50,6 @@ import org.wso2.carbon.device.application.mgt.core.internal.DataHolder; import org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManger; import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO; import org.wso2.carbon.device.mgt.core.dto.DeviceType; import org.wso2.carbon.user.api.UserRealm; @@ -214,13 +212,13 @@ public class ApplicationManagerImpl implements ApplicationManager { try { ConnectionManagerUtil.getDBConnection(); applicationList = applicationDAO.getApplications(filter, tenantId); - if(applicationList != null && applicationList.getApplications() != null && applicationList + if(applicationList != null && applicationList.getApplications() != null && !applicationList .getApplications().isEmpty()) { if (!isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) { applicationList = getRoleRestrictedApplicationList(applicationList, userName); } for (Application application : applicationList.getApplications()) { - applicationReleases = getReleases(application.getId()); + applicationReleases = getReleases(application, false); application.setApplicationReleases(applicationReleases); } } @@ -288,7 +286,7 @@ public class ApplicationManagerImpl implements ApplicationManager { application = ApplicationManagementDAOFactory.getApplicationDAO() .getApplicationById(id, tenantId); if (isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) { - applicationReleases = getReleases(application.getId()); + applicationReleases = getReleases(application, false); application.setApplicationReleases(applicationReleases); return application; } @@ -305,7 +303,7 @@ public class ApplicationManagerImpl implements ApplicationManager { return null; } - applicationReleases = getReleases(application.getId()); + applicationReleases = getReleases(application, false); application.setApplicationReleases(applicationReleases); return application; } catch (UserStoreException e) { @@ -352,7 +350,7 @@ public class ApplicationManagerImpl implements ApplicationManager { application = ApplicationManagementDAOFactory.getApplicationDAO() .getApplication(appName, appType, tenantId); if (isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) { - applicationReleases = getReleases(application.getId()); + applicationReleases = getReleases(application, false); application.setApplicationReleases(applicationReleases); return application; } @@ -369,7 +367,7 @@ public class ApplicationManagerImpl implements ApplicationManager { return null; } - applicationReleases = getReleases(application.getId()); + applicationReleases = getReleases(application, false); application.setApplicationReleases(applicationReleases); return application; } catch (UserStoreException e) { @@ -424,11 +422,38 @@ public class ApplicationManagerImpl implements ApplicationManager { } } - @Override - public List getReleases(int applicationId) throws ApplicationManagementException { +// todo +// public List getinstallableReleases(int applicationId) throws ApplicationManagementException { +// int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); +// +// Application application = getApplicationIfAccessible(applicationId); +// List applicationReleases; +// List filteredApplicationReleases = new ArrayList<>(); +// if (log.isDebugEnabled()) { +// log.debug("Request is received to retrieve all the releases related with the application " + application +// .toString()); +// } +// ConnectionManagerUtil.getDBConnection(); +// applicationReleases = this.applicationReleaseDAO.getReleases(application.getName(), application.getType(), tenantId); +// for (ApplicationRelease applicationRelease : applicationReleases) { +// LifecycleState lifecycleState = ApplicationManagementDAOFactory.getLifecycleStateDAO(). +// getLatestLifeCycleStateByReleaseID(applicationRelease.getId()); +// if (lifecycleState != null) { +// applicationRelease.setLifecycleState(lifecycleState); +// +// if (!AppLifecycleState.REMOVED.toString() +// .equals(applicationRelease.getLifecycleState().getCurrentState())) { +// filteredApplicationReleases.add(applicationRelease); +// } +// } +// } +// return filteredApplicationReleases; +// +// } + + private List getReleases(Application application, boolean requirePublishedRelease) + throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); - - Application application = getApplicationIfAccessible(applicationId); List applicationReleases; List filteredApplicationReleases = new ArrayList<>(); if (log.isDebugEnabled()) { @@ -436,7 +461,7 @@ public class ApplicationManagerImpl implements ApplicationManager { .toString()); } ConnectionManagerUtil.getDBConnection(); - applicationReleases = this.applicationReleaseDAO.getReleases(application.getName(), application.getType(), tenantId); + applicationReleases = this.applicationReleaseDAO.getReleases(application.getId(), tenantId); for (ApplicationRelease applicationRelease : applicationReleases) { LifecycleState lifecycleState = ApplicationManagementDAOFactory.getLifecycleStateDAO(). getLatestLifeCycleStateByReleaseID(applicationRelease.getId()); @@ -445,19 +470,34 @@ public class ApplicationManagerImpl implements ApplicationManager { if (!AppLifecycleState.REMOVED.toString() .equals(applicationRelease.getLifecycleState().getCurrentState())) { - filteredApplicationReleases.add(applicationRelease); + if (requirePublishedRelease){ + if (AppLifecycleState.PUBLISHED.toString() + .equals(applicationRelease.getLifecycleState().getCurrentState())){ + filteredApplicationReleases.add(applicationRelease); + } + }else{ + filteredApplicationReleases.add(applicationRelease); + } } } } + + if (requirePublishedRelease && filteredApplicationReleases.size() > 1) { + log.error("There are more than one published application releases for application ID: " + application + .getId()); + } return filteredApplicationReleases; } + + @Override public List deleteApplication(int applicationId) throws ApplicationManagementException { String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); List storedLocations = new ArrayList<>(); + Application application; try { if (!isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) { @@ -466,10 +506,11 @@ public class ApplicationManagerImpl implements ApplicationManager { "need to have admin permission"); } - if (getApplicationIfAccessible(applicationId) == null) { + application = getApplicationIfAccessible(applicationId); + if ( application == null) { throw new ApplicationManagementException("Invalid Application"); } - List applicationReleases = getReleases(applicationId); + List applicationReleases = getReleases(application, false); if (log.isDebugEnabled()) { log.debug("Request is received to delete applications which are related with the application id " + applicationId); From f4e1ca6815ab8a14c9c325fcb75a9abc3c3f5b2c Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Thu, 27 Sep 2018 09:24:31 +0530 Subject: [PATCH 08/11] Improve publisher APIs --- .../device/application/mgt/common/Filter.java | 63 ++++++++++--------- .../common/services/ApplicationManager.java | 3 +- .../mgt/core/impl/ApplicationManagerImpl.java | 8 +-- .../services/ApplicationManagementAPI.java | 8 +++ .../impl/ApplicationManagementAPIImpl.java | 6 +- 5 files changed, 52 insertions(+), 36 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Filter.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Filter.java index 96ee8e49bd..0d1c5b693c 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Filter.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Filter.java @@ -18,54 +18,51 @@ */ package org.wso2.carbon.device.application.mgt.common; -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; - /** * Filter represents a criteria that can be used for searching applications. */ - -@ApiModel(value = "Filter", description = "This is related to the application filtering.") public class Filter { - @ApiModelProperty( - name = "appName", - value = "Name of the application", - required = false) + /** + * Name of the application + */ private String appName; - @ApiModelProperty( - name = "appType", - value = "Type of the application", - required = false) + /** + * Type of the application + */ private String appType; + /** + * Category of the application + */ private String appCategory; - @ApiModelProperty( - name = "isFullMatch", - value = "Checking the application name matches fully with given name", - required = false) + /** + * Checking the application name matches fully with given name + */ private boolean isFullMatch; - @ApiModelProperty( - name = "limit", - value = "Limit of the applications", - required = false) + /** + * Limit of the applications + */ private int limit; - @ApiModelProperty( - name = "offset", - value = "Started from", - required = false) + /** + * Started from + */ private int offset; - @ApiModelProperty( - name = "sortBy", - value = "Ascending or descending order", - required = false) + /** + * Ascending or descending order + */ private String sortBy; + /** + * Set as True if required to have only published application release, otherwise set to False + */ + private boolean requirePublishedRelease; + public int getLimit() { return limit; } @@ -121,4 +118,12 @@ public class Filter { public void setAppCategory(String appCategory) { this.appCategory = appCategory; } + + public boolean isRequirePublishedRelease() { + return requirePublishedRelease; + } + + public void setRequirePublishedRelease(boolean requirePublishedRelease) { + this.requirePublishedRelease = requirePublishedRelease; + } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java index 44733a2f37..a4260704d4 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java @@ -90,10 +90,11 @@ public interface ApplicationManager { * To get Application with the given Id. * * @param id id of the Application + * @param requirePublishedReleases If it is required to have only published application release set to True, otherwise set to false * @return the Application identified by the UUID * @throws ApplicationManagementException Application Management Exception. */ - Application getApplicationById(int id) throws ApplicationManagementException; + Application getApplicationById(int id, boolean requirePublishedReleases) throws ApplicationManagementException; /** * To get an application associated with the release. 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 adf98a7c18..2ca8c4b250 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 @@ -218,7 +218,7 @@ public class ApplicationManagerImpl implements ApplicationManager { applicationList = getRoleRestrictedApplicationList(applicationList, userName); } for (Application application : applicationList.getApplications()) { - applicationReleases = getReleases(application, false); + applicationReleases = getReleases(application, filter.isRequirePublishedRelease()); application.setApplicationReleases(applicationReleases); } } @@ -275,7 +275,7 @@ public class ApplicationManagerImpl implements ApplicationManager { } @Override - public Application getApplicationById(int id) throws ApplicationManagementException { + public Application getApplicationById(int id, boolean requirePublishedReleases) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); Application application; @@ -286,7 +286,7 @@ public class ApplicationManagerImpl implements ApplicationManager { application = ApplicationManagementDAOFactory.getApplicationDAO() .getApplicationById(id, tenantId); if (isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) { - applicationReleases = getReleases(application, false); + applicationReleases = getReleases(application, requirePublishedReleases); application.setApplicationReleases(applicationReleases); return application; } @@ -303,7 +303,7 @@ public class ApplicationManagerImpl implements ApplicationManager { return null; } - applicationReleases = getReleases(application, false); + applicationReleases = getReleases(application, requirePublishedReleases); application.setApplicationReleases(applicationReleases); return application; } catch (UserStoreException e) { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementAPI.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementAPI.java index 3459bd7d81..1151dc3d6e 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementAPI.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementAPI.java @@ -141,6 +141,10 @@ public interface ApplicationManagementAPI { name = "exact-match", value = "Is it requesting exactly matching application or partially matching application.") @QueryParam("exact-match") boolean isFullMatch, + @ApiParam( + name = "published-release", + value = "If set to True, only get published release for the application") + @QueryParam("published-release") boolean requirePublishedReleases, @ApiParam( name = "offset", value = "offset", @@ -190,6 +194,10 @@ public interface ApplicationManagementAPI { response = ErrorResponse.class) }) Response getApplication( + @ApiParam( + name = "published-release", + value = "If set to True, only get published release for the application") + @QueryParam("published-release") boolean requirePublishedReleases, @ApiParam( name = "appId", value = "application Id", diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementAPIImpl.java index eec6282e85..2b1ee720cb 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementAPIImpl.java @@ -49,7 +49,6 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; /** @@ -69,6 +68,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { @QueryParam("type") String appType, @QueryParam("category") String appCategory, @QueryParam("exact-match") boolean isFullMatch, + @QueryParam("published-release") boolean requirePublishedReleases, @DefaultValue("0") @QueryParam("offset") int offset, @DefaultValue("20") @QueryParam("limit") int limit, @DefaultValue("ASC") @QueryParam("sort") String sortBy) { @@ -80,6 +80,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { filter.setLimit(limit); filter.setSortBy(sortBy); filter.setFullMatch(isFullMatch); + filter.setRequirePublishedRelease(requirePublishedReleases); if (appName != null && !appName.isEmpty()) { filter.setAppName(appName); } @@ -107,10 +108,11 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { @Consumes("application/json") @Path("/{appId}") public Response getApplication( + @QueryParam("published-release") boolean requirePublishedReleases, @PathParam("appId") int appId) { ApplicationManager applicationManager = APIUtil.getApplicationManager(); try { - Application application = applicationManager.getApplicationById(appId); + Application application = applicationManager.getApplicationById(appId, requirePublishedReleases); if (application == null) { return Response.status(Response.Status.NOT_FOUND).entity ("Application with application id: " + appId + " not found").build(); From 409f6fce149fb3657455ca2b6285cceb857a9578 Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Thu, 27 Sep 2018 18:47:54 +0530 Subject: [PATCH 09/11] Fix get lifecycle issue --- .../common/services/ApplicationManager.java | 14 +------ .../mgt/core/dao/LifecycleStateDAO.java | 2 + .../GenericLifecycleStateDAOImpl.java | 42 ++++++++++++++++++- .../mgt/core/impl/ApplicationManagerImpl.java | 39 ++--------------- .../core/lifecycle/LifecycleStateManger.java | 6 ++- .../LifecycleManagementTest.java | 6 +-- 6 files changed, 56 insertions(+), 53 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java index a4260704d4..83c4e67495 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java @@ -122,25 +122,15 @@ public interface ApplicationManager { */ Boolean isUserAllowable(List unrestrictedRoles, String userName) throws ApplicationManagementException; -// todo -// /** -// * To get all the releases of a particular Application. -// * -// * @param applicationId ID 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. -// */ -// List getinstallableReleases(int applicationId) throws ApplicationManagementException; - /** * To get all the releases of a particular Application. * * @param applicationId ID of the Application . - * @param applicationUuid UUID of the Application Release. + * @param releaseUuid UUID of the Application Release. * @return the LifecycleState of the Application releases related with the particular Application. * @throws ApplicationManagementException Application Management Exception. */ - LifecycleState getLifecycleState(int applicationId, String applicationUuid) throws ApplicationManagementException; + LifecycleState getLifecycleState(int applicationId, String releaseUuid) throws ApplicationManagementException; /** * To get all the releases of a particular Application. diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/LifecycleStateDAO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/LifecycleStateDAO.java index 6fec1ee2b0..5ab07f9307 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/LifecycleStateDAO.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/LifecycleStateDAO.java @@ -31,6 +31,8 @@ public interface LifecycleStateDAO { LifecycleState getLatestLifeCycleStateByReleaseID(int applicationReleaseId) throws ApplicationManagementDAOException; + LifecycleState getLatestLifeCycleState(int appId, String uuid) throws ApplicationManagementDAOException; + List getLifecycleStates(int appReleaseId) throws LifeCycleManagementDAOException; void addLifecycleState(LifecycleState state, int appId, int releaseId, int tenantId) throws LifeCycleManagementDAOException; 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/lifecyclestate/GenericLifecycleStateDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/GenericLifecycleStateDAOImpl.java index 3103f2f814..a122d3159d 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/GenericLifecycleStateDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/GenericLifecycleStateDAOImpl.java @@ -74,6 +74,44 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif } } + public LifecycleState getLatestLifeCycleState(int appId, String uuid) throws ApplicationManagementDAOException{ + Connection conn = null; + PreparedStatement stmt = null; + ResultSet rs = null; + try { + conn = this.getDBConnection(); + String sql = "SELECT ID, CURRENT_STATE, PREVIOUS_STATE, TENANT_ID, UPDATED_AT, UPDATED_BY FROM " + + "AP_APP_LIFECYCLE_STATE WHERE AP_APP_ID=? AND AP_APP_RELEASE_ID=(SELECT ID FROM AP_APP_RELEASE " + + "WHERE UUID=?) ORDER BY UPDATED_AT DESC;"; + + stmt = conn.prepareStatement(sql); + stmt.setInt(1, appId); + stmt.setString(2, uuid); + rs = stmt.executeQuery(); + LifecycleState lifecycleState = null; + + if (rs.next()) { + lifecycleState = new LifecycleState(); + lifecycleState.setId(rs.getInt("ID")); + lifecycleState.setCurrentState(rs.getString("CURRENT_STATE")); + lifecycleState.setPreviousState(rs.getString("PREVIOUS_STATE")); + lifecycleState.setUpdatedAt(rs.getTimestamp("UPDATED_AT")); + lifecycleState.setUpdatedBy(rs.getString("UPDATED_BY")); + } + return lifecycleState; + + } catch (SQLException e) { + throw new ApplicationManagementDAOException("Error occurred while getting application List", e); + } catch (DBConnectionException e) { + throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection to get latest" + + " lifecycle state for a specific application", e); + } finally { + Util.cleanupResources(stmt, rs); + } + + } + + @Override public List getLifecycleStates(int appReleaseId) throws LifeCycleManagementDAOException { List lifecycleStates = new ArrayList<>(); @@ -116,8 +154,8 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif String sql = "INSERT INTO AP_APP_LIFECYCLE_STATE (CURRENT_STATE, PREVIOUS_STATE, TENANT_ID, UPDATED_BY, " + "AP_APP_RELEASE_ID, AP_APP_ID) VALUES (?,?, ?, ?,?,?);"; stmt = conn.prepareStatement(sql); - stmt.setString(1, state.getCurrentState()); - stmt.setString(2, state.getPreviousState()); + stmt.setString(1, state.getCurrentState().toUpperCase()); + stmt.setString(2, state.getPreviousState().toUpperCase()); stmt.setInt(3, tenantId); stmt.setString(4, state.getUpdatedBy()); stmt.setInt(5, releaseId); 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 2ca8c4b250..9a65522076 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 @@ -67,7 +67,6 @@ import java.util.List; public class ApplicationManagerImpl implements ApplicationManager { private static final Log log = LogFactory.getLog(ApplicationManagerImpl.class); - private DeviceTypeDAO deviceTypeDAO; private VisibilityDAO visibilityDAO; private ApplicationDAO applicationDAO; private ApplicationReleaseDAO applicationReleaseDAO; @@ -81,7 +80,6 @@ public class ApplicationManagerImpl implements ApplicationManager { } private void initDataAccessObjects() { - this.deviceTypeDAO = ApplicationManagementDAOFactory.getDeviceTypeDAO(); this.visibilityDAO = ApplicationManagementDAOFactory.getVisibilityDAO(); this.applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO(); this.lifecycleStateDAO = ApplicationManagementDAOFactory.getLifecycleStateDAO(); @@ -422,35 +420,6 @@ public class ApplicationManagerImpl implements ApplicationManager { } } -// todo -// public List getinstallableReleases(int applicationId) throws ApplicationManagementException { -// int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); -// -// Application application = getApplicationIfAccessible(applicationId); -// List applicationReleases; -// List filteredApplicationReleases = new ArrayList<>(); -// if (log.isDebugEnabled()) { -// log.debug("Request is received to retrieve all the releases related with the application " + application -// .toString()); -// } -// ConnectionManagerUtil.getDBConnection(); -// applicationReleases = this.applicationReleaseDAO.getReleases(application.getName(), application.getType(), tenantId); -// for (ApplicationRelease applicationRelease : applicationReleases) { -// LifecycleState lifecycleState = ApplicationManagementDAOFactory.getLifecycleStateDAO(). -// getLatestLifeCycleStateByReleaseID(applicationRelease.getId()); -// if (lifecycleState != null) { -// applicationRelease.setLifecycleState(lifecycleState); -// -// if (!AppLifecycleState.REMOVED.toString() -// .equals(applicationRelease.getLifecycleState().getCurrentState())) { -// filteredApplicationReleases.add(applicationRelease); -// } -// } -// } -// return filteredApplicationReleases; -// -// } - private List getReleases(Application application, boolean requirePublishedRelease) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); @@ -785,19 +754,19 @@ public class ApplicationManagerImpl implements ApplicationManager { } @Override - public LifecycleState getLifecycleState(int applicationId, String applicationUuid) throws + public LifecycleState getLifecycleState(int applicationId, String releaseUuid) throws ApplicationManagementException { LifecycleState lifecycleState; try { ConnectionManagerUtil.openDBConnection(); - lifecycleState = this.lifecycleStateDAO.getLatestLifeCycleStateByReleaseID(applicationId); + lifecycleState = this.lifecycleStateDAO.getLatestLifeCycleState(applicationId, releaseUuid); if (lifecycleState == null) { throw new NotFoundException( "Couldn't find the lifecycle data for appid: " + applicationId + " and app release UUID: " - + applicationUuid); + + releaseUuid); } - lifecycleState.setNextStates(new ArrayList<>(lifecycleStateManger. + lifecycleState.setNextStates(new ArrayList<>(getLifecycleManagementService(). getNextLifecycleStates(lifecycleState.getCurrentState()))); } catch (ApplicationManagementDAOException e) { throw new ApplicationManagementException("Failed to get lifecycle state", e); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/LifecycleStateManger.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/LifecycleStateManger.java index ea36735100..bef2750694 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/LifecycleStateManger.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/LifecycleStateManger.java @@ -18,7 +18,11 @@ public class LifecycleStateManger { public LifecycleStateManger(List states) { lifecycleStates = new HashMap<>(); for (LifecycleState s : states) { - lifecycleStates.put(s.getName(), new State(s.getName(), s.getProceedingStates())); + if (s.getProceedingStates() != null) { + s.getProceedingStates().replaceAll(String::toUpperCase); + } + lifecycleStates.put(s.getName().toUpperCase(), new State(s.getName().toUpperCase(), s.getProceedingStates())); + } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/LifecycleManagementTest.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/LifecycleManagementTest.java index 4b644debac..b616b0bf8e 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/LifecycleManagementTest.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/LifecycleManagementTest.java @@ -16,9 +16,9 @@ public class LifecycleManagementTest { private List lifecycleStates; private LifecycleStateManger lifecycleStateManger; - private final String CURRENT_STATE = "Approved"; - private final String NEXT_STATE = "Published"; - private final String BOGUS_STATE = "Removed"; + private final String CURRENT_STATE = "APPROVED"; + private final String NEXT_STATE = "PUBLISHED"; + private final String BOGUS_STATE = "REMOVED"; @BeforeClass public void init() { From b283c1dfde2509527e80552873a9040e1258a390 Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Fri, 28 Sep 2018 04:10:07 +0530 Subject: [PATCH 10/11] Improve lifecycle management --- .../mgt/core/dao/LifecycleStateDAO.java | 46 +++++++++++++-- .../GenericLifecycleStateDAOImpl.java | 58 +++++++++---------- .../mgt/core/impl/ApplicationManagerImpl.java | 17 ++++-- .../core/lifecycle/LifecycleStateManger.java | 2 +- .../LifecycleManagementTest.java | 10 ++-- 5 files changed, 85 insertions(+), 48 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/LifecycleStateDAO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/LifecycleStateDAO.java index 5ab07f9307..f1b857d0c3 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/LifecycleStateDAO.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/LifecycleStateDAO.java @@ -19,7 +19,6 @@ package org.wso2.carbon.device.application.mgt.core.dao; import org.wso2.carbon.device.application.mgt.common.LifecycleState; -import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; import org.wso2.carbon.device.application.mgt.core.exception.LifeCycleManagementDAOException; import java.util.List; @@ -29,14 +28,51 @@ import java.util.List; */ public interface LifecycleStateDAO { - LifecycleState getLatestLifeCycleStateByReleaseID(int applicationReleaseId) throws ApplicationManagementDAOException; + /** + * To get the latest lifecycle state for the given application release id. + * @param applicationReleaseId id of the application release. + * + * @return Latest Lifecycle State for the given application release + * @throws LifeCycleManagementDAOException Lifecycle Management DAO Exception. + */ + LifecycleState getLatestLifeCycleStateByReleaseID(int applicationReleaseId) throws LifeCycleManagementDAOException; - LifecycleState getLatestLifeCycleState(int appId, String uuid) throws ApplicationManagementDAOException; + /** + * To get the latest lifecycle state for the given application id and the application release UUID. + * @param appId id of the application. + * @param uuid UUID of the application release + * + * @return Latest Lifecycle State for the given application release + * @throws LifeCycleManagementDAOException Lifecycle Management DAO Exception. + */ + LifecycleState getLatestLifeCycleState(int appId, String uuid) throws LifeCycleManagementDAOException; + /** + * To get all changed lifecycle states for the given application release id. + * @param appReleaseId id of the application release. + * + * @return Lifecycle States for the given application release + * @throws LifeCycleManagementDAOException Lifecycle Management DAO Exception. + */ List getLifecycleStates(int appReleaseId) throws LifeCycleManagementDAOException; - void addLifecycleState(LifecycleState state, int appId, int releaseId, int tenantId) throws LifeCycleManagementDAOException; + /** + * To add new lifecycle states for the given application release. + * @param releaseId Id of the application release. + * @param appId Id of the application. + * @param state LifecycleState. + * @param tenantId Tenant id + * + * @throws LifeCycleManagementDAOException Lifecycle Management DAO Exception. + */ + void addLifecycleState(LifecycleState state, int appId, int releaseId, int tenantId) + throws LifeCycleManagementDAOException; + /** + * To delete a specific lifecycle state for application release. + * @param identifier Id of the LifecycleState. + * + * @throws LifeCycleManagementDAOException Lifecycle Management DAO Exception. + */ void deleteLifecycleState(int identifier) throws LifeCycleManagementDAOException; - } 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/lifecyclestate/GenericLifecycleStateDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/GenericLifecycleStateDAOImpl.java index a122d3159d..29cf7c8084 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/GenericLifecycleStateDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/GenericLifecycleStateDAOImpl.java @@ -23,7 +23,6 @@ import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionExcep import org.wso2.carbon.device.application.mgt.core.dao.LifecycleStateDAO; 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 org.wso2.carbon.device.application.mgt.core.exception.LifeCycleManagementDAOException; import java.sql.Connection; @@ -39,7 +38,7 @@ import java.util.List; public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements LifecycleStateDAO { @Override - public LifecycleState getLatestLifeCycleStateByReleaseID(int applicationReleaseId) throws ApplicationManagementDAOException { + public LifecycleState getLatestLifeCycleStateByReleaseID(int applicationReleaseId) throws LifeCycleManagementDAOException { Connection conn = null; PreparedStatement stmt = null; @@ -52,29 +51,18 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif stmt = conn.prepareStatement(sql); stmt.setInt(1, applicationReleaseId); rs = stmt.executeQuery(); - LifecycleState lifecycleState = null; - - if (rs.next()) { - lifecycleState = new LifecycleState(); - lifecycleState.setId(rs.getInt("ID")); - lifecycleState.setCurrentState(rs.getString("CURRENT_STATE")); - lifecycleState.setPreviousState(rs.getString("PREVIOUS_STATE")); - lifecycleState.setUpdatedAt(rs.getTimestamp("UPDATED_AT")); - lifecycleState.setUpdatedBy(rs.getString("UPDATED_BY")); - } - return lifecycleState; - + return constructLifecycle(rs); } catch (SQLException e) { - throw new ApplicationManagementDAOException("Error occurred while getting application List", e); + throw new LifeCycleManagementDAOException("Error occurred while getting application List", e); } catch (DBConnectionException e) { - throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection to get latest" + throw new LifeCycleManagementDAOException("Error occurred while obtaining the DB connection to get latest" + " lifecycle state for a specific application", e); } finally { Util.cleanupResources(stmt, rs); } } - public LifecycleState getLatestLifeCycleState(int appId, String uuid) throws ApplicationManagementDAOException{ + public LifecycleState getLatestLifeCycleState(int appId, String uuid) throws LifeCycleManagementDAOException{ Connection conn = null; PreparedStatement stmt = null; ResultSet rs = null; @@ -88,22 +76,11 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif stmt.setInt(1, appId); stmt.setString(2, uuid); rs = stmt.executeQuery(); - LifecycleState lifecycleState = null; - - if (rs.next()) { - lifecycleState = new LifecycleState(); - lifecycleState.setId(rs.getInt("ID")); - lifecycleState.setCurrentState(rs.getString("CURRENT_STATE")); - lifecycleState.setPreviousState(rs.getString("PREVIOUS_STATE")); - lifecycleState.setUpdatedAt(rs.getTimestamp("UPDATED_AT")); - lifecycleState.setUpdatedBy(rs.getString("UPDATED_BY")); - } - return lifecycleState; - + return constructLifecycle(rs); } catch (SQLException e) { - throw new ApplicationManagementDAOException("Error occurred while getting application List", e); + throw new LifeCycleManagementDAOException("Error occurred while getting application List", e); } catch (DBConnectionException e) { - throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection to get latest" + throw new LifeCycleManagementDAOException("Error occurred while obtaining the DB connection to get latest" + " lifecycle state for a specific application", e); } finally { Util.cleanupResources(stmt, rs); @@ -191,4 +168,23 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif Util.cleanupResources(stmt, rs); } } + + private LifecycleState constructLifecycle(ResultSet rs) throws LifeCycleManagementDAOException { + LifecycleState lifecycleState = null; + try { + if (rs.next()) { + lifecycleState = new LifecycleState(); + lifecycleState.setId(rs.getInt("ID")); + lifecycleState.setCurrentState(rs.getString("CURRENT_STATE")); + lifecycleState.setPreviousState(rs.getString("PREVIOUS_STATE")); + lifecycleState.setUpdatedAt(rs.getTimestamp("UPDATED_AT")); + lifecycleState.setUpdatedBy(rs.getString("UPDATED_BY")); + } + } catch (SQLException e) { + throw new LifeCycleManagementDAOException( + "Error occurred while construct lifecycle state by retrieving data from SQL query", e); + } + return lifecycleState; + + } } 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 9a65522076..a1e887f068 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 @@ -432,8 +432,15 @@ public class ApplicationManagerImpl implements ApplicationManager { ConnectionManagerUtil.getDBConnection(); applicationReleases = this.applicationReleaseDAO.getReleases(application.getId(), tenantId); for (ApplicationRelease applicationRelease : applicationReleases) { - LifecycleState lifecycleState = ApplicationManagementDAOFactory.getLifecycleStateDAO(). - getLatestLifeCycleStateByReleaseID(applicationRelease.getId()); + LifecycleState lifecycleState = null; + try { + lifecycleState = ApplicationManagementDAOFactory.getLifecycleStateDAO(). + getLatestLifeCycleStateByReleaseID(applicationRelease.getId()); + } catch (LifeCycleManagementDAOException e) { + throw new ApplicationManagementException( + "Error occurred while getting the latest lifecycle state for the application release UUID: " + + applicationRelease.getUuid(), e); + } if (lifecycleState != null) { applicationRelease.setLifecycleState(lifecycleState); @@ -768,10 +775,8 @@ public class ApplicationManagerImpl implements ApplicationManager { } lifecycleState.setNextStates(new ArrayList<>(getLifecycleManagementService(). getNextLifecycleStates(lifecycleState.getCurrentState()))); - } catch (ApplicationManagementDAOException e) { - throw new ApplicationManagementException("Failed to get lifecycle state", e); - } catch (ApplicationManagementException e) { - throw new ApplicationManagementException("Failed to get application and application management", e); + } catch (LifeCycleManagementDAOException e) { + throw new ApplicationManagementException("Failed to get lifecycle state from database", e); } finally { ConnectionManagerUtil.closeDBConnection(); } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/LifecycleStateManger.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/LifecycleStateManger.java index bef2750694..b32ab3ab8e 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/LifecycleStateManger.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/LifecycleStateManger.java @@ -27,7 +27,7 @@ public class LifecycleStateManger { } public Set getNextLifecycleStates(String currentLifecycleState) { - return lifecycleStates.get(currentLifecycleState).getProceedingStates(); + return lifecycleStates.get(currentLifecycleState.toUpperCase()).getProceedingStates(); } public boolean isValidStateChange(String currentState, String nextState) { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/LifecycleManagementTest.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/LifecycleManagementTest.java index b616b0bf8e..919a92d7c5 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/LifecycleManagementTest.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/LifecycleManagementTest.java @@ -16,9 +16,9 @@ public class LifecycleManagementTest { private List lifecycleStates; private LifecycleStateManger lifecycleStateManger; - private final String CURRENT_STATE = "APPROVED"; - private final String NEXT_STATE = "PUBLISHED"; - private final String BOGUS_STATE = "REMOVED"; + private final String CURRENT_STATE = "Approved"; + private final String NEXT_STATE = "Published"; + private final String BOGUS_STATE = "Removed"; @BeforeClass public void init() { @@ -32,14 +32,14 @@ public class LifecycleManagementTest { public void checkValidNextLifecycleState() { Set proceedingStates = lifecycleStateManger.getNextLifecycleStates(CURRENT_STATE); Assert.assertTrue("Invalid proceeding state of: " + CURRENT_STATE, - proceedingStates.contains(NEXT_STATE)); + proceedingStates.contains(NEXT_STATE.toUpperCase())); } @Test public void checkInvalidNextLifecycleState() { Set proceedingStates = lifecycleStateManger.getNextLifecycleStates(CURRENT_STATE); Assert.assertFalse("Invalid proceeding state of: " + CURRENT_STATE, - proceedingStates.contains(BOGUS_STATE)); + proceedingStates.contains(BOGUS_STATE.toUpperCase())); } @Test From 2c9ea2b5cf05e625f6caa2da503be675e0d5086b Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Fri, 28 Sep 2018 17:57:04 +0530 Subject: [PATCH 11/11] Fix lifecycle adding issue --- .../common/services/ApplicationManager.java | 9 +- .../mgt/core/dao/ApplicationDAO.java | 3 +- .../mgt/core/dao/ApplicationReleaseDAO.java | 14 +- .../mgt/core/dao/LifecycleStateDAO.java | 4 +- .../GenericApplicationDAOImpl.java | 8 +- .../GenericApplicationReleaseDAOImpl.java | 137 +++++++++++------- .../GenericLifecycleStateDAOImpl.java | 9 +- .../mgt/core/impl/ApplicationManagerImpl.java | 82 ++++++----- .../services/ApplicationManagementAPI.java | 4 + .../impl/ApplicationManagementAPIImpl.java | 14 +- 10 files changed, 168 insertions(+), 116 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java index 83c4e67495..cc5a50681c 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java @@ -112,7 +112,7 @@ public interface ApplicationManager { * @return the boolean value, whether application exist or not * @throws ApplicationManagementException Application Management Exception. */ - Boolean verifyApplicationExistenceById(int appId) throws ApplicationManagementException; + boolean verifyApplicationExistenceById(int appId) throws ApplicationManagementException; /** * To get Application with the given UUID. @@ -136,14 +136,13 @@ public interface ApplicationManager { * To get all the releases of a particular Application. * * @param applicationId ID of the Application. - * @param applicationUuid UUID of the Application Release. + * @param releaseUuid UUID of the Application Release. * @param state Lifecycle state to change the app * @param checkExist whether it is needed to check if the app and release already exist in the database - * @param releaseId The release ID of the application(optional) * @throws ApplicationManagementException Application Management Exception. */ - void changeLifecycleState(int applicationId, String applicationUuid, LifecycleState state, Boolean checkExist, - int releaseId) throws ApplicationManagementException; + void changeLifecycleState(int applicationId, String releaseUuid, LifecycleState state, Boolean checkExist) + throws ApplicationManagementException; /** * Get the application if application is an accessible one. 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 2556238e61..772dea5e8d 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 @@ -109,10 +109,11 @@ public interface ApplicationDAO { * To get the application with the given uuid * * @param appId ID of the application + * @param tenantId Tenant Id * @return the boolean value * @throws ApplicationManagementDAOException Application Management DAO Exception. */ - Boolean verifyApplicationExistenceById(int appId) throws ApplicationManagementDAOException; + boolean verifyApplicationExistenceById(int appId, int tenantId) throws ApplicationManagementDAOException; /** * To get the application id of the application specified by the UUID diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationReleaseDAO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationReleaseDAO.java index a62053a377..d08af3c8c4 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationReleaseDAO.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationReleaseDAO.java @@ -115,6 +115,16 @@ public interface ApplicationReleaseDAO { * @throws ApplicationManagementDAOException Application Management DAO Exception. */ ApplicationRelease getReleaseByIds(int applicationId, String releaseUuid, int tenantId) throws - ApplicationManagementDAOException; + ApplicationManagementDAOException; + + /** + * To verify whether application release exist or not. + * + * @param appId ID of the application. + * @param uuid UUID of the application release. + * @param tenantId Tenant Id + * @throws ApplicationManagementDAOException Application Management DAO Exception. + */ + boolean verifyReleaseExistence(int appId, String uuid, int tenantId) 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/LifecycleStateDAO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/LifecycleStateDAO.java index f1b857d0c3..40cc7a79ec 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/LifecycleStateDAO.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/LifecycleStateDAO.java @@ -58,14 +58,14 @@ public interface LifecycleStateDAO { /** * To add new lifecycle states for the given application release. - * @param releaseId Id of the application release. + * @param uuid Id of the application release. * @param appId Id of the application. * @param state LifecycleState. * @param tenantId Tenant id * * @throws LifeCycleManagementDAOException Lifecycle Management DAO Exception. */ - void addLifecycleState(LifecycleState state, int appId, int releaseId, int tenantId) + void addLifecycleState(LifecycleState state, int appId, String uuid, int tenantId) throws LifeCycleManagementDAOException; /** 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 5847eda9b8..f2d417ee44 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 @@ -433,7 +433,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic } @Override - public Boolean verifyApplicationExistenceById(int appId) throws ApplicationManagementDAOException { + public boolean verifyApplicationExistenceById(int appId, int tenantId) throws ApplicationManagementDAOException { if (log.isDebugEnabled()) { log.debug("Getting application with the application ID(" + appId + " ) from the database"); } @@ -443,13 +443,11 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic try { conn = this.getDBConnection(); String sql = - "SELECT AP_APP.ID AS APP_ID, AP_APP.NAME AS APP_NAME, AP_APP.TYPE AS APP_TYPE, AP_APP.APP_CATEGORY " - + "AS APP_CATEGORY, AP_APP.SUB_TYPE AS SUB_TYPE, AP_APP_TAG.TAG AS TAG, " - + "AP_UNRESTRICTED_ROLE.ROLE AS ROLE FROM AP_APP, AP_APP_TAG, AP_UNRESTRICTED_ROLE " - + "WHERE AP_APP.ID = ?;"; + "SELECT AP_APP.ID AS APP_ID FROM AP_APP WHERE AP_APP.ID = ? AND AP_APP.TENANT_ID=?;"; stmt = conn.prepareStatement(sql); stmt.setInt(1, appId); + stmt.setInt(2, tenantId); rs = stmt.executeQuery(); if (log.isDebugEnabled()) { 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/release/GenericApplicationReleaseDAOImpl.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/release/GenericApplicationReleaseDAOImpl.java index 4445bcf717..68d934d9a8 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/release/GenericApplicationReleaseDAOImpl.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/release/GenericApplicationReleaseDAOImpl.java @@ -43,29 +43,26 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements private static final Log log = LogFactory.getLog(GenericApplicationReleaseDAOImpl.class); - /** * To insert the Application Release Details. * - * @param appId Id of the application + * @param appId Id of the application * @param applicationRelease Application Release the properties of which that need to be inserted. - * @param tenantId Tenant Id + * @param tenantId Tenant Id * @throws ApplicationManagementDAOException Application Management DAO Exception. */ - @Override - public ApplicationRelease createRelease(ApplicationRelease applicationRelease, int appId, int tenantId) throws - ApplicationManagementDAOException { + @Override public ApplicationRelease createRelease(ApplicationRelease applicationRelease, int appId, int tenantId) + throws ApplicationManagementDAOException { Connection connection; PreparedStatement statement = null; ResultSet resultSet = null; String sql = "INSERT INTO AP_APP_RELEASE (VERSION,TENANT_ID,UUID,RELEASE_TYPE, PACKAGE_NAME, APP_PRICE," + "STORED_LOCATION, BANNER_LOCATION, SC_1_LOCATION,SC_2_LOCATION,SC_3_LOCATION, APP_HASH_VALUE," - + "SHARED_WITH_ALL_TENANTS, APP_META_INFO,AP_APP_ID) " - + "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);"; + + "SHARED_WITH_ALL_TENANTS, APP_META_INFO,AP_APP_ID) " + "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);"; int index = 0; - String generatedColumns[] = {"ID"}; + String generatedColumns[] = { "ID" }; try { connection = this.getDBConnection(); statement = connection.prepareStatement(sql, generatedColumns); @@ -95,7 +92,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements "SQL Exception while trying to release an application by executing the query " + sql, e); } catch (DBConnectionException e) { throw new ApplicationManagementDAOException( - "Database Connection Exception while trying to release a new version" , e); + "Database Connection Exception while trying to release a new version", e); } finally { Util.cleanupResources(statement, resultSet); } @@ -106,13 +103,12 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements * * @param applicationName Name of the application. * @param applicationType Type of the application. - * @param versionName version name of the application. - * @param releaseType type of the application release. - * @param tenantId Tenant Id + * @param versionName version name of the application. + * @param releaseType type of the application release. + * @param tenantId Tenant Id * @throws ApplicationManagementDAOException Application Management DAO Exception. */ - @Override - public ApplicationRelease getRelease(String applicationName, String applicationType, String versionName, + @Override public ApplicationRelease getRelease(String applicationName, String applicationType, String versionName, String releaseType, int tenantId) throws ApplicationManagementDAOException { Connection connection; @@ -144,11 +140,10 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements return null; } catch (DBConnectionException e) { throw new ApplicationManagementDAOException("Database connection exception while trying to get the " - + "release details of the application with " + applicationName + " and version " + - versionName, e); + + "release details of the application with " + applicationName + " and version " + versionName, e); } catch (SQLException e) { - throw new ApplicationManagementDAOException("Error while getting release details of the application " + - applicationName + " and version " + versionName + " , while executing the query " + sql, e); + throw new ApplicationManagementDAOException( + "Error while getting release details of the application " + applicationName + " and version " + versionName + " , while executing the query " + sql, e); } finally { Util.cleanupResources(statement, resultSet); } @@ -158,25 +153,25 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements * To get release details of a specific application. * * @param applicationId ID of the application. - * @param releaseUuid UUID of the application release. - * @param tenantId Tenant Id + * @param releaseUuid UUID of the application release. + * @param tenantId Tenant Id * @throws ApplicationManagementDAOException Application Management DAO Exception. */ - @Override - public ApplicationRelease getReleaseByIds(int applicationId, String releaseUuid, int tenantId) throws - ApplicationManagementDAOException { + @Override public ApplicationRelease getReleaseByIds(int applicationId, String releaseUuid, int tenantId) + throws ApplicationManagementDAOException { Connection connection; PreparedStatement statement = null; ResultSet resultSet = null; - String sql = "SELECT AR.ID AS RELEASE_ID, AR.VERSION AS RELEASE_VERSION, AR.UUID, AR.RELEASE_TYPE, AR.APP_PRICE," - + " AR.STORED_LOCATION, AR.BANNER_LOCATION, AR.SC_1_LOCATION AS SCREEN_SHOT_1, " - + "AR.SC_2_LOCATION AS SCREEN_SHOT_2, AR.SC_3_LOCATION AS SCREEN_SHOT_3, AR.APP_HASH_VALUE AS " + - "HASH_VALUE, AR.SHARED_WITH_ALL_TENANTS AS SHARED, AR.APP_META_INFO, AR.CREATED_BY, AR.CREATED_AT, AR" + - ".PUBLISHED_BY, AR.PUBLISHED_AT, AR.STARS, AL.CURRENT_STATE, AL.PREVIOUS_STATE, AL.UPDATED_BY, " + - "AL.UPDATED_AT FROM AP_APP_RELEASE AS AR, AP_APP_LIFECYCLE_STATE AS AL WHERE " + - "AR.AP_APP_ID = ? AND AR.UUID = ? AND AR.TENANT_ID = ? AND AL.AP_APP_RELEASE_ID=AR.ID AND " + - "AL.TENANT_ID = AR.TENANT_ID ORDER BY AL.UPDATED_AT DESC;"; + String sql = + "SELECT AR.ID AS RELEASE_ID, AR.VERSION AS RELEASE_VERSION, AR.UUID, AR.RELEASE_TYPE, AR.APP_PRICE, " + + "AR.STORED_LOCATION, AR.BANNER_LOCATION, AR.SC_1_LOCATION AS SCREEN_SHOT_1, " + + "AR.SC_2_LOCATION AS SCREEN_SHOT_2, AR.SC_3_LOCATION AS SCREEN_SHOT_3, AR.PACKAGE_NAME AS " + + "PACKAGE_NAME, AR.APP_HASH_VALUE AS HASH_VALUE, AR.SHARED_WITH_ALL_TENANTS AS SHARED, " + + "AR.APP_META_INFO AS APP_META_INFO, AR.RATING AS RATING, AL.CURRENT_STATE, AL.PREVIOUS_STATE, " + + "AL.UPDATED_BY, AL.UPDATED_AT FROM AP_APP_RELEASE AS AR, AP_APP_LIFECYCLE_STATE AS AL " + + "WHERE AR.AP_APP_ID = ? AND AR.UUID = ? AND AR.TENANT_ID = ? AND AL.AP_APP_RELEASE_ID=AR.ID " + + "AND AL.TENANT_ID = AR.TENANT_ID ORDER BY AL.UPDATED_AT DESC;"; try { connection = this.getDBConnection(); @@ -192,14 +187,12 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements return null; } catch (DBConnectionException e) { throw new ApplicationManagementDAOException( - "Database connection exception while trying to get the release details of the " + - "application id: " + applicationId + "and UUID of the application release: " + - releaseUuid, e); + "Database connection exception while trying to get the release details of the " + "application id: " + + applicationId + "and UUID of the application release: " + releaseUuid, e); } catch (SQLException e) { throw new ApplicationManagementDAOException( - "Error while getting release details of the application id: " + applicationId + - " and theUUID of the application " + - "release: " + releaseUuid + " , while executing the query " + sql, e); + "Error while getting release details of the application id: " + applicationId + + " and theUUID of the application " + "release: " + releaseUuid + " , while executing the query " + sql, e); } finally { Util.cleanupResources(statement, resultSet); } @@ -209,11 +202,10 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements * To insert the application release properties. * * @param applicationId Id of the application. - * @param tenantId Tenant Id + * @param tenantId Tenant Id * @throws ApplicationManagementDAOException Application Management DAO Exception. */ - @Override - public List getReleases(int applicationId, int tenantId) + @Override public List getReleases(int applicationId, int tenantId) throws ApplicationManagementDAOException { Connection connection; PreparedStatement statement = null; @@ -254,12 +246,12 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements /** * To Update starts of an application release. * - * @param uuid UUID of the application Release. + * @param uuid UUID of the application Release. * @param rating given stars for the application release. * @throws ApplicationManagementDAOException Application Management DAO Exception. */ - @Override - public void updateRatingValue(String uuid, double rating, int ratedUsers) throws ApplicationManagementDAOException { + @Override public void updateRatingValue(String uuid, double rating, int ratedUsers) + throws ApplicationManagementDAOException { Connection connection; PreparedStatement statement = null; String sql = "UPDATE AP_APP_RELEASE SET RATING = ?,RATED_USERS = ? WHERE UUID = ?;"; @@ -287,8 +279,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements * @param uuid UUID of the application Release. * @throws ApplicationManagementDAOException Application Management DAO Exception. */ - @Override - public Rating getRating(String uuid, int tenantId) throws ApplicationManagementDAOException { + @Override public Rating getRating(String uuid, int tenantId) throws ApplicationManagementDAOException { Connection connection; PreparedStatement statement = null; ResultSet resultSet = null; @@ -301,7 +292,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements statement.setInt(2, tenantId); resultSet = statement.executeQuery(); - if (resultSet.next()){ + if (resultSet.next()) { rating = new Rating(); rating.setRatingValue(resultSet.getDouble("RATING")); rating.setNoOfUsers(resultSet.getInt("RATED_USERS")); @@ -324,8 +315,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements * @param applicationRelease Application Release the properties of which that need to be inserted. * @throws ApplicationManagementDAOException Application Management DAO Exception. */ - @Override - public ApplicationRelease updateRelease(int applicationId, ApplicationRelease applicationRelease, int tenantId) + @Override public ApplicationRelease updateRelease(int applicationId, ApplicationRelease applicationRelease, int tenantId) throws ApplicationManagementDAOException { Connection connection; PreparedStatement statement = null; @@ -349,7 +339,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements statement.setString(11, applicationRelease.getAppHashValue()); statement.setInt(12, applicationRelease.getIsSharedWithAllTenants()); statement.setString(13, applicationRelease.getMetaData()); - statement.setInt(14,applicationId); + statement.setInt(14, applicationId); statement.setInt(15, tenantId); statement.setInt(16, applicationRelease.getId()); @@ -369,12 +359,11 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements /** * To delete an application release. * - * @param id Id of the application Release. + * @param id Id of the application Release. * @param version version name of the application release. * @throws ApplicationManagementDAOException Application Management DAO Exception. */ - @Override - public void deleteRelease(int id, String version) throws ApplicationManagementDAOException { + @Override public void deleteRelease(int id, String version) throws ApplicationManagementDAOException { Connection connection; PreparedStatement statement = null; String sql = "DELETE FROM AP_APP_RELEASE WHERE ID = ? AND VERSION = ?"; @@ -396,8 +385,46 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements } } + @Override + public boolean verifyReleaseExistence(int appId, String uuid, int tenantId) throws ApplicationManagementDAOException { + if (log.isDebugEnabled()) { + log.debug("Verifying application release existence by application id:" + appId + + " and application release uuid: " + uuid); + } + Connection conn; + PreparedStatement stmt = null; + ResultSet rs = null; + try { + conn = this.getDBConnection(); + String sql = + "SELECT AR.ID AS RELEASE_ID FROM AP_APP_RELEASE AS AR WHERE AR.AP_APP_ID = ? AND AR.UUID = ? AND " + + "AR.TENANT_ID = ?;"; + + stmt = conn.prepareStatement(sql); + stmt.setInt(1, appId); + stmt.setString(2, uuid); + stmt.setInt(3, tenantId); + rs = stmt.executeQuery(); + + if (log.isDebugEnabled()) { + log.debug("Successfully retrieved basic details of the application release with the application ID " + + appId + " Application release uuid: " + uuid); + } + return rs.next(); + } catch (SQLException e) { + throw new ApplicationManagementDAOException( + "Error occurred while getting application release details with app ID: " + appId + + " App release uuid: " + uuid + " While executing query ", e); + } catch (DBConnectionException e) { + throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e); + } finally { + Util.cleanupResources(stmt, rs); + } + } + /** * This method is capable to construct {@link ApplicationRelease} and return the object + * * @param resultSet result set obtained from the query executing. * @throws SQLException SQL exception while accessing result set data. */ @@ -418,8 +445,6 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements applicationRelease.setIsSharedWithAllTenants(resultSet.getInt("SHARED")); applicationRelease.setMetaData(resultSet.getString("APP_META_INFO")); applicationRelease.setRating(resultSet.getDouble("RATING")); - return applicationRelease; } - -} +} \ No newline at end of file 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/lifecyclestate/GenericLifecycleStateDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/GenericLifecycleStateDAOImpl.java index 29cf7c8084..515379ede3 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/GenericLifecycleStateDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/GenericLifecycleStateDAOImpl.java @@ -123,19 +123,19 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif } @Override - public void addLifecycleState(LifecycleState state, int appId, int releaseId, int tenantId) throws LifeCycleManagementDAOException { + public void addLifecycleState(LifecycleState state, int appId, String uuid, int tenantId) throws LifeCycleManagementDAOException { Connection conn = null; PreparedStatement stmt = null; try { conn = this.getDBConnection(); String sql = "INSERT INTO AP_APP_LIFECYCLE_STATE (CURRENT_STATE, PREVIOUS_STATE, TENANT_ID, UPDATED_BY, " - + "AP_APP_RELEASE_ID, AP_APP_ID) VALUES (?,?, ?, ?,?,?);"; + + "AP_APP_RELEASE_ID, AP_APP_ID) VALUES (?,?, ?, ?,(SELECT ID FROM AP_APP_RELEASE WHERE UUID=?),?);"; stmt = conn.prepareStatement(sql); stmt.setString(1, state.getCurrentState().toUpperCase()); stmt.setString(2, state.getPreviousState().toUpperCase()); stmt.setInt(3, tenantId); stmt.setString(4, state.getUpdatedBy()); - stmt.setInt(5, releaseId); + stmt.setString(5, uuid); stmt.setInt(6, appId); stmt.executeUpdate(); @@ -172,7 +172,7 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif private LifecycleState constructLifecycle(ResultSet rs) throws LifeCycleManagementDAOException { LifecycleState lifecycleState = null; try { - if (rs.next()) { + if (rs !=null && rs.next()) { lifecycleState = new LifecycleState(); lifecycleState.setId(rs.getInt("ID")); lifecycleState.setCurrentState(rs.getString("CURRENT_STATE")); @@ -185,6 +185,5 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif "Error occurred while construct lifecycle state by retrieving data from SQL query", e); } return lifecycleState; - } } 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 a1e887f068..1013f98fa6 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 @@ -50,7 +50,6 @@ import org.wso2.carbon.device.application.mgt.core.internal.DataHolder; import org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManger; import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO; import org.wso2.carbon.device.mgt.core.dto.DeviceType; import org.wso2.carbon.user.api.UserRealm; import org.wso2.carbon.user.api.UserStoreException; @@ -95,7 +94,6 @@ public class ApplicationManagerImpl implements ApplicationManager { log.debug("Create Application received for the tenant : " + tenantId + " From" + " the user : " + userName); } - ConnectionManagerUtil.openDBConnection(); validateAppCreatingRequest(application); validateAppReleasePayload(application.getApplicationReleases().get(0)); @@ -162,8 +160,7 @@ public class ApplicationManagerImpl implements ApplicationManager { LifecycleState lifecycleState = new LifecycleState(); lifecycleState.setCurrentState(AppLifecycleState.CREATED.toString()); lifecycleState.setPreviousState(AppLifecycleState.CREATED.toString()); - changeLifecycleState(appId, applicationRelease.getUuid(), lifecycleState, false, - applicationRelease.getId()); + changeLifecycleState(appId, applicationRelease.getUuid(), lifecycleState, false); applicationRelease.setLifecycleState(lifecycleState); applicationReleases.add(applicationRelease); @@ -247,7 +244,7 @@ public class ApplicationManagerImpl implements ApplicationManager { LifecycleState lifecycleState = new LifecycleState(); lifecycleState.setCurrentState(AppLifecycleState.CREATED.toString()); lifecycleState.setPreviousState(AppLifecycleState.CREATED.toString()); - changeLifecycleState(application.getId(), applicationRelease.getUuid(), lifecycleState, true, 0); + changeLifecycleState(application.getId(), applicationRelease.getUuid(), lifecycleState, true); ConnectionManagerUtil.commitDBTransaction(); return applicationRelease; @@ -281,8 +278,7 @@ public class ApplicationManagerImpl implements ApplicationManager { List applicationReleases; try { ConnectionManagerUtil.openDBConnection(); - application = ApplicationManagementDAOFactory.getApplicationDAO() - .getApplicationById(id, tenantId); + application = this.applicationDAO.getApplicationById(id, tenantId); if (isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) { applicationReleases = getReleases(application, requirePublishedReleases); application.setApplicationReleases(applicationReleases); @@ -345,8 +341,7 @@ public class ApplicationManagerImpl implements ApplicationManager { List applicationReleases; try { ConnectionManagerUtil.openDBConnection(); - application = ApplicationManagementDAOFactory.getApplicationDAO() - .getApplication(appName, appType, tenantId); + application = this.applicationDAO.getApplication(appName, appType, tenantId); if (isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) { applicationReleases = getReleases(application, false); application.setApplicationReleases(applicationReleases); @@ -383,8 +378,7 @@ public class ApplicationManagerImpl implements ApplicationManager { Application application; try { ConnectionManagerUtil.openDBConnection(); - application = ApplicationManagementDAOFactory.getApplicationDAO() - .getApplicationByRelease(appReleaseUUID, tenantId); + application = this.applicationDAO.getApplicationByRelease(appReleaseUUID, tenantId); if (application.getUnrestrictedRoles().isEmpty() || isRoleExists(application.getUnrestrictedRoles(), userName)) { @@ -399,11 +393,12 @@ public class ApplicationManagerImpl implements ApplicationManager { } } - public Boolean verifyApplicationExistenceById(int appId) throws ApplicationManagementException { + public boolean verifyApplicationExistenceById(int appId) throws ApplicationManagementException { try { - Boolean isAppExist; + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); + boolean isAppExist; ConnectionManagerUtil.openDBConnection(); - isAppExist = ApplicationManagementDAOFactory.getApplicationDAO().verifyApplicationExistenceById(appId); + isAppExist = this.applicationDAO.verifyApplicationExistenceById(appId, tenantId); return isAppExist; } finally { ConnectionManagerUtil.closeDBConnection(); @@ -496,11 +491,11 @@ public class ApplicationManagerImpl implements ApplicationManager { LifecycleState newAppLifecycleState = new LifecycleState(); newAppLifecycleState.setPreviousState(appLifecycleState.getCurrentState()); newAppLifecycleState.setCurrentState(AppLifecycleState.REMOVED.toString()); - changeLifecycleState(applicationId, applicationRelease.getUuid(), newAppLifecycleState, true, 0); + changeLifecycleState(applicationId, applicationRelease.getUuid(), newAppLifecycleState, true); storedLocations.add(applicationRelease.getAppHashValue()); } ConnectionManagerUtil.openDBConnection(); - ApplicationManagementDAOFactory.getApplicationDAO().deleteApplication(applicationId); + this.applicationDAO.deleteApplication(applicationId); } catch (UserStoreException e) { String msg = "Error occured while check whether current user has the permission to delete an application"; log.error(msg); @@ -527,7 +522,7 @@ public class ApplicationManagerImpl implements ApplicationManager { LifecycleState newAppLifecycleState = new LifecycleState(); newAppLifecycleState.setPreviousState(appLifecycleState.getCurrentState()); newAppLifecycleState.setCurrentState(AppLifecycleState.REMOVED.toString()); - changeLifecycleState(applicationId, applicationRelease.getUuid(), newAppLifecycleState, true, 0); + changeLifecycleState(applicationId, applicationRelease.getUuid(), newAppLifecycleState, true); }else{ throw new ApplicationManagementException("Can't delete the application release, You have to move the " + "lifecycle state from "+ currentState + " to acceptable " + @@ -634,8 +629,7 @@ public class ApplicationManagerImpl implements ApplicationManager { Application application; boolean isAppAllowed = false; try { - application = ApplicationManagementDAOFactory.getApplicationDAO() - .getApplicationById(applicationId, tenantId); + application = this.applicationDAO.getApplicationById(applicationId, tenantId); if (isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) { return application; } @@ -784,34 +778,48 @@ public class ApplicationManagerImpl implements ApplicationManager { } @Override - public void changeLifecycleState(int applicationId, String applicationUuid, LifecycleState state, Boolean - checkExist, int releaseId) throws ApplicationManagementException { + public void changeLifecycleState(int applicationId, String releaseUuid, LifecycleState state, Boolean checkExist) + throws ApplicationManagementException { try { + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); if (checkExist) { - getApplicationIfAccessible(applicationId); - } - if (releaseId < 1) { - releaseId = getAppReleaseIfExists(applicationId, applicationUuid).getId(); + ConnectionManagerUtil.openDBConnection(); + if (!this.applicationDAO.verifyApplicationExistenceById(applicationId, tenantId)){ + throw new NotFoundException( + "Couldn't found application for the application Id: " + applicationId); + } + if (!this.applicationReleaseDAO.verifyReleaseExistence(applicationId, releaseUuid, tenantId)){ + throw new NotFoundException( + "Couldn't found application release for the application Id: " + applicationId + + " application release uuid: " + releaseUuid); + } } - int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); + String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); state.setUpdatedBy(userName); if (state.getCurrentState() != null && state.getPreviousState() != null) { - - if (getLifecycleManagementService().isValidStateChange(state.getPreviousState(), state.getCurrentState())) { - this.lifecycleStateDAO - .addLifecycleState(state, applicationId, releaseId, tenantId); + if (getLifecycleManagementService() + .isValidStateChange(state.getPreviousState(), state.getCurrentState())) { + ConnectionManagerUtil.beginDBTransaction(); + //todo if current state of the adding lifecycle state is PUBLISHED, need to check whether is there + //todo any other application release in PUBLISHED state for the application( i.e for the appid) + this.lifecycleStateDAO.addLifecycleState(state, applicationId, releaseUuid, tenantId); + ConnectionManagerUtil.commitDBTransaction(); } else { - log.error("Invalid lifecycle state transition from '" + state.getPreviousState() + "'" - + " to '" + state.getCurrentState() + "'"); - throw new ApplicationManagementException("Lifecycle State Validation failed"); + log.error("Invalid lifecycle state transition from '" + state.getPreviousState() + "'" + " to '" + + state.getCurrentState() + "'"); + throw new ApplicationManagementException("Lifecycle State Validation failed. Application Id: " + + applicationId + " Application release UUID: " + releaseUuid); } } - } catch (LifeCycleManagementDAOException | DBConnectionException e) { - throw new ApplicationManagementException("Failed to add lifecycle state", e); - } catch (ApplicationManagementException e) { - throw new ApplicationManagementException("Lifecycle State Validation failed", e); + } catch (LifeCycleManagementDAOException e) { + ConnectionManagerUtil.rollbackDBTransaction(); + throw new ApplicationManagementException( + "Failed to add lifecycle state. Application Id: " + applicationId + " Application release UUID: " + + releaseUuid, e); + } finally { + ConnectionManagerUtil.closeDBConnection(); } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementAPI.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementAPI.java index 1151dc3d6e..57b35871e1 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementAPI.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementAPI.java @@ -529,6 +529,10 @@ public interface ApplicationManagementAPI { code = 201, message = "OK. \n Successfully add a lifecycle state.", response = Application.class), + @ApiResponse( + code = 404, + message = "NOT FOUND. \n Error occurred while adding new lifecycle state.", + response = ErrorResponse.class), @ApiResponse( code = 500, message = "Internal Server Error. \n Error occurred adding a lifecycle state.", diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementAPIImpl.java index 2b1ee720cb..f3b93e84c3 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementAPIImpl.java @@ -414,7 +414,8 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { @DELETE @Path("/{appid}") - public Response deleteApplication(@PathParam("appid") int applicationId) { + public Response deleteApplication( + @PathParam("appid") int applicationId) { ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager(); try { @@ -435,7 +436,9 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { @DELETE @Path("/{appid}/{uuid}") - public Response deleteApplicationRelease(@PathParam("appid") int applicationId, @PathParam("uuid") String releaseUuid) { + public Response deleteApplicationRelease( + @PathParam("appid") int applicationId, + @PathParam("uuid") String releaseUuid) { ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager(); try { @@ -485,7 +488,12 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { LifecycleState state) { ApplicationManager applicationManager = APIUtil.getApplicationManager(); try { - applicationManager.changeLifecycleState(applicationId, applicationUuid, state, true, 0); + applicationManager.changeLifecycleState(applicationId, applicationUuid, state, true); + } catch (NotFoundException e) { + String msg = "Could,t find application release for application id: " + applicationId + + " and application release uuid: " + applicationUuid; + log.error(msg, e); + return Response.status(Response.Status.NOT_FOUND).build(); } catch (ApplicationManagementException e) { String msg = "Error occurred while adding lifecycle state."; log.error(msg, e);