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 a6fff500fe..8b6d7ed030 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 @@ -58,8 +58,8 @@ import javax.ws.rs.core.Response; permissions = {"/device-mgt/device-type/add"} ), @Scope( - name = "Get Feature Details of a Device Type", - description = "Get Feature Details of a Device Type", + name = "Get Events Details of a Device Type", + description = "Get Events Details of a Device Type", key = "perm:device-types:events:view", permissions = {"/device-mgt/devices/owning-device/view"} ) @@ -238,6 +238,60 @@ public interface DeviceEventManagementService { @ApiParam(name = "limit", value = "limit of the records that needs to be picked up", required = false) @QueryParam("limit") int limit); + @GET + @Path("last-known/{type}/{deviceId}") + @ApiOperation( + produces = MediaType.APPLICATION_JSON, + httpMethod = "GET", + value = "Getting Last Known Device Events", + notes = "Get the Last Known events for the device.", + tags = "Device Event Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "perm:device-types:events:view") + }) + } + ) + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully fetched the event.", + response = EventRecords.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 = 400, + message = + "Bad Request. \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 getLastKnownData(@ApiParam(name = "deviceId", value = "id of the device ", required = false) + @PathParam("deviceId") String deviceId, + @ApiParam(name = "type", value = "name of the device type", required = false) + @PathParam("type") String deviceType); + @GET @Path("/{type}") @ApiOperation( diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java index 06d2451044..8117a47d0f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java @@ -484,7 +484,7 @@ public interface DeviceManagementService { "Server error occurred while retrieving the device details.", response = ErrorResponse.class) }) - Response addDevice(@ApiParam(name = "device", value = "Device object with data.", required = true) + Response enrollDevice(@ApiParam(name = "device", value = "Device object with data.", required = true) @Valid Device device); @GET diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceTypeManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceTypeManagementService.java index 24bfe0b920..390bb2dca4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceTypeManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceTypeManagementService.java @@ -260,4 +260,50 @@ public interface DeviceTypeManagementService { @Size(min = 2, max = 45) String type); + @GET + @Path("/all") + @ApiOperation( + produces = MediaType.APPLICATION_JSON, + httpMethod = "GET", + value = "Retrieve device types information", + notes = "Retrieve device types information.", + response = DeviceType.class, + tags = "Device Type Management Administrative Service", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "perm:device-types:types") + }) + } + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "OK. \n Successfully fetched the device type.", + response = DeviceType.class, + responseContainer = "List", + responseHeaders = { + @ResponseHeader( + name = "Content-Type", + description = "The content type of the body") + }), + @ApiResponse( + code = 304, + message = "Not Modified. Empty body because the client already has the latest version of the " + + "requested resource.\n"), + @ApiResponse( + code = 401, + message = "Unauthorized.\n The unauthorized access to the requested resource.", + response = ErrorResponse.class), + @ApiResponse( + code = 404, + message = "Not Found.\n The specified device does not exist", + response = ErrorResponse.class), + @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 device list.", + response = ErrorResponse.class) + }) + Response getDeviceTypes(); + } 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 ea9d01de8b..fa4847ef91 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 @@ -110,6 +110,7 @@ public class DeviceEventManagementServiceImpl implements DeviceEventManagementSe 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 final String DEFAULT_DEVICE_ID_ATTRIBUTE = "deviceId"; private static KeyStore keyStore; private static KeyStore trustStore; @@ -162,6 +163,9 @@ public class DeviceEventManagementServiceImpl implements DeviceEventManagementSe EventAttributeList eventAttributeList = new EventAttributeList(); List attributes = new ArrayList<>(); for (EventStreamAttributeDto eventStreamAttributeDto : eventStreamAttributeDtos) { + if (DEFAULT_DEVICE_ID_ATTRIBUTE.equals(eventStreamAttributeDto.getAttributeName())) { + continue; + } attributes.add(new Attribute(eventStreamAttributeDto.getAttributeName() , AttributeType.valueOf(eventStreamAttributeDto.getAttributeType().toUpperCase()))); } @@ -278,8 +282,7 @@ public class DeviceEventManagementServiceImpl implements DeviceEventManagementSe if (deviceType == null || !DeviceMgtAPIUtils.getDeviceManagementService().getAvailableDeviceTypes().contains(deviceType)) { String errorMessage = "Invalid device type"; - log.error(errorMessage); - return Response.status(Response.Status.BAD_REQUEST).build(); + return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); } String eventReceiverName = getReceiverName(deviceType, tenantDomain); String eventPublisherName = deviceType.trim().toLowerCase() + "_websocket_publisher"; @@ -310,7 +313,8 @@ public class DeviceEventManagementServiceImpl implements DeviceEventManagementSe tenantBasedEventReceiverAdminServiceStub = getEventReceiverAdminServiceStub(); tenantBasedEventStreamAdminServiceStub = getEventStreamAdminServiceStub(); tenantBasedEventStreamAdminServiceStub.removeEventStreamDefinition(streamName, DEFAULT_STREAM_VERSION); - tenantBasedEventReceiverAdminServiceStub.startundeployInactiveEventReceiverConfiguration(eventReceiverName + tenantBasedEventReceiverAdminServiceStub.startundeployInactiveEventReceiverConfiguration( + eventReceiverName , eventReceiverAdminServiceCallbackHandler); } @@ -350,6 +354,10 @@ public class DeviceEventManagementServiceImpl implements DeviceEventManagementSe public Response getData(@PathParam("deviceId") String deviceId, @QueryParam("from") long from, @QueryParam("to") long to, @PathParam("type") String deviceType, @QueryParam("offset") int offset, @QueryParam("limit") int limit) { + if (from == 0 || to == 0) { + String errorMessage = "Invalid values for from/to"; + return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); + } String fromDate = String.valueOf(from); String toDate = String.valueOf(to); String query = "deviceId:" + deviceId + " AND _timestamp : [" + fromDate + " TO " + toDate + "]"; @@ -367,7 +375,7 @@ public class DeviceEventManagementServiceImpl implements DeviceEventManagementSe return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build(); } List sortByFields = new ArrayList<>(); - SortByField sortByField = new SortByField("_timestamp", SortType.ASC); + SortByField sortByField = new SortByField("_timestamp", SortType.DESC); sortByFields.add(sortByField); EventRecords eventRecords = getAllEventsForDevice(sensorTableName, query, sortByFields, offset, limit); return Response.status(Response.Status.OK.getStatusCode()).entity(eventRecords).build(); @@ -385,6 +393,43 @@ public class DeviceEventManagementServiceImpl implements DeviceEventManagementSe } } + @GET + @Path("/last-known/{type}/{deviceId}") + @Override + public Response getLastKnownData(@PathParam("deviceId") String deviceId, @PathParam("type") String deviceType) { + String query = "deviceId:" + deviceId; + String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); + String sensorTableName = getTableName(getStreamDefinition(deviceType, tenantDomain)); + try { + if (deviceType == null || + !DeviceMgtAPIUtils.getDeviceManagementService().getAvailableDeviceTypes().contains(deviceType)) { + String errorMessage = "Invalid device type"; + log.error(errorMessage); + return Response.status(Response.Status.BAD_REQUEST).build(); + } + if (!DeviceMgtAPIUtils.getDeviceAccessAuthorizationService().isUserAuthorized( + new DeviceIdentifier(deviceId, deviceType))) { + return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build(); + } + List sortByFields = new ArrayList<>(); + SortByField sortByField = new SortByField("_timestamp", SortType.DESC); + sortByFields.add(sortByField); + EventRecords eventRecords = getAllEventsForDevice(sensorTableName, query, sortByFields, 0, 1); + return Response.status(Response.Status.OK.getStatusCode()).entity(eventRecords).build(); + } catch (AnalyticsException e) { + String errorMsg = "Error on retrieving stats on table " + sensorTableName + " with query " + query; + log.error(errorMsg); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).entity(errorMsg).build(); + } catch (DeviceAccessAuthorizationException e) { + log.error(e.getErrorMessage(), e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + } catch (DeviceManagementException e) { + String errorMsg = "Error on retrieving stats on table " + sensorTableName + " with query " + query; + log.error(errorMsg); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).entity(errorMsg).build(); + } + } + private void publishEventReceivers(String eventRecieverName, String streamNameWithVersion, TransportType transportType , String requestedTenantDomain, String deviceType) @@ -434,7 +479,7 @@ public class DeviceEventManagementServiceImpl implements DeviceEventManagementSe } EventStreamAttributeDto eventStreamAttributeDto = new EventStreamAttributeDto(); - eventStreamAttributeDto.setAttributeName("deviceId"); + eventStreamAttributeDto.setAttributeName(DEFAULT_DEVICE_ID_ATTRIBUTE); eventStreamAttributeDto.setAttributeType(AttributeType.STRING.toString()); eventStreamAttributeDtos[i] = eventStreamAttributeDto; eventStreamDefinitionDto.setPayloadData(eventStreamAttributeDtos); @@ -476,7 +521,7 @@ public class DeviceEventManagementServiceImpl implements DeviceEventManagementSe i++; } AnalyticsTableRecord analyticsTableRecord = new AnalyticsTableRecord(); - analyticsTableRecord.setColumnName("deviceId"); + analyticsTableRecord.setColumnName(DEFAULT_DEVICE_ID_ATTRIBUTE); analyticsTableRecord.setColumnType(AttributeType.STRING.toString().toUpperCase()); analyticsTableRecord.setFacet(false); analyticsTableRecord.setIndexed(true); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java index ac6471e629..16e75f541c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java @@ -91,7 +91,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { @POST @Override - public Response addDevice(@Valid Device device) { + public Response enrollDevice(@Valid Device device) { if (device == null) { String errorMessage = "The payload of the device enrollment is incorrect."; return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); @@ -99,6 +99,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { try { DeviceManagementProviderService dms = DeviceMgtAPIUtils.getDeviceManagementService(); device.getEnrolmentInfo().setOwner(DeviceMgtAPIUtils.getAuthenticatedUser()); + device.getEnrolmentInfo().setDateOfEnrolment(System.currentTimeMillis()); + device.getEnrolmentInfo().setDateOfLastUpdate(System.currentTimeMillis()); boolean status = dms.enrollDevice(device); return Response.status(Response.Status.OK).entity(status).build(); } catch (DeviceManagementException e) { @@ -173,6 +175,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { } } if(updateDevice.getEnrolmentInfo() != null) { + device.getEnrolmentInfo().setDateOfLastUpdate(System.currentTimeMillis()); device.setEnrolmentInfo(device.getEnrolmentInfo()); } device.getEnrolmentInfo().setOwner(DeviceMgtAPIUtils.getAuthenticatedUser()); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceTypeManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceTypeManagementServiceImpl.java index 2d1a0d5f6d..2cae1b931d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceTypeManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceTypeManagementServiceImpl.java @@ -23,6 +23,8 @@ import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.Feature; import org.wso2.carbon.device.mgt.common.FeatureManager; +import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig; +import org.wso2.carbon.device.mgt.common.type.mgt.DeviceTypeMetaDefinition; import org.wso2.carbon.device.mgt.core.dto.DeviceType; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceTypeList; @@ -38,6 +40,7 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.QueryParam; import javax.ws.rs.core.Response; +import java.util.ArrayList; import java.util.List; @Path("/device-types") @@ -88,6 +91,24 @@ public class DeviceTypeManagementServiceImpl implements DeviceTypeManagementServ return Response.status(Response.Status.OK).entity(features).build(); } + @Override + @GET + @Path("/all") + public Response getDeviceTypes() { + try { + List deviceTypes = DeviceMgtAPIUtils.getDeviceManagementService().getDeviceTypes(); + List filteredDeviceTypes = new ArrayList<>(); + for (DeviceType deviceType : deviceTypes) { + filteredDeviceTypes.add(clearMetaEntryInfo(deviceType)); + } + return Response.status(Response.Status.OK).entity(filteredDeviceTypes).build(); + } catch (DeviceManagementException e) { + String msg = "Error occurred at server side while fetching device type."; + log.error(msg, e); + return Response.serverError().entity(msg).build(); + } + } + @Override @GET @Path("/all/{type}") @@ -110,4 +131,16 @@ public class DeviceTypeManagementServiceImpl implements DeviceTypeManagementServ } } + private DeviceType clearMetaEntryInfo(DeviceType deviceType) { + DeviceTypeMetaDefinition metaDefinition = deviceType.getDeviceTypeMetaDefinition(); + metaDefinition.setInitialOperationConfig(null); + if (metaDefinition.getPushNotificationConfig() != null) { + metaDefinition.setPushNotificationConfig(new PushNotificationConfig(metaDefinition. + getPushNotificationConfig().getType(), false, null)); + } + metaDefinition.setTaskConfig(null); + deviceType.setDeviceTypeMetaDefinition(metaDefinition); + return deviceType; + } + } 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 d0eb605e1f..98b6c36e32 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 @@ -15,7 +15,6 @@ public class DeviceTypeMetaDefinition { private boolean claimable; private PushNotificationConfig pushNotificationConfig; private boolean policyMonitoringEnabled; - private OperationMonitoringTaskConfig taskConfig; private InitialOperationConfig initialOperationConfig; private License license; private String description; @@ -69,14 +68,6 @@ public class DeviceTypeMetaDefinition { this.policyMonitoringEnabled = policyMonitoringEnabled; } - public OperationMonitoringTaskConfig getTaskConfig() { - return taskConfig; - } - - public void setTaskConfig(OperationMonitoringTaskConfig taskConfig) { - this.taskConfig = taskConfig; - } - public InitialOperationConfig getInitialOperationConfig() { return initialOperationConfig; } 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 26ed67ff18..496d7033c6 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 @@ -199,6 +199,8 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis addDeviceManagementProvider(deviceTypeManagerService); deviceTypeIdentifier = new DeviceTypeServiceIdentifier(type, tenantId); provider = providers.get(deviceTypeIdentifier); + } else { + provider.setTimestamp(System.currentTimeMillis()); } } } catch (DeviceManagementException e) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/DeviceType.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/DeviceType.java index fbfc8b4404..c56257a363 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/DeviceType.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/DeviceType.java @@ -18,6 +18,7 @@ package org.wso2.carbon.device.mgt.core.dto; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; @@ -46,6 +47,7 @@ public class DeviceType implements Serializable { this.name = name; } + @JsonIgnore public int getId() { return id; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManager.java index 17da5626a1..3c02df14ef 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManager.java @@ -175,6 +175,7 @@ public class DeviceTypeManager implements DeviceManager { if (deviceDetails.getProperties() != null && deviceDetails.getProperties().getProperty() != null && deviceDetails.getProperties().getProperty().size() > 0 ) { deviceTypePluginDAOManager = new DeviceTypePluginDAOManager(deviceType, deviceDetails); + propertiesExist = true; } } } 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 b5735f6aa8..e18b8076c4 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 @@ -138,24 +138,25 @@ public class HTTPDeviceTypeManagerService extends DeviceTypeManagerService imple deviceTypeConfiguration.setPushNotificationProvider(pushNotificationProvider); } - OperationMonitoringTaskConfig operationMonitoringTaskConfig = deviceTypeMetaDefinition.getTaskConfig(); - if (operationMonitoringTaskConfig != null) { - TaskConfiguration taskConfiguration = new TaskConfiguration(); - taskConfiguration.setEnabled(operationMonitoringTaskConfig.isEnabled()); - taskConfiguration.setFrequency(operationMonitoringTaskConfig.getFrequency()); - if (operationMonitoringTaskConfig.getMonitoringOperation() != null) { - List operations = new ArrayList<>(); - for (MonitoringOperation monitoringOperation : operationMonitoringTaskConfig - .getMonitoringOperation()) { - TaskConfiguration.Operation operation = new TaskConfiguration.Operation(); - operation.setOperationName(monitoringOperation.getTaskName()); - operation.setRecurrency(monitoringOperation.getRecurrentTimes()); - operations.add(operation); - } - taskConfiguration.setOperations(operations); - } - deviceTypeConfiguration.setTaskConfiguration(taskConfiguration); - } +// This is commented until the task registration handling issue is solved +// OperationMonitoringTaskConfig operationMonitoringTaskConfig = deviceTypeMetaDefinition.getTaskConfig(); +// if (operationMonitoringTaskConfig != null) { +// TaskConfiguration taskConfiguration = new TaskConfiguration(); +// taskConfiguration.setEnabled(operationMonitoringTaskConfig.isEnabled()); +// taskConfiguration.setFrequency(operationMonitoringTaskConfig.getFrequency()); +// if (operationMonitoringTaskConfig.getMonitoringOperation() != null) { +// List operations = new ArrayList<>(); +// for (MonitoringOperation monitoringOperation : operationMonitoringTaskConfig +// .getMonitoringOperation()) { +// TaskConfiguration.Operation operation = new TaskConfiguration.Operation(); +// operation.setOperationName(monitoringOperation.getTaskName()); +// operation.setRecurrency(monitoringOperation.getRecurrentTimes()); +// operations.add(operation); +// } +// taskConfiguration.setOperations(operations); +// } +// deviceTypeConfiguration.setTaskConfiguration(taskConfiguration); +// } if (deviceTypeMetaDefinition.getInitialOperationConfig() != null) { InitialOperationConfig initialOperationConfig = deviceTypeMetaDefinition.getInitialOperationConfig(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/dao/PropertyBasedPluginDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/dao/PropertyBasedPluginDAOImpl.java index 96992c5f9d..55419bb5b2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/dao/PropertyBasedPluginDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/dao/PropertyBasedPluginDAOImpl.java @@ -70,9 +70,6 @@ public class PropertyBasedPluginDAOImpl implements PluginDAO { stmt.setString(2, deviceId); stmt.setInt(3, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true)); resultSet = stmt.executeQuery(); - device = new Device(); - device.setDeviceIdentifier(deviceId); - device.setType(deviceType); List properties = new ArrayList<>(); while (resultSet.next()) { Device.Property property = new Device.Property(); @@ -80,7 +77,12 @@ public class PropertyBasedPluginDAOImpl implements PluginDAO { property.setValue(resultSet.getString(PROPERTY_VALUE_COLUMN_NAME)); properties.add(property); } - device.setProperties(properties); + if (properties.size() > 0) { + device = new Device(); + device.setDeviceIdentifier(deviceId); + device.setType(deviceType); + device.setProperties(properties); + } } catch (SQLException e) { String msg = "Error occurred while fetching device : '" + deviceId + "' type " + deviceType; log.error(msg, e); @@ -133,7 +135,11 @@ public class PropertyBasedPluginDAOImpl implements PluginDAO { "UPDATE DM_DEVICE_PROPERTIES SET PROPERTY_VALUE = ? WHERE DEVICE_TYPE_NAME = ? AND " + "DEVICE_IDENTIFICATION = ? AND PROPERTY_NAME = ? AND TENANT_ID= ?"); + Device.Property[] properties = new Device.Property[device.getProperties().size()]; + int i =0; for (Device.Property property : device.getProperties()) { + properties[i] = property; + i++; stmt.setString(1, getPropertyValue(device.getProperties(), property.getValue())); stmt.setString(1, deviceType); stmt.setString(2, device.getDeviceIdentifier()); @@ -141,13 +147,23 @@ public class PropertyBasedPluginDAOImpl implements PluginDAO { stmt.setInt(4, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true)); stmt.addBatch(); } - stmt.executeBatch(); - int rows = stmt.executeUpdate(); - if (rows > 0) { - status = true; - if (log.isDebugEnabled()) { - log.debug("device " + device.getDeviceIdentifier() + " data has been modified."); + int[] updates = stmt.executeBatch(); + if (updates.length > 0) { + for (int j = 0; j < updates.length; j++) { + if (updates[j] < 0) { + stmt = conn.prepareStatement( + "INSERT INTO DM_DEVICE_PROPERTIES(DEVICE_TYPE_NAME, DEVICE_IDENTIFICATION, PROPERTY_NAME, " + + "PROPERTY_VALUE, TENANT_ID) VALUES (?, ?, ?, ?, ?)"); + stmt.setString(1, deviceType); + stmt.setString(2, device.getDeviceIdentifier()); + stmt.setString(3, properties[j].getName()); + stmt.setString(4, getPropertyValue(device.getProperties(), properties[j].getValue())); + stmt.setInt(5, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true)); + stmt.addBatch(); + } } + stmt.executeBatch(); + status = true; } } catch (SQLException e) { String msg = "Error occurred while modifying the device '" + 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 3ae63189ee..61dda23a3a 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 @@ -179,7 +179,8 @@ "perm:devicetype:deployment", "perm:device-types:events", "perm:device-types:events:view", - "perm:admin:device-type" + "perm:admin:device-type", + "perm:devices:add" ], "isOAuthEnabled": true, "backendRestEndpoints": { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.js index 361868f05f..9f13ffd696 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.js @@ -62,7 +62,7 @@ function onRequest(context) { var config = utility.getDeviceTypeConfig(data[i]); var category = "iot"; var label = data[i]; - var analyticsEnabled = "true"; + var analyticsEnabled = "false"; var groupingEnabled = "true"; if (config) { var deviceType = config.deviceType; 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 index 0795c6bb63..784ae57ef0 100644 --- 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 @@ -57,7 +57,7 @@
1
- +
@@ -74,14 +74,14 @@