fixed UI Issues

revert-70aa11f8
ayyoob 8 years ago
parent dd1c2e4338
commit 4d22bc7064

@ -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(

@ -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

@ -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();
}

@ -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<Attribute> 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<SortByField> 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<SortByField> 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);

@ -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());

@ -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<DeviceType> deviceTypes = DeviceMgtAPIUtils.getDeviceManagementService().getDeviceTypes();
List<DeviceType> 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;
}
}

@ -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;
}

@ -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) {

@ -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;
}

@ -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;
}
}
}

@ -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<TaskConfiguration.Operation> 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<TaskConfiguration.Operation> 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();

@ -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<Device.Property> 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);
}
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();
}
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();
int rows = stmt.executeUpdate();
if (rows > 0) {
status = true;
if (log.isDebugEnabled()) {
log.debug("device " + device.getDeviceIdentifier() + " data has been modified.");
}
}
} catch (SQLException e) {
String msg = "Error occurred while modifying the device '" +

@ -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": {

@ -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;

@ -57,7 +57,7 @@
<div class="col-md-6 col-xs-6">
<div class="itm-wiz itm-wiz-current" data-step="policy-platform">
<div class="wiz-no">1</div>
<div class="wiz-lbl hidden-xs"><span>Create A Device Type</span></div>
<div class="wiz-lbl hidden-xs"><span>Create Device Type</span></div>
</div>
</div>
<div class="col-md-6 col-xs-6">
@ -74,14 +74,14 @@
<i class="icon fw fw-error"></i><span></span>
</div>
<label class="wr-input-label">
Device Type Name *
Name * (eg: firealarm)
</label>
<br>
<input aria-describedby="basic-addon1" type="text" id="deviceTypeName"
data-error-msg="invalid device type name" class="form-control"/>
<label class="wr-input-label">
Device Type Description *
Description *
</label>
<br>
<textarea aria-describedby="basic-addon1" type="text" id="deviceTypeDescription"
@ -94,13 +94,13 @@
<select id="pushNotification" class="form-control select">
<option>NONE</option>
<option>MQTT</option>
<option>FCM</option>
<option>APNS</option>
</select>
</div>
<label class="wr-input-label">
Features
Features (Definition of the operation from server to device)
<br/>
(eg: name: fire alarm range control, code: alarm, description: this controls the alarm sound type and range of firealarm)
</label>
<br>
@ -125,7 +125,7 @@
<br>
<label class="wr-input-label">
Device Attributes
Attributes (eg: vendor, model_number ...)
</label>
<br>
@ -149,7 +149,7 @@
</div>
<label class="wr-input-label">
Initial Operation(Feature Code, Trigger operation when device enrolls)
Enrolment Operation (Triggers the operation after the enrolment, eg: alarm)
</label>
<br>
@ -206,6 +206,41 @@
</button>
</div>
</div>
<!-- modal -->
<div class="modal fade" id="modalDevice" tabindex="-1" role="dialog" aria-labelledby="modalDevice">
<div class="modal-dialog" role="document">
<div class="modal-content clearfix">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fw fw-cancel"></i></button>
<h3 class="modal-title" id="deviceModalLabel">Device Type Updated</h3>
</div>
<div class="modal-body add-margin-top-2x add-margin-bottom-2x">
<p>One fine body…</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary">Go To Enrolment Page</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="modalDeviceFailed" tabindex="-1" role="dialog" aria-labelledby="modalDeviceFailed">
<div class="modal-dialog" role="document">
<div class="modal-content clearfix">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fw fw-cancel"></i></button>
<h3 class="modal-title" id="deviceModalLabel">Device Type Update Failed</h3>
</div>
<div class="modal-body add-margin-top-2x add-margin-bottom-2x">
<p>One fine body…</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
</div>
</div>
</div>
</div>
<!-- /modal -->
<!-- /content -->
<div id="app-context" data-app-context="{{@app.context}}" class="hidden"></div>
</div>

@ -61,7 +61,7 @@
data-error-msg="invalid device type name" class="form-control hidden-input" value="{{name}}"/>
<label class="wr-input-label">
Device Type Description *
Description *
</label>
<br>
<textarea aria-describedby="basic-addon1" type="text" id="deviceTypeDescription"
@ -76,24 +76,10 @@
<option>NONE</option>
{{#if_eq type.deviceTypeMetaDefinition.pushNotificationConfig.type "MQTT"}}
<option selected>MQTT</option>
<option>FCM</option>
<option>APNS</option>
{{/if_eq}}
{{#if_eq type.deviceTypeMetaDefinition.pushNotificationConfig.type "FCM"}}
<option>MQTT</option>
<option selected>FCM</option>
<option>APNS</option>
{{/if_eq}}
{{#if_eq type.deviceTypeMetaDefinition.pushNotificationConfig.type "APNS"}}
<option>MQTT</option>
<option>FCM</option>
<option selected>APNS</option>
{{/if_eq}}
{{else}}
<option selected>NONE</option>
<option>MQTT</option>
<option>FCM</option>
<option>APNS</option>
{{/if}}
@ -144,7 +130,7 @@
<br>
<label class="wr-input-label">
Device Attributes
Attributes
</label>
<br>
<div class="form-group attribute_field_wrapper">
@ -177,7 +163,7 @@
</div>
<label class="wr-input-label">
Initial Operation(Feature Code, Trigger operation when device enrolls)
Enrolment Operation
</label>
<br>
@ -253,6 +239,20 @@
</button>
</div>
</div>
<div class="modal fade" id="modalDevice" tabindex="-1" role="dialog" aria-labelledby="modalDevice">
<div class="modal-dialog" role="document">
<div class="modal-content clearfix">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fw fw-cancel"></i></button>
<h3 class="modal-title" id="deviceModalLabel">Device Type Definition Updated</h3>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" onclick="location.href='{{@app.context}}/device/enroll'">Go To Enrolment Page</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
</div>
</div>
</div>
</div>
<!-- /content -->
<div id="app-context" data-app-context="{{@app.context}}" class="hidden"></div>
</div>

@ -93,8 +93,6 @@ function formatRepoSelection(user) {
return user.username || user.text;
}
$(document).ready(function () {
var appContext = $("#app-context").data("app-context");
@ -222,8 +220,7 @@ $(document).ready(function () {
deviceType,
function (data, textStatus, jqXHR) {
if (jqXHR.status == 200) {
$(successMsg).text("Device type updated.");
$(successMsgWrapper).removeClass("hidden");
$("#modalDevice").modal('show');
}
},
function (jqXHR) {

@ -76,7 +76,7 @@
</div>
<label class="wr-input-label">
Event Attributes
Event Attributes (eg: alarm_status, temperature)
</label>
<br>
<div class="form-group event_field_wrapper">
@ -145,6 +145,21 @@
</div>
</div>
<!-- /content/body -->
<div class="modal fade" id="modalDevice" tabindex="-1" role="dialog" aria-labelledby="modalDevice">
<div class="modal-dialog" role="document">
<div class="modal-content clearfix">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fw fw-cancel"></i></button>
<h3 class="modal-title" id="deviceModalLabel">Successfully Deployed Event Definition</h3>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" onclick="location.href='{{@app.context}}/device/enroll'">Go To Enrolment Page</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
</div>
</div>
</div>
</div>
{{else}}
<h1 class="page-sub-title">
Permission Denied

@ -159,18 +159,17 @@ $(document).ready(function () {
deviceTypeEvent,
function (data, textStatus, jqXHR) {
if (jqXHR.status == 200) {
$(successMsg).text("Device Event Definition added.");
$(successMsgWrapper).removeClass("hidden");
$("#modalDevice").modal('show');
}
},
function (jqXHR) {
if (jqXHR.status == 500) {
$(errorMsg).text("Unexpected error.");
$(errorMsg).text("Failed to deploy event definition, Please Contact Administrator");
$(errorMsgWrapper).removeClass("hidden");
}
if (jqXHR.status == 409) {
$(errorMsg).text("Device type already exists");
$(errorMsg).text("Device type definition cannot be updated");
$(errorMsgWrapper).removeClass("hidden");
}
}

@ -17,48 +17,23 @@
}}
<table class="table table-responsive table-striped" id="members">
<tbody>
{{#each device.initialDeviceInfo}}
<tr role="row" class="odd">
<td class="sorting_1" style="padding:10px 15px;">Model</td>
<td style="padding:10px 15px;">TODO</td>
<td class="sorting_1" style="padding:10px 15px;">{{@key}}</td>
<td style="padding:10px 15px;">{{this}}</td>
</tr>
{{/each}}
<tr role="row" class="even">
<td class="sorting_1" style="padding:10px 15px;">Status</td>
<td style="padding:10px 15px;">
{{#if permissions.CHANGE_DEVICE_STATUS}}
{{#equal device.status "ACTIVE"}}<span><i id="statusIcon"
class="fw fw-success icon-success"></i>
<a href="#" id="status" data-type="select" data-pk="1"
data-title="Select status"
selectedValue="Active"></a>
</span>{{/equal}}
{{#equal device.status "INACTIVE"}}<span><i id="statusIcon"
class="fw fw-warning icon-warning"></i>
<a href="#" id="status" data-type="select" data-pk="1"
data-title="Select status"
selectedValue="Inactive"></a>
</span>{{/equal}}
{{#equal device.status "BLOCKED"}}<span><i id="statusIcon"
class="fw fw-remove icon-danger"></i>
<a href="#" id="status" data-type="select" data-pk="1"
data-title="Select status"
selectedValue="Blocked"></a>
</span>{{/equal}}
{{#equal device.status "REMOVED"}}<span><i id="statusIcon"
class="fw fw-delete icon-danger"></i>
<a href="#" id="status" data-type="select" data-pk="1"
data-title="Select status"
selectedValue="Removed"></a>
</span>{{/equal}}
{{else}}
{{#equal device.status "ACTIVE"}}<span><i
{{#equal device.enrolmentInfo.status "ACTIVE"}}<span><i
class="fw fw-success icon-success"></i> Active</span>{{/equal}}
{{#equal device.status "INACTIVE"}}<span><i
{{#equal device.enrolmentInfo.status "INACTIVE"}}<span><i
class="fw fw-warning icon-warning"></i> Inactive</span>{{/equal}}
{{#equal device.status "BLOCKED"}}<span><i
{{#equal device.enrolmentInfo.status "BLOCKED"}}<span><i
class="fw fw-remove icon-danger"></i> Blocked</span>{{/equal}}
{{#equal device.status "REMOVED"}}<span><i
{{#equal device.enrolmentInfo.status "REMOVED"}}<span><i
class="fw fw-delete icon-danger"></i> Removed</span>{{/equal}}
{{/if}}
</td>
</tr>
</tbody>

@ -34,10 +34,10 @@ function onRequest(context) {
restAPIEndpoint,
function (restAPIResponse) {
if (restAPIResponse["status"] == 200 && restAPIResponse["responseText"]) {
var eventAttributes = parse(restAPIResponse["responseText"]);
if (eventAttributes.attributes.length > 0) {
for (var i = 0; i < eventAttributes.attributes.length; i++) {
var attribute = eventAttributes.attributes[i];
var data = parse(restAPIResponse["responseText"]);
if (data.eventAttributes.attributes.length > 0) {
for (var i = 0; i < data.eventAttributes.attributes.length; i++) {
var attribute = data.eventAttributes.attributes[i];
if (attribute['name'] == "deviceId") {
continue;
}

@ -26,6 +26,7 @@
{{#zone "overview-section"}}
<div style="background: #11375B; color: #fff; padding: 10px; margin-bottom: 5px">
Device Overview - {{label}}</div>
{{device.type}}sdf
{{unit "cdmf.unit.default.device.overview-section" device=device}}
{{/zone}}

@ -31,10 +31,10 @@ function onRequest(context) {
restAPIEndpoint,
function (restAPIResponse) {
if (restAPIResponse["status"] == 200 && restAPIResponse["responseText"]) {
var eventAttributes = parse(restAPIResponse["responseText"]);
if (eventAttributes.attributes.length > 0) {
for (var i = 0; i < eventAttributes.attributes.length; i++) {
var attribute = eventAttributes.attributes[i];
var data = parse(restAPIResponse["responseText"]);
if (data.eventAttributes.attributes.length > 0) {
for (var i = 0; i < data.eventAttributes.attributes.length; i++) {
var attribute = data.eventAttributes.attributes[i];
if (attribute['name'] == "deviceId") {
continue;
}
@ -48,16 +48,18 @@ function onRequest(context) {
var featureEndpoint = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"]
+ "/device-types/" + deviceType + "/features";
var featuresList = serviceInvokers.XMLHttp.get(featureEndpoint, function (responsePayload) {
serviceInvokers.XMLHttp.get(featureEndpoint, function (responsePayload) {
var features = JSON.parse(responsePayload.responseText);
new Log().error(responsePayload.responseText);
var feature;
for (var i = 0; i < features.length; i++) {
feature = {};
feature["operation"] = features[i].code;
feature["name"] = features[i].name;
feature["description"] = features[i].description;
}
featureList.push(feature);
}
}, function (responsePayload) {
featureList = null;
}

@ -351,6 +351,8 @@ $(".download-link").click(function(){
toggleEnrollment();
});
var apiBasePath = "/api/device-mgt/v1.0";
$(document).ready(function () {
$.sidebar_toggle();
if (typeof $.fn.collapse == 'function') {
@ -385,4 +387,68 @@ $(document).ready(function () {
}
);
});
/**
* Following click function would execute
* when a user clicks on "Add Device type" button.
*/
$("button#add-device-btn").click(function () {
var errorMsgWrapper = "#device-create-error-msg";
var errorMsg = "#device-create-error-msg span";
var successMsgWrapper = "#device-create-success-msg";
var successMsg = "#device-create-success-msg span";
var deviceName = $("#deviceName").val();
var deviceType = $("#deviceTypeName").val();
var deviceId = $("#deviceId").val();
var deviceDescription = $("#deviceDescription").val();
if (!deviceType || deviceType.trim() == "" || !deviceName || deviceName.trim() == "" || !deviceId || deviceId.trim() == "") {
$(errorMsg).text("Device ID/Name Cannot be empty.");
$(errorMsgWrapper).removeClass("hidden");
return;
}
var device = {};
device.name = deviceName;
device.deviceIdentifier = deviceId;
device.description = deviceDescription;
device.type = deviceType;
device.enrolmentInfo = {};
device.enrolmentInfo.status = "ACTIVE";
device.enrolmentInfo.ownership = "BYOD";
device.properties = [];
$('input[name^="properties"]').each(function() {
var propName = $(this).attr('id');
var propValue = $(this).val();
if (propName && propName.trim() != "" && propValue && propValue.trim() != "") {
var property = {};
property.name = propName.trim();
property.value = propValue.trim();
device.properties.push(property);
}
});
var addDeviceAPI = apiBasePath + "/devices";
invokerUtil.post(
addDeviceAPI,
device,
function (data, textStatus, jqXHR) {
if (jqXHR.status == 200) {
$(successMsg).text("Device added.");
$(successMsgWrapper).removeClass("hidden");
}
},
function (jqXHR) {
if (jqXHR.status == 500) {
$(errorMsg).text("Unexpected error.");
$(errorMsgWrapper).removeClass("hidden");
}
if (jqXHR.status == 409) {
$(errorMsg).text("Device already exists");
$(errorMsgWrapper).removeClass("hidden");
}
}
);
});
});

@ -1,5 +1,6 @@
<div class="col-lg-12 margin-top-double">
<h1 class="grey "></h1>
<h1 class="grey ">{{deviceType}}</h1>
<hr>
</div>
@ -8,13 +9,12 @@
</div>
<div class="col-xs-12 col-sm-8 col-md-8 col-lg-8 padding-top">
</div>
<div class="col-xs-12 col-sm-8 col-md-8 col-lg-8 padding-top">
<h3 class="uppercase">Description</h3>
<hr>
<p class="grey margin-top">Need to get the description from the device</p>
<p class="grey margin-top">{{type.deviceTypeMetaDefinition.description}}</p>
<br>
<hr>
<br>
@ -108,54 +108,146 @@
<br/><br/>
</div>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 padding-double grey-bg">
<h3 class="uppercase">How To Enroll a Device</h3>
<h2 class="uppercase">How To Enroll a Device</h2>
<hr>
<ul class="list-unstyled">
<li class="padding-top-double"><span class="circle">01</span>
&nbsp;&nbsp;&nbsp;curl -k -X POST https://localhost:8243/api-application-registration/register -H
<li class="padding-top-double"><span><h3 class="uppercase">Generate Application</h3></span>
<code>curl -k -X POST https://localhost:8243/api-application-registration/register -H
'authorization: Basic Base64(username:password)' -H 'content-type: application/json'
-d '{ "applicationName":"testme", "isAllowedToAllDomains":false, "tags":["device_management"]}'
-d '{ "applicationName":"testme", "isAllowedToAllDomains":false, "tags":["device_management"]}'</code>
</li>
<li class="padding-top-double"><span class="circle">02</span>
&nbsp;&nbsp;&nbsp;curl -k -d "grant_type=password&username=%username%&password=%password%&scope=perm:devices:add"
<li class="padding-top-double"><span><h3 class="uppercase">Generate Token</h3></span>
<code>curl -k -d "grant_type=password&username=%username%&password=%password%&scope=perm:devices:add"
-H "Authorization: Basic Base64(client_id:client_secret)"
-H "Content-Type: application/x-www-form-urlencoded" https://localhost:8243/token
-H "Content-Type: application/x-www-form-urlencoded" https://localhost:8243/token</code>
</li>
<li class="padding-top-double"><span class="circle">03</span>
&nbsp;&nbsp;&nbsp;curl -X POST http://localhost:8280/api/device-mgt/v1.0/devices -H 'accept: application/json'
<li class="padding-top-double"><span><h3 class="uppercase">Create Device</h3></span>
<code>curl -X POST http://localhost:8280/api/device-mgt/v1.0/devices -H 'accept: application/json'
-H 'authorization: Bearer %accessToken%'
-H 'content-type: application/json' -d '{ "name": "devicename", "type": "{{deviceType}}",
"description": "descritption", "deviceIdentifier": "1234", "enrolmentInfo":
{"dateOfEnrolment": 0, "dateOfLastUpdate": 0, "ownership": "BYOD", "status": "ACTIVE", "owner": "username"}
,"properties": [{"name": "propertyName","value": "propertyValue"}]}'
{"ownership": "BYOD", "status": "ACTIVE"}
,"properties": [{"name": "propertyName","value": "propertyValue"}]}'</code>
</li>
</ul>
<br>
<br>
</div>
<hr/>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 padding-double grey-bg">
<h2 class="uppercase">Create A Device</h2>
<hr>
<div id="device-create-form" class="container col-centered wr-content">
<div class="wr-form">
<div class="row">
<div class="col-lg-8">
<div id="device-create-error-msg" class="alert alert-danger hidden" role="alert">
<i class="icon fw fw-error"></i><span></span>
</div>
<input aria-describedby="basic-addon1" type="text" id="deviceTypeName" style="display: none;"
data-error-msg="invalid device type name" class="form-control" value="{{deviceType}}"/>
<br>
<label class="wr-input-label">Name</label>
<input aria-describedby="basic-addon1" type="text" id="deviceName"
data-error-msg="invalid device name" class="form-control hidden-input"/>
<br/>
<label class="wr-input-label">Device Identifier</label>
<input aria-describedby="basic-addon1" type="text" id="deviceId"
data-error-msg="invalid device id" class="form-control hidden-input"/>
<br/>
<label class="wr-input-label">Description</label>
<input aria-describedby="basic-addon1" type="text" id="deviceDescription"
data-error-msg="invalid device description" class="form-control hidden-input"/>
<br/>
{{#if type.deviceTypeMetaDefinition}}
{{#each type.deviceTypeMetaDefinition.properties}}
<label class="wr-input-label">{{this}}</label>
<input aria-describedby="basic-addon1" type="text" id="{{this}}" name="properties"
data-error-msg="invalid device description" class="form-control hidden-input"/>
<br/>
{{/each}}
{{/if}}
<br>
<button id="add-device-btn" class="wr-btn">Create Device</button>
<div id="device-create-success-msg" class="alert hidden" role="alert">
<i class="icon fw fw-success"></i><span></span>
</div>
</div>
</div>
<div id="devicetype-created-msg" class="container col-centered wr-content hidden">
<div class="wr-form">
<p class="page-sub-title">Device Type Event was added successfully.</p>
<b>"View Device Type List"</b> to complete the process and go back to the devie type list.
<hr/>
<button class="wr-btn" onclick="window.location.href='{{@app.context}}/device-types'">
View Device Type List
</button>
</div>
</div>
<!-- /content -->
<div id="app-context" data-app-context="{{@app.context}}" class="hidden"></div>
</div>
</div>
<br>
<br>
</div>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 padding-double grey-bg">
<h3 class="uppercase">Topic to publish data for analytics : {{tenantDomain}}/{{deviceType}}/&lt;device_id&gt;/events</h3>
<h3 class="uppercase">Topic to publish data to an external system : {{tenantDomain}}/{{deviceType}}/&lt;device_id&gt;/proxy</h3>
<h3 class="uppercase">Topic to listen for operation: {{tenantDomain}}/{{deviceType}}/&lt;device_id&gt;/operation/#</h3>
<h2 class="uppercase">Device Communication</h2>
<hr>
{{#if event}}
<h3 class="uppercase">publish data for analytics :</h3>
{{#if_eq event.transport "MQTT"}}
MQTT Topic : <code>{{tenantDomain}}/{{deviceType}}/&lt;device_id&gt;/events</code>
{{/if_eq}}
{{#if_eq event.transport "HTTP"}}
HTTP API : <code>POST: </code>
{{/if_eq}}
{{#if eventSample}}
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 padding-double grey-bg">
Device Event Payload
<code>{{eventSample}}</code>
<br>
<br>
</div>
{{/if}}
{{/if}}
</br>
<h3 class="uppercase">Retrieve operations</h3>
{{#if type.deviceTypeMetaDefinition.pushNotificationConfig}}
{{#if_eq type.deviceTypeMetaDefinition.pushNotificationConfig.type "MQTT"}}
MQTT Topic : <code>{{tenantDomain}}/{{deviceType}}/&lt;device_id&gt;/operation/#</code>
<br/>
Topic Structure:
<ul class="list-unstyled">
<li class="padding-top-double">
{{tenantDomain}}/{{deviceType}}/&lt;device_id&gt;/operation/command/&lt;feature_code&gt;
<code>{{tenantDomain}}/{{deviceType}}/&lt;device_id&gt;/operation/command/&lt;feature_code&gt;</code>
</li>
<li class="padding-top-double">
{{tenantDomain}}/{{deviceType}}/&lt;device_id&gt;/operation/config/&lt;feature_code&gt;
<code>{{tenantDomain}}/{{deviceType}}/&lt;device_id&gt;/operation/config/&lt;feature_code&gt;</code>
</li>
<li class="padding-top-double">
{{tenantDomain}}/{{deviceType}}/&lt;device_id&gt;/operation/profile/&lt;feature_code&gt;
<code>{{tenantDomain}}/{{deviceType}}/&lt;device_id&gt;/operation/profile/&lt;feature_code&gt;</code>
</li>
<li class="padding-top-double">
{{tenantDomain}}/{{deviceType}}/&lt;device_id&gt;/operation/policy/policy_bundle
<code>{{tenantDomain}}/{{deviceType}}/&lt;device_id&gt;/operation/policy/policy_bundle</code>
</li>
<li class="padding-top-double">
{{tenantDomain}}/{{deviceType}}/&lt;device_id&gt;/operation/policy/policy_revoke
<code>{{tenantDomain}}/{{deviceType}}/&lt;device_id&gt;/operation/policy/policy_revoke</code>
</li>
</ul>
{{/if_eq}}
{{else}}
<a href="/api-store/apis/info?name=DeviceManagement&version=1.0.0&provider=admin"
class="btn-operations"
target="_blank"><i class="fw fw-api add-margin-1x"></i> View Operation API</i>
</a>
{{/if}}
<br>
<br>
</div>
@ -165,4 +257,5 @@
{{/zone}}
{{#zone "bottomJs"}}
{{js "js/type-view.js"}}
{{/zone}}

@ -18,11 +18,77 @@
function onRequest(context) {
var deviceType = context.uriParams.deviceType;
var displayData = {};
var userModule = require("/app/modules/business-controllers/user.js")["userModule"];
var user = userModule.getCarbonUser();
var tenantDomain = user.domain;
return {
"deviceType": deviceType,
"tenantDomain": tenantDomain
};
var deviceMgtProps = require("/app/modules/conf-reader/main.js")["conf"];
var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"];
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 restAPIEndpoint = deviceMgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"]
+ "/device-types/all/" + deviceType;
displayData.deviceType = deviceType;
displayData.tenantDomain = tenantDomain;
serviceInvokers.XMLHttp.get(
restAPIEndpoint,
function (restAPIResponse) {
if (restAPIResponse["status"] == 200 && restAPIResponse["responseText"]) {
var typeData = parse(restAPIResponse["responseText"]);
displayData.type = typeData;
}
}
);
var eventRestAPIEndpoint = deviceMgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"]
+ "/events/" + deviceType;
serviceInvokers.XMLHttp.get(
eventRestAPIEndpoint,
function (restAPIResponse) {
if (restAPIResponse["status"] == 200 && restAPIResponse["responseText"]) {
var typeData = parse(restAPIResponse["responseText"]);
displayData.event = typeData;
if (typeData.eventAttributes && typeData.eventAttributes.attributes) {
var sample = {};
sample.event = {};
var eventExample = {};
for (var i = 0; i < typeData.eventAttributes.attributes.length; i++) {
var attribute = typeData.eventAttributes.attributes[i];
new Log().error(attribute.type);
switch (attribute.type) {
case "STRING":
eventExample[attribute.name] = "string";
break;
case "LONG":
eventExample[attribute.name] = 0;
break;
case "INT":
eventExample[attribute.name] = 0;
break;
case "FLOAT":
eventExample[attribute.name] = 0.0;
break;
case "DOUBLE":
eventExample[attribute.name] = 0.0;
break;
case "BOOL":
eventExample[attribute.name] = false;
break;
}
}
sample.event.payloadData = eventExample;
displayData.eventSample = JSON.stringify(sample);
}
}
}
);
return displayData;
}

@ -44,9 +44,27 @@ function onRequest(context) {
deviceTypeLabel = configs[DTYPE_CONF_DEVICE_TYPE_KEY][DTYPE_CONF_DEVICE_TYPE_LABEL_KEY];
}
var policyWizardSrc = "/app/units/" + utility.getTenantedDeviceUnitName(deviceType, "policy-wizard");
if (new File(policyWizardSrc).isExists()) {
content["icon"] = utility.getDeviceThumb(deviceType);
content["label"] = deviceTypeLabel;
if (new File(policyWizardSrc).isExists()) {
var policyOperationsTemplateSrc = policyWizardSrc + "/public/templates/" + deviceType + "-policy-operations.hbs";
if (new File(policyOperationsTemplateSrc).isExists()) {
content["template"] = "/public/cdmf.unit.device.type." + deviceType +
".policy-wizard/templates/" + deviceType + "-policy-operations.hbs";
}
var policyOperationsScriptSrc = policyWizardSrc + "/public/js/" + deviceType + "-policy-operations.js";
if (new File(policyOperationsScriptSrc).isExists()) {
content["script"] = "/public/cdmf.unit.device.type." + deviceType +
".policy-wizard/js/" + deviceType + "-policy-operations.js";;
}
var policyOperationsStylesSrc = policyWizardSrc + "/public/css/" + deviceType + "-policy-operations.css";
if (new File(policyOperationsStylesSrc).isExists()) {
content["style"] = "/public/cdmf.unit.device.type." + deviceType +
".policy-wizard/css/" + deviceType + "-policy-operations.css";;
}
types["types"].push(content);
} else {
policyWizardSrc = "cdmf.unit.policy.create"
var policyOperationsTemplateSrc = policyWizardSrc + "/public/templates/" + deviceType + "-policy-operations.hbs";
if (new File(policyOperationsTemplateSrc).isExists()) {
content["template"] = "/public/cdmf.unit.device.type." + deviceType +

Loading…
Cancel
Save