From 7eac984e0c51edb5755c721afa974821ace69840 Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Wed, 19 Jun 2019 19:49:41 +0530 Subject: [PATCH] Improve app getting functionality in APPM publisher --- .../common/services/ApplicationManager.java | 2 +- .../application/mgt/core/dao/ReviewDAO.java | 2 +- .../core/dao/impl/review/ReviewDAOImpl.java | 3 +- .../mgt/core/impl/ApplicationManagerImpl.java | 45 ++++++++++--------- .../mgt/core/impl/ReviewManagerImpl.java | 3 +- .../ApplicationManagementPublisherAPI.java | 2 +- ...ApplicationManagementPublisherAPIImpl.java | 9 ++-- 7 files changed, 33 insertions(+), 33 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 3bbf1762f2..90f65a44a5 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,7 +122,7 @@ public interface ApplicationManager { * @return the Application Release identified by the UUID * @throws ApplicationManagementException Application Management Exception. */ - ApplicationRelease getApplicationReleaseByUUID(String uuid) throws ApplicationManagementException; + Application getApplicationByUuid(String uuid) throws ApplicationManagementException; /** * To get the ApplicationDTO for given application relase 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/ReviewDAO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ReviewDAO.java index 2a508b8e31..b7d099423e 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ReviewDAO.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ReviewDAO.java @@ -90,7 +90,7 @@ import java.util.List; * @return {@link List}List of all reviews for the application release * @throws ReviewManagementDAOException Review management DAO exception **/ - List getAllActiveReleaseReviews(int releaseId, PaginationRequest request, int tenantId) + List getAllReleaseReviews(int releaseId, PaginationRequest request, int tenantId) throws ReviewManagementDAOException; List getAllActiveAppReviews(List releaseIds, PaginationRequest request, int tenantId) 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 df6bf92627..b57486690a 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 @@ -258,7 +258,7 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO { @Override - public List getAllActiveReleaseReviews(int releaseId, PaginationRequest request, int tenantId) + public List getAllReleaseReviews(int releaseId, PaginationRequest request, int tenantId) throws ReviewManagementDAOException { if (log.isDebugEnabled()) { @@ -283,7 +283,6 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO { + "AP_APP_REVIEW.AP_APP_RELEASE_ID = AP_APP_RELEASE.ID " + "WHERE AP_APP_REVIEW.AP_APP_RELEASE_ID = ? AND " + "AP_APP_REVIEW.ROOT_PARENT_ID = ? AND " - + "AP_APP_REVIEW.ACTIVE_REVIEW = true AND " + "AP_APP_REVIEW.TENANT_ID = ? " + "LIMIT ? OFFSET ?"; try (PreparedStatement statement = conn.prepareStatement(sql)) { 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 77190def2f..dab6fdf57f 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 @@ -896,49 +896,50 @@ public class ApplicationManagerImpl implements ApplicationManager { } @Override - public ApplicationRelease getApplicationReleaseByUUID(String uuid) throws ApplicationManagementException{ + public Application getApplicationByUuid(String uuid) throws ApplicationManagementException{ int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); - boolean isVisibleAppRelease = false; + boolean isVisibleApp = false; + try { ConnectionManagerUtil.openDBConnection(); - ApplicationReleaseDTO applicationReleaseDTO = applicationReleaseDAO.getReleaseByUUID(uuid, tenantId); - if (applicationReleaseDTO == null) { - String msg = "Couldn't find an application release for the UUID: " + uuid; + ApplicationDTO applicationDTO = applicationDAO.getApplicationByUUID(uuid, tenantId); + + if (applicationDTO == null) { + String msg = "Couldn't found an application for application release UUID: " + uuid; log.error(msg); throw new NotFoundException(msg); } - if (applicationReleaseDTO.getCurrentState().equals(lifecycleStateManager.getEndState())) { - return null; - } - List unrestrictedRoles = this.visibilityDAO.getUnrestrictedRolesByUUID(uuid, tenantId); + List tags = this.applicationDAO.getAppTags(applicationDTO.getId(), tenantId); + List categories = this.applicationDAO.getAppCategories(applicationDTO.getId(), tenantId); + applicationDTO.setTags(tags); + applicationDTO.setAppCategories(categories); + + List unrestrictedRoles = this.visibilityDAO.getUnrestrictedRoles(applicationDTO.getId(), tenantId); if (!unrestrictedRoles.isEmpty()) { if (hasUserRole(unrestrictedRoles, userName)) { - isVisibleAppRelease = true; + isVisibleApp = true; } } else { - isVisibleAppRelease = true; + isVisibleApp = true; } - if (!isVisibleAppRelease) { - String msg = "You are trying to access release of visibility restricted application. You don't have " - + "required roles to view this application,"; + if (!isVisibleApp) { + String msg = "You are trying to access visibility restricted application. You don't have required " + + "roles to view this application,"; log.error(msg); throw new ForbiddenException(msg); } - return APIUtil.releaseDtoToRelease(applicationReleaseDTO); - } catch (LifecycleManagementException e) { - String msg = "Error occurred when getting the end state of the application lifecycle flow"; - log.error(msg); - throw new ApplicationManagementException(msg, e); + return APIUtil.appDtoToAppResponse(applicationDTO); } catch (UserStoreException e) { - String msg = "User-store exception while getting application with the application release UUID: " + uuid; + String msg = "User-store exception occurred while getting application for application release UUID " + uuid; log.error(msg); throw new ApplicationManagementException(msg, e); } catch (ApplicationManagementDAOException e) { - //todo - throw new ApplicationManagementException(""); + String msg = "Error occurred while getting dta which are related to Application."; + log.error(msg); + throw new ApplicationManagementException(msg); } 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/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 b550f6a64e..b31479c4ed 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 @@ -289,6 +289,7 @@ public class ReviewManagerImpl implements ReviewManager { log.error(msg); throw new ReviewManagementException(msg); } + uuid = reviewDTO.getReleaseUuid(); } else if (updatingReview.getRating() > 0 && updatingReview.getRating() != reviewDTO.getRating()) { Runnable task = () -> ReviewManagerImpl.this .calculateRating(updatingReview.getRating(), reviewDTO.getRating(), uuid, tenantId); @@ -353,7 +354,7 @@ public class ReviewManagerImpl implements ReviewManager { log.error(msg); throw new NotFoundException(msg); } - return getReviewTree(this.reviewDAO.getAllActiveReleaseReviews(releaseDTO.getId(), request, tenantId)); + return getReviewTree(this.reviewDAO.getAllReleaseReviews(releaseDTO.getId(), request, tenantId)); } catch (ReviewManagementDAOException e) { throw new ReviewManagementException("Error occured while getting all reviews for application uuid: " + uuid, 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/ApplicationManagementPublisherAPI.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/ApplicationManagementPublisherAPI.java index e2b50661e2..99355e5c96 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/ApplicationManagementPublisherAPI.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/ApplicationManagementPublisherAPI.java @@ -217,7 +217,7 @@ public interface ApplicationManagementPublisherAPI { message = "Internal Server Error. \n Error occurred while getting relevant application release.", response = ErrorResponse.class) }) - Response getApplicationRelease( + Response getApplicationByUUID( @ApiParam( name = "uuid", value = "application release uuid", 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/ApplicationManagementPublisherAPIImpl.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/ApplicationManagementPublisherAPIImpl.java index e5e6745dff..d0d091df03 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/ApplicationManagementPublisherAPIImpl.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/ApplicationManagementPublisherAPIImpl.java @@ -135,18 +135,17 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem @GET @Consumes("application/json") @Path("/release/{uuid}") - public Response getApplicationRelease( + public Response getApplicationByUUID( @PathParam("uuid") String uuid) { ApplicationManager applicationManager = APIUtil.getApplicationManager(); try { - //todo return application - ApplicationRelease applicationRelease = applicationManager.getApplicationReleaseByUUID(uuid); - if (applicationRelease == null){ + Application application = applicationManager.getApplicationByUuid(uuid); + if (application == null){ String msg = "Application release is in the end state of the application lifecycle flow."; log.error(msg); return Response.status(Response.Status.OK).entity(msg).build(); } - return Response.status(Response.Status.OK).entity(applicationRelease).build(); + return Response.status(Response.Status.OK).entity(application).build(); } catch (NotFoundException e) { String msg = "Application Release with UUID: " + uuid + " is not found"; log.error(msg, e);