mirror of
https://repository.entgra.net/community/device-mgt-plugins.git
synced 2025-09-16 23:42:15 +00:00
fix code conflicts
This commit is contained in:
commit
5c29ac8c4f
Binary file not shown.
@ -69,7 +69,6 @@ public class MQTTAdapterListener implements MqttCallback, Runnable {
|
||||
|
||||
private InputEventAdapterListener eventAdapterListener = null;
|
||||
|
||||
|
||||
public MQTTAdapterListener(MQTTBrokerConnectionConfiguration mqttBrokerConnectionConfiguration,
|
||||
String topic, String mqttClientId,
|
||||
InputEventAdapterListener inputEventAdapterListener, int tenantId) {
|
||||
@ -173,22 +172,26 @@ public class MQTTAdapterListener implements MqttCallback, Runnable {
|
||||
StringEntity requestEntity = new StringEntity(jsonString, ContentType.APPLICATION_JSON);
|
||||
postMethod.setEntity(requestEntity);
|
||||
HttpResponse httpResponse = httpClient.execute(postMethod);
|
||||
String response = MQTTUtil.getResponseString(httpResponse);
|
||||
try {
|
||||
JSONParser jsonParser = new JSONParser();
|
||||
JSONObject jsonPayload = (JSONObject) jsonParser.parse(response);
|
||||
String clientId = (String) jsonPayload.get(MQTTEventAdapterConstants.CLIENT_ID);
|
||||
String clientSecret = (String) jsonPayload.get(MQTTEventAdapterConstants.CLIENT_SECRET);
|
||||
JWTClientManagerService jwtClientManagerService = MQTTUtil.getJWTClientManagerService();
|
||||
AccessTokenInfo accessTokenInfo = jwtClientManagerService.getJWTClient().getAccessToken(
|
||||
clientId, clientSecret, username, scopes);
|
||||
connectionOptions.setUserName(accessTokenInfo.getAccessToken());
|
||||
} catch (ParseException e) {
|
||||
String msg = "error occurred while parsing client credential payload";
|
||||
log.error(msg, e);
|
||||
} catch (JWTClientException e) {
|
||||
String msg = "error occurred while parsing the response from JWT Client";
|
||||
log.error(msg, e);
|
||||
if (httpResponse != null) {
|
||||
String response = MQTTUtil.getResponseString(httpResponse);
|
||||
try {
|
||||
if (response != null) {
|
||||
JSONParser jsonParser = new JSONParser();
|
||||
JSONObject jsonPayload = (JSONObject) jsonParser.parse(response);
|
||||
String clientId = (String) jsonPayload.get(MQTTEventAdapterConstants.CLIENT_ID);
|
||||
String clientSecret = (String) jsonPayload.get(MQTTEventAdapterConstants.CLIENT_SECRET);
|
||||
JWTClientManagerService jwtClientManagerService = MQTTUtil.getJWTClientManagerService();
|
||||
AccessTokenInfo accessTokenInfo = jwtClientManagerService.getJWTClient().getAccessToken(
|
||||
clientId, clientSecret, username, scopes);
|
||||
connectionOptions.setUserName(accessTokenInfo.getAccessToken());
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
String msg = "error occurred while parsing client credential payload";
|
||||
log.error(msg, e);
|
||||
} catch (JWTClientException e) {
|
||||
String msg = "error occurred while parsing the response from JWT Client";
|
||||
log.error(msg, e);
|
||||
}
|
||||
}
|
||||
} catch (MalformedURLException e) {
|
||||
log.error("Invalid dcrUrl : " + dcrUrlString);
|
||||
@ -263,11 +266,11 @@ public class MQTTAdapterListener implements MqttCallback, Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
int connectionDuration = MQTTEventAdapterConstants.INITIAL_RECONNECTION_DURATION;
|
||||
while (!connectionSucceeded) {
|
||||
try {
|
||||
MQTTEventAdapterConstants.initialReconnectDuration = MQTTEventAdapterConstants.initialReconnectDuration
|
||||
* MQTTEventAdapterConstants.reconnectionProgressionFactor;
|
||||
Thread.sleep(MQTTEventAdapterConstants.initialReconnectDuration);
|
||||
connectionDuration = connectionDuration * MQTTEventAdapterConstants.RECONNECTION_PROGRESS_FACTOR;
|
||||
Thread.sleep(connectionDuration);
|
||||
startListener();
|
||||
connectionSucceeded = true;
|
||||
log.info("MQTT Connection successful");
|
||||
|
||||
@ -47,8 +47,8 @@ public class MQTTEventAdapterConstants {
|
||||
public static final String ADAPTER_CONF_KEEP_ALIVE = "keepAlive";
|
||||
public static final int ADAPTER_CONF_DEFAULT_KEEP_ALIVE = 60000;
|
||||
|
||||
public static int initialReconnectDuration = 2000;
|
||||
public static final int reconnectionProgressionFactor = 2;
|
||||
public static final int INITIAL_RECONNECTION_DURATION = 4000;
|
||||
public static final int RECONNECTION_PROGRESS_FACTOR = 2;
|
||||
|
||||
public static final String EMPTY_STRING = "";
|
||||
public static final String GRANT_TYPE = "urn:ietf:params:oauth:grant-type:jwt-bearer refresh_token";
|
||||
|
||||
@ -203,10 +203,10 @@ public class XMPPAdapterListener implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
while (!connectionSucceeded) {
|
||||
int connectionDuration = XMPPEventAdapterConstants.INITIAL_RECONNECTION_DURATION;
|
||||
try {
|
||||
XMPPEventAdapterConstants.initialReconnectDuration = XMPPEventAdapterConstants.initialReconnectDuration
|
||||
* XMPPEventAdapterConstants.reconnectionProgressionFactor;
|
||||
Thread.sleep(XMPPEventAdapterConstants.initialReconnectDuration);
|
||||
connectionDuration = connectionDuration * XMPPEventAdapterConstants.RECONNECTION_PROGRESS_FACTOR;
|
||||
Thread.sleep(connectionDuration);
|
||||
startListener();
|
||||
connectionSucceeded = true;
|
||||
log.info("XMPP Connection successful");
|
||||
|
||||
@ -49,8 +49,8 @@ public class XMPPEventAdapterConstants {
|
||||
public static final int DEFAULT_XMPP_PORT = 5222;
|
||||
public static final int DEFAULT_TIMEOUT_INTERVAL = 5000;
|
||||
|
||||
public static int initialReconnectDuration = 10000;
|
||||
public static final int reconnectionProgressionFactor = 2;
|
||||
public static int INITIAL_RECONNECTION_DURATION = 4000;
|
||||
public static final int RECONNECTION_PROGRESS_FACTOR = 2;
|
||||
|
||||
public static final String DEFAULT = "default";
|
||||
|
||||
|
||||
@ -61,9 +61,15 @@ function submitForm(formId) {
|
||||
var statusIcon = content.find("#status-icon");
|
||||
var description = content.find("#description");
|
||||
var successCallBack = function (response) {
|
||||
title.html("Response Received!");
|
||||
statusIcon.attr("class", defaultStatusClasses + " fw-success");
|
||||
description.html(response);
|
||||
var res = response;
|
||||
try {
|
||||
res = JSON.parse(response).messageFromServer;
|
||||
} catch (err) {
|
||||
//do nothing
|
||||
}
|
||||
title.html("Operation Triggered!");
|
||||
statusIcon.attr("class", defaultStatusClasses + " fw-check");
|
||||
description.html(res);
|
||||
$(modalPopupContent).html(content.html());
|
||||
};
|
||||
var errorCallBack = function (response) {
|
||||
@ -94,9 +100,9 @@ function submitForm(formId) {
|
||||
$(document).on('submit', 'form', function (e) {
|
||||
e.preventDefault();
|
||||
var postOperationRequest = $.ajax({
|
||||
url: $(this).attr("action") + '&' + $(this).serialize(),
|
||||
method: "post"
|
||||
});
|
||||
url: $(this).attr("action") + '&' + $(this).serialize(),
|
||||
method: "post"
|
||||
});
|
||||
|
||||
var btnSubmit = $('#btnSend', this);
|
||||
btnSubmit.addClass('hidden');
|
||||
|
||||
@ -73,7 +73,6 @@ validateStep["policy-profile"] = function () {
|
||||
};
|
||||
|
||||
stepForwardFrom["policy-profile"] = function () {
|
||||
policy["profile"] = operationModule.generateProfile(policy["platform"], configuredOperations);
|
||||
// updating next-page wizard title with selected platform
|
||||
$("#policy-criteria-page-wizard-title").text("ADD " + deviceTypeLabel + " POLICY");
|
||||
};
|
||||
@ -105,6 +104,8 @@ stepForwardFrom["policy-criteria"] = function () {
|
||||
policy["selectedUsers"] = $("#users-input").val();
|
||||
} else if ($(this).attr("id") == "user-roles-radio-btn") {
|
||||
policy["selectedUserRoles"] = $("#user-roles-input").val();
|
||||
} else if ($(this).attr("id") == "groups-radio-btn") {
|
||||
policy["selectedUserGroups"] = $("#groups-input").val();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -247,12 +248,15 @@ var savePolicy = function (policy, state) {
|
||||
invokerUtil.post(
|
||||
serviceURL,
|
||||
payload,
|
||||
function () {
|
||||
$(".add-policy").addClass("hidden");
|
||||
$(".policy-naming").addClass("hidden");
|
||||
$(".policy-message").removeClass("hidden");
|
||||
if (state == "publish") {
|
||||
publishToDevice();
|
||||
function (response) {
|
||||
response = JSON.parse(response);
|
||||
if (response["statusCode"] == 201) {
|
||||
$(".add-policy").addClass("hidden");
|
||||
$(".policy-naming").addClass("hidden");
|
||||
$(".policy-message").removeClass("hidden");
|
||||
if (state == "publish") {
|
||||
publishToDevice();
|
||||
}
|
||||
}
|
||||
},
|
||||
function (err) {
|
||||
@ -351,6 +355,31 @@ function formatRepoSelection(user) {
|
||||
return user.username || user.text;
|
||||
}
|
||||
|
||||
function formatGroupRepo(group) {
|
||||
if (group.loading) {
|
||||
return group.text
|
||||
}
|
||||
if (!group.name) {
|
||||
return;
|
||||
}
|
||||
var markup = '<div class="clearfix">' +
|
||||
'<div clas="col-sm-8">' +
|
||||
'<div class="clearfix">' +
|
||||
'<div class="col-sm-3">' + group.name + '</div>';
|
||||
if (group.name) {
|
||||
markup += '<div class="col-sm-3"><i class="fa fa-code-fork"></i> ' + group.name + '</div>';
|
||||
}
|
||||
if (group.owner) {
|
||||
markup += '<div class="col-sm-2"><i class="fa fa-star"></i> ' + group.owner + '</div></div>';
|
||||
}
|
||||
markup += '</div></div>';
|
||||
return markup;
|
||||
}
|
||||
|
||||
function formatGroupRepoSelection(group) {
|
||||
return group.name || group.text;
|
||||
}
|
||||
|
||||
// End of functions related to grid-input-view
|
||||
|
||||
|
||||
@ -372,46 +401,85 @@ $(document).ready(function () {
|
||||
});
|
||||
|
||||
$("#users-input").select2({
|
||||
multiple: true,
|
||||
tags: true,
|
||||
ajax: {
|
||||
url: window.location.origin + "/devicemgt/api/invoker/execute/",
|
||||
method: "POST",
|
||||
dataType: 'json',
|
||||
delay: 250,
|
||||
id: function (user) {
|
||||
return user.username;
|
||||
},
|
||||
data: function (params) {
|
||||
var postData = {};
|
||||
postData.actionMethod = "GET";
|
||||
postData.actionUrl = "/devicemgt_admin/users";
|
||||
postData.actionPayload = JSON.stringify({
|
||||
q: params.term, // search term
|
||||
page: params.page
|
||||
});
|
||||
multiple: true,
|
||||
tags: true,
|
||||
ajax: {
|
||||
url: window.location.origin + "/devicemgt/api/invoker/execute/",
|
||||
method: "POST",
|
||||
dataType: 'json',
|
||||
delay: 250,
|
||||
id: function (user) {
|
||||
return user.username;
|
||||
},
|
||||
data: function (params) {
|
||||
var postData = {};
|
||||
postData.actionMethod = "GET";
|
||||
postData.actionUrl = "/devicemgt_admin/users";
|
||||
postData.actionPayload = JSON.stringify({
|
||||
q: params.term, // search term
|
||||
page: params.page
|
||||
});
|
||||
|
||||
return JSON.stringify(postData);
|
||||
},
|
||||
processResults: function (data, page) {
|
||||
var newData = [];
|
||||
$.each(data.responseContent, function (index, value) {
|
||||
value.id = value.username;
|
||||
newData.push(value);
|
||||
});
|
||||
return {
|
||||
results: newData
|
||||
};
|
||||
},
|
||||
cache: true
|
||||
},
|
||||
escapeMarkup: function (markup) {
|
||||
return markup;
|
||||
}, // let our custom formatter work
|
||||
minimumInputLength: 1,
|
||||
templateResult: formatRepo, // omitted for brevity, see the source of this page
|
||||
templateSelection: formatRepoSelection // omitted for brevity, see the source of this page
|
||||
});
|
||||
return JSON.stringify(postData);
|
||||
},
|
||||
processResults: function (data, page) {
|
||||
var newData = [];
|
||||
$.each(data.responseContent, function (index, value) {
|
||||
value.id = value.username;
|
||||
newData.push(value);
|
||||
});
|
||||
return {
|
||||
results: newData
|
||||
};
|
||||
},
|
||||
cache: true
|
||||
},
|
||||
escapeMarkup: function (markup) {
|
||||
return markup;
|
||||
}, // let our custom formatter work
|
||||
minimumInputLength: 1,
|
||||
templateResult: formatRepo, // omitted for brevity, see the source of this page
|
||||
templateSelection: formatRepoSelection // omitted for brevity, see the source of this page
|
||||
});
|
||||
|
||||
$("#groups-input").select2({
|
||||
multiple: true,
|
||||
tags: true,
|
||||
ajax: {
|
||||
url: window.location.origin + "/devicemgt/api/invoker/execute/",
|
||||
method: "POST",
|
||||
dataType: 'json',
|
||||
delay: 250,
|
||||
id: function (group) {
|
||||
return group.name;
|
||||
},
|
||||
data: function (params) {
|
||||
var postData = {};
|
||||
postData.actionMethod = "GET";
|
||||
var username = $("#platform").data("username");
|
||||
postData.actionUrl = "/devicemgt_admin/groups/user/" + username +
|
||||
"/search?groupName=" + params.term;
|
||||
return JSON.stringify(postData);
|
||||
},
|
||||
processResults: function (data, page) {
|
||||
var newData = [];
|
||||
$.each(data, function (index, value) {
|
||||
value.id = value.name;
|
||||
newData.push(value);
|
||||
});
|
||||
return {
|
||||
results: newData
|
||||
};
|
||||
},
|
||||
cache: true
|
||||
},
|
||||
escapeMarkup: function (markup) {
|
||||
return markup;
|
||||
}, // let our custom formatter work
|
||||
minimumInputLength: 1,
|
||||
templateResult: formatGroupRepo, // omitted for brevity, see the source of this page
|
||||
templateSelection: formatGroupRepoSelection // omitted for brevity, see the source of this page
|
||||
});
|
||||
|
||||
// Adding initial state of wizard-steps.
|
||||
$("#policy-profile-wizard-steps").html($(".wr-steps").html());
|
||||
@ -427,16 +495,24 @@ $(document).ready(function () {
|
||||
});
|
||||
|
||||
$("#users-select-field").hide();
|
||||
$("#groups-select-field").hide();
|
||||
$("#user-roles-select-field").show();
|
||||
|
||||
$("input[type='radio'].select-users-radio").change(function () {
|
||||
if ($("#user-roles-radio-btn").is(":checked")) {
|
||||
$("#user-roles-select-field").show();
|
||||
$("#users-select-field").hide();
|
||||
$("#groups-select-field").hide();
|
||||
}
|
||||
if ($("#users-radio-btn").is(":checked")) {
|
||||
$("#user-roles-select-field").hide();
|
||||
$("#users-select-field").show();
|
||||
$("#groups-select-field").hide();
|
||||
}
|
||||
if ($("#user-roles-radio-btn").is(":checked")) {
|
||||
if ($("#groups-radio-btn").is(":checked")) {
|
||||
$("#user-roles-select-field").hide();
|
||||
$("#users-select-field").hide();
|
||||
$("#user-roles-select-field").show();
|
||||
$("#groups-select-field").show();
|
||||
}
|
||||
});
|
||||
|
||||
@ -657,7 +733,9 @@ $(document).ready(function () {
|
||||
|
||||
// hiding current section of the wizard and showing next section.
|
||||
$("." + currentStep).addClass("hidden");
|
||||
$("." + nextStep).removeClass("hidden");
|
||||
if (nextStep !== "policy-message") {
|
||||
$("." + nextStep).removeClass("hidden");
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
{{css "css/codemirror.css"}}
|
||||
{{/zone}}
|
||||
<span id="platform" class="hidden" data-platform="{{type.name}}" data-platform-id="{{type.id}}"
|
||||
data-platform-label="{{type.label}}"></span>
|
||||
data-platform-label="{{type.label}}" data-username="{{username}}"></span>
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="wr-steps hidden">
|
||||
@ -23,7 +23,7 @@
|
||||
<div class="col-md-3 col-xs-3">
|
||||
<div class="itm-wiz" data-step="policy-criteria">
|
||||
<div class="wiz-no">3</div>
|
||||
<div class="wiz-lbl hidden-xs"><span>Assign to groups</span></div>
|
||||
<div class="wiz-lbl hidden-xs"><span>Assign</span></div>
|
||||
</div>
|
||||
<br class="c-both"/>
|
||||
</div>
|
||||
@ -130,48 +130,80 @@
|
||||
<hr>
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<h4>Step 3: Assign to groups</h4>
|
||||
<h4>Step 3: Assign</h4>
|
||||
<br>
|
||||
|
||||
<div>
|
||||
<div class="wr-input-control">
|
||||
<label class="wr-input-control radio light">
|
||||
<input id="user-roles-radio-btn" type="radio"
|
||||
name="select-users-radio-btn" class="select-users-radio"
|
||||
checked/>
|
||||
<span class="helper"> Set user role(s)</span>
|
||||
</label>
|
||||
<label class="wr-input-control radio light" rel="assetfilter">
|
||||
<input id="users-radio-btn" type="radio"
|
||||
name="select-users-radio-btn"
|
||||
class="select-users-radio"/>
|
||||
<span class="helper"> Set user(s)</span>
|
||||
</label>
|
||||
{{#if permissions.LIST_ROLES}}
|
||||
<label class="wr-input-control radio light">
|
||||
<input id="user-roles-radio-btn" type="radio"
|
||||
name="select-users-radio-btn" class="select-users-radio"
|
||||
checked/>
|
||||
<span class="helper"> Set user role(s)</span>
|
||||
</label>
|
||||
{{/if}}
|
||||
{{#if permissions.LIST_USERS}}
|
||||
<label class="wr-input-control radio light" rel="assetfilter">
|
||||
<input id="users-radio-btn" type="radio"
|
||||
name="select-users-radio-btn"
|
||||
class="select-users-radio"/>
|
||||
<span class="helper"> Set user(s)</span>
|
||||
</label>
|
||||
{{/if}}
|
||||
<!--
|
||||
{{#if permissions.LIST_GROUPS}}
|
||||
<label class="wr-input-control radio light" rel="assetfilter">
|
||||
<input id="groups-radio-btn" type="radio"
|
||||
name="select-users-radio-btn"
|
||||
class="select-users-radio"/>
|
||||
<span class="helper"> Set groups(s)</span>
|
||||
</label>
|
||||
{{/if}}
|
||||
-->
|
||||
</div>
|
||||
<div id="user-roles-select-field" class="select-users">
|
||||
<div class="wr-input-control">
|
||||
<div class="cus-col-50">
|
||||
<select id="user-roles-input" class="form-control select2"
|
||||
multiple="multiple">
|
||||
<option value="ANY" selected>ANY</option>
|
||||
{{#each roles}}
|
||||
<option>{{this}}</option>
|
||||
{{/each}}
|
||||
</select>
|
||||
{{#if permissions.LIST_ROLES}}
|
||||
<div id="user-roles-select-field" class="select-users">
|
||||
<div class="wr-input-control">
|
||||
<div class="cus-col-50">
|
||||
<select id="user-roles-input" class="form-control select2"
|
||||
multiple="multiple">
|
||||
<option value="ANY" selected>ANY</option>
|
||||
{{#each roles}}
|
||||
<option>{{this}}</option>
|
||||
{{/each}}
|
||||
</select>
|
||||
</div>
|
||||
<br class="c-both"/>
|
||||
</div>
|
||||
<br class="c-both"/>
|
||||
</div>
|
||||
</div>
|
||||
<div id="users-select-field" class="select-users">
|
||||
<div class="wr-input-control">
|
||||
<div class="cus-col-50">
|
||||
<select id="users-input" class="form-control select2"
|
||||
multiple="multiple">
|
||||
</select>
|
||||
{{/if}}
|
||||
{{#if permissions.LIST_USERS}}
|
||||
<div id="users-select-field" class="select-users">
|
||||
<div class="wr-input-control">
|
||||
<div class="cus-col-50">
|
||||
<select id="users-input" class="form-control select2"
|
||||
multiple="multiple">
|
||||
</select>
|
||||
</div>
|
||||
<br class="c-both"/>
|
||||
</div>
|
||||
<br class="c-both"/>
|
||||
</div>
|
||||
</div>
|
||||
{{/if}}
|
||||
<!--
|
||||
{{#if permissions.LIST_GROUPS}}
|
||||
<div id="groups-select-field" class="select-users">
|
||||
<div class="wr-input-control">
|
||||
<div class="cus-col-50">
|
||||
<select id="groups-input" class="form-control select2"
|
||||
multiple="multiple">
|
||||
</select>
|
||||
</div>
|
||||
<br class="c-both"/>
|
||||
</div>
|
||||
</div>
|
||||
{{/if}}
|
||||
-->
|
||||
<br>
|
||||
<label class="wr-input-label" title="">
|
||||
Set an action upon non-compliance
|
||||
@ -237,7 +269,7 @@
|
||||
<a href="javascript:void(0)" class="wr-btn wizard-stepper"
|
||||
data-current="policy-profile" data-next="policy-criteria"
|
||||
data-validate="true">
|
||||
Continue
|
||||
Continue
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -18,6 +18,7 @@
|
||||
|
||||
function onRequest(context) {
|
||||
//var log = new Log("wizard.js");
|
||||
var constants = require("/app/modules/constants.js");
|
||||
var DTYPE_CONF_DEVICE_TYPE_KEY = "deviceType";
|
||||
var DTYPE_CONF_DEVICE_TYPE_LABEL_KEY = "label";
|
||||
|
||||
@ -43,5 +44,8 @@ function onRequest(context) {
|
||||
}
|
||||
}
|
||||
}
|
||||
var user = session.get(constants.USER_SESSION_KEY);
|
||||
wizardPage.username = user.username;
|
||||
wizardPage.permissions = userModule.getUIPermissions();
|
||||
return wizardPage;
|
||||
}
|
||||
@ -37,7 +37,7 @@ public class RaspberrypiConstants {
|
||||
//type of the sensor
|
||||
public static final String SENSOR_TEMPERATURE = "temperature";
|
||||
//sensor events summerized table name
|
||||
public static final String TEMPERATURE_EVENT_TABLE = "ORG_WSO2_IOT_DEVICES_TEMPERATURE";
|
||||
public static final String TEMPERATURE_EVENT_TABLE = "DEVICE_TEMPERATURE_SUMMARY";
|
||||
public static final String DATA_SOURCE_NAME = "jdbc/RaspberryPiDM_DB";
|
||||
public final static String DEVICE_TYPE_PROVIDER_DOMAIN = "carbon.super";
|
||||
|
||||
|
||||
@ -39,10 +39,10 @@ public class AgentConstants {
|
||||
|
||||
public static final String AGENT_CONTROL_APP_EP = "/devicemgt/device/%s?id=%s";
|
||||
public static final String DEVICE_DETAILS_PAGE_EP = "/devicemgt/device/%s?id=%s";
|
||||
public static final String DEVICE_ANALYTICS_PAGE_URL = "/devicemgt/analytics?deviceId=%s&deviceType=%s&deviceName=%s";
|
||||
public static final String DEVICE_ANALYTICS_PAGE_URL = "/devicemgt/device/virtual_firealarm/analytics?deviceId=%s&deviceName=%s";
|
||||
/* ---------------------------------------------------------------------------------------
|
||||
HTTP Connection specific information for communicating with IoT-Server
|
||||
--------------------------------------------------------------------------------------- */
|
||||
HTTP Connection specific information for communicating with IoT-Server
|
||||
--------------------------------------------------------------------------------------- */
|
||||
public static final String HTTP_POST = "POST";
|
||||
public static final String HTTP_GET = "GET";
|
||||
public static final String APPLICATION_JSON_TYPE = "application/json";
|
||||
|
||||
@ -101,7 +101,6 @@ public class AgentManager {
|
||||
|
||||
String analyticsPageContext = String.format(AgentConstants.DEVICE_ANALYTICS_PAGE_URL,
|
||||
agentConfigs.getDeviceId(),
|
||||
AgentConstants.DEVICE_TYPE,
|
||||
agentConfigs.getDeviceName());
|
||||
|
||||
String controlPageContext = String.format(AgentConstants.DEVICE_DETAILS_PAGE_EP,
|
||||
|
||||
@ -38,7 +38,8 @@ public class AgentConstants {
|
||||
|
||||
public static final String AGENT_CONTROL_APP_EP = "/devicemgt/device/%s?id=%s";
|
||||
public static final String DEVICE_DETAILS_PAGE_EP = "/devicemgt/device/%s?id=%s";
|
||||
public static final String DEVICE_ANALYTICS_PAGE_URL = "/devicemgt/analytics?deviceId=%s&deviceType=%s&deviceName=%s";
|
||||
public static final String DEVICE_ANALYTICS_PAGE_URL = "/devicemgt/device/virtual_firealarm/analytics?deviceId=%s&deviceName=%s";
|
||||
|
||||
/* ---------------------------------------------------------------------------------------
|
||||
HTTP Connection specific information for communicating with IoT-Server
|
||||
--------------------------------------------------------------------------------------- */
|
||||
|
||||
@ -89,7 +89,6 @@ public class AgentManager {
|
||||
|
||||
String analyticsPageContext = String.format(AgentConstants.DEVICE_ANALYTICS_PAGE_URL,
|
||||
agentConfigs.getDeviceId(),
|
||||
AgentConstants.DEVICE_TYPE,
|
||||
agentConfigs.getDeviceName());
|
||||
|
||||
String controlPageContext = String.format(AgentConstants.DEVICE_DETAILS_PAGE_EP,
|
||||
|
||||
@ -53,7 +53,6 @@ public interface VirtualFireAlarmService {
|
||||
@Feature(code = "buzz", name = "Buzzer On / Off", description = "Switch on/off Virtual Fire Alarm Buzzer. (On / Off)")
|
||||
Response switchBuzzer(@PathParam("deviceId") String deviceId, @QueryParam("protocol") String protocol,
|
||||
@FormParam("state") String state);
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve Sensor data for the device type
|
||||
|
||||
@ -34,6 +34,9 @@ import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
||||
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException;
|
||||
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation;
|
||||
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.exception.VirtualFirealarmDeviceMgtPluginException;
|
||||
@ -51,30 +54,18 @@ import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo;
|
||||
import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException;
|
||||
import org.wso2.carbon.user.api.UserStoreException;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.FormParam;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.PrivateKey;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
public class VirtualFireAlarmServiceImpl implements VirtualFireAlarmService {
|
||||
|
||||
private static final String XMPP_PROTOCOL = "XMPP";
|
||||
private static final String MQTT_PROTOCOL = "MQTT";
|
||||
private static final String KEY_TYPE = "PRODUCTION";
|
||||
private static ApiApplicationKey apiApplicationKey;
|
||||
private static Log log = LogFactory.getLog(VirtualFireAlarmServiceImpl.class);
|
||||
@ -83,13 +74,24 @@ public class VirtualFireAlarmServiceImpl implements VirtualFireAlarmService {
|
||||
@Path("device/{deviceId}/buzz")
|
||||
public Response switchBuzzer(@PathParam("deviceId") String deviceId, @QueryParam("protocol") String protocol,
|
||||
@FormParam("state") String state) {
|
||||
if (state == null || state.isEmpty()) {
|
||||
log.error("State is not defined for the buzzer operation");
|
||||
return Response.status(Response.Status.BAD_REQUEST).build();
|
||||
}
|
||||
String switchToState = state.toUpperCase();
|
||||
if (!switchToState.equals(VirtualFireAlarmConstants.STATE_ON) && !switchToState.equals(
|
||||
VirtualFireAlarmConstants.STATE_OFF)) {
|
||||
log.error("The requested state change shoud be either - 'ON' or 'OFF'");
|
||||
return Response.status(Response.Status.BAD_REQUEST).build();
|
||||
}
|
||||
String protocolString = protocol.toUpperCase();
|
||||
String protocolString;
|
||||
|
||||
if (protocol == null || protocol.isEmpty()) {
|
||||
protocolString = MQTT_PROTOCOL;
|
||||
} else {
|
||||
protocolString = protocol.toUpperCase();
|
||||
}
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Sending request to switch-bulb of device [" + deviceId + "] via " +
|
||||
protocolString);
|
||||
@ -122,6 +124,19 @@ public class VirtualFireAlarmServiceImpl implements VirtualFireAlarmService {
|
||||
dynamicProperties.put(VirtualFireAlarmConstants.ADAPTER_TOPIC_PROPERTY, publishTopic);
|
||||
APIUtil.getOutputEventAdapterService().publish(VirtualFireAlarmConstants.MQTT_ADAPTER_NAME,
|
||||
dynamicProperties, encryptedMsg);
|
||||
Operation commandOp = new CommandOperation();
|
||||
commandOp.setCode("buzz");
|
||||
commandOp.setType(Operation.Type.COMMAND);
|
||||
commandOp.setEnabled(true);
|
||||
commandOp.setPayLoad(encryptedMsg);
|
||||
|
||||
Properties props = new Properties();
|
||||
props.setProperty(VirtualFireAlarmConstants.MQTT_ADAPTER_TOPIC_PROPERTY_NAME, publishTopic);
|
||||
commandOp.setProperties(props);
|
||||
|
||||
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>();
|
||||
deviceIdentifiers.add(new DeviceIdentifier(deviceId, VirtualFireAlarmConstants.DEVICE_TYPE));
|
||||
APIUtil.getDeviceManagementService().addOperation(VirtualFireAlarmConstants.DEVICE_TYPE, commandOp, deviceIdentifiers);
|
||||
break;
|
||||
}
|
||||
return Response.ok().build();
|
||||
@ -132,6 +147,10 @@ public class VirtualFireAlarmServiceImpl implements VirtualFireAlarmService {
|
||||
String errorMsg = "Preparing Secure payload failed for device - [" + deviceId + "]";
|
||||
log.error(errorMsg);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
||||
} catch (OperationManagementException e) {
|
||||
String msg = "Error occurred while executing command operation upon ringing the buzzer";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -37,7 +37,7 @@
|
||||
</Permission>
|
||||
<Permission>
|
||||
<name>Control Buzz</name>
|
||||
<path>/device-mgt/user/operations</path>
|
||||
<path>/device-mgt/user/operation</path>
|
||||
<url>/device/*/buzz</url>
|
||||
<method>POST</method>
|
||||
<scope>virtual_firealarm_user</scope>
|
||||
@ -47,6 +47,6 @@
|
||||
<path>/device-mgt/user/stats</path>
|
||||
<url>/device/stats/*</url>
|
||||
<method>GET</method>
|
||||
<scope>virtual_firealarm_device</scope>
|
||||
<scope>virtual_firealarm_user</scope>
|
||||
</Permission>
|
||||
</PermissionConfiguration>
|
||||
@ -88,7 +88,11 @@
|
||||
org.wso2.carbon.device.mgt.analytics.data.publisher.service,
|
||||
org.wso2.carbon.event.input.adapter.core,
|
||||
org.wso2.carbon.event.input.adapter.core.exception,
|
||||
org.jivesoftware.smack.*
|
||||
org.jivesoftware.smack.*,
|
||||
javax.xml.bind,
|
||||
javax.xml.bind.annotation,
|
||||
javax.xml.parsers,
|
||||
org.w3c.dom
|
||||
</Import-Package>
|
||||
<Export-Package>
|
||||
!org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.internal,
|
||||
|
||||
@ -90,4 +90,6 @@ public class VirtualFireAlarmConstants {
|
||||
+ "mqtt.properties";
|
||||
public static final String XMPP_CONFIG_LOCATION = CarbonUtils.getEtcCarbonConfigDirPath() + File.separator
|
||||
+ "xmpp.properties";
|
||||
|
||||
public static final String MQTT_ADAPTER_TOPIC_PROPERTY_NAME = "mqtt.adapter.topic";
|
||||
}
|
||||
|
||||
@ -25,10 +25,15 @@ import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
|
||||
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
|
||||
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
|
||||
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.constants.VirtualFireAlarmConstants;
|
||||
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.internal.config.VirtualFireAlarmConfig;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class VirtualFireAlarmManagerService implements DeviceManagementService {
|
||||
|
||||
private DeviceManager deviceManager;
|
||||
private PushNotificationConfig pushNotificationConfig;
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
@ -38,6 +43,18 @@ public class VirtualFireAlarmManagerService implements DeviceManagementService {
|
||||
@Override
|
||||
public void init() throws DeviceManagementException {
|
||||
this.deviceManager = new VirtualFireAlarmManager();
|
||||
this.pushNotificationConfig = this.populatePushNotificationConfig();
|
||||
}
|
||||
|
||||
private PushNotificationConfig populatePushNotificationConfig() {
|
||||
org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.internal.config.PushNotificationConfig sourceConfig =
|
||||
VirtualFireAlarmConfig.getInstance().getPushNotificationConfig();
|
||||
Map<String, String> staticProps = new HashMap<>();
|
||||
for (org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.internal.config.PushNotificationConfig.Property
|
||||
property : sourceConfig.getProperties()) {
|
||||
staticProps.put(property.getName(), property.getValue());
|
||||
}
|
||||
return new PushNotificationConfig("MQTT", staticProps);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -57,7 +74,7 @@ public class VirtualFireAlarmManagerService implements DeviceManagementService {
|
||||
|
||||
@Override
|
||||
public PushNotificationConfig getPushNotificationConfig() {
|
||||
return null;
|
||||
return pushNotificationConfig;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -32,6 +32,7 @@ import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl.VirtualFireAl
|
||||
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl.util.VirtualFireAlarmUtils;
|
||||
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl.util.VirtualFirealarmSecurityManager;
|
||||
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl.util.VirtualFirealarmStartupListener;
|
||||
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.internal.config.VirtualFireAlarmConfig;
|
||||
import org.wso2.carbon.event.input.adapter.core.InputEventAdapterService;
|
||||
import org.wso2.carbon.event.output.adapter.core.OutputEventAdapterService;
|
||||
|
||||
@ -74,6 +75,9 @@ public class VirtualFirealarmManagementServiceComponent {
|
||||
log.debug("Activating Virtual Firealarm Device Management Service Component");
|
||||
}
|
||||
try {
|
||||
/* Initializing Virtual Fire Alarm Configuration */
|
||||
VirtualFireAlarmConfig.init();
|
||||
|
||||
VirtualFireAlarmManagerService virtualFireAlarmManagerService = new VirtualFireAlarmManagerService();
|
||||
BundleContext bundleContext = ctx.getBundleContext();
|
||||
firealarmServiceRegRef = bundleContext.registerService(DeviceManagementService.class.getName()
|
||||
|
||||
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 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.iot.virtualfirealarm.plugin.internal.config;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
/**
|
||||
* Class for holding data source configuration in malformed-cdm-config-no-mgt-repo.xml at parsing
|
||||
* with JAXB.
|
||||
*/
|
||||
@XmlRootElement(name = "DataSourceConfiguration")
|
||||
public class DataSourceConfig {
|
||||
|
||||
private JNDILookupDefinition jndiLookupDefinition;
|
||||
|
||||
@XmlElement(name = "JndiLookupDefinition", required = true)
|
||||
public JNDILookupDefinition getJndiLookupDefinition() {
|
||||
return jndiLookupDefinition;
|
||||
}
|
||||
|
||||
public void setJndiLookupDefinition(JNDILookupDefinition jndiLookupDefinition) {
|
||||
this.jndiLookupDefinition = jndiLookupDefinition;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 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.iot.virtualfirealarm.plugin.internal.config;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
/**
|
||||
* Class for holding management repository data.
|
||||
*/
|
||||
@XmlRootElement(name = "ManagementRepository")
|
||||
public class DeviceManagementConfigRepository {
|
||||
|
||||
private DataSourceConfig dataSourceConfig;
|
||||
|
||||
@XmlElement(name = "DataSourceConfiguration", required = true)
|
||||
public DataSourceConfig getDataSourceConfig() {
|
||||
return dataSourceConfig;
|
||||
}
|
||||
|
||||
public void setDataSourceConfig(DataSourceConfig dataSourceConfig) {
|
||||
this.dataSourceConfig = dataSourceConfig;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 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.iot.virtualfirealarm.plugin.internal.config;
|
||||
|
||||
import javax.xml.bind.annotation.*;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Class for hold JndiLookupDefinition of rss-manager.xml at parsing with JAXB.
|
||||
*/
|
||||
@XmlRootElement(name = "JndiLookupDefinition")
|
||||
public class JNDILookupDefinition {
|
||||
|
||||
private String jndiName;
|
||||
private List<JNDIProperty> jndiProperties;
|
||||
|
||||
@XmlElement(name = "Name", required = false)
|
||||
public String getJndiName() {
|
||||
return jndiName;
|
||||
}
|
||||
|
||||
public void setJndiName(String jndiName) {
|
||||
this.jndiName = jndiName;
|
||||
}
|
||||
|
||||
@XmlElementWrapper(name = "Environment", required = false)
|
||||
@XmlElement(name = "Property", nillable = false)
|
||||
public List<JNDIProperty> getJndiProperties() {
|
||||
return jndiProperties;
|
||||
}
|
||||
|
||||
public void setJndiProperties(List<JNDIProperty> jndiProperties) {
|
||||
this.jndiProperties = jndiProperties;
|
||||
}
|
||||
|
||||
@XmlRootElement(name = "Property")
|
||||
public static class JNDIProperty {
|
||||
|
||||
private String name;
|
||||
|
||||
private String value;
|
||||
|
||||
@XmlAttribute(name = "Name")
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@XmlValue
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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.iot.virtualfirealarm.plugin.internal.config;
|
||||
|
||||
import javax.xml.bind.annotation.*;
|
||||
import java.util.List;
|
||||
|
||||
@XmlRootElement(name = "PushNotificationConfiguration")
|
||||
public class PushNotificationConfig {
|
||||
|
||||
private List<Property> properties;
|
||||
|
||||
@XmlElementWrapper(name = "Properties", required = true)
|
||||
@XmlElement(name = "Property", required = true)
|
||||
public List<Property> getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
public void setProperties(List<Property> properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
@XmlRootElement(name = "Property")
|
||||
public static class Property {
|
||||
|
||||
private String name;
|
||||
private String value;
|
||||
|
||||
@XmlAttribute(name = "Name", required = true)
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@XmlValue
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,93 @@
|
||||
/*
|
||||
* 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.iot.virtualfirealarm.plugin.internal.config;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.w3c.dom.Document;
|
||||
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.internal.config.exception.InvalidConfigurationStateException;
|
||||
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.internal.config.exception.VirtualFireAlarmConfigurationException;
|
||||
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.internal.util.VirtualFireAlarmUtil;
|
||||
import org.wso2.carbon.utils.CarbonUtils;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import java.io.File;
|
||||
|
||||
@XmlRootElement(name = "DeviceManagementConfiguration")
|
||||
public class VirtualFireAlarmConfig {
|
||||
|
||||
private DeviceManagementConfigRepository deviceManagementConfigRepository;
|
||||
private PushNotificationConfig pushNotificationConfig;
|
||||
private static VirtualFireAlarmConfig config;
|
||||
|
||||
private static final Log log = LogFactory.getLog(VirtualFireAlarmConfig.class);
|
||||
private static final String VIRTUAL_FIRE_ALARM_CONFIG_PATH =
|
||||
CarbonUtils.getEtcCarbonConfigDirPath() + File.separator + "device-mgt-plugins" + File.separator +
|
||||
"virtual-fire-alarm" + File.separator + "virtual-fire-alarm-config.xml";
|
||||
|
||||
private VirtualFireAlarmConfig() {
|
||||
}
|
||||
|
||||
public static VirtualFireAlarmConfig getInstance() {
|
||||
if (config == null) {
|
||||
throw new InvalidConfigurationStateException("Webapp Authenticator Configuration is not " +
|
||||
"initialized properly");
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
@XmlElement(name = "ManagementRepository", required = true)
|
||||
public DeviceManagementConfigRepository getDeviceManagementConfigRepository() {
|
||||
return deviceManagementConfigRepository;
|
||||
}
|
||||
|
||||
public void setDeviceManagementConfigRepository(DeviceManagementConfigRepository deviceManagementConfigRepository) {
|
||||
this.deviceManagementConfigRepository = deviceManagementConfigRepository;
|
||||
}
|
||||
|
||||
@XmlElement(name = "PushNotificationConfiguration", required = false)
|
||||
public PushNotificationConfig getPushNotificationConfig() {
|
||||
return pushNotificationConfig;
|
||||
}
|
||||
|
||||
public void setPushNotificationConfig(PushNotificationConfig pushNotificationConfig) {
|
||||
this.pushNotificationConfig = pushNotificationConfig;
|
||||
}
|
||||
|
||||
public static void init() throws VirtualFireAlarmConfigurationException {
|
||||
try {
|
||||
File authConfig = new File(VirtualFireAlarmConfig.VIRTUAL_FIRE_ALARM_CONFIG_PATH);
|
||||
Document doc = VirtualFireAlarmUtil.convertToDocument(authConfig);
|
||||
|
||||
/* Un-marshaling Webapp Authenticator configuration */
|
||||
JAXBContext ctx = JAXBContext.newInstance(VirtualFireAlarmConfig.class);
|
||||
Unmarshaller unmarshaller = ctx.createUnmarshaller();
|
||||
//unmarshaller.setSchema(getSchema());
|
||||
config = (VirtualFireAlarmConfig) unmarshaller.unmarshal(doc);
|
||||
} catch (JAXBException e) {
|
||||
throw new VirtualFireAlarmConfigurationException("Error occurred while un-marshalling Virtual Fire Alarm " +
|
||||
" Config", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.internal.config.exception;
|
||||
|
||||
public class InvalidConfigurationStateException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = -3151279411229070297L;
|
||||
|
||||
public InvalidConfigurationStateException(int errorCode, String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public InvalidConfigurationStateException(int errorCode, String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public InvalidConfigurationStateException(String msg, Exception nestedEx) {
|
||||
super(msg, nestedEx);
|
||||
}
|
||||
|
||||
public InvalidConfigurationStateException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public InvalidConfigurationStateException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public InvalidConfigurationStateException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public InvalidConfigurationStateException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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.iot.virtualfirealarm.plugin.internal.config.exception;
|
||||
|
||||
public class VirtualFireAlarmConfigurationException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = -3151279431229070297L;
|
||||
|
||||
public VirtualFireAlarmConfigurationException(int errorCode, String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public VirtualFireAlarmConfigurationException(int errorCode, String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public VirtualFireAlarmConfigurationException(String msg, Exception nestedEx) {
|
||||
super(msg, nestedEx);
|
||||
}
|
||||
|
||||
public VirtualFireAlarmConfigurationException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public VirtualFireAlarmConfigurationException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public VirtualFireAlarmConfigurationException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public VirtualFireAlarmConfigurationException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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.iot.virtualfirealarm.plugin.internal.util;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.internal.config.exception.VirtualFireAlarmConfigurationException;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import java.io.File;
|
||||
|
||||
public class VirtualFireAlarmUtil {
|
||||
|
||||
public static Document convertToDocument(File file) throws VirtualFireAlarmConfigurationException {
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
factory.setNamespaceAware(true);
|
||||
try {
|
||||
DocumentBuilder docBuilder = factory.newDocumentBuilder();
|
||||
return docBuilder.parse(file);
|
||||
} catch (Exception e) {
|
||||
throw new VirtualFireAlarmConfigurationException("Error occurred while parsing file, while converting " +
|
||||
"to a org.w3c.dom.Document", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -35,21 +35,6 @@ function setPopupMaxHeight() {
|
||||
function showAgentDownloadPopup() {
|
||||
$(modalPopup).show();
|
||||
setPopupMaxHeight();
|
||||
$('#downloadForm').validate({
|
||||
rules: {
|
||||
deviceName: {
|
||||
minlength: 4,
|
||||
required: true
|
||||
}
|
||||
},
|
||||
highlight: function (element) {
|
||||
$(element).closest('.control-group').removeClass('success').addClass('error');
|
||||
},
|
||||
success: function (element) {
|
||||
$(element).closest('.control-group').removeClass('error').addClass('success');
|
||||
$('label[for=deviceName]').remove();
|
||||
}
|
||||
});
|
||||
var deviceType = "";
|
||||
$('.deviceType').each(function () {
|
||||
if (this.value != "") {
|
||||
@ -88,43 +73,6 @@ function attachEvents() {
|
||||
var payload = {"sketchType": sketchType, "deviceType": deviceType};
|
||||
$(modalPopupContent).html($('#download-device-modal-content').html());
|
||||
showAgentDownloadPopup();
|
||||
var deviceName;
|
||||
$("a#download-device-download-link").click(function () {
|
||||
$('.new-device-name').each(function () {
|
||||
if (this.value != "") {
|
||||
deviceName = this.value;
|
||||
}
|
||||
});
|
||||
$('label[for=deviceName]').remove();
|
||||
if (deviceName && deviceName.length >= 4) {
|
||||
payload.deviceName = deviceName;
|
||||
invokerUtil.post(
|
||||
downloadDeviceAPI,
|
||||
payload,
|
||||
function (data, textStatus, jqxhr) {
|
||||
doAction(data);
|
||||
},
|
||||
function (data) {
|
||||
doAction(data);
|
||||
}
|
||||
);
|
||||
} else if (deviceName) {
|
||||
$('.controls').append('<label for="deviceName" generated="true" class="error" ' +
|
||||
'style="display: inline-block;">Please enter at least 4 ' +
|
||||
'characters.</label>');
|
||||
$('.control-group').removeClass('success').addClass('error');
|
||||
} else {
|
||||
$('.controls').append('<label for="deviceName" generated="true" class="error" ' +
|
||||
'style="display: inline-block;">This field is required.' +
|
||||
'</label>');
|
||||
$('.control-group').removeClass('success').addClass('error');
|
||||
}
|
||||
});
|
||||
|
||||
$("a#download-device-cancel-link").click(function () {
|
||||
hideAgentDownloadPopup();
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@ -136,7 +84,10 @@ function downloadAgent() {
|
||||
}
|
||||
});
|
||||
var deviceNameFormat = /^[^~?!#$:;%^*`+={}\[\]\\()|<>,'"]{1,30}$/;
|
||||
if (deviceName && deviceNameFormat.test(deviceName)) {
|
||||
if (deviceName && deviceName.length < 4) {
|
||||
$("#invalid-username-error-msg span").text("Device name should be more than 3 letters!");
|
||||
$("#invalid-username-error-msg").removeClass("hidden");
|
||||
} else if (deviceName && deviceNameFormat.test(deviceName)) {
|
||||
$('#downloadForm').submit();
|
||||
hidePopup();
|
||||
$(modalPopupContent).html($('#device-agent-downloading-content').html());
|
||||
|
||||
@ -29,8 +29,11 @@ import org.wso2.carbon.analytics.datasource.commons.Record;
|
||||
import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException;
|
||||
import org.wso2.carbon.context.CarbonContext;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
<<<<<<< HEAD
|
||||
import org.wso2.carbon.device.mgt.analytics.data.publisher.service.EventsPublisherService;
|
||||
import org.wso2.carbon.device.mgt.common.Device;
|
||||
=======
|
||||
>>>>>>> 344232fc3287dc7566624756aa2ea17d7874dcf9
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
@ -45,8 +48,11 @@ import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceDetailsMgtExcept
|
||||
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager;
|
||||
import org.wso2.carbon.device.mgt.core.search.mgt.impl.Utils;
|
||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||
<<<<<<< HEAD
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.android.gcm.GCMService;
|
||||
import org.wso2.carbon.mdm.services.android.bean.DeviceState;
|
||||
=======
|
||||
>>>>>>> 344232fc3287dc7566624756aa2ea17d7874dcf9
|
||||
import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException;
|
||||
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
||||
|
||||
@ -93,16 +99,16 @@ public class AndroidAPIUtils {
|
||||
return deviceManagementProviderService;
|
||||
}
|
||||
|
||||
public static GCMService getGCMService() {
|
||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||
GCMService gcmService = (GCMService) ctx.getOSGiService(GCMService.class, null);
|
||||
if (gcmService == null) {
|
||||
String msg = "GCM service has not initialized.";
|
||||
log.error(msg);
|
||||
throw new IllegalStateException(msg);
|
||||
}
|
||||
return gcmService;
|
||||
}
|
||||
// public static GCMService getGCMService() {
|
||||
// PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||
// GCMService gcmService = (GCMService) ctx.getOSGiService(GCMService.class, null);
|
||||
// if (gcmService == null) {
|
||||
// String msg = "GCM service has not initialized.";
|
||||
// log.error(msg);
|
||||
// throw new IllegalStateException(msg);
|
||||
// }
|
||||
// return gcmService;
|
||||
// }
|
||||
|
||||
public static MediaType getResponseMediaType(String acceptHeader) {
|
||||
MediaType responseMediaType;
|
||||
|
||||
@ -1,4 +1,8 @@
|
||||
{
|
||||
"version": "1.0.0",
|
||||
"extends": "cdmf.unit.device.operation-mod"
|
||||
"version": "1.0.0",
|
||||
"pushedUris": [
|
||||
"/policies",
|
||||
"/policy/{+any}"
|
||||
],
|
||||
"extends": "cdmf.unit.device.operation-mod"
|
||||
}
|
||||
@ -134,7 +134,7 @@ public class WindowsAPIUtils {
|
||||
WindowsDeviceUtils deviceUtils = new WindowsDeviceUtils();
|
||||
DeviceIDHolder deviceIDHolder = deviceUtils.validateDeviceIdentifiers(deviceIDs,
|
||||
message, responseMediaType);
|
||||
getDeviceManagementService().addOperation(operation, deviceIDHolder.getValidDeviceIDList());
|
||||
getDeviceManagementService().addOperation("windows", operation, deviceIDHolder.getValidDeviceIDList());
|
||||
if (!deviceIDHolder.getErrorDeviceIdList().isEmpty()) {
|
||||
return javax.ws.rs.core.Response.status(PluginConstants.StatusCodes.
|
||||
MULTI_STATUS_HTTP_CODE).type(
|
||||
|
||||
@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
<DeviceManagementConfiguration>
|
||||
<ManagementRepository>
|
||||
<DataSourceConfigurations>
|
||||
<DataSourceConfiguration>
|
||||
<JndiLookupDefinition>
|
||||
<Name>jdbc/VirtualFireAlarmDM_DB</Name>
|
||||
</JndiLookupDefinition>
|
||||
</DataSourceConfiguration>
|
||||
</DataSourceConfigurations>
|
||||
</ManagementRepository>
|
||||
<PushNotificationConfiguration>
|
||||
<Properties>
|
||||
<Property Name="url">tcp://${mqtt.broker.host}:${mqtt.broker.port}</Property>
|
||||
<Property Name="username">admin</Property>
|
||||
<Property Name="dcrUrl">https://localhost:${carbon.https.port}/dynamic-client-web/register</Property>
|
||||
<Property Name="qos">0</Property>
|
||||
<Property Name="scopes"/>
|
||||
<Property Name="clearSession">true</Property>
|
||||
</Properties>
|
||||
</PushNotificationConfiguration>
|
||||
</DeviceManagementConfiguration>
|
||||
@ -15,6 +15,7 @@ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../featur
|
||||
org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../resources/security/);\
|
||||
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.iot.virtualfirealarm_${feature.version}/certs/,target:${installFolder}/../../resources/security/,overwrite:true);\
|
||||
org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../resources/device-types/);\
|
||||
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.iot.virtualfirealarm_${feature.version}/conf/virtual-fire-alarm-config.xml,target:${installFolder}/../../conf/etc/device-mgt-plugins/virtual-fire-alarm/virtual-fire-alarm-config.xml,overwrite:true);\
|
||||
|
||||
instructions.unconfigure = \
|
||||
org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/webapps/virtual_firealarm.war);\
|
||||
|
||||
Loading…
Reference in New Issue
Block a user