merge ui fixes

revert-70aa11f8
ayyoob 8 years ago
parent f47d0deb1a
commit ca33f035df

@ -8,6 +8,7 @@ import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.InvalidConfigurationException;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext;
import java.net.UnknownHostException;
@ -80,8 +81,10 @@ public class HTTPMessageExecutor implements Runnable {
} catch (UnknownHostException e) {
log.error("Push Notification message dropped " + url, e);
throw new InvalidConfigurationException("invalid host: url", e);
} catch (Throwable e) {
log.error("Push Notification message dropped ", e);
throw new InvalidConfigurationException("Push Notification message dropped, " + e.getMessage(), e);
} finally {
if (method != null) {
method.releaseConnection();

@ -22,6 +22,7 @@ import org.apache.commons.httpclient.HostConfiguration;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.InvalidConfigurationException;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
@ -48,10 +49,9 @@ public class HTTPNotificationStrategy implements NotificationStrategy {
public HTTPNotificationStrategy(PushNotificationConfig config) {
this.config = config;
}
@Override
public void init() {
if (this.config == null) {
throw new InvalidConfigurationException("Properties Cannot be found");
}
endpoint = config.getProperties().get(URL_PROPERTY);
if (endpoint == null || endpoint.isEmpty()) {
throw new InvalidConfigurationException("Property - 'url' cannot be found");
@ -69,6 +69,11 @@ public class HTTPNotificationStrategy implements NotificationStrategy {
}
}
@Override
public void init() {
}
@Override
public void execute(NotificationContext ctx) throws PushNotificationExecutionFailedException {
try {

@ -1,46 +0,0 @@
/*
* 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.
*
*/
package org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt;
/**
* This exception is thrown whether the mqtt configured with invalid configuration.
*/
public class InvalidConfigurationException extends RuntimeException {
public InvalidConfigurationException(String msg, Exception nestedEx) {
super(msg, nestedEx);
}
public InvalidConfigurationException(String message, Throwable cause) {
super(message, cause);
}
public InvalidConfigurationException(String msg) {
super(msg);
}
public InvalidConfigurationException() {
super();
}
public InvalidConfigurationException(Throwable cause) {
super(cause);
}
}

@ -21,6 +21,7 @@ package org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt;
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.InvalidConfigurationException;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;

@ -1,46 +0,0 @@
/*
* 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.
*
*/
package org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp;
/**
* This exception is thrown whether the xmpp configured with invalid configuration.
*/
public class InvalidConfigurationException extends RuntimeException {
public InvalidConfigurationException(String msg, Exception nestedEx) {
super(msg, nestedEx);
}
public InvalidConfigurationException(String message, Throwable cause) {
super(message, cause);
}
public InvalidConfigurationException(String msg) {
super(msg);
}
public InvalidConfigurationException() {
super();
}
public InvalidConfigurationException(Throwable cause) {
super(cause);
}
}

@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.InvalidConfigurationException;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;

@ -31,6 +31,7 @@ import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.common.InvalidConfigurationException;
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException;
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
@ -85,7 +86,7 @@ public class DeviceAgentServiceImpl implements DeviceAgentService {
String errorMessage = "The payload of the device enrollment is incorrect.";
return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build();
}
Device existingDevice = dms.getDevice(new DeviceIdentifier(device.getType(), device.getType()));
Device existingDevice = dms.getDevice(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
if (existingDevice != null && existingDevice.getEnrolmentInfo() != null && existingDevice
.getEnrolmentInfo().getStatus().equals(EnrolmentInfo.Status.ACTIVE)) {
String errorMessage = "An active enrolment exists";
@ -101,6 +102,9 @@ public class DeviceAgentServiceImpl implements DeviceAgentService {
device.getDeviceIdentifier() + "'";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (InvalidConfigurationException e) {
log.error("failed to add operation", e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}
}

@ -485,7 +485,7 @@ public class DeviceEventManagementServiceImpl implements DeviceEventManagementSe
analyticsTableRecord.setColumnName(attribute.getName());
analyticsTableRecord.setColumnType(attribute.getType().toString().toUpperCase());
analyticsTableRecord.setFacet(false);
analyticsTableRecord.setIndexed(true);
analyticsTableRecord.setIndexed(false);
analyticsTableRecord.setPersist(true);
analyticsTableRecord.setPrimaryKey(false);
analyticsTableRecord.setScoreParam(false);

@ -29,6 +29,7 @@ import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.common.Feature;
import org.wso2.carbon.device.mgt.common.FeatureManager;
import org.wso2.carbon.device.mgt.common.InvalidConfigurationException;
import org.wso2.carbon.device.mgt.common.InvalidDeviceException;
import org.wso2.carbon.device.mgt.common.PaginationRequest;
import org.wso2.carbon.device.mgt.common.PaginationResult;
@ -716,6 +717,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
log.error(errorMessage, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
} catch (InvalidConfigurationException e) {
log.error("failed to add operation", e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}
}
}

@ -21,6 +21,7 @@ package org.wso2.carbon.device.mgt.jaxrs.service.impl.admin;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.InvalidConfigurationException;
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
import org.wso2.carbon.device.mgt.common.spi.DeviceTypeGeneratorService;
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
@ -88,6 +89,8 @@ public class DeviceTypeManagementAdminServiceImpl implements DeviceTypeManagemen
String msg = "Error occurred at server side while adding a device type.";
log.error(msg, e);
return Response.serverError().entity(msg).build();
} catch (InvalidConfigurationException e) {
return Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build();
}
} else {
return Response.status(Response.Status.BAD_REQUEST).build();
@ -111,6 +114,8 @@ public class DeviceTypeManagementAdminServiceImpl implements DeviceTypeManagemen
String msg = "Error occurred at server side while updating the device type.";
log.error(msg, e);
return Response.serverError().entity(msg).build();
} catch (InvalidConfigurationException e) {
return Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build();
}
} else {
return Response.status(Response.Status.BAD_REQUEST).build();

@ -16,10 +16,10 @@
* under the License.
*
*/
package org.wso2.carbon.device.mgt.extensions.push.notification.provider.http;
package org.wso2.carbon.device.mgt.common;
/**
* This exception is thrown whether the http configured with invalid configuration.
* This exception is thrown when configured with invalid configuration.
*/
public class InvalidConfigurationException extends RuntimeException {

@ -121,7 +121,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, d.NAME, " +
"t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE " +
"t.NAME = ? AND d.DEVICE_IDENTIFICATION = ? AND d.TENANT_ID = ?) d1 WHERE d1.ID = e.DEVICE_ID " +
"t.NAME = ? AND t.ID = d.DEVICE_TYPE_ID AND d.DEVICE_IDENTIFICATION = ? AND d.TENANT_ID = ?) d1 WHERE d1.ID = e.DEVICE_ID " +
"AND TENANT_ID = ? ORDER BY e.DATE_OF_LAST_UPDATE DESC";
stmt = conn.prepareStatement(sql);
stmt.setString(1, deviceIdentifier.getType());
@ -154,7 +154,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, d.NAME, " +
"t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, DM_DEVICE_TYPE t, DM_DEVICE_DETAIL dt " +
"WHERE t.NAME = ? AND d.DEVICE_IDENTIFICATION = ? AND d.TENANT_ID = ? AND dt.DEVICE_ID = d.ID " +
"WHERE t.NAME = ? AND t.ID = d.DEVICE_TYPE_ID AND d.DEVICE_IDENTIFICATION = ? AND d.TENANT_ID = ? AND dt.DEVICE_ID = d.ID " +
"AND dt.UPDATE_TIMESTAMP > ?) d1 WHERE d1.ID = e.DEVICE_ID AND TENANT_ID = ?" ;
stmt = conn.prepareStatement(sql);
int paramIdx = 1;
@ -189,7 +189,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, d.NAME, " +
"t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE " +
"t.NAME = ? AND d.DEVICE_IDENTIFICATION = ? AND d.TENANT_ID = ?) d1 WHERE d1.ID = e.DEVICE_ID " +
"t.NAME = ? AND t.ID = d.DEVICE_TYPE_ID AND d.DEVICE_IDENTIFICATION = ? AND d.TENANT_ID = ?) d1 WHERE d1.ID = e.DEVICE_ID " +
"AND TENANT_ID = ? AND e.STATUS = ?";
stmt = conn.prepareStatement(sql);
stmt.setString(1, deviceIdentifier.getType());
@ -223,7 +223,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, d.NAME, " +
"t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE " +
"t.NAME = ? AND d.DEVICE_IDENTIFICATION = ? ) d1 WHERE d1.ID = e.DEVICE_ID ORDER BY e.DATE_OF_LAST_UPDATE DESC";
"t.NAME = ? AND t.ID = d.DEVICE_TYPE_ID AND d.DEVICE_IDENTIFICATION = ? ) d1 WHERE d1.ID = e.DEVICE_ID ORDER BY e.DATE_OF_LAST_UPDATE DESC";
stmt = conn.prepareStatement(sql);
stmt.setString(1, deviceIdentifier.getType());
stmt.setString(2, deviceIdentifier.getId());
@ -253,7 +253,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, d.NAME, " +
"t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE " +
"d.ID = ? AND d.TENANT_ID = ?) d1 WHERE d1.ID = e.DEVICE_ID " +
"d.ID = ? AND t.ID = d.DEVICE_TYPE_ID AND d.TENANT_ID = ?) d1 WHERE d1.ID = e.DEVICE_ID " +
"AND TENANT_ID = ? ORDER BY e.DATE_OF_LAST_UPDATE DESC";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, deviceId);
@ -317,7 +317,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, " +
"d.NAME, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, " +
"DM_DEVICE_TYPE t WHERE DEVICE_TYPE_ID = t.ID AND t.NAME = ? " +
"AND d.TENANT_ID = ?) d1 WHERE d1.ID = e.DEVICE_ID AND TENANT_ID = ?";
"AND t.ID = d.DEVICE_TYPE_ID AND d.TENANT_ID = ?) d1 WHERE d1.ID = e.DEVICE_ID AND TENANT_ID = ?";
stmt = conn.prepareStatement(sql);
stmt.setString(1, type);
stmt.setInt(2, tenantId);

@ -387,7 +387,7 @@ deviceModule = function () {
var jwtClient = JWTClientManagerService.getJWTClient();
// returning access token by JWT grant type
var deviceScope = "device_" + type.replace(" ", "") + "_" + deviceId + " perm:device:enroll " +
"perm:device:disenroll perm:device:modify perm:device:operations perm:device:publish-event";
"perm:device:disenroll perm:device:modify perm:devices:operations perm:device:publish-event";
var tokenInfo = jwtClient.getAccessToken(config.clientId, config.clientSecret,
userName, deviceScope);
config.accessToken = tokenInfo.getAccessToken();

@ -51,8 +51,7 @@
<div class="wr-form">
<p class="page-sub-title">Create Device Type</p>
<hr/>
<div class="row">
<div class="col-lg-8">
<div class="">
<div class="wr-steps">
<div class="col-md-6 col-xs-6">
<div class="itm-wiz itm-wiz-current" data-step="policy-platform">
@ -70,42 +69,48 @@
</div>
<br/><br/>
<hr/>
<div id="devicetype-create-error-msg" class="alert alert-danger hidden" role="alert">
<i class="icon fw fw-error"></i><span></span>
</div>
<label class="wr-input-label">
Name * (eg: firealarm)
Name *
</label>
<br>
<input aria-describedby="basic-addon1" type="text" id="deviceTypeName"
<div class="wr-input-control">
<input placeholder="E.g firealarm" aria-describedby="basic-addon1" type="text" id="deviceTypeName"
data-error-msg="invalid device type name" class="form-control"/>
</div>
<label class="wr-input-label">
Description *
</label>
<br>
<textarea aria-describedby="basic-addon1" type="text" id="deviceTypeDescription"
<div class="wr-input-control ">
<textarea aria-describedby="basic-addon1" type="text" id="deviceTypeDescription"
data-error-msg="invalid device type description"
class="form-control" rows="3" cols="70"></textarea>
</div>
<label class="wr-input-label">Push Notification Transport</label>
<label class="wr-input-label">
Push Notification Transport
</label>
<div class="wr-input-control">
<!--suppress HtmlFormInputWithoutLabel -->
<select id="pushNotification" class="form-control select">
<option>NONE</option>
<option>MQTT</option>
</select>
</div>
<label class="wr-input-label">
<label class="wr-input-label" for="passcode-policy-min-length">
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)
<span class="helper" title="E.g name: fire alarm range control, code: alarm, description: this controls the alarm sound type and range of firealarm">
<span class="wr-help-tip glyphicon glyphicon-question-sign"></span>
</span>
</label>
<br>
<div class="form-group feature_field_wrapper">
<div class="dontfloat" name="deviceFeature">
<div class="row">
<div class="col-xs-3">
<input type="text" class="form-control" id="feature-name" placeholder="name"/>
</div>
@ -118,71 +123,70 @@
data-error-msg="invalid feature description"
class="form-control" rows="1" cols="30"></textarea>
</div>
<button type="button" class="btn btn-default add_feature_button"><i class="fa fa-plus"></i></button>
<button type="button" class="wr-btn wr-btn-horizontal add_feature_button"><i class="fa fa-plus"></i></button>
</div>
</div>
<br>
<label class="wr-input-label">
Attributes (eg: vendor, model_number ...)
<label class="wr-input-label" for="passcode-policy-min-length">
Attributes
<span class="helper" title="E.g vendor, model_number ...">
<span class="wr-help-tip glyphicon glyphicon-question-sign"></span>
</span>
</label>
<br>
<div class="form-group attribute_field_wrapper">
<div class="dontfloat">
<div class="col-xs-3">
<input type="text" class="form-control" name="attribute[]" />
<div class="row">
<div class="dontfloat">
<div class="col-xs-3">
<input type="text" class="form-control" name="attribute[]" />
</div>
<button type="button" class="wr-btn wr-btn-horizontal add_button"><i class="fa fa-plus"></i></button>
</div>
<button type="button" class="btn btn-default add_button"><i class="fa fa-plus"></i></button>
</div>
</div>
<div class="hidden-div">
<div id="add-attribute-field" name="add-attribute-field">
<div class="dontfloat">
<div class="col-xs-3">
<input type="text" class="form-control" name="attribute[]" />
<div class="row">
<div class="dontfloat feature-wrapper">
<div class="col-xs-3">
<input type="text" class="form-control" name="attribute[]" />
</div>
<button type="button" class="wr-btn wr-btn-horizontal wr-btn-secondary remove_button"><i class="fa fa-minus"></i></button>
</div>
<button type="button" class="btn btn-default remove_button"><i class="fa fa-minus"></i></button>
</div>
</div>
</div>
<label class="wr-input-label">
Enrolment Operation (Triggers the operation after the enrolment, eg: alarm)
<label class="wr-input-label" for="passcode-policy-min-length">
Enrolment Operation
<span class="helper" title="Triggers the operation after the enrolment, E.g alarm">
<span class="wr-help-tip glyphicon glyphicon-question-sign"></span>
</span>
</label>
<br>
<div class="form-group operation_field_wrapper">
<div class="dontfloat">
<div class="col-xs-3">
<input type="text" class="form-control" name="operation[]" />
<div class="row">
<div class="dontfloat">
<div class="col-xs-3">
<input type="text" class="form-control" name="operation[]" />
</div>
<button type="button" class="wr-btn wr-btn-horizontal add_operation_button"><i class="fa fa-plus"></i></button>
</div>
<button type="button" class="btn btn-default add_operation_button"><i class="fa fa-plus"></i></button>
</div>
</div>
<div class="hidden-div">
<div id="add-operation-field" name="add-operation-field">
<div class="dontfloat">
<div class="col-xs-3">
<input type="text" class="form-control" name="operation[]" />
<div class="row">
<div class="dontfloat feature-wrapper">
<div class="col-xs-3">
<input type="text" class="form-control" name="operation[]" />
</div>
<button type="button" class="wr-btn wr-btn-horizontal wr-btn-secondary remove_operation_button"><i class="fa fa-minus"></i></button>
</div>
<button type="button" class="btn btn-default remove_operation_button"><i class="fa fa-minus"></i></button>
</div>
</div>
</div>
<label class="wr-input-label">Claimable</label>
<input aria-describedby="basic-addon1" type="checkbox" id="deviceClaimable"/>
</br>
<label class="wr-input-label">Policy Monitoring</label>
<input aria-describedby="basic-addon1" type="checkbox" id="policyMonitoring"/>
</br>
<span class="roleNameError hidden glyphicon glyphicon-remove form-control-feedback"></span>
<label class="error roleNameEmpty hidden" for="summary">
Device Type Name is required, should be in minimum 3 characters long and not include any
@ -191,7 +195,6 @@
</div>
</div>
<br>
<button id="add-devicetype-btn" class="wr-btn">Add Device Type</button>
</div>

@ -1,4 +1,6 @@
.wr-btn-horizontal{
padding: 7px 10px;
}
.dontfloat {
clear:both;
@ -8,3 +10,10 @@
display: none;
}
.feature-wrapper{
margin-top: 10px;
}
.wr-btn-secondary{
background-color: #617d8b;
}

@ -97,6 +97,7 @@ function formatRepoSelection(user) {
$(document).ready(function () {
$('[data-toggle="tooltip"]').tooltip();
var appContext = $("#app-context").data("app-context");
var maxField = 100; //Input fields increment limitation
@ -126,13 +127,13 @@ $(document).ready(function () {
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 = ' <div class="dontfloat" name ="deviceFeature"> <div class="col-xs-3"> <input type="text"' +
var featureFieldHtml = '<div class="row"><div class="dontfloat feature-wrapper" name ="deviceFeature"> <div class="col-xs-3"> <input type="text"' +
' class="form-control" id="feature-name" placeholder="name"/> </div> <div class="col-xs-4"> ' +
'<input type="text" class="form-control" id="feature-code" placeholder="code"/> </div> ' +
'<div class="col-xs-4"> <textarea aria-describedby="basic-addon1" type="text" ' +
'id="feature-description" placeholder="description"data-error-msg="invalid ' +
'feature description"class="form-control" rows="1" cols="30"></textarea> </div> ' +
'<button type="button" class="btn btn-default remove_feature_button"><i class="fa fa-minus"></i></button> </div>'
'<button type="button" class="wr-btn wr-btn-horizontal wr-btn-secondary remove_feature_button"><i class="fa fa-minus"></i></button> </div></div>'
$(featureWrapper).append(featureFieldHtml); // Add field html
});
$(featureWrapper).on('click', '.remove_feature_button', function(e){ //Once remove button is clicked
@ -195,9 +196,6 @@ $(document).ready(function () {
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();

@ -60,31 +60,32 @@
<input aria-describedby="basic-addon1" type="text" id="deviceTypeName"
data-error-msg="invalid device type name" class="form-control hidden-input" value="{{name}}"/>
<label class="wr-input-label">
<div class="wr-input-control">
<label class="wr-input-label">
Description *
</label>
<br>
<textarea aria-describedby="basic-addon1" type="text" id="deviceTypeDescription"
data-error-msg="invalid device type description"
class="form-control" rows="3" cols="70">{{type.deviceTypeMetaDefinition.description}}</textarea>
</label>
<br>
<textarea aria-describedby="basic-addon1" type="text" id="deviceTypeDescription"
data-error-msg="invalid device type description"
class="form-control" rows="3" cols="70">{{type.deviceTypeMetaDefinition.description}}</textarea>
</div>
<label class="wr-input-label">Push Notification Transport</label>
<div class="wr-input-control">
<!--suppress HtmlFormInputWithoutLabel -->
<select id="pushNotification" class="form-control select">
{{#if type.deviceTypeMetaDefinition.pushNotificationConfig}}
<option>NONE</option>
{{#if_eq type.deviceTypeMetaDefinition.pushNotificationConfig.type "MQTT"}}
<option selected>MQTT</option>
{{/if_eq}}
{{else}}
<option selected>NONE</option>
<option>MQTT</option>
{{/if}}
</select>
<label class="wr-input-label">Push Notification Transport</label>
<div class="wr-input-control">
<!--suppress HtmlFormInputWithoutLabel -->
<select id="pushNotification" class="form-control select">
{{#if type.deviceTypeMetaDefinition.pushNotificationConfig}}
<option>NONE</option>
{{#if_eq type.deviceTypeMetaDefinition.pushNotificationConfig.type "MQTT"}}
<option selected>MQTT</option>
{{/if_eq}}
{{else}}
<option selected>NONE</option>
<option>MQTT</option>
{{/if}}
</select>
</div>
</div>
<label class="wr-input-label">
@ -94,7 +95,8 @@
<div class="form-group feature_field_wrapper">
{{#if type.deviceTypeMetaDefinition.features}}
{{#each type.deviceTypeMetaDefinition.features}}
<div class="dontfloat" name ="deviceFeature">
<div class="row">
<div class="dontfloat feature-wrapper" name ="deviceFeature">
<div class="col-xs-3">
<input type="text" class="form-control" id="feature-name" placeholder="name" value="{{this.name}}"/>
</div>
@ -105,24 +107,27 @@
<textarea aria-describedby="basic-addon1" type="text" id="feature-description"
placeholder="description" data-error-msg="invalid feature description" class="form-control" rows="1" cols="30">{{this.description}}</textarea>
</div>
<button type="button" class="btn btn-default remove_feature_button"><i class="fa fa-minus"></i></button>
<button type="button" class="wr-btn wr-btn-horizontal remove_feature_button"><i class="fa fa-minus"></i></button>
</div>
</div>
{{/each}}
{{/if}}
<div class="dontfloat" name="deviceFeature">
<div class="col-xs-3">
<input type="text" class="form-control" id="feature-name" placeholder="name"/>
</div>
<div class="col-xs-4">
<input type="text" class="form-control" id="feature-code" placeholder="code"/>
</div>
<div class="col-xs-4">
<textarea aria-describedby="basic-addon1" type="text" id="feature-description"
placeholder="description"
data-error-msg="invalid feature description"
class="form-control" rows="1" cols="30"></textarea>
<div class="row">
<div class="dontfloat feature-wrapper" name="deviceFeature">
<div class="col-xs-3">
<input type="text" class="form-control" id="feature-name" placeholder="name"/>
</div>
<div class="col-xs-4">
<input type="text" class="form-control" id="feature-code" placeholder="code"/>
</div>
<div class="col-xs-4">
<textarea aria-describedby="basic-addon1" type="text" id="feature-description"
placeholder="description"
data-error-msg="invalid feature description"
class="form-control" rows="1" cols="30"></textarea>
</div>
<button type="button" class="wr-btn wr-btn-horizontal add_feature_button"><i class="fa fa-plus"></i></button>
</div>
<button type="button" class="btn btn-default add_feature_button"><i class="fa fa-plus"></i></button>
</div>
</div>
@ -134,28 +139,34 @@
<div class="form-group attribute_field_wrapper">
{{#if type.deviceTypeMetaDefinition.properties}}
{{#each type.deviceTypeMetaDefinition.properties}}
<div class="row">
<div class="dontfloat">
<div class="col-xs-3">
<input type="text" class="form-control" name="attribute[]" value="{{this}}" />
</div>
<button type="button" class="btn btn-default remove_button"><i class="fa fa-minus"></i></button>
<button type="button" class="wr-btn wr-btn-horizontal wr-btn-secondary remove_button"><i class="fa fa-minus"></i></button>
</div>
</div>
{{/each}}
{{/if}}
<div class="dontfloat">
<div class="col-xs-3">
<input type="text" class="form-control" name="attribute[]" />
<div class="row">
<div class="dontfloat feature-wrapper">
<div class="col-xs-3">
<input type="text" class="form-control" name="attribute[]" />
</div>
<button type="button" class="wr-btn wr-btn-horizontal add_button"><i class="fa fa-plus"></i></button>
</div>
<button type="button" class="btn btn-default add_button"><i class="fa fa-plus"></i></button>
</div>
</div>
<div class="hidden-div">
<div id="add-attribute-field" name="add-attribute-field">
<div class="dontfloat">
<div class="col-xs-3">
<input type="text" class="form-control" name="attribute[]" />
<div class="row">
<div class="dontfloat feature-wrapper">
<div class="col-xs-3">
<input type="text" class="form-control" name="attribute[]" />
</div>
<button type="button" class="wr-btn wr-btn-horizontal wr-btn-secondary remove_button"><i class="fa fa-minus"></i></button>
</div>
<button type="button" class="btn btn-default remove_button"><i class="fa fa-minus"></i></button>
</div>
</div>
</div>
@ -168,49 +179,38 @@
<div class="form-group operation_field_wrapper">
{{#if type.deviceTypeMetaDefinition.initialOperationConfig}}
{{#each type.deviceTypeMetaDefinition.initialOperationConfig.operations}}
<div class="dontfloat">
<div class="row">
<div class="dontfloat feature-wrapper">
<div class="col-xs-3">
<input type="text" class="form-control" name="operation[]" value="{{this}}"/>
</div>
<button type="button" class="btn btn-default remove_operation_button"><i class="fa fa-minus"></i></button>
<button type="button" class="wr-btn wr-btn-horizontal wr-btn-secondary remove_operation_button"><i class="fa fa-minus"></i></button>
</div>
</div>
{{/each}}
{{/if}}
<div class="dontfloat">
<div class="col-xs-3">
<input type="text" class="form-control" name="operation[]" />
<div class="row">
<div class="dontfloat feature-wrapper">
<div class="col-xs-3">
<input type="text" class="form-control" name="operation[]" />
</div>
<button type="button" class="wr-btn wr-btn-horizontal add_operation_button"><i class="fa fa-plus"></i></button>
</div>
<button type="button" class="btn btn-default add_operation_button"><i class="fa fa-plus"></i></button>
</div>
</div>
<div class="hidden-div">
<div id="add-operation-field" name="add-operation-field">
<div class="dontfloat">
<div class="col-xs-3">
<input type="text" class="form-control" name="operation[]" />
<div class="row">
<div class="dontfloat feature-wrapper">
<div class="col-xs-3">
<input type="text" class="form-control" name="operation[]" />
</div>
<button type="button" class="wr-btn wr-btn-horizontal wr-btn-secondary remove_operation_button"><i class="fa fa-minus"></i></button>
</div>
<button type="button" class="btn btn-default remove_operation_button"><i class="fa fa-minus"></i></button>
</div>
</div>
</div>
<label class="wr-input-label">Claimable</label>
<input aria-describedby="basic-addon1" type="checkbox" id="deviceClaimable"
{{#if type.deviceTypeMetaDefinition.claimable}}
checked
{{/if}}/>
</br>
<label class="wr-input-label">Policy Monitoring</label>
<input aria-describedby="basic-addon1" type="checkbox" id="policyMonitoring"
{{#if type.deviceTypeMetaDefinition.policyMonitoringEnabled}}
checked
{{/if}}/>
</br>
<span class="roleNameError hidden glyphicon glyphicon-remove form-control-feedback"></span>
<label class="error roleNameEmpty hidden" for="summary">
Device Type Name is required, should be in minimum 3 characters long and not include any

@ -1,4 +1,6 @@
.wr-btn-horizontal{
padding: 7px 10px;
}
.dontfloat {
clear:both;
@ -11,3 +13,13 @@
.hidden-input {
display: none;
}
.feature-wrapper{
margin-top: 10px;
}
.wr-btn-secondary{
background-color: #617d8b;
}
.wr-btn-secondary{
background-color: #617d8b;
}

@ -123,13 +123,13 @@ $(document).ready(function () {
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 = ' <div class="dontfloat" name ="deviceFeature"> <div class="col-xs-3"> <input type="text"' +
var featureFieldHtml = '<div class="row"><div class="dontfloat feature-wrapper" name ="deviceFeature"> <div class="col-xs-3"> <input type="text"' +
' class="form-control" id="feature-name" placeholder="name"/> </div> <div class="col-xs-4"> ' +
'<input type="text" class="form-control" id="feature-code" placeholder="code"/> </div> ' +
'<div class="col-xs-4"> <textarea aria-describedby="basic-addon1" type="text" ' +
'id="feature-description" placeholder="description"data-error-msg="invalid ' +
'feature description"class="form-control" rows="1" cols="30"></textarea> </div> ' +
'<button type="button" class="btn btn-default remove_feature_button"><i class="fa fa-minus"></i></button> </div>'
'<button type="button" class="wr-btn wr-btn-horizontal wr-btn-secondary remove_feature_button"><i class="fa fa-minus"></i></button> </div></div>'
$(featureWrapper).append(featureFieldHtml); // Add field html
});
@ -196,9 +196,6 @@ $(document).ready(function () {
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();

@ -65,11 +65,11 @@
<!--suppress HtmlFormInputWithoutLabel -->
<select id="transport" class="form-control select">
{{#if event}}
<option {{selected event.transport "MQTT"}}>MQTT</option>
<option {{selected event.transport "HTTP"}}>HTTP</option>
<option {{selected event.transport "MQTT"}}>MQTT</option>
{{else}}
<option>MQTT</option>
<option>HTTP</option>
<option>MQTT</option>
{{/if}}
</select>
@ -82,39 +82,43 @@
<div class="form-group event_field_wrapper">
{{#if event.eventAttributes}}
{{#each event.eventAttributes.attributes}}
<div class="dontfloat" name="deviceEvent">
<div class="col-xs-3">
<input type="text" class="form-control" id="event-name" placeholder="name" value="{{this.name}}"/>
<div class="row">
<div class="dontfloat" name="deviceEvent">
<div class="col-xs-3">
<input type="text" class="form-control" id="event-name" placeholder="name" value="{{this.name}}"/>
</div>
<div class="col-xs-4">
<select class="form-control select" id="event-type">
<option {{selected this.type "STRING"}}>STRING</option>
<option {{selected this.type "LONG"}}>LONG</option>
<option {{selected this.type "BOOL"}}>BOOL</option>
<option {{selected this.type "INT"}}>INT</option>
<option {{selected this.type "FLOAT"}}>FLOAT</option>
<option {{selected this.type "DOUBLE"}}>DOUBLE</option>
</select>
</div>
<button type="button" class="wr-btn wr-btn-horizontal remove_event_button"><i class="fa fa-minus"></i></button>
</div>
<div class="col-xs-4">
<select class="form-control select" id="event-type">
<option {{selected this.type "STRING"}}>STRING</option>
<option {{selected this.type "LONG"}}>LONG</option>
<option {{selected this.type "BOOL"}}>BOOL</option>
<option {{selected this.type "INT"}}>INT</option>
<option {{selected this.type "FLOAT"}}>FLOAT</option>
<option {{selected this.type "DOUBLE"}}>DOUBLE</option>
</select>
</div>
<button type="button" class="btn btn-default remove_event_button"><i class="fa fa-minus"></i></button>
</div>
{{/each}}
{{/if}}
<div class="dontfloat" name="deviceEvent">
<div class="col-xs-3">
<input type="text" class="form-control" id="event-name" placeholder="name"/>
</div>
<div class="col-xs-4">
<select class="form-control select" id="event-type">
<option>STRING</option>
<option>LONG</option>
<option>BOOL</option>
<option>INT</option>
<option>FLOAT</option>
<option>DOUBLE</option>
</select>
<div class="row">
<div class="dontfloat event-wrapper" name="deviceEvent">
<div class="col-xs-3">
<input type="text" class="form-control" id="event-name" placeholder="name"/>
</div>
<div class="col-xs-4">
<select class="form-control select" id="event-type">
<option>STRING</option>
<option>LONG</option>
<option>BOOL</option>
<option>INT</option>
<option>FLOAT</option>
<option>DOUBLE</option>
</select>
</div>
<button type="button" class="wr-btn wr-btn-horizontal add_event_button"><i class="fa fa-plus"></i></button>
</div>
<button type="button" class="btn btn-default add_event_button"><i class="fa fa-plus"></i></button>
</div>
</div>

@ -11,3 +11,19 @@
.hidden-input {
display: none;
}
.event-wrapper{
margin-top: 10px;
}
.wr-btn-horizontal{
padding: 7px 10px;
}
.wr-btn-secondary{
background-color: #617d8b;
}
.page-content-wrapper{
height: calc(100vh - 50px);
}

@ -101,12 +101,12 @@ $(document).ready(function () {
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 = ' <div class="dontfloat" name="deviceEvent"> ' +
var eventFieldHtml = '<div class="row"><div class="dontfloat event-wrapper" name="deviceEvent"> ' +
'<div class="col-xs-3"> <input type="text" class="form-control" id="event-name" placeholder="name"/> ' +
'</div> <div class="col-xs-4"> <select class="form-control select" id="event-type"> ' +
'<option>STRING</option> <option>LONG</option> <option>BOOL</option> <option>INT</option> <option>FLOAT</option> ' +
'<option>DOUBLE</option> </select> </div> ' +
'<button type="button" class="btn btn-default remove_event_button"><i class="fa fa-minus"></i></button> </div>'
'<button type="button" class="wr-btn wr-btn-horizontal wr-btn-secondary remove_event_button"><i class="fa fa-minus"></i></button> </div></div>'
$(eventWrapper).append(eventFieldHtml); // Add field html
});

@ -20,6 +20,17 @@
.thumbnail.icon:before {
padding-top: 0;
}
.code-segment{
margin-bottom: 10px;
}
.code-segment span{
display: block;
}
.code-segment code{
padding: 10px;
display: block;
background-color: #f3f3f3;
}
</style>
{{/zone}}
@ -91,4 +102,87 @@
</div>
</div>
{{/if}}
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 padding-double grey-bg">
<h2 class="uppercase">Device Communication</h2>
<hr>
{{#if event}}
<h3 class="uppercase">publish device events :</h3>
{{#if_eq event.transport "MQTT"}}
<div class="code-segment">
<span>MQTT Topic :</span>
<code>{{tenantDomain}}/{{device.type}}/&lt;device_id&gt;/events</code>
</div>
{{#if eventSample}}
<div class="code-segment">
<span>Device Event Payload :</span>
<code>{{eventSample}}</code>
</div>
{{/if}}
{{/if_eq}}
{{#if_eq event.transport "HTTP"}}
<div class="code-segment">
<code> curl -k -X POST {{httpsGateway}}/api/device-mgt/v1.0/device/agent/events/publish/{{device.type}}/{{device.deviceIdentifier}}
-H 'authorization: Bearer %accessToken%'
-H 'content-type: application/json'
-d '{{eventSample}}'
</code>
</div>
{{/if_eq}}
{{/if}}
</br>
<h3 class="uppercase">Retrieve operations</h3>
{{#if type.deviceTypeMetaDefinition.pushNotificationConfig}}
{{#if_eq type.deviceTypeMetaDefinition.pushNotificationConfig.type "MQTT"}}
MQTT - {{mqttGateway}}
<div class="code-segment">
<span>MQTT Topic :</span>
<code>{{tenantDomain}}/{{device.type}}/{{device.deviceIdentifier}}/operation/#</code>
</div>
<div class="code-segment">
<span>Operation Response :</span>
<code>{{tenantDomain}}/{{device.type}}/{{device.deviceIdentifier}}/update/operation</code>
</div>
<div class="code-segment">
<span>Payload :</span>
<code>{"id": 1,"status": "COMPLETED", "operationResponse": "this is my response"}</code>
</div>
<br/>
Topic Structure:
<ul class="list-unstyled">
<li class="padding-top-double">
<code>{{tenantDomain}}/{{device.type}}/{{device.deviceIdentifier}}/operation/command/&lt;feature_code&gt;/&lt;operation_id&gt;</code>
</li>
<li class="padding-top-double">
<code>{{tenantDomain}}/{{device.type}}/{{device.deviceIdentifier}}/operation/config/&lt;feature_code&gt;/&lt;operation_id&gt;</code>
</li>
<li class="padding-top-double">
<code>{{tenantDomain}}/{{device.type}}/{{device.deviceIdentifier}}/operation/profile/&lt;feature_code&gt;/&lt;operation_id&gt;</code>
</li>
<li class="padding-top-double">
<code>{{tenantDomain}}/{{device.type}}/{{device.deviceIdentifier}}/operation/policy/policy_bundle</code>
</li>
<li class="padding-top-double">
<code>{{tenantDomain}}/{{device.type}}/{{device.deviceIdentifier}}/operation/policy/policy_revoke</code>
</li>
</ul>
{{/if_eq}}
{{else}}
<div class="code-segment">
<span>Retrieve pending operation :</span>
<code>curl -k -X GET {{httpsGateway}}/api/device-mgt/v1.0/device/agent/pending/operations/{{device.type}}/{{device.deviceIdentifier}} -H 'authorization: Bearer %accessToken%' -H 'content-type: application/json'</code>
</div>
<div class="code-segment">
<span>Retrieve next pending operation :</span>
<code>curl -k -X GET {{httpsGateway}}/api/device-mgt/v1.0/device/agent/next-pending/ -H 'authorization: Bearer %accessToken%' -H 'content-type: application/json'</code>
</div>
<div class="code-segment">
<span>Update operation :</span>
<code>curl -k -X PUT {{httpsGateway}}/api/device-mgt/v1.0/device/agent/operations/{{device.type}}/{{device.deviceIdentifier}} -H 'authorization: Bearer %accessToken%' -H 'content-type: application/json' -d '{"id": 1,"status": "COMPLETED", "payload": "this is my response"}'</code>
</div>
{{/if}}
<br>
<br>
</div>
{{/zone}}

@ -17,6 +17,7 @@
*/
var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"];
var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"];
var process = require("process");
function onRequest(context) {
var log = new Log("device-view.js");
@ -65,17 +66,82 @@ function onRequest(context) {
var autoCompleteParams = [
{"name" : "deviceId", "value" : deviceId}
];
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 displayData = {};
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;
var sampleValue = "";
if (typeData.eventAttributes && typeData.eventAttributes.attributes) {
var eventExample = {};
for (var i = 0; i < typeData.eventAttributes.attributes.length; i++) {
var attribute = typeData.eventAttributes.attributes[i];
switch (attribute.type) {
case "STRING":
eventExample[attribute.name] = "string";
sampleValue = sampleValue + "\"string\", ";
break;
case "LONG":
eventExample[attribute.name] = 0;
sampleValue = sampleValue + 0 +", ";
break;
case "INT":
eventExample[attribute.name] = 0;
sampleValue = sampleValue + 0 +", ";
break;
case "FLOAT":
eventExample[attribute.name] = 0.0;
sampleValue = sampleValue + 0.0 +", ";
break;
case "DOUBLE":
eventExample[attribute.name] = 0.0;
sampleValue = sampleValue + 0.0 +", ";
break;
case "BOOL":
eventExample[attribute.name] = false;
sampleValue = sampleValue + false + ", ";
break;
}
}
var sample = eventExample;
if (sampleValue && sampleValue.length > 2) {
displayData.sampleValue = sampleValue.substring(0, sampleValue.length - 2);
}
displayData.eventSample = JSON.stringify(sample);
displayData.mqttGateway = "tcp://" + process.getProperty("mqtt.broker.host") + ":" + process.getProperty("mqtt.broker.port");
displayData.httpsGateway = "https://" + process.getProperty("iot.gateway.host") + ":" + process.getProperty("iot.gateway.https.port");
}
}
}
);
if (deviceType != null && deviceType != undefined && deviceId != null && deviceId != undefined) {
var deviceModule = require("/app/modules/business-controllers/device.js")["deviceModule"];
var device = deviceModule.viewDevice(deviceType, deviceId);
if (device && device.status != "error") {
displayData.device = device.content;
displayData.autoCompleteParams = autoCompleteParams;
displayData.encodedFeaturePayloads = "";
displayData.features = featureList;
if (attributes.length === 0 || attributes.length === undefined) {
return {"device": device.content, "autoCompleteParams" : autoCompleteParams
, "encodedFeaturePayloads": "", "features":featureList};
return displayData;
} else {
return {"device": device.content, "autoCompleteParams" : autoCompleteParams
, "encodedFeaturePayloads": "", "attributes": attributes, "features":featureList};
displayData.attributes = attributes;
return displayData;
}
} else {
response.sendError(404, "Device Id " + deviceId + " of type " + deviceType + " cannot be found!");

@ -78,6 +78,13 @@ function onRequest(context) {
event.value = record["" + attributes[eventAttribute]];
events.push(event);
}
} else {
for (var eventAttribute in attributes){
var event = {};
event.key = attributes[eventAttribute];
event.value = "-";
events.push(event);
}
}
}

@ -4,7 +4,7 @@
<hr>
</div>
<div class="col-xs-12 col-sm-4 col-md-4 col-lg-4 padding-top">
<div class="col-xs-12 col-sm-4 col-md-4 col-lg-3 padding-top add-margin-bottom-5x">
<img src="{{@unit.publicUri}}/images/deviceType.png" class="img-responsive">
</div>
@ -18,6 +18,9 @@
<br>
<hr>
<br>
<a href="#create"
class="btn-operations"><i class="fw fw-add add-margin-1x"></i> Create Device</i>
</a>
<a href="/api-store/apis/info?name=DeviceAgent Service&version=1.0.0&provider=admin"
class="btn-operations"
target="_blank"><i class="fw fw-api add-margin-1x"></i> View API</i>
@ -111,17 +114,17 @@
<h2 class="uppercase">How To Enroll a Device</h2>
<hr>
<ul class="list-unstyled">
<li class="padding-top-double"><span><h3 class="uppercase">Generate Application</h3></span>
<li class="padding-top-double"><span><h4 class="uppercase">Generate Application</h4></span>
<code>curl -k -X POST {{httpsGateway}}/api-application-registration/register -H
'authorization: Basic Base64(username:password)' -H 'content-type: application/json'
-d '{ "applicationName":"testme", "isAllowedToAllDomains":false, "tags":["device_agent"]}'</code>
</li>
<li class="padding-top-double"><span><h3 class="uppercase">Generate Token</h3></span>
<li class="padding-top-double"><span><h4 class="uppercase">Generate Token</h4></span>
<code>curl -k -d "grant_type=password&username=%username%&password=%password%&scope=perm:device:enroll perm:device:disenroll perm:device:modify perm:device:operations perm:device:publish-event"
-H "Authorization: Basic Base64(client_id:client_secret)"
-H "Content-Type: application/x-www-form-urlencoded" {{httpsGateway}}/token</code>
</li>
<li class="padding-top-double"><span><h3 class="uppercase">Create Device</h3></span>
<li class="padding-top-double"><span><h4 class="uppercase">Create Device</h4></span>
<code>curl -X POST {{httpsGateway}}/api/device-mgt/v1.0/device/agent/enroll -H 'accept: application/json'
-H 'authorization: Bearer %accessToken%'
-H 'content-type: application/json' -d '{ "name": "devicename", "type": "{{deviceType}}",
@ -135,10 +138,10 @@
</div>
<hr/>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 padding-double grey-bg">
<div id="create" 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 id="device-create-form" class=" wr-content">
<div class="wr-form">
<div class="row">
<div class="col-lg-8">
@ -210,80 +213,6 @@
<br>
</div>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 padding-double grey-bg">
<h2 class="uppercase">Device Communication</h2>
<hr>
{{#if event}}
<h3 class="uppercase">publish device events :</h3>
{{#if_eq event.transport "MQTT"}}
MQTT Topic : <code>{{tenantDomain}}/{{deviceType}}/&lt;device_id&gt;/events</code>
{{#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_eq}}
{{#if_eq event.transport "HTTP"}}
<code> curl -k -X POST {{httpsGateway}}/api/device-mgt/v1.0/device/agent/events/publish/{{deviceType}}/%deviceId%
-H 'authorization: Bearer %accessToken%'
-H 'content-type: application/json'
-d '{{eventSample}}'
</code>
{{/if_eq}}
{{/if}}
</br>
<h3 class="uppercase">Retrieve operations</h3>
{{#if type.deviceTypeMetaDefinition.pushNotificationConfig}}
{{#if_eq type.deviceTypeMetaDefinition.pushNotificationConfig.type "MQTT"}}
MQTT - {{mqttGateway}}
MQTT Topic : <code>{{tenantDomain}}/{{deviceType}}/&lt;device_id&gt;/operation/#</code>
<br/>
Operation Response:
<code>{{tenantDomain}}/{{deviceType}}/&lt;device_id&gt;/update/operation</code>
<br/>
Payload : <code>{"id": 1,"status": "COMPLETED", "operationResponse": "this is my response"}</code>
<br/>
Topic Structure:
<ul class="list-unstyled">
<li class="padding-top-double">
<code>{{tenantDomain}}/{{deviceType}}/&lt;device_id&gt;/operation/command/&lt;feature_code&gt;/&lt;operation_id&gt;</code>
</li>
<li class="padding-top-double">
<code>{{tenantDomain}}/{{deviceType}}/&lt;device_id&gt;/operation/config/&lt;feature_code&gt;/&lt;operation_id&gt;</code>
</li>
<li class="padding-top-double">
<code>{{tenantDomain}}/{{deviceType}}/&lt;device_id&gt;/operation/profile/&lt;feature_code&gt;/&lt;operation_id&gt;</code>
</li>
<li class="padding-top-double">
<code>{{tenantDomain}}/{{deviceType}}/&lt;device_id&gt;/operation/policy/policy_bundle</code>
</li>
<li class="padding-top-double">
<code>{{tenantDomain}}/{{deviceType}}/&lt;device_id&gt;/operation/policy/policy_revoke</code>
</li>
</ul>
{{/if_eq}}
{{else}}
Retrieve pending operation:
<code>curl -k -X GET {{httpsGateway}}/api/device-mgt/v1.0/device/agent/pending/operations/{{deviceType}}/deviceId
-H 'authorization: Bearer %accessToken%' -H 'content-type: application/json'</code>
</br>
Retrieve next pending operation:
<code>curl -k -X GET {{httpsGateway}}/api/device-mgt/v1.0/device/agent/next-pending/operations/{{deviceType}}/deviceId
-H 'authorization: Bearer %accessToken%' -H 'content-type: application/json'</code>
</br>
<code>curl -k -X PUT {{httpsGateway}}/api/device-mgt/v1.0/device/agent/operations/{{deviceType}}/deviceId
-H 'authorization: Bearer %accessToken%' -H 'content-type: application/json' -d '{"id": 1,"status": "COMPLETED", "payload": "this is my response"}'</code>
{{/if}}
<br>
<br>
</div>
{{#zone "topCss"}}
{{css "css/styles.css"}}
{{/zone}}

Loading…
Cancel
Save