From b7566f4e4ae5a8b3764e45aea59656f63d83fc08 Mon Sep 17 00:00:00 2001 From: ayyoob Date: Sun, 5 Feb 2017 17:51:48 +0530 Subject: [PATCH] added artifact deployment support through UI --- .../APIManagementProviderServiceImpl.java | 2 +- .../APIPublisherLifecycleListener.java | 9 ++-- .../org.wso2.carbon.device.mgt.api/pom.xml | 5 ++ .../mgt/jaxrs/util/DeviceMgtAPIUtils.java | 13 +++++ .../src/main/webapp/WEB-INF/cxf-servlet.xml | 6 ++- .../devicemgt/app/conf/app-conf.json | 2 +- .../devicemgt/app/conf/config.json | 3 +- .../cdmf.unit.ui.navbar.nav-menu/nav-menu.hbs | 22 ++++++++- .../public/js/nav-menu.js | 47 +++++++++++++++++-- pom.xml | 5 ++ 10 files changed, 100 insertions(+), 14 deletions(-) diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/src/main/java/org/wso2/carbon/apimgt/application/extension/APIManagementProviderServiceImpl.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/src/main/java/org/wso2/carbon/apimgt/application/extension/APIManagementProviderServiceImpl.java index 07f8a2a8a7..af471ebd6e 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/src/main/java/org/wso2/carbon/apimgt/application/extension/APIManagementProviderServiceImpl.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/src/main/java/org/wso2/carbon/apimgt/application/extension/APIManagementProviderServiceImpl.java @@ -93,7 +93,7 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); APIList apiList = storeClient.getApis().apisGet(MAX_API_PER_TAG, 0, tenantDomain, "tag:" + tag , CONTENT_TYPE, null); - if (apiList.getList() != null && apiList.getList().size() == 0) { + if (apiList.getList() == null || apiList.getList().size() == 0) { apiList = storeClient.getApis().apisGet(MAX_API_PER_TAG, 0 , MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, "tag:" + tag, CONTENT_TYPE, null); } diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/listener/APIPublisherLifecycleListener.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/listener/APIPublisherLifecycleListener.java index 24c73c739d..3f0730b36a 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/listener/APIPublisherLifecycleListener.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/listener/APIPublisherLifecycleListener.java @@ -109,14 +109,11 @@ public class APIPublisherLifecycleListener implements LifecycleListener { } catch (UserStoreException e) { log.error("Error while retrieving tenant admin user for the tenant domain" + PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(), e); + } catch (Throwable e) { + // This is done to stop tomcat failure if a webapp failed to publish apis. + log.error("Failed to Publish api from " + servletContext.getContextPath(), e); } } } } - - //TODO : Need to implemented, to merge API Definitions in cases where implementation of an API Lies in two classes - private List mergeAPIDefinitions(List inputList) { - return null; - } - } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml index 5ad39c39aa..11b998998d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml @@ -281,6 +281,11 @@ javax.ws.rs javax.ws.rs-api + + org.wso2.carbon.commons + org.wso2.carbon.application.mgt.stub + provided + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java index ad32fc3b98..2e562b03b3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java @@ -39,6 +39,7 @@ import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.InputValidationExcepti import org.wso2.carbon.policy.mgt.common.PolicyMonitoringTaskException; import org.wso2.carbon.policy.mgt.core.PolicyManagerService; import org.wso2.carbon.policy.mgt.core.task.TaskScheduleService; +import org.wso2.carbon.registry.core.service.RegistryService; import org.wso2.carbon.user.api.AuthorizationManager; import org.wso2.carbon.user.api.UserRealm; import org.wso2.carbon.user.api.UserStoreException; @@ -155,6 +156,18 @@ public class DeviceMgtAPIUtils { return realmService; } + public static RegistryService getRegistryService() { + RegistryService registryService; + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + registryService = (RegistryService) ctx.getOSGiService(RegistryService.class, null); + if (registryService == null) { + String msg = "registry service has not initialized."; + log.error(msg); + throw new IllegalStateException(msg); + } + return registryService; + } + /** * Getting the current tenant's user realm */ diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml index 7948186893..fd6c5e0309 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -39,6 +39,8 @@ + + @@ -80,7 +82,9 @@ - + + + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/app-conf.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/app-conf.json index 7087cdb976..bfe2bd2a0f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/app-conf.json +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/app-conf.json @@ -31,7 +31,7 @@ "issuer" : "devicemgt", "appName" : "devicemgt", "identityProviderUrl" : "https://%iot.keymanager.host%:%iot.keymanager.https.port%/samlsso", - "acs": "https://%iot.keymanager.host%:%iot.keymanager.https.port%/devicemgt/uuf/sso/acs", + "acs": "https://%iot.manager.host%:%iot.manager.https.port%/devicemgt/uuf/sso/acs", "identityAlias": "wso2carbon", "responseSigningEnabled" : true, "validateAssertionValidityPeriod": true, diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/config.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/config.json index 340aac83e8..fdd9550439 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/config.json +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/config.json @@ -175,7 +175,8 @@ "perm:ios:remove-profile", "perm:ios:get-restrictions", "perm:ios:wipe-data", - "perm:admin" + "perm:admin", + "perm:devicetype:deployment" ], "isOAuthEnabled" : true, "backendRestEndpoints" : { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/nav-menu.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/nav-menu.hbs index 61655a5f44..c3a76babc9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/nav-menu.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/nav-menu.hbs @@ -32,9 +32,29 @@ {{/if}} {{#if permissions.VIEW_DASHBOARD}}
  • - + Device Statistics +
  • {{/if}} {{#if permissions.LIST_GROUPS}} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/public/js/nav-menu.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/public/js/nav-menu.js index 2b7d3cf2d4..07ddd59f2a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/public/js/nav-menu.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/public/js/nav-menu.js @@ -20,7 +20,7 @@ var modalPopup = ".modal"; var modalPopupContainer = modalPopup + " .modal-content"; var modalPopupContent = modalPopup + " .modal-content"; -var emmAdminBasePath = "/api/device-mgt/v1.0"; +var backendEndBasePath = "/api/device-mgt/v1.0"; /* * set popup maximum height function. @@ -66,7 +66,7 @@ var updateNotificationCount = function (data, textStatus, jqXHR) { function loadNotificationsPanel() { if ("true" == $("#right-sidebar").attr("is-authorized")) { - var serviceURL = emmAdminBasePath + "/notifications?status=NEW"; + var serviceURL = backendEndBasePath + "/notifications?status=NEW"; invokerUtil.get(serviceURL, updateNotificationCount, hideNotificationCount); loadNewNotifications(); } else { @@ -90,7 +90,7 @@ function loadNewNotifications() { var currentUser = notifications.data("currentUser"); $.template("notification-listing", notifications.attr("src"), function (template) { - var serviceURL = emmAdminBasePath + "/notifications?status=NEW"; + var serviceURL = backendEndBasePath + "/notifications?status=NEW"; var successCallback = function (data, textStatus, jqXHR) { if (jqXHR.status == 200 && data) { @@ -453,3 +453,44 @@ $(document).ready(function () { }); } }); + +function statisticLoad(redirectUrl) { + var contentType = "application/json"; + + var uri = backendEndBasePath + "/admin/devicetype/deploy/device_management/status"; + var defaultStatusClasses = "fw fw-stack-1x"; + var content = $("#statistic-response-template").find(".content"); + var title = content.find("#title"); + var statusIcon = content.find("#status-icon"); + + invokerUtil.get(uri, function (data, textStatus, jqXHR) { + if (jqXHR.status == 204) { + var urix = backendEndBasePath + "/admin/devicetype/deploy/device_management"; + var device = {}; + invokerUtil.post(urix, device, function (data) { + title.html("Deploying statistic artifacts. Please wait..."); + statusIcon.attr("class", defaultStatusClasses + " fw-check"); + $(modalPopupContent).html(content.html()); + showPopup(); + setTimeout(function () { + hidePopup(); + // location.reload(true); + location.href = redirectUrl; + }, 20000); + + }, function (jqXHR) { + title.html("Failed to deploy artifacts, Please contact administrator."); + statusIcon.attr("class", defaultStatusClasses + " fw-error"); + $(modalPopupContent).html(content.html()); + showPopup(); + }, contentType); + } else { + location.href = redirectUrl; + } + }, function (jqXHR) { + title.html("Failed to connect with server, Please contact administrator."); + statusIcon.attr("class", defaultStatusClasses + " fw-error"); + $(modalPopupContent).html(content.html()); + showPopup(); + }, contentType); +} diff --git a/pom.xml b/pom.xml index 9bbaf653fa..3e745d19bd 100644 --- a/pom.xml +++ b/pom.xml @@ -1161,6 +1161,11 @@ + + org.wso2.carbon.commons + org.wso2.carbon.application.mgt.stub + ${carbon.commons.version} + org.wso2.orbit.org.bouncycastle