From 23e3732ac178ad75fe2507a8035a18efa8f40909 Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Mon, 24 Sep 2018 14:03:11 +0530 Subject: [PATCH] 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) {