Merge pull request #299 from ayyoob/transport

added configuration ui for device types to load through base ui
revert-dabc3590
Ruwan 9 years ago committed by GitHub
commit 4bef868624

@ -28,6 +28,7 @@ import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException; import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException;
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants;
import org.wso2.carbon.device.mgt.iot.androidsense.plugin.mqtt.MqttConfig; import org.wso2.carbon.device.mgt.iot.androidsense.plugin.mqtt.MqttConfig;
import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util.APIUtil; import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util.APIUtil;
@ -216,11 +217,7 @@ public class AndroidSenseServiceImpl implements AndroidSenseService {
if (APIUtil.getDeviceManagementService().isEnrolled(deviceIdentifier)) { if (APIUtil.getDeviceManagementService().isEnrolled(deviceIdentifier)) {
AndroidConfiguration androidConfiguration = new AndroidConfiguration(); AndroidConfiguration androidConfiguration = new AndroidConfiguration();
androidConfiguration.setTenantDomain(APIUtil.getAuthenticatedUserTenantDomain()); androidConfiguration.setTenantDomain(APIUtil.getAuthenticatedUserTenantDomain());
String mqttEndpoint = MqttConfig.getInstance().getBrokerEndpoint(); androidConfiguration.setMqttEndpoint(APIUtil.getMqttEndpoint());
if (mqttEndpoint.contains(Constants.LOCALHOST)) {
mqttEndpoint = mqttEndpoint.replace(Constants.LOCALHOST, Utils.getServerUrl());
}
androidConfiguration.setMqttEndpoint(mqttEndpoint);
return Response.status(Response.Status.ACCEPTED.getStatusCode()).entity(androidConfiguration.toString()) return Response.status(Response.Status.ACCEPTED.getStatusCode()).entity(androidConfiguration.toString())
.build(); .build();
} }
@ -251,6 +248,9 @@ public class AndroidSenseServiceImpl implements AndroidSenseService {
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
log.error(e.getErrorMessage(), e); log.error(e.getErrorMessage(), e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).entity(false).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).entity(false).build();
} catch (ConfigurationManagementException e) {
log.error(e.getErrorMessage(), e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).entity(false).build();
} }
} }

@ -13,9 +13,15 @@ import org.wso2.carbon.apimgt.application.extension.APIManagementProviderService
import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService; import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService;
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry;
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException;
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfigurationManagementService;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.iot.util.Utils;
import org.wso2.carbon.event.output.adapter.core.OutputEventAdapterService; import org.wso2.carbon.event.output.adapter.core.OutputEventAdapterService;
import org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerService; import org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerService;
import org.wso2.carbon.utils.CarbonUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -185,4 +191,34 @@ public class APIUtil {
return threadLocalCarbonContext.getTenantDomain(); return threadLocalCarbonContext.getTenantDomain();
} }
public static PlatformConfigurationManagementService getTenantConfigurationManagementService() {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
PlatformConfigurationManagementService tenantConfigurationManagementService =
(PlatformConfigurationManagementService) ctx.getOSGiService(PlatformConfigurationManagementService.class, null);
if (tenantConfigurationManagementService == null) {
String msg = "Tenant configuration Management service not initialized.";
log.error(msg);
throw new IllegalStateException(msg);
}
return tenantConfigurationManagementService;
}
public static String getMqttEndpoint() throws ConfigurationManagementException {
String iotServerIP = Constants.DEFAULT_ENDPOINT;
iotServerIP = iotServerIP.replace(Constants.LOCALHOST, Utils.getServerUrl());;
PlatformConfiguration configuration = APIUtil.getTenantConfigurationManagementService().getConfiguration(
Constants.CONFIG_TYPE);
if (configuration != null && configuration.getConfiguration() != null && configuration
.getConfiguration().size() > 0) {
List<ConfigurationEntry> configurations = configuration.getConfiguration();
for (ConfigurationEntry configurationEntry : configurations) {
switch (configurationEntry.getName()) {
case "ANDROID_SENSE_MQTT_EP":
iotServerIP = (String)configurationEntry.getValue();
break;
}
}
}
return iotServerIP;
}
} }

@ -25,4 +25,6 @@ import org.wso2.carbon.user.core.Permission;
*/ */
public class Constants { public class Constants {
public static final String LOCALHOST = "localhost"; public static final String LOCALHOST = "localhost";
public static final String CONFIG_TYPE = "general";
public static final String DEFAULT_ENDPOINT = "tcp://localhost:1883";
} }

