parent
c664bf8d7a
commit
75bcbcaa46
@ -1,95 +0,0 @@
|
||||
{
|
||||
"store": {
|
||||
"types": ["fs"]
|
||||
},
|
||||
"gadgetGeneration" :{
|
||||
"isCreateGadgetEnable": false,
|
||||
"ignoreProviders": ["rt"]
|
||||
},
|
||||
"authentication": {
|
||||
"activeMethod": "sso",
|
||||
"methods": {
|
||||
"sso": {
|
||||
"attributes": {
|
||||
"issuer": "analyticsportal",
|
||||
"identityProviderURL": "https://localhost:9443/samlsso",
|
||||
"responseSigningEnabled": true,
|
||||
"validateAssertionValidityPeriod": true,
|
||||
"validateAudienceRestriction": true,
|
||||
"assertionSigningEnabled": true,
|
||||
"acs": "https://localhost:9445/portal/acs",
|
||||
"identityAlias": "wso2carbon",
|
||||
"defaultNameIDPolicy": "urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified",
|
||||
"useTenantKey": false,
|
||||
"isPassive": false
|
||||
}
|
||||
},
|
||||
"basic": {
|
||||
"attributes": {}
|
||||
}
|
||||
}
|
||||
},
|
||||
"authorization": {
|
||||
"activeMethod": "oauth",
|
||||
"methods": {
|
||||
"oauth": {
|
||||
"attributes": {
|
||||
"apimgt-gateway": true,
|
||||
"oauthProvider": {
|
||||
"appRegistration": {
|
||||
"appType": "webapp",
|
||||
"clientName": "analyticsportal",
|
||||
"owner": "admin",
|
||||
"password":"admin",
|
||||
"dynamicClientAppRegistrationServiceURL": "https://localhost:9443/dynamic-client-web/register",
|
||||
"apiManagerClientAppRegistrationServiceURL": "https://localhost:9443/api-application-registration/register/tenants",
|
||||
"grantType": "urn:ietf:urn:ietf:params:oauth:grant-type:saml2-bearer",
|
||||
"tokenScope": "admin",
|
||||
"callbackUrl": "https://localhost:9445/portal",
|
||||
"saasApp":true
|
||||
|
||||
},
|
||||
"tokenServiceURL": "https://localhost:9443/oauth2/token"
|
||||
},
|
||||
"adminUser":"admin@carbon.super",
|
||||
"adminUserTenantId":"-1234",
|
||||
"adminRole":"admin",
|
||||
"scopes" : [
|
||||
"device:view"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"designers": [
|
||||
"Internal/everyone"
|
||||
],
|
||||
"tenantPrefix": "/t",
|
||||
"shareStore": false,
|
||||
"theme": "basic",
|
||||
"cacheTimeoutSeconds": "5",
|
||||
"cacheSizeBytes": "1073741824",
|
||||
"defaultDashboardRedirect": false,
|
||||
"isCreateGadgetEnable": true,
|
||||
"isSecureVaultEnabled" : false,
|
||||
"assets": {
|
||||
"gadget": {
|
||||
"fileSizeLimit": 5
|
||||
},
|
||||
"layout": {
|
||||
"fileSizeLimit": 1
|
||||
}
|
||||
},
|
||||
"oauth": {
|
||||
"username": "admin",
|
||||
"password": "admin"
|
||||
},
|
||||
"host": {
|
||||
"hostname": "localhost",
|
||||
"port": "",
|
||||
"protocol": ""
|
||||
},
|
||||
"queryParameters" : {
|
||||
"passBetweenPages" : ["shared", "owner", "deviceId"]
|
||||
}
|
||||
}
|
@ -1,187 +0,0 @@
|
||||
{
|
||||
"initScripts": [
|
||||
"js/dashboard-deployer.js"
|
||||
],
|
||||
"welcomeFiles": [
|
||||
"routers/tenant.jag"
|
||||
],
|
||||
"errorPages": {
|
||||
"500": "/controllers/error-pages/error500.html",
|
||||
"404": "/controllers/error-pages/error404.html",
|
||||
"401": "/controllers/error-pages/error401.html",
|
||||
"405": "/controllers/error-pages/error405.html",
|
||||
"403": "/controllers/error-pages/error403.html",
|
||||
"400": "/controllers/error-pages/error400.html"
|
||||
},
|
||||
"urlMappings": [
|
||||
{
|
||||
"url": "/login-controller",
|
||||
"path": "/routers/tenant.jag"
|
||||
},
|
||||
{
|
||||
"url": "/login",
|
||||
"path": "/routers/tenant.jag"
|
||||
},
|
||||
{
|
||||
"url": "/logout",
|
||||
"path": "/routers/tenant.jag"
|
||||
},
|
||||
{
|
||||
"url": "/t/*",
|
||||
"path": "/routers/tenant.jag"
|
||||
},
|
||||
{
|
||||
"url": "/apis/*",
|
||||
"path": "/routers/tenant.jag"
|
||||
},
|
||||
{
|
||||
"url": "/dashboards/*",
|
||||
"path": "/routers/tenant.jag"
|
||||
},
|
||||
{
|
||||
"url": "/gadget/*",
|
||||
"path": "/routers/tenant.jag"
|
||||
},
|
||||
{
|
||||
"url": "/layout/*",
|
||||
"path": "/routers/tenant.jag"
|
||||
},
|
||||
{
|
||||
"url": "/assets/*",
|
||||
"path": "/routers/tenant.jag"
|
||||
},
|
||||
{
|
||||
"url": "/create-dashboard",
|
||||
"path": "/routers/tenant.jag"
|
||||
},
|
||||
{
|
||||
"url": "/dashboard-settings/*",
|
||||
"path": "/routers/tenant.jag"
|
||||
},
|
||||
{
|
||||
"url": "/select-layout",
|
||||
"path": "/routers/tenant.jag"
|
||||
},
|
||||
{
|
||||
"url": "/create-gadget",
|
||||
"path": "/routers/tenant.jag"
|
||||
},
|
||||
{
|
||||
"url": "/upload-gadget",
|
||||
"path": "/routers/tenant.jag"
|
||||
},
|
||||
{
|
||||
"url": "/upload-layout",
|
||||
"path": "/routers/tenant.jag"
|
||||
},
|
||||
{
|
||||
"url": "/geojson/world/*",
|
||||
"path": "/templates/geojson/world.json"
|
||||
},
|
||||
{
|
||||
"url": "/geojson/europe/*",
|
||||
"path": "/templates/geojson/europe.json"
|
||||
},
|
||||
{
|
||||
"url": "/geojson/usa/*",
|
||||
"path": "/templates/geojson/usa.json"
|
||||
},
|
||||
{
|
||||
"url": "/geojson/countryInfo/*",
|
||||
"path": "/templates/geojson/countryInfo.json"
|
||||
},
|
||||
{
|
||||
"url": "/geojson/usaInfo/*",
|
||||
"path": "/templates/geojson/usaInfo.json"
|
||||
},
|
||||
{
|
||||
"url": "/acs",
|
||||
"path": "/controllers/acs.jag"
|
||||
},
|
||||
{
|
||||
"url": "/banners/*",
|
||||
"path": "/routers/tenant.jag"
|
||||
},
|
||||
{
|
||||
"url": "/gadgets/*",
|
||||
"path": "/routers/tenant.jag"
|
||||
},
|
||||
{
|
||||
"url": "/configs/designer.json",
|
||||
"path": "/controllers/error-pages/error404.html"
|
||||
}
|
||||
],
|
||||
"listeners": [
|
||||
{
|
||||
"class": "org.owasp.csrfguard.CsrfGuardServletContextListener"
|
||||
},
|
||||
{
|
||||
"class": "org.owasp.csrfguard.CsrfGuardHttpSessionListener"
|
||||
}
|
||||
],
|
||||
"servlets": [
|
||||
{
|
||||
"name": "JavaScriptServlet",
|
||||
"class": "org.owasp.csrfguard.servlet.JavaScriptServlet"
|
||||
}
|
||||
],
|
||||
"servletMappings": [
|
||||
{
|
||||
"name": "JavaScriptServlet",
|
||||
"url": "/csrf.js"
|
||||
}
|
||||
],
|
||||
"contextParams": [
|
||||
{
|
||||
"name": "Owasp.CsrfGuard.Config",
|
||||
"value": "repository/conf/security/Owasp.CsrfGuard.dashboard.properties"
|
||||
}
|
||||
],
|
||||
"filters": [
|
||||
{
|
||||
"name": "ContentTypeBasedCachePreventionFilter",
|
||||
"class": "org.wso2.carbon.ui.filters.cache.ContentTypeBasedCachePreventionFilter",
|
||||
"params" : [
|
||||
{"name" : "patterns", "value" : "text/html\" ,application/json\" ,text/plain"},
|
||||
{"name" : "filterAction", "value" : "enforce"},
|
||||
{"name" : "httpHeaders", "value" : "Cache-Control: no-store, no-cache, must-revalidate, private"}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "HttpHeaderSecurityFilter",
|
||||
"class": "org.apache.catalina.filters.HttpHeaderSecurityFilter",
|
||||
"params": [
|
||||
{
|
||||
"name": "hstsEnabled",
|
||||
"value": "false"
|
||||
},
|
||||
{
|
||||
"name": "antiClickJackingOption",
|
||||
"value": "SAMEORIGIN"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "TenantStoresFilter",
|
||||
"class": "org.wso2.carbon.dashboard.store.filter.TenantStoreFilter"
|
||||
}
|
||||
],
|
||||
"filterMappings": [
|
||||
{
|
||||
"name": "HttpHeaderSecurityFilter",
|
||||
"url": "*"
|
||||
},
|
||||
{
|
||||
"name": "TenantStoresFilter",
|
||||
"url": "/store/*"
|
||||
},
|
||||
{
|
||||
"name": "TenantStoresFilter",
|
||||
"url": "/temp/*"
|
||||
},
|
||||
{
|
||||
"name":"ContentTypeBasedCachePreventionFilter",
|
||||
"url":"*"
|
||||
}
|
||||
]
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,60 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
|
||||
var getDateString, getDuration;
|
||||
|
||||
(function() {
|
||||
|
||||
getDateString = function (timestamp) {
|
||||
var date = new Date();
|
||||
date.setTime(timestamp);
|
||||
return date.toString();
|
||||
};
|
||||
|
||||
getDuration = function (durationInMS) {
|
||||
var time = '';
|
||||
var date = new Date();
|
||||
date.setTime(durationInMS);
|
||||
|
||||
var day = Math.floor(durationInMS/86400000);
|
||||
if (day > 0){
|
||||
//More than 1 day
|
||||
time = day +' day : ';
|
||||
durationInMS = durationInMS - (day * 86400000);
|
||||
}
|
||||
var hour = Math.floor(durationInMS/3600000);
|
||||
if (hour > 0){
|
||||
//More than 1 hour
|
||||
time = time + hour + ' hour : ';
|
||||
durationInMS = durationInMS - (hour * 3600000);
|
||||
}
|
||||
|
||||
var minutes = Math.floor(durationInMS/60000);
|
||||
if (minutes > 0){
|
||||
//More than 1 minute
|
||||
time = time + minutes + ' minutes : ';
|
||||
durationInMS = durationInMS - (minutes * 60000);
|
||||
}
|
||||
|
||||
var seconds = Math.ceil(durationInMS/1000);
|
||||
if (seconds > 0){
|
||||
//More than 1 minute
|
||||
time = time + seconds + ' seconds : ';
|
||||
}
|
||||
time = time.slice(0, -2);
|
||||
return time;
|
||||
};
|
||||
}());
|
@ -1,598 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
var utils = function () {
|
||||
var log = new Log("/modules/oauth/token-handler-utils.js");
|
||||
|
||||
var configs = require('/configs/portal.js').config();
|
||||
var constants = require("/modules/constants.js");
|
||||
var carbon = require("carbon");
|
||||
|
||||
//noinspection JSUnresolvedVariable
|
||||
var Base64 = Packages.org.apache.commons.codec.binary.Base64;
|
||||
//noinspection JSUnresolvedVariable
|
||||
var String = Packages.java.lang.String;
|
||||
|
||||
var publicMethods = {};
|
||||
var privateMethods = {};
|
||||
|
||||
publicMethods["encode"] = function (payload) {
|
||||
return String(Base64.encodeBase64(String(payload).getBytes()));
|
||||
};
|
||||
|
||||
publicMethods["decode"] = function (payload) {
|
||||
return String(Base64.decodeBase64(String(payload).getBytes()));
|
||||
};
|
||||
|
||||
/**
|
||||
* Check whether this application is oauth enable or not
|
||||
* @returns boolean if oauth enable
|
||||
*/
|
||||
publicMethods["checkOAuthEnabled"] = function () {
|
||||
if (constants.AUTHORIZATION_TYPE_OAUTH === configs["authorization"]["activeMethod"]) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set access token into xml http request header
|
||||
* @param xhr xml http request
|
||||
* @returns {*} xhr which has access token it's header
|
||||
*/
|
||||
publicMethods["setAccessToken"] = function (xhr, callback) {
|
||||
var accessToken;
|
||||
if (publicMethods.checkOAuthEnabled()) {
|
||||
try {
|
||||
accessToken = parse(session.get(constants.ACCESS_TOKEN_PAIR_IDENTIFIER_FOR_PORTAL))["accessToken"];
|
||||
xhr.setRequestHeader(constants.AUTHORIZATION_HEADER, constants.BEARER_PREFIX + accessToken);
|
||||
} catch (exception) {
|
||||
log.error("Access token hasn't been set yet, " + exception);
|
||||
} finally {
|
||||
callback(xhr);
|
||||
}
|
||||
}
|
||||
callback(xhr);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get access token of current logged user
|
||||
* @param callBack response with access token
|
||||
*/
|
||||
publicMethods["getAccessToken"] = function (callBack) {
|
||||
var accessToken = null;
|
||||
if (publicMethods.checkOAuthEnabled()) {
|
||||
try {
|
||||
accessToken = parse(session.get(constants.ACCESS_TOKEN_PAIR_IDENTIFIER_FOR_PORTAL))["accessToken"];
|
||||
} catch (exception) {
|
||||
log.error("Access token hasn't been set yet, " + exception);
|
||||
} finally {
|
||||
callBack(accessToken);
|
||||
}
|
||||
}
|
||||
callBack(accessToken);
|
||||
};
|
||||
|
||||
/**
|
||||
* Create error message which adhere to xml http response object
|
||||
* @param statusCode response status code
|
||||
* @param status response status
|
||||
* @param responseText response message
|
||||
* @returns {{statusCode: *, status: *, responseText: *}}
|
||||
*/
|
||||
publicMethods["createXHRObject"] = function (statusCode, status, responseText) {
|
||||
return {"statusCode": statusCode, "status": status, "responseText": responseText};
|
||||
};
|
||||
|
||||
/**
|
||||
* check whether user already logged to system before invoking any apis
|
||||
* @param callBack
|
||||
*/
|
||||
publicMethods["isUserAuthorized"] = function (callBack) {
|
||||
if (session.get("Loged") !== constants.LOGIN_MESSAGE) {
|
||||
callBack(false);
|
||||
} else {
|
||||
callBack(true);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get identity provider uir
|
||||
* @returns {*}
|
||||
*/
|
||||
publicMethods["getIdPServerURL"] = function () {
|
||||
return configs["authorization"]["methods"]["oauth"]["attributes"]["oauthProvider"]["tokenServiceURL"];
|
||||
};
|
||||
|
||||
/**
|
||||
* Get an Access token pair based on client secret
|
||||
* @param encodedClientKeys {{clientId:"", clientSecret:""}}
|
||||
* @param scope eg: PRODUCTION
|
||||
* @param idPServer identity provider url
|
||||
* @returns {{accessToken: *, refreshToken: *}}
|
||||
*/
|
||||
publicMethods["getTokenWithClientSecretType"] = function (encodedClientKeys, scope, idPServer) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
var tokenEndpoint = idPServer;
|
||||
xhr.open(constants.HTTP_POST, tokenEndpoint, false);
|
||||
xhr.setRequestHeader(constants.CONTENT_TYPE_IDENTIFIER, constants.APPLICATION_X_WWW_FOR_URLENCODED);
|
||||
xhr.setRequestHeader(constants.AUTHORIZATION_HEADER, constants.BASIC_PREFIX + encodedClientKeys);
|
||||
xhr.send("grant_type=client_credentials&scope=" + scope);
|
||||
var tokenPair = {};
|
||||
if (xhr.status == constants.HTTP_ACCEPTED) {
|
||||
var data = parse(xhr.responseText);
|
||||
tokenPair.refreshToken = data.refresh_token;
|
||||
tokenPair.accessToken = data.access_token;
|
||||
} else if (xhr.status == constants.HTTP_USER_NOT_AUTHENTICATED) {
|
||||
log.error("Error in obtaining token with client secret grant type, You are not authenticated yet");
|
||||
return null;
|
||||
} else {
|
||||
log.error("Error in obtaining token with client secret grant type, This might be a problem with client meta " +
|
||||
"data which required for client secret grant type");
|
||||
return null;
|
||||
}
|
||||
return tokenPair;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* This will create client id and client secret for a given application
|
||||
* @param properties "callbackUrl": "",
|
||||
* "clientName": "",
|
||||
* "owner": "",
|
||||
* "applicationType": "",
|
||||
* "grantType": "",
|
||||
* "saasApp" :"",
|
||||
* "dynamicClientRegistrationEndPoint" : ""
|
||||
*
|
||||
* @returns {{clientId:*, clientSecret:*}}
|
||||
*/
|
||||
publicMethods["getDynamicClientAppCredentials"] = function (username) {
|
||||
// setting up dynamic client application properties
|
||||
var dcAppProperties = {
|
||||
"applicationType": configs["authorization"]["methods"]["oauth"]["attributes"]["oauthProvider"]["appRegistration"]["appType"],
|
||||
"clientName": configs["authorization"]["methods"]["oauth"]["attributes"]["oauthProvider"]["appRegistration"]["clientName"],
|
||||
"owner": configs["authorization"]["methods"]["oauth"]["attributes"]["oauthProvider"]["appRegistration"]["owner"],
|
||||
"tokenScope": configs["authorization"]["methods"]["oauth"]["attributes"]["oauthProvider"]["appRegistration"]["tokenScope"],
|
||||
"grantType": configs["authorization"]["methods"]["oauth"]["attributes"]["oauthProvider"]["appRegistration"]["grantType"],
|
||||
"callbackUrl": configs["authorization"]["methods"]["oauth"]["attributes"]["oauthProvider"]["appRegistration"]["callbackUrl"],
|
||||
"saasApp" : configs["authorization"]["methods"]["oauth"]["attributes"]["oauthProvider"]["appRegistration"]["saasApp"]
|
||||
};
|
||||
|
||||
var tenantDomain = carbon.server.tenantDomain({username: username});
|
||||
if (!tenantDomain) {
|
||||
log.error("{/modules/oauth/token-handler-utils.js} Error in retrieving tenant " +
|
||||
"based client application credentials. Unable to obtain a valid tenant domain for provided username "+
|
||||
username +"- getDynamicClientAppCredentials(x)");
|
||||
return null;
|
||||
} else {
|
||||
var cachedTenantBasedClientAppCredentials = privateMethods.
|
||||
getCachedTenantBasedClientAppCredentials(tenantDomain);
|
||||
if (cachedTenantBasedClientAppCredentials) {
|
||||
return cachedTenantBasedClientAppCredentials;
|
||||
} else {
|
||||
// calling dynamic client app registration service endpoint
|
||||
var requestURL = configs["authorization"]["methods"]["oauth"]["attributes"]["oauthProvider"]["appRegistration"]
|
||||
["dynamicClientAppRegistrationServiceURL"];
|
||||
var requestPayload = dcAppProperties;
|
||||
var token = publicMethods.encode(configs["authorization"]["methods"]["oauth"]["attributes"]["oauthProvider"]
|
||||
["appRegistration"]["owner"] + ":" + configs["authorization"]["methods"]["oauth"]["attributes"]
|
||||
["oauthProvider"]["appRegistration"]["password"]);
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", requestURL, false);
|
||||
xhr.setRequestHeader("Content-Type", "application/json");
|
||||
xhr.setRequestHeader("Authorization", "Basic "+ token);
|
||||
xhr.send(stringify(requestPayload));
|
||||
var dynamicClientAppCredentials = {};
|
||||
if (xhr["status"] == 201 || xhr["status"] == 200 && xhr["responseText"]) {
|
||||
var responsePayload = parse(xhr["responseText"]);
|
||||
var clientId = responsePayload["client_id"];
|
||||
var clientSecret = responsePayload["client_secret"];
|
||||
if(typeof clientId == "undefined"){
|
||||
clientId = responsePayload["clientId"];
|
||||
}
|
||||
if(typeof clientSecret == "undefined"){
|
||||
clientSecret = responsePayload["clientSecret"];
|
||||
}
|
||||
dynamicClientAppCredentials["clientId"] = clientId;
|
||||
dynamicClientAppCredentials["clientSecret"] = clientSecret;
|
||||
privateMethods.
|
||||
setCachedTenantBasedClientAppCredentials(tenantDomain, dynamicClientAppCredentials);
|
||||
} else if (xhr["status"] == 400) {
|
||||
log.error("{/modules/oauth/token-handler-utils.js - getDynamicClientAppCredentials()} " +
|
||||
"Bad request. Invalid data provided as dynamic client application properties.");
|
||||
dynamicClientAppCredentials = null;
|
||||
} else {
|
||||
log.error("{/modules/oauth/token-handler-utils.js - getDynamicClientAppCredentials()} " +
|
||||
"Error in retrieving dynamic client credentials.");
|
||||
dynamicClientAppCredentials = null;
|
||||
}
|
||||
// returning dynamic client credentials
|
||||
return dynamicClientAppCredentials;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* If gateway is enable, apiManagerClientAppRegistrationServiceURL is used to create oauth application
|
||||
* @param username username of current logged user
|
||||
* @returns {{clientId:*, clientSecret:*}}
|
||||
*/
|
||||
publicMethods["getTenantBasedClientAppCredentials"] = function (username) {
|
||||
if (!username) {
|
||||
log.error("{/modules/oauth/token-handler-utils.js} Error in retrieving tenant " +
|
||||
"based client app credentials. No username " +
|
||||
"as input - getTenantBasedClientAppCredentials(x)");
|
||||
return null;
|
||||
} else {
|
||||
//noinspection JSUnresolvedFunction, JSUnresolvedVariable
|
||||
var tenantDomain = carbon.server.tenantDomain({username: username});
|
||||
|
||||
if (!tenantDomain) {
|
||||
log.error("{/modules/oauth/token-handler-utils.js} Error in retrieving tenant " +
|
||||
"based client application credentials. Unable to obtain a valid tenant domain for provided " +
|
||||
"username - getTenantBasedClientAppCredentials(x, y)");
|
||||
return null;
|
||||
} else {
|
||||
var cachedTenantBasedClientAppCredentials = privateMethods.
|
||||
getCachedTenantBasedClientAppCredentials(tenantDomain);
|
||||
if (cachedTenantBasedClientAppCredentials) {
|
||||
return cachedTenantBasedClientAppCredentials;
|
||||
} else {
|
||||
var adminUsername = configs["authorization"]["methods"]["oauth"]["attributes"]["adminUser"];
|
||||
var adminUserTenantId = configs["authorization"]["methods"]["oauth"]["attributes"]
|
||||
["adminUserTenantId"];
|
||||
//claims required for jwtAuthenticator.
|
||||
var claims = {"http://wso2.org/claims/enduserTenantId": adminUserTenantId,
|
||||
"http://wso2.org/claims/enduser": adminUsername};
|
||||
var jwtToken = publicMethods.getJwtToken(adminUsername, claims);
|
||||
// register a tenant based client app at API Manager
|
||||
var applicationName = configs["authorization"]["methods"]["oauth"]["attributes"]["oauthProvider"]
|
||||
["appRegistration"]["clientName"] + "_" + tenantDomain;
|
||||
var requestURL = configs["authorization"]["methods"]["oauth"]["attributes"]["oauthProvider"]
|
||||
["appRegistration"]["apiManagerClientAppRegistrationServiceURL"] +
|
||||
"?tenantDomain=" + tenantDomain + "&applicationName=" + applicationName;
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", requestURL, false);
|
||||
xhr.setRequestHeader("Content-Type", "application/json");
|
||||
xhr.setRequestHeader("X-JWT-Assertion", "" + jwtToken);
|
||||
xhr.send();
|
||||
if ((xhr["status"] == 201 || xhr["status"] == 200) && xhr["responseText"]) {
|
||||
var responsePayload = parse(xhr["responseText"]);
|
||||
var tenantBasedClientAppCredentials = {};
|
||||
var clientId = responsePayload["client_id"];
|
||||
var clientSecret = responsePayload["client_secret"];
|
||||
if(typeof clientId == "undefined"){
|
||||
clientId = responsePayload["clientId"];
|
||||
}
|
||||
if(typeof clientSecret == "undefined"){
|
||||
clientSecret = responsePayload["clientSecret"];
|
||||
}
|
||||
tenantBasedClientAppCredentials["clientId"] = clientId;
|
||||
tenantBasedClientAppCredentials["clientSecret"] = clientSecret;
|
||||
privateMethods.
|
||||
setCachedTenantBasedClientAppCredentials(tenantDomain, tenantBasedClientAppCredentials);
|
||||
return tenantBasedClientAppCredentials;
|
||||
} else {
|
||||
log.error("{/modules/oauth/token-handler-utils.js} Error in retrieving tenant " +
|
||||
"based client application credentials from API " +
|
||||
"Manager - getTenantBasedClientAppCredentials(x, y)");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Caching oauth application credentials
|
||||
* @param tenantDomain tenant domain where application is been created
|
||||
* @param clientAppCredentials {{clientId:*, clientSecret:*}}
|
||||
*/
|
||||
privateMethods["setCachedTenantBasedClientAppCredentials"] = function (tenantDomain, clientAppCredentials) {
|
||||
var cachedTenantBasedClientAppCredentialsMap = application.get(constants["CACHED_CREDENTIALS_PORTAL_APP"]);
|
||||
if (!cachedTenantBasedClientAppCredentialsMap) {
|
||||
cachedTenantBasedClientAppCredentialsMap = {};
|
||||
cachedTenantBasedClientAppCredentialsMap[tenantDomain] = clientAppCredentials;
|
||||
application.put(constants["CACHED_CREDENTIALS_PORTAL_APP"], cachedTenantBasedClientAppCredentialsMap);
|
||||
} else if (!cachedTenantBasedClientAppCredentialsMap[tenantDomain]) {
|
||||
cachedTenantBasedClientAppCredentialsMap[tenantDomain] = clientAppCredentials;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get oauth application credentials from cache
|
||||
* @param tenantDomain tenant domain where application is been created
|
||||
* @returns {{clientId:*, clientSecret:*}}
|
||||
*/
|
||||
privateMethods["getCachedTenantBasedClientAppCredentials"] = function (tenantDomain) {
|
||||
var cachedTenantBasedClientAppCredentialsMap = application.get(constants["CACHED_CREDENTIALS_PORTAL_APP"]);
|
||||
if (!cachedTenantBasedClientAppCredentialsMap ||
|
||||
!cachedTenantBasedClientAppCredentialsMap[tenantDomain]) {
|
||||
return null;
|
||||
} else {
|
||||
return cachedTenantBasedClientAppCredentialsMap[tenantDomain];
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get access token and refresh token using password grant type
|
||||
* @param username username of the logged user
|
||||
* @param password password of the logged user
|
||||
* @param encodedClientAppCredentials {{clientId:*, clientSecret:*}}
|
||||
* @param scopes scopes list
|
||||
* @returns {{accessToken: *, refreshToken: *}}
|
||||
*/
|
||||
publicMethods["getTokenPairAndScopesByPasswordGrantType"] = function (username, password
|
||||
, encodedClientAppCredentials, scopes) {
|
||||
if (!username || !password || !encodedClientAppCredentials || !scopes) {
|
||||
log.error("{/modules/oauth/token-handler-utils.js} Error in retrieving access token by password " +
|
||||
"grant type. No username, password, encoded client app credentials or scopes are " +
|
||||
"found - getTokenPairAndScopesByPasswordGrantType(a, b, c, d)");
|
||||
return null;
|
||||
} else {
|
||||
// calling oauth provider token service endpoint
|
||||
var requestURL = configs["authorization"]["methods"]["oauth"]["attributes"]["oauthProvider"]
|
||||
["tokenServiceURL"];
|
||||
var requestPayload = "grant_type=password&username=" +
|
||||
username + "&password=" + password + "&scope=" + scopes;
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", requestURL, false);
|
||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
xhr.setRequestHeader("Authorization", "Basic " + encodedClientAppCredentials);
|
||||
xhr.send(requestPayload);
|
||||
|
||||
if (xhr["status"] == 200 && xhr["responseText"]) {
|
||||
var responsePayload = parse(xhr["responseText"]);
|
||||
var tokenData = {};
|
||||
tokenData["accessToken"] = responsePayload["access_token"];
|
||||
tokenData["refreshToken"] = responsePayload["refresh_token"];
|
||||
tokenData["scopes"] = responsePayload["scope"];
|
||||
return tokenData;
|
||||
} else {
|
||||
log.error("{/modules/oauth/token-handler-utils.js} Error in retrieving access token " +
|
||||
"by password grant type - getTokenPairAndScopesByPasswordGrantType(a, b, c, d)");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get access token and refresh token using SAML grant type
|
||||
* @param assertion
|
||||
* @param encodedClientAppCredentials
|
||||
* @param scopes
|
||||
* @returns {{accessToken: *, refreshToken: *}}
|
||||
*/
|
||||
publicMethods["getTokenPairAndScopesByJWTGrantType"] = function (username, encodedClientAppCredentials, scopes) {
|
||||
if (!username || !encodedClientAppCredentials || !scopes) {
|
||||
log.error("{/app/modules/oauth/token-handler-utils.js} Error in retrieving access token by jwt " +
|
||||
"grant type. No assertion, encoded client app credentials or scopes are " +
|
||||
"found - getTokenPairAndScopesByJWTGrantType(x, y, z)");
|
||||
return null;
|
||||
} else {
|
||||
var JWTClientManagerServicePackagePath =
|
||||
"org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerService";
|
||||
//noinspection JSUnresolvedFunction, JSUnresolvedVariable
|
||||
var JWTClientManagerService = carbon.server.osgiService(JWTClientManagerServicePackagePath);
|
||||
//noinspection JSUnresolvedFunction
|
||||
var jwtClient = JWTClientManagerService.getJWTClient();
|
||||
// returning access token by JWT grant type
|
||||
var tokenInfo = jwtClient.getAccessToken(encodedClientAppCredentials,
|
||||
username, scopes);
|
||||
var tokenData = {};
|
||||
tokenData["accessToken"] = tokenInfo.getAccessToken();
|
||||
tokenData["refreshToken"] = tokenInfo.getRefreshToken();
|
||||
tokenData["scopes"] = tokenInfo.getScopes();
|
||||
return tokenData;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get access token and refresh token using SAML grant type
|
||||
* @param assertion
|
||||
* @param encodedClientAppCredentials
|
||||
* @param scopes
|
||||
* @returns {{accessToken: *, refreshToken: *}}
|
||||
*/
|
||||
publicMethods["getTokenPairAndScopesBySAMLGrantType"] = function (assertion, encodedClientAppCredentials, scopes) {
|
||||
if (!assertion || !encodedClientAppCredentials || !scopes) {
|
||||
log.error("{/modules/oauth/token-handler-utils.js} Error in retrieving access token by saml " +
|
||||
"grant type. No assertion, encoded client app credentials or scopes are " +
|
||||
"found - getTokenPairAndScopesBySAMLGrantType(x, y, z)");
|
||||
return null;
|
||||
} else {
|
||||
|
||||
var assertionXML = publicMethods.decode(assertion);
|
||||
/*
|
||||
TODO: make assertion extraction with proper parsing.
|
||||
Since Jaggery XML parser seem to add formatting which causes signature verification to fail.
|
||||
*/
|
||||
var assertionStartMarker = "<saml2:Assertion";
|
||||
var assertionEndMarker = "<\/saml2:Assertion>";
|
||||
var assertionStartIndex = assertionXML.indexOf(assertionStartMarker);
|
||||
var assertionEndIndex = assertionXML.indexOf(assertionEndMarker);
|
||||
|
||||
var extractedAssertion;
|
||||
if (assertionStartIndex == -1 || assertionEndIndex == -1) {
|
||||
log.error("{/modules/oauth/token-handler-utils.js} Error in retrieving access token by saml grant " +
|
||||
"type. Issue in assertion format - getTokenPairAndScopesBySAMLGrantType(x, y, z)");
|
||||
return null;
|
||||
} else {
|
||||
extractedAssertion = assertionXML.
|
||||
substring(assertionStartIndex, assertionEndIndex) + assertionEndMarker;
|
||||
var encodedAssertion = publicMethods.encode(extractedAssertion);
|
||||
// calling oauth provider token service endpoint
|
||||
var requestURL = configs["authorization"]["methods"]["oauth"]["attributes"]["oauthProvider"]
|
||||
["tokenServiceURL"];
|
||||
var requestPayload = "grant_type=urn:ietf:params:oauth:grant-type:saml2-bearer&" +
|
||||
"assertion=" + encodeURIComponent(encodedAssertion) + "&scope=" + scopes;
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", requestURL, false);
|
||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
xhr.setRequestHeader("Authorization", "Basic " + encodedClientAppCredentials);
|
||||
xhr.send(requestPayload);
|
||||
|
||||
if (xhr["status"] == 200 && xhr["responseText"]) {
|
||||
var responsePayload = parse(xhr["responseText"]);
|
||||
var tokenData = {};
|
||||
tokenData["accessToken"] = responsePayload["access_token"];
|
||||
tokenData["refreshToken"] = responsePayload["refresh_token"];
|
||||
tokenData["scopes"] = responsePayload["scope"];
|
||||
return tokenData;
|
||||
} else {
|
||||
log.error("{/modules/oauth/token-handler-utils.js} Error in retrieving access token " +
|
||||
"by password grant type - getTokenPairAndScopesBySAMLGrantType(x, y, z)");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* If access token is expired, try to refresh it using existing refresh token
|
||||
* @param callback
|
||||
*/
|
||||
publicMethods["refreshAccessToken"] = function (callback) {
|
||||
try {
|
||||
if (publicMethods.checkOAuthEnabled()) {
|
||||
var currentTokenPair = parse(session.get(constants["ACCESS_TOKEN_PAIR_IDENTIFIER_FOR_PORTAL"]));
|
||||
// currentTokenPair includes current access token as well as current refresh token
|
||||
var encodedClientAppCredentials
|
||||
= session.get(constants["ENCODED_TENANT_BASED_CLIENT_APP_CREDENTIALS_PORTAL_APP"]);
|
||||
if (!currentTokenPair || !encodedClientAppCredentials) {
|
||||
callback(false);
|
||||
throw new Error("{/modules/oauth/token-handlers.js} Error in refreshing tokens. Either the " +
|
||||
"token pair, encoded client app credentials or both input are not found under " +
|
||||
"session context - refreshTokenPair()");
|
||||
} else {
|
||||
var newTokenPair = publicMethods.
|
||||
getNewTokenPairByRefreshToken(currentTokenPair["refreshToken"], encodedClientAppCredentials);
|
||||
if (!newTokenPair) {
|
||||
log.error("{/app/modules/oauth/token-handlers.js} Error in refreshing token pair. " +
|
||||
"Unable to update session context with new access token pair - refreshTokenPair()");
|
||||
callback(false);
|
||||
} else {
|
||||
session.put(constants["ACCESS_TOKEN_PAIR_IDENTIFIER_FOR_PORTAL"], stringify(newTokenPair));
|
||||
callback(true);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log.error("You have not enable dynamic client yet");
|
||||
callback(false);
|
||||
}
|
||||
} catch (exception) {
|
||||
callback(false);
|
||||
throw "Error while refreshing existing access token, " + exception;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get access token and refresh token using refresh token grant type
|
||||
* @param refreshToken refresh token
|
||||
* @param encodedClientAppCredentials {{clientId:*, clientSecret:*}}
|
||||
* @param scopes
|
||||
* @returns {{accessToken: *, refreshToken: *}}
|
||||
*/
|
||||
publicMethods["getNewTokenPairByRefreshToken"] = function (refreshToken, encodedClientAppCredentials, scopes) {
|
||||
if (!refreshToken || !encodedClientAppCredentials) {
|
||||
log.error("{/modules/oauth/token-handler-utils.js} Error in retrieving new access token " +
|
||||
"by current refresh token. No refresh token or encoded client app credentials are " +
|
||||
"found - getNewTokenPairByRefreshToken(x, y, z)");
|
||||
return null;
|
||||
} else {
|
||||
var requestURL = configs["authorization"]["methods"]["oauth"]["attributes"]["oauthProvider"]
|
||||
["tokenServiceURL"];
|
||||
var requestPayload = "grant_type=refresh_token&refresh_token=" + refreshToken;
|
||||
if (scopes) {
|
||||
requestPayload = requestPayload + "&scope=" + scopes;
|
||||
}
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", requestURL, false);
|
||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
xhr.setRequestHeader("Authorization", "Basic " + encodedClientAppCredentials);
|
||||
xhr.send(requestPayload);
|
||||
|
||||
if (xhr["status"] == 200 && xhr["responseText"]) {
|
||||
var responsePayload = parse(xhr["responseText"]);
|
||||
var tokenPair = {};
|
||||
tokenPair["accessToken"] = responsePayload["access_token"];
|
||||
tokenPair["refreshToken"] = responsePayload["refresh_token"];
|
||||
return tokenPair;
|
||||
} else {
|
||||
log.error("{/modules/oauth/token-handler-utils.js} Error in retrieving new access token by " +
|
||||
"current refresh token - getNewTokenPairByRefreshToken(x, y, z)");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get access token using JWT grant type
|
||||
* @param clientAppCredentials {{clientId:*, clientSecret:*}}
|
||||
* @returns {{accessToken: *, refreshToken: *}}
|
||||
*/
|
||||
publicMethods["getAccessTokenByJWTGrantType"] = function (clientAppCredentials) {
|
||||
if (!clientAppCredentials) {
|
||||
log.error("{/modules/oauth/token-handler-utils.js} Error in retrieving new access token " +
|
||||
"by current refresh token. No client app credentials are found " +
|
||||
"as input - getAccessTokenByJWTGrantType(x)");
|
||||
return null;
|
||||
} else {
|
||||
var JWTClientManagerServicePackagePath =
|
||||
"org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerService";
|
||||
//noinspection JSUnresolvedFunction, JSUnresolvedVariable
|
||||
var JWTClientManagerService = carbon.server.osgiService(JWTClientManagerServicePackagePath);
|
||||
//noinspection JSUnresolvedFunction
|
||||
var jwtClient = JWTClientManagerService.getJWTClient();
|
||||
// returning access token by JWT grant type
|
||||
return jwtClient.getAccessToken(clientAppCredentials["clientId"], clientAppCredentials["clientSecret"],
|
||||
configs["authorization"]["methods"]["oauth"]["attributes"]["oauthProvider"]["appRegistration"]["owner"],
|
||||
null)["accessToken"];
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get jwt token
|
||||
* @param username username of logged user
|
||||
* @param claims claims which are required
|
||||
* @returns {"jwtToken"}
|
||||
*/
|
||||
publicMethods["getJwtToken"] = function (username, claims) {
|
||||
if (!username) {
|
||||
log.error("{/modules/oauth/token-handler-utils.js} Error in retrieving new jwt token");
|
||||
return null;
|
||||
} else {
|
||||
var JWTClientManagerServicePackagePath =
|
||||
"org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerService";
|
||||
//noinspection JSUnresolvedFunction, JSUnresolvedVariable
|
||||
var JWTClientManagerService = carbon.server.osgiService(JWTClientManagerServicePackagePath);
|
||||
//noinspection JSUnresolvedFunction
|
||||
var jwtClient = JWTClientManagerService.getJWTClient();
|
||||
// returning access token by JWT grant type
|
||||
if (claims) {
|
||||
return jwtClient.getJwtToken(username, claims);
|
||||
} else {
|
||||
return jwtClient.getJwtToken(username);
|
||||
}
|
||||
}
|
||||
};
|
||||
return publicMethods;
|
||||
}();
|
@ -1,192 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* -----------------------------------------------------
|
||||
* Following module includes handlers
|
||||
* at Jaggery Layer for handling OAuth tokens.
|
||||
* -----------------------------------------------------
|
||||
*/
|
||||
var handlers = function () {
|
||||
var log = new Log("/modules/oauth/token-handlers.js");
|
||||
|
||||
var tokenUtil = require("/modules/oauth/token-handler-utils.js")["utils"];
|
||||
var constants = require("/modules/constants.js");
|
||||
var configs = require('/configs/portal.js').config();
|
||||
|
||||
var publicMethods = {};
|
||||
var privateMethods = {};
|
||||
|
||||
/**
|
||||
* Get an AccessToken pair based on username and password
|
||||
* @param username username of the logged user
|
||||
* @param password password of the logged user
|
||||
*/
|
||||
publicMethods["setupTokenPairByPasswordGrantType"] = function (username, password) {
|
||||
if (!username || !password) {
|
||||
throw new Error("{/modules/oauth/token-handlers.js} Could not set up access token pair by " +
|
||||
"password grant type. Either username of logged in user, password or both are missing " +
|
||||
"as input - setupTokenPairByPasswordGrantType(x, y)");
|
||||
} else {
|
||||
privateMethods.setUpEncodedTenantBasedClientAppCredentials(username);
|
||||
var encodedClientAppCredentials =
|
||||
session.get(constants["ENCODED_TENANT_BASED_CLIENT_APP_CREDENTIALS_PORTAL_APP"]);
|
||||
if (!encodedClientAppCredentials) {
|
||||
throw new Error("{/modules/oauth/token-handlers.js} Could not set up access token pair by " +
|
||||
"password grant type. Encoded client credentials are " +
|
||||
"missing - setupTokenPairByPasswordGrantType(x, y)");
|
||||
} else {
|
||||
var tokenData;
|
||||
// tokenPair will include current access token as well as current refresh token
|
||||
var arrayOfScopes = configs["authorization"]["methods"]["oauth"]["attributes"]["scopes"];
|
||||
var stringOfScopes = "";
|
||||
arrayOfScopes.forEach(function (entry) {
|
||||
stringOfScopes += entry + " ";
|
||||
});
|
||||
tokenData = tokenUtil.
|
||||
getTokenPairAndScopesByPasswordGrantType(username,
|
||||
encodeURIComponent(password), encodedClientAppCredentials, stringOfScopes);
|
||||
if (!tokenData) {
|
||||
throw new Error("{/app/modules/oauth/token-handlers.js} Could not set up " +
|
||||
"token pair by password grant type. Error in token " +
|
||||
"retrieval - setupTokenPairByPasswordGrantType(x, y)");
|
||||
} else {
|
||||
var tokenPair = {};
|
||||
tokenPair["accessToken"] = tokenData["accessToken"];
|
||||
tokenPair["refreshToken"] = tokenData["refreshToken"];
|
||||
// setting up token pair into session context as a string
|
||||
session.put(constants["ACCESS_TOKEN_PAIR_IDENTIFIER_FOR_PORTAL"], stringify(tokenPair));
|
||||
var scopes = tokenData.scopes.split(" ");
|
||||
// adding allowed scopes to the session
|
||||
session.put(constants["ALLOWED_SCOPES"], scopes);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get an AccessToken pair based on SAML assertion
|
||||
* @param samlToken SAML assertion
|
||||
* @param username {{clientId:"", clientSecret:""}}
|
||||
*/
|
||||
publicMethods["setupTokenPairBySamlGrantType"] = function (username, samlToken) {
|
||||
if (!username || !samlToken) {
|
||||
throw new Error("{/modules/oauth/token-handlers.js} Could not set up access token pair by " +
|
||||
"saml grant type. Either username of logged in user, samlToken or both are missing " +
|
||||
"as input - setupTokenPairBySamlGrantType(x, y)");
|
||||
} else {
|
||||
privateMethods.setUpEncodedTenantBasedClientAppCredentials(username);
|
||||
var encodedClientAppCredentials =
|
||||
session.get(constants["ENCODED_TENANT_BASED_CLIENT_APP_CREDENTIALS_PORTAL_APP"]);
|
||||
if (!encodedClientAppCredentials) {
|
||||
throw new Error("{/app/modules/oauth/token-handlers.js} Could not set up access token pair " +
|
||||
"by saml grant type. Encoded client credentials are " +
|
||||
"missing - setupTokenPairBySamlGrantType(x, y)");
|
||||
} else {
|
||||
var tokenData;
|
||||
// accessTokenPair will include current access token as well as current refresh token
|
||||
tokenData = tokenUtil.
|
||||
getTokenPairAndScopesByJWTGrantType(username, encodedClientAppCredentials, "PRODUCTION");
|
||||
if (!tokenData) {
|
||||
throw new Error("{/modules/oauth/token-handlers.js} Could not set up token " +
|
||||
"pair by saml grant type. Error in token " +
|
||||
"retrieval - setupTokenPairBySamlGrantType(x, y)");
|
||||
} else {
|
||||
var tokenPair = {};
|
||||
tokenPair["accessToken"] = tokenData["accessToken"];
|
||||
tokenPair["refreshToken"] = tokenData["refreshToken"];
|
||||
// setting up access token pair into session context as a string
|
||||
session.put(constants["ACCESS_TOKEN_PAIR_IDENTIFIER_FOR_PORTAL"], stringify(tokenPair));
|
||||
|
||||
var scopes = tokenData.scopes.split(" ");
|
||||
// adding allowed scopes to the session
|
||||
session.put(constants["ALLOWED_SCOPES"], scopes);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Set access token and refresh token using refresh token grant type
|
||||
*/
|
||||
publicMethods["refreshTokenPair"] = function () {
|
||||
var currentTokenPair = parse(session.get(constants["ACCESS_TOKEN_PAIR_IDENTIFIER_FOR_PORTAL"]));
|
||||
// currentTokenPair includes current access token as well as current refresh token
|
||||
var encodedClientAppCredentials
|
||||
= session.get(constants["ENCODED_TENANT_BASED_CLIENT_APP_CREDENTIALS_PORTAL_APP"]);
|
||||
if (!currentTokenPair || !encodedClientAppCredentials) {
|
||||
throw new Error("{/modules/oauth/token-handlers.js} Error in refreshing tokens. Either the " +
|
||||
"token pair, encoded client app credentials or both input are not found under " +
|
||||
"session context - refreshTokenPair()");
|
||||
} else {
|
||||
var newTokenPair = tokenUtil.
|
||||
getNewTokenPairByRefreshToken(currentTokenPair["refreshToken"], encodedClientAppCredentials);
|
||||
if (!newTokenPair) {
|
||||
log.error("{/app/modules/oauth/token-handlers.js} Error in refreshing token pair. " +
|
||||
"Unable to update session context with new access token pair - refreshTokenPair()");
|
||||
} else {
|
||||
session.put(constants["ACCESS_TOKEN_PAIR_IDENTIFIER_FOR_PORTAL"], stringify(newTokenPair));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* If gateway is enable, apiManagerClientAppRegistrationServiceURL is used to create an oauth application or
|
||||
* else DCR endpoint is used to create an oauth application
|
||||
* @param username username of current logged user
|
||||
*/
|
||||
privateMethods["setUpEncodedTenantBasedClientAppCredentials"] = function (username) {
|
||||
if (!username) {
|
||||
throw new Error("{/modules/oauth/token-handlers.js} Could not set up encoded tenant based " +
|
||||
"client credentials to session context. No username of logged in user is found as " +
|
||||
"input - setUpEncodedTenantBasedClientAppCredentials(x)");
|
||||
} else {
|
||||
if (configs["authorization"]["methods"]["oauth"]["attributes"]["apimgt-gateway"]) {
|
||||
var tenantBasedClientAppCredentials = tokenUtil.getTenantBasedClientAppCredentials(username);
|
||||
if (!tenantBasedClientAppCredentials) {
|
||||
throw new Error("{/modules/oauth/token-handlers.js} Could not set up encoded tenant " +
|
||||
"based client credentials to session context as the server is unable " +
|
||||
"to obtain such credentials - setUpEncodedTenantBasedClientAppCredentials(x)");
|
||||
} else {
|
||||
var encodedTenantBasedClientAppCredentials =
|
||||
tokenUtil.encode(tenantBasedClientAppCredentials["clientId"] + ":" +
|
||||
tenantBasedClientAppCredentials["clientSecret"]);
|
||||
// setting up encoded tenant based client credentials to session context.
|
||||
session.put(constants["ENCODED_TENANT_BASED_CLIENT_APP_CREDENTIALS_PORTAL_APP"],
|
||||
encodedTenantBasedClientAppCredentials);
|
||||
}
|
||||
} else {
|
||||
var dynamicClientAppCredentials = tokenUtil.getDynamicClientAppCredentials(username);
|
||||
if (!dynamicClientAppCredentials) {
|
||||
throw new Error("{/modules/oauth/token-handlers.js} Could not set up encoded tenant based " +
|
||||
"client credentials to session context as the server is unable to obtain " +
|
||||
"dynamic client credentials - setUpEncodedTenantBasedClientAppCredentials(x)");
|
||||
}
|
||||
var encodedTenantBasedClientAppCredentials =
|
||||
tokenUtil.encode(dynamicClientAppCredentials["clientId"] + ":" +
|
||||
dynamicClientAppCredentials["clientSecret"]);
|
||||
// setting up encoded tenant based client credentials to session context.
|
||||
session.put(constants["ENCODED_TENANT_BASED_CLIENT_APP_CREDENTIALS_PORTAL_APP"],
|
||||
encodedTenantBasedClientAppCredentials);
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
return publicMethods;
|
||||
}();
|
@ -1,245 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
|
||||
.truncate {
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validation messages
|
||||
*/
|
||||
.required {
|
||||
color: #e74c3c;
|
||||
}
|
||||
|
||||
.required-error {
|
||||
background: #a94442;
|
||||
border: 1px solid #a94442;
|
||||
padding: 6px 12px;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
/**
|
||||
* Theme overrides
|
||||
*/
|
||||
.breadcrumb li .fw-home {
|
||||
float: left;
|
||||
padding-top: 2px;
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
||||
/**
|
||||
* Auth menu
|
||||
*/
|
||||
.auth .hidden-xs {
|
||||
line-height: 38px;
|
||||
}
|
||||
|
||||
.auth-xs {
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.auth-xs ul {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
line-height: 28px;
|
||||
background-color: #2a80b9;
|
||||
}
|
||||
|
||||
.auth-xs li {
|
||||
color: #ccc;
|
||||
}
|
||||
|
||||
.auth-xs li a {
|
||||
display: block;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.auth-xs li a:hover {
|
||||
background-color: #499dd5;
|
||||
}
|
||||
|
||||
ul.dropdown-menu.more-actions-button {
|
||||
list-style-type: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
overflow: hidden;
|
||||
width: 40px;
|
||||
background: #F9F9F9;
|
||||
border-bottom: 1px solid #EFEFEF;
|
||||
min-width: 45px;
|
||||
|
||||
}
|
||||
|
||||
ul.dropdown-menu.more-actions-button > li {
|
||||
height: 40px;
|
||||
width: 40px;
|
||||
border: 1px;
|
||||
}
|
||||
|
||||
ul.dropdown-menu.more-actions-button > li > button {
|
||||
border-bottom: 1px solid #e4e4e4;
|
||||
border-top: 1px solid darkred;
|
||||
}
|
||||
|
||||
.btn-group.open .dropdown-toggle {
|
||||
-webkit-box-shadow: none;
|
||||
box-shadow: none;
|
||||
border: 0px;
|
||||
}
|
||||
|
||||
.btn-custom {
|
||||
border-width: 1px;
|
||||
}
|
||||
|
||||
|
||||
.cloud-menu .popover {
|
||||
border-radius: 0px;
|
||||
width: 24em;
|
||||
left: -21.1em !important;
|
||||
max-width: 32em;
|
||||
background-color: #006690
|
||||
}
|
||||
.cloud-menu .popover-title,.navbar-header .popover-title {
|
||||
background-color: #006690;
|
||||
font-size: 16px;
|
||||
border-bottom: none;
|
||||
font-weight: 400;
|
||||
}
|
||||
.cloud-menu .popover.bottom>.arrow{
|
||||
margin-left:-2px;
|
||||
}
|
||||
.cloud-menu .popover.bottom>.arrow:after,.navbar-header .popover.bottom>.arrow:after{
|
||||
border-bottom-color: #006690;
|
||||
}
|
||||
.cloud-block {
|
||||
float: left;
|
||||
width: 8.2em;
|
||||
height: 8.2em;
|
||||
background-color: #fff;
|
||||
margin: 0.5em 0em 0.5em 0.5em;
|
||||
text-align: center;
|
||||
vertical-align: middle;
|
||||
}
|
||||
.cloud-name {
|
||||
font-size:14px;
|
||||
margin-top: .5em;
|
||||
font-weight: 400;
|
||||
}
|
||||
.cloud-menu-popover {
|
||||
position: relative;
|
||||
float: right;
|
||||
padding: 0px 8px;
|
||||
background-color: transparent;
|
||||
background-image: none;
|
||||
border: 1px solid transparent;
|
||||
border-radius: 4px;
|
||||
color: #fff;
|
||||
cursor: pointer;
|
||||
}
|
||||
#cloud-menu-popover-xs {
|
||||
color: #fff;
|
||||
line-height:24px;
|
||||
border: none;
|
||||
margin-right: 15px!important;
|
||||
}
|
||||
.navbar-toggle{
|
||||
border:none;
|
||||
border-radius: 0px;
|
||||
}
|
||||
.navbar-header .popover {
|
||||
border-radius: 0px;
|
||||
width: 21em;
|
||||
max-width:32em;
|
||||
background-color: #006690;
|
||||
}
|
||||
.navbar-header .popover .popover-content{
|
||||
padding:0px;
|
||||
}
|
||||
.cloud-menu .popover-content {
|
||||
padding: 0px;
|
||||
}
|
||||
.cloud-actions {
|
||||
background-color: #005578;
|
||||
float: left;
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
left: 0px;
|
||||
overflow:hidden;
|
||||
}
|
||||
.cloud-actions h3 {
|
||||
font-size: 16px;
|
||||
font-weight: 400;
|
||||
padding-left: 14px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
.cloud-block-invert {
|
||||
color: #fff;
|
||||
float: left;
|
||||
width: 8.2em;
|
||||
height: 8.2em;
|
||||
background-color: #1f1f1f;
|
||||
margin: 0.5em 0em 0.5em 0.5em;
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.cloud-block-default {
|
||||
color: #006690;
|
||||
background-color: #fff;
|
||||
cursor: pointer;
|
||||
}
|
||||
.cloud-actions a:hover {
|
||||
color: #d7d5d5;
|
||||
background-color: #3d3d3d;
|
||||
text-decoration: none
|
||||
}
|
||||
.cloud-apps a {
|
||||
text-decoration: none;
|
||||
color: #006690 !important;
|
||||
cursor: pointer
|
||||
}
|
||||
.cloud-apps a:hover {
|
||||
text-decoration: none;
|
||||
color: #006690;
|
||||
background-color: #c5c5c5;
|
||||
}
|
||||
.cloud-apps .cloud-actions a {
|
||||
color: #fff
|
||||
}
|
||||
|
||||
.add-padding-top-3x {
|
||||
padding-top: 15px !important;
|
||||
}
|
||||
|
||||
.nav li a{
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.cloud-menu-content li a{
|
||||
color:inherit;
|
||||
}
|
||||
|
||||
html{
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
body{
|
||||
height: calc(100% - 50px);
|
||||
}
|
@ -1,204 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
$(function () {
|
||||
|
||||
var dashboardsApi = ues.utils.tenantPrefix() + 'apis/dashboards';
|
||||
var dashboards = [];
|
||||
var isStillLoading = false;
|
||||
var nextStart = 0;
|
||||
var hasMore = true;
|
||||
|
||||
/**
|
||||
* Page count.
|
||||
* @const
|
||||
*/
|
||||
var PAGE_COUNT = 10;
|
||||
|
||||
// Pre-compiling handlebar templates
|
||||
var dashboardsListHbs = Handlebars.compile($("#ues-dashboards-list-hbs").html());
|
||||
var dashboardThumbnailHbs = Handlebars.compile($("#ues-dashboard-thumbnail-hbs").html());
|
||||
var dashboardConfirmHbs = Handlebars.compile($("#ues-dashboard-confirm-hbs").html());
|
||||
var dashboardsEmptyHbs = Handlebars.compile($("#ues-dashboards-empty-hbs").html());
|
||||
Handlebars.registerPartial('ues-dashboard-thumbnail-hbs', dashboardThumbnailHbs);
|
||||
|
||||
/**
|
||||
* Find the dashboard using dashboard id.
|
||||
* @param id
|
||||
* @return {object}
|
||||
* @private
|
||||
* */
|
||||
var findDashboard = function (id) {
|
||||
var i;
|
||||
var dashboard;
|
||||
var length = dashboards.length;
|
||||
for (i = 0; i < length; i++) {
|
||||
dashboard = dashboards[i];
|
||||
if (dashboard.id === id) {
|
||||
return dashboard;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Delete the selected dashboard
|
||||
* @param el:-selected dashboard element
|
||||
* @private
|
||||
* */
|
||||
var deleteDashboard = function (el) {
|
||||
var button = Ladda.create(el[0]);
|
||||
button.start();
|
||||
var id = el.closest('.ues-dashboard').data('id');
|
||||
$.ajax({
|
||||
url: dashboardsApi + '/' + id,
|
||||
method: 'DELETE',
|
||||
async : false,
|
||||
success: function () {
|
||||
button.stop();
|
||||
location.reload();
|
||||
},
|
||||
error: function () {
|
||||
button.stop();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Load the list of dashboards available.
|
||||
* @private
|
||||
* */
|
||||
var loadDashboards = function () {
|
||||
isStillLoading = true;
|
||||
|
||||
if (!hasMore) {
|
||||
isStillLoading = false;
|
||||
$('.ues-dashboard').each(function (i, obj) {
|
||||
if ($(this).find('.ues-dashboard-share').length) {
|
||||
$(this).addClass("shared");
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
ues.store.assets('dashboard', {
|
||||
start: nextStart,
|
||||
count: PAGE_COUNT
|
||||
}, function (err, data) {
|
||||
var dashboardsEl = $('#ues-portal').find('.ues-dashboards');
|
||||
hasMore = data.length;
|
||||
if (!hasMore && nextStart === 0) {
|
||||
dashboardsEl.append(dashboardsEmptyHbs());
|
||||
return;
|
||||
}
|
||||
|
||||
nextStart += PAGE_COUNT;
|
||||
dashboards = dashboards.concat(data);
|
||||
dashboardsEl.append(dashboardsListHbs(data));
|
||||
|
||||
var win = $(window);
|
||||
var doc = $(document);
|
||||
isStillLoading = false;
|
||||
if (doc.height() > win.height()) {
|
||||
return;
|
||||
}
|
||||
|
||||
loadDashboards();
|
||||
|
||||
$(".disable").on('click', function (event) {
|
||||
event.preventDefault();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialize the UI functionality such as binding events.
|
||||
* @private
|
||||
* */
|
||||
var initUI = function () {
|
||||
var portal = $('#ues-portal');
|
||||
portal.on('click', '.ues-dashboards .ues-dashboard-trash-handle', function (e) {
|
||||
e.preventDefault();
|
||||
var thiz = $(this);
|
||||
var dashboardEl = thiz.closest('.ues-dashboard');
|
||||
var id = dashboardEl.data('id');
|
||||
var dashboard = findDashboard(id);
|
||||
dashboardEl.html(dashboardConfirmHbs(dashboard));
|
||||
});
|
||||
|
||||
portal.on('click', '.ues-dashboards .ues-dashboard-trash-confirm', function (e) {
|
||||
e.preventDefault();
|
||||
deleteDashboard($(this));
|
||||
});
|
||||
|
||||
portal.on('click', '.ues-dashboards .ues-dashboard-trash-cancel', function (e) {
|
||||
e.preventDefault();
|
||||
var thiz = $(this);
|
||||
var dashboardEl = thiz.closest('.ues-dashboard');
|
||||
var id = dashboardEl.data('id');
|
||||
var dashboard = findDashboard(id);
|
||||
dashboardEl.html(dashboardThumbnailHbs(dashboard));
|
||||
});
|
||||
|
||||
portal.on('click', '.ues-view:not(.disable)', function(e) {
|
||||
e.preventDefault();
|
||||
window.open($(this).attr('href'), '_blank');
|
||||
});
|
||||
|
||||
$('#filter-dashboards a').on('click', function () {
|
||||
$('#filter').html($(this).text());
|
||||
var filter = $(this).data('filter');
|
||||
|
||||
$('.ues-dashboard-container').each(function (i, obj) {
|
||||
if (filter === "All") {
|
||||
$(this).show();
|
||||
} else {
|
||||
if ($(this).find('.ues-dashboard-share').length) {
|
||||
filter === "Shared" ? $(this).show() : $(this).hide();
|
||||
} else {
|
||||
filter === "Shared" ? $(this).hide() : $(this).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$(window).scroll(function () {
|
||||
var win = $(window);
|
||||
var doc = $(document);
|
||||
if (win.scrollTop() + win.height() < doc.height() - 100) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isStillLoading) {
|
||||
loadDashboards();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$(document).ready(function () {
|
||||
if($('#cloud-menu-popover').length) {
|
||||
$('#cloud-menu-popover i.fw-tiles').popover({
|
||||
html: true,
|
||||
trigger:'click',
|
||||
title: function() {
|
||||
return $("#popover-head").html();
|
||||
},
|
||||
content: function() {
|
||||
return $("#popover-content").html();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
initUI();
|
||||
loadDashboards();
|
||||
});
|
@ -1,60 +0,0 @@
|
||||
<!--
|
||||
~ Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
~
|
||||
~ Licensed 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.
|
||||
-->
|
||||
|
||||
<ServiceProvider>
|
||||
<ApplicationID>9</ApplicationID>
|
||||
<ApplicationName>portal</ApplicationName>
|
||||
<Description>Carbon Dashboards Portal</Description>
|
||||
<InboundAuthenticationConfig>
|
||||
<InboundAuthenticationRequestConfigs>
|
||||
<InboundAuthenticationRequestConfig>
|
||||
<InboundAuthKey>portal</InboundAuthKey>
|
||||
<InboundAuthType>samlsso</InboundAuthType>
|
||||
<Properties>
|
||||
</Properties>
|
||||
</InboundAuthenticationRequestConfig>
|
||||
</InboundAuthenticationRequestConfigs>
|
||||
</InboundAuthenticationConfig>
|
||||
<LocalAndOutBoundAuthenticationConfig>
|
||||
<AuthenticationSteps>
|
||||
<AuthenticationStep>
|
||||
<StepOrder>1</StepOrder>
|
||||
<LocalAuthenticatorConfigs>
|
||||
<LocalAuthenticatorConfig>
|
||||
<Name>BasicAuthenticator</Name>
|
||||
<DisplayName>basicauth</DisplayName>
|
||||
<IsEnabled>true</IsEnabled>
|
||||
</LocalAuthenticatorConfig>
|
||||
</LocalAuthenticatorConfigs>
|
||||
<SubjectStep>true</SubjectStep>
|
||||
<AttributeStep>true</AttributeStep>
|
||||
</AuthenticationStep>
|
||||
</AuthenticationSteps>
|
||||
<UseUserstoreDomainInUsername>true</UseUserstoreDomainInUsername>
|
||||
<UseTenantDomainInUsername>true</UseTenantDomainInUsername>
|
||||
</LocalAndOutBoundAuthenticationConfig>
|
||||
<RequestPathAuthenticatorConfigs>
|
||||
</RequestPathAuthenticatorConfigs>
|
||||
<InboundProvisioningConfig>
|
||||
</InboundProvisioningConfig>
|
||||
<OutboundProvisioningConfig>
|
||||
</OutboundProvisioningConfig>
|
||||
<ClaimConfig>
|
||||
<AlwaysSendMappedLocalSubjectId>true</AlwaysSendMappedLocalSubjectId>
|
||||
</ClaimConfig>
|
||||
<PermissionAndRoleConfig>
|
||||
</PermissionAndRoleConfig>
|
||||
</ServiceProvider>
|
@ -1,96 +0,0 @@
|
||||
{
|
||||
"isCloud" : false,
|
||||
"store": {
|
||||
"types": ["fs"]
|
||||
},
|
||||
"gadgetGeneration" :{
|
||||
"isCreateGadgetEnable": false,
|
||||
"ignoreProviders": ["rt"]
|
||||
},
|
||||
"authentication": {
|
||||
"activeMethod": "sso",
|
||||
"methods": {
|
||||
"sso": {
|
||||
"attributes": {
|
||||
"issuer": "portal",
|
||||
"identityProviderURL": "%https.host%/samlsso",
|
||||
"responseSigningEnabled": true,
|
||||
"validateAssertionValidityPeriod": true,
|
||||
"validateAudienceRestriction": true,
|
||||
"assertionSigningEnabled": true,
|
||||
"acs": "%https.host%/portal/acs",
|
||||
"identityAlias": "wso2carbon",
|
||||
"defaultNameIDPolicy": "urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified",
|
||||
"useTenantKey": false,
|
||||
"isPassive": false
|
||||
}
|
||||
},
|
||||
"basic": {
|
||||
"attributes": {}
|
||||
}
|
||||
}
|
||||
},
|
||||
"authorization": {
|
||||
"activeMethod": "oauth",
|
||||
"methods": {
|
||||
"oauth": {
|
||||
"attributes": {
|
||||
"apimgt-gateway": true,
|
||||
"oauthProvider": {
|
||||
"appRegistration": {
|
||||
"appType": "webapp",
|
||||
"clientName": "portal",
|
||||
"owner": "admin",
|
||||
"password":"admin",
|
||||
"dynamicClientAppRegistrationServiceURL": "https://localhost:9443/dynamic-client-web/register",
|
||||
"apiManagerClientAppRegistrationServiceURL": "%https.host%/api-application-registration/register/tenants",
|
||||
"grantType": "password refresh_token urn:ietf:params:oauth:grant-type:saml2-bearer urn:ietf:params:oauth:grant-type:jwt-bearer",
|
||||
"tokenScope": "admin",
|
||||
"callbackUrl": "%https.host%/portal",
|
||||
"saasApp":true,
|
||||
"samlGrantTypeName":"urn:ietf:params:oauth:grant-type:saml2-bearer"
|
||||
},
|
||||
"tokenServiceURL": "https://localhost:9443/oauth2/token"
|
||||
},
|
||||
"adminUser":"admin@carbon.super",
|
||||
"adminUserTenantId":"-1234",
|
||||
"adminRole":"admin",
|
||||
"scopes" : [
|
||||
"device:view"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"designers": [
|
||||
"Internal/everyone"
|
||||
],
|
||||
"tenantPrefix": "/t",
|
||||
"shareStore": false,
|
||||
"theme": "basic",
|
||||
"cacheTimeoutSeconds": "5",
|
||||
"cacheSizeBytes": "1073741824",
|
||||
"defaultDashboardRedirect": false,
|
||||
"isCreateGadgetEnable": true,
|
||||
"isSecureVaultEnabled" : false,
|
||||
"assets": {
|
||||
"gadget": {
|
||||
"fileSizeLimit": 5
|
||||
},
|
||||
"layout": {
|
||||
"fileSizeLimit": 1
|
||||
}
|
||||
},
|
||||
"oauth": {
|
||||
"username": "admin",
|
||||
"password": "admin"
|
||||
},
|
||||
"host": {
|
||||
"hostname": "localhost",
|
||||
"port": "",
|
||||
"protocol": ""
|
||||
},
|
||||
"queryParameters" : {
|
||||
"passBetweenPages" : ["shared"]
|
||||
}
|
||||
}
|
@ -1,195 +0,0 @@
|
||||
{
|
||||
"initScripts": [
|
||||
"js/dashboard-deployer.js"
|
||||
],
|
||||
"welcomeFiles": [
|
||||
"routers/tenant.jag"
|
||||
],
|
||||
"errorPages": {
|
||||
"500": "/controllers/error-pages/error500.html",
|
||||
"404": "/controllers/error-pages/error404.html",
|
||||
"401": "/controllers/error-pages/error401.html",
|
||||
"405": "/controllers/error-pages/error405.html",
|
||||
"403": "/controllers/error-pages/error403.html",
|
||||
"400": "/controllers/error-pages/error400.html"
|
||||
},
|
||||
"urlMappings": [
|
||||
{
|
||||
"url": "/login-controller",
|
||||
"path": "/routers/tenant.jag"
|
||||
},
|
||||
{
|
||||
"url": "/login",
|
||||
"path": "/routers/tenant.jag"
|
||||
},
|
||||
{
|
||||
"url": "/logout",
|
||||
"path": "/routers/tenant.jag"
|
||||
},
|
||||
{
|
||||
"url": "/t/*",
|
||||
"path": "/routers/tenant.jag"
|
||||
},
|
||||
{
|
||||
"url": "/apis/*",
|
||||
"path": "/routers/tenant.jag"
|
||||
},
|
||||
{
|
||||
"url": "/dashboards/*",
|
||||
"path": "/routers/tenant.jag"
|
||||
},
|
||||
{
|
||||
"url": "/gadget/*",
|
||||
"path": "/routers/tenant.jag"
|
||||
},
|
||||
{
|
||||
"url": "/layout/*",
|
||||
"path": "/routers/tenant.jag"
|
||||
},
|
||||
{
|
||||
"url": "/assets/*",
|
||||
"path": "/routers/tenant.jag"
|
||||
},
|
||||
{
|
||||
"url": "/create-dashboard",
|
||||
"path": "/routers/tenant.jag"
|
||||
},
|
||||
{
|
||||
"url": "/dashboard-settings/*",
|
||||
"path": "/routers/tenant.jag"
|
||||
},
|
||||
{
|
||||
"url": "/select-layout",
|
||||
"path": "/routers/tenant.jag"
|
||||
},
|
||||
{
|
||||
"url": "/create-gadget",
|
||||
"path": "/routers/tenant.jag"
|
||||
},
|
||||
{
|
||||
"url": "/upload-gadget",
|
||||
"path": "/routers/tenant.jag"
|
||||
},
|
||||
{
|
||||
"url": "/upload-layout",
|
||||
"path": "/routers/tenant.jag"
|
||||
},
|
||||
{
|
||||
"url": "/geojson/world/*",
|
||||
"path": "/templates/geojson/world.json"
|
||||
},
|
||||
{
|
||||
"url": "/geojson/europe/*",
|
||||
"path": "/templates/geojson/europe.json"
|
||||
},
|
||||
{
|
||||
"url": "/geojson/usa/*",
|
||||
"path": "/templates/geojson/usa.json"
|
||||
},
|
||||
{
|
||||
"url": "/geojson/countryInfo/*",
|
||||
"path": "/templates/geojson/countryInfo.json"
|
||||
},
|
||||
{
|
||||
"url": "/geojson/usaInfo/*",
|
||||
"path": "/templates/geojson/usaInfo.json"
|
||||
},
|
||||
{
|
||||
"url": "/acs",
|
||||
"path": "/controllers/acs.jag"
|
||||
},
|
||||
{
|
||||
"url": "/banners/*",
|
||||
"path": "/routers/tenant.jag"
|
||||
},
|
||||
{
|
||||
"url": "/gadgets/*",
|
||||
"path": "/routers/tenant.jag"
|
||||
},
|
||||
{
|
||||
"url": "/configs/designer.json",
|
||||
"path": "/controllers/error-pages/error404.html"
|
||||
}
|
||||
],
|
||||
"listeners": [
|
||||
{
|
||||
"class": "org.owasp.csrfguard.CsrfGuardServletContextListener"
|
||||
},
|
||||
{
|
||||
"class": "org.owasp.csrfguard.CsrfGuardHttpSessionListener"
|
||||
}
|
||||
],
|
||||
"servlets": [
|
||||
{
|
||||
"name": "JavaScriptServlet",
|
||||
"class": "org.owasp.csrfguard.servlet.JavaScriptServlet"
|
||||
}
|
||||
],
|
||||
"servletMappings": [
|
||||
{
|
||||
"name": "JavaScriptServlet",
|
||||
"url": "/csrf.js"
|
||||
}
|
||||
],
|
||||
"contextParams": [
|
||||
{
|
||||
"name": "Owasp.CsrfGuard.Config",
|
||||
"value": "repository/conf/security/Owasp.CsrfGuard.dashboard.properties"
|
||||
}
|
||||
],
|
||||
"filters": [
|
||||
{
|
||||
"name": "ContentTypeBasedCachePreventionFilter",
|
||||
"class": "org.wso2.carbon.ui.filters.cache.ContentTypeBasedCachePreventionFilter",
|
||||
"params" : [
|
||||
{"name" : "patterns", "value" : "text/html\" ,application/json\" ,text/plain"},
|
||||
{"name" : "filterAction", "value" : "enforce"},
|
||||
{"name" : "httpHeaders", "value" : "Cache-Control: no-store, no-cache, must-revalidate, private"}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "HttpHeaderSecurityFilter",
|
||||
"class": "org.apache.catalina.filters.HttpHeaderSecurityFilter",
|
||||
"params": [
|
||||
{
|
||||
"name": "hstsEnabled",
|
||||
"value": "false"
|
||||
},
|
||||
{
|
||||
"name": "antiClickJackingOption",
|
||||
"value": "SAMEORIGIN"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "TenantStoresFilter",
|
||||
"class": "org.wso2.carbon.dashboard.store.filter.TenantStoreFilter"
|
||||
},
|
||||
{
|
||||
"name" : "CSRFGuard",
|
||||
"class" : "org.owasp.csrfguard.CsrfGuardFilter"
|
||||
}
|
||||
],
|
||||
"filterMappings": [
|
||||
{
|
||||
"name": "HttpHeaderSecurityFilter",
|
||||
"url": "*"
|
||||
},
|
||||
{
|
||||
"name": "TenantStoresFilter",
|
||||
"url": "/store/*"
|
||||
},
|
||||
{
|
||||
"name": "TenantStoresFilter",
|
||||
"url": "/temp/*"
|
||||
},
|
||||
{
|
||||
"name" : "CSRFGuard",
|
||||
"url" : "/*"
|
||||
},
|
||||
{
|
||||
"name":"ContentTypeBasedCachePreventionFilter",
|
||||
"url":"*"
|
||||
}
|
||||
]
|
||||
}
|
@ -1,598 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
var utils = function () {
|
||||
var log = new Log("/modules/oauth/token-handler-utils.js");
|
||||
|
||||
var configs = require('/configs/portal.js').config();
|
||||
var constants = require("/modules/constants.js");
|
||||
var carbon = require("carbon");
|
||||
|
||||
//noinspection JSUnresolvedVariable
|
||||
var Base64 = Packages.org.apache.commons.codec.binary.Base64;
|
||||
//noinspection JSUnresolvedVariable
|
||||
var String = Packages.java.lang.String;
|
||||
|
||||
var publicMethods = {};
|
||||
var privateMethods = {};
|
||||
|
||||
publicMethods["encode"] = function (payload) {
|
||||
return String(Base64.encodeBase64(String(payload).getBytes()));
|
||||
};
|
||||
|
||||
publicMethods["decode"] = function (payload) {
|
||||
return String(Base64.decodeBase64(String(payload).getBytes()));
|
||||
};
|
||||
|
||||
/**
|
||||
* Check whether this application is oauth enable or not
|
||||
* @returns boolean if oauth enable
|
||||
*/
|
||||
publicMethods["checkOAuthEnabled"] = function () {
|
||||
if (constants.AUTHORIZATION_TYPE_OAUTH === configs["authorization"]["activeMethod"]) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set access token into xml http request header
|
||||
* @param xhr xml http request
|
||||
* @returns {*} xhr which has access token it's header
|
||||
*/
|
||||
publicMethods["setAccessToken"] = function (xhr, callback) {
|
||||
var accessToken;
|
||||
if (publicMethods.checkOAuthEnabled()) {
|
||||
try {
|
||||
accessToken = parse(session.get(constants.ACCESS_TOKEN_PAIR_IDENTIFIER_FOR_PORTAL))["accessToken"];
|
||||
xhr.setRequestHeader(constants.AUTHORIZATION_HEADER, constants.BEARER_PREFIX + accessToken);
|
||||
} catch (exception) {
|
||||
log.error("Access token hasn't been set yet, " + exception);
|
||||
} finally {
|
||||
callback(xhr);
|
||||
}
|
||||
}
|
||||
callback(xhr);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get access token of current logged user
|
||||
* @param callBack response with access token
|
||||
*/
|
||||
publicMethods["getAccessToken"] = function (callBack) {
|
||||
var accessToken = null;
|
||||
if (publicMethods.checkOAuthEnabled()) {
|
||||
try {
|
||||
accessToken = parse(session.get(constants.ACCESS_TOKEN_PAIR_IDENTIFIER_FOR_PORTAL))["accessToken"];
|
||||
} catch (exception) {
|
||||
log.error("Access token hasn't been set yet, " + exception);
|
||||
} finally {
|
||||
callBack(accessToken);
|
||||
}
|
||||
}
|
||||
callBack(accessToken);
|
||||
};
|
||||
|
||||
/**
|
||||
* Create error message which adhere to xml http response object
|
||||
* @param statusCode response status code
|
||||
* @param status response status
|
||||
* @param responseText response message
|
||||
* @returns {{statusCode: *, status: *, responseText: *}}
|
||||
*/
|
||||
publicMethods["createXHRObject"] = function (statusCode, status, responseText) {
|
||||
return {"statusCode": statusCode, "status": status, "responseText": responseText};
|
||||
};
|
||||
|
||||
/**
|
||||
* check whether user already logged to system before invoking any apis
|
||||
* @param callBack
|
||||
*/
|
||||
publicMethods["isUserAuthorized"] = function (callBack) {
|
||||
if (session.get("Loged") !== constants.LOGIN_MESSAGE) {
|
||||
callBack(false);
|
||||
} else {
|
||||
callBack(true);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get identity provider uir
|
||||
* @returns {*}
|
||||
*/
|
||||
publicMethods["getIdPServerURL"] = function () {
|
||||
return configs["authorization"]["methods"]["oauth"]["attributes"]["oauthProvider"]["tokenServiceURL"];
|
||||
};
|
||||
|
||||
/**
|
||||
* Get an Access token pair based on client secret
|
||||
* @param encodedClientKeys {{clientId:"", clientSecret:""}}
|
||||
* @param scope eg: PRODUCTION
|
||||
* @param idPServer identity provider url
|
||||
* @returns {{accessToken: *, refreshToken: *}}
|
||||
*/
|
||||
publicMethods["getTokenWithClientSecretType"] = function (encodedClientKeys, scope, idPServer) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
var tokenEndpoint = idPServer;
|
||||
xhr.open(constants.HTTP_POST, tokenEndpoint, false);
|
||||
xhr.setRequestHeader(constants.CONTENT_TYPE_IDENTIFIER, constants.APPLICATION_X_WWW_FOR_URLENCODED);
|
||||
xhr.setRequestHeader(constants.AUTHORIZATION_HEADER, constants.BASIC_PREFIX + encodedClientKeys);
|
||||
xhr.send("grant_type=client_credentials&scope=" + scope);
|
||||
var tokenPair = {};
|
||||
if (xhr.status == constants.HTTP_ACCEPTED) {
|
||||
var data = parse(xhr.responseText);
|
||||
tokenPair.refreshToken = data.refresh_token;
|
||||
tokenPair.accessToken = data.access_token;
|
||||
} else if (xhr.status == constants.HTTP_USER_NOT_AUTHENTICATED) {
|
||||
log.error("Error in obtaining token with client secret grant type, You are not authenticated yet");
|
||||
return null;
|
||||
} else {
|
||||
log.error("Error in obtaining token with client secret grant type, This might be a problem with client meta " +
|
||||
"data which required for client secret grant type");
|
||||
return null;
|
||||
}
|
||||
return tokenPair;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* This will create client id and client secret for a given application
|
||||
* @param properties "callbackUrl": "",
|
||||
* "clientName": "",
|
||||
* "owner": "",
|
||||
* "applicationType": "",
|
||||
* "grantType": "",
|
||||
* "saasApp" :"",
|
||||
* "dynamicClientRegistrationEndPoint" : ""
|
||||
*
|
||||
* @returns {{clientId:*, clientSecret:*}}
|
||||
*/
|
||||
publicMethods["getDynamicClientAppCredentials"] = function (username) {
|
||||
// setting up dynamic client application properties
|
||||
var dcAppProperties = {
|
||||
"applicationType": configs["authorization"]["methods"]["oauth"]["attributes"]["oauthProvider"]["appRegistration"]["appType"],
|
||||
"clientName": configs["authorization"]["methods"]["oauth"]["attributes"]["oauthProvider"]["appRegistration"]["clientName"],
|
||||
"owner": configs["authorization"]["methods"]["oauth"]["attributes"]["oauthProvider"]["appRegistration"]["owner"],
|
||||
"tokenScope": configs["authorization"]["methods"]["oauth"]["attributes"]["oauthProvider"]["appRegistration"]["tokenScope"],
|
||||
"grantType": configs["authorization"]["methods"]["oauth"]["attributes"]["oauthProvider"]["appRegistration"]["grantType"],
|
||||
"callbackUrl": configs["authorization"]["methods"]["oauth"]["attributes"]["oauthProvider"]["appRegistration"]["callbackUrl"],
|
||||
"saasApp" : configs["authorization"]["methods"]["oauth"]["attributes"]["oauthProvider"]["appRegistration"]["saasApp"]
|
||||
};
|
||||
|
||||
var tenantDomain = carbon.server.tenantDomain({username: username});
|
||||
if (!tenantDomain) {
|
||||
log.error("{/modules/oauth/token-handler-utils.js} Error in retrieving tenant " +
|
||||
"based client application credentials. Unable to obtain a valid tenant domain for provided username "+
|
||||
username +"- getDynamicClientAppCredentials(x)");
|
||||
return null;
|
||||
} else {
|
||||
var cachedTenantBasedClientAppCredentials = privateMethods.
|
||||
getCachedTenantBasedClientAppCredentials(tenantDomain);
|
||||
if (cachedTenantBasedClientAppCredentials) {
|
||||
return cachedTenantBasedClientAppCredentials;
|
||||
} else {
|
||||
// calling dynamic client app registration service endpoint
|
||||
var requestURL = configs["authorization"]["methods"]["oauth"]["attributes"]["oauthProvider"]["appRegistration"]
|
||||
["dynamicClientAppRegistrationServiceURL"];
|
||||
var requestPayload = dcAppProperties;
|
||||
var token = publicMethods.encode(configs["authorization"]["methods"]["oauth"]["attributes"]["oauthProvider"]
|
||||
["appRegistration"]["owner"] + ":" + configs["authorization"]["methods"]["oauth"]["attributes"]
|
||||
["oauthProvider"]["appRegistration"]["password"]);
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", requestURL, false);
|
||||
xhr.setRequestHeader("Content-Type", "application/json");
|
||||
xhr.setRequestHeader("Authorization", "Basic "+ token);
|
||||
xhr.send(stringify(requestPayload));
|
||||
var dynamicClientAppCredentials = {};
|
||||
if (xhr["status"] == 201 || xhr["status"] == 200 && xhr["responseText"]) {
|
||||
var responsePayload = parse(xhr["responseText"]);
|
||||
var clientId = responsePayload["client_id"];
|
||||
var clientSecret = responsePayload["client_secret"];
|
||||
if(typeof clientId == "undefined"){
|
||||
clientId = responsePayload["clientId"];
|
||||
}
|
||||
if(typeof clientSecret == "undefined"){
|
||||
clientSecret = responsePayload["clientSecret"];
|
||||
}
|
||||
dynamicClientAppCredentials["clientId"] = clientId;
|
||||
dynamicClientAppCredentials["clientSecret"] = clientSecret;
|
||||
privateMethods.
|
||||
setCachedTenantBasedClientAppCredentials(tenantDomain, dynamicClientAppCredentials);
|
||||
} else if (xhr["status"] == 400) {
|
||||
log.error("{/modules/oauth/token-handler-utils.js - getDynamicClientAppCredentials()} " +
|
||||
"Bad request. Invalid data provided as dynamic client application properties.");
|
||||
dynamicClientAppCredentials = null;
|
||||
} else {
|
||||
log.error("{/modules/oauth/token-handler-utils.js - getDynamicClientAppCredentials()} " +
|
||||
"Error in retrieving dynamic client credentials.");
|
||||
dynamicClientAppCredentials = null;
|
||||
}
|
||||
// returning dynamic client credentials
|
||||
return dynamicClientAppCredentials;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* If gateway is enable, apiManagerClientAppRegistrationServiceURL is used to create oauth application
|
||||
* @param username username of current logged user
|
||||
* @returns {{clientId:*, clientSecret:*}}
|
||||
*/
|
||||
publicMethods["getTenantBasedClientAppCredentials"] = function (username) {
|
||||
if (!username) {
|
||||
log.error("{/modules/oauth/token-handler-utils.js} Error in retrieving tenant " +
|
||||
"based client app credentials. No username " +
|
||||
"as input - getTenantBasedClientAppCredentials(x)");
|
||||
return null;
|
||||
} else {
|
||||
//noinspection JSUnresolvedFunction, JSUnresolvedVariable
|
||||
var tenantDomain = carbon.server.tenantDomain({username: username});
|
||||
|
||||
if (!tenantDomain) {
|
||||
log.error("{/modules/oauth/token-handler-utils.js} Error in retrieving tenant " +
|
||||
"based client application credentials. Unable to obtain a valid tenant domain for provided " +
|
||||
"username - getTenantBasedClientAppCredentials(x, y)");
|
||||
return null;
|
||||
} else {
|
||||
var cachedTenantBasedClientAppCredentials = privateMethods.
|
||||
getCachedTenantBasedClientAppCredentials(tenantDomain);
|
||||
if (cachedTenantBasedClientAppCredentials) {
|
||||
return cachedTenantBasedClientAppCredentials;
|
||||
} else {
|
||||
var adminUsername = configs["authorization"]["methods"]["oauth"]["attributes"]["adminUser"];
|
||||
var adminUserTenantId = configs["authorization"]["methods"]["oauth"]["attributes"]
|
||||
["adminUserTenantId"];
|
||||
//claims required for jwtAuthenticator.
|
||||
var claims = {"http://wso2.org/claims/enduserTenantId": adminUserTenantId,
|
||||
"http://wso2.org/claims/enduser": adminUsername};
|
||||
var jwtToken = publicMethods.getJwtToken(adminUsername, claims);
|
||||
// register a tenant based client app at API Manager
|
||||
var applicationName = configs["authorization"]["methods"]["oauth"]["attributes"]["oauthProvider"]
|
||||
["appRegistration"]["clientName"] + "_" + tenantDomain;
|
||||
var requestURL = configs["authorization"]["methods"]["oauth"]["attributes"]["oauthProvider"]
|
||||
["appRegistration"]["apiManagerClientAppRegistrationServiceURL"] +
|
||||
"?tenantDomain=" + tenantDomain + "&applicationName=" + applicationName;
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", requestURL, false);
|
||||
xhr.setRequestHeader("Content-Type", "application/json");
|
||||
xhr.setRequestHeader("X-JWT-Assertion", "" + jwtToken);
|
||||
xhr.send();
|
||||
if ((xhr["status"] == 201 || xhr["status"] == 200) && xhr["responseText"]) {
|
||||
var responsePayload = parse(xhr["responseText"]);
|
||||
var tenantBasedClientAppCredentials = {};
|
||||
var clientId = responsePayload["client_id"];
|
||||
var clientSecret = responsePayload["client_secret"];
|
||||
if(typeof clientId == "undefined"){
|
||||
clientId = responsePayload["clientId"];
|
||||
}
|
||||
if(typeof clientSecret == "undefined"){
|
||||
clientSecret = responsePayload["clientSecret"];
|
||||
}
|
||||
tenantBasedClientAppCredentials["clientId"] = clientId;
|
||||
tenantBasedClientAppCredentials["clientSecret"] = clientSecret;
|
||||
privateMethods.
|
||||
setCachedTenantBasedClientAppCredentials(tenantDomain, tenantBasedClientAppCredentials);
|
||||
return tenantBasedClientAppCredentials;
|
||||
} else {
|
||||
log.error("{/modules/oauth/token-handler-utils.js} Error in retrieving tenant " +
|
||||
"based client application credentials from API " +
|
||||
"Manager - getTenantBasedClientAppCredentials(x, y)");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Caching oauth application credentials
|
||||
* @param tenantDomain tenant domain where application is been created
|
||||
* @param clientAppCredentials {{clientId:*, clientSecret:*}}
|
||||
*/
|
||||
privateMethods["setCachedTenantBasedClientAppCredentials"] = function (tenantDomain, clientAppCredentials) {
|
||||
var cachedTenantBasedClientAppCredentialsMap = application.get(constants["CACHED_CREDENTIALS_PORTAL_APP"]);
|
||||
if (!cachedTenantBasedClientAppCredentialsMap) {
|
||||
cachedTenantBasedClientAppCredentialsMap = {};
|
||||
cachedTenantBasedClientAppCredentialsMap[tenantDomain] = clientAppCredentials;
|
||||
application.put(constants["CACHED_CREDENTIALS_PORTAL_APP"], cachedTenantBasedClientAppCredentialsMap);
|
||||
} else if (!cachedTenantBasedClientAppCredentialsMap[tenantDomain]) {
|
||||
cachedTenantBasedClientAppCredentialsMap[tenantDomain] = clientAppCredentials;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get oauth application credentials from cache
|
||||
* @param tenantDomain tenant domain where application is been created
|
||||
* @returns {{clientId:*, clientSecret:*}}
|
||||
*/
|
||||
privateMethods["getCachedTenantBasedClientAppCredentials"] = function (tenantDomain) {
|
||||
var cachedTenantBasedClientAppCredentialsMap = application.get(constants["CACHED_CREDENTIALS_PORTAL_APP"]);
|
||||
if (!cachedTenantBasedClientAppCredentialsMap ||
|
||||
!cachedTenantBasedClientAppCredentialsMap[tenantDomain]) {
|
||||
return null;
|
||||
} else {
|
||||
return cachedTenantBasedClientAppCredentialsMap[tenantDomain];
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get access token and refresh token using password grant type
|
||||
* @param username username of the logged user
|
||||
* @param password password of the logged user
|
||||
* @param encodedClientAppCredentials {{clientId:*, clientSecret:*}}
|
||||
* @param scopes scopes list
|
||||
* @returns {{accessToken: *, refreshToken: *}}
|
||||
*/
|
||||
publicMethods["getTokenPairAndScopesByPasswordGrantType"] = function (username, password
|
||||
, encodedClientAppCredentials, scopes) {
|
||||
if (!username || !password || !encodedClientAppCredentials || !scopes) {
|
||||
log.error("{/modules/oauth/token-handler-utils.js} Error in retrieving access token by password " +
|
||||
"grant type. No username, password, encoded client app credentials or scopes are " +
|
||||
"found - getTokenPairAndScopesByPasswordGrantType(a, b, c, d)");
|
||||
return null;
|
||||
} else {
|
||||
// calling oauth provider token service endpoint
|
||||
var requestURL = configs["authorization"]["methods"]["oauth"]["attributes"]["oauthProvider"]
|
||||
["tokenServiceURL"];
|
||||
var requestPayload = "grant_type=password&username=" +
|
||||
username + "&password=" + password + "&scope=" + scopes;
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", requestURL, false);
|
||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
xhr.setRequestHeader("Authorization", "Basic " + encodedClientAppCredentials);
|
||||
xhr.send(requestPayload);
|
||||
|
||||
if (xhr["status"] == 200 && xhr["responseText"]) {
|
||||
var responsePayload = parse(xhr["responseText"]);
|
||||
var tokenData = {};
|
||||
tokenData["accessToken"] = responsePayload["access_token"];
|
||||
tokenData["refreshToken"] = responsePayload["refresh_token"];
|
||||
tokenData["scopes"] = responsePayload["scope"];
|
||||
return tokenData;
|
||||
} else {
|
||||
log.error("{/modules/oauth/token-handler-utils.js} Error in retrieving access token " +
|
||||
"by password grant type - getTokenPairAndScopesByPasswordGrantType(a, b, c, d)");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get access token and refresh token using SAML grant type
|
||||
* @param assertion
|
||||
* @param encodedClientAppCredentials
|
||||
* @param scopes
|
||||
* @returns {{accessToken: *, refreshToken: *}}
|
||||
*/
|
||||
publicMethods["getTokenPairAndScopesByJWTGrantType"] = function (username, encodedClientAppCredentials, scopes) {
|
||||
if (!username || !encodedClientAppCredentials || !scopes) {
|
||||
log.error("{/app/modules/oauth/token-handler-utils.js} Error in retrieving access token by jwt " +
|
||||
"grant type. No assertion, encoded client app credentials or scopes are " +
|
||||
"found - getTokenPairAndScopesByJWTGrantType(x, y, z)");
|
||||
return null;
|
||||
} else {
|
||||
var JWTClientManagerServicePackagePath =
|
||||
"org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerService";
|
||||
//noinspection JSUnresolvedFunction, JSUnresolvedVariable
|
||||
var JWTClientManagerService = carbon.server.osgiService(JWTClientManagerServicePackagePath);
|
||||
//noinspection JSUnresolvedFunction
|
||||
var jwtClient = JWTClientManagerService.getJWTClient();
|
||||
// returning access token by JWT grant type
|
||||
var tokenInfo = jwtClient.getAccessToken(encodedClientAppCredentials,
|
||||
username, scopes);
|
||||
var tokenData = {};
|
||||
tokenData["accessToken"] = tokenInfo.getAccessToken();
|
||||
tokenData["refreshToken"] = tokenInfo.getRefreshToken();
|
||||
tokenData["scopes"] = tokenInfo.getScopes();
|
||||
return tokenData;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get access token and refresh token using SAML grant type
|
||||
* @param assertion
|
||||
* @param encodedClientAppCredentials
|
||||
* @param scopes
|
||||
* @returns {{accessToken: *, refreshToken: *}}
|
||||
*/
|
||||
publicMethods["getTokenPairAndScopesBySAMLGrantType"] = function (assertion, encodedClientAppCredentials, scopes) {
|
||||
if (!assertion || !encodedClientAppCredentials || !scopes) {
|
||||
log.error("{/modules/oauth/token-handler-utils.js} Error in retrieving access token by saml " +
|
||||
"grant type. No assertion, encoded client app credentials or scopes are " +
|
||||
"found - getTokenPairAndScopesBySAMLGrantType(x, y, z)");
|
||||
return null;
|
||||
} else {
|
||||
|
||||
var assertionXML = publicMethods.decode(assertion);
|
||||
/*
|
||||
TODO: make assertion extraction with proper parsing.
|
||||
Since Jaggery XML parser seem to add formatting which causes signature verification to fail.
|
||||
*/
|
||||
var assertionStartMarker = "<saml2:Assertion";
|
||||
var assertionEndMarker = "<\/saml2:Assertion>";
|
||||
var assertionStartIndex = assertionXML.indexOf(assertionStartMarker);
|
||||
var assertionEndIndex = assertionXML.indexOf(assertionEndMarker);
|
||||
|
||||
var extractedAssertion;
|
||||
if (assertionStartIndex == -1 || assertionEndIndex == -1) {
|
||||
log.error("{/modules/oauth/token-handler-utils.js} Error in retrieving access token by saml grant " +
|
||||
"type. Issue in assertion format - getTokenPairAndScopesBySAMLGrantType(x, y, z)");
|
||||
return null;
|
||||
} else {
|
||||
extractedAssertion = assertionXML.
|
||||
substring(assertionStartIndex, assertionEndIndex) + assertionEndMarker;
|
||||
var encodedAssertion = publicMethods.encode(extractedAssertion);
|
||||
// calling oauth provider token service endpoint
|
||||
var requestURL = configs["authorization"]["methods"]["oauth"]["attributes"]["oauthProvider"]
|
||||
["tokenServiceURL"];
|
||||
var requestPayload = "grant_type=urn:ietf:params:oauth:grant-type:saml2-bearer&" +
|
||||
"assertion=" + encodeURIComponent(encodedAssertion) + "&scope=" + scopes;
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", requestURL, false);
|
||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
xhr.setRequestHeader("Authorization", "Basic " + encodedClientAppCredentials);
|
||||
xhr.send(requestPayload);
|
||||
|
||||
if (xhr["status"] == 200 && xhr["responseText"]) {
|
||||
var responsePayload = parse(xhr["responseText"]);
|
||||
var tokenData = {};
|
||||
tokenData["accessToken"] = responsePayload["access_token"];
|
||||
tokenData["refreshToken"] = responsePayload["refresh_token"];
|
||||
tokenData["scopes"] = responsePayload["scope"];
|
||||
return tokenData;
|
||||
} else {
|
||||
log.error("{/modules/oauth/token-handler-utils.js} Error in retrieving access token " +
|
||||
"by password grant type - getTokenPairAndScopesBySAMLGrantType(x, y, z)");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* If access token is expired, try to refresh it using existing refresh token
|
||||
* @param callback
|
||||
*/
|
||||
publicMethods["refreshAccessToken"] = function (callback) {
|
||||
try {
|
||||
if (publicMethods.checkOAuthEnabled()) {
|
||||
var currentTokenPair = parse(session.get(constants["ACCESS_TOKEN_PAIR_IDENTIFIER_FOR_PORTAL"]));
|
||||
// currentTokenPair includes current access token as well as current refresh token
|
||||
var encodedClientAppCredentials
|
||||
= session.get(constants["ENCODED_TENANT_BASED_CLIENT_APP_CREDENTIALS_PORTAL_APP"]);
|
||||
if (!currentTokenPair || !encodedClientAppCredentials) {
|
||||
callback(false);
|
||||
throw new Error("{/modules/oauth/token-handlers.js} Error in refreshing tokens. Either the " +
|
||||
"token pair, encoded client app credentials or both input are not found under " +
|
||||
"session context - refreshTokenPair()");
|
||||
} else {
|
||||
var newTokenPair = publicMethods.
|
||||
getNewTokenPairByRefreshToken(currentTokenPair["refreshToken"], encodedClientAppCredentials);
|
||||
if (!newTokenPair) {
|
||||
log.error("{/app/modules/oauth/token-handlers.js} Error in refreshing token pair. " +
|
||||
"Unable to update session context with new access token pair - refreshTokenPair()");
|
||||
callback(false);
|
||||
} else {
|
||||
session.put(constants["ACCESS_TOKEN_PAIR_IDENTIFIER_FOR_PORTAL"], stringify(newTokenPair));
|
||||
callback(true);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log.error("You have not enable dynamic client yet");
|
||||
callback(false);
|
||||
}
|
||||
} catch (exception) {
|
||||
callback(false);
|
||||
throw "Error while refreshing existing access token, " + exception;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get access token and refresh token using refresh token grant type
|
||||
* @param refreshToken refresh token
|
||||
* @param encodedClientAppCredentials {{clientId:*, clientSecret:*}}
|
||||
* @param scopes
|
||||
* @returns {{accessToken: *, refreshToken: *}}
|
||||
*/
|
||||
publicMethods["getNewTokenPairByRefreshToken"] = function (refreshToken, encodedClientAppCredentials, scopes) {
|
||||
if (!refreshToken || !encodedClientAppCredentials) {
|
||||
log.error("{/modules/oauth/token-handler-utils.js} Error in retrieving new access token " +
|
||||
"by current refresh token. No refresh token or encoded client app credentials are " +
|
||||
"found - getNewTokenPairByRefreshToken(x, y, z)");
|
||||
return null;
|
||||
} else {
|
||||
var requestURL = configs["authorization"]["methods"]["oauth"]["attributes"]["oauthProvider"]
|
||||
["tokenServiceURL"];
|
||||
var requestPayload = "grant_type=refresh_token&refresh_token=" + refreshToken;
|
||||
if (scopes) {
|
||||
requestPayload = requestPayload + "&scope=" + scopes;
|
||||
}
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", requestURL, false);
|
||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
xhr.setRequestHeader("Authorization", "Basic " + encodedClientAppCredentials);
|
||||
xhr.send(requestPayload);
|
||||
|
||||
if (xhr["status"] == 200 && xhr["responseText"]) {
|
||||
var responsePayload = parse(xhr["responseText"]);
|
||||
var tokenPair = {};
|
||||
tokenPair["accessToken"] = responsePayload["access_token"];
|
||||
tokenPair["refreshToken"] = responsePayload["refresh_token"];
|
||||
return tokenPair;
|
||||
} else {
|
||||
log.error("{/modules/oauth/token-handler-utils.js} Error in retrieving new access token by " +
|
||||
"current refresh token - getNewTokenPairByRefreshToken(x, y, z)");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get access token using JWT grant type
|
||||
* @param clientAppCredentials {{clientId:*, clientSecret:*}}
|
||||
* @returns {{accessToken: *, refreshToken: *}}
|
||||
*/
|
||||
publicMethods["getAccessTokenByJWTGrantType"] = function (clientAppCredentials) {
|
||||
if (!clientAppCredentials) {
|
||||
log.error("{/modules/oauth/token-handler-utils.js} Error in retrieving new access token " +
|
||||
"by current refresh token. No client app credentials are found " +
|
||||
"as input - getAccessTokenByJWTGrantType(x)");
|
||||
return null;
|
||||
} else {
|
||||
var JWTClientManagerServicePackagePath =
|
||||
"org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerService";
|
||||
//noinspection JSUnresolvedFunction, JSUnresolvedVariable
|
||||
var JWTClientManagerService = carbon.server.osgiService(JWTClientManagerServicePackagePath);
|
||||
//noinspection JSUnresolvedFunction
|
||||
var jwtClient = JWTClientManagerService.getJWTClient();
|
||||
// returning access token by JWT grant type
|
||||
return jwtClient.getAccessToken(clientAppCredentials["clientId"], clientAppCredentials["clientSecret"],
|
||||
configs["authorization"]["methods"]["oauth"]["attributes"]["oauthProvider"]["appRegistration"]["owner"],
|
||||
null)["accessToken"];
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get jwt token
|
||||
* @param username username of logged user
|
||||
* @param claims claims which are required
|
||||
* @returns {"jwtToken"}
|
||||
*/
|
||||
publicMethods["getJwtToken"] = function (username, claims) {
|
||||
if (!username) {
|
||||
log.error("{/modules/oauth/token-handler-utils.js} Error in retrieving new jwt token");
|
||||
return null;
|
||||
} else {
|
||||
var JWTClientManagerServicePackagePath =
|
||||
"org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerService";
|
||||
//noinspection JSUnresolvedFunction, JSUnresolvedVariable
|
||||
var JWTClientManagerService = carbon.server.osgiService(JWTClientManagerServicePackagePath);
|
||||
//noinspection JSUnresolvedFunction
|
||||
var jwtClient = JWTClientManagerService.getJWTClient();
|
||||
// returning access token by JWT grant type
|
||||
if (claims) {
|
||||
return jwtClient.getJwtToken(username, claims);
|
||||
} else {
|
||||
return jwtClient.getJwtToken(username);
|
||||
}
|
||||
}
|
||||
};
|
||||
return publicMethods;
|
||||
}();
|
@ -1,192 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* -----------------------------------------------------
|
||||
* Following module includes handlers
|
||||
* at Jaggery Layer for handling OAuth tokens.
|
||||
* -----------------------------------------------------
|
||||
*/
|
||||
var handlers = function () {
|
||||
var log = new Log("/modules/oauth/token-handlers.js");
|
||||
|
||||
var tokenUtil = require("/modules/oauth/token-handler-utils.js")["utils"];
|
||||
var constants = require("/modules/constants.js");
|
||||
var configs = require('/configs/portal.js').config();
|
||||
|
||||
var publicMethods = {};
|
||||
var privateMethods = {};
|
||||
|
||||
/**
|
||||
* Get an AccessToken pair based on username and password
|
||||
* @param username username of the logged user
|
||||
* @param password password of the logged user
|
||||
*/
|
||||
publicMethods["setupTokenPairByPasswordGrantType"] = function (username, password) {
|
||||
if (!username || !password) {
|
||||
throw new Error("{/modules/oauth/token-handlers.js} Could not set up access token pair by " +
|
||||
"password grant type. Either username of logged in user, password or both are missing " +
|
||||
"as input - setupTokenPairByPasswordGrantType(x, y)");
|
||||
} else {
|
||||
privateMethods.setUpEncodedTenantBasedClientAppCredentials(username);
|
||||
var encodedClientAppCredentials =
|
||||
session.get(constants["ENCODED_TENANT_BASED_CLIENT_APP_CREDENTIALS_PORTAL_APP"]);
|
||||
if (!encodedClientAppCredentials) {
|
||||
throw new Error("{/modules/oauth/token-handlers.js} Could not set up access token pair by " +
|
||||
"password grant type. Encoded client credentials are " +
|
||||
"missing - setupTokenPairByPasswordGrantType(x, y)");
|
||||
} else {
|
||||
var tokenData;
|
||||
// tokenPair will include current access token as well as current refresh token
|
||||
var arrayOfScopes = configs["authorization"]["methods"]["oauth"]["attributes"]["scopes"];
|
||||
var stringOfScopes = "";
|
||||
arrayOfScopes.forEach(function (entry) {
|
||||
stringOfScopes += entry + " ";
|
||||
});
|
||||
tokenData = tokenUtil.
|
||||
getTokenPairAndScopesByPasswordGrantType(username,
|
||||
encodeURIComponent(password), encodedClientAppCredentials, stringOfScopes);
|
||||
if (!tokenData) {
|
||||
throw new Error("{/app/modules/oauth/token-handlers.js} Could not set up " +
|
||||
"token pair by password grant type. Error in token " +
|
||||
"retrieval - setupTokenPairByPasswordGrantType(x, y)");
|
||||
} else {
|
||||
var tokenPair = {};
|
||||
tokenPair["accessToken"] = tokenData["accessToken"];
|
||||
tokenPair["refreshToken"] = tokenData["refreshToken"];
|
||||
// setting up token pair into session context as a string
|
||||
session.put(constants["ACCESS_TOKEN_PAIR_IDENTIFIER_FOR_PORTAL"], stringify(tokenPair));
|
||||
var scopes = tokenData.scopes.split(" ");
|
||||
// adding allowed scopes to the session
|
||||
session.put(constants["ALLOWED_SCOPES"], scopes);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get an AccessToken pair based on SAML assertion
|
||||
* @param samlToken SAML assertion
|
||||
* @param username {{clientId:"", clientSecret:""}}
|
||||
*/
|
||||
publicMethods["setupTokenPairBySamlGrantType"] = function (username, samlToken) {
|
||||
if (!username || !samlToken) {
|
||||
throw new Error("{/modules/oauth/token-handlers.js} Could not set up access token pair by " +
|
||||
"saml grant type. Either username of logged in user, samlToken or both are missing " +
|
||||
"as input - setupTokenPairBySamlGrantType(x, y)");
|
||||
} else {
|
||||
privateMethods.setUpEncodedTenantBasedClientAppCredentials(username);
|
||||
var encodedClientAppCredentials =
|
||||
session.get(constants["ENCODED_TENANT_BASED_CLIENT_APP_CREDENTIALS_PORTAL_APP"]);
|
||||
if (!encodedClientAppCredentials) {
|
||||
throw new Error("{/app/modules/oauth/token-handlers.js} Could not set up access token pair " +
|
||||
"by saml grant type. Encoded client credentials are " +
|
||||
"missing - setupTokenPairBySamlGrantType(x, y)");
|
||||
} else {
|
||||
var tokenData;
|
||||
// accessTokenPair will include current access token as well as current refresh token
|
||||
tokenData = tokenUtil.
|
||||
getTokenPairAndScopesByJWTGrantType(username, encodedClientAppCredentials, "PRODUCTION");
|
||||
if (!tokenData) {
|
||||
throw new Error("{/modules/oauth/token-handlers.js} Could not set up token " +
|
||||
"pair by saml grant type. Error in token " +
|
||||
"retrieval - setupTokenPairBySamlGrantType(x, y)");
|
||||
} else {
|
||||
var tokenPair = {};
|
||||
tokenPair["accessToken"] = tokenData["accessToken"];
|
||||
tokenPair["refreshToken"] = tokenData["refreshToken"];
|
||||
// setting up access token pair into session context as a string
|
||||
session.put(constants["ACCESS_TOKEN_PAIR_IDENTIFIER_FOR_PORTAL"], stringify(tokenPair));
|
||||
|
||||
var scopes = tokenData.scopes.split(" ");
|
||||
// adding allowed scopes to the session
|
||||
session.put(constants["ALLOWED_SCOPES"], scopes);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Set access token and refresh token using refresh token grant type
|
||||
*/
|
||||
publicMethods["refreshTokenPair"] = function () {
|
||||
var currentTokenPair = parse(session.get(constants["ACCESS_TOKEN_PAIR_IDENTIFIER_FOR_PORTAL"]));
|
||||
// currentTokenPair includes current access token as well as current refresh token
|
||||
var encodedClientAppCredentials
|
||||
= session.get(constants["ENCODED_TENANT_BASED_CLIENT_APP_CREDENTIALS_PORTAL_APP"]);
|
||||
if (!currentTokenPair || !encodedClientAppCredentials) {
|
||||
throw new Error("{/modules/oauth/token-handlers.js} Error in refreshing tokens. Either the " +
|
||||
"token pair, encoded client app credentials or both input are not found under " +
|
||||
"session context - refreshTokenPair()");
|
||||
} else {
|
||||
var newTokenPair = tokenUtil.
|
||||
getNewTokenPairByRefreshToken(currentTokenPair["refreshToken"], encodedClientAppCredentials);
|
||||
if (!newTokenPair) {
|
||||
log.error("{/app/modules/oauth/token-handlers.js} Error in refreshing token pair. " +
|
||||
"Unable to update session context with new access token pair - refreshTokenPair()");
|
||||
} else {
|
||||
session.put(constants["ACCESS_TOKEN_PAIR_IDENTIFIER_FOR_PORTAL"], stringify(newTokenPair));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* If gateway is enable, apiManagerClientAppRegistrationServiceURL is used to create an oauth application or
|
||||
* else DCR endpoint is used to create an oauth application
|
||||
* @param username username of current logged user
|
||||
*/
|
||||
privateMethods["setUpEncodedTenantBasedClientAppCredentials"] = function (username) {
|
||||
if (!username) {
|
||||
throw new Error("{/modules/oauth/token-handlers.js} Could not set up encoded tenant based " +
|
||||
"client credentials to session context. No username of logged in user is found as " +
|
||||
"input - setUpEncodedTenantBasedClientAppCredentials(x)");
|
||||
} else {
|
||||
if (configs["authorization"]["methods"]["oauth"]["attributes"]["apimgt-gateway"]) {
|
||||
var tenantBasedClientAppCredentials = tokenUtil.getTenantBasedClientAppCredentials(username);
|
||||
if (!tenantBasedClientAppCredentials) {
|
||||
throw new Error("{/modules/oauth/token-handlers.js} Could not set up encoded tenant " +
|
||||
"based client credentials to session context as the server is unable " +
|
||||
"to obtain such credentials - setUpEncodedTenantBasedClientAppCredentials(x)");
|
||||
} else {
|
||||
var encodedTenantBasedClientAppCredentials =
|
||||
tokenUtil.encode(tenantBasedClientAppCredentials["clientId"] + ":" +
|
||||
tenantBasedClientAppCredentials["clientSecret"]);
|
||||
// setting up encoded tenant based client credentials to session context.
|
||||
session.put(constants["ENCODED_TENANT_BASED_CLIENT_APP_CREDENTIALS_PORTAL_APP"],
|
||||
encodedTenantBasedClientAppCredentials);
|
||||
}
|
||||
} else {
|
||||
var dynamicClientAppCredentials = tokenUtil.getDynamicClientAppCredentials(username);
|
||||
if (!dynamicClientAppCredentials) {
|
||||
throw new Error("{/modules/oauth/token-handlers.js} Could not set up encoded tenant based " +
|
||||
"client credentials to session context as the server is unable to obtain " +
|
||||
"dynamic client credentials - setUpEncodedTenantBasedClientAppCredentials(x)");
|
||||
}
|
||||
var encodedTenantBasedClientAppCredentials =
|
||||
tokenUtil.encode(dynamicClientAppCredentials["clientId"] + ":" +
|
||||
dynamicClientAppCredentials["clientSecret"]);
|
||||
// setting up encoded tenant based client credentials to session context.
|
||||
session.put(constants["ENCODED_TENANT_BASED_CLIENT_APP_CREDENTIALS_PORTAL_APP"],
|
||||
encodedTenantBasedClientAppCredentials);
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
return publicMethods;
|
||||
}();
|
@ -1,239 +0,0 @@
|
||||
body.dashboard {
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.dropdown-menu {
|
||||
border: 1px solid #ccc;
|
||||
}
|
||||
|
||||
.dashboard .btn-default.active,
|
||||
.dashboard .btn-default.active:focus {
|
||||
background-color: #29313E;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.dashboard .btn-default.active:hover {
|
||||
background-color: #53627B;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.dashboard .page-header {
|
||||
background: #29313e;
|
||||
min-height: 50px;
|
||||
padding: 0;
|
||||
color: #ebeced;
|
||||
}
|
||||
|
||||
.dashboard .page-header .page-title > h1 {
|
||||
padding: 15px 15px 0 15px;
|
||||
font-weight: 100;
|
||||
text-transform: uppercase;
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.dashboard .page-header .page-title > h1 > .icon {
|
||||
font-size: 24px;
|
||||
margin-top: -5px;
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
||||
.dashboard .page-header .navbar-header {
|
||||
margin-right: 15px;
|
||||
margin-left: 15px;
|
||||
float: none;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.dashboard .page-header .navbar-collapse.collapse {
|
||||
display: none !important;
|
||||
}
|
||||
.page-header .container-fluid {
|
||||
padding: 0 15px;
|
||||
}
|
||||
.navbar-nav > li > a {
|
||||
padding: 10px 0;
|
||||
}
|
||||
}
|
||||
|
||||
.nav > li > a > .icon {
|
||||
margin-right: 8px;
|
||||
}
|
||||
|
||||
.nav > li > a > .badge {
|
||||
position: absolute;
|
||||
top: 5px;
|
||||
right: 5px;
|
||||
background: #ff124a;
|
||||
}
|
||||
|
||||
.dashboard .page-header .auth {
|
||||
margin-bottom: 0;
|
||||
padding: 6px 0;
|
||||
}
|
||||
|
||||
.dashboard .page-content {
|
||||
overflow: inherit;
|
||||
}
|
||||
|
||||
.dashboard .footer {
|
||||
background: #0d1219;
|
||||
}
|
||||
|
||||
.dashboard .gadget-wrapper {
|
||||
border: 1px dashed #e4e4e4;
|
||||
}
|
||||
|
||||
.dashboard .gadget .gadget-heading {
|
||||
background: transparent;
|
||||
border-bottom: none;
|
||||
color: #29313e;
|
||||
}
|
||||
|
||||
.gadget .gadget-heading > .gadget-title {
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.gadget .gadget-heading > .gadget-actions button {
|
||||
border: none;
|
||||
}
|
||||
|
||||
.sidebar-wrapper hr {
|
||||
border-top-color: #ebeced;
|
||||
}
|
||||
|
||||
.sidebar-toggle-button {
|
||||
float: left;
|
||||
height: 50px;
|
||||
line-height: 50px;
|
||||
font-size: 18px;
|
||||
background: #438cad;
|
||||
color: #ffffff;
|
||||
margin-left: -15px;
|
||||
}
|
||||
|
||||
.sidebar-toggle-button > .icon {
|
||||
line-height: 48px;
|
||||
}
|
||||
|
||||
.sidebar-nav {
|
||||
background: #29313e;
|
||||
color: #e3e5e6;
|
||||
}
|
||||
|
||||
.nav.pages {
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.nav.pages > li {
|
||||
line-height: 20px;
|
||||
}
|
||||
|
||||
.nav > li {
|
||||
text-indent: 0;
|
||||
line-height: 10px;
|
||||
}
|
||||
|
||||
.nav > li > a {
|
||||
border-radius: 0;
|
||||
color: #e3e5e6;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.collapse-nav-sub > li > a {
|
||||
padding: 4px 10px;
|
||||
font-size: 21px;
|
||||
}
|
||||
|
||||
.collapse-nav-sub > li > a > .icon {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.page-header .fw-inverse {
|
||||
color: #29313e;
|
||||
}
|
||||
|
||||
.nav li:hover > a,
|
||||
.nav li.open > a,
|
||||
.nav li.open > a:focus,
|
||||
.nav li.open > a:hover {
|
||||
background: #1a2332;
|
||||
}
|
||||
|
||||
.nav > li > a:focus {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.nav.pages > li.active a {
|
||||
background: #121822;
|
||||
border-left: 5px solid #438cad;
|
||||
}
|
||||
|
||||
.navbar-collapse {
|
||||
padding: 15px;
|
||||
background: #1A2331;
|
||||
}
|
||||
|
||||
.navbar-collapse li:hover > a {
|
||||
background: #29313E;
|
||||
}
|
||||
|
||||
.sidebar-nav .user {
|
||||
text-align: center;
|
||||
margin: 20px auto;
|
||||
}
|
||||
|
||||
.sidebar-nav .user > .user-image {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.sidebar-nav .user > .user-image > .default .icon {
|
||||
font-size: 25px;
|
||||
}
|
||||
|
||||
.sidebar-nav .user > .user-image > .default .icon .fw-inverse,
|
||||
.sidebar-nav .user > .user-image > .default .icon .fa-inverse {
|
||||
color: #29313e;
|
||||
}
|
||||
|
||||
.widget .gadget-wrapper {
|
||||
border: none;
|
||||
}
|
||||
|
||||
.widget .ues-component-heading {
|
||||
display: none !important;
|
||||
height: 0;
|
||||
}
|
||||
|
||||
.widget .ues-component {
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.widget.form-control-widget {
|
||||
height: 35px !important;
|
||||
}
|
||||
|
||||
.dropdown-menu.arrow.arrow-top-right:before {
|
||||
right: 20px;
|
||||
}
|
||||
|
||||
.dropdown-menu.arrow:before,
|
||||
.dropdown-menu.arrow.arrow-top-left:before {
|
||||
top: -10px;
|
||||
border-right: 10px solid transparent;
|
||||
border-bottom: 10px solid #e4e4e4;
|
||||
border-left: 10px solid transparent;
|
||||
}
|
||||
|
||||
.dropdown-menu.alerts {
|
||||
min-width: 400px;
|
||||
max-width: 100%;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
ul.sidebar-messages > li:first-child {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
ul.sidebar-messages > li:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
var vizgSettings = {
|
||||
colorScale: colorbrewer.RdYlBu[4].reverse(),
|
||||
colors: {
|
||||
green:"#5FCE9B",
|
||||
blue:"#438CAD",
|
||||
red:"#E87352",
|
||||
yellow:"#EECA5A",
|
||||
purple:"#B6688F",
|
||||
grey:"434343",
|
||||
brown:"#C59787"
|
||||
}
|
||||
}
|
@ -1,303 +0,0 @@
|
||||
// This product includes color specifications and designs developed by Cynthia Brewer (http://colorbrewer.org/).
|
||||
// JavaScript specs as packaged in the D3 library (d3js.org). Please see license at http://colorbrewer.org/export/LICENSE.txt
|
||||
var colorbrewer = {YlGn: {
|
||||
3: ["#f7fcb9","#addd8e","#31a354"],
|
||||
4: ["#ffffcc","#c2e699","#78c679","#238443"],
|
||||
5: ["#ffffcc","#c2e699","#78c679","#31a354","#006837"],
|
||||
6: ["#ffffcc","#d9f0a3","#addd8e","#78c679","#31a354","#006837"],
|
||||
7: ["#ffffcc","#d9f0a3","#addd8e","#78c679","#41ab5d","#238443","#005a32"],
|
||||
8: ["#ffffe5","#f7fcb9","#d9f0a3","#addd8e","#78c679","#41ab5d","#238443","#005a32"],
|
||||
9: ["#ffffe5","#f7fcb9","#d9f0a3","#addd8e","#78c679","#41ab5d","#238443","#006837","#004529"]
|
||||
},YlGnBu: {
|
||||
3: ["#edf8b1","#7fcdbb","#2c7fb8"],
|
||||
4: ["#ffffcc","#a1dab4","#41b6c4","#225ea8"],
|
||||
5: ["#ffffcc","#a1dab4","#41b6c4","#2c7fb8","#253494"],
|
||||
6: ["#ffffcc","#c7e9b4","#7fcdbb","#41b6c4","#2c7fb8","#253494"],
|
||||
7: ["#ffffcc","#c7e9b4","#7fcdbb","#41b6c4","#1d91c0","#225ea8","#0c2c84"],
|
||||
8: ["#ffffd9","#edf8b1","#c7e9b4","#7fcdbb","#41b6c4","#1d91c0","#225ea8","#0c2c84"],
|
||||
9: ["#ffffd9","#edf8b1","#c7e9b4","#7fcdbb","#41b6c4","#1d91c0","#225ea8","#253494","#081d58"]
|
||||
},GnBu: {
|
||||
3: ["#e0f3db","#a8ddb5","#43a2ca"],
|
||||
4: ["#f0f9e8","#bae4bc","#7bccc4","#2b8cbe"],
|
||||
5: ["#f0f9e8","#bae4bc","#7bccc4","#43a2ca","#0868ac"],
|
||||
6: ["#f0f9e8","#ccebc5","#a8ddb5","#7bccc4","#43a2ca","#0868ac"],
|
||||
7: ["#f0f9e8","#ccebc5","#a8ddb5","#7bccc4","#4eb3d3","#2b8cbe","#08589e"],
|
||||
8: ["#f7fcf0","#e0f3db","#ccebc5","#a8ddb5","#7bccc4","#4eb3d3","#2b8cbe","#08589e"],
|
||||
9: ["#f7fcf0","#e0f3db","#ccebc5","#a8ddb5","#7bccc4","#4eb3d3","#2b8cbe","#0868ac","#084081"]
|
||||
},BuGn: {
|
||||
3: ["#e5f5f9","#99d8c9","#2ca25f"],
|
||||
4: ["#edf8fb","#b2e2e2","#66c2a4","#238b45"],
|
||||
5: ["#edf8fb","#b2e2e2","#66c2a4","#2ca25f","#006d2c"],
|
||||
6: ["#edf8fb","#ccece6","#99d8c9","#66c2a4","#2ca25f","#006d2c"],
|
||||
7: ["#edf8fb","#ccece6","#99d8c9","#66c2a4","#41ae76","#238b45","#005824"],
|
||||
8: ["#f7fcfd","#e5f5f9","#ccece6","#99d8c9","#66c2a4","#41ae76","#238b45","#005824"],
|
||||
9: ["#f7fcfd","#e5f5f9","#ccece6","#99d8c9","#66c2a4","#41ae76","#238b45","#006d2c","#00441b"]
|
||||
},PuBuGn: {
|
||||
3: ["#ece2f0","#a6bddb","#1c9099"],
|
||||
4: ["#f6eff7","#bdc9e1","#67a9cf","#02818a"],
|
||||
5: ["#f6eff7","#bdc9e1","#67a9cf","#1c9099","#016c59"],
|
||||
6: ["#f6eff7","#d0d1e6","#a6bddb","#67a9cf","#1c9099","#016c59"],
|
||||
7: ["#f6eff7","#d0d1e6","#a6bddb","#67a9cf","#3690c0","#02818a","#016450"],
|
||||
8: ["#fff7fb","#ece2f0","#d0d1e6","#a6bddb","#67a9cf","#3690c0","#02818a","#016450"],
|
||||
9: ["#fff7fb","#ece2f0","#d0d1e6","#a6bddb","#67a9cf","#3690c0","#02818a","#016c59","#014636"]
|
||||
},PuBu: {
|
||||
3: ["#ece7f2","#a6bddb","#2b8cbe"],
|
||||
4: ["#f1eef6","#bdc9e1","#74a9cf","#0570b0"],
|
||||
5: ["#f1eef6","#bdc9e1","#74a9cf","#2b8cbe","#045a8d"],
|
||||
6: ["#f1eef6","#d0d1e6","#a6bddb","#74a9cf","#2b8cbe","#045a8d"],
|
||||
7: ["#f1eef6","#d0d1e6","#a6bddb","#74a9cf","#3690c0","#0570b0","#034e7b"],
|
||||
8: ["#fff7fb","#ece7f2","#d0d1e6","#a6bddb","#74a9cf","#3690c0","#0570b0","#034e7b"],
|
||||
9: ["#fff7fb","#ece7f2","#d0d1e6","#a6bddb","#74a9cf","#3690c0","#0570b0","#045a8d","#023858"]
|
||||
},BuPu: {
|
||||
3: ["#e0ecf4","#9ebcda","#8856a7"],
|
||||
4: ["#edf8fb","#b3cde3","#8c96c6","#88419d"],
|
||||
5: ["#edf8fb","#b3cde3","#8c96c6","#8856a7","#810f7c"],
|
||||
6: ["#edf8fb","#bfd3e6","#9ebcda","#8c96c6","#8856a7","#810f7c"],
|
||||
7: ["#edf8fb","#bfd3e6","#9ebcda","#8c96c6","#8c6bb1","#88419d","#6e016b"],
|
||||
8: ["#f7fcfd","#e0ecf4","#bfd3e6","#9ebcda","#8c96c6","#8c6bb1","#88419d","#6e016b"],
|
||||
9: ["#f7fcfd","#e0ecf4","#bfd3e6","#9ebcda","#8c96c6","#8c6bb1","#88419d","#810f7c","#4d004b"]
|
||||
},RdPu: {
|
||||
3: ["#fde0dd","#fa9fb5","#c51b8a"],
|
||||
4: ["#feebe2","#fbb4b9","#f768a1","#ae017e"],
|
||||
5: ["#feebe2","#fbb4b9","#f768a1","#c51b8a","#7a0177"],
|
||||
6: ["#feebe2","#fcc5c0","#fa9fb5","#f768a1","#c51b8a","#7a0177"],
|
||||
7: ["#feebe2","#fcc5c0","#fa9fb5","#f768a1","#dd3497","#ae017e","#7a0177"],
|
||||
8: ["#fff7f3","#fde0dd","#fcc5c0","#fa9fb5","#f768a1","#dd3497","#ae017e","#7a0177"],
|
||||
9: ["#fff7f3","#fde0dd","#fcc5c0","#fa9fb5","#f768a1","#dd3497","#ae017e","#7a0177","#49006a"]
|
||||
},PuRd: {
|
||||
3: ["#e7e1ef","#c994c7","#dd1c77"],
|
||||
4: ["#f1eef6","#d7b5d8","#df65b0","#ce1256"],
|
||||
5: ["#f1eef6","#d7b5d8","#df65b0","#dd1c77","#980043"],
|
||||
6: ["#f1eef6","#d4b9da","#c994c7","#df65b0","#dd1c77","#980043"],
|
||||
7: ["#f1eef6","#d4b9da","#c994c7","#df65b0","#e7298a","#ce1256","#91003f"],
|
||||
8: ["#f7f4f9","#e7e1ef","#d4b9da","#c994c7","#df65b0","#e7298a","#ce1256","#91003f"],
|
||||
9: ["#f7f4f9","#e7e1ef","#d4b9da","#c994c7","#df65b0","#e7298a","#ce1256","#980043","#67001f"]
|
||||
},OrRd: {
|
||||
3: ["#fee8c8","#fdbb84","#e34a33"],
|
||||
4: ["#fef0d9","#fdcc8a","#fc8d59","#d7301f"],
|
||||
5: ["#fef0d9","#fdcc8a","#fc8d59","#e34a33","#b30000"],
|
||||
6: ["#fef0d9","#fdd49e","#fdbb84","#fc8d59","#e34a33","#b30000"],
|
||||
7: ["#fef0d9","#fdd49e","#fdbb84","#fc8d59","#ef6548","#d7301f","#990000"],
|
||||
8: ["#fff7ec","#fee8c8","#fdd49e","#fdbb84","#fc8d59","#ef6548","#d7301f","#990000"],
|
||||
9: ["#fff7ec","#fee8c8","#fdd49e","#fdbb84","#fc8d59","#ef6548","#d7301f","#b30000","#7f0000"]
|
||||
},YlOrRd: {
|
||||
3: ["#ffeda0","#feb24c","#f03b20"],
|
||||
4: ["#ffffb2","#fecc5c","#fd8d3c","#e31a1c"],
|
||||
5: ["#ffffb2","#fecc5c","#fd8d3c","#f03b20","#bd0026"],
|
||||
6: ["#ffffb2","#fed976","#feb24c","#fd8d3c","#f03b20","#bd0026"],
|
||||
7: ["#ffffb2","#fed976","#feb24c","#fd8d3c","#fc4e2a","#e31a1c","#b10026"],
|
||||
8: ["#ffffcc","#ffeda0","#fed976","#feb24c","#fd8d3c","#fc4e2a","#e31a1c","#b10026"],
|
||||
9: ["#ffffcc","#ffeda0","#fed976","#feb24c","#fd8d3c","#fc4e2a","#e31a1c","#bd0026","#800026"]
|
||||
},YlOrBr: {
|
||||
3: ["#fff7bc","#fec44f","#d95f0e"],
|
||||
4: ["#ffffd4","#fed98e","#fe9929","#cc4c02"],
|
||||
5: ["#ffffd4","#fed98e","#fe9929","#d95f0e","#993404"],
|
||||
6: ["#ffffd4","#fee391","#fec44f","#fe9929","#d95f0e","#993404"],
|
||||
7: ["#ffffd4","#fee391","#fec44f","#fe9929","#ec7014","#cc4c02","#8c2d04"],
|
||||
8: ["#ffffe5","#fff7bc","#fee391","#fec44f","#fe9929","#ec7014","#cc4c02","#8c2d04"],
|
||||
9: ["#ffffe5","#fff7bc","#fee391","#fec44f","#fe9929","#ec7014","#cc4c02","#993404","#662506"]
|
||||
},Purples: {
|
||||
3: ["#efedf5","#bcbddc","#756bb1"],
|
||||
4: ["#f2f0f7","#cbc9e2","#9e9ac8","#6a51a3"],
|
||||
5: ["#f2f0f7","#cbc9e2","#9e9ac8","#756bb1","#54278f"],
|
||||
6: ["#f2f0f7","#dadaeb","#bcbddc","#9e9ac8","#756bb1","#54278f"],
|
||||
7: ["#f2f0f7","#dadaeb","#bcbddc","#9e9ac8","#807dba","#6a51a3","#4a1486"],
|
||||
8: ["#fcfbfd","#efedf5","#dadaeb","#bcbddc","#9e9ac8","#807dba","#6a51a3","#4a1486"],
|
||||
9: ["#fcfbfd","#efedf5","#dadaeb","#bcbddc","#9e9ac8","#807dba","#6a51a3","#54278f","#3f007d"]
|
||||
},Blues: {
|
||||
3: ["#deebf7","#9ecae1","#3182bd"],
|
||||
4: ["#eff3ff","#bdd7e7","#6baed6","#2171b5"],
|
||||
5: ["#eff3ff","#bdd7e7","#6baed6","#3182bd","#08519c"],
|
||||
6: ["#eff3ff","#c6dbef","#9ecae1","#6baed6","#3182bd","#08519c"],
|
||||
7: ["#eff3ff","#c6dbef","#9ecae1","#6baed6","#4292c6","#2171b5","#084594"],
|
||||
8: ["#f7fbff","#deebf7","#c6dbef","#9ecae1","#6baed6","#4292c6","#2171b5","#084594"],
|
||||
9: ["#f7fbff","#deebf7","#c6dbef","#9ecae1","#6baed6","#4292c6","#2171b5","#08519c","#08306b"]
|
||||
},Greens: {
|
||||
3: ["#e5f5e0","#a1d99b","#31a354"],
|
||||
4: ["#edf8e9","#bae4b3","#74c476","#238b45"],
|
||||
5: ["#edf8e9","#bae4b3","#74c476","#31a354","#006d2c"],
|
||||
6: ["#edf8e9","#c7e9c0","#a1d99b","#74c476","#31a354","#006d2c"],
|
||||
7: ["#edf8e9","#c7e9c0","#a1d99b","#74c476","#41ab5d","#238b45","#005a32"],
|
||||
8: ["#f7fcf5","#e5f5e0","#c7e9c0","#a1d99b","#74c476","#41ab5d","#238b45","#005a32"],
|
||||
9: ["#f7fcf5","#e5f5e0","#c7e9c0","#a1d99b","#74c476","#41ab5d","#238b45","#006d2c","#00441b"]
|
||||
},Oranges: {
|
||||
3: ["#fee6ce","#fdae6b","#e6550d"],
|
||||
4: ["#feedde","#fdbe85","#fd8d3c","#d94701"],
|
||||
5: ["#feedde","#fdbe85","#fd8d3c","#e6550d","#a63603"],
|
||||
6: ["#feedde","#fdd0a2","#fdae6b","#fd8d3c","#e6550d","#a63603"],
|
||||
7: ["#feedde","#fdd0a2","#fdae6b","#fd8d3c","#f16913","#d94801","#8c2d04"],
|
||||
8: ["#fff5eb","#fee6ce","#fdd0a2","#fdae6b","#fd8d3c","#f16913","#d94801","#8c2d04"],
|
||||
9: ["#fff5eb","#fee6ce","#fdd0a2","#fdae6b","#fd8d3c","#f16913","#d94801","#a63603","#7f2704"]
|
||||
},Reds: {
|
||||
3: ["#fee0d2","#fc9272","#de2d26"],
|
||||
4: ["#fee5d9","#fcae91","#fb6a4a","#cb181d"],
|
||||
5: ["#fee5d9","#fcae91","#fb6a4a","#de2d26","#a50f15"],
|
||||
6: ["#fee5d9","#fcbba1","#fc9272","#fb6a4a","#de2d26","#a50f15"],
|
||||
7: ["#fee5d9","#fcbba1","#fc9272","#fb6a4a","#ef3b2c","#cb181d","#99000d"],
|
||||
8: ["#fff5f0","#fee0d2","#fcbba1","#fc9272","#fb6a4a","#ef3b2c","#cb181d","#99000d"],
|
||||
9: ["#fff5f0","#fee0d2","#fcbba1","#fc9272","#fb6a4a","#ef3b2c","#cb181d","#a50f15","#67000d"]
|
||||
},Greys: {
|
||||
3: ["#f0f0f0","#bdbdbd","#636363"],
|
||||
4: ["#f7f7f7","#cccccc","#969696","#525252"],
|
||||
5: ["#f7f7f7","#cccccc","#969696","#636363","#252525"],
|
||||
6: ["#f7f7f7","#d9d9d9","#bdbdbd","#969696","#636363","#252525"],
|
||||
7: ["#f7f7f7","#d9d9d9","#bdbdbd","#969696","#737373","#525252","#252525"],
|
||||
8: ["#ffffff","#f0f0f0","#d9d9d9","#bdbdbd","#969696","#737373","#525252","#252525"],
|
||||
9: ["#ffffff","#f0f0f0","#d9d9d9","#bdbdbd","#969696","#737373","#525252","#252525","#000000"]
|
||||
},PuOr: {
|
||||
3: ["#f1a340","#f7f7f7","#998ec3"],
|
||||
4: ["#e66101","#fdb863","#b2abd2","#5e3c99"],
|
||||
5: ["#e66101","#fdb863","#f7f7f7","#b2abd2","#5e3c99"],
|
||||
6: ["#b35806","#f1a340","#fee0b6","#d8daeb","#998ec3","#542788"],
|
||||
7: ["#b35806","#f1a340","#fee0b6","#f7f7f7","#d8daeb","#998ec3","#542788"],
|
||||
8: ["#b35806","#e08214","#fdb863","#fee0b6","#d8daeb","#b2abd2","#8073ac","#542788"],
|
||||
9: ["#b35806","#e08214","#fdb863","#fee0b6","#f7f7f7","#d8daeb","#b2abd2","#8073ac","#542788"],
|
||||
10: ["#7f3b08","#b35806","#e08214","#fdb863","#fee0b6","#d8daeb","#b2abd2","#8073ac","#542788","#2d004b"],
|
||||
11: ["#7f3b08","#b35806","#e08214","#fdb863","#fee0b6","#f7f7f7","#d8daeb","#b2abd2","#8073ac","#542788","#2d004b"]
|
||||
},BrBG: {
|
||||
3: ["#d8b365","#f5f5f5","#5ab4ac"],
|
||||
4: ["#a6611a","#dfc27d","#80cdc1","#018571"],
|
||||
5: ["#a6611a","#dfc27d","#f5f5f5","#80cdc1","#018571"],
|
||||
6: ["#8c510a","#d8b365","#f6e8c3","#c7eae5","#5ab4ac","#01665e"],
|
||||
7: ["#8c510a","#d8b365","#f6e8c3","#f5f5f5","#c7eae5","#5ab4ac","#01665e"],
|
||||
8: ["#8c510a","#bf812d","#dfc27d","#f6e8c3","#c7eae5","#80cdc1","#35978f","#01665e"],
|
||||
9: ["#8c510a","#bf812d","#dfc27d","#f6e8c3","#f5f5f5","#c7eae5","#80cdc1","#35978f","#01665e"],
|
||||
10: ["#543005","#8c510a","#bf812d","#dfc27d","#f6e8c3","#c7eae5","#80cdc1","#35978f","#01665e","#003c30"],
|
||||
11: ["#543005","#8c510a","#bf812d","#dfc27d","#f6e8c3","#f5f5f5","#c7eae5","#80cdc1","#35978f","#01665e","#003c30"]
|
||||
},PRGn: {
|
||||
3: ["#af8dc3","#f7f7f7","#7fbf7b"],
|
||||
4: ["#7b3294","#c2a5cf","#a6dba0","#008837"],
|
||||
5: ["#7b3294","#c2a5cf","#f7f7f7","#a6dba0","#008837"],
|
||||
6: ["#762a83","#af8dc3","#e7d4e8","#d9f0d3","#7fbf7b","#1b7837"],
|
||||
7: ["#762a83","#af8dc3","#e7d4e8","#f7f7f7","#d9f0d3","#7fbf7b","#1b7837"],
|
||||
8: ["#762a83","#9970ab","#c2a5cf","#e7d4e8","#d9f0d3","#a6dba0","#5aae61","#1b7837"],
|
||||
9: ["#762a83","#9970ab","#c2a5cf","#e7d4e8","#f7f7f7","#d9f0d3","#a6dba0","#5aae61","#1b7837"],
|
||||
10: ["#40004b","#762a83","#9970ab","#c2a5cf","#e7d4e8","#d9f0d3","#a6dba0","#5aae61","#1b7837","#00441b"],
|
||||
11: ["#40004b","#762a83","#9970ab","#c2a5cf","#e7d4e8","#f7f7f7","#d9f0d3","#a6dba0","#5aae61","#1b7837","#00441b"]
|
||||
},PiYG: {
|
||||
3: ["#e9a3c9","#f7f7f7","#a1d76a"],
|
||||
4: ["#d01c8b","#f1b6da","#b8e186","#4dac26"],
|
||||
5: ["#d01c8b","#f1b6da","#f7f7f7","#b8e186","#4dac26"],
|
||||
6: ["#c51b7d","#e9a3c9","#fde0ef","#e6f5d0","#a1d76a","#4d9221"],
|
||||
7: ["#c51b7d","#e9a3c9","#fde0ef","#f7f7f7","#e6f5d0","#a1d76a","#4d9221"],
|
||||
8: ["#c51b7d","#de77ae","#f1b6da","#fde0ef","#e6f5d0","#b8e186","#7fbc41","#4d9221"],
|
||||
9: ["#c51b7d","#de77ae","#f1b6da","#fde0ef","#f7f7f7","#e6f5d0","#b8e186","#7fbc41","#4d9221"],
|
||||
10: ["#8e0152","#c51b7d","#de77ae","#f1b6da","#fde0ef","#e6f5d0","#b8e186","#7fbc41","#4d9221","#276419"],
|
||||
11: ["#8e0152","#c51b7d","#de77ae","#f1b6da","#fde0ef","#f7f7f7","#e6f5d0","#b8e186","#7fbc41","#4d9221","#276419"]
|
||||
},RdBu: {
|
||||
3: ["#ef8a62","#f7f7f7","#67a9cf"],
|
||||
4: ["#ca0020","#f4a582","#92c5de","#0571b0"],
|
||||
5: ["#ca0020","#f4a582","#f7f7f7","#92c5de","#0571b0"],
|
||||
6: ["#b2182b","#ef8a62","#fddbc7","#d1e5f0","#67a9cf","#2166ac"],
|
||||
7: ["#b2182b","#ef8a62","#fddbc7","#f7f7f7","#d1e5f0","#67a9cf","#2166ac"],
|
||||
8: ["#b2182b","#d6604d","#f4a582","#fddbc7","#d1e5f0","#92c5de","#4393c3","#2166ac"],
|
||||
9: ["#b2182b","#d6604d","#f4a582","#fddbc7","#f7f7f7","#d1e5f0","#92c5de","#4393c3","#2166ac"],
|
||||
10: ["#67001f","#b2182b","#d6604d","#f4a582","#fddbc7","#d1e5f0","#92c5de","#4393c3","#2166ac","#053061"],
|
||||
11: ["#67001f","#b2182b","#d6604d","#f4a582","#fddbc7","#f7f7f7","#d1e5f0","#92c5de","#4393c3","#2166ac","#053061"]
|
||||
},RdGy: {
|
||||
3: ["#ef8a62","#ffffff","#999999"],
|
||||
4: ["#ca0020","#f4a582","#bababa","#404040"],
|
||||
5: ["#ca0020","#f4a582","#ffffff","#bababa","#404040"],
|
||||
6: ["#b2182b","#ef8a62","#fddbc7","#e0e0e0","#999999","#4d4d4d"],
|
||||
7: ["#b2182b","#ef8a62","#fddbc7","#ffffff","#e0e0e0","#999999","#4d4d4d"],
|
||||
8: ["#b2182b","#d6604d","#f4a582","#fddbc7","#e0e0e0","#bababa","#878787","#4d4d4d"],
|
||||
9: ["#b2182b","#d6604d","#f4a582","#fddbc7","#ffffff","#e0e0e0","#bababa","#878787","#4d4d4d"],
|
||||
10: ["#67001f","#b2182b","#d6604d","#f4a582","#fddbc7","#e0e0e0","#bababa","#878787","#4d4d4d","#1a1a1a"],
|
||||
11: ["#67001f","#b2182b","#d6604d","#f4a582","#fddbc7","#ffffff","#e0e0e0","#bababa","#878787","#4d4d4d","#1a1a1a"]
|
||||
},RdYlBu: {
|
||||
3: ["#fc8d59","#ffffbf","#91bfdb"],
|
||||
4: ["#d7191c","#fdae61","#abd9e9","#2c7bb6"],
|
||||
5: ["#d7191c","#fdae61","#ffffbf","#abd9e9","#2c7bb6"],
|
||||
6: ["#d73027","#fc8d59","#fee090","#e0f3f8","#91bfdb","#4575b4"],
|
||||
7: ["#d73027","#fc8d59","#fee090","#ffffbf","#e0f3f8","#91bfdb","#4575b4"],
|
||||
8: ["#d73027","#f46d43","#fdae61","#fee090","#e0f3f8","#abd9e9","#74add1","#4575b4"],
|
||||
9: ["#d73027","#f46d43","#fdae61","#fee090","#ffffbf","#e0f3f8","#abd9e9","#74add1","#4575b4"],
|
||||
10: ["#a50026","#d73027","#f46d43","#fdae61","#fee090","#e0f3f8","#abd9e9","#74add1","#4575b4","#313695"],
|
||||
11: ["#a50026","#d73027","#f46d43","#fdae61","#fee090","#ffffbf","#e0f3f8","#abd9e9","#74add1","#4575b4","#313695"]
|
||||
},Spectral: {
|
||||
3: ["#fc8d59","#ffffbf","#99d594"],
|
||||
4: ["#d7191c","#fdae61","#abdda4","#2b83ba"],
|
||||
5: ["#d7191c","#fdae61","#ffffbf","#abdda4","#2b83ba"],
|
||||
6: ["#d53e4f","#fc8d59","#fee08b","#e6f598","#99d594","#3288bd"],
|
||||
7: ["#d53e4f","#fc8d59","#fee08b","#ffffbf","#e6f598","#99d594","#3288bd"],
|
||||
8: ["#d53e4f","#f46d43","#fdae61","#fee08b","#e6f598","#abdda4","#66c2a5","#3288bd"],
|
||||
9: ["#d53e4f","#f46d43","#fdae61","#fee08b","#ffffbf","#e6f598","#abdda4","#66c2a5","#3288bd"],
|
||||
10: ["#9e0142","#d53e4f","#f46d43","#fdae61","#fee08b","#e6f598","#abdda4","#66c2a5","#3288bd","#5e4fa2"],
|
||||
11: ["#9e0142","#d53e4f","#f46d43","#fdae61","#fee08b","#ffffbf","#e6f598","#abdda4","#66c2a5","#3288bd","#5e4fa2"]
|
||||
},RdYlGn: {
|
||||
3: ["#fc8d59","#ffffbf","#91cf60"],
|
||||
4: ["#d7191c","#fdae61","#a6d96a","#1a9641"],
|
||||
5: ["#d7191c","#fdae61","#ffffbf","#a6d96a","#1a9641"],
|
||||
6: ["#d73027","#fc8d59","#fee08b","#d9ef8b","#91cf60","#1a9850"],
|
||||
7: ["#d73027","#fc8d59","#fee08b","#ffffbf","#d9ef8b","#91cf60","#1a9850"],
|
||||
8: ["#d73027","#f46d43","#fdae61","#fee08b","#d9ef8b","#a6d96a","#66bd63","#1a9850"],
|
||||
9: ["#d73027","#f46d43","#fdae61","#fee08b","#ffffbf","#d9ef8b","#a6d96a","#66bd63","#1a9850"],
|
||||
10: ["#a50026","#d73027","#f46d43","#fdae61","#fee08b","#d9ef8b","#a6d96a","#66bd63","#1a9850","#006837"],
|
||||
11: ["#a50026","#d73027","#f46d43","#fdae61","#fee08b","#ffffbf","#d9ef8b","#a6d96a","#66bd63","#1a9850","#006837"]
|
||||
},Accent: {
|
||||
3: ["#7fc97f","#beaed4","#fdc086"],
|
||||
4: ["#7fc97f","#beaed4","#fdc086","#ffff99"],
|
||||
5: ["#7fc97f","#beaed4","#fdc086","#ffff99","#386cb0"],
|
||||
6: ["#7fc97f","#beaed4","#fdc086","#ffff99","#386cb0","#f0027f"],
|
||||
7: ["#7fc97f","#beaed4","#fdc086","#ffff99","#386cb0","#f0027f","#bf5b17"],
|
||||
8: ["#7fc97f","#beaed4","#fdc086","#ffff99","#386cb0","#f0027f","#bf5b17","#666666"]
|
||||
},Dark2: {
|
||||
3: ["#1b9e77","#d95f02","#7570b3"],
|
||||
4: ["#1b9e77","#d95f02","#7570b3","#e7298a"],
|
||||
5: ["#1b9e77","#d95f02","#7570b3","#e7298a","#66a61e"],
|
||||
6: ["#1b9e77","#d95f02","#7570b3","#e7298a","#66a61e","#e6ab02"],
|
||||
7: ["#1b9e77","#d95f02","#7570b3","#e7298a","#66a61e","#e6ab02","#a6761d"],
|
||||
8: ["#1b9e77","#d95f02","#7570b3","#e7298a","#66a61e","#e6ab02","#a6761d","#666666"]
|
||||
},Paired: {
|
||||
3: ["#a6cee3","#1f78b4","#b2df8a"],
|
||||
4: ["#a6cee3","#1f78b4","#b2df8a","#33a02c"],
|
||||
5: ["#a6cee3","#1f78b4","#b2df8a","#33a02c","#fb9a99"],
|
||||
6: ["#a6cee3","#1f78b4","#b2df8a","#33a02c","#fb9a99","#e31a1c"],
|
||||
7: ["#a6cee3","#1f78b4","#b2df8a","#33a02c","#fb9a99","#e31a1c","#fdbf6f"],
|
||||
8: ["#a6cee3","#1f78b4","#b2df8a","#33a02c","#fb9a99","#e31a1c","#fdbf6f","#ff7f00"],
|
||||
9: ["#a6cee3","#1f78b4","#b2df8a","#33a02c","#fb9a99","#e31a1c","#fdbf6f","#ff7f00","#cab2d6"],
|
||||
10: ["#a6cee3","#1f78b4","#b2df8a","#33a02c","#fb9a99","#e31a1c","#fdbf6f","#ff7f00","#cab2d6","#6a3d9a"],
|
||||
11: ["#a6cee3","#1f78b4","#b2df8a","#33a02c","#fb9a99","#e31a1c","#fdbf6f","#ff7f00","#cab2d6","#6a3d9a","#ffff99"],
|
||||
12: ["#a6cee3","#1f78b4","#b2df8a","#33a02c","#fb9a99","#e31a1c","#fdbf6f","#ff7f00","#cab2d6","#6a3d9a","#ffff99","#b15928"]
|
||||
},Pastel1: {
|
||||
3: ["#fbb4ae","#b3cde3","#ccebc5"],
|
||||
4: ["#fbb4ae","#b3cde3","#ccebc5","#decbe4"],
|
||||
5: ["#fbb4ae","#b3cde3","#ccebc5","#decbe4","#fed9a6"],
|
||||
6: ["#fbb4ae","#b3cde3","#ccebc5","#decbe4","#fed9a6","#ffffcc"],
|
||||
7: ["#fbb4ae","#b3cde3","#ccebc5","#decbe4","#fed9a6","#ffffcc","#e5d8bd"],
|
||||
8: ["#fbb4ae","#b3cde3","#ccebc5","#decbe4","#fed9a6","#ffffcc","#e5d8bd","#fddaec"],
|
||||
9: ["#fbb4ae","#b3cde3","#ccebc5","#decbe4","#fed9a6","#ffffcc","#e5d8bd","#fddaec","#f2f2f2"]
|
||||
},Pastel2: {
|
||||
3: ["#b3e2cd","#fdcdac","#cbd5e8"],
|
||||
4: ["#b3e2cd","#fdcdac","#cbd5e8","#f4cae4"],
|
||||
5: ["#b3e2cd","#fdcdac","#cbd5e8","#f4cae4","#e6f5c9"],
|
||||
6: ["#b3e2cd","#fdcdac","#cbd5e8","#f4cae4","#e6f5c9","#fff2ae"],
|
||||
7: ["#b3e2cd","#fdcdac","#cbd5e8","#f4cae4","#e6f5c9","#fff2ae","#f1e2cc"],
|
||||
8: ["#b3e2cd","#fdcdac","#cbd5e8","#f4cae4","#e6f5c9","#fff2ae","#f1e2cc","#cccccc"]
|
||||
},Set1: {
|
||||
3: ["#e41a1c","#377eb8","#4daf4a"],
|
||||
4: ["#e41a1c","#377eb8","#4daf4a","#984ea3"],
|
||||
5: ["#e41a1c","#377eb8","#4daf4a","#984ea3","#ff7f00"],
|
||||
6: ["#e41a1c","#377eb8","#4daf4a","#984ea3","#ff7f00","#ffff33"],
|
||||
7: ["#e41a1c","#377eb8","#4daf4a","#984ea3","#ff7f00","#ffff33","#a65628"],
|
||||
8: ["#e41a1c","#377eb8","#4daf4a","#984ea3","#ff7f00","#ffff33","#a65628","#f781bf"],
|
||||
9: ["#e41a1c","#377eb8","#4daf4a","#984ea3","#ff7f00","#ffff33","#a65628","#f781bf","#999999"]
|
||||
},Set2: {
|
||||
3: ["#66c2a5","#fc8d62","#8da0cb"],
|
||||
4: ["#66c2a5","#fc8d62","#8da0cb","#e78ac3"],
|
||||
5: ["#66c2a5","#fc8d62","#8da0cb","#e78ac3","#a6d854"],
|
||||
6: ["#66c2a5","#fc8d62","#8da0cb","#e78ac3","#a6d854","#ffd92f"],
|
||||
7: ["#66c2a5","#fc8d62","#8da0cb","#e78ac3","#a6d854","#ffd92f","#e5c494"],
|
||||
8: ["#66c2a5","#fc8d62","#8da0cb","#e78ac3","#a6d854","#ffd92f","#e5c494","#b3b3b3"]
|
||||
},Set3: {
|
||||
3: ["#8dd3c7","#ffffb3","#bebada"],
|
||||
4: ["#8dd3c7","#ffffb3","#bebada","#fb8072"],
|
||||
5: ["#8dd3c7","#ffffb3","#bebada","#fb8072","#80b1d3"],
|
||||
6: ["#8dd3c7","#ffffb3","#bebada","#fb8072","#80b1d3","#fdb462"],
|
||||
7: ["#8dd3c7","#ffffb3","#bebada","#fb8072","#80b1d3","#fdb462","#b3de69"],
|
||||
8: ["#8dd3c7","#ffffb3","#bebada","#fb8072","#80b1d3","#fdb462","#b3de69","#fccde5"],
|
||||
9: ["#8dd3c7","#ffffb3","#bebada","#fb8072","#80b1d3","#fdb462","#b3de69","#fccde5","#d9d9d9"],
|
||||
10: ["#8dd3c7","#ffffb3","#bebada","#fb8072","#80b1d3","#fdb462","#b3de69","#fccde5","#d9d9d9","#bc80bd"],
|
||||
11: ["#8dd3c7","#ffffb3","#bebada","#fb8072","#80b1d3","#fdb462","#b3de69","#fccde5","#d9d9d9","#bc80bd","#ccebc5"],
|
||||
12: ["#8dd3c7","#ffffb3","#bebada","#fb8072","#80b1d3","#fdb462","#b3de69","#fccde5","#d9d9d9","#bc80bd","#ccebc5","#ffed6f"]
|
||||
}};
|
@ -1,447 +0,0 @@
|
||||
<!--
|
||||
~ Copyright (c) WSO2 Inc. (http://wso2.com) All Rights Reserved.
|
||||
~
|
||||
~ Licensed 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.
|
||||
-->
|
||||
<%
|
||||
// i18n
|
||||
var i18n = require("i18n");
|
||||
i18n.init(request, utils.getLocaleResourcePath());
|
||||
|
||||
// If the pageId is null, render the landing page
|
||||
pageId = pageId || dashboard.landing;
|
||||
|
||||
var usr = require('/modules/user.js'),
|
||||
user = usr.current(),
|
||||
isAnonView = request.getParameter('isAnonView');
|
||||
|
||||
// Get the anon view
|
||||
if (!user) {
|
||||
if (isAnonView) {
|
||||
response.sendRedirect(request.getRequestURL());
|
||||
}
|
||||
isAnonView = true;
|
||||
} else {
|
||||
isAnonView = JSON.parse(isAnonView);
|
||||
|
||||
if((user.domain != urlDomain && urlDomain) ||
|
||||
(dashboard.isanon && !utils.allowed(user.roles, dashboard.permissions.editors) && !utils.allowed(user.roles, dashboard.permissions.viewers))) {
|
||||
isAnonView = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Get the current page
|
||||
var pages = dashboard.pages,
|
||||
page;
|
||||
pages.forEach(function(p) {
|
||||
if (p.id == pageId) {
|
||||
page = p;
|
||||
}
|
||||
});
|
||||
%>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
||||
<title><%= i18n.localize("dashboard.server.label")%></title>
|
||||
|
||||
<!-- Favicon -->
|
||||
<link rel="shortcut icon" href="<%=urlPrefix%>libs/theme-wso2_1.0/images/favicon.png" />
|
||||
|
||||
<!-- Bootstrap CSS -->
|
||||
<link href="<%=urlPrefix%>libs/bootstrap_3.3.5/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
|
||||
|
||||
<!-- Font WSO2 CSS -->
|
||||
<link href="<%=urlPrefix%>libs/font-wso2_1.0.0/css/font-wso2.min.css" rel="stylesheet" type="text/css" />
|
||||
|
||||
<!-- Jquery Nanoscroller CSS -->
|
||||
<link href="<%=urlPrefix%>libs/nanoscroller_0.8.7/nanoscroller.css" rel="stylesheet" type="text/css" />
|
||||
|
||||
<!-- Theme WSO2 CSS -->
|
||||
<link href="<%=urlPrefix%>libs/theme-wso2_1.0/css/theme-wso2.css" rel="stylesheet" type="text/css" />
|
||||
|
||||
<!-- Custom CSS -->
|
||||
<link href="<%=urlPrefix%>css/custom.css" rel="stylesheet" type="text/css" />
|
||||
|
||||
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
|
||||
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
|
||||
<!--[if lt IE 9]>
|
||||
<script src="<%=urlPrefix%>libs/html5shiv_3.7.2/html5shiv.min.js"></script>
|
||||
<script src="<%=urlPrefix%>libs/respond_1.4.2/respond.min.js"></script>
|
||||
<![endif]-->
|
||||
|
||||
<!-- JQuery UI -->
|
||||
<link rel="stylesheet" type="text/css" href="<%=urlPrefix%>libs/jquery-ui-1.11.4/jquery-ui.min.css" />
|
||||
|
||||
<link rel="stylesheet" href="<%=urlPrefix%>css/dashboard.css" />
|
||||
|
||||
<!-- Common CSS -->
|
||||
<link rel="stylesheet" type="text/css" href="<%=urlPrefix%>css/common.css" />
|
||||
|
||||
<!-- Custom theme overrides -->
|
||||
<link rel="stylesheet" href="<%=urlPrefix%><%=utils.dashboardStyles(dashboard.theme)%>">
|
||||
</head>
|
||||
|
||||
<body class="dashboard lang_<%=request.getLocale()%>">
|
||||
|
||||
<!-- .left-sidebar -->
|
||||
<div class="sidebar-wrapper sidebar-nav toggled hidden-xs" id="left-sidebar" data-side="left" data-width="260" style="width:260px">
|
||||
<div class="nano">
|
||||
<div class="nano-content">
|
||||
|
||||
<div class="user">
|
||||
<div class="user-image">
|
||||
<span class="default">
|
||||
<span class="icon fw fw-stack">
|
||||
<i class="fw fw-circle fw-stack-2x"></i>
|
||||
<i class="fw fw-user fw-stack-1x fw-inverse"></i>
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
<div class="user-name"><%= user ? user.username : "anon" %></div>
|
||||
</div>
|
||||
|
||||
<ul class="nav nav-pills nav-stacked pages">
|
||||
<% if (pages.length > 1) {
|
||||
// render links
|
||||
pages.forEach(function (p) {
|
||||
if (isAnonView || !user) {
|
||||
if (p.isanon) {
|
||||
// Anonymous viewing. So render only anonymous pages links.
|
||||
renderPageLink(p);
|
||||
}
|
||||
} else {
|
||||
renderPageLink(p);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function renderPageLink(p) {
|
||||
var queryString = isAnonView ? '?isAnonView=true' : '';
|
||||
%>
|
||||
<li class="<%= (p.id === pageId) ? 'active': '' %>"><a href="<%=dbRoot%><%=p.id%><%=queryString%>"><%=encodeHtml(p.title)%></a></li>
|
||||
<% } %>
|
||||
</ul>
|
||||
|
||||
<hr>
|
||||
|
||||
<ul class="nav nav-pills nav-stacked">
|
||||
<% if (user) { %>
|
||||
<% if (!isAnonView && (urlDomain == user.domain || (user.domain == superDomain && (!urlDomain || urlDomain == superDomain)))) { %>
|
||||
<% if (user.isEditor) { %>
|
||||
<li><a href="<%=dbRoot%>?editor=true"><i class="icon fw fw-settings ues-copy" title="<%= i18n.localize("edit.button")%>"></i>Dashboard Settings</a></li>
|
||||
<% } else { %>
|
||||
<li><a href="<%=dbRoot%>?custom=true"><i class="icon fw fw-settings ues-copy" title="<%= i18n.localize("personalize")%>"></i>Customize Dashboard</a></li>
|
||||
<% } %>
|
||||
<% } %>
|
||||
<li><a href="<%=urlPrefix%>logout?destination=<%=dest%>"><i class="icon fw fw-sign-out"></i><%= i18n.localize("logout.label")%></a></li>
|
||||
<% } else { %>
|
||||
<li><a href="<%=urlPrefix%>login-controller?destination=<%=dest%>"><i class="icon fw fw-sign-in"></i><%= i18n.localize("login.label")%></a></li>
|
||||
<% } %>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- #page-content-wrapper -->
|
||||
<div class="page-content-wrapper remove-padding-xs" style="padding-left:260px;">
|
||||
<div class="nano">
|
||||
<div class="nano-content">
|
||||
|
||||
<div class="page-header">
|
||||
<div class="container-fluid">
|
||||
|
||||
<div class="navbar-header">
|
||||
<a class="sidebar-toggle-button hidden-xs" data-toggle="sidebar" data-target="#left-sidebar" data-container=".page-content-wrapper" data-container-divide="true" aria-expanded="true" rel="sub-nav">
|
||||
<span class="icon fw-stack">
|
||||
<i class="fw fw-menu fw-stack-1x toggle-icon-left"></i>
|
||||
</span>
|
||||
</a>
|
||||
<a class="sidebar-toggle-button visible-xs" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
|
||||
<span class="icon fw-stack">
|
||||
<i class="fw fw-menu fw-stack-1x toggle-icon-up"></i>
|
||||
</span>
|
||||
</a>
|
||||
<div class="page-title pull-left text-center-xs">
|
||||
<h1 class="text-center-xs"><i class="icon fw fw-wso2-logo"></i><%=encodeHtml(dashboard.title)%></h1>
|
||||
</div>
|
||||
<div class="pull-right auth visible-xs">
|
||||
<span class="add-padding-left-3x"><%= user ? user.username : "anon" %></span>
|
||||
<span class="icon fw-stack fw-lg">
|
||||
<i class="fw fw-circle fw-stack-2x"></i>
|
||||
<i class="fw fw-user fw-stack-1x fw-inverse"></i>
|
||||
</span>
|
||||
</div>
|
||||
<ul class="nav collapse-nav-sub pull-right hidden">
|
||||
<li class="visible-inline-block">
|
||||
<a data-toggle="dropdown">
|
||||
<span class="icon fw-stack">
|
||||
<i class="fw fw-notification fw-stack-1x"></i>
|
||||
</span>
|
||||
<span class="badge">4</span>
|
||||
</a>
|
||||
<div class="dropdown-menu dropdown-menu-right arrow alerts arrow-top-right dark add-margin-top-2x" role="menu">
|
||||
<ul class="sidebar-messages">
|
||||
<li class="message message-success">
|
||||
<h4><i class="icon fw fw-success"></i>Minor Information Message</h4>
|
||||
<p>Alerts don't have default classes, only base and modifier classes.</p>
|
||||
</li>
|
||||
<li class="message message-info">
|
||||
<h4><i class="icon fw fw-info"></i>Minor Information Message</h4>
|
||||
<p>Alerts don't have default classes, only base and modifier classes.</p>
|
||||
</li>
|
||||
<li class="message message-warning">
|
||||
<h4><i class="icon fw fw-warning"></i>Major Information Message</h4>
|
||||
<p>Alerts don't have default classes, only base and modifier classes.</p>
|
||||
</li>
|
||||
<li class="message message-danger">
|
||||
<h4><i class="icon fw fw-error"></i>Critical Information Message</h4>
|
||||
<p>Alerts don't have default classes, only base and modifier classes.</p>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div id="navbar" class="navbar-collapse collapse" aria-expanded="false">
|
||||
<ul class="nav navbar-nav pages">
|
||||
<% if (pages.length > 1) {
|
||||
// render links
|
||||
pages.forEach(function (p) {
|
||||
if (isAnonView || !user) {
|
||||
if (p.isanon) {
|
||||
// Anonymous viewing. So render only anonymous pages links.
|
||||
renderPageLink(p);
|
||||
}
|
||||
} else {
|
||||
renderPageLink(p);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function renderPageLink(p) {
|
||||
var queryString = isAnonView ? '?isAnonView=true' : '';
|
||||
%>
|
||||
<li class="<%= (p.id === pageId) ? 'active': '' %>"><a href="<%=dbRoot%><%=p.id%><%=queryString%>"><%=encodeHtml(p.title)%></a></li>
|
||||
<% } %>
|
||||
</ul>
|
||||
|
||||
<hr>
|
||||
|
||||
<ul class="nav nav-pills nav-stacked">
|
||||
<% if (user) { %>
|
||||
<% if (!isAnonView && (urlDomain == user.domain || (user.domain == superDomain && (!urlDomain || urlDomain == superDomain)))) { %>
|
||||
<% if (user.isEditor) { %>
|
||||
<li><a href="<%=dbRoot%>?editor=true"><i class="icon fw fw-settings ues-copy" title="<%= i18n.localize("edit.button")%>"></i>Dashboard Settings</a></li>
|
||||
<% } else { %>
|
||||
<li><a href="<%=dbRoot%>?custom=true"><i class="icon fw fw-settings ues-copy" title="<%= i18n.localize("personalize")%>"></i>Customize Dashboard</a></li>
|
||||
<% } %>
|
||||
<% } %>
|
||||
<li><a href="<%=urlPrefix%>logout?destination=<%=dest%>"><i class="icon fw fw-sign-out"></i><%= i18n.localize("logout.label")%></a></li>
|
||||
<% } else { %>
|
||||
<li><a href="<%=urlPrefix%>login-controller?destination=<%=dest%>"><i class="icon fw fw-sign-in"></i><%= i18n.localize("login.label")%></a></li>
|
||||
<% } %>
|
||||
</ul>
|
||||
</div><!--/.nav-collapse -->
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- page content -->
|
||||
<div class="container-fluid body-wrapper">
|
||||
|
||||
<div class="page-content">
|
||||
<!-- Components grid -->
|
||||
<div class="ues-components-grid gadgets-grid">
|
||||
<%=renderEngine.getDashboardContent(pageId || dashboard.landing, isAnonView)%>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div><!-- /#page-content-wrapper -->
|
||||
|
||||
<!--Footer -->
|
||||
<footer class="footer">
|
||||
<div class="container-fluid">
|
||||
<p>WSO2 Dashboard Server 2.0.0 | © <script>document.write(new Date().getFullYear());</script> <a href="http://wso2.com/" target="_blank"><i class="icon fw fw-wso2"></i> Inc</a>.</p>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<!-- Jquery/Jquery UI JS -->
|
||||
<script src="<%=urlPrefix%>libs/jquery_1.11.0/jquery-1.11.3.min.js"></script>
|
||||
<script src="<%=urlPrefix%>libs/jquery-ui-1.11.4/jquery-ui.min.js"></script>
|
||||
|
||||
<!-- Bootstrap JS -->
|
||||
<script src="<%=urlPrefix%>libs/bootstrap_3.3.5/js/bootstrap.min.js"></script>
|
||||
|
||||
<!-- Jquery Nanoscroller JS -->
|
||||
<script src="<%=urlPrefix%>libs/nanoscroller_0.8.7/jquery.nanoscroller.min.js"></script>
|
||||
|
||||
<!-- Theme WSO2 JS -->
|
||||
<script src="<%=urlPrefix%>libs/theme-wso2_1.0/js/theme-wso2.js"></script>
|
||||
|
||||
<!-- Handlebars JS -->
|
||||
<script src="<%=urlPrefix%>libs/handlebars-v4.0.2/handlebars.min.js"></script>
|
||||
|
||||
<script src="/shindig/gadgets/js/container:open-views:opensearch:rpc:xmlutil:pubsub-2.js?c=1&debug=1&container=default"></script>
|
||||
<script src="<%=urlPrefix%>js/ues.js"></script>
|
||||
<script src="<%=urlPrefix%>js/ues-prefs.js"></script>
|
||||
<% include('/controllers/includes/common-scripts.jag'); %>
|
||||
<% include('/controllers/includes/dashboard-scripts.jag'); %>
|
||||
<script src="<%=urlPrefix%>js/ues-gadgets.js"></script>
|
||||
<script src="<%=urlPrefix%>js/ues-dashboards.js"></script>
|
||||
<script src="<%=urlPrefix%>extensions/components/gadget/index.js"></script>
|
||||
<script src="<%=urlPrefix%>extensions/components/widget/index.js"></script>
|
||||
<script src="<%=urlPrefix%>extensions/uris/local/index.js"></script>
|
||||
<script src="<%=urlPrefix%>extensions/uris/store/index.js"></script>
|
||||
<script src="<%=urlPrefix%>js/gadget-properties.js"></script>
|
||||
<script src="<%=urlPrefix%>js/ds-handlebar-helpers.js"></script>
|
||||
<script src="<%=urlPrefix%>js/ues-saml-at.js"></script>
|
||||
<script src="<%=urlPrefix%>js/dashboard.js"></script>
|
||||
<% include('/controllers/includes/theme-dashboard-scripts.jag'); %>
|
||||
|
||||
<!-- Handlebar templates -->
|
||||
<!-- Component container -->
|
||||
<script id="ues-component-box-content-hbs" type="text/x-handlebars-template">
|
||||
<div class="gadget-wrapper">
|
||||
<div class="ues-component gadget">
|
||||
<div class="ues-component-heading gadget-heading">
|
||||
<h4 class="ues-component-title gadget-title truncate"></h4>
|
||||
|
||||
<div class="ues-component-actions gadget-actions">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="ues-component-body gadget-body"></div>
|
||||
</div>
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<!-- Component toolbar actions -->
|
||||
<script id="ues-component-actions-hbs" type="text/x-handlebars-template">
|
||||
<div class="btn-group">
|
||||
{{#if userPrefsExists}}
|
||||
<button type="button" class="btn btn-default ues-component-settings-handle" title="<%= i18n.localize("properties.label") %>">
|
||||
<i class="icon fw fw fw-configarations"></i>
|
||||
</button>
|
||||
{{/if}}
|
||||
<button type="button" class="btn btn-default ues-component-full-handle" title="<%= i18n.localize("maximize.label") %>"
|
||||
data-maximize-title="<%= i18n.localize("maximize.label") %>" data-minimize-title="<%= i18n.localize("minimize.label") %>">
|
||||
<i class="icon fw fw-expand"></i>
|
||||
</button>
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<!-- Gadget settings -->
|
||||
<script id="ues-gadget-setting-hbs" type="text/x-handlebars-template">
|
||||
<div class="ues-sandbox gadget-setting" data-component="{{id}}">
|
||||
<form>
|
||||
{{#has options}}
|
||||
<div class="ues-options">
|
||||
<h4><%= i18n.localize("options") %></h4>
|
||||
{{#each options}}
|
||||
<div class="form-group">
|
||||
<div class="col-sm-12">
|
||||
{{#equals type "STRING"}}
|
||||
<label>{{title}}
|
||||
<input type="text" class="form-control" name="{{@key}}" placeholder="{{title}}" value="{{value}}">
|
||||
</label>
|
||||
{{/equals}}
|
||||
{{#equals type "BOOL"}}
|
||||
<label>
|
||||
<input type="checkbox" name="{{title}}"{{#equals value true}} checked="checked"{{/equals}}> {{title}}
|
||||
</label>
|
||||
{{/equals}}
|
||||
{{#equals type "ENUM"}}
|
||||
<label>{{title}}
|
||||
<select id={{title}} name={{title}} class="form-control ues-title-position">
|
||||
{{#each options}}
|
||||
<option value={{value}}{{#equals value ../value}} selected="selected"{{/equals}}>{{displayValue}}</option>
|
||||
{{/each}}
|
||||
</select>
|
||||
</label>
|
||||
{{/equals}}
|
||||
{{#equals type "LIST"}}
|
||||
<label>{{title}}
|
||||
<textarea name="{{@key}}" class="form-control" rows="4" placeholder='<%= i18n.localize("placeholder.item.list")%>'>{{value}}</textarea>
|
||||
<label><%= i18n.localize("enter.your.list.entries.label")%></label>
|
||||
</label>
|
||||
{{/equals}}
|
||||
{{#equals type "text"}}
|
||||
<label>{{title}}
|
||||
<textarea name="{{@key}}" class="form-control" rows="4">{{value}}</textarea>
|
||||
</label>
|
||||
{{/equals}}
|
||||
</div>
|
||||
</div>
|
||||
{{/each}}
|
||||
</div>
|
||||
{{else}}
|
||||
<div class="alert alert-info">No properties to configure.</div>
|
||||
{{/has}}
|
||||
</form>
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<!-- Scripts -->
|
||||
<script>
|
||||
|
||||
var nanoScrollerSelector = $(".nano");
|
||||
nanoScrollerSelector.nanoScroller();
|
||||
|
||||
function updateSidebarNav(target) {
|
||||
$(target).show();
|
||||
$(target).siblings().hide();
|
||||
nanoScrollerSelector[0].nanoscroller.reset();
|
||||
}
|
||||
|
||||
if (!ues.global.renderFromExtension) {
|
||||
ues.dashboards.render($('.ues-components-grid'), ues.global.dashboard, ues.global.page);
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
// Show banner
|
||||
if (ues.global.dashboard.banner.globalBannerExists || ues.global.dashboard.banner.customBannerExists) {
|
||||
$('.ues-banner-placeholder').css("background-image", "url('<%=tenantedUrlPrefix%>banners/<%=dashboard.id%>')");
|
||||
} else {
|
||||
$('.ues-banner-placeholder').hide();
|
||||
}
|
||||
|
||||
// Toggle component box heading
|
||||
$('.ues-component').hover(function() {
|
||||
toggleHeading($(this), true);
|
||||
}, function() {
|
||||
toggleHeading($(this), false);
|
||||
});
|
||||
});
|
||||
|
||||
function toggleHeading(source, show) {
|
||||
if (source.hasClass('ues-no-heading')) {
|
||||
var heading = source.find('.ues-component-heading');
|
||||
if (show) {
|
||||
heading.slideDown();
|
||||
} else {
|
||||
heading.slideUp();
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -1,52 +0,0 @@
|
||||
<%
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
var user = session.get('user');
|
||||
var streamName;
|
||||
var streamVersion;
|
||||
var log = new Log();
|
||||
var JaggeryWebSocketHelper = Packages.org.wso2.carbon.event.output.adapter.ui.JaggeryWebSocketHelper;
|
||||
|
||||
webSocket.onopen = function () {
|
||||
if (user == null) {
|
||||
this.close();
|
||||
}
|
||||
};
|
||||
|
||||
webSocket.ontext = function (data) {
|
||||
log.info(data);
|
||||
var dataObj = parse(data);
|
||||
streamName = dataObj.streamName;
|
||||
streamVersion = dataObj.streamVersion;
|
||||
JaggeryWebSocketHelper.subscribeWebSocket(streamName, streamVersion, stringify(dataObj.filterProps),
|
||||
user.username, session.getId(), user.tenantId, this);
|
||||
};
|
||||
|
||||
webSocket.onclose = function () {
|
||||
if (user != null && streamName != null && streamVersion != null) { //onclose may get invoked when an invalid user (user==null case) closes the connection. Hence this check is required.
|
||||
JaggeryWebSocketHelper.unsubscribeWebsocket(streamName, streamVersion, session.getId(), user.tenantId);
|
||||
}
|
||||
};
|
||||
|
||||
webSocket.onerror = function () {
|
||||
if (user != null) {
|
||||
JaggeryWebSocketHelper.unsubscribeWebsocket(streamId.split(":")[0], streamId.split(":")[1], session.getId(), user.tenantId);
|
||||
}
|
||||
};
|
||||
|
||||
%>
|
@ -1,249 +0,0 @@
|
||||
<!--
|
||||
~ Copyright (c) 2017, 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.
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<parent>
|
||||
<groupId>org.wso2</groupId>
|
||||
<artifactId>wso2</artifactId>
|
||||
<version>1</version>
|
||||
</parent>
|
||||
|
||||
<modules>
|
||||
<module>connectedcup</module>
|
||||
<module>../wso2/analytics/samples/connected-cup</module>
|
||||
</modules>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.wso2.iot.devicemgt-plugins</groupId>
|
||||
<artifactId>iot-devicetype-samples</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>Install Connected Cup Device Types - IoT Core</name>
|
||||
<url>http://wso2.org</url>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.wso2.maven</groupId>
|
||||
<artifactId>carbon-p2-plugin</artifactId>
|
||||
<version>1.5.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>2-p2-repo-generation</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>p2-repo-gen</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<metadataRepository>file:\${basedir}/target/p2-repo</metadataRepository>
|
||||
<artifactRepository>file:\${basedir}/target/p2-repo</artifactRepository>
|
||||
<publishArtifacts>true</publishArtifacts>
|
||||
<publishArtifactRepository>true</publishArtifactRepository>
|
||||
<featureArtifacts>
|
||||
<featureArtifactDef>
|
||||
org.coffeeking:org.coffeeking.connectedcup.backend.feature:\${org.coffeeking.version}
|
||||
</featureArtifactDef>
|
||||
<featureArtifactDef>
|
||||
org.coffeeking:org.coffeeking.connectedcup.ui.feature:\${org.coffeeking.version}
|
||||
</featureArtifactDef>
|
||||
</featureArtifacts>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>default-feature-install</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>p2-profile-gen</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<profile>default</profile>
|
||||
<metadataRepository>file:\${basedir}/target/p2-repo</metadataRepository>
|
||||
<artifactRepository>file:\${basedir}/target/p2-repo</artifactRepository>
|
||||
<destination>\${basedir}/../wso2/components</destination>
|
||||
<deleteOldProfileFiles>false</deleteOldProfileFiles>
|
||||
<features>
|
||||
<!-- Connected Cup Features -->
|
||||
<feature>
|
||||
<id>org.coffeeking.connectedcup.ui.feature.group</id>
|
||||
<version>\${org.coffeeking.version}</version>
|
||||
</feature>
|
||||
<feature>
|
||||
<id>org.coffeeking.connectedcup.backend.feature.group</id>
|
||||
<version>\${org.coffeeking.version}</version>
|
||||
</feature>
|
||||
</features>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>manager-feature-install</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>p2-profile-gen</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<profile>device-manager</profile>
|
||||
<metadataRepository>file:\${basedir}/target/p2-repo</metadataRepository>
|
||||
<artifactRepository>file:\${basedir}/target/p2-repo</artifactRepository>
|
||||
<destination>\${basedir}/../wso2/components</destination>
|
||||
<deleteOldProfileFiles>false</deleteOldProfileFiles>
|
||||
<features>
|
||||
<!-- Connected Cup UI Features -->
|
||||
<feature>
|
||||
<id>org.coffeeking.connectedcup.ui.feature.group</id>
|
||||
<version>\${org.coffeeking.version}</version>
|
||||
</feature>
|
||||
</features>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>backend-feature-install</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>p2-profile-gen</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<profile>device-backend</profile>
|
||||
<metadataRepository>file:\${basedir}/target/p2-repo</metadataRepository>
|
||||
<artifactRepository>file:\${basedir}/target/p2-repo</artifactRepository>
|
||||
<destination>\${basedir}/../wso2/components</destination>
|
||||
<deleteOldProfileFiles>false</deleteOldProfileFiles>
|
||||
<features>
|
||||
<!-- Connected Cup BE Features -->
|
||||
<feature>
|
||||
<id>org.coffeeking.connectedcup.backend.feature.group</id>
|
||||
<version>\${org.coffeeking.version}</version>
|
||||
</feature>
|
||||
</features>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-antrun-plugin</artifactId>
|
||||
<version>1.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>default-feature-install</id>
|
||||
<phase>package</phase>
|
||||
<configuration>
|
||||
<tasks>
|
||||
<replace token="false" value="true"
|
||||
dir="../wso2/components/default/configuration/org.eclipse.equinox.simpleconfigurator">
|
||||
<include name="**/bundles.info"/>
|
||||
</replace>
|
||||
<replace token="false" value="true"
|
||||
dir="../wso2/components/device-manager/configuration/org.eclipse.equinox.simpleconfigurator">
|
||||
<include name="**/bundles.info"/>
|
||||
</replace>
|
||||
<replace token="false" value="true"
|
||||
dir="../wso2/components/device-backend/configuration/org.eclipse.equinox.simpleconfigurator">
|
||||
<include name="**/bundles.info"/>
|
||||
</replace>
|
||||
</tasks>
|
||||
</configuration>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>wso2.releases</id>
|
||||
<name>WSO2 internal Repository</name>
|
||||
<url>http://maven.wso2.org/nexus/content/repositories/releases/</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
<updatePolicy>daily</updatePolicy>
|
||||
<checksumPolicy>ignore</checksumPolicy>
|
||||
</releases>
|
||||
</pluginRepository>
|
||||
<pluginRepository>
|
||||
<id>wso2.snapshots</id>
|
||||
<name>Apache Snapshot Repository</name>
|
||||
<url>http://maven.wso2.org/nexus/content/repositories/snapshots/</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
<updatePolicy>daily</updatePolicy>
|
||||
</snapshots>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
</pluginRepository>
|
||||
<pluginRepository>
|
||||
<id>wso2-nexus</id>
|
||||
<name>WSO2 internal Repository</name>
|
||||
<url>http://maven.wso2.org/nexus/content/groups/wso2-public/</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
<updatePolicy>daily</updatePolicy>
|
||||
<checksumPolicy>ignore</checksumPolicy>
|
||||
</releases>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
|
||||
|
||||
<repositories>
|
||||
<!-- Before adding ANYTHING in here, please start a discussion on the dev list.
|
||||
Ideally the Axis2 build should only use Maven central (which is available
|
||||
by default) and nothing else. We had troubles with other repositories in
|
||||
the past. Therefore configuring additional repositories here should be
|
||||
considered very carefully. -->
|
||||
<repository>
|
||||
<id>wso2-nexus</id>
|
||||
<name>WSO2 internal Repository</name>
|
||||
<url>http://maven.wso2.org/nexus/content/groups/wso2-public/</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
<updatePolicy>daily</updatePolicy>
|
||||
<checksumPolicy>ignore</checksumPolicy>
|
||||
</releases>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>wso2.releases</id>
|
||||
<name>WSO2 internal Repository</name>
|
||||
<url>http://maven.wso2.org/nexus/content/repositories/releases/</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
<updatePolicy>daily</updatePolicy>
|
||||
<checksumPolicy>ignore</checksumPolicy>
|
||||
</releases>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>wso2.snapshots</id>
|
||||
<name>WSO2 Snapshot Repository</name>
|
||||
<url>http://maven.wso2.org/nexus/content/repositories/snapshots/</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
<updatePolicy>daily</updatePolicy>
|
||||
</snapshots>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
</repository>
|
||||
</repositories>
|
||||
<properties>
|
||||
<carbon.device.mgt.plugin.version>${carbon.device.mgt.plugin.version}</carbon.device.mgt.plugin.version>
|
||||
<org.coffeeking.version>1.0.0</org.coffeeking.version>
|
||||
</properties>
|
||||
</project>
|
@ -1,155 +0,0 @@
|
||||
<!--
|
||||
~ Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
~
|
||||
~ WSO2 Inc. licenses this file to you under the Apache License,
|
||||
~ Version 2.0 (the "License"); you may not use this file except
|
||||
~ in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing,
|
||||
~ software distributed under the License is distributed on an
|
||||
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
~ KIND, either express or implied. See the License for the
|
||||
~ specific language governing permissions and limitations
|
||||
~ under the License.
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<parent>
|
||||
<artifactId>device-mgt-iot-connectedcup</artifactId>
|
||||
<groupId>org.coffeeking</groupId>
|
||||
<version>1.0.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>org.coffeeking.connectedcup.agent</artifactId>
|
||||
<packaging>war</packaging>
|
||||
<version>1.0.0</version>
|
||||
<name>WSO2 IoTS(Device Types) - Connected Cup Agent Web app</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.json</groupId>
|
||||
<artifactId>json</artifactId>
|
||||
<version>20151123</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<version>3.0.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<version>1.1.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.paho</groupId>
|
||||
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
|
||||
<version>1.0.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>connected-cup-agent</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>wso2.releases</id>
|
||||
<name>WSO2 internal Repository</name>
|
||||
<url>http://maven.wso2.org/nexus/content/repositories/releases/</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
<updatePolicy>daily</updatePolicy>
|
||||
<checksumPolicy>ignore</checksumPolicy>
|
||||
</releases>
|
||||
</pluginRepository>
|
||||
<pluginRepository>
|
||||
<id>wso2.snapshots</id>
|
||||
<name>Apache Snapshot Repository</name>
|
||||
<url>http://maven.wso2.org/nexus/content/repositories/snapshots/</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
<updatePolicy>daily</updatePolicy>
|
||||
</snapshots>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
</pluginRepository>
|
||||
<pluginRepository>
|
||||
<id>wso2-nexus</id>
|
||||
<name>WSO2 internal Repository</name>
|
||||
<url>http://maven.wso2.org/nexus/content/groups/wso2-public/</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
<updatePolicy>daily</updatePolicy>
|
||||
<checksumPolicy>ignore</checksumPolicy>
|
||||
</releases>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
|
||||
|
||||
<repositories>
|
||||
<!-- Before adding ANYTHING in here, please start a discussion on the dev list.
|
||||
Ideally the Axis2 build should only use Maven central (which is available
|
||||
by default) and nothing else. We had troubles with other repositories in
|
||||
the past. Therefore configuring additional repositories here should be
|
||||
considered very carefully. -->
|
||||
<repository>
|
||||
<id>wso2-nexus</id>
|
||||
<name>WSO2 internal Repository</name>
|
||||
<url>http://maven.wso2.org/nexus/content/groups/wso2-public/</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
<updatePolicy>daily</updatePolicy>
|
||||
<checksumPolicy>ignore</checksumPolicy>
|
||||
</releases>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>wso2.releases</id>
|
||||
<name>WSO2 internal Repository</name>
|
||||
<url>http://maven.wso2.org/nexus/content/repositories/releases/</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
<updatePolicy>daily</updatePolicy>
|
||||
<checksumPolicy>ignore</checksumPolicy>
|
||||
</releases>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>wso2.snapshots</id>
|
||||
<name>WSO2 Snapshot Repository</name>
|
||||
<url>http://maven.wso2.org/nexus/content/repositories/snapshots/</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
<updatePolicy>daily</updatePolicy>
|
||||
</snapshots>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
</project>
|
@ -1,67 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.coffeeking.agent.datasense;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.coffeeking.agent.transport.TransportHandlerException;
|
||||
import org.coffeeking.agent.transport.mqtt.ConnectedCupMQttTransportHandler;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.StreamCorruptedException;
|
||||
|
||||
public class PushLevel extends HttpServlet {
|
||||
private static final Log log = LogFactory.getLog(PushLevel.class);
|
||||
private ConnectedCupMQttTransportHandler connectedCupMQttTransportHandler;
|
||||
|
||||
public PushLevel() {
|
||||
connectedCupMQttTransportHandler = ConnectedCupMQttTransportHandler.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
String deviceId = req.getParameter("deviceId");
|
||||
String tenantDomain = req.getParameter("tenantDomain");
|
||||
String deviceOwner = req.getParameter("deviceOwner");
|
||||
String payload = req.getParameter("payload");
|
||||
payload = " {\"event\": {\"metaData\": {\"owner\": \"" + deviceOwner +
|
||||
"\", \"type\": \"coffeelevel\",\"deviceId\": " +
|
||||
"\"" + deviceId + "\",\"timestamp\": " + System.currentTimeMillis() +
|
||||
"},\"payloadData\": { \"coffeelevel\": " + Float.parseFloat(payload) + ", \"temperature\": 0} }}";
|
||||
String token = (String) req.getSession().getAttribute("token");
|
||||
if (!connectedCupMQttTransportHandler.isConnected()) {
|
||||
connectedCupMQttTransportHandler.setToken(token);
|
||||
connectedCupMQttTransportHandler.connect();
|
||||
}
|
||||
try {
|
||||
if (connectedCupMQttTransportHandler.isConnected()) {
|
||||
connectedCupMQttTransportHandler.publishToConnectedCup(deviceOwner, deviceId, payload, tenantDomain, 0,
|
||||
true);
|
||||
}
|
||||
} catch (TransportHandlerException e) {
|
||||
log.error(e);
|
||||
resp.sendError(500);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.coffeeking.agent.datasense;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.coffeeking.agent.transport.TransportHandlerException;
|
||||
import org.coffeeking.agent.transport.mqtt.ConnectedCupMQttTransportHandler;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
public class PushTemperature extends HttpServlet {
|
||||
private static final Log log = LogFactory.getLog(PushTemperature.class);
|
||||
private ConnectedCupMQttTransportHandler connectedCupMQttTransportHandler;
|
||||
|
||||
public PushTemperature() {
|
||||
connectedCupMQttTransportHandler = ConnectedCupMQttTransportHandler.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
String deviceId = req.getParameter("deviceId");
|
||||
String tenantDomain = req.getParameter("tenantDomain");
|
||||
String payload = req.getParameter("payload");
|
||||
String deviceOwner = req.getParameter("deviceOwner");
|
||||
payload = " {\"event\": {\"metaData\": {\"owner\": \"" + deviceOwner +
|
||||
"\", \"type\": \"temperature\",\"deviceId\": " +
|
||||
"\"" + deviceId + "\",\"timestamp\": " + System.currentTimeMillis() +
|
||||
"},\"payloadData\": { \"temperature\": " + Float.parseFloat(payload) + ", \"coffeelevel\": 0} }}";
|
||||
String token = (String) req.getSession().getAttribute("token");
|
||||
if (!connectedCupMQttTransportHandler.isConnected()) {
|
||||
connectedCupMQttTransportHandler.setToken(token);
|
||||
connectedCupMQttTransportHandler.connect();
|
||||
}
|
||||
try {
|
||||
if (connectedCupMQttTransportHandler.isConnected()) {
|
||||
connectedCupMQttTransportHandler.publishToConnectedCup(deviceOwner, deviceId, payload, tenantDomain, 0,
|
||||
true);
|
||||
}
|
||||
} catch (TransportHandlerException e) {
|
||||
log.error(e);
|
||||
resp.sendError(500);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
/*
|
||||
* 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.coffeeking.agent.transport;
|
||||
|
||||
/**
|
||||
* This interface consists of the core functionality related to the transport between any device and the server. The
|
||||
* interface is an abstraction, regardless of the underlying protocol used for the transport. Implementation of this
|
||||
* interface by any class that caters a specific protocol (ex: HTTP, XMPP, MQTT, CoAP) would ideally have methods
|
||||
* specific to the protocol used for communication and thees methods that implement the logic related to the devices
|
||||
* using the protocol.
|
||||
*
|
||||
* @param <T> a message type specific to the protocol implemented
|
||||
*/
|
||||
public interface TransportHandler<T> {
|
||||
int DEFAULT_TIMEOUT_INTERVAL = 5000; // millis ~ 10 sec
|
||||
|
||||
void connect();
|
||||
|
||||
boolean isConnected();
|
||||
|
||||
void processIncomingMessage() throws TransportHandlerException;
|
||||
|
||||
void processIncomingMessage(T message) throws TransportHandlerException;
|
||||
|
||||
void processIncomingMessage(T message, String... messageParams) throws TransportHandlerException;
|
||||
|
||||
void publishDeviceData() throws TransportHandlerException;
|
||||
|
||||
void publishDeviceData(T publishData) throws TransportHandlerException;
|
||||
|
||||
void publishDeviceData(String... publishData) throws TransportHandlerException;
|
||||
|
||||
void disconnect();
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
/*
|
||||
* 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.coffeeking.agent.transport;
|
||||
|
||||
public class TransportHandlerException extends Exception {
|
||||
private static final long serialVersionUID = 2736466230451105440L;
|
||||
|
||||
private String errorMessage;
|
||||
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
public void setErrorMessage(String errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
|
||||
public TransportHandlerException(String msg, Exception nestedEx) {
|
||||
super(msg, nestedEx);
|
||||
setErrorMessage(msg);
|
||||
}
|
||||
|
||||
public TransportHandlerException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
public TransportHandlerException(String msg) {
|
||||
super(msg);
|
||||
setErrorMessage(msg);
|
||||
}
|
||||
|
||||
public TransportHandlerException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public TransportHandlerException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
@ -1,160 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.coffeeking.agent.transport.mqtt;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.coffeeking.agent.transport.TransportHandlerException;
|
||||
import org.eclipse.paho.client.mqttv3.MqttException;
|
||||
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
|
||||
public class ConnectedCupMQttTransportHandler extends MQTTTransportHandler {
|
||||
|
||||
private static Log log = LogFactory.getLog(ConnectedCupMQttTransportHandler.class);
|
||||
|
||||
private static String iotServerSubscriber = UUID.randomUUID().toString().substring(0, 5);
|
||||
|
||||
private static final String DEVICE_TYPE = "connectedcup";
|
||||
|
||||
private static ConnectedCupMQttTransportHandler connectedCupMQttTransportHandler;
|
||||
|
||||
private static String publishTopic = "%s/" + DEVICE_TYPE + "/%s";
|
||||
|
||||
protected ConnectedCupMQttTransportHandler() {
|
||||
super(iotServerSubscriber, DEVICE_TYPE, "tcp://localhost:1886", "");
|
||||
}
|
||||
|
||||
private ScheduledFuture<?> dataPushServiceHandler;
|
||||
|
||||
public ScheduledFuture<?> getDataPushServiceHandler() {
|
||||
return dataPushServiceHandler;
|
||||
}
|
||||
|
||||
public void setToken(String token) {
|
||||
setUsernameAndPassword(token, "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connect() {
|
||||
Runnable connect = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
log.info("Trying to connect..");
|
||||
while (!isConnected()) {
|
||||
try {
|
||||
connectToQueue();
|
||||
} catch (TransportHandlerException e) {
|
||||
log.warn("Connection to MQTT Broker at: " +
|
||||
mqttBrokerEndPoint + " failed");
|
||||
|
||||
try {
|
||||
Thread.sleep(timeoutInterval);
|
||||
} catch (InterruptedException ex) {
|
||||
log.error("MQTT-Subscriber: Thread Sleep Interrupt Exception");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log.info("Connected..");
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
Thread connectorThread = new Thread(connect);
|
||||
connectorThread.start();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processIncomingMessage(MqttMessage message, String... messageParams) {
|
||||
}
|
||||
|
||||
public void publishToConnectedCup(String deviceOwner , String deviceId, String payLoad, String tenantDomain, int qos, boolean retained)
|
||||
throws TransportHandlerException{
|
||||
String topic = String.format(publishTopic, tenantDomain, deviceId);
|
||||
publishToQueue(topic, payLoad, qos, retained);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnect() {
|
||||
Runnable stopConnection = new Runnable() {
|
||||
public void run() {
|
||||
while (isConnected()) {
|
||||
try {
|
||||
dataPushServiceHandler.cancel(true);
|
||||
closeConnection();
|
||||
|
||||
} catch (MqttException e) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.warn("Unable to 'STOP' MQTT connection at broker at: " +
|
||||
mqttBrokerEndPoint);
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(timeoutInterval);
|
||||
} catch (InterruptedException e1) {
|
||||
log.error("MQTT-Terminator: Thread Sleep Interrupt Exception");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Thread terminatorThread = new Thread(stopConnection);
|
||||
terminatorThread.start();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void publishDeviceData() throws TransportHandlerException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void publishDeviceData(MqttMessage publishData) throws TransportHandlerException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void publishDeviceData(String... publishData) throws TransportHandlerException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processIncomingMessage() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processIncomingMessage(MqttMessage message) throws TransportHandlerException {
|
||||
|
||||
}
|
||||
|
||||
public static ConnectedCupMQttTransportHandler getInstance(){
|
||||
if(connectedCupMQttTransportHandler == null){
|
||||
connectedCupMQttTransportHandler = new ConnectedCupMQttTransportHandler();
|
||||
}
|
||||
return connectedCupMQttTransportHandler;
|
||||
}
|
||||
|
||||
}
|
@ -1,372 +0,0 @@
|
||||
/*
|
||||
* 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.coffeeking.agent.transport.mqtt;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.coffeeking.agent.transport.TransportHandler;
|
||||
import org.coffeeking.agent.transport.TransportHandlerException;
|
||||
import org.eclipse.paho.client.mqttv3.*;
|
||||
import java.io.File;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* This is an abstract class that implements the "TransportHandler" interface. The interface is an abstraction for
|
||||
* the core functionality with regards to device-server communication regardless of the Transport protocol. This
|
||||
* specific class contains the HTTP-Transport specific implementations. The class implements utility methods for the
|
||||
* case of a HTTP communication. However, this "abstract class", even-though it implements the "TransportHandler"
|
||||
* interface, does not contain the logic relevant to the interface methods. The specific functionality of the
|
||||
* interface methods are intended to be implemented by the concrete class that extends this abstract class and
|
||||
* utilizes the HTTP specific functionality (ideally a device API writer who would like to communicate to the device
|
||||
* via HTTP Protocol).
|
||||
* <p/>
|
||||
* This class contains the Device-Management specific implementation for all the MQTT functionality. This includes
|
||||
* connecting to a MQTT Broker & subscribing to the appropriate MQTT-topic, action plan upon losing connection or
|
||||
* successfully delivering a message to the broker and processing incoming messages. Makes use of the 'Paho-MQTT'
|
||||
* library provided by Eclipse Org.
|
||||
*/
|
||||
public abstract class MQTTTransportHandler
|
||||
implements MqttCallback, TransportHandler<MqttMessage> {
|
||||
private static final Log log = LogFactory.getLog(MQTTTransportHandler.class);
|
||||
|
||||
public static final int DEFAULT_MQTT_QUALITY_OF_SERVICE = 0;
|
||||
|
||||
private MqttClient client;
|
||||
private String clientId;
|
||||
private MqttConnectOptions options;
|
||||
private String clientWillTopic;
|
||||
|
||||
protected String mqttBrokerEndPoint;
|
||||
protected int timeoutInterval;
|
||||
protected String subscribeTopic;
|
||||
|
||||
/**
|
||||
* Constructor for the MQTTTransportHandler which takes in the owner, type of the device
|
||||
* and the MQTT Broker URL and the topic to subscribe.
|
||||
*
|
||||
* @param deviceOwner the owner of the device.
|
||||
* @param deviceType the CDMF Device-Type of the device.
|
||||
* @param mqttBrokerEndPoint the IP/URL of the MQTT broker endpoint.
|
||||
* @param subscribeTopic the MQTT topic to which the client is to be subscribed
|
||||
*/
|
||||
protected MQTTTransportHandler(String deviceOwner, String deviceType,
|
||||
String mqttBrokerEndPoint,
|
||||
String subscribeTopic) {
|
||||
this.clientId = deviceOwner + ":" + deviceType;
|
||||
this.subscribeTopic = subscribeTopic;
|
||||
this.clientWillTopic = deviceType + File.separator + "disconnection";
|
||||
this.mqttBrokerEndPoint = mqttBrokerEndPoint;
|
||||
this.timeoutInterval = DEFAULT_TIMEOUT_INTERVAL;
|
||||
this.initSubscriber();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for the MQTTTransportHandler which takes in the owner, type of the device
|
||||
* and the MQTT Broker URL and the topic to subscribe. Additionally this constructor takes in
|
||||
* the reconnection-time interval between successive attempts to connect to the broker.
|
||||
*
|
||||
* @param deviceOwner the owner of the device.
|
||||
* @param deviceType the CDMF Device-Type of the device.
|
||||
* @param mqttBrokerEndPoint the IP/URL of the MQTT broker endpoint.
|
||||
* @param subscribeTopic the MQTT topic to which the client is to be subscribed
|
||||
* @param intervalInMillis the time interval in MILLI-SECONDS between successive
|
||||
* attempts to connect to the broker.
|
||||
*/
|
||||
protected MQTTTransportHandler(String deviceOwner, String deviceType,
|
||||
String mqttBrokerEndPoint, String subscribeTopic,
|
||||
int intervalInMillis) {
|
||||
this.clientId = deviceOwner + ":" + deviceType;
|
||||
this.subscribeTopic = subscribeTopic;
|
||||
//TODO:: Use constant strings
|
||||
this.clientWillTopic = deviceType + File.separator + "disconnection";
|
||||
this.mqttBrokerEndPoint = mqttBrokerEndPoint;
|
||||
this.timeoutInterval = intervalInMillis;
|
||||
this.initSubscriber();
|
||||
}
|
||||
|
||||
public void setUsernameAndPassword (String username, String password) {
|
||||
options.setUserName(username);
|
||||
options.setPassword(password.toCharArray());
|
||||
}
|
||||
|
||||
public void setTimeoutInterval(int timeoutInterval) {
|
||||
this.timeoutInterval = timeoutInterval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the MQTT-Client. Creates a client using the given MQTT-broker endpoint and the
|
||||
* clientId (which is constructed by a concatenation of [deviceOwner]:[deviceType]). Also sets
|
||||
* the client's options parameter with the clientWillTopic (in-case of connection failure) and
|
||||
* other info. Also sets the call-back this current class.
|
||||
*/
|
||||
private void initSubscriber() {
|
||||
try {
|
||||
client = new MqttClient(this.mqttBrokerEndPoint, clientId, null);
|
||||
//TODO:: Need to check for debug
|
||||
log.info("MQTT subscriber was created with ClientID : " + clientId);
|
||||
} catch (MqttException ex) {
|
||||
//TODO:: Remove unnecessary formatting and print exception
|
||||
String errorMsg = "MQTT Client Error\n" + "\tReason: " + ex.getReasonCode() +
|
||||
"\n\tMessage: " + ex.getMessage() + "\n\tLocalMsg: " +
|
||||
ex.getLocalizedMessage() + "\n\tCause: " + ex.getCause() +
|
||||
"\n\tException: " + ex;
|
||||
log.error(errorMsg);
|
||||
//TODO:: Throw the error out
|
||||
}
|
||||
|
||||
options = new MqttConnectOptions();
|
||||
options.setCleanSession(true);
|
||||
//TODO:: Use constant strings
|
||||
options.setWill(clientWillTopic, "Connection-Lost".getBytes(StandardCharsets.UTF_8), 2,
|
||||
true);
|
||||
client.setCallback(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the connection to the MQTT-Broker persists.
|
||||
*
|
||||
* @return true if the client is connected to the MQTT-Broker, else false.
|
||||
*/
|
||||
@Override
|
||||
public boolean isConnected() {
|
||||
return client.isConnected();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Connects to the MQTT-Broker and if successfully established connection.
|
||||
*
|
||||
* @throws TransportHandlerException in the event of 'Connecting to' the MQTT broker fails.
|
||||
*/
|
||||
protected void connectToQueue() throws TransportHandlerException {
|
||||
try {
|
||||
client.connect(options);
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Subscriber connected to queue at: " + this.mqttBrokerEndPoint);
|
||||
}
|
||||
} catch (MqttSecurityException ex) {
|
||||
String errorMsg = "MQTT Security Exception when connecting to queue\n" + "\tReason: " +
|
||||
" " +
|
||||
ex.getReasonCode() + "\n\tMessage: " + ex.getMessage() +
|
||||
"\n\tLocalMsg: " + ex.getLocalizedMessage() + "\n\tCause: " +
|
||||
ex.getCause() + "\n\tException: " + ex;
|
||||
//TODO:: Compulsory log of errors and remove formatted error
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(errorMsg);
|
||||
}
|
||||
throw new TransportHandlerException(errorMsg, ex);
|
||||
|
||||
} catch (MqttException ex) {
|
||||
//TODO:: Compulsory log of errors and remove formatted error
|
||||
String errorMsg = "MQTT Exception when connecting to queue\n" + "\tReason: " +
|
||||
ex.getReasonCode() + "\n\tMessage: " + ex.getMessage() +
|
||||
"\n\tLocalMsg: " + ex.getLocalizedMessage() + "\n\tCause: " +
|
||||
ex.getCause() + "\n\tException: " + ex;
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(errorMsg);
|
||||
}
|
||||
throw new TransportHandlerException(errorMsg, ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscribes to the MQTT-Topic specific to this MQTT Client. (The MQTT-Topic specific to the
|
||||
* device is taken in as a constructor parameter of this class) .
|
||||
*
|
||||
* @throws TransportHandlerException in the event of 'Subscribing to' the MQTT broker
|
||||
* fails.
|
||||
*/
|
||||
protected void subscribeToQueue() throws TransportHandlerException {
|
||||
try {
|
||||
//TODO:: QoS Level take it from a variable
|
||||
client.subscribe(subscribeTopic, 0);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Subscriber '" + clientId + "' subscribed to topic: " + subscribeTopic);
|
||||
}
|
||||
} catch (MqttException ex) {
|
||||
//TODO:: Compulsory log of errors and remove formatted error
|
||||
String errorMsg = "MQTT Exception when trying to subscribe to topic: " +
|
||||
subscribeTopic + "\n\tReason: " + ex.getReasonCode() +
|
||||
"\n\tMessage: " + ex.getMessage() + "\n\tLocalMsg: " +
|
||||
ex.getLocalizedMessage() + "\n\tCause: " + ex.getCause() +
|
||||
"\n\tException: " + ex;
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(errorMsg);
|
||||
}
|
||||
|
||||
throw new TransportHandlerException(errorMsg, ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method is used to publish reply-messages for the control signals received.
|
||||
* Invocation of this method calls its overloaded-method with a QoS equal to that of the
|
||||
* default value.
|
||||
*
|
||||
* @param topic the topic to which the reply message is to be published.
|
||||
* @param payLoad the reply-message (payload) of the MQTT publish action.
|
||||
*/
|
||||
protected void publishToQueue(String topic, String payLoad)
|
||||
throws TransportHandlerException {
|
||||
publishToQueue(topic, payLoad, DEFAULT_MQTT_QUALITY_OF_SERVICE, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is an overloaded method that publishes MQTT reply-messages for control signals
|
||||
* received form the IoT-Server.
|
||||
*
|
||||
* @param topic the topic to which the reply message is to be published
|
||||
* @param payLoad the reply-message (payload) of the MQTT publish action.
|
||||
* @param qos the Quality-of-Service of the current publish action.
|
||||
* Could be 0(At-most once), 1(At-least once) or 2(Exactly once)
|
||||
*/
|
||||
protected void publishToQueue(String topic, String payLoad, int qos, boolean retained)
|
||||
throws TransportHandlerException {
|
||||
try {
|
||||
client.publish(topic, payLoad.getBytes(StandardCharsets.UTF_8), qos, retained);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Message: " + payLoad + " to MQTT topic [" + topic +
|
||||
"] published successfully");
|
||||
}
|
||||
} catch (MqttException ex) {
|
||||
String errorMsg =
|
||||
"MQTT Client Error" + "\n\tReason: " + ex.getReasonCode() + "\n\tMessage: " +
|
||||
ex.getMessage() + "\n\tLocalMsg: " + ex.getLocalizedMessage() +
|
||||
"\n\tCause: " + ex.getCause() + "\n\tException: " + ex;
|
||||
log.info(errorMsg);
|
||||
throw new TransportHandlerException(errorMsg, ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void publishToQueue(String topic, MqttMessage message)
|
||||
throws TransportHandlerException {
|
||||
try {
|
||||
client.publish(topic, message);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Message: " + message.toString() + " to MQTT topic [" + topic +
|
||||
"] published successfully");
|
||||
}
|
||||
} catch (MqttException ex) {
|
||||
//TODO:: Compulsory log of errors and remove formatted error
|
||||
String errorMsg =
|
||||
"MQTT Client Error" + "\n\tReason: " + ex.getReasonCode() + "\n\tMessage: " +
|
||||
ex.getMessage() + "\n\tLocalMsg: " + ex.getLocalizedMessage() +
|
||||
"\n\tCause: " + ex.getCause() + "\n\tException: " + ex;
|
||||
log.info(errorMsg);
|
||||
throw new TransportHandlerException(errorMsg, ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Callback method which is triggered once the MQTT client losers its connection to the broker.
|
||||
* Spawns a new thread that executes necessary actions to try and reconnect to the endpoint.
|
||||
*
|
||||
* @param throwable a Throwable Object containing the details as to why the failure occurred.
|
||||
*/
|
||||
@Override
|
||||
public void connectionLost(Throwable throwable) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.warn("Lost Connection for client: " + this.clientId + " to " + this.mqttBrokerEndPoint + "." +
|
||||
"\nThis was due to - " + throwable.getMessage());
|
||||
}
|
||||
|
||||
Thread reconnectThread = new Thread() {
|
||||
public void run() {
|
||||
connect();
|
||||
}
|
||||
};
|
||||
reconnectThread.setDaemon(true);
|
||||
reconnectThread.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback method which is triggered upon receiving a MQTT Message from the broker. Spawns a
|
||||
* new thread that executes any actions to be taken with the received message.
|
||||
*
|
||||
* @param topic the MQTT-Topic to which the received message was published to and the
|
||||
* client was subscribed to.
|
||||
* @param mqttMessage the actual MQTT-Message that was received from the broker.
|
||||
*/
|
||||
@Override
|
||||
public void messageArrived(final String topic, final MqttMessage mqttMessage) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Got an MQTT message '" + mqttMessage.toString() + "' for topic '" + topic + "'.");
|
||||
}
|
||||
|
||||
Thread messageProcessorThread = new Thread() {
|
||||
public void run() {
|
||||
try {
|
||||
processIncomingMessage(mqttMessage, topic);
|
||||
} catch (TransportHandlerException e) {
|
||||
log.error("An error occurred when trying to process received MQTT message [" + mqttMessage + "] " +
|
||||
"for topic [" + topic + "].", e);
|
||||
}
|
||||
}
|
||||
};
|
||||
messageProcessorThread.setDaemon(true);
|
||||
messageProcessorThread.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback method which gets triggered upon successful completion of a message delivery to
|
||||
* the broker.
|
||||
*
|
||||
* @param iMqttDeliveryToken the MQTT-DeliveryToken which includes the details about the
|
||||
* specific message delivery.
|
||||
*/
|
||||
@Override
|
||||
public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
|
||||
String topic = iMqttDeliveryToken.getTopics()[0];
|
||||
String client = iMqttDeliveryToken.getClient().getClientId();
|
||||
|
||||
try {
|
||||
if (iMqttDeliveryToken.isComplete()) {
|
||||
if (log.isDebugEnabled()) {
|
||||
if (iMqttDeliveryToken.getMessage() != null) {
|
||||
String message = iMqttDeliveryToken.getMessage().toString();
|
||||
log.debug("Message to client [" + client + "] under topic (" + topic +
|
||||
") was delivered successfully with the delivery message: '" + message + "'");
|
||||
} else {
|
||||
log.debug("Message to client [" + client + "] under topic (" + topic +
|
||||
") was delivered successfully.");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log.warn("FAILED: Delivery of MQTT message to [" + client + "] under topic [" + topic + "] failed.");
|
||||
}
|
||||
} catch (MqttException e) {
|
||||
//TODO:: Throw errors
|
||||
log.error("Error occurred whilst trying to read the message from the MQTT delivery token.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the connection to the MQTT Broker.
|
||||
*/
|
||||
public void closeConnection() throws MqttException {
|
||||
if (client != null && isConnected()) {
|
||||
client.disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,27 +0,0 @@
|
||||
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://java.sun.com/xml/ns/javaee"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
|
||||
version="2.5">
|
||||
<display-name>ConnectedCup-Webapp</display-name>
|
||||
|
||||
<servlet>
|
||||
<servlet-name>PushTemperature</servlet-name>
|
||||
<servlet-class>org.coffeeking.agent.datasense.PushTemperature</servlet-class>
|
||||
<load-on-startup>1</load-on-startup>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>PushTemperature</servlet-name>
|
||||
<url-pattern>/push_temperature</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<servlet>
|
||||
<servlet-name>PushLevel</servlet-name>
|
||||
<servlet-class>org.coffeeking.agent.datasense.PushLevel</servlet-class>
|
||||
<load-on-startup>1</load-on-startup>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>PushLevel</servlet-name>
|
||||
<url-pattern>/push_level</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
</web-app>
|
@ -1,299 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
input[type=range][orient=vertical]
|
||||
{
|
||||
writing-mode: bt-lr; /* IE */
|
||||
-webkit-appearance: slider-vertical; /* WebKit */
|
||||
width: 8px;
|
||||
height: 175px;
|
||||
padding: 0 5px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
padding-top: 10px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.left-pane{
|
||||
float: left;
|
||||
width: 30%;
|
||||
text-align: center;
|
||||
min-width: 325px;
|
||||
}
|
||||
.right-pane{
|
||||
float: right;
|
||||
background-color: rgba(204, 204, 204, 0.61);
|
||||
width: 70%;
|
||||
}
|
||||
.coffee-wrapper{
|
||||
margin: 10% 0 5% 10%;
|
||||
text-align: center;
|
||||
}
|
||||
.coffee-top{
|
||||
position: absolute;
|
||||
bottom: 10px;
|
||||
height: 30px;
|
||||
width: 100%;
|
||||
z-index: 99;
|
||||
background-color: aquamarine;
|
||||
}
|
||||
.coffee-bottom{
|
||||
position: absolute;
|
||||
bottom: 0px;
|
||||
height: 10px;
|
||||
width: 100%;
|
||||
z-index: 98;
|
||||
background-color: aqua;
|
||||
}
|
||||
|
||||
.handle {
|
||||
position: absolute;
|
||||
height: 200px;
|
||||
width: 97px;
|
||||
top: 39px;
|
||||
left: -111px;
|
||||
border-top-left-radius: 75px 100px;
|
||||
border-bottom-left-radius: 75px 100px;
|
||||
border-top-right-radius: 50% 20px;
|
||||
border-bottom-right-radius: 50% 20px;
|
||||
background: linear-gradient(to left, rgba(0, 0, 0, 0.01) 0%, rgba(0, 0, 0, 0.01) 100%);
|
||||
background-color: rgba(255, 255, 255, 0.28);
|
||||
border: 1px solid rgba(255, 255, 255, 0.25);
|
||||
}
|
||||
.handle:after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
height: 167px;
|
||||
width: 76px;
|
||||
top: 15px;
|
||||
right: 0;
|
||||
border-top-left-radius: 45px 70px;
|
||||
border-bottom-left-radius: 45px 70px;
|
||||
border-top-right-radius: 45px 35px;
|
||||
border-bottom-right-radius: 45px 35px;
|
||||
background: rgba(204, 204, 204, 0.3);
|
||||
}
|
||||
|
||||
:before, :after {
|
||||
content: '';
|
||||
display: block;
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
html, body {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.coffee {
|
||||
display: inline-block;
|
||||
position: relative;
|
||||
width: 300px;
|
||||
margin: 0 20px 50px 0;
|
||||
}
|
||||
|
||||
.coffee:after {
|
||||
height: 14px;
|
||||
width: 300px;
|
||||
border-radius: 46px/10px;
|
||||
box-shadow: 0px 1px 4px -2px rgba(0, 0, 0, 0.2), 0px 2px 10px -3px rgba(0, 0, 0, 0.1);
|
||||
bottom: -7.6px;
|
||||
z-index: 0;
|
||||
}
|
||||
|
||||
.coffee:before {
|
||||
height: 14px;
|
||||
width: 300px;
|
||||
border-radius: 46px/10px;
|
||||
box-shadow: 0px 2px 10px -2px rgba(0, 204, 255, 0.3), 0px 2px 15px -2px rgba(0, 204, 255, 0.4);
|
||||
bottom: -7.6px;
|
||||
z-index: 0;
|
||||
}
|
||||
|
||||
.coffee_main {
|
||||
height: 300px;
|
||||
position: relative;
|
||||
width: 298px;
|
||||
background: none;
|
||||
border: 1px solid rgba(255, 255, 255, 0.5);
|
||||
border-top: none;
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.coffee_main:after, .coffee_main:before {
|
||||
height: 12px;
|
||||
width: 296px;
|
||||
border-radius: 46px/10px;
|
||||
border: 2px solid rgba(255, 255, 255, 0.5);
|
||||
border-bottom: 2px solid rgba(255, 255, 255, 0.7);
|
||||
border-top: 1px solid rgba(255, 255, 255, 0.3);
|
||||
left: -1px;
|
||||
}
|
||||
|
||||
.coffee_main:after {
|
||||
top: -7px;
|
||||
box-shadow: 0px 0px 6px rgba(255, 255, 255, 0.6) inset, 0px 3px 3px -1px rgba(255, 255, 255, 0.4), 0px 0px 3px rgba(0, 0, 0, 0.05) inset, 0px 0px 6px rgba(255, 255, 255, 0.7) inset, 0px 0px 3px rgba(0, 0, 0, 0.15) inset;
|
||||
}
|
||||
|
||||
.coffee_main:before {
|
||||
top: 294px;
|
||||
box-shadow: 0px 0px 6px rgba(255, 255, 255, 0.7) inset, 0px 0px 3px rgba(0, 0, 0, 0.15) inset;
|
||||
}
|
||||
|
||||
.coffee_mouth {
|
||||
height: 52px;
|
||||
width: 44px;
|
||||
margin: 0px auto;
|
||||
position: relative;
|
||||
background: none;
|
||||
border: 1px solid rgba(0, 0, 0, 0.04);
|
||||
border-top: none;
|
||||
border-bottom: none;
|
||||
background: linear-gradient(to right, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0) 5%, rgba(255, 255, 255, 0) 95%, rgba(255, 255, 255, 0.3));
|
||||
box-shadow: 0px 0px 6px rgba(255, 255, 255, 0.3);
|
||||
}
|
||||
|
||||
.coffee_mouth:after {
|
||||
height: 6px;
|
||||
width: 44px;
|
||||
border-radius: 25px/6px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.4);
|
||||
left: -1px;
|
||||
top: -4px;
|
||||
z-index: 1;
|
||||
box-shadow: 0px 0px 3px rgba(255, 255, 255, 0.3);
|
||||
}
|
||||
|
||||
.coffee_inner {
|
||||
height: 295px;
|
||||
width: 92%;
|
||||
margin: 0px auto;
|
||||
border-radius: 10px 10px 20px 20px/10px;
|
||||
border: 1px solid rgba(0, 0, 0, 0.01);
|
||||
border-top: 1px solid rgba(255, 255, 255, 0.3);
|
||||
border-bottom-width: 0.5px;
|
||||
position: relative;
|
||||
box-shadow: 0px 0px 2px rgba(255, 255, 255, 0.5) inset, 0px 0px 8px rgba(255, 255, 255, 0.6) inset, 0px 0px 5px rgba(255, 255, 255, 0.5);
|
||||
position: relative;
|
||||
top: 1px;
|
||||
}
|
||||
|
||||
.coffee_inner:before {
|
||||
border-radius: 40px/4px;
|
||||
top: 140px;
|
||||
width: 90%;
|
||||
left: 3px;
|
||||
height: 9px;
|
||||
}
|
||||
|
||||
.coffee_top .highlight {
|
||||
display: block;
|
||||
height: 30px;
|
||||
width: 20px;
|
||||
position: absolute;
|
||||
left: 5px;
|
||||
top: 5px;
|
||||
transform: skew(0deg, 5deg);
|
||||
background: linear-gradient(to right, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.6) 4%, rgba(255, 255, 255, 0.2) 98%, rgba(255, 255, 255, 0));
|
||||
}
|
||||
|
||||
.coffee_top .highlight:after {
|
||||
height: 30px;
|
||||
width: 2px;
|
||||
left: -3px;
|
||||
top: -1px;
|
||||
transform: skew(0deg, 5deg);
|
||||
background: rgba(255, 255, 255, 0.3);
|
||||
}
|
||||
|
||||
.coffee_main .highlight {
|
||||
display: block;
|
||||
height: 301px;
|
||||
width: 25px;
|
||||
position: absolute;
|
||||
left: 10px;
|
||||
top: 6px;
|
||||
transform: skew(0deg, 6deg);
|
||||
background: linear-gradient(to right, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0.5) 4%, rgba(255, 255, 255, 0.2) 98%, rgba(255, 255, 255, 0));
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
.coffee_main .highlight:after {
|
||||
height: 150px;
|
||||
width: 4px;
|
||||
left: -6px;
|
||||
top: 0px;
|
||||
transform: skew(0deg, 3deg);
|
||||
background: linear-gradient(to bottom, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0) 80%);
|
||||
}
|
||||
|
||||
.coffee_neck .highlight {
|
||||
display: block;
|
||||
height: 20px;
|
||||
width: 25px;
|
||||
position: absolute;
|
||||
left: 2px;
|
||||
top: 6px;
|
||||
transform: skew(0deg, 6deg);
|
||||
background: linear-gradient(to right, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.3) 4%, rgba(255, 255, 255, 0.1) 98%, rgba(255, 255, 255, 0));
|
||||
}
|
||||
|
||||
.water {
|
||||
background: linear-gradient(-85deg, rgba(167, 92, 24, 0.35), rgba(169, 108, 52, 0.55) 70%, rgba(185, 128, 76, 0.4));
|
||||
width: 99%;
|
||||
height: 80px;
|
||||
position: absolute;
|
||||
left: 1px;
|
||||
bottom: 1px;
|
||||
border-radius: 50px 50px 20px 20px/8px 8px 10px 10px;
|
||||
box-shadow: 0px 0px 6px rgba(165, 117, 73, 0.5) inset, 0px 0.2px 3px -1px rgba(0, 0, 0, 0.3) inset, 0px 2px 6px -1px rgba(0, 0, 0, 0.1) inset, 0px 2px 5px rgba(190,155,123,0.3), 0px 1px 3px rgba(190,155,123,0.2);
|
||||
}
|
||||
|
||||
.water:after {
|
||||
height: 10px;
|
||||
width: 100%;
|
||||
left: -1px;
|
||||
top: 0px;
|
||||
background: linear-gradient(to right, rgba(255, 255, 255, 0.4), rgba(255, 127, 0, 0.05) 50%, rgba(251, 148, 0, 0.1) 80%, rgba(255, 255, 255, 0.3));
|
||||
border-radius: 50px/8px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.2);
|
||||
border-bottom-color: rgba(255, 255, 255, 0.4);
|
||||
box-shadow: 0px 1px 2px -1px rgba(165, 90, 26, 0.35);
|
||||
}
|
||||
|
||||
.water:before {
|
||||
height: 10px;
|
||||
width: 100%;
|
||||
left: 2px;
|
||||
bottom: -1px;
|
||||
background: linear-gradient(to right, rgba(190,155,123,0.2), rgba(190,155,123,0.1) 50%, rgba(190,155,123,0.2) 80%, rgba(190,155,123,0.3));
|
||||
border-radius: 50px/10px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||
border-bottom: none;
|
||||
box-shadow: 0px -2px 3px -1px rgba(190,155,123,0.25);
|
||||
}
|
||||
|
||||
.water {
|
||||
height: 0px;
|
||||
-webkit-transition: all 3s ease-out;
|
||||
-moz-transition: all 3s ease-out;
|
||||
-o-transition: all 3s ease-out;
|
||||
transition: all 3s ease-out;
|
||||
-webkit-border-radius: 10px;
|
||||
-moz-border-radius: 10px;
|
||||
}
|
@ -1,134 +0,0 @@
|
||||
<%--
|
||||
~ Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
~
|
||||
~ WSO2 Inc. licenses this file to you under the Apache License,
|
||||
~ Version 2.0 (the "License"); you may not use this file except
|
||||
~ in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing,
|
||||
~ software distributed under the License is distributed on an
|
||||
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
~ KIND, either express or implied. See the License for the
|
||||
~ specific language governing permissions and limitations
|
||||
~ under the License.
|
||||
--%>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>Connected Coffee Cup</title>
|
||||
<link rel="stylesheet" href="css/coffee.css">
|
||||
<!--[if lt IE 9]>
|
||||
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
||||
<![endif]-->
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<%
|
||||
String deviceId = request.getParameter("deviceId");
|
||||
if (deviceId != null) {
|
||||
request.getSession().setAttribute("deviceId", deviceId);
|
||||
}
|
||||
|
||||
String deviceOwner = request.getParameter("deviceOwner");
|
||||
if (deviceOwner != null) {
|
||||
request.getSession().setAttribute("deviceOwner", deviceOwner);
|
||||
}
|
||||
|
||||
String tenantDomain = request.getParameter("tenantDomain");
|
||||
if (tenantDomain != null) {
|
||||
request.getSession().setAttribute("tenantDomain", tenantDomain);
|
||||
}
|
||||
|
||||
String token = request.getParameter("token");
|
||||
if (token != null) {
|
||||
request.getSession().setAttribute("token", token);
|
||||
}
|
||||
%>
|
||||
|
||||
<div class="container">
|
||||
<h1>Coffee Cup - Demo</h1>
|
||||
<div class="left-pane">
|
||||
<table style="width:100%">
|
||||
<tr>
|
||||
<td align="right" style="width: 140px">Temperature:</td>
|
||||
<td id="temperature_level" align="left" style="width: 60px">0 C</td>
|
||||
<td align="right" style="width: 140px">Coffee Level:</td>
|
||||
<td id="coffee_level" align="left" style="width: 60px">0%</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2" align="center">
|
||||
<input id="amount_temp" type="range" orient="vertical" min="0" max="100"
|
||||
value="0"
|
||||
onchange="updateTemperature(this.value)"><br/>
|
||||
</td>
|
||||
<td colspan="2" align="center">
|
||||
<input id="amount_coffee" type="range" orient="vertical" min="0" max="100"
|
||||
value="0"
|
||||
onchange="updateCoffee(this.value)">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="4" align="center">
|
||||
<button id="order-cup">Order Coffee Cup</button>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="right-pane">
|
||||
<div class="coffee-wrapper">
|
||||
<div class="coffee">
|
||||
<div class="coffee_main">
|
||||
<div class="coffee_inner">
|
||||
<div class="handle"></div>
|
||||
<div class="water" id="water"></div>
|
||||
</div>
|
||||
<div class="highlight"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="js/libs/jquery.min.js"></script>
|
||||
<script src="js/coffee.js"></script>
|
||||
<script src="js/libs/htmlpreview.min.js"></script>
|
||||
<script>HTMLPreview.replaceAssets();</script>
|
||||
<script>
|
||||
$('#order-cup').click(function () {
|
||||
var deviceId = '<%=request.getSession().getAttribute("deviceId")%>';
|
||||
var deviceOwner = '<%=request.getSession().getAttribute("deviceOwner")%>';
|
||||
var token = '<%=request.getSession().getAttribute("token")%>';
|
||||
var url = '/connectedcup/device/ordercoffee?deviceId=' + deviceId ;
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: url,
|
||||
headers: {
|
||||
'Authorization': 'Bearer ' + token
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function sendData() {
|
||||
var deviceId = '<%=request.getSession().getAttribute("deviceId")%>';
|
||||
var deviceOwner = '<%=request.getSession().getAttribute("deviceOwner")%>';
|
||||
var tenantDomain = '<%=request.getSession().getAttribute("tenantDomain")%>';
|
||||
if (tenantDomain == null) {
|
||||
tenantDomain = 'carbon.super';
|
||||
}
|
||||
var tempPayload = temperature;
|
||||
var levelPayload = coffee_amount;
|
||||
$.post('/connected-cup-agent/push_temperature?deviceId=' + deviceId + '&deviceOwner=' + deviceOwner +
|
||||
'&payload=' + tempPayload + '&tenantDomain=' + tenantDomain);
|
||||
$.post('/connected-cup-agent/push_level?deviceId=' + deviceId + '&deviceOwner=' + deviceOwner +
|
||||
'&payload=' + levelPayload + '&tenantDomain=' + tenantDomain);
|
||||
setTimeout(sendData, 5000);
|
||||
}
|
||||
|
||||
sendData();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -1,39 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
var temperature = 0;
|
||||
var coffee_amount = 0;
|
||||
|
||||
function updateCoffee(newValue) {
|
||||
var coffee_level = document.getElementById('coffee_level');
|
||||
coffee_level.innerHTML = newValue + '%';
|
||||
coffee_amount = newValue;
|
||||
|
||||
var coffee = document.getElementById('water');
|
||||
if (newValue == 0) {
|
||||
coffee.style.height = (newValue * 3) + 'px';
|
||||
} else {
|
||||
coffee.style.height = (newValue * 3) - 3 + 'px';
|
||||
}
|
||||
}
|
||||
|
||||
function updateTemperature(newValue) {
|
||||
temperature = newValue;
|
||||
var temperature_level = document.getElementById('temperature_level');
|
||||
temperature_level.innerHTML = newValue + ' C';
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
var HTMLPreview={content:"",previewform:document.getElementById("previewform"),file:function(){return location.search.substring(1)},raw:function(){return HTMLPreview.file().replace(/\/\/github\.com/,"//raw.githubusercontent.com").replace(/\/blob\//,"/")},replaceAssets:function(){var a,b,c;a=document.querySelectorAll("iframe[src],frame[src]");for(b=0;b<a.length;++b)if(c=a[b].src,0<c.indexOf("//raw.githubusercontent.com")||0<c.indexOf("//bitbucket.org"))a[b].src="//"+location.hostname+location.pathname+"?"+c;a=document.querySelectorAll("a[href]");for(b=0;b<a.length;++b)if(c=a[b].href,0<c.indexOf("#"))a[b].href="//"+location.hostname+location.pathname+location.search+"#"+a[b].hash.substring(1);else if((0<c.indexOf("//raw.githubusercontent.com")||0<c.indexOf("//bitbucket.org"))&&(0<c.indexOf(".html")||0<c.indexOf(".htm")))a[b].href="//"+location.hostname+location.pathname+"?"+c;if(!document.querySelectorAll("frameset").length){a=document.querySelectorAll("link[rel=stylesheet]");for(b=0;b<a.length;++b)c=a[b].href,(0<c.indexOf("//raw.githubusercontent.com")||0<c.indexOf("//bitbucket.org"))&&HTMLPreview.send(c,"loadCSS");a=document.querySelectorAll("script");for(b=0;b<a.length;++b)c=a[b].src,0<c.indexOf("//raw.githubusercontent.com")||0<c.indexOf("//bitbucket.org")?HTMLPreview.send(c,"loadJS"):!c&&0>a[b].innerHTML.indexOf("HTMLPreview")&&document.write(a[b].outerHTML)}},loadHTML:function(a){a&&a.query&&a.query.diagnostics&&a.query.diagnostics.redirect?HTMLPreview.send(a.query.diagnostics.redirect.content,"loadHTML"):a&&a.query&&a.query.results&&a.query.results.resources&&a.query.results.resources.content&&200==a.query.results.resources.status?(HTMLPreview.content=a.query.results.resources.content.replace(/<head>/i,'<head><base href="'+HTMLPreview.raw()+'">').replace(/<\/body>/i,'<script src="//'+location.hostname+'/htmlpreview.min.js">\x3c/script><script>HTMLPreview.replaceAssets();\x3c/script></body>').replace(/<\/head>\s*<frameset/gi,'<script src="//'+location.hostname+'/htmlpreview.min.js">\x3c/script><script>document.addEventListener("DOMContentLoaded",HTMLPreview.replaceAssets,false);\x3c/script></head><frameset'),setTimeout(function(){document.open();document.write(HTMLPreview.content);document.close()},50)):HTMLPreview.previewform.innerHTML=a&&a.error&&a.error.description?a.error.description:"Error: Cannot load file "+HTMLPreview.raw()},loadCSS:function(a){a&&a.query&&a.query.diagnostics&&a.query.diagnostics.redirect?HTMLPreview.send(a.query.diagnostics.redirect.content,"loadCSS"):a&&a.query&&a.query.results&&a.query.results.resources&&a.query.results.resources.content&&200==a.query.results.resources.status&&document.write("<style>"+a.query.results.resources.content.replace(/url\((?:'|")?([^\/][^:'"\)]+)(?:'|")?\)/gi,"url("+a.query.results.resources.url.replace(/[^\/]+\.css.*$/gi,"")+"$1)")+"</style>")},loadJS:function(a){a&&a.query&&a.query.diagnostics&&a.query.diagnostics.redirect?HTMLPreview.send(a.query.diagnostics.redirect.content,"loadJS"):a&&a.query&&a.query.results&&a.query.results.resources&&a.query.results.resources.content&&200==a.query.results.resources.status&&document.write("<script>"+a.query.results.resources.content+"\x3c/script>")},send:function(a,b){document.write('<script src="//query.yahooapis.com/v1/public/yql?q=select%20*%20from%20data.headers%20where%20url%3D%22'+encodeURIComponent(a)+"%22&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=HTMLPreview."+b+'">\x3c/script>')},submitform:function(){location.href="/?"+document.getElementById("file").value;return!1},init:function(){HTMLPreview.previewform.onsubmit=HTMLPreview.submitform;HTMLPreview.file()&&(HTMLPreview.previewform.innerHTML="<p>Loading...</p>",HTMLPreview.send(HTMLPreview.raw(),"loadHTML"))}};
|
File diff suppressed because one or more lines are too long
@ -1,43 +0,0 @@
|
||||
<?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.
|
||||
-->
|
||||
|
||||
<project name="create-connectedcup-capps" default="zip" basedir=".">
|
||||
|
||||
<property name="project-name" value="${ant.project.name}"/>
|
||||
<property name="target-dir" value="target/carbonapps"/>
|
||||
<property name="src-dir" value="src/main/resources/carbonapps"/>
|
||||
|
||||
<property name="ConnectedCup_dir" value="connected_cup"/>
|
||||
<property name="CoffeeLevel_Sensor_dir" value="coffee_level"/>
|
||||
|
||||
<target name="clean">
|
||||
<delete dir="${target-dir}" />
|
||||
</target>
|
||||
|
||||
<target name="zip" depends="clean">
|
||||
<mkdir dir="${target-dir}"/>
|
||||
<zip destfile="${target-dir}/${ConnectedCup_dir}.car">
|
||||
<zipfileset dir="${src-dir}/${ConnectedCup_dir}"/>
|
||||
</zip>
|
||||
<zip destfile="${target-dir}/${CoffeeLevel_Sensor_dir}.car">
|
||||
<zipfileset dir="${src-dir}/${CoffeeLevel_Sensor_dir}"/>
|
||||
</zip>
|
||||
</target>
|
||||
|
||||
</project>
|
@ -1,93 +0,0 @@
|
||||
<?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.
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
|
||||
<parent>
|
||||
<groupId>org.coffeeking</groupId>
|
||||
<artifactId>device-mgt-iot-connectedcup</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>org.coffeeking.connectedcup.analytics</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<name>WSO2 IoTS(Device Types) - Connected Cup Analytics capp</name>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-clean-plugin</artifactId>
|
||||
<version>2.4.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>auto-clean</id>
|
||||
<phase>initialize</phase>
|
||||
<goals>
|
||||
<goal>clean</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-antrun-plugin</artifactId>
|
||||
<version>1.7</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>process-resources</phase>
|
||||
<configuration>
|
||||
<target>
|
||||
<ant antfile="build.xml" target="zip"/>
|
||||
</target>
|
||||
</configuration>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>2.5.5</version>
|
||||
<configuration>
|
||||
<finalName>${project.artifactId}-${carbon.device.mgt.version}</finalName>
|
||||
<appendAssemblyId>false</appendAssemblyId>
|
||||
<descriptors>
|
||||
<descriptor>src/assembly/src.xml</descriptor>
|
||||
</descriptors>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>create-archive</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
@ -1,36 +0,0 @@
|
||||
<!--
|
||||
~ Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
~
|
||||
~ WSO2 Inc. licenses this file to you under the Apache License,
|
||||
~ Version 2.0 (the "License"); you may not use this file except
|
||||
~ in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing,
|
||||
~ software distributed under the License is distributed on an
|
||||
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
~ KIND, either express or implied. See the License for the
|
||||
~ specific language governing permissions and limitations
|
||||
~ under the License.
|
||||
-->
|
||||
|
||||
<assembly
|
||||
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
|
||||
<id>src</id>
|
||||
<formats>
|
||||
<format>zip</format>
|
||||
</formats>
|
||||
<includeBaseDirectory>false</includeBaseDirectory>
|
||||
<baseDirectory>${basedir}/src</baseDirectory>
|
||||
<fileSets>
|
||||
<fileSet>
|
||||
<directory>${basedir}/target/carbonapps</directory>
|
||||
<outputDirectory>/</outputDirectory>
|
||||
<useDefaultExcludes>true</useDefaultExcludes>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
</assembly>
|
@ -1,33 +0,0 @@
|
||||
<?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.
|
||||
-->
|
||||
|
||||
<artifacts>
|
||||
<artifact name="coffee_level" version="1.0.0" type="carbon/application">
|
||||
<dependency artifact="coffee_level_stream" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/>
|
||||
<dependency artifact="coffee_level_store" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/>
|
||||
<dependency artifact="coffee_level_receiver" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/>
|
||||
<dependency artifact="coffee_level_script" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/>
|
||||
<dependency artifact="coffee_level_publisher" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/>
|
||||
<dependency artifact="temperature_level_stream" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/>
|
||||
<dependency artifact="temperature_level_store" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/>
|
||||
<dependency artifact="temperature_level_receiver" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/>
|
||||
<dependency artifact="temperature_level_script" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/>
|
||||
<dependency artifact="temperature_level_publisher" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/>
|
||||
</artifact>
|
||||
</artifacts>
|
@ -1,22 +0,0 @@
|
||||
<?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.
|
||||
-->
|
||||
|
||||
<artifact name="coffee_level_publisher" version="1.0.0" type="event/publisher" serverRole="DataAnalyticsServer">
|
||||
<file>coffee_level_publisher.xml</file>
|
||||
</artifact>
|
@ -1,25 +0,0 @@
|
||||
<?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.
|
||||
-->
|
||||
|
||||
<eventPublisher name="coffee_level_publisher" statistics="disable" trace="disable" xmlns="http://wso2.org/carbon/eventpublisher">
|
||||
<from streamName="org.wso2.iot.devices.coffeelevel" version="1.0.0"/>
|
||||
<mapping customMapping="disable" type="wso2event"/>
|
||||
<to eventAdapterType="secured-websocket"/>
|
||||
</eventPublisher>
|
||||
|
@ -1,22 +0,0 @@
|
||||
<?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.
|
||||
-->
|
||||
|
||||
<artifact name="coffee_level_receiver" version="1.0.0" type="event/receiver" serverRole="DataAnalyticsServer">
|
||||
<file>coffee_level_receiver.xml</file>
|
||||
</artifact>
|
@ -1,27 +0,0 @@
|
||||
<?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.
|
||||
-->
|
||||
|
||||
<eventReceiver name="coffee_level_receiver" statistics="disable" trace="disable"
|
||||
xmlns="http://wso2.org/carbon/eventreceiver">
|
||||
<from eventAdapterType="wso2event">
|
||||
<property name="events.duplicated.in.cluster">false</property>
|
||||
</from>
|
||||
<mapping customMapping="disable" type="wso2event"/>
|
||||
<to streamName="org.wso2.iot.devices.coffeelevel" version="1.0.0"/>
|
||||
</eventReceiver>
|
@ -1,22 +0,0 @@
|
||||
<?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.
|
||||
-->
|
||||
|
||||
<artifact name="coffee_level_script" version="1.0.0" type="analytics/spark" serverRole="DataAnalyticsServer">
|
||||
<file>coffee_level_script.xml</file>
|
||||
</artifact>
|
@ -1,37 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<Analytics>
|
||||
<Name>coffee_level_script</Name>
|
||||
<Script>
|
||||
CREATE TEMPORARY TABLE DeviceCoffeeLevelData
|
||||
USING CarbonAnalytics OPTIONS(tableName "ORG_WSO2_IOT_DEVICES_COFFEELEVEL");
|
||||
|
||||
CREATE TEMPORARY TABLE DeviceCoffeeLevelSummaryData
|
||||
USING CarbonAnalytics OPTIONS (tableName "DEVICE_COFFEELEVEL_SUMMARY",
|
||||
schema "coffeelevel FLOAT, deviceType STRING -i, deviceId STRING -i, owner STRING -i, time LONG -i",
|
||||
primaryKeys "deviceType, deviceId, owner, time");
|
||||
|
||||
insert into table DeviceCoffeeLevelSummaryData
|
||||
select coffeelevel, meta_deviceType as deviceType, meta_deviceId as deviceId, meta_owner as owner, cast(meta_time/1000 as BIGINT)as time
|
||||
from DeviceCoffeeLevelData
|
||||
group by coffeelevel, meta_deviceType, meta_deviceId, meta_owner, cast(meta_time/1000 as BIGINT);
|
||||
</Script>
|
||||
<CronExpression>0 0/3 * * * ?</CronExpression>
|
||||
</Analytics>
|
@ -1,22 +0,0 @@
|
||||
<?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.
|
||||
-->
|
||||
|
||||
<artifact name="coffee_level_store" version="1.0.0" type="analytics/eventstore" serverRole="DataAnalyticsServer">
|
||||
<file>org_wso2_iot_devices_coffeelevel.xml</file>
|
||||
</artifact>
|
@ -1,62 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<EventStoreConfiguration>
|
||||
<Source>
|
||||
<StreamId>org.wso2.iot.devices.coffeelevel:1.0.0</StreamId>
|
||||
</Source>
|
||||
<RecordStoreName>EVENT_STORE</RecordStoreName>
|
||||
<TableSchema>
|
||||
<ColumnDefinition>
|
||||
<Name>meta_owner</Name>
|
||||
<EnableIndexing>true</EnableIndexing>
|
||||
<IsPrimaryKey>true</IsPrimaryKey>
|
||||
<EnableScoreParam>false</EnableScoreParam>
|
||||
<Type>STRING</Type>
|
||||
</ColumnDefinition>
|
||||
<ColumnDefinition>
|
||||
<Name>meta_deviceType</Name>
|
||||
<EnableIndexing>true</EnableIndexing>
|
||||
<IsPrimaryKey>true</IsPrimaryKey>
|
||||
<EnableScoreParam>false</EnableScoreParam>
|
||||
<Type>STRING</Type>
|
||||
</ColumnDefinition>
|
||||
<ColumnDefinition>
|
||||
<Name>meta_deviceId</Name>
|
||||
<EnableIndexing>true</EnableIndexing>
|
||||
<IsPrimaryKey>true</IsPrimaryKey>
|
||||
<EnableScoreParam>false</EnableScoreParam>
|
||||
<Type>STRING</Type>
|
||||
</ColumnDefinition>
|
||||
<ColumnDefinition>
|
||||
<Name>meta_time</Name>
|
||||
<EnableIndexing>true</EnableIndexing>
|
||||
<IsPrimaryKey>true</IsPrimaryKey>
|
||||
<EnableScoreParam>false</EnableScoreParam>
|
||||
<Type>LONG</Type>
|
||||
</ColumnDefinition>
|
||||
<ColumnDefinition>
|
||||
<Name>coffeelevel</Name>
|
||||
<EnableIndexing>false</EnableIndexing>
|
||||
<IsPrimaryKey>false</IsPrimaryKey>
|
||||
<EnableScoreParam>false</EnableScoreParam>
|
||||
<Type>FLOAT</Type>
|
||||
</ColumnDefinition>
|
||||
</TableSchema>
|
||||
</EventStoreConfiguration>
|
@ -1,23 +0,0 @@
|
||||
<?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.
|
||||
-->
|
||||
|
||||
<artifact name="coffee_level_stream" version="1.0.0" type="event/stream" serverRole="DataAnalyticsServer">
|
||||
<file>org.wso2.iot.devices.coffeelevel_1.0.0.json</file>
|
||||
</artifact>
|
||||
|
@ -1,17 +0,0 @@
|
||||
{
|
||||
"name": "org.wso2.iot.devices.coffeelevel",
|
||||
"version": "1.0.0",
|
||||
"nickName": "CoffeeLevel",
|
||||
"description": "Coffee Level data received from the Device",
|
||||
"metaData": [
|
||||
{"name":"owner","type":"STRING"},
|
||||
{"name":"deviceType","type":"STRING"},
|
||||
{"name":"deviceId","type":"STRING"},
|
||||
{"name":"time","type":"LONG"}
|
||||
],
|
||||
"payloadData": [
|
||||
{
|
||||
"name": "coffeelevel","type": "FLOAT"
|
||||
}
|
||||
]
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
<?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.
|
||||
-->
|
||||
|
||||
<artifact name="temperature_level_publisher" version="1.0.0" type="event/publisher" serverRole="DataAnalyticsServer">
|
||||
<file>temperature_level_publisher.xml</file>
|
||||
</artifact>
|
@ -1,25 +0,0 @@
|
||||
<?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.
|
||||
-->
|
||||
|
||||
<eventPublisher name="temperature_level_publisher" statistics="disable" trace="disable" xmlns="http://wso2.org/carbon/eventpublisher">
|
||||
<from streamName="org.wso2.iot.devices.temperature" version="1.0.0"/>
|
||||
<mapping customMapping="disable" type="wso2event"/>
|
||||
<to eventAdapterType="secured-websocket"/>
|
||||
</eventPublisher>
|
||||
|
@ -1,22 +0,0 @@
|
||||
<?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.
|
||||
-->
|
||||
|
||||
<artifact name="temperature_level_receiver" version="1.0.0" type="event/receiver" serverRole="DataAnalyticsServer">
|
||||
<file>temperature_level_receiver.xml</file>
|
||||
</artifact>
|
@ -1,27 +0,0 @@
|
||||
<?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.
|
||||
-->
|
||||
|
||||
<eventReceiver name="temperature_level_receiver" statistics="disable" trace="disable"
|
||||
xmlns="http://wso2.org/carbon/eventreceiver">
|
||||
<from eventAdapterType="wso2event">
|
||||
<property name="events.duplicated.in.cluster">false</property>
|
||||
</from>
|
||||
<mapping customMapping="disable" type="wso2event"/>
|
||||
<to streamName="org.wso2.iot.devices.temperature" version="1.0.0"/>
|
||||
</eventReceiver>
|
@ -1,22 +0,0 @@
|
||||
<?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.
|
||||
-->
|
||||
|
||||
<artifact name="temperature_level_script" version="1.0.0" type="analytics/spark" serverRole="DataAnalyticsServer">
|
||||
<file>temperature_level_script.xml</file>
|
||||
</artifact>
|
@ -1,35 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<Analytics>
|
||||
<Name>temperature_level_script</Name>
|
||||
<Script>
|
||||
CREATE TEMPORARY TABLE DeviceTemperatureLevelData
|
||||
USING CarbonAnalytics OPTIONS(tableName "ORG_WSO2_IOT_DEVICES_TEMPERATURE");
|
||||
|
||||
CREATE TEMPORARY TABLE DeviceTemperatureLevelSummaryData
|
||||
USING CarbonAnalytics OPTIONS (tableName "DEVICE_TEMPERATURE_SUMMARY", schema "temperature FLOAT, deviceType STRING -i, deviceId STRING -i, owner STRING -i, time LONG -i",primaryKeys "deviceType, deviceId, owner, time");
|
||||
|
||||
insert into table DeviceTemperatureLevelSummaryData select temperature, meta_deviceType as deviceType,
|
||||
meta_deviceId as deviceId, meta_owner as owner, cast(meta_time/1000 as BIGINT)as time
|
||||
from DeviceTemperatureLevelData
|
||||
group by temperature, meta_deviceType, meta_deviceId, meta_owner, cast(meta_time/1000 as BIGINT);
|
||||
</Script>
|
||||
<CronExpression>0 0/3 * * * ?</CronExpression>
|
||||
</Analytics>
|
@ -1,22 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright (c) 2017, 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.
|
||||
-->
|
||||
|
||||
<artifact name="temperature_level_store" version="1.0.0" type="analytics/eventstore" serverRole="DataAnalyticsServer">
|
||||
<file>org_wso2_iot_devices_temperature.xml</file>
|
||||
</artifact>
|
@ -1,63 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<!--
|
||||
~ Copyright (c) 2017, 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.
|
||||
-->
|
||||
|
||||
<EventStoreConfiguration>
|
||||
<TableSchema>
|
||||
<ColumnDefinition>
|
||||
<Name>meta_owner</Name>
|
||||
<EnableIndexing>true</EnableIndexing>
|
||||
<IsPrimaryKey>true</IsPrimaryKey>
|
||||
<EnableScoreParam>false</EnableScoreParam>
|
||||
<Type>STRING</Type>
|
||||
</ColumnDefinition>
|
||||
<ColumnDefinition>
|
||||
<Name>meta_deviceType</Name>
|
||||
<EnableIndexing>true</EnableIndexing>
|
||||
<IsPrimaryKey>true</IsPrimaryKey>
|
||||
<EnableScoreParam>false</EnableScoreParam>
|
||||
<Type>STRING</Type>
|
||||
</ColumnDefinition>
|
||||
<ColumnDefinition>
|
||||
<Name>meta_deviceId</Name>
|
||||
<EnableIndexing>true</EnableIndexing>
|
||||
<IsPrimaryKey>true</IsPrimaryKey>
|
||||
<EnableScoreParam>false</EnableScoreParam>
|
||||
<Type>STRING</Type>
|
||||
</ColumnDefinition>
|
||||
<ColumnDefinition>
|
||||
<Name>meta_time</Name>
|
||||
<EnableIndexing>true</EnableIndexing>
|
||||
<IsPrimaryKey>true</IsPrimaryKey>
|
||||
<EnableScoreParam>false</EnableScoreParam>
|
||||
<Type>LONG</Type>
|
||||
</ColumnDefinition>
|
||||
<ColumnDefinition>
|
||||
<Name>temperature</Name>
|
||||
<EnableIndexing>false</EnableIndexing>
|
||||
<IsPrimaryKey>false</IsPrimaryKey>
|
||||
<EnableScoreParam>false</EnableScoreParam>
|
||||
<Type>FLOAT</Type>
|
||||
</ColumnDefinition>
|
||||
</TableSchema>
|
||||
<Source>
|
||||
<StreamId>org.wso2.iot.devices.temperature:1.0.0</StreamId>
|
||||
</Source>
|
||||
<!--<MergeSchema>false</MergeSchema>-->
|
||||
<RecordStoreName>EVENT_STORE</RecordStoreName>
|
||||
</EventStoreConfiguration>
|
@ -1,23 +0,0 @@
|
||||
<?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.
|
||||
-->
|
||||
|
||||
<artifact name="temperature_level_stream" version="1.0.0" type="event/stream" serverRole="DataAnalyticsServer">
|
||||
<file>org.wso2.iot.devices.temperature_1.0.0.json</file>
|
||||
</artifact>
|
||||
|
@ -1,17 +0,0 @@
|
||||
{
|
||||
"name": "org.wso2.iot.devices.temperature",
|
||||
"version": "1.0.0",
|
||||
"nickName": "TemperatureLevel",
|
||||
"description": "Temperature Level data received from the Device",
|
||||
"metaData": [
|
||||
{"name":"owner","type":"STRING"},
|
||||
{"name":"deviceType","type":"STRING"},
|
||||
{"name":"deviceId","type":"STRING"},
|
||||
{"name":"time","type":"LONG"}
|
||||
],
|
||||
"payloadData": [
|
||||
{
|
||||
"name": "temperature","type": "FLOAT"
|
||||
}
|
||||
]
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
<?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.
|
||||
-->
|
||||
|
||||
<artifacts>
|
||||
<artifact name="connected_cup" version="1.0.0" type="carbon/application">
|
||||
<dependency artifact="connected_cup_stream" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/>
|
||||
<dependency artifact="connected_cup_receiver" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/>
|
||||
<dependency artifact="connected_cup_publisher" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/>
|
||||
<dependency artifact="connected_cup_execution" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/>
|
||||
</artifact>
|
||||
</artifacts>
|
@ -1,23 +0,0 @@
|
||||
<?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.
|
||||
-->
|
||||
|
||||
<artifact name="connected_cup_execution" version="1.0.0" type="event/execution-plan" serverRole="DataAnalyticsServer">
|
||||
<file>connected_cup_execution.siddhiql</file>
|
||||
</artifact>
|
||||
|
@ -1,24 +0,0 @@
|
||||
/* Enter a unique ExecutionPlan */
|
||||
@Plan:name('connected_cup_execution')
|
||||
|
||||
/* Enter a unique description for ExecutionPlan */
|
||||
-- @Plan:description('connected_cup_execution')
|
||||
|
||||
/* define streams/tables and write queries here ... */
|
||||
|
||||
@Export('org.wso2.iot.devices.temperature:1.0.0')
|
||||
define stream temperature (meta_owner string, meta_deviceType string, meta_deviceId string, meta_time long, temperature float);
|
||||
|
||||
@Export('org.wso2.iot.devices.coffeelevel:1.0.0')
|
||||
define stream coffeelevel (meta_owner string, meta_deviceType string, meta_deviceId string, meta_time long, coffeelevel float);
|
||||
|
||||
@Import('org.wso2.iot.connectedcup:1.0.0')
|
||||
define stream connectedcup (meta_owner string, meta_deviceId string, meta_type string, meta_timestamp long, temperature float, coffeelevel float);
|
||||
|
||||
from connectedcup[meta_type == 'coffeelevel']
|
||||
select meta_owner, 'connectedcup' as meta_deviceType, meta_deviceId, meta_timestamp as meta_time, coffeelevel
|
||||
insert into coffeelevel;
|
||||
|
||||
from connectedcup[meta_type == 'temperature']
|
||||
select meta_owner, 'connectedcup' as meta_deviceType, meta_deviceId, meta_timestamp as meta_time, temperature
|
||||
insert into temperature;
|
@ -1,22 +0,0 @@
|
||||
<?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.
|
||||
-->
|
||||
|
||||
<artifact name="connected_cup_publisher" version="1.0.0" type="event/publisher" serverRole="DataAnalyticsServer">
|
||||
<file>connected_cup_publisher.xml</file>
|
||||
</artifact>
|
@ -1,25 +0,0 @@
|
||||
<?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.
|
||||
-->
|
||||
|
||||
<eventPublisher name="connected_cup_publisher" statistics="disable" trace="disable" xmlns="http://wso2.org/carbon/eventpublisher">
|
||||
<from streamName="org.wso2.iot.connectedcup" version="1.0.0"/>
|
||||
<mapping customMapping="disable" type="wso2event"/>
|
||||
<to eventAdapterType="secured-websocket"/>
|
||||
</eventPublisher>
|
||||
|
@ -1,22 +0,0 @@
|
||||
<?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.
|
||||
-->
|
||||
|
||||
<artifact name="connected_cup_receiver" version="1.0.0" type="event/receiver" serverRole="DataAnalyticsServer">
|
||||
<file>connected_cup_receiver.xml</file>
|
||||
</artifact>
|
@ -1,29 +0,0 @@
|
||||
<?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.
|
||||
-->
|
||||
|
||||
<eventReceiver name="connected_cup_receiver" statistics="disable" trace="disable" xmlns="http://wso2.org/carbon/eventreceiver">
|
||||
<from eventAdapterType="oauth-mqtt">
|
||||
<property name="topic">carbon.super/connectedcup/#</property>
|
||||
<property name="contentValidator">deviceid-topic-content-validator</property>
|
||||
<property name="contentTransformer">default</property>
|
||||
<property name="cleanSession">true</property>
|
||||
</from>
|
||||
<mapping customMapping="disable" type="json"/>
|
||||
<to streamName="org.wso2.iot.connectedcup" version="1.0.0"/>
|
||||
</eventReceiver>
|
@ -1,23 +0,0 @@
|
||||
<?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.
|
||||
-->
|
||||
|
||||
<artifact name="connected_cup_stream" version="1.0.0" type="event/stream" serverRole="DataAnalyticsServer">
|
||||
<file>org.wso2.iot.connectedcup_1.0.0.json</file>
|
||||
</artifact>
|
||||
|
@ -1,16 +0,0 @@
|
||||
{
|
||||
"name": "org.wso2.iot.connectedcup",
|
||||
"version": "1.0.0",
|
||||
"nickName": "connectedcup",
|
||||
"description": "This hold the device type stream of connectedcup",
|
||||
"metaData": [
|
||||
{"name": "owner", "type": "STRING"},
|
||||
{"name": "deviceId", "type": "STRING"},
|
||||
{"name": "type", "type": "STRING"},
|
||||
{"name": "timestamp", "type": "LONG"}
|
||||
],
|
||||
"payloadData": [
|
||||
{"name": "temperature", "type": "FLOAT"},
|
||||
{"name": "coffeelevel", "type": "FLOAT"}
|
||||
]
|
||||
}
|
@ -1,162 +0,0 @@
|
||||
<?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.
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>device-mgt-iot-connectedcup</artifactId>
|
||||
<groupId>org.coffeeking</groupId>
|
||||
<version>1.0.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>org.coffeeking.connectedcup.api</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<packaging>war</packaging>
|
||||
<name>WSO2 IoTS(Device Types) - Connected Cup API</name>
|
||||
<description>WSO2 IoTS(Device Types) - Connected Cup API</description>
|
||||
<url>http://wso2.org</url>
|
||||
|
||||
<dependencies>
|
||||
<!-- CDM -->
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>org.wso2.carbon.device.mgt.common</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>org.wso2.carbon.device.mgt.core</artifactId>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.apache.axis2.wso2</groupId>
|
||||
<artifactId>axis2-client</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!--CXF -->
|
||||
<dependency>
|
||||
<groupId>org.apache.cxf</groupId>
|
||||
<artifactId>cxf-rt-frontend-jaxws</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cxf</groupId>
|
||||
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cxf</groupId>
|
||||
<artifactId>cxf-rt-transports-http</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!--MQTT -->
|
||||
<dependency>
|
||||
<groupId>org.eclipse.paho</groupId>
|
||||
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!--IOT -->
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpasyncclient</artifactId>
|
||||
<version>4.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.coffeeking</groupId>
|
||||
<artifactId>org.coffeeking.connectedcup.plugin</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!--JAX-RS -->
|
||||
<dependency>
|
||||
<groupId>org.codehaus.jackson</groupId>
|
||||
<artifactId>jackson-core-asl</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.jackson</groupId>
|
||||
<artifactId>jackson-jaxrs</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax</groupId>
|
||||
<artifactId>javaee-web-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.ws.rs</groupId>
|
||||
<artifactId>jsr311-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>org.wso2.carbon.device.mgt.analytics.data.publisher</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>org.wso2.carbon.apimgt.annotations</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>org.wso2.carbon.apimgt.webapp.publisher</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.analytics</groupId>
|
||||
<artifactId>org.wso2.carbon.analytics.api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>org.wso2.carbon.device.mgt.extensions</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<sourceDirectory>${basedir}/src/main/java</sourceDirectory>
|
||||
<plugins>
|
||||
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
<version>2.3.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<configuration>
|
||||
<warName>connectedcup</warName>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
@ -1,127 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.coffeeking.api;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.Extension;
|
||||
import io.swagger.annotations.ExtensionProperty;
|
||||
import io.swagger.annotations.Info;
|
||||
import io.swagger.annotations.SwaggerDefinition;
|
||||
import io.swagger.annotations.Tag;
|
||||
import org.wso2.carbon.apimgt.annotations.api.Scope;
|
||||
import org.wso2.carbon.apimgt.annotations.api.Scopes;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
|
||||
@SwaggerDefinition(
|
||||
info = @Info(
|
||||
version = "1.0.0",
|
||||
title = "",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = "name", value = "connectedcup"),
|
||||
@ExtensionProperty(name = "context", value = "/connectedcup"),
|
||||
})
|
||||
}
|
||||
),
|
||||
tags = {
|
||||
@Tag(name = "connectedcup,device_management", description = "")
|
||||
}
|
||||
)
|
||||
@Scopes(
|
||||
scopes = {
|
||||
@Scope(
|
||||
name = "Enroll device",
|
||||
description = "",
|
||||
key = "perm:connectedcup:enroll",
|
||||
permissions = {"/device-mgt/devices/enroll/connectedcup"}
|
||||
)
|
||||
}
|
||||
)
|
||||
public interface ConnectedCupService {
|
||||
|
||||
String SCOPE = "scope";
|
||||
|
||||
@Path("device/ordercoffee")
|
||||
@POST
|
||||
@ApiOperation(
|
||||
consumes = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "POST",
|
||||
value = "Order Coffee",
|
||||
notes = "",
|
||||
response = Response.class,
|
||||
tags = "connectedcup",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = SCOPE, value = "perm:connectedcup:enroll")
|
||||
})
|
||||
}
|
||||
)
|
||||
Response orderCoffee(@QueryParam("deviceId") String deviceId);
|
||||
|
||||
/**
|
||||
* Retrieve Sensor data for the device type
|
||||
*/
|
||||
@Path("stats/{deviceId}/sensors/{sensorName}")
|
||||
@GET
|
||||
@Consumes("application/json")
|
||||
@Produces("application/json")
|
||||
@ApiOperation(
|
||||
consumes = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "GET",
|
||||
value = "Retrieve Sensor data for the device type",
|
||||
notes = "",
|
||||
response = Response.class,
|
||||
tags = "connectedcup",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = SCOPE, value = "perm:connectedcup:enroll")
|
||||
})
|
||||
}
|
||||
)
|
||||
Response getDeviceStats(@PathParam("deviceId") String deviceId, @PathParam("sensorName") String sensor,
|
||||
@QueryParam("from") long from, @QueryParam("to") long to);
|
||||
|
||||
@Path("device/register")
|
||||
@POST
|
||||
@ApiOperation(
|
||||
consumes = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "POST",
|
||||
value = "Enroll Cup",
|
||||
notes = "",
|
||||
response = Response.class,
|
||||
tags = "connectedcup",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = SCOPE, value = "perm:connectedcup:enroll")
|
||||
})
|
||||
}
|
||||
)
|
||||
boolean register(@QueryParam("name") String name);
|
||||
|
||||
}
|
@ -1,162 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.coffeeking.api;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.coffeeking.api.util.APIUtil;
|
||||
import org.coffeeking.api.util.SensorRecord;
|
||||
import org.coffeeking.connectedcup.plugin.constants.ConnectedCupConstants;
|
||||
import org.wso2.carbon.analytics.dataservice.commons.SortByField;
|
||||
import org.wso2.carbon.analytics.dataservice.commons.SortType;
|
||||
import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException;
|
||||
import org.wso2.carbon.device.mgt.common.Device;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
||||
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException;
|
||||
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ConnectedCupServiceImpl implements ConnectedCupService {
|
||||
|
||||
private static Log log = LogFactory.getLog(ConnectedCupServiceImpl.class);
|
||||
|
||||
private static String shortUUID() {
|
||||
UUID uuid = UUID.randomUUID();
|
||||
long l = ByteBuffer.wrap(uuid.toString().getBytes(StandardCharsets.UTF_8)).getLong();
|
||||
return Long.toString(l, Character.MAX_RADIX);
|
||||
}
|
||||
|
||||
@Path("device/ordercoffee")
|
||||
@POST
|
||||
public Response orderCoffee(@QueryParam("deviceId") String deviceId) {
|
||||
try {
|
||||
if (!APIUtil.getDeviceAccessAuthorizationService()
|
||||
.isUserAuthorized(new DeviceIdentifier(deviceId, ConnectedCupConstants.DEVICE_TYPE),
|
||||
DeviceGroupConstants.Permissions.DEFAULT_OPERATOR_PERMISSIONS)) {
|
||||
return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build();
|
||||
}
|
||||
log.info("Coffee ordered....!");
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Sending request to read liquid level value of device [" + deviceId + "] via MQTT");
|
||||
}
|
||||
return Response.ok().entity("Coffee ordered.").build();
|
||||
} catch (DeviceAccessAuthorizationException e) {
|
||||
log.error(e.getErrorMessage(), e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
|
||||
}
|
||||
}
|
||||
|
||||
@Path("stats/{deviceId}/sensors/{sensorName}")
|
||||
@GET
|
||||
@Consumes("application/json")
|
||||
@Produces("application/json")
|
||||
public Response getDeviceStats(@PathParam("deviceId") String deviceId, @PathParam("sensorName") String sensor,
|
||||
@QueryParam("from") long from, @QueryParam("to") long to) {
|
||||
String fromDate = String.valueOf(from);
|
||||
String toDate = String.valueOf(to);
|
||||
String query = " deviceId:" + deviceId + " AND deviceType:" +
|
||||
ConnectedCupConstants.DEVICE_TYPE + " AND time : [" + fromDate + " TO " + toDate + "]";
|
||||
String sensorTableName = getSensorEventTableName(sensor);
|
||||
|
||||
try {
|
||||
if (!APIUtil.getDeviceAccessAuthorizationService()
|
||||
.isUserAuthorized(new DeviceIdentifier(deviceId, ConnectedCupConstants.DEVICE_TYPE),
|
||||
DeviceGroupConstants.Permissions.DEFAULT_STATS_MONITOR_PERMISSIONS)) {
|
||||
return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build();
|
||||
}
|
||||
List<SensorRecord> sensorDatas;
|
||||
List<SortByField> sortByFields = new ArrayList<>();
|
||||
SortByField sortByField = new SortByField("time", SortType.ASC);
|
||||
sortByFields.add(sortByField);
|
||||
sensorDatas = APIUtil.getAllEventsForDevice(sensorTableName, query, sortByFields);
|
||||
return Response.ok().entity(sensorDatas).build();
|
||||
} catch (AnalyticsException e) {
|
||||
String errorMsg = "Error on retrieving stats on table " + sensorTableName + " with query " + query;
|
||||
log.error(errorMsg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).entity(errorMsg).build();
|
||||
} catch (DeviceAccessAuthorizationException e) {
|
||||
log.error(e.getErrorMessage(), e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get the event table from the sensor name.
|
||||
*/
|
||||
private String getSensorEventTableName(String sensorName) {
|
||||
String sensorEventTableName;
|
||||
switch (sensorName) {
|
||||
case "temperature":
|
||||
sensorEventTableName = "DEVICE_TEMPERATURE_SUMMARY";
|
||||
break;
|
||||
case "coffeelevel":
|
||||
sensorEventTableName = "DEVICE_COFFEELEVEL_SUMMARY";
|
||||
break;
|
||||
default:
|
||||
sensorEventTableName = "";
|
||||
}
|
||||
return sensorEventTableName;
|
||||
}
|
||||
|
||||
@Path("device/register")
|
||||
@POST
|
||||
public boolean register(@QueryParam("name") String name) {
|
||||
try {
|
||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||
String deviceId = shortUUID();
|
||||
deviceIdentifier.setId(deviceId);
|
||||
deviceIdentifier.setType(ConnectedCupConstants.DEVICE_TYPE);
|
||||
if (APIUtil.getDeviceManagementService().isEnrolled(deviceIdentifier)) {
|
||||
return false;
|
||||
}
|
||||
Device device = new Device();
|
||||
device.setDeviceIdentifier(deviceId);
|
||||
EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
|
||||
enrolmentInfo.setDateOfEnrolment(new Date().getTime());
|
||||
enrolmentInfo.setDateOfLastUpdate(new Date().getTime());
|
||||
enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE);
|
||||
enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD);
|
||||
device.setName(name);
|
||||
device.setType(ConnectedCupConstants.DEVICE_TYPE);
|
||||
enrolmentInfo.setOwner(APIUtil.getAuthenticatedUser());
|
||||
device.setEnrolmentInfo(enrolmentInfo);
|
||||
return APIUtil.getDeviceManagementService().enrollDevice(device);
|
||||
} catch (DeviceManagementException e) {
|
||||
log.error("Failed to enroll device with device name :" + name, e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
/*
|
||||
* 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.coffeeking.api.exception;
|
||||
|
||||
public class ConnectedCupException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 118512086957330189L;
|
||||
|
||||
public ConnectedCupException(String errorMessage) {
|
||||
super(errorMessage);
|
||||
}
|
||||
|
||||
public ConnectedCupException(String errorMessage, Throwable throwable) {
|
||||
super(errorMessage, throwable);
|
||||
}
|
||||
|
||||
}
|
@ -1,156 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.coffeeking.api.util;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.analytics.api.AnalyticsDataAPI;
|
||||
import org.wso2.carbon.analytics.api.AnalyticsDataAPIUtil;
|
||||
import org.wso2.carbon.analytics.dataservice.commons.AnalyticsDataResponse;
|
||||
import org.wso2.carbon.analytics.dataservice.commons.SearchResultEntry;
|
||||
import org.wso2.carbon.analytics.dataservice.commons.SortByField;
|
||||
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;
|
||||
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService;
|
||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* This class provides utility functions used by REST-API.
|
||||
*/
|
||||
public class APIUtil {
|
||||
|
||||
private static Log log = LogFactory.getLog(APIUtil.class);
|
||||
|
||||
public static String getAuthenticatedUser() {
|
||||
PrivilegedCarbonContext threadLocalCarbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||
String username = threadLocalCarbonContext.getUsername();
|
||||
String tenantDomain = threadLocalCarbonContext.getTenantDomain();
|
||||
if (username.endsWith(tenantDomain)) {
|
||||
return username.substring(0, username.lastIndexOf("@"));
|
||||
}
|
||||
return username;
|
||||
}
|
||||
|
||||
public static DeviceManagementProviderService getDeviceManagementService() {
|
||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||
DeviceManagementProviderService deviceManagementProviderService =
|
||||
(DeviceManagementProviderService) ctx.getOSGiService(DeviceManagementProviderService.class, null);
|
||||
if (deviceManagementProviderService == null) {
|
||||
throw new IllegalStateException("Device Management service has not initialized");
|
||||
}
|
||||
return deviceManagementProviderService;
|
||||
}
|
||||
|
||||
public static DeviceAccessAuthorizationService getDeviceAccessAuthorizationService() {
|
||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||
DeviceAccessAuthorizationService deviceAccessAuthorizationService =
|
||||
(DeviceAccessAuthorizationService) ctx.getOSGiService(DeviceAccessAuthorizationService.class, null);
|
||||
if (deviceAccessAuthorizationService == null) {
|
||||
throw new IllegalStateException("Device Authorization service has not initialized");
|
||||
}
|
||||
return deviceAccessAuthorizationService;
|
||||
}
|
||||
|
||||
public static AnalyticsDataAPI getAnalyticsDataAPI() {
|
||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||
AnalyticsDataAPI analyticsDataAPI =
|
||||
(AnalyticsDataAPI) ctx.getOSGiService(AnalyticsDataAPI.class, null);
|
||||
if (analyticsDataAPI == null) {
|
||||
throw new IllegalStateException("Analytics api service has not initialized");
|
||||
}
|
||||
return analyticsDataAPI;
|
||||
}
|
||||
|
||||
public static List<SensorRecord> getAllEventsForDevice(String tableName, String query,
|
||||
List<SortByField> sortByFields) throws AnalyticsException {
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
AnalyticsDataAPI analyticsDataAPI = getAnalyticsDataAPI();
|
||||
int eventCount = analyticsDataAPI.searchCount(tenantId, tableName, query);
|
||||
// limiting the data read from the server
|
||||
int start = 0;
|
||||
int dataCount = 100;
|
||||
if (eventCount == 0) {
|
||||
return null;
|
||||
} else if (eventCount >= dataCount){
|
||||
start = eventCount - dataCount;
|
||||
}
|
||||
|
||||
List<SearchResultEntry> resultEntries = analyticsDataAPI.search(tenantId, tableName, query, start, eventCount,
|
||||
sortByFields);
|
||||
List<String> recordIds = getRecordIds(resultEntries);
|
||||
AnalyticsDataResponse response = analyticsDataAPI.get(tenantId, tableName, 1, null, recordIds);
|
||||
Map<String, SensorRecord> sensorDatas = createSensorData(AnalyticsDataAPIUtil.listRecords(
|
||||
analyticsDataAPI, response));
|
||||
List<SensorRecord> sortedSensorData = getSortedSensorData(sensorDatas, resultEntries);
|
||||
return sortedSensorData;
|
||||
}
|
||||
|
||||
|
||||
private static List<String> getRecordIds(List<SearchResultEntry> searchResults) {
|
||||
List<String> ids = new ArrayList<>();
|
||||
for (SearchResultEntry searchResult : searchResults) {
|
||||
ids.add(searchResult.getId());
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
public static List<SensorRecord> getSortedSensorData(Map<String, SensorRecord> sensorDatas,
|
||||
List<SearchResultEntry> searchResults) {
|
||||
List<SensorRecord> sortedRecords = new ArrayList<>();
|
||||
for (SearchResultEntry searchResultEntry : searchResults) {
|
||||
sortedRecords.add(sensorDatas.get(searchResultEntry.getId()));
|
||||
}
|
||||
return sortedRecords;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the SensorDatas from records.
|
||||
*
|
||||
* @param records the records
|
||||
* @return the Map of SensorRecord <id, SensorRecord>
|
||||
*/
|
||||
public static Map<String, SensorRecord> createSensorData(List<Record> records) {
|
||||
Map<String, SensorRecord> sensorDatas = new HashMap<>();
|
||||
for (Record record : records) {
|
||||
SensorRecord sensorData = createSensorData(record);
|
||||
sensorDatas.put(sensorData.getId(), sensorData);
|
||||
}
|
||||
return sensorDatas;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a SensorRecord object out of a Record object
|
||||
*
|
||||
* @param record the record object
|
||||
* @return SensorRecord object
|
||||
*/
|
||||
public static SensorRecord createSensorData(Record record) {
|
||||
SensorRecord recordBean = new SensorRecord();
|
||||
recordBean.setId(record.getId());
|
||||
recordBean.setValues(record.getValues());
|
||||
return recordBean;
|
||||
}
|
||||
}
|
@ -1,89 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.coffeeking.api.util;
|
||||
|
||||
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@XmlRootElement
|
||||
/**
|
||||
* This stores sensor event data for android sense.
|
||||
*/
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class SensorRecord {
|
||||
|
||||
@XmlElementWrapper(required = true, name = "values")
|
||||
private Map<String, Object> values;
|
||||
|
||||
@XmlElement(required = false, name = "id")
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* Gets the values.
|
||||
*
|
||||
* @return the values
|
||||
*/
|
||||
public Map<String, Object> getValues() {
|
||||
return values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the values.
|
||||
*
|
||||
* @param values the values
|
||||
*/
|
||||
public void setValues(Map<String, Object> values) {
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the id.
|
||||
*
|
||||
* @return the id
|
||||
*/
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the id.
|
||||
*
|
||||
* @param id the new id
|
||||
*/
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
List<String> valueList = new ArrayList<String>();
|
||||
for (Map.Entry<String, Object> entry : values.entrySet()) {
|
||||
valueList.add(entry.getKey() + ":" + entry.getValue());
|
||||
}
|
||||
return valueList.toString();
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
<?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.
|
||||
-->
|
||||
|
||||
<!-- This file contains the list of permissions that are associated with URL end points
|
||||
of the web app. Each permission should contain the name, permission path ,API path
|
||||
(URL) , HTTP method and OAUTH2 authorization scope (not-required).
|
||||
When defining dynamic paths for APIs, path variables are denoted by '*' notation.
|
||||
NOTE: All the endpoints of the web app should be available in this file. Otherwise
|
||||
it will result 403 error at the runtime.
|
||||
-->
|
||||
<PermissionConfiguration>
|
||||
|
||||
<APIVersion></APIVersion>
|
||||
<!-- Device related APIs -->
|
||||
<Permission>
|
||||
<name>Register a device</name>
|
||||
<path>/device-mgt/user/devices</path>
|
||||
<url>/device/register</url>
|
||||
<method>POST</method>
|
||||
<scope>connectedcup_user</scope>
|
||||
</Permission>
|
||||
<Permission>
|
||||
<name>Order coffee cup</name>
|
||||
<path>/device-mgt/user/operation</path>
|
||||
<url>/device/ordercoffee</url>
|
||||
<method>POST</method>
|
||||
<scope>connectedcup_user</scope>
|
||||
</Permission>
|
||||
<Permission>
|
||||
<name>get device stats</name>
|
||||
<path>/device-mgt/user/stats</path>
|
||||
<url>/stats/*/sensors/*</url>
|
||||
<method>GET</method>
|
||||
<scope>connectedcup_user</scope>
|
||||
</Permission>
|
||||
</PermissionConfiguration>
|
@ -1,34 +0,0 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<!--
|
||||
This file defines class loading policy of the whole container. But this behaviour can be overridden by individual webapps by putting this file into the META-INF/ directory.
|
||||
-->
|
||||
<Classloading xmlns="http://wso2.org/projects/as/classloading">
|
||||
|
||||
<!-- Parent-first or child-first. Default behaviour is child-first.-->
|
||||
<ParentFirst>false</ParentFirst>
|
||||
|
||||
<!--
|
||||
Default environments that contains provides to all the webapps. This can be overridden by individual webapps by specifing required environments
|
||||
Tomcat environment is the default and every webapps gets it even if they didn't specify it.
|
||||
e.g. If a webapps requires CXF, they will get both Tomcat and CXF.
|
||||
-->
|
||||
<Environments>CXF,Carbon</Environments>
|
||||
</Classloading>
|
@ -1,39 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd">
|
||||
|
||||
|
||||
<jaxrs:server id="ConnectedCup" address="/">
|
||||
<jaxrs:serviceBeans>
|
||||
<bean id="ConnectedCupService"
|
||||
class="org.coffeeking.api.ConnectedCupServiceImpl">
|
||||
</bean>
|
||||
</jaxrs:serviceBeans>
|
||||
<jaxrs:providers>
|
||||
<bean class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"/>
|
||||
</jaxrs:providers>
|
||||
</jaxrs:server>
|
||||
|
||||
</beans>
|
@ -1,61 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://java.sun.com/xml/ns/javaee"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
|
||||
version="2.5">
|
||||
<display-name>ConnectedCup-Webapp</display-name>
|
||||
|
||||
<servlet>
|
||||
<servlet-name>CXFServlet</servlet-name>
|
||||
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
|
||||
<load-on-startup>1</load-on-startup>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>CXFServlet</servlet-name>
|
||||
<url-pattern>/*</url-pattern>
|
||||
</servlet-mapping>
|
||||
<context-param>
|
||||
<param-name>isAdminService</param-name>
|
||||
<param-value>false</param-value>
|
||||
</context-param>
|
||||
<context-param>
|
||||
<param-name>doAuthentication</param-name>
|
||||
<param-value>true</param-value>
|
||||
</context-param>
|
||||
<context-param>
|
||||
<param-name>isSharedWithAllTenants</param-name>
|
||||
<param-value>true</param-value>
|
||||
</context-param>
|
||||
<context-param>
|
||||
<param-name>providerTenantDomain</param-name>
|
||||
<param-value>carbon.super</param-value>
|
||||
</context-param>
|
||||
|
||||
<!--publish to apim-->
|
||||
<context-param>
|
||||
<param-name>managed-api-enabled</param-name>
|
||||
<param-value>true</param-value>
|
||||
</context-param>
|
||||
<context-param>
|
||||
<param-name>managed-api-owner</param-name>
|
||||
<param-value>admin</param-value>
|
||||
</context-param>
|
||||
|
||||
</web-app>
|
@ -1,112 +0,0 @@
|
||||
<?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.
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>device-mgt-iot-connectedcup</artifactId>
|
||||
<groupId>org.coffeeking</groupId>
|
||||
<version>1.0.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>org.coffeeking.connectedcup.plugin</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<packaging>bundle</packaging>
|
||||
<name>WSO2 IoTS(Device Types) - Connected Cup CDMF Plugin</name>
|
||||
<description>WSO2 IoTS(Device Types) - Connected Cup CDMF Plugin</description>
|
||||
<url>http://wso2.org</url>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-scr-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
<version>2.3.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-bundle-plugin</artifactId>
|
||||
<version>1.4.0</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<instructions>
|
||||
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
|
||||
<Bundle-Name>${project.artifactId}</Bundle-Name>
|
||||
<Bundle-Version>${org.coffeeking.version}</Bundle-Version>
|
||||
<Bundle-Description>IoT Server Impl Bundle</Bundle-Description>
|
||||
<Private-Package>org.coffeeking.connectedcup.plugin.internal</Private-Package>
|
||||
<Import-Package>
|
||||
org.osgi.framework,
|
||||
org.osgi.service.component,
|
||||
org.apache.commons.logging,
|
||||
javax.xml.bind.*;resolution:=optional,
|
||||
javax.naming;resolution:=optional,
|
||||
javax.sql;resolution:=optional,
|
||||
javax.xml.bind.annotation.*;resolution:=optional,
|
||||
org.wso2.carbon.device.mgt.common.*,
|
||||
org.wso2.carbon.device.mgt.common,
|
||||
org.wso2.carbon.context.*,
|
||||
org.wso2.carbon.base.*,
|
||||
javax.xml.parsers.*;resolution:=optional
|
||||
</Import-Package>
|
||||
<Export-Package>
|
||||
!org.coffeeking.connectedcup.plugin.internal,
|
||||
org.coffeeking.connectedcup.plugin.*
|
||||
</Export-Package>
|
||||
</instructions>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.osgi</groupId>
|
||||
<artifactId>org.eclipse.osgi</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.osgi</groupId>
|
||||
<artifactId>org.eclipse.osgi.services</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.logging</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>org.wso2.carbon.device.mgt.common</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.ndatasource.core</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.coffeeking.connectedcup.plugin.constants;
|
||||
|
||||
public class ConnectedCupConstants {
|
||||
|
||||
public final static String DEVICE_TYPE = "connectedcup";
|
||||
public final static String DEVICE_PLUGIN_DEVICE_NAME = "DEVICE_NAME";
|
||||
public final static String DEVICE_PLUGIN_DEVICE_ID = "CONNECTED_CUP_DEVICE_ID";
|
||||
public final static String ORDER_ON = "YES";
|
||||
public final static String ORDER_OFF = "NO";
|
||||
|
||||
public static final String URL_PREFIX = "http://";
|
||||
public static final String LEVEL_CONTEXT = "/LEVEL/";
|
||||
public static final String TEMPERATURE_CONTEXT = "/TEMPERATURE/";
|
||||
|
||||
public static final String SENSOR_TEMPERATURE = "temperature";
|
||||
public static final String SENSOR_LEVEL = "level";
|
||||
public static final String DATA_SOURCE_NAME = "jdbc/ConnectedCupDM_DB";
|
||||
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.coffeeking.connectedcup.plugin.exception;
|
||||
|
||||
public class ConnectedCupDeviceMgtPluginException extends Exception {
|
||||
|
||||
public ConnectedCupDeviceMgtPluginException(String msg, Exception nestedEx) {
|
||||
super(msg, nestedEx);
|
||||
}
|
||||
|
||||
public ConnectedCupDeviceMgtPluginException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public ConnectedCupDeviceMgtPluginException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public ConnectedCupDeviceMgtPluginException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ConnectedCupDeviceMgtPluginException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
@ -1,100 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.coffeeking.connectedcup.plugin.impl;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.Feature;
|
||||
import org.wso2.carbon.device.mgt.common.FeatureManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* This hold the feature manager implementation for Connected CUp.
|
||||
*/
|
||||
public class ConnectedCupFeatureManager implements FeatureManager{
|
||||
private static Feature feature = new Feature();
|
||||
private static final String METHOD = "method";
|
||||
private static final String URI = "uri";
|
||||
private static final String CONTENT_TYPE = "contentType";
|
||||
private static final String PATH_PARAMS = "pathParams";
|
||||
private static final String QUERY_PARAMS = "queryParams";
|
||||
private static final String FORM_PARAMS = "formParams";
|
||||
|
||||
public ConnectedCupFeatureManager() {
|
||||
|
||||
feature.setCode("ordercoffee");
|
||||
feature.setName("Order Coffee");
|
||||
feature.setDescription("Order coffee cup");
|
||||
|
||||
Map<String, Object> apiParams = new HashMap<>();
|
||||
apiParams.put(METHOD, "POST");
|
||||
apiParams.put(URI, "/connectedcup/device/ordercoffee");
|
||||
List<String> pathParams = new ArrayList<>();
|
||||
List<String> queryParams = new ArrayList<>();
|
||||
List<String> formParams = new ArrayList<>();
|
||||
apiParams.put(PATH_PARAMS, pathParams);
|
||||
queryParams.add("deviceId");
|
||||
apiParams.put(QUERY_PARAMS, queryParams);
|
||||
apiParams.put(FORM_PARAMS, formParams);
|
||||
List<Feature.MetadataEntry> metadataEntries = new ArrayList<>();
|
||||
Feature.MetadataEntry metadataEntry = new Feature.MetadataEntry();
|
||||
metadataEntry.setId(-1);
|
||||
metadataEntry.setValue(apiParams);
|
||||
metadataEntries.add(metadataEntry);
|
||||
feature.setMetadataEntries(metadataEntries);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addFeature(Feature feature) throws DeviceManagementException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addFeatures(List<Feature> list) throws DeviceManagementException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Feature getFeature(String code) throws DeviceManagementException {
|
||||
if (code.equals(feature.getCode())) {
|
||||
return feature;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Feature> getFeatures() throws DeviceManagementException {
|
||||
List<Feature> features = new ArrayList<>();
|
||||
features.add(feature);
|
||||
return features;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeFeature(String s) throws DeviceManagementException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addSupportedFeaturesToDB() throws DeviceManagementException {
|
||||
return false;
|
||||
}
|
||||
}
|
@ -1,259 +0,0 @@
|
||||
/*
|
||||
* 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.coffeeking.connectedcup.plugin.impl;
|
||||
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.coffeeking.connectedcup.plugin.exception.ConnectedCupDeviceMgtPluginException;
|
||||
import org.coffeeking.connectedcup.plugin.impl.dao.ConnectedCupDAOUtil;
|
||||
import org.wso2.carbon.device.mgt.common.Device;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManager;
|
||||
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
||||
import org.wso2.carbon.device.mgt.common.FeatureManager;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Device Manager interface impl for connected cup.
|
||||
*/
|
||||
public class ConnectedCupManager implements DeviceManager {
|
||||
|
||||
private static final Log log = LogFactory.getLog(ConnectedCupManager.class);
|
||||
|
||||
private static final ConnectedCupDAOUtil CONNECTED_CUP_DAO_UTIL = new ConnectedCupDAOUtil();
|
||||
|
||||
|
||||
@Override
|
||||
public FeatureManager getFeatureManager() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveConfiguration(PlatformConfiguration platformConfiguration) throws DeviceManagementException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformConfiguration getConfiguration() throws DeviceManagementException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enrollDevice(Device device) throws DeviceManagementException {
|
||||
boolean status;
|
||||
try {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Enrolling a new Connected Cup device : " + device.getDeviceIdentifier());
|
||||
}
|
||||
ConnectedCupDAOUtil.beginTransaction();
|
||||
status = CONNECTED_CUP_DAO_UTIL.getConnectedCupDeviceDAO().addDevice(device);
|
||||
ConnectedCupDAOUtil.commitTransaction();
|
||||
} catch (ConnectedCupDeviceMgtPluginException e) {
|
||||
try {
|
||||
ConnectedCupDAOUtil.rollbackTransaction();
|
||||
} catch (ConnectedCupDeviceMgtPluginException iotDAOEx) {
|
||||
String msg = "Error occurred while roll back the device enrol transaction :" + device.toString();
|
||||
log.warn(msg, iotDAOEx);
|
||||
}
|
||||
String msg = "Error while enrolling the Connected Cup device : " + device.getDeviceIdentifier();
|
||||
log.error(msg, e);
|
||||
throw new DeviceManagementException(msg, e);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
|
||||
boolean status;
|
||||
try {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Modifying the Connected Cup device enrollment data");
|
||||
}
|
||||
ConnectedCupDAOUtil.beginTransaction();
|
||||
status = CONNECTED_CUP_DAO_UTIL.getConnectedCupDeviceDAO().updateDevice(device);
|
||||
ConnectedCupDAOUtil.commitTransaction();
|
||||
} catch (ConnectedCupDeviceMgtPluginException e) {
|
||||
try {
|
||||
ConnectedCupDAOUtil.rollbackTransaction();
|
||||
} catch (ConnectedCupDeviceMgtPluginException iotDAOEx) {
|
||||
String msg = "Error occurred while roll back the update device transaction :" + device.toString();
|
||||
log.warn(msg, iotDAOEx);
|
||||
}
|
||||
String msg = "Error while updating the enrollment of the Connected Cup device : " +
|
||||
device.getDeviceIdentifier();
|
||||
log.error(msg, e);
|
||||
throw new DeviceManagementException(msg, e);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||
boolean status;
|
||||
try {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Dis-enrolling Connected Cup device : " + deviceId);
|
||||
}
|
||||
ConnectedCupDAOUtil.beginTransaction();
|
||||
status = CONNECTED_CUP_DAO_UTIL.getConnectedCupDeviceDAO().deleteDevice(deviceId.getId());
|
||||
ConnectedCupDAOUtil.commitTransaction();
|
||||
} catch (ConnectedCupDeviceMgtPluginException e) {
|
||||
try {
|
||||
ConnectedCupDAOUtil.rollbackTransaction();
|
||||
} catch (ConnectedCupDeviceMgtPluginException iotDAOEx) {
|
||||
String msg = "Error occurred while roll back the device dis enrol transaction :" + deviceId.toString();
|
||||
log.warn(msg, iotDAOEx);
|
||||
}
|
||||
String msg = "Error while removing the Connected Cup device : " + deviceId.getId();
|
||||
log.error(msg, e);
|
||||
throw new DeviceManagementException(msg, e);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||
boolean isEnrolled = false;
|
||||
try {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Checking the enrollment of Connected Cup device : " + deviceId.getId());
|
||||
}
|
||||
Device iotDevice = CONNECTED_CUP_DAO_UTIL.getConnectedCupDeviceDAO().getDevice(deviceId.getId());
|
||||
if (iotDevice != null) {
|
||||
isEnrolled = true;
|
||||
}
|
||||
} catch (ConnectedCupDeviceMgtPluginException e) {
|
||||
String msg = "Error while checking the enrollment status of Connected Cup device : " +
|
||||
deviceId.getId();
|
||||
log.error(msg, e);
|
||||
throw new DeviceManagementException(msg, e);
|
||||
}
|
||||
return isEnrolled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setActive(DeviceIdentifier deviceId, boolean status)
|
||||
throws DeviceManagementException {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||
Device device;
|
||||
try {if (log.isDebugEnabled()) {
|
||||
log.debug("Getting the details of Connected Cup device : " + deviceId.getId());
|
||||
}
|
||||
device = CONNECTED_CUP_DAO_UTIL.getConnectedCupDeviceDAO().getDevice(deviceId.getId());
|
||||
|
||||
} catch (ConnectedCupDeviceMgtPluginException e) {
|
||||
String msg = "Error while fetching the Connected Cup device : " + deviceId.getId();
|
||||
log.error(msg, e);
|
||||
throw new DeviceManagementException(msg, e);
|
||||
}
|
||||
return device;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType)
|
||||
throws DeviceManagementException {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isClaimable(DeviceIdentifier deviceIdentifier) throws DeviceManagementException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setStatus(DeviceIdentifier deviceId, String currentOwner,
|
||||
EnrolmentInfo.Status status) throws DeviceManagementException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public License getLicense(String s) throws LicenseManagementException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addLicense(License license) throws LicenseManagementException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requireDeviceAuthorization() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device) throws DeviceManagementException {
|
||||
boolean status;
|
||||
try {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(
|
||||
"updating the details of Connected Cup device : " + deviceIdentifier);
|
||||
}
|
||||
ConnectedCupDAOUtil.beginTransaction();
|
||||
status = CONNECTED_CUP_DAO_UTIL.getConnectedCupDeviceDAO().updateDevice(device);
|
||||
ConnectedCupDAOUtil.commitTransaction();
|
||||
} catch (ConnectedCupDeviceMgtPluginException e) {
|
||||
try {
|
||||
ConnectedCupDAOUtil.rollbackTransaction();
|
||||
} catch (ConnectedCupDeviceMgtPluginException iotDAOEx) {
|
||||
String msg = "Error occurred while roll back the update device info transaction :" + device.toString();
|
||||
log.warn(msg, iotDAOEx);
|
||||
}
|
||||
String msg =
|
||||
"Error while updating the Connected Cup device : " + deviceIdentifier;
|
||||
log.error(msg, e);
|
||||
throw new DeviceManagementException(msg, e);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Device> getAllDevices() throws DeviceManagementException {
|
||||
List<Device> devices = null;
|
||||
try {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Fetching the details of all Connected Cup devices");
|
||||
}
|
||||
devices = CONNECTED_CUP_DAO_UTIL.getConnectedCupDeviceDAO().getAllDevices();
|
||||
} catch (ConnectedCupDeviceMgtPluginException e) {
|
||||
String msg = "Error while fetching all Connected Cup devices.";
|
||||
log.error(msg, e);
|
||||
throw new DeviceManagementException(msg, e);
|
||||
}
|
||||
return devices;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateDeviceProperties(DeviceIdentifier deviceIdentifier, List<Device.Property> list) throws DeviceManagementException {
|
||||
return false;
|
||||
}
|
||||
}
|
@ -1,98 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.coffeeking.connectedcup.plugin.impl;
|
||||
|
||||
import org.coffeeking.connectedcup.plugin.constants.ConnectedCupConstants;
|
||||
import org.wso2.carbon.base.MultitenantConstants;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManager;
|
||||
import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig;
|
||||
import org.wso2.carbon.device.mgt.common.InitialOperationConfig;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceStatusTaskPluginConfig;
|
||||
import org.wso2.carbon.device.mgt.common.ProvisioningConfig;
|
||||
import org.wso2.carbon.device.mgt.common.general.GeneralConfig;
|
||||
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
|
||||
import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager;
|
||||
import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber;
|
||||
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
|
||||
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
|
||||
|
||||
public class ConnectedCupManagerService implements DeviceManagementService {
|
||||
private DeviceManager deviceManager;
|
||||
|
||||
@Override
|
||||
public void init() throws DeviceManagementException {
|
||||
this.deviceManager = new ConnectedCupManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return ConnectedCupConstants.DEVICE_TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OperationMonitoringTaskConfig getOperationMonitoringConfig() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeviceManager getDeviceManager() {
|
||||
return deviceManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationManager getApplicationManager() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProvisioningConfig getProvisioningConfig() {
|
||||
return new ProvisioningConfig(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PushNotificationConfig getPushNotificationConfig() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PolicyMonitoringManager getPolicyMonitoringManager() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InitialOperationConfig getInitialOperationConfig() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PullNotificationSubscriber getPullNotificationSubscriber() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeviceStatusTaskPluginConfig getDeviceStatusTaskPluginConfig() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeneralConfig getGeneralConfig() {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,204 +0,0 @@
|
||||
/*
|
||||
* 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.coffeeking.connectedcup.plugin.impl.dao;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.coffeeking.connectedcup.plugin.constants.ConnectedCupConstants;
|
||||
import org.coffeeking.connectedcup.plugin.exception.ConnectedCupDeviceMgtPluginException;
|
||||
import org.coffeeking.connectedcup.plugin.impl.dao.util.ConnectedCupUtils;
|
||||
import org.wso2.carbon.device.mgt.common.Device;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Device Dao for connected cup Devices.
|
||||
*/
|
||||
public class ConnectedCupDAO {
|
||||
|
||||
|
||||
private static final Log log = LogFactory.getLog(ConnectedCupDAO.class);
|
||||
|
||||
public Device getDevice(String deviceId) throws ConnectedCupDeviceMgtPluginException {
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
Device connectedCupDevice = null;
|
||||
ResultSet resultSet = null;
|
||||
try {
|
||||
conn = ConnectedCupDAOUtil.getConnection();
|
||||
String selectDBQuery =
|
||||
"SELECT CONNECTED_CUP_DEVICE_ID, DEVICE_NAME FROM CONNECTED_CUP_DEVICE WHERE CONNECTED_CUP_DEVICE_ID = ?";
|
||||
stmt = conn.prepareStatement(selectDBQuery);
|
||||
stmt.setString(1, deviceId);
|
||||
resultSet = stmt.executeQuery();
|
||||
|
||||
if (resultSet.next()) {
|
||||
connectedCupDevice = new Device();
|
||||
connectedCupDevice.setName(resultSet.getString(ConnectedCupConstants.DEVICE_PLUGIN_DEVICE_NAME));
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Connected Cup service " + deviceId + " data has been fetched from" +
|
||||
"Connected Cup database.");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while fetching Connected Cup device : '" + deviceId + "'";
|
||||
log.error(msg, e);
|
||||
throw new ConnectedCupDeviceMgtPluginException(msg, e);
|
||||
} finally {
|
||||
ConnectedCupUtils.cleanupResources(stmt, resultSet);
|
||||
ConnectedCupDAOUtil.closeConnection();
|
||||
}
|
||||
return connectedCupDevice;
|
||||
}
|
||||
|
||||
|
||||
public boolean addDevice(Device connectedCupDevice) throws ConnectedCupDeviceMgtPluginException {
|
||||
boolean status = false;
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = ConnectedCupDAOUtil.getConnection();
|
||||
String createDBQuery =
|
||||
"INSERT INTO CONNECTED_CUP_DEVICE(CONNECTED_CUP_DEVICE_ID, DEVICE_NAME ) VALUES (?, ?)";
|
||||
|
||||
stmt = conn.prepareStatement(createDBQuery);
|
||||
stmt.setString(1, connectedCupDevice.getDeviceIdentifier());
|
||||
stmt.setString(2, connectedCupDevice.getName());
|
||||
|
||||
int rows = stmt.executeUpdate();
|
||||
if (rows > 0) {
|
||||
status = true;
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Connected Cup device " + connectedCupDevice.getDeviceIdentifier() +
|
||||
" data has been added to the Connected Cup database.");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while adding the Connected Cup device '" +
|
||||
connectedCupDevice.getDeviceIdentifier() + "' to the Connected Cup db.";
|
||||
log.error(msg, e);
|
||||
throw new ConnectedCupDeviceMgtPluginException(msg, e);
|
||||
} finally {
|
||||
ConnectedCupUtils.cleanupResources(stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
public boolean updateDevice(Device connectedCupDevice) throws ConnectedCupDeviceMgtPluginException {
|
||||
boolean status = false;
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = ConnectedCupDAOUtil.getConnection();
|
||||
String updateDBQuery =
|
||||
"UPDATE CONNECTED_CUP_DEVICE SET DEVICE_NAME = ? WHERE CONNECTED_CUP_DEVICE_ID = ?";
|
||||
|
||||
stmt = conn.prepareStatement(updateDBQuery);
|
||||
stmt.setString(1, connectedCupDevice.getName());
|
||||
stmt.setString(2, connectedCupDevice.getDeviceIdentifier());
|
||||
int rows = stmt.executeUpdate();
|
||||
if (rows > 0) {
|
||||
status = true;
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Connected Cup device " + connectedCupDevice.getDeviceIdentifier() +
|
||||
" data has been modified.");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while modifying the Connected Cup device '" +
|
||||
connectedCupDevice.getDeviceIdentifier() + "' data.";
|
||||
log.error(msg, e);
|
||||
throw new ConnectedCupDeviceMgtPluginException(msg, e);
|
||||
} finally {
|
||||
ConnectedCupUtils.cleanupResources(stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
public boolean deleteDevice(String deviceId) throws ConnectedCupDeviceMgtPluginException {
|
||||
boolean status = false;
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = ConnectedCupDAOUtil.getConnection();
|
||||
String deleteDBQuery =
|
||||
"DELETE FROM CONNECTED_CUP_DEVICE WHERE CONNECTED_CUP_DEVICE_ID = ?";
|
||||
stmt = conn.prepareStatement(deleteDBQuery);
|
||||
stmt.setString(1, deviceId);
|
||||
int rows = stmt.executeUpdate();
|
||||
if (rows > 0) {
|
||||
status = true;
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Connected Cup device " + deviceId + " data has deleted" +
|
||||
" from the Connected Cup database.");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while deleting Connected Cup device " + deviceId;
|
||||
log.error(msg, e);
|
||||
throw new ConnectedCupDeviceMgtPluginException(msg, e);
|
||||
} finally {
|
||||
ConnectedCupUtils.cleanupResources(stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
public List<Device> getAllDevices() throws ConnectedCupDeviceMgtPluginException {
|
||||
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet resultSet = null;
|
||||
Device connectedCupDevice;
|
||||
List<Device> iotDevices = new ArrayList<>();
|
||||
|
||||
try {
|
||||
conn = ConnectedCupDAOUtil.getConnection();
|
||||
String selectDBQuery =
|
||||
"SELECT CONNECTED_CUP_DEVICE_ID, DEVICE_NAME" +
|
||||
"FROM CONNECTED_CUP_DEVICE";
|
||||
stmt = conn.prepareStatement(selectDBQuery);
|
||||
resultSet = stmt.executeQuery();
|
||||
while (resultSet.next()) {
|
||||
connectedCupDevice = new Device();
|
||||
connectedCupDevice.setDeviceIdentifier(resultSet.getString(
|
||||
ConnectedCupConstants.DEVICE_PLUGIN_DEVICE_ID));
|
||||
connectedCupDevice.setName(resultSet.getString(
|
||||
ConnectedCupConstants.DEVICE_PLUGIN_DEVICE_NAME));
|
||||
}
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("All Connected Cup device details have fetched from Connected Cup database" +
|
||||
".");
|
||||
}
|
||||
return iotDevices;
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while fetching all Connected Cup device data'";
|
||||
log.error(msg, e);
|
||||
throw new ConnectedCupDeviceMgtPluginException(msg, e);
|
||||
} finally {
|
||||
ConnectedCupUtils.cleanupResources(stmt, resultSet);
|
||||
ConnectedCupDAOUtil.closeConnection();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,132 +0,0 @@
|
||||
/*
|
||||
* 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.coffeeking.connectedcup.plugin.impl.dao;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.coffeeking.connectedcup.plugin.constants.ConnectedCupConstants;
|
||||
import org.coffeeking.connectedcup.plugin.exception.ConnectedCupDeviceMgtPluginException;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.InitialContext;
|
||||
import javax.naming.NamingException;
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class ConnectedCupDAOUtil {
|
||||
|
||||
private static final Log log = LogFactory.getLog(ConnectedCupDAOUtil.class);
|
||||
static DataSource dataSource;
|
||||
private static ThreadLocal<Connection> currentConnection = new ThreadLocal<Connection>();
|
||||
|
||||
public ConnectedCupDAOUtil() {
|
||||
initConnectedCupDAO();
|
||||
}
|
||||
|
||||
public static void initConnectedCupDAO() {
|
||||
try {
|
||||
Context ctx = new InitialContext();
|
||||
dataSource = (DataSource) ctx.lookup(ConnectedCupConstants.DATA_SOURCE_NAME);
|
||||
} catch (NamingException e) {
|
||||
log.error("Error while looking up the data source: " +
|
||||
ConnectedCupConstants.DATA_SOURCE_NAME);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public ConnectedCupDAO getConnectedCupDeviceDAO() {
|
||||
return new ConnectedCupDAO();
|
||||
}
|
||||
|
||||
public static void beginTransaction() throws ConnectedCupDeviceMgtPluginException {
|
||||
try {
|
||||
Connection conn = dataSource.getConnection();
|
||||
conn.setAutoCommit(false);
|
||||
currentConnection.set(conn);
|
||||
} catch (SQLException e) {
|
||||
throw new ConnectedCupDeviceMgtPluginException(
|
||||
"Error occurred while retrieving datasource connection", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static Connection getConnection() throws ConnectedCupDeviceMgtPluginException {
|
||||
if (currentConnection.get() == null) {
|
||||
try {
|
||||
currentConnection.set(dataSource.getConnection());
|
||||
} catch (SQLException e) {
|
||||
throw new ConnectedCupDeviceMgtPluginException(
|
||||
"Error occurred while retrieving data source connection", e);
|
||||
}
|
||||
}
|
||||
return currentConnection.get();
|
||||
}
|
||||
|
||||
public static void commitTransaction() throws ConnectedCupDeviceMgtPluginException {
|
||||
try {
|
||||
Connection conn = currentConnection.get();
|
||||
if (conn != null) {
|
||||
conn.commit();
|
||||
} else {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Datasource connection associated with the current thread is null, " +
|
||||
"hence commit has not been attempted");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new ConnectedCupDeviceMgtPluginException(
|
||||
"Error occurred while committing the transaction", e);
|
||||
} finally {
|
||||
closeConnection();
|
||||
}
|
||||
}
|
||||
|
||||
public static void closeConnection() throws ConnectedCupDeviceMgtPluginException {
|
||||
|
||||
Connection con = currentConnection.get();
|
||||
if (con != null) {
|
||||
try {
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
log.error("Error occurred while close the connection");
|
||||
}
|
||||
}
|
||||
currentConnection.remove();
|
||||
}
|
||||
|
||||
public static void rollbackTransaction() throws ConnectedCupDeviceMgtPluginException {
|
||||
try {
|
||||
Connection conn = currentConnection.get();
|
||||
if (conn != null) {
|
||||
conn.rollback();
|
||||
} else {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(
|
||||
"Datasource connection associated with the current thread is null, " +
|
||||
"hence rollback has not been attempted");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new ConnectedCupDeviceMgtPluginException("Error occurred while rollback the transaction", e);
|
||||
} finally {
|
||||
closeConnection();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,88 +0,0 @@
|
||||
/*
|
||||
* 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.coffeeking.connectedcup.plugin.impl.dao.util;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.Device;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Contains utility methods used by FireAlarm plugin.
|
||||
*/
|
||||
public class ConnectedCupUtils {
|
||||
|
||||
private static Log log = LogFactory.getLog(ConnectedCupUtils.class);
|
||||
|
||||
public static String getDeviceProperty(List<Device.Property> deviceProperties, String propertyKey) {
|
||||
String deviceProperty = "";
|
||||
for (Device.Property property : deviceProperties) {
|
||||
if (propertyKey.equals(property.getName())) {
|
||||
deviceProperty = property.getValue();
|
||||
}
|
||||
}
|
||||
return deviceProperty;
|
||||
}
|
||||
|
||||
public static Device.Property getProperty(String property, String value) {
|
||||
if (property != null) {
|
||||
Device.Property prop = new Device.Property();
|
||||
prop.setName(property);
|
||||
prop.setValue(value);
|
||||
return prop;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void cleanupResources(Connection conn, PreparedStatement stmt, ResultSet rs) {
|
||||
if (rs != null) {
|
||||
try {
|
||||
rs.close();
|
||||
} catch (SQLException e) {
|
||||
log.warn("Error occurred while closing result set", e);
|
||||
}
|
||||
}
|
||||
if (stmt != null) {
|
||||
try {
|
||||
stmt.close();
|
||||
} catch (SQLException e) {
|
||||
log.warn("Error occurred while closing prepared statement", e);
|
||||
}
|
||||
}
|
||||
if (conn != null) {
|
||||
try {
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
log.warn("Error occurred while closing database connection", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void cleanupResources(PreparedStatement stmt, ResultSet rs) {
|
||||
cleanupResources(null, stmt, rs);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,74 +0,0 @@
|
||||
/*
|
||||
* 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.coffeeking.connectedcup.plugin.internal;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.coffeeking.connectedcup.plugin.impl.ConnectedCupManagerService;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.framework.ServiceRegistration;
|
||||
import org.osgi.service.component.ComponentContext;
|
||||
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
|
||||
|
||||
/**
|
||||
* @scr.component name="org.coffeeking.connectedcup.plugin.internal
|
||||
* .ConnectedCupServiceComponent"
|
||||
* immediate="true"
|
||||
*/
|
||||
|
||||
public class ConnectedCupServiceComponent {
|
||||
private static final Log log = LogFactory.getLog(ConnectedCupServiceComponent.class);
|
||||
private ServiceRegistration connectedCupServiceRegRef;
|
||||
|
||||
protected void activate(ComponentContext ctx) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Activating Connected Cup Service Component");
|
||||
}
|
||||
try {
|
||||
BundleContext bundleContext = ctx.getBundleContext();
|
||||
connectedCupServiceRegRef =
|
||||
bundleContext.registerService(DeviceManagementService.class.getName(),
|
||||
new ConnectedCupManagerService(), null);
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Connected Cup Service Component has been successfully activated");
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
log.error("Error occurred while activating Connected Cup Service Component", e);
|
||||
}
|
||||
}
|
||||
|
||||
protected void deactivate(ComponentContext ctx) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("De-activating Connected Cup Service Component");
|
||||
}
|
||||
try {
|
||||
if (connectedCupServiceRegRef != null) {
|
||||
connectedCupServiceRegRef.unregister();
|
||||
}
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Connected Cup Service Component has been successfully de-activated");
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
log.error("Error occurred while de-activating Connected Cup Service Component", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
<?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.
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<parent>
|
||||
<groupId>org.coffeeking</groupId>
|
||||
<artifactId>device.mgt.iot.connectedcup-parent</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>device-mgt-iot-connectedcup</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>WSO2 IoTS(Device Types) - Connected Cup Component</name>
|
||||
<description>WSO2 IoTS(Device Types) - Connected Cup Component</description>
|
||||
<url>http://wso2.org</url>
|
||||
|
||||
<modules>
|
||||
<module>analytics</module>
|
||||
<module>plugin</module>
|
||||
<module>api</module>
|
||||
<module>agent</module>
|
||||
<module>ui</module>
|
||||
</modules>
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-scr-plugin</artifactId>
|
||||
<version>1.7.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>generate-scr-scrdescriptor</id>
|
||||
<goals>
|
||||
<goal>scr</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
|
||||
</project>
|
@ -1,63 +0,0 @@
|
||||
<?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.
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
|
||||
<parent>
|
||||
<groupId>org.coffeeking</groupId>
|
||||
<artifactId>device-mgt-iot-connectedcup</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>org.coffeeking.connectedcup.ui</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<name>WSO2 IoTS(Device Types) - Connected Cup UI</name>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>2.5.5</version>
|
||||
<configuration>
|
||||
<finalName>${project.artifactId}-${carbon.device.mgt.version}</finalName>
|
||||
<appendAssemblyId>false</appendAssemblyId>
|
||||
<descriptors>
|
||||
<descriptor>src/assembly/src.xml</descriptor>
|
||||
</descriptors>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>create-archive</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
@ -1,36 +0,0 @@
|
||||
<!--
|
||||
~ Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
~
|
||||
~ WSO2 Inc. licenses this file to you under the Apache License,
|
||||
~ Version 2.0 (the "License"); you may not use this file except
|
||||
~ in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing,
|
||||
~ software distributed under the License is distributed on an
|
||||
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
~ KIND, either express or implied. See the License for the
|
||||
~ specific language governing permissions and limitations
|
||||
~ under the License.
|
||||
-->
|
||||
|
||||
<assembly
|
||||
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
|
||||
<id>src</id>
|
||||
<formats>
|
||||
<format>zip</format>
|
||||
</formats>
|
||||
<includeBaseDirectory>false</includeBaseDirectory>
|
||||
<baseDirectory>${basedir}/src</baseDirectory>
|
||||
<fileSets>
|
||||
<fileSet>
|
||||
<directory>${basedir}/src/main/resources/jaggeryapps/devicemgt</directory>
|
||||
<outputDirectory>/</outputDirectory>
|
||||
<useDefaultExcludes>true</useDefaultExcludes>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
</assembly>
|
@ -1,48 +0,0 @@
|
||||
{{!
|
||||
Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
|
||||
WSO2 Inc. licenses this file to you under the Apache License,
|
||||
Version 2.0 (the "License"); you may not use this file except
|
||||
in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
}}
|
||||
<span id="connectedcup-details" data-devices="{{devices}}" data-devicename="{{device.name}}"
|
||||
data-deviceid="{{device.deviceIdentifier}}"
|
||||
data-appcontext="{{@app.context}}"></span>
|
||||
<div id="connectedcup-div-chart" data-backend-api-url= {{backendApiUri}}>
|
||||
<div class="chartWrapper" id="chartWrapper">
|
||||
<h3 id="span-title">Temperature</h3>
|
||||
<div id="y_axis-temperature" class="custom_y_axis"></div>
|
||||
<div class="legend_container">
|
||||
<div id="smoother-temperature" title="Smoothing"></div>
|
||||
<div id="legend-temperature"></div>
|
||||
</div>
|
||||
<div id="chart-temperature" class="custom_rickshaw_graph"></div>
|
||||
<div id="x_axis-temperature" class="custom_x_axis"></div>
|
||||
<div id="slider-temperature" class="custom_slider"></div>
|
||||
</div>
|
||||
<div class="chartWrapper" id="chartWrapper">
|
||||
<h3 id="span-title">Coffee Level</h3>
|
||||
<div id="y_axis-coffeelevel" class="custom_y_axis"></div>
|
||||
<div class="legend_container">
|
||||
<div id="smoother-coffeelevel" title="Smoothing"></div>
|
||||
<div id="legend-coffeelevel"></div>
|
||||
</div>
|
||||
<div id="chart-coffeelevel" class="custom_rickshaw_graph"></div>
|
||||
<div id="x_axis-coffeelevel" class="custom_x_axis"></div>
|
||||
<div id="slider-coffeelevel" class="custom_slider"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{#zone "bottomJs"}}
|
||||
{{js "js/connectedcup.js"}}
|
||||
{{/zone}}
|
@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
function onRequest(context) {
|
||||
var devices = context.unit.params.devices;
|
||||
var deviceType = context.uriParams.deviceType;
|
||||
var deviceId = request.getParameter("deviceId");
|
||||
|
||||
if (devices) {
|
||||
return {
|
||||
"devices": stringify(devices),
|
||||
"backendApiUri": "/connectedcup/stats/"
|
||||
};
|
||||
} else if (deviceType != null && deviceType != undefined && deviceId != null && deviceId != undefined) {
|
||||
var deviceModule = require("/app/modules/business-controllers/device.js")["deviceModule"];
|
||||
var device = deviceModule.viewDevice(deviceType, deviceId);
|
||||
if (device && device.status != "error") {
|
||||
return {
|
||||
"device": device.content,
|
||||
"backendApiUri": "/connectedcup/stats/" + deviceId
|
||||
};
|
||||
} else {
|
||||
response.sendError(404, "Device Id " + deviceId + " of type " + deviceType + " cannot be found!");
|
||||
exit();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
{
|
||||
"version": "1.0.0"
|
||||
}
|
@ -1,316 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
var palette = new Rickshaw.Color.Palette({scheme: 'classic9'});
|
||||
|
||||
function drawGraph_connectedcup(from, to) {
|
||||
$('#y_axis-temperature').html('');
|
||||
$('#smoother-temperature').html('');
|
||||
$('#legend-temperature').html('');
|
||||
$('#chart-temperature').html('');
|
||||
$('#x_axis-temperature').html('');
|
||||
$('#slider-temperature').html('');
|
||||
|
||||
$('#y_axis-coffeelevel').html('');
|
||||
$('#smoother-coffeelevel').html('');
|
||||
$('#legend-coffeelevel').html('');
|
||||
$('#chart-coffeelevel').html('');
|
||||
$('#x_axis-coffeelevel').html('');
|
||||
$('#slider-coffeelevel').html('');
|
||||
|
||||
var devices = $('#connectedcup-details').data('devices');
|
||||
var tzOffset = new Date().getTimezoneOffset() * 60;
|
||||
|
||||
var chartWrapperElmId = '#connectedcup-div-chart';
|
||||
var graphWidth = $(chartWrapperElmId).width() - 50;
|
||||
var temperatureGraphConfig = {
|
||||
element: document.getElementById('chart-temperature'),
|
||||
width: graphWidth,
|
||||
height: 400,
|
||||
strokeWidth: 2,
|
||||
renderer: 'line',
|
||||
interpolation: 'linear',
|
||||
unstack: true,
|
||||
stack: false,
|
||||
xScale: d3.time.scale(),
|
||||
padding: {top: 0.2, left: 0.02, right: 0.02, bottom: 0.2},
|
||||
series: []
|
||||
};
|
||||
|
||||
var coffeelevelGraphConfig = {
|
||||
element: document.getElementById('chart-coffeelevel'),
|
||||
width: graphWidth,
|
||||
height: 400,
|
||||
strokeWidth: 2,
|
||||
renderer: 'line',
|
||||
interpolation: 'linear',
|
||||
unstack: true,
|
||||
stack: false,
|
||||
xScale: d3.time.scale(),
|
||||
padding: {top: 0.2, left: 0.02, right: 0.02, bottom: 0.2},
|
||||
series: []
|
||||
};
|
||||
|
||||
if (devices) {
|
||||
for (var i = 0; i < devices.length; i++) {
|
||||
temperatureGraphConfig['series'].push(
|
||||
{
|
||||
'color': palette.color(),
|
||||
'data': [{
|
||||
x: parseInt(new Date().getTime() / 1000),
|
||||
y: 0
|
||||
}],
|
||||
'name': devices[i].name
|
||||
});
|
||||
|
||||
coffeelevelGraphConfig['series'].push(
|
||||
{
|
||||
'color': palette.color(),
|
||||
'data': [{
|
||||
x: parseInt(new Date().getTime() / 1000),
|
||||
y: 0
|
||||
}],
|
||||
'name': devices[i].name
|
||||
});
|
||||
}
|
||||
} else {
|
||||
temperatureGraphConfig['series'].push(
|
||||
{
|
||||
'color': palette.color(),
|
||||
'data': [{
|
||||
x: parseInt(new Date().getTime() / 1000),
|
||||
y: 0
|
||||
}],
|
||||
'name': $('#connectedcup-details').data('devicename')
|
||||
});
|
||||
coffeelevelGraphConfig['series'].push(
|
||||
{
|
||||
'color': palette.color(),
|
||||
'data': [{
|
||||
x: parseInt(new Date().getTime() / 1000),
|
||||
y: 0
|
||||
}],
|
||||
'name': $('#connectedcup-details').data('devicename')
|
||||
});
|
||||
}
|
||||
|
||||
var temperatureGraph = new Rickshaw.Graph(temperatureGraphConfig);
|
||||
var coffeelevelGraph = new Rickshaw.Graph(coffeelevelGraphConfig);
|
||||
|
||||
temperatureGraph.render();
|
||||
coffeelevelGraph.render
|
||||
|
||||
var xAxisTemepature = new Rickshaw.Graph.Axis.Time({
|
||||
graph: temperatureGraph
|
||||
});
|
||||
|
||||
xAxisTemepature.render();
|
||||
|
||||
var xAxisCoffeelevel = new Rickshaw.Graph.Axis.Time({
|
||||
graph: coffeelevelGraph
|
||||
});
|
||||
|
||||
xAxisCoffeelevel.render();
|
||||
|
||||
var yAxisTemperature = new Rickshaw.Graph.Axis.Y({
|
||||
graph: temperatureGraph,
|
||||
orientation: 'left',
|
||||
element: document.getElementById('y_axis-temperature'),
|
||||
width: 40,
|
||||
height: 410
|
||||
});
|
||||
|
||||
yAxisTemperature.render();
|
||||
|
||||
var yAxisCoffeelevel = new Rickshaw.Graph.Axis.Y({
|
||||
graph: coffeelevelGraph,
|
||||
orientation: 'left',
|
||||
element: document.getElementById('y_axis-coffeelevel'),
|
||||
width: 40,
|
||||
height: 410
|
||||
});
|
||||
|
||||
yAxisCoffeelevel.render();
|
||||
|
||||
var slider = new Rickshaw.Graph.RangeSlider.Preview({
|
||||
graph: temperatureGraph,
|
||||
element: document.getElementById('slider-temperature')
|
||||
});
|
||||
|
||||
var legend = new Rickshaw.Graph.Legend({
|
||||
graph: temperatureGraph,
|
||||
element: document.getElementById('legend-temperature')
|
||||
});
|
||||
|
||||
var sliderCoffee = new Rickshaw.Graph.RangeSlider.Preview({
|
||||
graph: coffeelevelGraph,
|
||||
element: document.getElementById('slider-coffeelevel')
|
||||
});
|
||||
|
||||
var legendCoffee = new Rickshaw.Graph.Legend({
|
||||
graph: coffeelevelGraph,
|
||||
element: document.getElementById('legend-coffeelevel')
|
||||
});
|
||||
|
||||
var hoverDetail = new Rickshaw.Graph.HoverDetail({
|
||||
graph: temperatureGraph,
|
||||
formatter: function (series, x, y) {
|
||||
var date = '<span class="date">' +
|
||||
moment((x + tzOffset) * 1000).format('Do MMM YYYY h:mm:ss a') + '</span>';
|
||||
var swatch = '<span class="detail_swatch" style="background-color: ' +
|
||||
series.color + '"></span>';
|
||||
return swatch + series.name + ': ' + parseInt(y) + '<br>' + date;
|
||||
}
|
||||
});
|
||||
|
||||
var hoverDetailCoffeelevel = new Rickshaw.Graph.HoverDetail({
|
||||
graph: coffeelevelGraph,
|
||||
formatter: function (series, x, y) {
|
||||
var date = '<span class="date">' +
|
||||
moment((x + tzOffset) * 1000).format('Do MMM YYYY h:mm:ss a') + '</span>';
|
||||
var swatch = '<span class="detail_swatch" style="background-color: ' +
|
||||
series.color + '"></span>';
|
||||
return swatch + series.name + ': ' + parseInt(y) + '<br>' + date;
|
||||
}
|
||||
});
|
||||
|
||||
var shelving = new Rickshaw.Graph.Behavior.Series.Toggle({
|
||||
graph: temperatureGraph,
|
||||
legend: legend
|
||||
});
|
||||
|
||||
var order = new Rickshaw.Graph.Behavior.Series.Order({
|
||||
graph: temperatureGraph,
|
||||
legend: legend
|
||||
});
|
||||
|
||||
var highlighter = new Rickshaw.Graph.Behavior.Series.Highlight({
|
||||
graph: temperatureGraph,
|
||||
legend: legend
|
||||
});
|
||||
|
||||
var shelvingCoffee = new Rickshaw.Graph.Behavior.Series.Toggle({
|
||||
graph: coffeelevelGraph,
|
||||
legend: legendCoffee
|
||||
});
|
||||
|
||||
var orderCoffee = new Rickshaw.Graph.Behavior.Series.Order({
|
||||
graph: coffeelevelGraph,
|
||||
legend: legendCoffee
|
||||
});
|
||||
|
||||
var highlighterCoffee = new Rickshaw.Graph.Behavior.Series.Highlight({
|
||||
graph: coffeelevelGraph,
|
||||
legend: legendCoffee
|
||||
});
|
||||
|
||||
var deviceIndex = 0;
|
||||
|
||||
if (devices) {
|
||||
getData();
|
||||
} else {
|
||||
var backendApiUrl = $('#connectedcup-div-chart').data('backend-api-url') + '/sensors/temperature'
|
||||
+ '?from=' + from + '&to=' + to;
|
||||
var successCallback = function (data) {
|
||||
if (data) {
|
||||
drawTemperatureLineGraph(JSON.parse(data));
|
||||
}
|
||||
};
|
||||
invokerUtil.get(backendApiUrl, successCallback, function (message) {});
|
||||
|
||||
var coffeeLevelApiUrl = $('#connectedcup-div-chart').data('backend-api-url') + '/sensors/coffeelevel'
|
||||
+ '?from=' + from + '&to=' + to;
|
||||
var successCallbackCoffeeLevel = function (data) {
|
||||
if (data) {
|
||||
drawCoffeeLevelLineGraph(JSON.parse(data));
|
||||
}
|
||||
};
|
||||
invokerUtil.get(coffeeLevelApiUrl, successCallbackCoffeeLevel, function (message) {
|
||||
console.log(message);
|
||||
});
|
||||
}
|
||||
|
||||
function getData() {
|
||||
if (deviceIndex >= devices.length) {
|
||||
return;
|
||||
}
|
||||
var backendApiUrl = $('#connectedcup-div-chart').data('backend-api-url') + devices[deviceIndex].deviceIdentifier
|
||||
+ '/sensors/temperature?from=' + from + '&to=' + to;
|
||||
var successCallback = function (data) {
|
||||
if (data) {
|
||||
drawTemperatureLineGraph(JSON.parse(data));
|
||||
}
|
||||
deviceIndex++;
|
||||
getData();
|
||||
};
|
||||
invokerUtil.get(backendApiUrl, successCallback, function (message) {
|
||||
console.log(message);
|
||||
deviceIndex++;
|
||||
getData();
|
||||
});
|
||||
var coffeeLevelApiUrl = $('#connectedcup-div-chart').data('backend-api-url') + devices[deviceIndex].deviceIdentifier
|
||||
+ '/sensors/coffeelevel?from=' + from + '&to=' + to;
|
||||
|
||||
var successCallbackCoffeeLevel = function (data) {
|
||||
if (data) {
|
||||
drawCoffeeLevelLineGraph(JSON.parse(data));
|
||||
}
|
||||
};
|
||||
invokerUtil.get(coffeeLevelApiUrl, successCallbackCoffeeLevel, function (message) {
|
||||
console.log(message);
|
||||
});
|
||||
}
|
||||
|
||||
function drawTemperatureLineGraph(data) {
|
||||
if (data.length === 0 || data.length === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
var chartData = [];
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
chartData.push(
|
||||
{
|
||||
x: parseInt(data[i].values.time) - tzOffset,
|
||||
y: parseInt(data[i].values.temperature)
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
temperatureGraphConfig.series[deviceIndex].data = chartData;
|
||||
temperatureGraph.update();
|
||||
}
|
||||
|
||||
function drawCoffeeLevelLineGraph(data) {
|
||||
if (data.length === 0 || data.length === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
var chartData = [];
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
chartData.push(
|
||||
{
|
||||
x: parseInt(data[i].values.time) - tzOffset,
|
||||
y: parseInt(data[i].values.coffeelevel)
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
coffeelevelGraphConfig.series[deviceIndex].data = chartData;
|
||||
coffeelevelGraph.update();
|
||||
}
|
||||
}
|
@ -1,84 +0,0 @@
|
||||
{{!
|
||||
Copyright (c) 2017, 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.
|
||||
}}
|
||||
|
||||
{{#zone "topCss"}}
|
||||
<style>
|
||||
.thumbnail.icon:before {
|
||||
padding-top: 0;
|
||||
}
|
||||
</style>
|
||||
{{/zone}}
|
||||
|
||||
{{#zone "device-thumbnail"}}
|
||||
<img src="{{@unit.publicUri}}/images/thumb.png" class="img-responsive"/>
|
||||
{{/zone}}
|
||||
|
||||
{{#zone "device-details-header"}}
|
||||
<h1 class="device-id"
|
||||
data-deviceid="{{device.deviceIdentifier}}"
|
||||
data-type="{{device.type}}"
|
||||
data-ownership="{{device.ownership}}"
|
||||
data-owner="{{device.owner}}">
|
||||
{{device.enrolmentInfo.owner}}'s {{device.name}}
|
||||
<a id="device-info-tooltip" href="#" data-toggle="tooltip" title="Device Identifier: {{device.deviceIdentifier}}">
|
||||
<i class="fw fw-info"></i>
|
||||
</a>
|
||||
</h1>
|
||||
<h4>Ownership - <strong>{{device.enrolmentInfo.ownership}}</strong></h4>
|
||||
<h4>Device is
|
||||
<strong>
|
||||
{{#equal device.enrolmentInfo.status "ACTIVE"}}Active{{/equal}}
|
||||
{{#equal device.enrolmentInfo.status "INACTIVE"}}Inactive{{/equal}}
|
||||
{{#equal device.enrolmentInfo.status "BLOCKED"}}Blocked{{/equal}}
|
||||
{{#equal device.enrolmentInfo.status "REMOVED"}}Removed{{/equal}}
|
||||
{{#equal device.enrolmentInfo.status "UNREACHABLE"}}Unreachable{{/equal}}
|
||||
</strong>
|
||||
</h4>
|
||||
{{/zone}}
|
||||
|
||||
|
||||
{{#zone "device-opetations"}}
|
||||
<div class="operation-container">
|
||||
<div class="operation-title">
|
||||
<h4>Device Operations</h4>
|
||||
</div>
|
||||
<div class="buttons">
|
||||
<a class="btn-operations" target="_blank"
|
||||
href="{{../device.ip}}/connected-cup-agent/index.jsp?deviceOwner={{@user.username}}&tenantDomain={{@user.domain}}&deviceId={{../device.deviceIdentifier}}&token={{../device.accessToken}}" >
|
||||
Go To Device
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
{{/zone}}
|
||||
|
||||
{{#zone "device-view-tabs"}}
|
||||
<li class="active"><a class="list-group-item" href="#device_statistics" role="tab"
|
||||
data-toggle="tab" aria-controls="device_statistics">Device
|
||||
Statistics</a>
|
||||
</li>
|
||||
{{/zone}}
|
||||
|
||||
{{#zone "device-view-tab-contents"}}
|
||||
|
||||
<div class="panel panel-default tab-pane active"
|
||||
id="device_statistics" role="tabpanel" aria-labelledby="device_statistics">
|
||||
<div class="panel-heading">Device Statistics</div>
|
||||
{{unit "cdmf.unit.device.type.connectedcup.realtime.analytics-view" device=device}}
|
||||
</div>
|
||||
|
||||
{{/zone}}
|
@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
|
||||
function onRequest(context) {
|
||||
var deviceType = context.uriParams.deviceType;
|
||||
var deviceId = request.getParameter('id');
|
||||
|
||||
if (deviceType && deviceId) {
|
||||
var deviceModule = require("/app/modules/business-controllers/device.js").deviceModule;
|
||||
var deviceData = deviceModule.viewDevice(deviceType, deviceId);
|
||||
|
||||
if (deviceData && deviceData.status != 'error') {
|
||||
var device = deviceData.content;
|
||||
var constants = require('/app/modules/constants.js');
|
||||
var tokenPair = JSON.parse(session.get(constants.TOKEN_PAIR));
|
||||
if (tokenPair) {
|
||||
device.accessToken = tokenPair.accessToken;
|
||||
}
|
||||
var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"];
|
||||
device.ip = devicemgtProps['httpsWebURL'];
|
||||
return {'device': deviceData.content};
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
{
|
||||
"version": "1.0.0"
|
||||
}
|
Before Width: | Height: | Size: 5.3 KiB |
@ -1,64 +0,0 @@
|
||||
{{!
|
||||
Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
|
||||
WSO2 Inc. licenses this file to you under the Apache License,
|
||||
Version 2.0 (the "License"); you may not use this file except
|
||||
in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
}}
|
||||
{{unit "cdmf.unit.lib.rickshaw-graph"}}
|
||||
|
||||
<div id="div-chartTemperature" data-websocketurl="{{websocketEndpointTemperature}}" data-sensorType="temperature">
|
||||
<div class="chartWrapper" id="chartWrapper">
|
||||
<div id="y_axisTemperature" class="custom_y_axis" style="margin-top: -20px;">Temperature</div>
|
||||
<div class="legend_container">
|
||||
<div id="smoother" title="Smoothing"></div>
|
||||
<div id="legend"></div>
|
||||
</div>
|
||||
<div id="chartTemperature" class="custom_rickshaw_graph"></div>
|
||||
<div class="custom_x_axis">Time</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="div-chartCoffeeLevel" data-websocketurl="{{websocketEndpointCoffeeLevel}}" data-sensorType="coffeelevel">
|
||||
<div class="chartWrapper" id="chartWrapper">
|
||||
<div id="y_axisCoffeeLevel" class="custom_y_axis" style="margin-top: -20px;">Coffee Level</div>
|
||||
<div class="legend_container">
|
||||
<div id="smoother" title="Smoothing"></div>
|
||||
<div id="legend2"></div>
|
||||
</div>
|
||||
<div id="chartCoffeeLevel" class="custom_rickshaw_graph"></div>
|
||||
<div class="custom_x_axis">Time</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<a class="padding-left"
|
||||
href="{{@app.context}}/device/{{device.type}}/analytics?deviceId={{device.deviceIdentifier}}&deviceName={{device.name}}">
|
||||
<span class="fw-stack">
|
||||
<i class="fw fw-circle-outline fw-stack-2x"></i>
|
||||
<i class="fw fw-statistics fw-stack-1x"></i>
|
||||
<span class="fw-stack fw-move-right fw-move-bottom">
|
||||
<i class="fw fw-circle fw-stack-2x fw-stroke"></i>
|
||||
<i class="fw fw-clock fw-stack-1x fw-inverse"></i>
|
||||
</span>
|
||||
</span> View Device Analytics
|
||||
</a>
|
||||
|
||||
<div class="hide" id="websocker-onerror">
|
||||
Realtime Analytics for $sensorType not available. Failed to connect to the websocket. Please make sure; '<a style="color: white" href="$webSocketURL">$webSocketURL</a>' is available and re-try again.
|
||||
</div>
|
||||
<!-- /statistics -->
|
||||
{{#zone "bottomJs"}}
|
||||
{{js "js/moment.min.js"}}
|
||||
{{js "js/socket.io.min.js"}}
|
||||
{{js "js/device-stats.js"}}
|
||||
{{/zone}}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue