From dd1c2e43385fd0ac8f86d0b9d58329f881961f8e Mon Sep 17 00:00:00 2001 From: ayyoob Date: Mon, 22 May 2017 02:51:35 +0530 Subject: [PATCH] Added few fixes after testing and added default UI for device type management --- .../api/DeviceEventManagementService.java | 2 +- .../DeviceTypeManagementAdminService.java | 52 ++++ .../DeviceEventManagementServiceImpl.java | 30 +- .../DeviceTypeManagementAdminServiceImpl.java | 23 +- .../type/mgt/DeviceTypeMetaDefinition.java | 9 + .../DeviceManagementPluginRepository.java | 75 +++-- .../dto/DeviceManagementServiceHolder.java | 47 +++ .../dto}/DeviceTypeServiceIdentifier.java | 2 +- .../mgt/OperationManagerRepository.java | 2 +- .../DeviceManagementProviderService.java | 6 + .../DeviceManagementProviderServiceImpl.java | 19 +- .../src/test/resources/sql/h2.sql | 2 +- .../template/DeviceTypeManagerService.java | 3 +- .../HTTPDeviceTypeManagerService.java | 23 +- .../devicemgt/app/conf/config.json | 3 +- .../modules/business-controllers/device.js | 28 ++ .../pages/cdmf.page.dashboard/dashboard.hbs | 34 +++ .../pages/cdmf.page.dashboard/dashboard.js | 1 + .../cdmf.page.devicetype.create/create.hbs | 226 +++++++++++++++ .../cdmf.page.devicetype.create/create.js | 29 ++ .../cdmf.page.devicetype.create/create.json | 5 + .../public/css/devicetype.css | 10 + .../public/js/bottomJs.js | 240 +++++++++++++++ .../pages/cdmf.page.devicetype.edit/edit.hbs | 273 ++++++++++++++++++ .../pages/cdmf.page.devicetype.edit/edit.js | 52 ++++ .../pages/cdmf.page.devicetype.edit/edit.json | 5 + .../public/css/devicetype.css | 13 + .../public/js/bottomJs.js | 243 ++++++++++++++++ .../cdmf.page.devicetype.event.edit/edit.hbs | 160 ++++++++++ .../cdmf.page.devicetype.event.edit/edit.js | 51 ++++ .../cdmf.page.devicetype.event.edit/edit.json | 5 + .../public/css/devicetype.css | 13 + .../public/js/bottomJs.js | 182 ++++++++++++ .../cdmf.page.devicetypes/devicetypes.hbs | 110 +++++++ .../cdmf.page.devicetypes/devicetypes.js | 36 +++ .../cdmf.page.devicetypes/devicetypes.json | 5 + .../public/js/devicetype-listing.js | 206 +++++++++++++ .../public/templates/devicetype-listing.hbs | 44 +++ .../cdmf.unit.ui.navbar.nav-menu/nav-menu.hbs | 9 +- .../src/test/resources/sql/CreateH2TestDB.sql | 2 +- .../src/main/resources/dbscripts/cdm/h2.sql | 2 +- .../main/resources/dbscripts/cdm/mssql.sql | 2 +- .../main/resources/dbscripts/cdm/mysql.sql | 2 +- .../main/resources/dbscripts/cdm/oracle.sql | 2 +- .../resources/dbscripts/cdm/postgresql.sql | 2 +- 45 files changed, 2226 insertions(+), 64 deletions(-) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/DeviceManagementServiceHolder.java rename components/device-mgt/{org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common => org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto}/DeviceTypeServiceIdentifier.java (97%) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.create/create.hbs create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.create/create.js create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.create/create.json create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.create/public/css/devicetype.css create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.create/public/js/bottomJs.js create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.edit/edit.hbs create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.edit/edit.js create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.edit/edit.json create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.edit/public/css/devicetype.css create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.edit/public/js/bottomJs.js create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.event.edit/edit.hbs create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.event.edit/edit.js create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.event.edit/edit.json create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.event.edit/public/css/devicetype.css create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.event.edit/public/js/bottomJs.js create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetypes/devicetypes.hbs create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetypes/devicetypes.js create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetypes/devicetypes.json create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetypes/public/js/devicetype-listing.js create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetypes/public/templates/devicetype-listing.hbs diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceEventManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceEventManagementService.java index 5a77c51074a..a6fff500fea 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceEventManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceEventManagementService.java @@ -257,7 +257,7 @@ public interface DeviceEventManagementService { @ApiResponse( code = 200, message = "OK. \n Successfully fetched the event defintion.", - response = EventAttributeList.class, + response = DeviceTypeEvent.class, responseHeaders = { @ResponseHeader( name = "Content-Type", diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/DeviceTypeManagementAdminService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/DeviceTypeManagementAdminService.java index b01c18ab8d0..aa90b5b3042 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/DeviceTypeManagementAdminService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/DeviceTypeManagementAdminService.java @@ -33,6 +33,7 @@ import org.wso2.carbon.apimgt.annotations.api.Scope; import org.wso2.carbon.apimgt.annotations.api.Scopes; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.core.dto.DeviceType; +import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceTypeList; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; import org.wso2.carbon.device.mgt.jaxrs.util.Constants; @@ -81,6 +82,57 @@ import javax.ws.rs.core.Response; ) public interface DeviceTypeManagementAdminService { + @GET + @ApiOperation( + produces = MediaType.APPLICATION_JSON, + httpMethod = "GET", + value = "Getting the Supported Device Type with Meta Definition", + notes = "Get the list of device types supported by WSO2 IoT.", + tags = "Device Type Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "perm:admin:device-type") + }) + } + ) + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully fetched the list of supported device types.", + response = DeviceTypeList.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Type", + description = "The content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = + "Date and time the resource was last modified.\n" + + "Used by caches, or in conditional requests."), + } + ), + @ApiResponse( + code = 304, + message = + "Not Modified. \n Empty body because the client already has the latest version " + + "of the requested resource.\n"), + @ApiResponse( + code = 406, + message = "Not Acceptable.\n The requested media type is not supported"), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Server error occurred while fetching the " + + "list of supported device types.", + response = ErrorResponse.class) + } + ) + Response getDeviceTypes(); + @POST @ApiOperation( produces = MediaType.APPLICATION_JSON, diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceEventManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceEventManagementServiceImpl.java index 2d26538ec4e..ea9d01de8b7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceEventManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceEventManagementServiceImpl.java @@ -40,16 +40,17 @@ import org.wso2.carbon.device.mgt.jaxrs.service.api.DeviceEventManagementService import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; import org.wso2.carbon.event.publisher.stub.EventPublisherAdminServiceCallbackHandler; import org.wso2.carbon.event.publisher.stub.EventPublisherAdminServiceStub; +import org.wso2.carbon.event.receiver.stub.types.EventMappingPropertyDto; import org.wso2.carbon.event.receiver.stub.EventReceiverAdminServiceCallbackHandler; import org.wso2.carbon.event.receiver.stub.EventReceiverAdminServiceStub; import org.wso2.carbon.event.receiver.stub.types.BasicInputAdapterPropertyDto; +import org.wso2.carbon.event.receiver.stub.types.EventReceiverConfigurationDto; import org.wso2.carbon.event.stream.stub.EventStreamAdminServiceStub; import org.wso2.carbon.event.stream.stub.types.EventStreamAttributeDto; import org.wso2.carbon.event.stream.stub.types.EventStreamDefinitionDto; import org.wso2.carbon.identity.jwt.client.extension.JWTClient; import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException; import org.wso2.carbon.user.api.UserStoreException; -import org.wso2.carbon.analytics.datasource.commons.Record; import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException; import javax.net.ssl.KeyManagerFactory; @@ -107,6 +108,8 @@ public class DeviceEventManagementServiceImpl implements DeviceEventManagementSe private static final String DEFAULT_STREAM_VERSION = "1.0.0"; private static final String DEFAULT_EVENT_STORE_NAME = "EVENT_STORE"; private static final String DEFAULT_WEBSOCKET_PUBLISHER_ADAPTER_TYPE = "secured-websocket"; + private static final String OAUTH_MQTT_ADAPTER_TYPE = "oauth-mqtt"; + private static final String OAUTH_HTTP_ADAPTER_TYPE = "oauth-http"; private static KeyStore keyStore; private static KeyStore trustStore; @@ -140,6 +143,7 @@ public class DeviceEventManagementServiceImpl implements DeviceEventManagementSe public Response getDeviceTypeEventDefinition(@PathParam("type") String deviceType) { String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); EventStreamAdminServiceStub eventStreamAdminServiceStub = null; + EventReceiverAdminServiceStub eventReceiverAdminServiceStub = null; try { if (deviceType == null || !DeviceMgtAPIUtils.getDeviceManagementService().getAvailableDeviceTypes().contains(deviceType)) { @@ -162,7 +166,18 @@ public class DeviceEventManagementServiceImpl implements DeviceEventManagementSe , AttributeType.valueOf(eventStreamAttributeDto.getAttributeType().toUpperCase()))); } eventAttributeList.setList(attributes); - return Response.ok().entity(eventAttributeList).build(); + DeviceTypeEvent deviceTypeEvent = new DeviceTypeEvent(); + deviceTypeEvent.setEventAttributeList(eventAttributeList); + deviceTypeEvent.setTransportType(TransportType.HTTP); + eventReceiverAdminServiceStub = getEventReceiverAdminServiceStub(); + EventReceiverConfigurationDto eventReceiverConfigurationDto = eventReceiverAdminServiceStub + .getActiveEventReceiverConfiguration(getReceiverName(deviceType, tenantDomain)); + String eventAdapterType = eventReceiverConfigurationDto.getFromAdapterConfigurationDto() + .getEventAdapterType(); + if (OAUTH_MQTT_ADAPTER_TYPE.equals(eventAdapterType)) { + deviceTypeEvent.setTransportType(TransportType.MQTT); + } + return Response.ok().entity(deviceTypeEvent).build(); } catch (AxisFault e) { log.error("failed to retrieve event definitions for tenantDomain:" + tenantDomain, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); @@ -180,6 +195,7 @@ public class DeviceEventManagementServiceImpl implements DeviceEventManagementSe return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } finally { cleanup(eventStreamAdminServiceStub); + cleanup(eventReceiverAdminServiceStub); } } @@ -293,8 +309,8 @@ public class DeviceEventManagementServiceImpl implements DeviceEventManagementSe if (!MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) { tenantBasedEventReceiverAdminServiceStub = getEventReceiverAdminServiceStub(); tenantBasedEventStreamAdminServiceStub = getEventStreamAdminServiceStub(); - eventStreamAdminServiceStub.removeEventStreamDefinition(streamName, DEFAULT_STREAM_VERSION); - eventReceiverAdminServiceStub.startundeployInactiveEventReceiverConfiguration(eventReceiverName + tenantBasedEventStreamAdminServiceStub.removeEventStreamDefinition(streamName, DEFAULT_STREAM_VERSION); + tenantBasedEventReceiverAdminServiceStub.startundeployInactiveEventReceiverConfiguration(eventReceiverName , eventReceiverAdminServiceCallbackHandler); } @@ -323,6 +339,8 @@ public class DeviceEventManagementServiceImpl implements DeviceEventManagementSe cleanup(eventReceiverAdminServiceStub); cleanup(eventReceiverAdminServiceStub); cleanup(eventStreamAdminServiceStub); + cleanup(tenantBasedEventReceiverAdminServiceStub); + cleanup(tenantBasedEventStreamAdminServiceStub); } } @@ -373,7 +391,7 @@ public class DeviceEventManagementServiceImpl implements DeviceEventManagementSe throws RemoteException, UserStoreException, JWTClientException { EventReceiverAdminServiceStub receiverAdminServiceStub = getEventReceiverAdminServiceStub(); try { - String adapterType = "oauth-mqtt"; + String adapterType = OAUTH_MQTT_ADAPTER_TYPE; BasicInputAdapterPropertyDto basicInputAdapterPropertyDtos[]; if (transportType == TransportType.MQTT) { basicInputAdapterPropertyDtos = new BasicInputAdapterPropertyDto[4]; @@ -383,7 +401,7 @@ public class DeviceEventManagementServiceImpl implements DeviceEventManagementSe basicInputAdapterPropertyDtos[2] = getBasicInputAdapterPropertyDto("cleanSession", "true"); basicInputAdapterPropertyDtos[3] = getBasicInputAdapterPropertyDto("clientId", generateUUID()); } else { - adapterType = "oauth-http"; + adapterType = OAUTH_HTTP_ADAPTER_TYPE; basicInputAdapterPropertyDtos = new BasicInputAdapterPropertyDto[1]; basicInputAdapterPropertyDtos[0] = getBasicInputAdapterPropertyDto("contentValidator", "iot-mqtt"); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceTypeManagementAdminServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceTypeManagementAdminServiceImpl.java index aaeee3a0af7..d573414ea0b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceTypeManagementAdminServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceTypeManagementAdminServiceImpl.java @@ -23,16 +23,21 @@ import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.core.dto.DeviceType; import org.wso2.carbon.device.mgt.extensions.device.type.template.HTTPDeviceTypeManagerService; +import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceTypeList; +import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; import org.wso2.carbon.device.mgt.jaxrs.service.api.admin.DeviceTypeManagementAdminService; import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.HeaderParam; import javax.ws.rs.POST; import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import java.util.List; @Path("/admin/device-types") @Produces(MediaType.APPLICATION_JSON) @@ -41,10 +46,24 @@ public class DeviceTypeManagementAdminServiceImpl implements DeviceTypeManagemen private static final Log log = LogFactory.getLog(DeviceTypeManagementAdminServiceImpl.class); + @GET + @Override + public Response getDeviceTypes() { + try { + List deviceTypes = DeviceMgtAPIUtils.getDeviceManagementService().getDeviceTypes(); + return Response.status(Response.Status.OK).entity(deviceTypes).build(); + } catch (DeviceManagementException e) { + String msg = "Error occurred while fetching the list of device types."; + log.error(msg, e); + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); + } + } + @Override @POST public Response addDeviceType(DeviceType deviceType) { - if (deviceType != null) { + if (deviceType != null && deviceType.getDeviceTypeMetaDefinition() != null) { try { if (DeviceMgtAPIUtils.getDeviceManagementService().getDeviceType(deviceType.getName()) != null) { String msg = "Device type already available, " + deviceType.getName(); @@ -67,7 +86,7 @@ public class DeviceTypeManagementAdminServiceImpl implements DeviceTypeManagemen @Override @PUT public Response updateDeviceType(DeviceType deviceType) { - if (deviceType != null) { + if (deviceType != null && deviceType.getDeviceTypeMetaDefinition() != null) { try { if (DeviceMgtAPIUtils.getDeviceManagementService().getDeviceType(deviceType.getName()) == null) { String msg = "Device type does not exist, " + deviceType.getName(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/type/mgt/DeviceTypeMetaDefinition.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/type/mgt/DeviceTypeMetaDefinition.java index 8f6cd14a6d5..d0eb605e1f0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/type/mgt/DeviceTypeMetaDefinition.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/type/mgt/DeviceTypeMetaDefinition.java @@ -18,6 +18,15 @@ public class DeviceTypeMetaDefinition { private OperationMonitoringTaskConfig taskConfig; private InitialOperationConfig initialOperationConfig; private License license; + private String description; + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } public List getProperties() { return properties; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java index b547221d728..26ed67ff187 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java @@ -22,7 +22,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.DeviceTypeServiceIdentifier; +import org.wso2.carbon.device.mgt.core.dto.DeviceManagementServiceHolder; +import org.wso2.carbon.device.mgt.core.dto.DeviceTypeServiceIdentifier; import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig; import org.wso2.carbon.device.mgt.common.ProvisioningConfig; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager; @@ -50,8 +51,7 @@ import java.util.Map; public class DeviceManagementPluginRepository implements DeviceManagerStartupListener { - private Map providers; - private Map dynamicProviderTimestamp; + private Map providers; private boolean isInited; private static final Log log = LogFactory.getLog(DeviceManagementPluginRepository.class); private OperationManagerRepository operationManagerRepository; @@ -59,8 +59,7 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis public DeviceManagementPluginRepository() { this.operationManagerRepository = new OperationManagerRepository(); - providers = Collections.synchronizedMap(new HashMap()); - dynamicProviderTimestamp = Collections.synchronizedMap(new HashMap()); + providers = Collections.synchronizedMap(new HashMap()); DeviceManagementServiceComponent.registerStartupListener(this); } @@ -81,15 +80,23 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis provider.init(); DeviceTypeMetaDefinition deviceTypeDefinition = null; if (provider instanceof DeviceTypeDefinitionProvider) { + DeviceTypeServiceIdentifier deviceTypeIdentifier = new DeviceTypeServiceIdentifier( + provider.getType()); + DeviceManagementServiceHolder existingProvider = providers.get(deviceTypeIdentifier); deviceTypeDefinition = ((DeviceTypeDefinitionProvider) provider).getDeviceTypeMeta(); + if (existingProvider != null && !(existingProvider.getDeviceManagementService() + instanceof DeviceTypeDefinitionProvider)) { + throw new DeviceManagementException("Definition of device type " + provider.getType() + + " is already available through sharing."); + } - DeviceTypeServiceIdentifier deviceTypeIdentifier = new DeviceTypeServiceIdentifier( - provider.getType().toLowerCase(), tenantId); - DeviceManagementService existingProvider = providers.get(deviceTypeIdentifier); + deviceTypeIdentifier = new DeviceTypeServiceIdentifier(provider.getType(), tenantId); + existingProvider = providers.get(deviceTypeIdentifier); if (existingProvider != null) { removeDeviceManagementProvider(provider); } } + DeviceManagerUtil.registerDeviceType(deviceType, tenantId, isSharedWithAllTenants, deviceTypeDefinition); DeviceManagementDataHolder.getInstance().setRequireDeviceAuthorization(deviceType, provider.getDeviceManager() @@ -101,15 +108,13 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis throw new DeviceManagementException("Error occurred while adding device management provider '" + deviceType + "'", e); } + DeviceManagementServiceHolder deviceManagementServiceHolder = new DeviceManagementServiceHolder(provider); if (isSharedWithAllTenants) { DeviceTypeServiceIdentifier deviceTypeIdentifier = new DeviceTypeServiceIdentifier(deviceType); - providers.put(deviceTypeIdentifier, provider); + providers.put(deviceTypeIdentifier, deviceManagementServiceHolder); } else { DeviceTypeServiceIdentifier deviceTypeIdentifier = new DeviceTypeServiceIdentifier(deviceType, tenantId); - providers.put(deviceTypeIdentifier, provider); - if (provider instanceof DeviceTypeDefinitionProvider) { - dynamicProviderTimestamp.put(deviceTypeIdentifier, System.currentTimeMillis()); - } + providers.put(deviceTypeIdentifier, deviceManagementServiceHolder); } } } @@ -126,9 +131,6 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis int providerTenantId = DeviceManagerUtil.getTenantId(provisioningConfig.getProviderTenantDomain()); deviceTypeIdentifier = new DeviceTypeServiceIdentifier(deviceTypeName, providerTenantId); providers.remove(deviceTypeIdentifier); - if (provider instanceof DeviceTypeDefinitionProvider) { - dynamicProviderTimestamp.remove(deviceTypeIdentifier); - } } unregisterPushNotificationStrategy(deviceTypeIdentifier); unregisterMonitoringTask(provider); @@ -148,30 +150,39 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis public DeviceManagementService getDeviceManagementService(String type, int tenantId) { //Priority need to be given to the tenant before public. - DeviceTypeServiceIdentifier deviceTypeIdentifier = new DeviceTypeServiceIdentifier(type.toLowerCase(), tenantId); - DeviceManagementService provider = providers.get(deviceTypeIdentifier); + DeviceTypeServiceIdentifier deviceTypeIdentifier = new DeviceTypeServiceIdentifier(type, tenantId); + DeviceManagementServiceHolder provider = providers.get(deviceTypeIdentifier); if (provider == null) { - deviceTypeIdentifier = new DeviceTypeServiceIdentifier(type.toLowerCase()); + deviceTypeIdentifier = new DeviceTypeServiceIdentifier(type); provider = providers.get(deviceTypeIdentifier); if (provider == null) { try { - DeviceType deviceType = DeviceManagerUtil.getDeviceType(type,tenantId); + DeviceType deviceType = DeviceManagerUtil.getDeviceType(type, tenantId); + if (deviceType == null) { + return null; + } DeviceTypeMetaDefinition deviceTypeMetaDefinition = deviceType.getDeviceTypeMetaDefinition(); if (deviceTypeMetaDefinition != null) { HTTPDeviceTypeManagerService deviceTypeManagerService = new HTTPDeviceTypeManagerService (type, deviceTypeMetaDefinition); addDeviceManagementProvider(deviceTypeManagerService); + deviceTypeIdentifier = new DeviceTypeServiceIdentifier(type, tenantId); + provider = providers.get(deviceTypeIdentifier); } } catch (DeviceManagementException e) { log.error("Failing to retrieve the device type service for " + type, e); return null; } } + if (provider == null) { + log.error("Device Type Definition not found for " + type); + return null; + } } else { // retrieves per tenant device type management service - if (provider instanceof DeviceTypeDefinitionProvider) { + if (provider.getDeviceManagementService() instanceof DeviceTypeDefinitionProvider) { //handle updates. - long updatedTimestamp = dynamicProviderTimestamp.get(deviceTypeIdentifier); + long updatedTimestamp = provider.getTimestamp(); if (System.currentTimeMillis() - updatedTimestamp > DEFAULT_UPDATE_TIMESTAMP) { try { DeviceType deviceType = DeviceManagerUtil.getDeviceType(type,tenantId); @@ -179,7 +190,8 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis if (deviceTypeMetaDefinition != null) { Gson gson = new Gson(); String dbStoredDefinition = gson.toJson(deviceTypeMetaDefinition); - deviceTypeMetaDefinition = ((DeviceTypeDefinitionProvider) provider).getDeviceTypeMeta(); + deviceTypeMetaDefinition = ((DeviceTypeDefinitionProvider) + provider.getDeviceManagementService()).getDeviceTypeMeta(); String cachedDefinition = gson.toJson(deviceTypeMetaDefinition); if (!cachedDefinition.equals(dbStoredDefinition)) { HTTPDeviceTypeManagerService deviceTypeManagerService = new HTTPDeviceTypeManagerService @@ -196,14 +208,14 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis } } } - return provider; + return provider.getDeviceManagementService(); } public Map getAllDeviceManagementServices(int tenantId) { Map tenantProviders = new HashMap<>(); for (DeviceTypeServiceIdentifier identifier : providers.keySet()) { if (identifier.getTenantId() == tenantId || identifier.isSharedWithAllTenant()) { - tenantProviders.put(identifier, providers.get(identifier)); + tenantProviders.put(identifier, providers.get(identifier).getDeviceManagementService()); } } return tenantProviders; @@ -289,10 +301,10 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis public OperationManager getOperationManager(String deviceType, int tenantId) { //Priority need to be given to the tenant before public. - DeviceTypeServiceIdentifier deviceTypeIdentifier = new DeviceTypeServiceIdentifier(deviceType.toLowerCase(), tenantId); + DeviceTypeServiceIdentifier deviceTypeIdentifier = new DeviceTypeServiceIdentifier(deviceType, tenantId); OperationManager operationManager = operationManagerRepository.getOperationManager(deviceTypeIdentifier); if (operationManager == null) { - deviceTypeIdentifier = new DeviceTypeServiceIdentifier(deviceType.toLowerCase()); + deviceTypeIdentifier = new DeviceTypeServiceIdentifier(deviceType); operationManager = operationManagerRepository.getOperationManager(deviceTypeIdentifier); } return operationManager; @@ -302,10 +314,11 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis public void notifyObserver() { String deviceTypeName; synchronized (providers) { - for (DeviceManagementService provider : providers.values()) { + for (DeviceManagementServiceHolder deviceManagementServiceHolder : providers.values()) { + DeviceManagementService provider= deviceManagementServiceHolder.getDeviceManagementService(); try { provider.init(); - deviceTypeName = provider.getType().toLowerCase(); + deviceTypeName = provider.getType(); ProvisioningConfig provisioningConfig = provider.getProvisioningConfig(); int tenantId = DeviceManagerUtil.getTenantId(provisioningConfig.getProviderTenantDomain()); DeviceTypeMetaDefinition deviceTypeDefinition = null; @@ -313,8 +326,8 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis deviceTypeDefinition = ((DeviceTypeDefinitionProvider) provider).getDeviceTypeMeta(); DeviceTypeServiceIdentifier deviceTypeIdentifier = new DeviceTypeServiceIdentifier( - provider.getType().toLowerCase(), tenantId); - DeviceManagementService existingProvider = providers.get(deviceTypeIdentifier); + provider.getType(), tenantId); + DeviceManagementServiceHolder existingProvider = providers.get(deviceTypeIdentifier); if (existingProvider == null) { removeDeviceManagementProvider(provider); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/DeviceManagementServiceHolder.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/DeviceManagementServiceHolder.java new file mode 100644 index 00000000000..d8491204145 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/DeviceManagementServiceHolder.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2017, 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.mgt.core.dto; + +import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; + +/** + * This holds the information of the registered device management service against the device type + * definition loaded timestamp. This is used to handle device type update scenario. + */ +public class DeviceManagementServiceHolder { + + private DeviceManagementService deviceManagementService; + private long timestamp; + + public DeviceManagementServiceHolder(DeviceManagementService deviceManagementService) { + this.deviceManagementService = deviceManagementService; + this.timestamp = System.currentTimeMillis(); + } + + public DeviceManagementService getDeviceManagementService() { + return deviceManagementService; + } + + public long getTimestamp() { + return timestamp; + } + + public void setTimestamp(long timestamp) { + this.timestamp = timestamp; + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceTypeServiceIdentifier.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/DeviceTypeServiceIdentifier.java similarity index 97% rename from components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceTypeServiceIdentifier.java rename to components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/DeviceTypeServiceIdentifier.java index 2b55b13a229..70f6ce84be2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceTypeServiceIdentifier.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/DeviceTypeServiceIdentifier.java @@ -15,7 +15,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.wso2.carbon.device.mgt.common; +package org.wso2.carbon.device.mgt.core.dto; import java.io.Serializable; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerRepository.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerRepository.java index d59a3748f54..8a44192f00d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerRepository.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerRepository.java @@ -18,7 +18,7 @@ */ package org.wso2.carbon.device.mgt.core.operation.mgt; -import org.wso2.carbon.device.mgt.common.DeviceTypeServiceIdentifier; +import org.wso2.carbon.device.mgt.core.dto.DeviceTypeServiceIdentifier; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager; import java.util.Map; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java index 4398349a892..b88a43b2569 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java @@ -343,4 +343,10 @@ public interface DeviceManagementProviderService { * @throws DeviceManagementException */ DeviceType getDeviceType(String deviceType) throws DeviceManagementException; + + /** + * This retrieves the device type info for the given type + * @throws DeviceManagementException + */ + List getDeviceTypes() throws DeviceManagementException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index 376acb49163..22439fafe40 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -28,7 +28,7 @@ import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManager; import org.wso2.carbon.device.mgt.common.DeviceNotFoundException; -import org.wso2.carbon.device.mgt.common.DeviceTypeServiceIdentifier; +import org.wso2.carbon.device.mgt.core.dto.DeviceTypeServiceIdentifier; import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.FeatureManager; import org.wso2.carbon.device.mgt.common.InitialOperationConfig; @@ -2174,7 +2174,6 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public DeviceType getDeviceType(String deviceType) throws DeviceManagementException { - HashMap deviceHashMap; try { DeviceManagementDAOFactory.openConnection(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); @@ -2187,4 +2186,20 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv DeviceManagementDAOFactory.closeConnection(); } } + + @Override + public List getDeviceTypes() throws DeviceManagementException { + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); + try { + DeviceManagementDAOFactory.openConnection(); + return deviceTypeDAO.getDeviceTypes(tenantId); + } catch (DeviceManagementDAOException e) { + throw new DeviceManagementException("Error occurred while obtaining the device types for tenant " + + tenantId, e); + } catch (SQLException e) { + throw new DeviceManagementException("Error occurred while opening a connection to the data source", e); + } finally { + DeviceManagementDAOFactory.closeConnection(); + } + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql index 04e4548545e..e71f55399df 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql @@ -1,7 +1,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE ( ID INT AUTO_INCREMENT NOT NULL, NAME VARCHAR(300) NULL DEFAULT NULL, - DEVICE_TYPE_META VARCHAR(2000) NULL DEFAULT NULL, + DEVICE_TYPE_META VARCHAR(20000) NULL DEFAULT NULL, LAST_UPDATED_TIMESTAMP TIMESTAMP NOT NULL, PROVIDER_TENANT_ID INTEGER DEFAULT 0, SHARED_WITH_ALL_TENANTS BOOLEAN NOT NULL DEFAULT FALSE, diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerService.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerService.java index b40c040f0ec..0a0bc896ef7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerService.java @@ -72,7 +72,8 @@ public class DeviceTypeManagerService implements DeviceManagementService { this.setOperationMonitoringConfig(deviceTypeConfiguration); this.initialOperationConfig = new InitialOperationConfig(); this.setInitialOperationConfig(deviceTypeConfiguration); - if (deviceTypeConfiguration.getPolicyMonitoring() != null ) { + if (deviceTypeConfiguration.getPolicyMonitoring() != null + && deviceTypeConfiguration.getPolicyMonitoring().isEnabled()) { this.policyMonitoringManager = new DefaultPolicyMonitoringManager(); } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/HTTPDeviceTypeManagerService.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/HTTPDeviceTypeManagerService.java index 6d00a881b18..b5735f6aa82 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/HTTPDeviceTypeManagerService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/HTTPDeviceTypeManagerService.java @@ -81,17 +81,19 @@ public class HTTPDeviceTypeManagerService extends DeviceTypeManagerService imple for (Feature feature : deviceTypeMetaDefinition.getFeatures()) { org.wso2.carbon.device.mgt.extensions.device.type.template.config.Feature configFeature = new org .wso2.carbon.device.mgt.extensions.device.type.template.config.Feature(); - configFeature.setCode(feature.getCode()); - configFeature.setDescription(feature.getDescription()); - configFeature.setName(feature.getName()); - if (feature.getMetadataEntries() != null && feature.getMetadataEntries().size() > 0) { - List metaValues = new ArrayList<>(); - for (Feature.MetadataEntry metadataEntry : feature.getMetadataEntries()) { - metadataEntry.getValue(); + if (feature.getCode() != null && feature.getName() != null) { + configFeature.setCode(feature.getCode()); + configFeature.setDescription(feature.getDescription()); + configFeature.setName(feature.getName()); + if (feature.getMetadataEntries() != null && feature.getMetadataEntries().size() > 0) { + List metaValues = new ArrayList<>(); + for (Feature.MetadataEntry metadataEntry : feature.getMetadataEntries()) { + metadataEntry.getValue(); + } + configFeature.setMetaData(metaValues); } - configFeature.setMetaData(metaValues); + featureList.add(configFeature); } - featureList.add(configFeature); } features.addFeatures(featureList); deviceTypeConfiguration.setFeatures(features); @@ -117,7 +119,8 @@ public class HTTPDeviceTypeManagerService extends DeviceTypeManagerService imple if (pushNotificationConfig != null) { PushNotificationProvider pushNotificationProvider = new PushNotificationProvider(); pushNotificationProvider.setType(pushNotificationConfig.getType()); - pushNotificationProvider.setScheduled(pushNotificationConfig.isScheduled()); + //default schedule value will be true. + pushNotificationProvider.setScheduled(true); if (pushNotificationConfig.getProperties() != null && pushNotificationConfig.getProperties().size() > 0) { ConfigProperties configProperties = new ConfigProperties(); 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 b123053b3ae..3ae63189ee6 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 @@ -178,7 +178,8 @@ "perm:admin", "perm:devicetype:deployment", "perm:device-types:events", - "perm:device-types:events:view" + "perm:device-types:events:view", + "perm:admin:device-type" ], "isOAuthEnabled": true, "backendRestEndpoints": { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/device.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/device.js index 0138c578977..838444d8a86 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/device.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/device.js @@ -268,6 +268,34 @@ deviceModule = function () { } }; + publicMethods.getDeviceTypeCount = function () { + var carbonUser = session.get(constants.USER_SESSION_KEY); + if (carbonUser) { + var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; + var uiPermissions = userModule.getUIPermissions(); + var url; + if (uiPermissions.LIST_OWN_DEVICES) { + url = devicemgtProps["httpsURL"] + + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/device-types"; + } else { + log.error("Access denied for user: " + carbonUser.username); + return -1; + } + return serviceInvokers.XMLHttp.get( + url, function (responsePayload) { + return parse(responsePayload["responseText"])["count"]; + }, + function (responsePayload) { + log.error(responsePayload["responseText"]); + return -1; + } + ); + } else { + log.error("User object was not found in the session"); + throw constants["ERRORS"]["USER_NOT_FOUND"]; + } + }; + publicMethods.getDeviceTypes = function () { var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/device-types"; var response = privateMethods.callBackend(url, constants["HTTP_GET"]); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.dashboard/dashboard.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.dashboard/dashboard.hbs index f526cc03a33..689312a441e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.dashboard/dashboard.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.dashboard/dashboard.hbs @@ -191,6 +191,40 @@ + {{#if permissions.IS_ADMIN}} +
+
+
Device Types
+
+
+
+ {{deviceTypeCount}} + + + {{#if deviceTypeCount}} + + + + + + View + + {{/if}} + + + + + + + Add + + +
+
+
+
+ {{/if}} + {{else}}

Permitted None diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.dashboard/dashboard.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.dashboard/dashboard.js index 4e0c9aafa19..bc1460153ca 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.dashboard/dashboard.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.dashboard/dashboard.js @@ -44,6 +44,7 @@ function onRequest(context) { viewModel.groupCount = groupModule.getGroupCount(); viewModel.userCount = userModule.getUsersCount(); viewModel.policyCount = policyModule.getPoliciesCount(); + viewModel.deviceTypeCount = deviceModule.getDeviceTypeCount(); viewModel.isCloud = devicemgtProps.isCloud; if (devicemgtProps.isCloud) { viewModel.roleCount = userModule.getFilteredRoles("devicemgt").content.count; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.create/create.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.create/create.hbs new file mode 100644 index 00000000000..0795c6bb631 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.create/create.hbs @@ -0,0 +1,226 @@ +{{! + Copyright (c) 2017, 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. +}} +{{unit "cdmf.unit.ui.title" pageTitle="Device Type Management"}} + +{{#zone "topCss"}} + {{css "css/devicetype.css"}} +{{/zone}} + +{{#zone "breadcrumbs"}} +
  • + + + +
  • +
  • + + + Device Types + +
  • +
  • + + + Add + +
  • +{{/zone}} + +{{#zone "content"}} + {{#if canManage}} + +
    +
    + +
    +
    +

    Create Device Type

    +
    +
    +
    +
    +
    +
    +
    1
    + +
    +
    +
    +
    +
    2
    + +
    +
    +
    +
    +

    +
    + + +
    + + + +
    + + + +
    + + +
    + + +
    + +
    +
    +
    + +
    +
    + +
    +
    + +
    + +
    +
    + + +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    +
    +
    +
    + +
    + +
    +
    +
    + + +
    + +
    +
    +
    + +
    + +
    + +
    +
    +
    +
    +
    + +
    + +
    +
    +
    + + + + +
    + + + +
    + + + + + +
    + +
    +
    + +
    +
    + + + +
    +
    + + {{else}} +

    + Permission Denied +

    +
    + You not authorized to create device type. +
    + {{/if}} +{{/zone}} + +{{#zone "bottomJs"}} + {{js "js/bottomJs.js"}} +{{/zone}} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.create/create.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.create/create.js new file mode 100644 index 00000000000..f67504684b4 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.create/create.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2016, 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. + */ + +function onRequest(context) { + var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; + var deviceMgtProps = require("/app/modules/conf-reader/main.js")["conf"]; + var displayData = {}; + + if (userModule.isAuthorized("/permission/admin/device-mgt/admin/device-type")) { + displayData.canManage = true; + } + + return displayData; +} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.create/create.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.create/create.json new file mode 100644 index 00000000000..0de47dfc78f --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.create/create.json @@ -0,0 +1,5 @@ +{ + "version": "1.0.0", + "uri": "/device-type/add", + "layout": "cdmf.layout.default" +} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.create/public/css/devicetype.css b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.create/public/css/devicetype.css new file mode 100644 index 00000000000..c7ab583aeb7 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.create/public/css/devicetype.css @@ -0,0 +1,10 @@ + + +.dontfloat { + clear:both; +} + +.hidden-div { + display: none; +} + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.create/public/js/bottomJs.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.create/public/js/bottomJs.js new file mode 100644 index 00000000000..1adc246527e --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.create/public/js/bottomJs.js @@ -0,0 +1,240 @@ +/* + * Copyright (c) 2016, 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. + */ + +/** + * Checks if provided input is valid against RegEx input. + * + * @param regExp Regular expression + * @param inputString Input string to check + * @returns {boolean} Returns true if input matches RegEx + */ +function inputIsValid(regExp, inputString) { + regExp = new RegExp(regExp); + return regExp.test(inputString); +} + +var validateInline = {}; +var clearInline = {}; + +var apiBasePath = "/api/device-mgt/v1.0"; + + +var enableInlineError = function (inputField, errorMsg, errorSign) { + var fieldIdentifier = "#" + inputField; + var errorMsgIdentifier = "#" + inputField + " ." + errorMsg; + var errorSignIdentifier = "#" + inputField + " ." + errorSign; + + if (inputField) { + $(fieldIdentifier).addClass(" has-error has-feedback"); + } + + if (errorMsg) { + $(errorMsgIdentifier).removeClass(" hidden"); + } + + if (errorSign) { + $(errorSignIdentifier).removeClass(" hidden"); + } +}; + +var disableInlineError = function (inputField, errorMsg, errorSign) { + var fieldIdentifier = "#" + inputField; + var errorMsgIdentifier = "#" + inputField + " ." + errorMsg; + var errorSignIdentifier = "#" + inputField + " ." + errorSign; + + if (inputField) { + $(fieldIdentifier).removeClass(" has-error has-feedback"); + } + + if (errorMsg) { + $(errorMsgIdentifier).addClass(" hidden"); + } + + if (errorSign) { + $(errorSignIdentifier).addClass(" hidden"); + } +}; + + +function formatRepo(user) { + if (user.loading) { + return user.text + } + if (!user.username) { + return; + } + var markup = '
    ' + + '
    ' + + '
    ' + + '
    ' + user.username + '
    '; + if (user.name || user.name != undefined) { + markup += '
    ( ' + user.name + ' )
    '; + } + markup += '
    '; + return markup; +} + +function formatRepoSelection(user) { + return user.username || user.text; +} + + + +$(document).ready(function () { + + var appContext = $("#app-context").data("app-context"); + + var maxField = 100; //Input fields increment limitation + var addButton = $('.add_button'); //Add button selector + var wrapper = $('.attribute_field_wrapper'); //Input field wrapper + var fieldHTML = $('#add-attribute-field').html(); //New input field html + $(addButton).click(function(){ //Once add button is clicked + $(wrapper).append(fieldHTML); // Add field html + }); + $(wrapper).on('click', '.remove_button', function(e){ //Once remove button is clicked + e.preventDefault(); + $(this).parent('div').remove(); + }); + + var addOperationButton = $('.add_operation_button'); //Add button selector + var operationWrapper = $('.operation_field_wrapper'); //Input field wrapper + var operationFieldHTML = $('#add-operation-field').html(); //New input field html + $(addOperationButton).click(function(){ //Once add button is clicked + $(operationWrapper).append(operationFieldHTML); // Add field html + }); + $(operationWrapper).on('click', '.remove_operation_button', function(e){ //Once remove button is clicked + e.preventDefault(); + $(this).parent('div').remove(); + }); + + + var addFeatureButton = $('.add_feature_button'); //Add button selector + var featureWrapper = $('.feature_field_wrapper'); //Input field wrapper + $(addFeatureButton).click(function(){ //Once add button is clicked + var featureFieldHtml = '
    ' + + '
    ' + + '
    ' + + '
    ' + $(featureWrapper).append(featureFieldHtml); // Add field html + }); + $(featureWrapper).on('click', '.remove_feature_button', function(e){ //Once remove button is clicked + e.preventDefault(); + $(this).parent('div').remove(); //Remove field html + }); + + /** + * Following click function would execute + * when a user clicks on "Add Device type" button. + */ + $("button#add-devicetype-btn").click(function () { + + var errorMsgWrapper = "#devicetype-create-error-msg"; + var errorMsg = "#devicetype-create-error-msg span"; + var deviceType = {}; + var deviceTypeName = $("#deviceTypeName").val(); + var deviceTypeDescription = $("#deviceTypeDescription").val(); + if (!deviceTypeName || deviceTypeName.trim() == "" ) { + $(errorMsg).text("Device Type Name Cannot be empty."); + $(errorMsgWrapper).removeClass("hidden"); + return; + } + + if (!deviceTypeDescription || deviceTypeDescription.trim() == "" ) { + $(errorMsg).text("Device Type Description Cannot be empty."); + $(errorMsgWrapper).removeClass("hidden"); + return + } + + deviceType.name = deviceTypeName.trim(); + deviceType.deviceTypeMetaDefinition = {} + deviceType.deviceTypeMetaDefinition.description = deviceTypeDescription.trim(); + + var pushNotification = $("#pushNotification").val(); + if (pushNotification != "NONE") { + deviceType.deviceTypeMetaDefinition.pushNotificationConfig = {}; + deviceType.deviceTypeMetaDefinition.pushNotificationConfig.scheduled = true; + deviceType.deviceTypeMetaDefinition.pushNotificationConfig.type = pushNotification; + } + + var propertyValues = []; + $('input[name^="attribute"]').each(function() { + var propertyValue = $(this).val(); + if (propertyValue.trim() != "") { + propertyValues.push(propertyValue.trim()); + } + }); + deviceType.deviceTypeMetaDefinition.properties = propertyValues; + + var operationValues = []; + $('input[name^="operation"]').each(function() { + var operationValue = $(this).val(); + if (operationValue.trim() != "") { + operationValues.push(operationValue.trim()); + } + }); + if (operationValues.length > 0) { + deviceType.deviceTypeMetaDefinition.initialOperationConfig = {}; + deviceType.deviceTypeMetaDefinition.initialOperationConfig.operations = operationValues; + } + + deviceType.deviceTypeMetaDefinition.policyMonitoringEnabled = $("#policyMonitoring").is(":checked"); + deviceType.deviceTypeMetaDefinition.claimable = $("#deviceClaimable").is(":checked");; + + var features = []; + $('div[name^="deviceFeature"]').each(function() { + var featureName = $(this).find("#feature-name").val(); + var featureCode = $(this).find("#feature-code").val(); + if (featureName && featureName.trim() != "" && featureCode && featureCode.trim() != "") { + var feature = {}; + feature.name = featureName.trim(); + feature.code = featureCode.trim(); + feature.description = $("#feature-description").val(); + features.push(feature); + } + }); + deviceType.deviceTypeMetaDefinition.features = features; + + var addRoleAPI = apiBasePath + "/admin/device-types"; + + invokerUtil.post( + addRoleAPI, + deviceType, + function (data, textStatus, jqXHR) { + if (jqXHR.status == 200) { + window.location.href = appContext + "/device-type/edit-event?type=" + + encodeURIComponent(deviceTypeName); + } + }, + function (jqXHR) { + if (jqXHR.status == 500) { + $(errorMsg).text("Unexpected error."); + $(errorMsgWrapper).removeClass("hidden"); + } + + if (jqXHR.status == 409) { + $(errorMsg).text("Device type already exists"); + $(errorMsgWrapper).removeClass("hidden"); + } + } + ); + }); + +}); \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.edit/edit.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.edit/edit.hbs new file mode 100644 index 00000000000..d15f9be2d24 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.edit/edit.hbs @@ -0,0 +1,273 @@ +{{! + Copyright (c) 2017, 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. +}} +{{unit "cdmf.unit.ui.title" pageTitle="Device Type Management"}} + +{{#zone "topCss"}} + {{css "css/devicetype.css"}} +{{/zone}} + +{{#zone "breadcrumbs"}} +
  • + + + +
  • +
  • + + + Device Types + +
  • +
  • + + + Edit + +
  • +{{/zone}} + +{{#zone "content"}} + {{#if canManage}} + +
    +
    + +
    +
    +

    {{name}}

    +
    +
    +
    + +
    + + + +
    + + + +
    + + +
    + + +
    +
    + {{#if type.deviceTypeMetaDefinition.features}} + {{#each type.deviceTypeMetaDefinition.features}} +
    +
    + +
    +
    + +
    +
    + +
    + +
    + {{/each}} + {{/if}} +
    +
    + +
    +
    + +
    +
    + +
    + +
    +
    + +
    + +
    +
    + {{#if type.deviceTypeMetaDefinition.properties}} + {{#each type.deviceTypeMetaDefinition.properties}} +
    +
    + +
    + +
    + {{/each}} + {{/if}} +
    +
    + +
    + +
    +
    +
    +
    +
    +
    + +
    + +
    +
    +
    + + +
    + +
    + {{#if type.deviceTypeMetaDefinition.initialOperationConfig}} + {{#each type.deviceTypeMetaDefinition.initialOperationConfig.operations}} +
    +
    + +
    + +
    + {{/each}} + {{/if}} +
    +
    + +
    + +
    + +
    +
    +
    +
    +
    + +
    + +
    +
    +
    + + + + +
    + + + +
    + + + + + +
    + +
    +
    + + +
    +
    + + + +
    +
    + + {{else}} +

    + Permission Denied +

    +
    + You not authorized to edit device type. +
    + {{/if}} +{{/zone}} + +{{#zone "bottomJs"}} + {{js "js/bottomJs.js"}} +{{/zone}} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.edit/edit.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.edit/edit.js new file mode 100644 index 00000000000..279f4a65524 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.edit/edit.js @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2016, 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. + */ + +function onRequest(context) { + var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; + var deviceMgtProps = require("/app/modules/conf-reader/main.js")["conf"]; + var displayData = {}; + + + if (userModule.isAuthorized("/permission/admin/device-mgt/admin/device-type")) { + displayData.canManage = true; + } + context.handlebars.registerHelper('if_eq', function(a, b, opts) { + if(a == b) // Or === depending on your needs + return opts.fn(this); + else + return opts.inverse(this); + }); + + var deviceType = request.getParameter("type"); + var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"]; + var restAPIEndpoint = deviceMgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + + "/device-types/all/" + deviceType; + displayData.name = deviceType; + serviceInvokers.XMLHttp.get( + restAPIEndpoint, + function (restAPIResponse) { + if (restAPIResponse["status"] == 200 && restAPIResponse["responseText"]) { + var typeData = parse(restAPIResponse["responseText"]); + displayData.type = typeData; + + } + } + ); + + return displayData; +} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.edit/edit.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.edit/edit.json new file mode 100644 index 00000000000..26088b9d86d --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.edit/edit.json @@ -0,0 +1,5 @@ +{ + "version": "1.0.0", + "uri": "/device-type/edit", + "layout": "cdmf.layout.default" +} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.edit/public/css/devicetype.css b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.edit/public/css/devicetype.css new file mode 100644 index 00000000000..04201c68a10 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.edit/public/css/devicetype.css @@ -0,0 +1,13 @@ + + +.dontfloat { + clear:both; +} + +.hidden-div { + display: none; +} + +.hidden-input { + display: none; +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.edit/public/js/bottomJs.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.edit/public/js/bottomJs.js new file mode 100644 index 00000000000..51500dcdcb3 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.edit/public/js/bottomJs.js @@ -0,0 +1,243 @@ +/* + * Copyright (c) 2016, 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. + */ + +/** + * Checks if provided input is valid against RegEx input. + * + * @param regExp Regular expression + * @param inputString Input string to check + * @returns {boolean} Returns true if input matches RegEx + */ +function inputIsValid(regExp, inputString) { + regExp = new RegExp(regExp); + return regExp.test(inputString); +} + +var validateInline = {}; +var clearInline = {}; + +var apiBasePath = "/api/device-mgt/v1.0"; +var domain = $("#domain").val(); + + +var enableInlineError = function (inputField, errorMsg, errorSign) { + var fieldIdentifier = "#" + inputField; + var errorMsgIdentifier = "#" + inputField + " ." + errorMsg; + var errorSignIdentifier = "#" + inputField + " ." + errorSign; + + if (inputField) { + $(fieldIdentifier).addClass(" has-error has-feedback"); + } + + if (errorMsg) { + $(errorMsgIdentifier).removeClass(" hidden"); + } + + if (errorSign) { + $(errorSignIdentifier).removeClass(" hidden"); + } +}; + +var disableInlineError = function (inputField, errorMsg, errorSign) { + var fieldIdentifier = "#" + inputField; + var errorMsgIdentifier = "#" + inputField + " ." + errorMsg; + var errorSignIdentifier = "#" + inputField + " ." + errorSign; + + if (inputField) { + $(fieldIdentifier).removeClass(" has-error has-feedback"); + } + + if (errorMsg) { + $(errorMsgIdentifier).addClass(" hidden"); + } + + if (errorSign) { + $(errorSignIdentifier).addClass(" hidden"); + } +}; + +function formatRepo(user) { + if (user.loading) { + return user.text + } + if (!user.username) { + return; + } + var markup = '
    ' + + '
    ' + + '
    ' + + '
    ' + user.username + '
    '; + if (user.name || user.name != undefined) { + markup += '
    ( ' + user.name + ' )
    '; + } + markup += '
    '; + return markup; +} + +function formatRepoSelection(user) { + return user.username || user.text; +} + + + +$(document).ready(function () { + + var appContext = $("#app-context").data("app-context"); + + var addButton = $('.add_button'); //Add button selector + var wrapper = $('.attribute_field_wrapper'); //Input field wrapper + var fieldHTML = $('#add-attribute-field').html(); //New input field html + $(addButton).click(function(){ //Once add button is clicked + $(wrapper).append(fieldHTML); // Add field html + }); + $(wrapper).on('click', '.remove_button', function(e){ //Once remove button is clicked + e.preventDefault(); + $(this).parent('div').remove(); //Remove field html + }); + + var addOperationButton = $('.add_operation_button'); //Add button selector + var operationWrapper = $('.operation_field_wrapper'); //Input field wrapper + var operationFieldHTML = $('#add-operation-field').html(); //New input field html + $(addOperationButton).click(function(){ //Once add button is clicked + $(operationWrapper).append(operationFieldHTML); // Add field html + }); + $(operationWrapper).on('click', '.remove_operation_button', function(e){ //Once remove button is clicked + e.preventDefault(); + $(this).parent('div').remove(); + }); + + + var addFeatureButton = $('.add_feature_button'); //Add button selector + var featureWrapper = $('.feature_field_wrapper'); //Input field wrapper + $(addFeatureButton).click(function(){ //Once add button is clicked + var featureFieldHtml = '
    ' + + '
    ' + + '
    ' + + '
    ' + $(featureWrapper).append(featureFieldHtml); // Add field html + + }); + $(featureWrapper).on('click', '.remove_feature_button', function(e){ //Once remove button is clicked + e.preventDefault(); + $(this).parent('div').remove(); //Remove field html + op--; //Decrement field counter + }); + + /** + * Following click function would execute + * when a user clicks on "Add Device type" button. + */ + $("button#add-devicetype-btn").click(function () { + + var errorMsgWrapper = "#devicetype-create-error-msg"; + var errorMsg = "#devicetype-create-error-msg span"; + var successMsgWrapper = "#devicetype-create-success-msg"; + var successMsg = "#devicetype-create-success-msg span"; + var deviceType = {}; + var deviceTypeName = $("#deviceTypeName").val(); + var deviceTypeDescription = $("#deviceTypeDescription").val(); + if (!deviceTypeName || deviceTypeName.trim() == "" ) { + $(errorMsg).text("Device Type Name Cannot be empty."); + $(errorMsgWrapper).removeClass("hidden"); + return; + } + + if (!deviceTypeDescription || deviceTypeDescription.trim() == "" ) { + $(errorMsg).text("Device Type Description Cannot be empty."); + $(errorMsgWrapper).removeClass("hidden"); + return + } + + deviceType.name = deviceTypeName.trim(); + deviceType.deviceTypeMetaDefinition = {} + deviceType.deviceTypeMetaDefinition.description = deviceTypeDescription.trim(); + + var pushNotification = $("#pushNotification").val(); + if (pushNotification != "NONE") { + deviceType.deviceTypeMetaDefinition.pushNotificationConfig = {}; + deviceType.deviceTypeMetaDefinition.pushNotificationConfig.scheduled = true; + deviceType.deviceTypeMetaDefinition.pushNotificationConfig.type = pushNotification; + } + + var propertyValues = []; + $('input[name^="attribute"]').each(function() { + var propertyValue = $(this).val(); + if (propertyValue.trim() != "") { + propertyValues.push(propertyValue.trim()); + } + }); + deviceType.deviceTypeMetaDefinition.properties = propertyValues; + + var operationValues = []; + $('input[name^="operation"]').each(function() { + var operationValue = $(this).val(); + if (operationValue.trim() != "") { + operationValues.push(operationValue.trim()); + } + }); + if (operationValues.length > 0) { + deviceType.deviceTypeMetaDefinition.initialOperationConfig = {}; + deviceType.deviceTypeMetaDefinition.initialOperationConfig.operations = operationValues; + } + + deviceType.deviceTypeMetaDefinition.policyMonitoringEnabled = $("#policyMonitoring").is(":checked"); + deviceType.deviceTypeMetaDefinition.claimable = $("#deviceClaimable").is(":checked");; + + var features = []; + $('div[name^="deviceFeature"]').each(function() { + var featureName = $(this).find("#feature-name").val(); + var featureCode = $(this).find("#feature-code").val(); + if (featureName && featureName.trim() != "" && featureCode && featureCode.trim() != "") { + var feature = {}; + feature.name = featureName.trim(); + feature.code = featureCode.trim(); + feature.description = $("#feature-description").val(); + features.push(feature); + } + }); + deviceType.deviceTypeMetaDefinition.features = features; + + var addRoleAPI = apiBasePath + "/admin/device-types"; + + invokerUtil.put( + addRoleAPI, + deviceType, + function (data, textStatus, jqXHR) { + if (jqXHR.status == 200) { + $(successMsg).text("Device type updated."); + $(successMsgWrapper).removeClass("hidden"); + } + }, + function (jqXHR) { + if (jqXHR.status == 500) { + $(errorMsg).text("Unexpected error."); + $(errorMsgWrapper).removeClass("hidden"); + } + + if (jqXHR.status == 409) { + $(errorMsg).text("Device type already exists"); + $(errorMsgWrapper).removeClass("hidden"); + } + } + ); + }); + +}); \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.event.edit/edit.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.event.edit/edit.hbs new file mode 100644 index 00000000000..6160e849dbf --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.event.edit/edit.hbs @@ -0,0 +1,160 @@ +{{! + Copyright (c) 2017, 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. +}} +{{unit "cdmf.unit.ui.title" pageTitle="Device Type Management"}} + +{{#zone "topCss"}} + {{css "css/devicetype.css"}} +{{/zone}} + +{{#zone "breadcrumbs"}} +
  • + + + +
  • +
  • + + + Device Types + +
  • +
  • + + + Event + +
  • +{{/zone}} + +{{#zone "content"}} + {{#if canManage}} + +
    +
    + +
    +
    +

    {{name}}

    +
    +
    +
    + +
    + + + +
    + + +
    + + +
    +
    + {{#if event.eventAttributes}} + {{#each event.eventAttributes.attributes}} +
    +
    + +
    +
    + +
    + +
    + {{/each}} + {{/if}} +
    +
    + +
    +
    + +
    + +
    +
    + +
    + {{#if event}} + + {{else}} + + {{/if}} + + +
    +
    + + + +
    +
    + + {{else}} +

    + Permission Denied +

    +
    + You not authorized to edit device type. +
    + {{/if}} +{{/zone}} + +{{#zone "bottomJs"}} + {{js "js/bottomJs.js"}} +{{/zone}} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.event.edit/edit.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.event.edit/edit.js new file mode 100644 index 00000000000..d18ee388b14 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.event.edit/edit.js @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2016, 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. + */ + +function onRequest(context) { + var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; + var deviceMgtProps = require("/app/modules/conf-reader/main.js")["conf"]; + var displayData = {}; + + + if (userModule.isAuthorized("/permission/admin/device-mgt/admin/device-type")) { + displayData.canManage = true; + } + context.handlebars.registerHelper('selected', function(a, b, opts) { + if(a == b) // Or === depending on your needs + return "selected"; + else + return ""; + }); + + var deviceType = request.getParameter("type"); + var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"]; + var restAPIEndpoint = deviceMgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + + "/events/" + deviceType; + displayData.name = deviceType; + serviceInvokers.XMLHttp.get( + restAPIEndpoint, + function (restAPIResponse) { + if (restAPIResponse["status"] == 200 && restAPIResponse["responseText"]) { + var typeData = parse(restAPIResponse["responseText"]); + displayData.event = typeData; + } + } + ); + + return displayData; +} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.event.edit/edit.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.event.edit/edit.json new file mode 100644 index 00000000000..9e773121e56 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.event.edit/edit.json @@ -0,0 +1,5 @@ +{ + "version": "1.0.0", + "uri": "/device-type/edit-event", + "layout": "cdmf.layout.default" +} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.event.edit/public/css/devicetype.css b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.event.edit/public/css/devicetype.css new file mode 100644 index 00000000000..04201c68a10 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.event.edit/public/css/devicetype.css @@ -0,0 +1,13 @@ + + +.dontfloat { + clear:both; +} + +.hidden-div { + display: none; +} + +.hidden-input { + display: none; +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.event.edit/public/js/bottomJs.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.event.edit/public/js/bottomJs.js new file mode 100644 index 00000000000..f6249043b04 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.event.edit/public/js/bottomJs.js @@ -0,0 +1,182 @@ +/* + * Copyright (c) 2016, 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. + */ + +/** + * Checks if provided input is valid against RegEx input. + * + * @param regExp Regular expression + * @param inputString Input string to check + * @returns {boolean} Returns true if input matches RegEx + */ +function inputIsValid(regExp, inputString) { + regExp = new RegExp(regExp); + return regExp.test(inputString); +} + +var validateInline = {}; +var clearInline = {}; + +var apiBasePath = "/api/device-mgt/v1.0"; +var domain = $("#domain").val(); + + +var enableInlineError = function (inputField, errorMsg, errorSign) { + var fieldIdentifier = "#" + inputField; + var errorMsgIdentifier = "#" + inputField + " ." + errorMsg; + var errorSignIdentifier = "#" + inputField + " ." + errorSign; + + if (inputField) { + $(fieldIdentifier).addClass(" has-error has-feedback"); + } + + if (errorMsg) { + $(errorMsgIdentifier).removeClass(" hidden"); + } + + if (errorSign) { + $(errorSignIdentifier).removeClass(" hidden"); + } +}; + +var disableInlineError = function (inputField, errorMsg, errorSign) { + var fieldIdentifier = "#" + inputField; + var errorMsgIdentifier = "#" + inputField + " ." + errorMsg; + var errorSignIdentifier = "#" + inputField + " ." + errorSign; + + if (inputField) { + $(fieldIdentifier).removeClass(" has-error has-feedback"); + } + + if (errorMsg) { + $(errorMsgIdentifier).addClass(" hidden"); + } + + if (errorSign) { + $(errorSignIdentifier).addClass(" hidden"); + } +}; + +function formatRepo(user) { + if (user.loading) { + return user.text + } + if (!user.username) { + return; + } + var markup = '
    ' + + '
    ' + + '
    ' + + '
    ' + user.username + '
    '; + if (user.name || user.name != undefined) { + markup += '
    ( ' + user.name + ' )
    '; + } + markup += '
    '; + return markup; +} + +function formatRepoSelection(user) { + return user.username || user.text; +} + + + +$(document).ready(function () { + + var appContext = $("#app-context").data("app-context"); + var addEventButton = $('.add_event_button'); //Add button selector + var eventWrapper = $('.event_field_wrapper'); //Input field wrapper + $(addEventButton).click(function(){ //Once add button is clicked + var eventFieldHtml = '
    ' + + '
    ' + + '
    ' + + '
    ' + $(eventWrapper).append(eventFieldHtml); // Add field html + + }); + $(eventWrapper).on('click', '.remove_event_button', function(e){ //Once remove button is clicked + e.preventDefault(); + $(this).parent('div').remove(); + }); + + /** + * Following click function would execute + * when a user clicks on "Add Device type" button. + */ + $("button#add-event-btn").click(function () { + + var errorMsgWrapper = "#devicetype-create-error-msg"; + var errorMsg = "#devicetype-create-error-msg span"; + var successMsgWrapper = "#devicetype-create-success-msg"; + var successMsg = "#devicetype-create-success-msg span"; + var deviceTypeEvent = {}; + var deviceTypeName = $("#deviceTypeName").val(); + var deviceTypeDescription = $("#deviceTypeDescription").val(); + if (!deviceTypeName || deviceTypeName.trim() == "" ) { + $(errorMsg).text("Device Type Name Cannot be empty."); + $(errorMsgWrapper).removeClass("hidden"); + return; + } + + + deviceTypeEvent.eventAttributes = {}; + + deviceTypeEvent.transport = $("#transport").val(); + + var attributes = []; + $('div[name^="deviceEvent"]').each(function() { + var eventName = $(this).find("#event-name").val(); + var eventType = $(this).find("#event-type").val(); + if (eventName && eventName.trim() != "" && eventType && eventType.trim() != "" && eventName != "deviceId") { + var attribute = {}; + attribute.name = eventName.trim(); + attribute.type = eventType.trim(); + attributes.push(attribute); + } + }); + deviceTypeEvent.eventAttributes.attributes = attributes; + + var addEventsAPI = apiBasePath + "/events/" + deviceTypeName; + + invokerUtil.post( + addEventsAPI, + deviceTypeEvent, + function (data, textStatus, jqXHR) { + if (jqXHR.status == 200) { + $(successMsg).text("Device Event Definition added."); + $(successMsgWrapper).removeClass("hidden"); + } + }, + function (jqXHR) { + if (jqXHR.status == 500) { + $(errorMsg).text("Unexpected error."); + $(errorMsgWrapper).removeClass("hidden"); + } + + if (jqXHR.status == 409) { + $(errorMsg).text("Device type already exists"); + $(errorMsgWrapper).removeClass("hidden"); + } + } + ); + }); + + + +}); \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetypes/devicetypes.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetypes/devicetypes.hbs new file mode 100644 index 00000000000..21dd6abb7d0 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetypes/devicetypes.hbs @@ -0,0 +1,110 @@ +{{! + Copyright (c) 2016, 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. +}} + +{{unit "cdmf.unit.ui.title" pageTitle="Device Type Management"}} +{{unit "cdmf.unit.data-tables-extended"}} +{{unit "cdmf.unit.ui.modal"}} + +{{#zone "breadcrumbs"}} +
  • + + + +
  • +
  • + + + Device Types + +
  • +{{/zone}} + +{{#zone "navbarActions"}} + {{#unless isCloud}} +
  • + + + + + + + Create Device Type + +
  • + {{/unless}} +{{/zone}} + +{{#zone "content"}} + {{#if hasDeviceTypes}} +
    + + + Loading device types . . . +
    +
    + +
    + + + + + + + + + + +
    By Device Type Name
    +
    + + + + {{else}} + +
    +
    +

    You Haven't created device types yet.

    +
    Please click "Create a Device Type", if you wish to create a device type. +
    + + + + + + + Create Device Type + +
    +
    + + {{/if}} +{{/zone}} + +{{#zone "bottomJs"}} + + + {{js "js/devicetype-listing.js"}} +{{/zone}} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetypes/devicetypes.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetypes/devicetypes.js new file mode 100644 index 00000000000..4fb1980df56 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetypes/devicetypes.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2016, 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. + */ + +function onRequest(context) { + var deviceModule = require("/app/modules/business-controllers/device.js")["deviceModule"]; + var deviceMgtProps = require("/app/modules/conf-reader/main.js")["conf"]; + + context["permissions"] = userModule.getUIPermissions(); + if (userModule.isAuthorized("/permission/admin/device-mgt/admin/device-type")) { + context["editPermitted"] = true; + } + var deviceTypeCount = deviceModule.getDeviceTypeCount(); + + if (deviceTypeCount > 0) { + context["hasDeviceTypes"] = true; + } else { + context["hasDeviceTypes"] = false; + } + + return context; +} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetypes/devicetypes.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetypes/devicetypes.json new file mode 100644 index 00000000000..4dfd6843803 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetypes/devicetypes.json @@ -0,0 +1,5 @@ +{ + "version": "1.0.0", + "uri": "/device-types", + "layout": "cdmf.layout.default" +} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetypes/public/js/devicetype-listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetypes/public/js/devicetype-listing.js new file mode 100644 index 00000000000..6d990d9a850 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetypes/public/js/devicetype-listing.js @@ -0,0 +1,206 @@ +/* + * Copyright (c) 2015, 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. + */ + +var loadDeviceTypeBasedActionURL = function (action, deviceTypeName) { + href = $("#ast-container").data("app-context") + "device-type/" + action + "?type=" + encodeURIComponent(deviceTypeName); + $(location).attr('href', href); +}; + +$(function () { + var sortableElem = '.wr-sortable'; + $(sortableElem).sortable({ + beforeStop: function () { + $(this).sortable('toArray'); + } + }); + $(sortableElem).disableSelection(); +}); + +var apiBasePath = "/api/device-mgt/v1.0"; +var modalPopup = ".modal"; +var modalPopupContainer = modalPopup + " .modal-content"; +var modalPopupContent = modalPopup + " .modal-content"; +var body = "body"; +var isInit = true; +var isCloud = false; + + +/** + * + * Fires the res_text when ever a data table redraw occurs making + * the font icons change the size to respective screen resolution. + * + */ +$(document).on('draw.dt', function () { + $(".icon .text").res_text(0.2); +}); + + +/* + * set popup maximum height function. + */ +function setPopupMaxHeight() { + $(modalPopupContent).css('max-height', ($(body).height() - ($(body).height() / 100 * 30))); + $(modalPopupContainer).css('margin-top', (-($(modalPopupContainer).height() / 2))); +} + +/* + * show popup function. + */ +function showPopup() { + $(modalPopup).modal('show'); + //setPopupMaxHeight(); +} + +/* + * hide popup function. + */ +function hidePopup() { + $(modalPopupContent).html(''); + $(modalPopup).modal('hide'); + $('body').removeClass('modal-open').css('padding-right', '0px'); + $('.modal-backdrop').remove(); +} + + +/** + * Following function would execute + * when a user clicks on the list item + * initial mode and with out select mode. + */ +function InitiateViewOption() { + // $(location).attr('href', $(this).data("url")); +} + +function htmlspecialchars(text) { + return jQuery('
    ').text(text).html(); +} + +function loadDeviceTypes() { + var loadingContent = $("#loading-content"); + loadingContent.show(); + + var dataFilter = function (data) { + data = JSON.parse(data); + var objects = []; + $(data).each(function (index) { + objects.push( + { + name: htmlspecialchars(data[index].name), + DT_RowId: "devicetype-" + htmlspecialchars(data[index].name), + metaDefinition: (data[index].deviceTypeMetaDefinition ? true : false) + } + ) + }); + + var json = { + "recordsTotal": data.length, + "recordsFiltered": data.length, + "data": objects + }; + + return JSON.stringify(json); + }; + + //noinspection JSUnusedLocalSymbols + var fnCreatedRow = function (nRow, aData, iDataIndex) { + $(nRow).attr('data-type', 'selectable'); + }; + + //noinspection JSUnusedLocalSymbols + var columns = [ + { + class: "remove-padding icon-only content-fill", + data: null, + defaultContent: "
    " + + "" + + "
    " + }, + { + class: "", + data: "name", + render: function (name, type, row, meta) { + return '

    ' + name.replace("devicemgt", ""); + '

    '; + } + }, + { + class: "text-right content-fill text-left-on-grid-view no-wrap", + data: null, + render: function (data, type, row, meta) { + var isCloud = false; + if ($('#is-cloud').length > 0) { + isCloud = true; + } + + var innerhtml = ''; + if (data.metaDefinition) { + + var editLink = '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + ''; + + var editEventLink = '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + ''; + + innerhtml = editLink + editEventLink; + } + return innerhtml; + } + } + ]; + + var options = { + "placeholder": "Search By Device Type Name", + "searchKey": "filter" + }; + var settings = { + "sorting": false + }; + var deviceTypeApiUrl = '/api/device-mgt/v1.0/admin/device-types'; + + $('#devicetype-grid').datatables_extended_serverside_paging(settings, deviceTypeApiUrl, dataFilter, columns, fnCreatedRow, null, options); + loadingContent.hide(); + +} + +$(document).ready(function () { + loadDeviceTypes(); +}); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetypes/public/templates/devicetype-listing.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetypes/public/templates/devicetype-listing.hbs new file mode 100644 index 00000000000..6835f28e9cd --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetypes/public/templates/devicetype-listing.hbs @@ -0,0 +1,44 @@ +{{#each deviceTypes}} + + +
    + +
    + + {{deviceTypeName}} + + + {{#if canEdit}} + + + + + + + + + + + + + + + + + + + + + + + + + {{/if}} + + +{{/each}} \ No newline at end of file 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 f5416944dd8..45899c51cf7 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 @@ -30,7 +30,14 @@ {{/if}} - + {{#if permissions.IS_ADMIN}} +
  • + + + Device Type Management + +
  • + {{/if}} {{#unless isCloud}} {{#if permissions.VIEW_DASHBOARD}}
  • diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql index 1811fbdaa9b..108b32d48a3 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql @@ -1,7 +1,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE ( ID INT AUTO_INCREMENT NOT NULL, NAME VARCHAR(300) NULL DEFAULT NULL, - DEVICE_TYPE_META VARCHAR(2000) NULL DEFAULT NULL, + DEVICE_TYPE_META VARCHAR(20000) NULL DEFAULT NULL, LAST_UPDATED_TIMESTAMP TIMESTAMP NOT NULL, PROVIDER_TENANT_ID INTEGER DEFAULT 0, SHARED_WITH_ALL_TENANTS BOOLEAN NOT NULL DEFAULT FALSE, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql index b809b7c7967..39ea23a9d26 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql @@ -1,7 +1,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE ( ID INT AUTO_INCREMENT NOT NULL, NAME VARCHAR(300) NULL DEFAULT NULL, - DEVICE_TYPE_META VARCHAR(2000) NULL DEFAULT NULL, + DEVICE_TYPE_META VARCHAR(20000) NULL DEFAULT NULL, LAST_UPDATED_TIMESTAMP TIMESTAMP NOT NULL, PROVIDER_TENANT_ID INTEGER DEFAULT 0, SHARED_WITH_ALL_TENANTS BOOLEAN NOT NULL DEFAULT FALSE, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql index b2171e5086e..8ce26434f6d 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql @@ -2,7 +2,7 @@ IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[D CREATE TABLE DM_DEVICE_TYPE ( ID INTEGER IDENTITY(1,1) NOT NULL, NAME VARCHAR(300) DEFAULT NULL, - DEVICE_TYPE_META VARCHAR(2000) DEFAULT NULL, + DEVICE_TYPE_META VARCHAR(20000) DEFAULT NULL, LAST_UPDATED_TIMESTAMP DATETIME2 NOT NULL, PROVIDER_TENANT_ID INTEGER NULL, SHARED_WITH_ALL_TENANTS BIT NOT NULL DEFAULT 0, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql index 673b85daea5..7359e8fe79d 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql @@ -1,7 +1,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE ( ID INTEGER AUTO_INCREMENT NOT NULL, NAME VARCHAR(300) DEFAULT NULL, - DEVICE_TYPE_META VARCHAR(2000) DEFAULT NULL, + DEVICE_TYPE_META VARCHAR(20000) DEFAULT NULL, LAST_UPDATED_TIMESTAMP TIMESTAMP NOT NULL, PROVIDER_TENANT_ID INTEGER DEFAULT 0, SHARED_WITH_ALL_TENANTS BOOLEAN NOT NULL DEFAULT FALSE, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql index 02dcacea778..e3580f9d990 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql @@ -1,7 +1,7 @@ CREATE TABLE DM_DEVICE_TYPE ( ID NUMBER(10) NOT NULL, NAME VARCHAR2(300) DEFAULT NULL, - DEVICE_TYPE_META VARCHAR2(2000) DEFAULT NULL, + DEVICE_TYPE_META VARCHAR2(20000) DEFAULT NULL, LAST_UPDATED_TIMESTAMP TIMESTAMP NOT NULL, PROVIDER_TENANT_ID INTEGER DEFAULT 0, SHARED_WITH_ALL_TENANTS NUMBER(1) DEFAULT 0 NOT NULL, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql index fd10c778ee2..04f531f79cb 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql @@ -1,7 +1,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE ( ID BIGSERIAL PRIMARY KEY, NAME VARCHAR(300) DEFAULT NULL, - DEVICE_TYPE_META VARCHAR(2000) DEFAULT NULL, + DEVICE_TYPE_META VARCHAR(20000) DEFAULT NULL, LAST_UPDATED_TIMESTAMP TIMESTAMP NOT NULL, PROVIDER_TENANT_ID INTEGER DEFAULT 0, SHARED_WITH_ALL_TENANTS BOOLEAN NOT NULL DEFAULT FALSE,