@ -0,0 +1,51 @@
{{!
Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
WSO2 Inc. licenses this file to you under the Apache License,
Version 2.0 (the "License"); you may not use this file except
in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
}}
<div class="panel panel-default">
<div id="general-config-heading" class="panel-heading" role="tab">
<h2 class="sub-title panel-title">
Android Sense Endpoint Configuration
</h2>
</div>
<div id="android_sense-config-body" class="panel-collapse panel-body"
role="tabpanel">
<div id="android_sense-config-error-msg"
class="alert alert-danger hidden" role="alert">
<i class="icon fw fw-error"></i><span></span>
</div>
<div class="wr-input-control">
<label class="wr-input-label" for="email-config-host">
Mqtt Endpoint
<span class="helper" title="SMTP Server Host">
<span class="wr-help-tip glyphicon glyphicon-question-sign"></span>
</span>
<br>
</label>
<input id="mqtt-endpoint" type="text" class="form-control"
placeholder="[ Required Field ]">
<br>
</div>
<div class="wr-input-control wr-btn-grp">
<button id="save-general-btn" class="wr-btn" onclick="addConfiguration();">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Save&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</button>
</div>
</div>
</div>
{{#zone "bottomJs"}}
{{js "js/platform-configuration.js"}}
{{/zone}}

@ -0,0 +1,97 @@
/*
* 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.
*/
$(document).ready(function () {
invokerUtil.get(
"/devicemgt_admin/configuration",
function (data) {
data = JSON.parse(data);
if (data && data.configuration) {
for (var i = 0; i < data.configuration.length; i++) {
var config = data.configuration[i];
if (config.name == "ARDUINO_HTTP_IP") {
$("input#http-endpoint").val(config.value);
} else if (config.name == "ARDUINO_HTTP_PORT") {
$("input#https-endpoint").val(config.value);
}
}
}
}, function (data) {
console.log(data);
});
});
// Start of HTML embedded invoke methods
var showAdvanceOperation = function (operation, button) {
$(button).addClass('selected');
$(button).siblings().removeClass('selected');
var hiddenOperation = ".wr-hidden-operations-content > div";
$(hiddenOperation + '[data-operation="' + operation + '"]').show();
$(hiddenOperation + '[data-operation="' + operation + '"]').siblings().hide();
};
// Start of HTML embedded invoke methods
var addConfiguration = function () {
var errorMsgWrapper = "#android_sense-config-error-msg";
var errorMsg = "#android_sense-config-error-msg span";
var addConfigFormData = {};
var configList = new Array();
var mqttEp = $("input#mqtt-endpoint").val();
var mqttConfig = {
"name": "ANDROID_SENSE_MQTT_EP",
"value": String(mqttEp),
"contentType": "text"
};
configList.push(mqttConfig);
addConfigFormData.type = "android_sense"
addConfigFormData.configuration = configList;
var addConfigAPI = "/devicemgt_admin/configuration";
invokerUtil.post(
addConfigAPI,
addConfigFormData,
function (data) {
data = JSON.parse(data);
if (data.statusCode == 201) {
$("#config-save-form").addClass("hidden");
$("#record-created-msg").removeClass("hidden");
} else if (data == 500) {
$(errorMsg).text("Exception occurred at backend.");
} else if (data == 403) {
$(errorMsg).text("Action was not permitted.");
} else {
$(errorMsg).text("An unexpected error occurred.");
}
$(errorMsgWrapper).removeClass("hidden");
}, function (data) {
data = data.status;
if (data == 500) {
$(errorMsg).text("Exception occurred at backend.");
} else if (data == 403) {
$(errorMsg).text("Action was not permitted.");
} else {
$(errorMsg).text("An unexpected error occurred.");
}
$(errorMsgWrapper).removeClass("hidden");
}
);
};

@ -14,6 +14,7 @@ import org.wso2.carbon.apimgt.application.extension.APIManagementProviderService
import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService; import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService;
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfigurationManagementService;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.iot.arduino.service.impl.dto.SensorRecord; import org.wso2.carbon.device.mgt.iot.arduino.service.impl.dto.SensorRecord;
import org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerService; import org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerService;
@ -171,4 +172,17 @@ public class APIUtil {
} }
return deviceAccessAuthorizationService; return deviceAccessAuthorizationService;
} }
public static PlatformConfigurationManagementService getTenantConfigurationManagementService() {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
PlatformConfigurationManagementService tenantConfigurationManagementService =
(PlatformConfigurationManagementService) ctx.getOSGiService(PlatformConfigurationManagementService.class, null);
if (tenantConfigurationManagementService == null) {
String msg = "Tenant configuration Management service not initialized.";
log.error(msg);
throw new IllegalStateException(msg);
}
return tenantConfigurationManagementService;
}
} }

@ -20,6 +20,9 @@ package org.wso2.carbon.device.mgt.iot.arduino.service.impl.util;
import org.wso2.carbon.base.MultitenantConstants; import org.wso2.carbon.base.MultitenantConstants;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry;
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException;
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
import org.wso2.carbon.device.mgt.iot.util.Utils; import org.wso2.carbon.device.mgt.iot.util.Utils;
import org.wso2.carbon.device.mgt.iot.util.ZipArchive; import org.wso2.carbon.device.mgt.iot.util.ZipArchive;
import org.wso2.carbon.utils.CarbonUtils; import org.wso2.carbon.utils.CarbonUtils;
@ -27,6 +30,7 @@ import org.wso2.carbon.utils.CarbonUtils;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
@ -35,6 +39,7 @@ import java.util.Map;
public class ZipUtil { public class ZipUtil {
private static final String HTTP_PORT_PROPERTY = "httpPort"; private static final String HTTP_PORT_PROPERTY = "httpPort";
private static final String CONFIG_TYPE = "general";
public ZipArchive createZipFile(String owner, String tenantDomain, String deviceType, public ZipArchive createZipFile(String owner, String tenantDomain, String deviceType,
String deviceId, String deviceName, String token, String deviceId, String deviceName, String token,
@ -57,6 +62,23 @@ public class ZipUtil {
} else { } else {
contextParams.put("TENANT_DOMAIN", "/t/" + tenantDomain); contextParams.put("TENANT_DOMAIN", "/t/" + tenantDomain);
} }
PlatformConfiguration configuration = APIUtil.getTenantConfigurationManagementService().getConfiguration(
CONFIG_TYPE);
if (configuration != null && configuration.getConfiguration() != null && configuration
.getConfiguration().size() > 0) {
List<ConfigurationEntry> configurations = configuration.getConfiguration();
for (ConfigurationEntry configurationEntry : configurations) {
switch (configurationEntry.getName()) {
case "ARDUINO_HTTP_IP":
iotServerIP = (String)configurationEntry.getValue();
break;
case "ARDUINO_HTTP_PORT":
httpServerPort = (String)configurationEntry.getValue();
break;
}
}
}
contextParams.put("DEVICE_OWNER", owner); contextParams.put("DEVICE_OWNER", owner);
contextParams.put("DEVICE_ID", deviceId); contextParams.put("DEVICE_ID", deviceId);
contextParams.put("DEVICE_NAME", deviceName); contextParams.put("DEVICE_NAME", deviceName);
@ -70,6 +92,8 @@ public class ZipUtil {
return zipFile; return zipFile;
} catch (IOException e) { } catch (IOException e) {
throw new DeviceManagementException("Zip File Creation Failed", e); throw new DeviceManagementException("Zip File Creation Failed", e);
} catch (ConfigurationManagementException e) {
throw new DeviceManagementException("Failed to retrieve configuration", e);
} }
} }
} }

