mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Merge pull request #423 from ayyoob/IoTS-1.0.0
few changes in feature manager implementation for deployer
This commit is contained in:
commit
906d870309
@ -42,10 +42,6 @@ public class ConfigurationBasedFeatureManager implements FeatureManager {
|
|||||||
private static final String QUERY_PARAMS = "queryParams";
|
private static final String QUERY_PARAMS = "queryParams";
|
||||||
private static final String FORM_PARAMS = "formParams";
|
private static final String FORM_PARAMS = "formParams";
|
||||||
private static final Pattern PATH_PARAM_REGEX = Pattern.compile("\\{(.*?)\\}");
|
private static final Pattern PATH_PARAM_REGEX = Pattern.compile("\\{(.*?)\\}");
|
||||||
private List<String> pathParams = new ArrayList<>();
|
|
||||||
private List<String> queryParams = new ArrayList<>();
|
|
||||||
private List<String> formParams = new ArrayList<>();
|
|
||||||
|
|
||||||
|
|
||||||
public ConfigurationBasedFeatureManager(
|
public ConfigurationBasedFeatureManager(
|
||||||
List<org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.Feature> features) {
|
List<org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.Feature> features) {
|
||||||
@ -59,7 +55,10 @@ public class ConfigurationBasedFeatureManager implements FeatureManager {
|
|||||||
Map<String, Object> apiParams = new HashMap<>();
|
Map<String, Object> apiParams = new HashMap<>();
|
||||||
apiParams.put(METHOD, operation.getMethod().toUpperCase());
|
apiParams.put(METHOD, operation.getMethod().toUpperCase());
|
||||||
apiParams.put(URI, operation.getContext());
|
apiParams.put(URI, operation.getContext());
|
||||||
setPathParams(operation.getContext());
|
List<String> pathParams = new ArrayList<>();
|
||||||
|
List<String> queryParams = new ArrayList<>();
|
||||||
|
List<String> formParams = new ArrayList<>();
|
||||||
|
setPathParams(operation.getContext(), pathParams);
|
||||||
apiParams.put(PATH_PARAMS, pathParams);
|
apiParams.put(PATH_PARAMS, pathParams);
|
||||||
if (operation.getQueryParameters() != null) {
|
if (operation.getQueryParameters() != null) {
|
||||||
queryParams = operation.getQueryParameters().getParameter();
|
queryParams = operation.getQueryParameters().getParameter();
|
||||||
@ -116,7 +115,7 @@ public class ConfigurationBasedFeatureManager implements FeatureManager {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setPathParams(String context) {
|
private void setPathParams(String context, List<String> pathParams) {
|
||||||
Matcher regexMatcher = PATH_PARAM_REGEX.matcher(context);
|
Matcher regexMatcher = PATH_PARAM_REGEX.matcher(context);
|
||||||
while (regexMatcher.find()) {
|
while (regexMatcher.find()) {
|
||||||
pathParams.add(regexMatcher.group(1));
|
pathParams.add(regexMatcher.group(1));
|
||||||
|
|||||||
@ -45,16 +45,6 @@ var operationModule = function () {
|
|||||||
var feature;
|
var feature;
|
||||||
for (var i = 0; i < features.length; i++) {
|
for (var i = 0; i < features.length; i++) {
|
||||||
feature = {};
|
feature = {};
|
||||||
var analyticStreams = utility.getDeviceTypeConfig(deviceType)["analyticStreams"];
|
|
||||||
if (analyticStreams) {
|
|
||||||
for (var stream in analyticStreams) {
|
|
||||||
if (analyticStreams[stream].name == features[i].name) {
|
|
||||||
feature.ui_unit = analyticStreams[stream].ui_unit;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
feature["operation"] = features[i].code;
|
feature["operation"] = features[i].code;
|
||||||
feature["name"] = features[i].name;
|
feature["name"] = features[i].name;
|
||||||
feature["description"] = features[i].description;
|
feature["description"] = features[i].description;
|
||||||
@ -80,10 +70,17 @@ var operationModule = function () {
|
|||||||
|
|
||||||
publicMethods.getControlOperations = function (deviceType) {
|
publicMethods.getControlOperations = function (deviceType) {
|
||||||
var operations = privateMethods.getOperationsFromFeatures(deviceType, "operation");
|
var operations = privateMethods.getOperationsFromFeatures(deviceType, "operation");
|
||||||
|
var features = utility.getDeviceTypeConfig(deviceType).deviceType.features;
|
||||||
for (var op in operations) {
|
for (var op in operations) {
|
||||||
var iconPath = utility.getOperationIcon(deviceType, operations[op].operation);
|
var iconIdentifier = operations[op].operation;
|
||||||
if (iconPath) {
|
if (features && features[iconIdentifier]) {
|
||||||
operations[op]["icon"] = iconPath;
|
var icon = features[iconIdentifier].icon;
|
||||||
|
if (icon) {
|
||||||
|
operations[op]["iconFont"] = icon;
|
||||||
|
} else if (iconPath) {
|
||||||
|
var iconPath = utility.getOperationIcon(deviceType, iconIdentifier);
|
||||||
|
operations[op]["icon"] = iconPath;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return operations;
|
return operations;
|
||||||
|
|||||||
@ -36,10 +36,14 @@
|
|||||||
</style>
|
</style>
|
||||||
{{#each control_operations}}
|
{{#each control_operations}}
|
||||||
<a href="javascript:operationSelect('{{operation}}')">
|
<a href="javascript:operationSelect('{{operation}}')">
|
||||||
{{#if icon}}
|
{{#if iconFont}}
|
||||||
<img src="{{@app.context}}/{{icon}}" style="width: 48px;"/>
|
<i class="fw {{iconFont}}"></i>
|
||||||
{{else}}
|
{{else}}
|
||||||
<i class="fw fw-service"></i>
|
{{#if icon}}
|
||||||
|
<img src="{{@app.context}}/{{icon}}" style="width: 48px;"/>
|
||||||
|
{{else}}
|
||||||
|
<i class="fw fw-service"></i>
|
||||||
|
{{/if}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
<span>{{name}}</span>
|
<span>{{name}}</span>
|
||||||
</a>
|
</a>
|
||||||
@ -61,7 +65,8 @@
|
|||||||
<br>
|
<br>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
<form action="{{@unit.params.backendApiUri}}{{params.0.uri}}" method="{{params.0.method}}" style="padding-bottom: 20px;" id="form-{{operation}}">
|
<form action="{{params.0.uri}}" method="{{params.0.method}}" style="padding-bottom: 20px;"
|
||||||
|
data-payload="{{payload}}" id="form-{{operation}}">
|
||||||
{{#each params.0.pathParams}}
|
{{#each params.0.pathParams}}
|
||||||
<input type="{{type}}" id="{{name}}" placeholder="{{name}}" class="form-control" data-param-type="path" value="{{value}}" />
|
<input type="{{type}}" id="{{name}}" placeholder="{{name}}" class="form-control" data-param-type="path" value="{{value}}" />
|
||||||
<br />
|
<br />
|
||||||
|
|||||||
@ -21,6 +21,7 @@ function onRequest(context) {
|
|||||||
var operationModule = require("/app/modules/business-controllers/operation.js")["operationModule"];
|
var operationModule = require("/app/modules/business-controllers/operation.js")["operationModule"];
|
||||||
var device = context.unit.params.device;
|
var device = context.unit.params.device;
|
||||||
var autoCompleteParams = context.unit.params.autoCompleteParams;
|
var autoCompleteParams = context.unit.params.autoCompleteParams;
|
||||||
|
var encodedFeaturePayloads=context.unit.params.encodedFeaturePayloads;
|
||||||
var controlOperations = operationModule.getControlOperations(device.type);
|
var controlOperations = operationModule.getControlOperations(device.type);
|
||||||
var queryParams = [];
|
var queryParams = [];
|
||||||
var formParams = [];
|
var formParams = [];
|
||||||
@ -34,6 +35,9 @@ function onRequest(context) {
|
|||||||
currentParamList[j]["pathParams"] = processParams(currentParam["pathParams"], autoCompleteParams);
|
currentParamList[j]["pathParams"] = processParams(currentParam["pathParams"], autoCompleteParams);
|
||||||
}
|
}
|
||||||
controlOperations[i]["params"] = currentParamList;
|
controlOperations[i]["params"] = currentParamList;
|
||||||
|
if (encodedFeaturePayloads) {
|
||||||
|
controlOperations[i]["payload"] = getPayload(encodedFeaturePayloads, controlOperations[i]["operation"]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return {"control_operations": controlOperations, "device": device};
|
return {"control_operations": controlOperations, "device": device};
|
||||||
}
|
}
|
||||||
@ -52,4 +56,9 @@ function processParams(paramsList, autoCompleteParams) {
|
|||||||
paramsList[i] = {"name": paramName, "value": paramValue, "type": paramType};
|
paramsList[i] = {"name": paramName, "value": paramValue, "type": paramType};
|
||||||
}
|
}
|
||||||
return paramsList;
|
return paramsList;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getPayload(featuresPayload, featureCode){
|
||||||
|
var featuresJSONPayloads = JSON.parse(featuresPayload);
|
||||||
|
return featuresJSONPayloads[featureCode];
|
||||||
}
|
}
|
||||||
@ -50,7 +50,12 @@ function submitForm(formId) {
|
|||||||
var httpMethod = form.attr("method").toUpperCase();
|
var httpMethod = form.attr("method").toUpperCase();
|
||||||
var contentType = form.attr("enctype");
|
var contentType = form.attr("enctype");
|
||||||
console.log(payload);
|
console.log(payload);
|
||||||
if (contentType == undefined || contentType.isEmpty()) {
|
var featurePayload = form.attr("data-payload");
|
||||||
|
if (featurePayload) {
|
||||||
|
contentType = "application/json";
|
||||||
|
payload = JSON.parse(atob(featurePayload));
|
||||||
|
|
||||||
|
} else if (contentType == undefined || contentType.isEmpty()) {
|
||||||
contentType = "application/x-www-form-urlencoded";
|
contentType = "application/x-www-form-urlencoded";
|
||||||
payload = uriencodedFormStr;
|
payload = uriencodedFormStr;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user