From cedb6cb798bf6eac4774bb4438569f451d29bfbe Mon Sep 17 00:00:00 2001 From: ayyoob Date: Fri, 5 May 2017 03:02:35 +0530 Subject: [PATCH] fixed device stats loading page issue --- .../DeviceTypePublisherAdminService.java | 38 ------------ .../DeviceTypePublisherAdminServiceImpl.java | 61 ++++++------------- .../app/modules/business-controllers/user.js | 3 + .../public/js/nav-menu.js | 53 ++++++++++------ 4 files changed, 55 insertions(+), 100 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/DeviceTypePublisherAdminService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/DeviceTypePublisherAdminService.java index 7914f9d071..d3c3ee25c2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/DeviceTypePublisherAdminService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/DeviceTypePublisherAdminService.java @@ -107,42 +107,4 @@ public interface DeviceTypePublisherAdminService { required = true) @PathParam("type") String type); - @GET - @Path("/deploy/{type}/status") - @ApiOperation( - httpMethod = "GET", - value = "Check the status of device type artifact\n", - notes = "This is an API that can be used to check the status of the artifact", - response = Response.class, - tags = "Devicetype Status Service", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "perm:devicetype:deployment") - }) - }) - - @ApiResponses(value = { - @ApiResponse( - code = 201, - message = "OK. \n Successfully deployed the artifacts.", - response = Response.class), - @ApiResponse( - code = 400, - message = "Bad Request. \n Invalid request or validation error.", - response = ErrorResponse.class), - @ApiResponse( - code = 404, - message = "Not Found. \n The specified resource does not exist."), - @ApiResponse( - code = 415, - message = "Unsupported media type. \n The entity of the request was in a not supported format."), - @ApiResponse( - code = 500, - message = "Internal Server Error. \n Server error occurred while checking the authorization" + - " for a specified set of devices.", - response = ErrorResponse.class) - }) - - Response getStatus(@PathParam("type") String deviceType); - } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceTypePublisherAdminServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceTypePublisherAdminServiceImpl.java index d959113709..9fbd5043e2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceTypePublisherAdminServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceTypePublisherAdminServiceImpl.java @@ -185,14 +185,6 @@ public class DeviceTypePublisherAdminServiceImpl implements DeviceTypePublisherA if (receiverFileList != null) { publishDynamicEventReceivers(type, tenantDomain, receiverFileList); } - int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); - Registry registry = DeviceMgtAPIUtils.getRegistryService().getConfigSystemRegistry(tenantId); - if (!registry.resourceExists(DEFAULT_RESOURCE_LOCATION + type + ".exist")) { - Resource resource = new ResourceImpl(); - resource.setContent(""); - resource.setMediaType(MEDIA_TYPE_XML); - registry.put(DEFAULT_RESOURCE_LOCATION + type + ".exist", resource); - } return Response.status(Response.Status.CREATED).entity("\"OK. \\n Successfully uploaded the artifacts.\"") .build(); } catch (AxisFault e) { @@ -227,23 +219,25 @@ public class DeviceTypePublisherAdminServiceImpl implements DeviceTypePublisherA if (directory.isDirectory() && directory.exists()) { UploadedFileItem[] uploadedFileItems = loadCappFromFileSystem(type); if (uploadedFileItems.length > 0) { - carbonAppUploaderStub = new CarbonAppUploaderStub(Utils.replaceSystemProperty( - IOT_MGT_URL)); - Options appUploaderOptions = carbonAppUploaderStub._getServiceClient().getOptions(); - if (appUploaderOptions == null) { - appUploaderOptions = new Options(); - } - appUploaderOptions.setProperty(HTTPConstants.HTTP_HEADERS, list); - appUploaderOptions.setProperty(HTTPConstants.CUSTOM_PROTOCOL_HANDLER - , new Protocol(DEFAULT_HTTP_PROTOCOL, (ProtocolSocketFactory) new SSLProtocolSocketFactory - (sslContext), Integer.parseInt(Utils.replaceSystemProperty(IOT_MGT_PORT)))); - - carbonAppUploaderStub._getServiceClient().setOptions(appUploaderOptions); - carbonAppUploaderStub.uploadApp(uploadedFileItems); + if (DEVICE_MANAGEMENT_TYPE.equals(type.toLowerCase())) { + carbonAppUploaderStub = new CarbonAppUploaderStub(Utils.replaceSystemProperty( + IOT_MGT_URL)); + Options appUploaderOptions = carbonAppUploaderStub._getServiceClient().getOptions(); + if (appUploaderOptions == null) { + appUploaderOptions = new Options(); + } + appUploaderOptions.setProperty(HTTPConstants.HTTP_HEADERS, list); + appUploaderOptions.setProperty(HTTPConstants.CUSTOM_PROTOCOL_HANDLER + , new Protocol(DEFAULT_HTTP_PROTOCOL, + (ProtocolSocketFactory) new SSLProtocolSocketFactory + (sslContext), Integer.parseInt(Utils.replaceSystemProperty( + IOT_MGT_PORT)))); - if (!DEVICE_MANAGEMENT_TYPE.equals(type.toLowerCase())) { + carbonAppUploaderStub._getServiceClient().setOptions(appUploaderOptions); + carbonAppUploaderStub.uploadApp(uploadedFileItems); + } else { carbonAppUploaderStub = new CarbonAppUploaderStub(Utils.replaceSystemProperty(DAS_URL)); - appUploaderOptions = carbonAppUploaderStub._getServiceClient().getOptions(); + Options appUploaderOptions = carbonAppUploaderStub._getServiceClient().getOptions(); if (appUploaderOptions == null) { appUploaderOptions = new Options(); } @@ -266,27 +260,6 @@ public class DeviceTypePublisherAdminServiceImpl implements DeviceTypePublisherA } } - @GET - @Path("/deploy/{type}/status") - @Override - public Response getStatus(@PathParam("type") String deviceType) { - int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); - Registry registry; - try { - registry = DeviceMgtAPIUtils.getRegistryService().getConfigSystemRegistry(tenantId); - if (registry.resourceExists(DEFAULT_RESOURCE_LOCATION + deviceType + ".exist")) { - return Response.status(Response.Status.OK).entity("Exist").build(); - } else { - return Response.status(Response.Status.NO_CONTENT).entity("Does not Exist").build(); - } - } catch (RegistryException e) { - log.error("Registry failed to load." + e.getMessage(), e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( - "\"Error, Artifact status check has failed\"").build(); - } - } - - private void publishDynamicEventReceivers(String deviceType, String tenantDomain, List receiversList) throws IOException, UserStoreException, JWTClientException { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js index e85f46c347..f8c420d58c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js @@ -612,6 +612,9 @@ var userModule = function () { if (publicMethods.isAuthorized("/permission/admin/device-mgt/devices/change-status")) { permissions["CHANGE_DEVICE_STATUS"] = true; } + if (publicMethods.isAuthorized("/permission/admin/device-mgt")) { + permissions["IS_ADMIN"] = true; + } return permissions; }; 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 07ddd59f2a..40c1cdd4f0 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 @@ -456,15 +456,18 @@ $(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) { + $.ajax({ + url: redirectUrl, + type: "GET", + success: function () { + window.location.href = redirectUrl; + }, + error: function() { var urix = backendEndBasePath + "/admin/devicetype/deploy/device_management"; var device = {}; invokerUtil.post(urix, device, function (data) { @@ -472,25 +475,39 @@ function statisticLoad(redirectUrl) { statusIcon.attr("class", defaultStatusClasses + " fw-check"); $(modalPopupContent).html(content.html()); showPopup(); - setTimeout(function () { - hidePopup(); - // location.reload(true); - location.href = redirectUrl; - }, 20000); - + poll(redirectUrl); }, 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); + }); + } +var pollingCount = 15; +function poll(portalUrl) { + var content = $("#statistic-response-template").find(".content"); + var title = content.find("#title"); + var defaultStatusClasses = "fw fw-stack-1x"; + var statusIcon = content.find("#status-icon"); + $.ajax({ + url: portalUrl, + type: "GET", + success: function (data) { + window.location.href = portalUrl; + }, + dataType: "json", + error: setTimeout(function () { + pollingCount = pollingCount - 1; + if (pollingCount > 0) { + poll(portalUrl); + } else { + window.location.href = portalUrl; + } + }, 5000), + timeout: 5000 + }); +} +