@ -0,0 +1,62 @@
{{!
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.
}}
<div class="panel panel-default">
<div id="general-config-heading" class="panel-heading" role="tab">
<h2 class="sub-title panel-title">
Arduino Endpoint Configuration
</h2>
</div>
<div id="arduino-config-body" class="panel-collapse panel-body"
role="tabpanel">
<div id="arduino-config-error-msg"
class="alert alert-danger hidden" role="alert">
<i class="icon fw fw-error"></i><span></span>
</div>
<div class="wr-input-control">
<label class="wr-input-label" for="email-config-host">
Http Server IP
<span class="helper" title="SMTP Server Host">
<span class="wr-help-tip glyphicon glyphicon-question-sign"></span>
</span>
<br>
</label>
<input id="http-endpoint" type="text" class="form-control"
placeholder="[ Required Field ]">
<br>
<label class="wr-input-label" for="email-config-host">
Http Server Port
<span class="helper" title="SMTP Server Host">
<span class="wr-help-tip glyphicon glyphicon-question-sign"></span>
</span>
<br>
</label>
<input id="https-endpoint" type="text" class="form-control"
placeholder="[ Required Field ]">
<br>
</div>
<div class="wr-input-control wr-btn-grp">
<button id="save-general-btn" class="wr-btn" onclick="addConfiguration();">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Save&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</button>
</div>
</div>
</div>
{{#zone "bottomJs"}}
{{js "js/platform-configuration.js"}}
{{/zone}}

@ -0,0 +1,105 @@
/*
* 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.
*/
$(document).ready(function () {
invokerUtil.get(
"/devicemgt_admin/configuration",
function (data) {
data = JSON.parse(data);
if (data && data.configuration) {
for (var i = 0; i < data.configuration.length; i++) {
var config = data.configuration[i];
if (config.name == "ARDUINO_HTTP_IP") {
$("input#http-endpoint").val(config.value);
} else if (config.name == "ARDUINO_HTTP_PORT") {
$("input#https-endpoint").val(config.value);
}
}
}
}, function (data) {
console.log(data);
});
});
// Start of HTML embedded invoke methods
var showAdvanceOperation = function (operation, button) {
$(button).addClass('selected');
$(button).siblings().removeClass('selected');
var hiddenOperation = ".wr-hidden-operations-content > div";
$(hiddenOperation + '[data-operation="' + operation + '"]').show();
$(hiddenOperation + '[data-operation="' + operation + '"]').siblings().hide();
};
// Start of HTML embedded invoke methods
var addConfiguration = function () {
var errorMsgWrapper = "#arduino-config-error-msg";
var errorMsg = "#arduino-config-error-msg span";
var addConfigFormData = {};
var configList = new Array();
var httpEp = $("input#http-endpoint").val();
var httpConfig = {
"name": "ARDUINO_HTTP_IP",
"value": String(httpEp),
"contentType": "text"
};
var httpsEp = $("input#https-endpoint").val();
var httpsConfig = {
"name": "ARDUINO_HTTP_PORT",
"value": String(httpsEp),
"contentType": "text"
};
configList.push(httpConfig);
configList.push(httpsConfig);
addConfigFormData.type = "arduino"
addConfigFormData.configuration = configList;
var addConfigAPI = "/devicemgt_admin/configuration";
invokerUtil.post(
addConfigAPI,
addConfigFormData,
function (data) {
data = JSON.parse(data);
if (data.statusCode == 201) {
$("#config-save-form").addClass("hidden");
$("#record-created-msg").removeClass("hidden");
} else if (data == 500) {
$(errorMsg).text("Exception occurred at backend.");
} else if (data == 403) {
$(errorMsg).text("Action was not permitted.");
} else {
$(errorMsg).text("An unexpected error occurred.");
}
$(errorMsgWrapper).removeClass("hidden");
}, function (data) {
data = data.status;
if (data == 500) {
$(errorMsg).text("Exception occurred at backend.");
} else if (data == 403) {
$(errorMsg).text("Action was not permitted.");
} else {
$(errorMsg).text("An unexpected error occurred.");
}
$(errorMsgWrapper).removeClass("hidden");
}
);
};

@ -21,7 +21,7 @@ function onRequest(context) {
var device = context.unit.params.device; var device = context.unit.params.device;
var devicemgtProps = require('/app/conf/devicemgt-props.js').config(); var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
var constants = require("/app/modules/constants.js"); var constants = require("/app/modules/constants.js");
var websocketEndpoint = devicemgtProps["httpsURL"].replace("https", "wss"); var websocketEndpoint = devicemgtProps["wssURL"].replace("https", "wss");
var tokenPair = session.get(constants.ACCESS_TOKEN_PAIR_IDENTIFIER); var tokenPair = session.get(constants.ACCESS_TOKEN_PAIR_IDENTIFIER);
var token = ""; var token = "";
if (tokenPair) { if (tokenPair) {

@ -14,6 +14,7 @@ import org.wso2.carbon.apimgt.application.extension.APIManagementProviderService
import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService; import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService;
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfigurationManagementService;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.dto.SensorRecord; import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.dto.SensorRecord;
import org.wso2.carbon.event.output.adapter.core.OutputEventAdapterService; import org.wso2.carbon.event.output.adapter.core.OutputEventAdapterService;
@ -181,4 +182,16 @@ public class APIUtil {
return outputEventAdapterService; return outputEventAdapterService;
} }
public static PlatformConfigurationManagementService getTenantConfigurationManagementService() {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
PlatformConfigurationManagementService tenantConfigurationManagementService =
(PlatformConfigurationManagementService) ctx.getOSGiService(PlatformConfigurationManagementService.class, null);
if (tenantConfigurationManagementService == null) {
String msg = "Tenant configuration Management service not initialized.";
log.error(msg);
throw new IllegalStateException(msg);
}
return tenantConfigurationManagementService;
}
} }

@ -19,6 +19,9 @@
package org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.util; package org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.util;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry;
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException;
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
import org.wso2.carbon.device.mgt.iot.raspberrypi.plugin.mqtt.MqttConfig; import org.wso2.carbon.device.mgt.iot.raspberrypi.plugin.mqtt.MqttConfig;
import org.wso2.carbon.device.mgt.iot.util.Utils; import org.wso2.carbon.device.mgt.iot.util.Utils;
import org.wso2.carbon.device.mgt.iot.util.ZipArchive; import org.wso2.carbon.device.mgt.iot.util.ZipArchive;
@ -27,6 +30,7 @@ import org.wso2.carbon.utils.CarbonUtils;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
@ -40,6 +44,7 @@ public class ZipUtil {
private static final String LOCALHOST = "localhost"; private static final String LOCALHOST = "localhost";
private static final String HTTPS_PROTOCOL_APPENDER = "https://"; private static final String HTTPS_PROTOCOL_APPENDER = "https://";
private static final String HTTP_PROTOCOL_APPENDER = "http://"; private static final String HTTP_PROTOCOL_APPENDER = "http://";
private static final String CONFIG_TYPE = "general";
public ZipArchive createZipFile(String owner, String tenantDomain, String deviceType, public ZipArchive createZipFile(String owner, String tenantDomain, String deviceType,
String deviceId, String deviceName, String token, String deviceId, String deviceName, String token,
@ -63,6 +68,26 @@ public class ZipUtil {
mqttEndpoint = mqttEndpoint.replace(LOCALHOST, iotServerIP); mqttEndpoint = mqttEndpoint.replace(LOCALHOST, iotServerIP);
} }
PlatformConfiguration configuration = APIUtil.getTenantConfigurationManagementService().getConfiguration(
CONFIG_TYPE);
if (configuration != null && configuration.getConfiguration() != null && configuration
.getConfiguration().size() > 0) {
List<ConfigurationEntry> configurations = configuration.getConfiguration();
for (ConfigurationEntry configurationEntry : configurations) {
switch (configurationEntry.getName()) {
case "RASPBERRYPI_HTTPS_EP":
httpsServerEP = (String)configurationEntry.getValue();
break;
case "RASPBERRYPI_HTTP_EP":
httpServerEP = (String)configurationEntry.getValue();
break;
case "RASPBERRYPI_MQTT_EP":
mqttEndpoint = (String)configurationEntry.getValue();
break;
}
}
}
Map<String, String> contextParams = new HashMap<>(); Map<String, String> contextParams = new HashMap<>();
contextParams.put("SERVER_NAME", APIUtil.getTenantDomainOftheUser()); contextParams.put("SERVER_NAME", APIUtil.getTenantDomainOftheUser());
contextParams.put("DEVICE_OWNER", owner); contextParams.put("DEVICE_OWNER", owner);
@ -80,6 +105,8 @@ public class ZipUtil {
return zipFile; return zipFile;
} catch (IOException e) { } catch (IOException e) {
throw new DeviceManagementException("Zip File Creation Failed", e); throw new DeviceManagementException("Zip File Creation Failed", e);
} catch (ConfigurationManagementException e) {
throw new DeviceManagementException("Failed to retrieve configuration", e);
} }
} }
} }

