Merge pull request #423 from ayyoob/IoTS-1.0.0

few changes in feature manager implementation for deployer
revert-70aa11f8
Ruwan 8 years ago committed by GitHub
commit 906d870309

@ -42,10 +42,6 @@ public class ConfigurationBasedFeatureManager implements FeatureManager {
private static final String QUERY_PARAMS = "queryParams";
private static final String FORM_PARAMS = "formParams";
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(
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<>();
apiParams.put(METHOD, operation.getMethod().toUpperCase());
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);
if (operation.getQueryParameters() != null) {
queryParams = operation.getQueryParameters().getParameter();
@ -116,7 +115,7 @@ public class ConfigurationBasedFeatureManager implements FeatureManager {
return false;
}
private void setPathParams(String context) {
private void setPathParams(String context, List<String> pathParams) {
Matcher regexMatcher = PATH_PARAM_REGEX.matcher(context);
while (regexMatcher.find()) {
pathParams.add(regexMatcher.group(1));

@ -45,16 +45,6 @@ var operationModule = function () {
var feature;
for (var i = 0; i < features.length; i++) {
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["name"] = features[i].name;
feature["description"] = features[i].description;
@ -80,10 +70,17 @@ var operationModule = function () {
publicMethods.getControlOperations = function (deviceType) {
var operations = privateMethods.getOperationsFromFeatures(deviceType, "operation");
var features = utility.getDeviceTypeConfig(deviceType).deviceType.features;
for (var op in operations) {
var iconPath = utility.getOperationIcon(deviceType, operations[op].operation);
if (iconPath) {
operations[op]["icon"] = iconPath;
var iconIdentifier = operations[op].operation;
if (features && features[iconIdentifier]) {
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;

@ -36,10 +36,14 @@
</style>
{{#each control_operations}}
<a href="javascript:operationSelect('{{operation}}')">
{{#if icon}}
<img src="{{@app.context}}/{{icon}}" style="width: 48px;"/>
{{#if iconFont}}
<i class="fw {{iconFont}}"></i>
{{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}}
<span>{{name}}</span>
</a>
@ -61,7 +65,8 @@
<br>
</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}}
<input type="{{type}}" id="{{name}}" placeholder="{{name}}" class="form-control" data-param-type="path" value="{{value}}" />
<br />

@ -21,6 +21,7 @@ function onRequest(context) {
var operationModule = require("/app/modules/business-controllers/operation.js")["operationModule"];
var device = context.unit.params.device;
var autoCompleteParams = context.unit.params.autoCompleteParams;
var encodedFeaturePayloads=context.unit.params.encodedFeaturePayloads;
var controlOperations = operationModule.getControlOperations(device.type);
var queryParams = [];
var formParams = [];
@ -34,6 +35,9 @@ function onRequest(context) {
currentParamList[j]["pathParams"] = processParams(currentParam["pathParams"], autoCompleteParams);
}
controlOperations[i]["params"] = currentParamList;
if (encodedFeaturePayloads) {
controlOperations[i]["payload"] = getPayload(encodedFeaturePayloads, controlOperations[i]["operation"]);
}
}
return {"control_operations": controlOperations, "device": device};
}
@ -53,3 +57,8 @@ function processParams(paramsList, autoCompleteParams) {
}
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 contentType = form.attr("enctype");
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";
payload = uriencodedFormStr;
}

Loading…
Cancel
Save