@ -0,0 +1,72 @@
{{!
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.
}}
<div class="panel panel-default">
<div id="general-config-heading" class="panel-heading" role="tab">
<h2 class="sub-title panel-title">
Raspberrypi Endpoint Configuration
</h2>
</div>
<div id="raspberrypi-config-body" class="panel-collapse panel-body"
role="tabpanel">
<div id="raspberrypi-config-error-msg"
class="alert alert-danger hidden" role="alert">
<i class="icon fw fw-error"></i><span></span>
</div>
<div class="wr-input-control">
<label class="wr-input-label" for="email-config-host">
Http Endpoint
<span class="helper" title="SMTP Server Host">
<span class="wr-help-tip glyphicon glyphicon-question-sign"></span>
</span>
<br>
</label>
<input id="http-endpoint" type="text" class="form-control"
placeholder="[ Required Field ]">
<br>
<label class="wr-input-label" for="email-config-host">
Https Endpoint
<span class="helper" title="SMTP Server Host">
<span class="wr-help-tip glyphicon glyphicon-question-sign"></span>
</span>
<br>
</label>
<input id="https-endpoint" type="text" class="form-control"
placeholder="[ Required Field ]">
<br>
<label class="wr-input-label" for="email-config-host">
Mqtt Endpoint
<span class="helper" title="SMTP Server Host">
<span class="wr-help-tip glyphicon glyphicon-question-sign"></span>
</span>
<br>
</label>
<input id="mqtt-endpoint" type="text" class="form-control"
placeholder="[ Required Field ]">
<br>
</div>
<div class="wr-input-control wr-btn-grp">
<button id="save-general-btn" class="wr-btn" onclick="addConfiguration();">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Save&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</button>
</div>
</div>
</div>
{{#zone "bottomJs"}}
{{js "js/platform-configuration.js"}}
{{/zone}}

@ -0,0 +1,115 @@
/*
* 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.
*/
$(document).ready(function () {
invokerUtil.get(
"/devicemgt_admin/configuration",
function (data) {
data = JSON.parse(data);
if (data && data.configuration) {
for (var i = 0; i < data.configuration.length; i++) {
var config = data.configuration[i];
if (config.name == "RASPBERRYPI_HTTP_EP") {
$("input#http-endpoint").val(config.value);
} else if (config.name == "RASPBERRYPI_HTTPS_EP") {
$("input#https-endpoint").val(config.value);
} else if (config.name == "RASPBERRYPI_MQTT_EP") {
$("input#mqtt-endpoint").val(config.value);
}
}
}
}, function (data) {
console.log(data);
});
});
// Start of HTML embedded invoke methods
var showAdvanceOperation = function (operation, button) {
$(button).addClass('selected');
$(button).siblings().removeClass('selected');
var hiddenOperation = ".wr-hidden-operations-content > div";
$(hiddenOperation + '[data-operation="' + operation + '"]').show();
$(hiddenOperation + '[data-operation="' + operation + '"]').siblings().hide();
};
// Start of HTML embedded invoke methods
var addConfiguration = function () {
var errorMsgWrapper = "#virtual_firelarm-config-error-msg";
var errorMsg = "#virtual_firelarm-config-error-msg span";
var addConfigFormData = {};
var configList = new Array();
var httpEp = $("input#http-endpoint").val();
var httpConfig = {
"name": "RASPBERRYPI_HTTP_EP",
"value": String(httpEp),
"contentType": "text"
};
var httpsEp = $("input#https-endpoint").val();
var httpsConfig = {
"name": "RASPBERRYPI_HTTPS_EP",
"value": String(httpsEp),
"contentType": "text"
};
var mqttEp = $("input#mqtt-endpoint").val();
var mqttConfig = {
"name": "RASPBERRYPI_MQTT_EP",
"value": String(mqttEp),
"contentType": "text"
};
configList.push(httpConfig);
configList.push(httpsConfig);
configList.push(mqttConfig);
addConfigFormData.type = "raspberrypi"
addConfigFormData.configuration = configList;
var addConfigAPI = "/devicemgt_admin/configuration";
invokerUtil.post(
addConfigAPI,
addConfigFormData,
function (data) {
data = JSON.parse(data);
if (data.statusCode == 201) {
$("#config-save-form").addClass("hidden");
$("#record-created-msg").removeClass("hidden");
} else if (data == 500) {
$(errorMsg).text("Exception occurred at backend.");
} else if (data == 403) {
$(errorMsg).text("Action was not permitted.");
} else {
$(errorMsg).text("An unexpected error occurred.");
}
$(errorMsgWrapper).removeClass("hidden");
}, function (data) {
data = data.status;
if (data == 500) {
$(errorMsg).text("Exception occurred at backend.");
} else if (data == 403) {
$(errorMsg).text("Action was not permitted.");
} else {
$(errorMsg).text("An unexpected error occurred.");
}
$(errorMsgWrapper).removeClass("hidden");
}
);
};

@ -21,7 +21,7 @@ function onRequest(context) {
var device = context.unit.params.device; var device = context.unit.params.device;
var devicemgtProps = require('/app/conf/devicemgt-props.js').config(); var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
var constants = require("/app/modules/constants.js"); var constants = require("/app/modules/constants.js");
var websocketEndpoint = devicemgtProps["httpsURL"].replace("https", "wss"); var websocketEndpoint = devicemgtProps["wssURL"].replace("https", "wss");
var tokenPair = session.get(constants.ACCESS_TOKEN_PAIR_IDENTIFIER); var tokenPair = session.get(constants.ACCESS_TOKEN_PAIR_IDENTIFIER);
var token = ""; var token = "";
if (tokenPair) { if (tokenPair) {

@ -14,6 +14,7 @@ import org.wso2.carbon.apimgt.application.extension.APIManagementProviderService
import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService; import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService;
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfigurationManagementService;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.dto.SensorRecord; import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.dto.SensorRecord;
import org.wso2.carbon.event.output.adapter.core.OutputEventAdapterService; import org.wso2.carbon.event.output.adapter.core.OutputEventAdapterService;
@ -181,4 +182,17 @@ public class APIUtil {
} }
return outputEventAdapterService; return outputEventAdapterService;
} }
public static PlatformConfigurationManagementService getTenantConfigurationManagementService() {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
PlatformConfigurationManagementService tenantConfigurationManagementService =
(PlatformConfigurationManagementService) ctx.getOSGiService(PlatformConfigurationManagementService.class, null);
if (tenantConfigurationManagementService == null) {
String msg = "Tenant configuration Management service not initialized.";
log.error(msg);
throw new IllegalStateException(msg);
}
return tenantConfigurationManagementService;
}
} }

@ -13,6 +13,11 @@ public class VirtualFireAlarmUtilConstants {
public static final String APIM_EP = "APIM_EP"; public static final String APIM_EP = "APIM_EP";
public static final String MQTT_EP = "MQTT_EP"; public static final String MQTT_EP = "MQTT_EP";
public static final String XMPP_EP = "XMPP_EP"; public static final String XMPP_EP = "XMPP_EP";
public static final String VIRTUAL_FIREALARM_HTTPS_EP = "VIRTUAL_FIREALARM_HTTPS_EP";
public static final String VIRTUAL_FIREALARM_HTTP_EP = "VIRTUAL_FIREALARM_HTTP_EP";
public static final String VIRTUAL_FIREALARM_APIM_EP = "VIRTUAL_FIREALARM_APIM_EP";
public static final String VIRTUAL_FIREALARM_MQTT_EP = "VIRTUAL_FIREALARM_MQTT_EP";
public static final String VIRTUAL_FIREALARM_XMPP_EP = "VIRTUAL_FIREALARM_XMPP_EP";
public static final String API_APPLICATION_KEY = "API_APPLICATION_KEY"; public static final String API_APPLICATION_KEY = "API_APPLICATION_KEY";
public static final String DEVICE_TOKEN = "DEVICE_TOKEN"; public static final String DEVICE_TOKEN = "DEVICE_TOKEN";
public static final String DEVICE_REFRESH_TOKEN = "DEVICE_REFRESH_TOKEN"; public static final String DEVICE_REFRESH_TOKEN = "DEVICE_REFRESH_TOKEN";

@ -24,8 +24,12 @@ import org.apache.commons.logging.LogFactory;
import org.json.JSONObject; import org.json.JSONObject;
import org.wso2.carbon.apimgt.application.extension.constants.ApiApplicationConstants; import org.wso2.carbon.apimgt.application.extension.constants.ApiApplicationConstants;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry;
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException;
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
import org.wso2.carbon.device.mgt.iot.util.Utils; import org.wso2.carbon.device.mgt.iot.util.Utils;
import org.wso2.carbon.device.mgt.iot.util.ZipArchive; import org.wso2.carbon.device.mgt.iot.util.ZipArchive;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.constants.VirtualFireAlarmConstants;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.mqtt.MqttConfig; import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.mqtt.MqttConfig;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.xmpp.XmppConfig; import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.xmpp.XmppConfig;
import org.wso2.carbon.utils.CarbonUtils; import org.wso2.carbon.utils.CarbonUtils;
@ -33,6 +37,7 @@ import org.wso2.carbon.utils.CarbonUtils;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
@ -47,6 +52,7 @@ public class ZipUtil {
private static final String LOCALHOST = "localhost"; private static final String LOCALHOST = "localhost";
private static final String HTTPS_PROTOCOL_APPENDER = "https://"; private static final String HTTPS_PROTOCOL_APPENDER = "https://";
private static final String HTTP_PROTOCOL_APPENDER = "http://"; private static final String HTTP_PROTOCOL_APPENDER = "http://";
private static final String CONFIG_TYPE = "general";
public ZipArchive createZipFile(String owner, String deviceType, String deviceId, String deviceName, public ZipArchive createZipFile(String owner, String deviceType, String deviceId, String deviceName,
String apiApplicationKey, String token, String refreshToken) String apiApplicationKey, String token, String refreshToken)
@ -65,7 +71,6 @@ public class ZipUtil {
String httpServerPort = System.getProperty(HTTP_PORT_PROPERTY); String httpServerPort = System.getProperty(HTTP_PORT_PROPERTY);
String httpsServerEP = HTTPS_PROTOCOL_APPENDER + iotServerIP + ":" + httpsServerPort; String httpsServerEP = HTTPS_PROTOCOL_APPENDER + iotServerIP + ":" + httpsServerPort;
String httpServerEP = HTTP_PROTOCOL_APPENDER + iotServerIP + ":" + httpServerPort; String httpServerEP = HTTP_PROTOCOL_APPENDER + iotServerIP + ":" + httpServerPort;
String apimEndpoint = httpsServerEP;
String mqttEndpoint = MqttConfig.getInstance().getBrokerEndpoint(); String mqttEndpoint = MqttConfig.getInstance().getBrokerEndpoint();
if (mqttEndpoint.contains(LOCALHOST)) { if (mqttEndpoint.contains(LOCALHOST)) {
mqttEndpoint = mqttEndpoint.replace(LOCALHOST, iotServerIP); mqttEndpoint = mqttEndpoint.replace(LOCALHOST, iotServerIP);
@ -77,6 +82,28 @@ public class ZipUtil {
xmppEndpoint = xmppEndpoint.replace(LOCALHOST, iotServerIP); xmppEndpoint = xmppEndpoint.replace(LOCALHOST, iotServerIP);
} }
PlatformConfiguration configuration = APIUtil.getTenantConfigurationManagementService().getConfiguration(
CONFIG_TYPE);
if (configuration != null && configuration.getConfiguration() != null && configuration
.getConfiguration().size() > 0) {
List<ConfigurationEntry> configurations = configuration.getConfiguration();
for (ConfigurationEntry configurationEntry : configurations) {
switch (configurationEntry.getName()) {
case VirtualFireAlarmUtilConstants.VIRTUAL_FIREALARM_HTTPS_EP:
httpsServerEP = (String)configurationEntry.getValue();
break;
case VirtualFireAlarmUtilConstants.VIRTUAL_FIREALARM_HTTP_EP:
httpServerEP = (String)configurationEntry.getValue();
break;
case VirtualFireAlarmUtilConstants.VIRTUAL_FIREALARM_MQTT_EP:
mqttEndpoint = (String)configurationEntry.getValue();
break;
case VirtualFireAlarmUtilConstants.VIRTUAL_FIREALARM_XMPP_EP:
xmppEndpoint = (String)configurationEntry.getValue();
break;
}
}
}
String base64EncodedApplicationKey = getBase64EncodedAPIAppKey(apiApplicationKey).trim(); String base64EncodedApplicationKey = getBase64EncodedAPIAppKey(apiApplicationKey).trim();
Map<String, String> contextParams = new HashMap<>(); Map<String, String> contextParams = new HashMap<>();
@ -86,7 +113,7 @@ public class ZipUtil {
contextParams.put(VirtualFireAlarmUtilConstants.DEVICE_NAME, deviceName); contextParams.put(VirtualFireAlarmUtilConstants.DEVICE_NAME, deviceName);
contextParams.put(VirtualFireAlarmUtilConstants.HTTPS_EP, httpsServerEP); contextParams.put(VirtualFireAlarmUtilConstants.HTTPS_EP, httpsServerEP);
contextParams.put(VirtualFireAlarmUtilConstants.HTTP_EP, httpServerEP); contextParams.put(VirtualFireAlarmUtilConstants.HTTP_EP, httpServerEP);
contextParams.put(VirtualFireAlarmUtilConstants.APIM_EP, apimEndpoint); contextParams.put(VirtualFireAlarmUtilConstants.APIM_EP, httpServerEP);
contextParams.put(VirtualFireAlarmUtilConstants.MQTT_EP, mqttEndpoint); contextParams.put(VirtualFireAlarmUtilConstants.MQTT_EP, mqttEndpoint);
contextParams.put(VirtualFireAlarmUtilConstants.XMPP_EP, "XMPP:" + xmppEndpoint); contextParams.put(VirtualFireAlarmUtilConstants.XMPP_EP, "XMPP:" + xmppEndpoint);
contextParams.put(VirtualFireAlarmUtilConstants.API_APPLICATION_KEY, base64EncodedApplicationKey); contextParams.put(VirtualFireAlarmUtilConstants.API_APPLICATION_KEY, base64EncodedApplicationKey);
@ -98,6 +125,8 @@ public class ZipUtil {
return zipFile; return zipFile;
} catch (IOException e) { } catch (IOException e) {
throw new DeviceManagementException("Zip File Creation Failed", e); throw new DeviceManagementException("Zip File Creation Failed", e);
} catch (ConfigurationManagementException e) {
throw new DeviceManagementException("Failed to retrieve configuration", e);
} }
} }

@ -0,0 +1,74 @@
{{!
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.
}}
<!--Virtual Firealarm-->
<div class="panel panel-default">
<div id="general-config-heading" class="panel-heading" role="tab">
<h2 class="sub-title panel-title">
Virtual Firealarm Endpoint Configuration
</h2>
</div>
<div id="virtual-alarm-config-body" class="panel-collapse panel-body"
role="tabpanel">
<div id="virtual_firelarm-config-error-msg"
class="alert alert-danger hidden" role="alert">
<i class="icon fw fw-error"></i><span></span>
</div>
<div class="wr-input-control">
<label class="wr-input-label" for="email-config-host">
Http Endpoint
<span class="helper" title="SMTP Server Host">
<span class="wr-help-tip glyphicon glyphicon-question-sign"></span>
</span>
<br>
</label>
<input id="http-endpoint" type="text" class="form-control"
placeholder="[ Required Field ]">
<br>
<label class="wr-input-label" for="email-config-host">
Https Endpoint
<span class="helper" title="SMTP Server Host">
<span class="wr-help-tip glyphicon glyphicon-question-sign"></span>
</span>
<br>
</label>
<input id="https-endpoint" type="text" class="form-control"
placeholder="[ Required Field ]">
<br>
<label class="wr-input-label" for="email-config-host">
Mqtt Endpoint
<span class="helper" title="SMTP Server Host">
<span class="wr-help-tip glyphicon glyphicon-question-sign"></span>
</span>
<br>
</label>
<input id="mqtt-endpoint" type="text" class="form-control"
placeholder="[ Required Field ]">
<br>
</div>
<div class="wr-input-control wr-btn-grp">
<button id="save-general-btn-virtualfirealarm" class="wr-btn" onclick="addConfiguration();">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Save&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</button>
</div>
</div>
</div>
<!-- Virtual Firealarm-->
{{#zone "bottomJs"}}
{{js "js/platform-configuration.js"}}
{{/zone}}

@ -0,0 +1,115 @@
/*
* 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.
*/
$(document).ready(function () {
invokerUtil.get(
"/devicemgt_admin/configuration",
function (data) {
data = JSON.parse(data);
if (data && data.configuration) {
for (var i = 0; i < data.configuration.length; i++) {
var config = data.configuration[i];
if (config.name == "VIRTUAL_FIREALARM_HTTP_EP") {
$("input#http-endpoint").val(config.value);
} else if (config.name == "VIRTUAL_FIREALARM_HTTPS_EP") {
$("input#https-endpoint").val(config.value);
} else if (config.name == "VIRTUAL_FIREALARM_MQTT_EP") {
$("input#mqtt-endpoint").val(config.value);
}
}
}
}, function (data) {
console.log(data);
});
});
// Start of HTML embedded invoke methods
var showAdvanceOperation = function (operation, button) {
$(button).addClass('selected');
$(button).siblings().removeClass('selected');
var hiddenOperation = ".wr-hidden-operations-content > div";
$(hiddenOperation + '[data-operation="' + operation + '"]').show();
$(hiddenOperation + '[data-operation="' + operation + '"]').siblings().hide();
};
// Start of HTML embedded invoke methods
var addConfiguration = function () {
var errorMsgWrapper = "#virtual_firelarm-config-error-msg";
var errorMsg = "#virtual_firelarm-config-error-msg span";
var addConfigFormData = {};
var configList = new Array();
var httpEp = $("input#http-endpoint").val();
var httpConfig = {
"name": "VIRTUAL_FIREALARM_HTTP_EP",
"value": String(httpEp),
"contentType": "text"
};
var httpsEp = $("input#https-endpoint").val();
var httpsConfig = {
"name": "VIRTUAL_FIREALARM_HTTPS_EP",
"value": String(httpsEp),
"contentType": "text"
};
var mqttEp = $("input#mqtt-endpoint").val();
var mqttConfig = {
"name": "VIRTUAL_FIREALARM_MQTT_EP",
"value": String(mqttEp),
"contentType": "text"
};
configList.push(httpConfig);
configList.push(httpsConfig);
configList.push(mqttConfig);
addConfigFormData.type = "virtual_firealarm"
addConfigFormData.configuration = configList;
var addConfigAPI = "/devicemgt_admin/configuration";
invokerUtil.post(
addConfigAPI,
addConfigFormData,
function (data) {
data = JSON.parse(data);
if (data.statusCode == 201) {
$("#config-save-form").addClass("hidden");
$("#record-created-msg").removeClass("hidden");
} else if (data == 500) {
$(errorMsg).text("Exception occurred at backend.");
} else if (data == 403) {
$(errorMsg).text("Action was not permitted.");
} else {
$(errorMsg).text("An unexpected error occurred.");
}
$(errorMsgWrapper).removeClass("hidden");
}, function (data) {
data = data.status;
if (data == 500) {
$(errorMsg).text("Exception occurred at backend.");
} else if (data == 403) {
$(errorMsg).text("Action was not permitted.");
} else {
$(errorMsg).text("An unexpected error occurred.");
}
$(errorMsgWrapper).removeClass("hidden");
}
);
};

@ -21,7 +21,7 @@ function onRequest(context) {
var device = context.unit.params.device; var device = context.unit.params.device;
var devicemgtProps = require('/app/conf/devicemgt-props.js').config(); var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
var constants = require("/app/modules/constants.js"); var constants = require("/app/modules/constants.js");
var websocketEndpoint = devicemgtProps["httpsURL"].replace("https", "wss"); var websocketEndpoint = devicemgtProps["wssURL"].replace("https", "wss");
var tokenPair = session.get(constants.ACCESS_TOKEN_PAIR_IDENTIFIER); var tokenPair = session.get(constants.ACCESS_TOKEN_PAIR_IDENTIFIER);
var token = ""; var token = "";
if (tokenPair) { if (tokenPair) {

@ -19,4 +19,7 @@ org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../con
org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../database/AndroidSenseDM_DB.h2.db);\ org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../database/AndroidSenseDM_DB.h2.db);\
org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.device-view);\ org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.device-view);\
org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.type-view);\ org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.type-view);\
org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.analytics-view);\
org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.platform.configuration);\
org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.realtime.analytics-view);\
org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/carbonapps/android_sense.car);\ org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/carbonapps/android_sense.car);\

@ -22,4 +22,7 @@ org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../con
org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../database/ArduinoDM_DB.h2.db);\ org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../database/ArduinoDM_DB.h2.db);\
org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.device-view);\ org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.device-view);\
org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.type-view);\ org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.type-view);\
org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.analytics-view);\
org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.realtime.analytics-view);\
org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.platform.configuration);\
org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/carbonapps/arduino.car);\ org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/carbonapps/arduino.car);\

@ -22,4 +22,7 @@ org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../con
org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../database/RaspberryPiDM_DB.h2.db);\ org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../database/RaspberryPiDM_DB.h2.db);\
org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.device-view);\ org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.device-view);\
org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.type-view);\ org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.type-view);\
org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.analytics-view);\
org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.realtime.analytics-view);\
org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.platform.configuration);\
org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/carbonapps/raspberrypi.car);\ org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/carbonapps/raspberrypi.car);\

@ -31,4 +31,8 @@ org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../dep
org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.type-view);\ org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.type-view);\
org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.policy-edit);\ org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.policy-edit);\
org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.policy-view);\ org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.policy-view);\
org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.analytics-view);\
org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.platform.configuration);\
org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.realtime.analytics-view);\
org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.policy-wizard);\
org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../resources/security/wso2certs.jks);\ org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../resources/security/wso2certs.jks);\

Loading…
Cancel
Save