Commit a4057635 authored by Boris Kocherov's avatar Boris Kocherov

[erp5_only_office] xmla: xmla_client improved olap_wizard and remote_settings...

[erp5_only_office] xmla: xmla_client improved olap_wizard and remote_settings forms completely use new xmla_client
parent 6b072483
......@@ -416,6 +416,24 @@ DocsAPI.DocEditor.version = function () {
}
});
})
.allowPublicAcquisition("xmla_request", function (arr) {
return this.getDeclaredGadget("xmla_client")
.push(function (g) {
return g.request(arr[0], arr[1], arr[2]);
})
.push(undefined, function (err) {
console.error(err);
});
})
.allowPublicAcquisition("xmla_getLevels", function (arr) {
return this.getDeclaredGadget("xmla_client")
.push(function (g) {
return g.getLevels(arr[0], arr[1], arr[2]);
})
.push(undefined, function (err) {
console.error(err);
});
})
// methods emulating Gateway used for connection with ooffice begin.
.declareMethod('appReady', function () {
......
......@@ -9,8 +9,6 @@
<script src="../rsvp.js"></script>
<script src="../renderjs.js"></script>
<script src="../jio.js"></script>
<script src="web-apps/vendor/xmla4js/Xmla-compiled.js"></script>
<script src="olap_wizard.js"></script>
</head>
......
/*jslint nomen: true, maxlen: 200, indent: 2*/
/*global rJS, console, window, document, RSVP, Xmla*/
/*global rJS, console, window, document, RSVP*/
(function (window, rJS) {
"use strict";
function getCurrentConnectionSettings(g, gadget) {
var connections;
return RSVP.Queue()
.push(function () {
return g.getRemoteSettings();
})
.push(function (c) {
connections = c;
return gadget.getContent("/connection_name");
})
.push(function (connection_name) {
return connections[connection_name];
})
.push(undefined, function (err) {
console.error(err);
});
}
function get_used_dimensions(g) {
return g.getContent()
.push(function (v) {
......@@ -53,159 +35,87 @@
return dimensions;
});
}
function xmla_request(func, prop) {
var xmla = new Xmla({async: true});
prop = JSON.parse(JSON.stringify(prop));
// return function () {
return new RSVP.Queue()
.push(function () {
return new RSVP.Promise(function (resolve, reject) {
prop.success = function (xmla, options, response) {
resolve(response);
};
prop.error = function (xmla, options, response) {
reject(response);
};
xmla[func](prop);
});
});
}
function xmla_request_retry(func, settings) {
var queue,
urls = settings.urls || [""],
i;
function make_request(url) {
return function (error) {
settings.prop.url = url;
return xmla_request(func, settings.prop)
.push(undefined, function (response) {
// fix mondrian Internal and Sql errors
if (response) {
switch (response["code"]) {
case "SOAP-ENV:Server.00HSBE02":
case "SOAP-ENV:00UE001.Internal Error":
// rarely server error, so try again
return xmla_request(func, settings.prop);
}
}
throw response;
});
};
}
queue = make_request(urls[0])();
for (i = 1; i < urls.length; i += 1) {
queue.push(undefined, make_request(urls[i]));
}
return queue;
}
function discoverDimensions(schema, used_dimensions, opt) {
return xmla_request_retry("discoverMDDimensions", opt)
function discoverDimensions(g, connection_name, used_dimensions) {
return g.request("discoverMDDimensions", connection_name)
.push(undefined, function (error) {
console.log(error);
})
.push(function (response) {
var arr = [],
i,
row;
if (response && response.numRows > 0) {
while (response.hasMoreRows()) {
row = response.readAsObject();
if (row["DIMENSION_TYPE"] !== 2) {
if (used_dimensions.indexOf(row["DIMENSION_UNIQUE_NAME"]) < 0) {
arr.push({
const: row["DIMENSION_UNIQUE_NAME"] || undefined,
title: row["DIMENSION_NAME"] || undefined
});
}
}
response.nextRow();
for (i = 0; i < response.length; i += 1) {
row = response[i];
if (row["DIMENSION_TYPE"] !== 2 &&
used_dimensions.indexOf(row["DIMENSION_UNIQUE_NAME"]) < 0) {
arr.push({
const: row["DIMENSION_UNIQUE_NAME"] || undefined,
title: row["DIMENSION_NAME"] || undefined
});
}
}
if (arr.length !== 0) {
schema.properties.dimension = {
title: " ",
oneOf: arr
};
}
return arr;
});
}
function discoverHierarchies(schema, opt) {
return xmla_request_retry("discoverMDHierarchies", opt)
function discoverHierarchies(g, connection_name, opt) {
return g.request("discoverMDHierarchies", connection_name, opt)
.push(undefined, function (error) {
console.log(error);
})
.push(function (response) {
var arr = [],
i,
row;
if (response && response.numRows > 0) {
while (response.hasMoreRows()) {
row = response.readAsObject();
arr.push({
const: row["HIERARCHY_UNIQUE_NAME"] || undefined,
title: row["HIERARCHY_NAME"] || undefined
});
response.nextRow();
}
}
if (arr.length !== 0) {
schema.properties.hierarchy = {
title: " ",
oneOf: arr
};
for (i = 0; i < response.length; i += 1) {
row = response[i];
arr.push({
const: row["HIERARCHY_UNIQUE_NAME"] || undefined,
title: row["HIERARCHY_NAME"] || undefined
});
}
return arr;
});
}
function discoverLevels(schema, opt) {
return xmla_request_retry("discoverMDLevels", opt)
function discoverLevels(g, connection_name, opt) {
return g.getLevels(connection_name, opt)
.push(undefined, function (error) {
console.log(error);
})
.push(function (response) {
var arr = [],
i,
row;
if (response && response.numRows > 0) {
while (response.hasMoreRows()) {
row = response.readAsObject();
if (row["LEVEL_TYPE"] !== 1) { // exclude all level type
arr.push({
const: row["LEVEL_UNIQUE_NAME"] || undefined,
title: row["LEVEL_NAME"] || undefined
});
}
response.nextRow();
for (i = 0; i < response.length; i += 1) {
row = response[i];
if (
row["LEVEL_CARDINALITY"] < 150 &&
row["LEVEL_TYPE"] !== 1 // exclude all level type
) {
arr.push({
const: row["LEVEL_UNIQUE_NAME"] || undefined,
title: row["LEVEL_NAME"] || undefined
});
}
}
if (arr.length !== 0) {
schema.properties.level = {
title: " ",
oneOf: arr
};
}
return arr;
});
}
function generateChoiceSchema(connection_settings, used_dimensions, choice_settings) {
function generateChoiceSchema(g, connection_name, used_dimensions, choice_settings) {
var schema = {
"type": "object",
"additionalProperties": false,
"properties": {}
},
current_dimension;
if (!connection_settings) {
if (!connection_name) {
return new RSVP.Queue()
.push(function () {
return schema;
});
}
if (!connection_settings.hasOwnProperty('properties')) {
connection_settings.properties = {};
}
if (!choice_settings) {
choice_settings = {};
}
......@@ -219,47 +129,46 @@
return new RSVP.Queue()
.push(function () {
var tasks = [discoverDimensions(schema, used_dimensions, {
urls: connection_settings.urls,
prop: {
restrictions: {
CATALOG_NAME: connection_settings.properties.Catalog,
CUBE_NAME: connection_settings.properties.Cube
}
}
})];
var tasks = [discoverDimensions(g, connection_name, used_dimensions)];
if (choice_settings.dimension) {
tasks.push(
discoverHierarchies(schema, {
urls: connection_settings.urls,
prop: {
restrictions: {
CATALOG_NAME: connection_settings.properties.Catalog,
CUBE_NAME: connection_settings.properties.Cube,
DIMENSION_UNIQUE_NAME: choice_settings.dimension
}
discoverHierarchies(g, connection_name,{prop: {
restrictions: {
DIMENSION_UNIQUE_NAME: choice_settings.dimension
}
})
}})
);
}
if (choice_settings.hierarchy) {
tasks.push(discoverLevels(schema, {
urls: connection_settings.urls,
prop: {
restrictions: {
CATALOG_NAME: connection_settings.properties.Catalog,
CUBE_NAME: connection_settings.properties.Cube,
DIMENSION_UNIQUE_NAME: choice_settings.dimension,
HIERARCHY_UNIQUE_NAME: choice_settings.hierarchy
}
}
tasks.push(discoverLevels(g, connection_name, {
DIMENSION_UNIQUE_NAME: choice_settings.dimension,
HIERARCHY_UNIQUE_NAME: choice_settings.hierarchy
}));
}
return RSVP.all(tasks);
})
.push(function () {
.push(function (arr) {
if (arr[0].length !== 0) {
schema.properties.dimension = {
title: " ",
oneOf: arr[0]
};
}
if (arr[1] && arr[1].length !== 0) {
schema.properties.hierarchy = {
title: " ",
oneOf: arr[1]
};
}
if (arr[2] && arr[2].length !== 0) {
schema.properties.level = {
title: " ",
oneOf: arr[2]
};
}
return schema;
})
.push(undefined, function () {
......@@ -277,6 +186,8 @@
});
})
.declareAcquiredMethod("getRemoteSettings", "getRemoteSettings")
.declareAcquiredMethod("request", "xmla_request")
.declareAcquiredMethod("getLevels", "xmla_getLevels")
.allowPublicAcquisition("notifyValid", function (arr, scope) {
})
.allowPublicAcquisition("notifyInvalid", function (arr, scope) {
......@@ -328,10 +239,10 @@
queue = RSVP.Queue();
}
function rerender_once(connection_settings, sub_gadget) {
function rerender_once(connection_name, sub_gadget) {
return sub_gadget.getContent()
.push(function (content) {
return generateChoiceSchema(connection_settings, used_diemensions, content);
return generateChoiceSchema(g, connection_name, used_diemensions, content);
})
.push(function (schema) {
return gadget_settings.rerender({
......@@ -349,25 +260,25 @@
.push(function (gadget) {
gadget_settings = gadget;
return RSVP.all([
getCurrentConnectionSettings(g, gadget),
gadget.getContent("/connection_name"),
gadget.getSubGadget(sub_scope)
]);
})
.push(function (arr) {
var connection_settings = arr[0],
var connection_name = arr[0],
sub_gadget = arr[1];
return rerender_once(connection_settings, sub_gadget)
return rerender_once(connection_name, sub_gadget)
.push(function (changed) {
if (changed && changed.length > 0) {
if (changed.indexOf('/dimension') >= 0) {
return allRerender();
}
return rerender_once(connection_settings, sub_gadget);
return rerender_once(connection_name, sub_gadget);
}
})
.push(function (changed) {
if (changed && changed.length > 0) {
return rerender_once(connection_settings, sub_gadget);
return rerender_once(connection_name, sub_gadget);
}
});
});
......@@ -441,20 +352,18 @@
return new RSVP.Queue()
.push(function () {
return RSVP.all([
g.getRemoteSettings(),
g.getContent("/connection_name"),
g.getContent(path),
get_used_dimensions(g)
]);
})
.push(function (arr) {
var connection_settings,
choice_settings;
connection_settings = arr[0][arr[1]];
var choice_settings;
if (path !== "/columns/" && path !== "/rows/") {
choice_settings = arr[2];
}
return generateChoiceSchema(connection_settings, arr[3], choice_settings);
return generateChoiceSchema(g, arr[0], arr[1], choice_settings);
});
}
throw new Error("urn: '" + url + "' not supported");
......
......@@ -9,8 +9,6 @@
<script src="../rsvp.js"></script>
<script src="../renderjs.js"></script>
<script src="../jio.js"></script>
<script src="web-apps/vendor/xmla4js/Xmla-compiled.js"></script>
<script src="remote_settings.js"></script>
</head>
......
/*jslint nomen: true, maxlen: 200, indent: 2*/
/*global rJS, console, window, document, RSVP, Xmla*/
/*global rJS, console, window, document, RSVP*/
(function (window, rJS) {
"use strict";
function xmla_request(func, prop) {
var xmla = new Xmla({async: true});
prop = JSON.parse(JSON.stringify(prop));
// return function () {
return new RSVP.Queue()
.push(function () {
return new RSVP.Promise(function (resolve, reject) {
prop.success = function (xmla, options, response) {
resolve(response);
};
prop.error = function (xmla, options, response) {
reject(response);
};
xmla[func](prop);
});
});
}
function xmla_request_retry(func, settings) {
var queue,
urls = settings.urls || [""],
i;
function make_request(url) {
return function (error) {
settings.prop.url = url;
return xmla_request(func, settings.prop)
.push(undefined, function (response) {
// fix mondrian Internal and Sql errors
if (response) {
switch (response["code"]) {
case "SOAP-ENV:Server.00HSBE02":
case "SOAP-ENV:00UE001.Internal Error":
// rarely server error, so try again
return xmla_request(func, settings.prop);
}
}
throw response;
});
};
}
queue = make_request(urls[0])();
for (i = 1; i < urls.length; i += 1) {
queue.push(undefined, make_request(urls[i]));
}
return queue;
}
function discoverDataSources(schema, opt) {
return xmla_request_retry("discoverDataSources", opt)
function discoverDataSources(g, opt) {
return g.request("discoverDataSources", undefined, opt)
.push(undefined, function (error) {
console.log(error);
})
.push(function (response) {
if (response && response.numRows > 0) {
schema.properties.DataSourceInfo = {
title: " ",
oneOf: []
};
var arr = schema.properties.DataSourceInfo.oneOf;
while (response.hasMoreRows()) {
arr.push({
const: response["getDataSourceInfo"]() || undefined,
title: response["getDataSourceName"]() || undefined,
description: response["getDataSourceDescription"]() || undefined
});
response.nextRow();
}
if (!response) {
return;
}
var arr = [],
i,
row;
for (i = 0; i < response.length; i += 1) {
row = response[i];
arr.push({
const: row["DataSourceInfo"] || undefined,
title: row["DataSourceName"] || undefined,
description: row["DataSourceDescription"] || undefined
});
}
return arr;
});
}
function discoverDBCatalogs(schema, opt) {
return xmla_request_retry("discoverDBCatalogs", opt)
function discoverDBCatalogs(g, opt) {
return g.request("discoverDBCatalogs", undefined, opt)
.push(undefined, function (error) {
console.log(error);
})
.push(function (response) {
if (response && response.numRows > 0) {
schema.properties.Catalog = {
title: " ",
oneOf: []
};
var arr = schema.properties.Catalog.oneOf;
while (response.hasMoreRows()) {
arr.push({
const: response["getCatalogName"]() || undefined,
title: response["getCatalogName"]() || undefined
});
response.nextRow();
}
if (!response) {
return;
}
var arr = [],
i,
row;
for (i = 0; i < response.length; i += 1) {
row = response[i];
arr.push({
const: row["CATALOG_NAME"] || undefined,
title: row["CATALOG_NAME"] || undefined
});
}
return arr;
});
}
function discoverMDCubes(schema, opt) {
return xmla_request_retry("discoverMDCubes", opt)
function discoverMDCubes(g, opt) {
return g.request("discoverMDCubes", undefined, opt)
.push(undefined, function (error) {
console.log(error);
})
.push(function (response) {
if (response && response.numRows > 0) {
schema.properties.Cube = {
title: " ",
oneOf: []
};
var arr = schema.properties.Cube.oneOf;
while (response.hasMoreRows()) {
arr.push({
const: response["getCubeName"]() || undefined,
title: response["getCubeName"]() || undefined
// title: response["getCatalogName"]() || undefined
});
response.nextRow();
}
if (!response) {
return;
}
var arr = [],
i,
row;
for (i = 0; i < response.length; i += 1) {
row = response[i];
arr.push({
const: row["CUBE_NAME"] || undefined,
title: row["CUBE_NAME"] || undefined
});
}
return arr;
});
}
function generateSchema(settings) {
function generateSchema(g, settings) {
var schema = {
"type": "object",
"additionalProperties": false,
......@@ -147,11 +97,11 @@
return new RSVP.Queue()
.push(function () {
return RSVP.all([
discoverDataSources(schema, {
discoverDataSources(g, {
urls: settings.urls,
prop: {}
}),
discoverDBCatalogs(schema, {
discoverDBCatalogs(g, {
urls: settings.urls,
prop: {
properties: {
......@@ -159,7 +109,7 @@
}
}
}),
discoverMDCubes(schema, {
discoverMDCubes(g, {
urls: settings.urls,
prop: {
properties: {
......@@ -170,39 +120,27 @@
})
]);
})
.push(function () {
return schema;
});
}
function decodeJsonPointer(_str) {
// https://tools.ietf.org/html/rfc6901#section-5
return _str.replace(/~1/g, '/').replace(/~0/g, '~');
}
function convertOnMultiLevel(d, key, value) {
var ii,
kk,
key_list = key.split("/");
for (ii = 1; ii < key_list.length; ii += 1) {
kk = decodeJsonPointer(key_list[ii]);
if (ii === key_list.length - 1) {
if (value !== undefined) {
d[kk] = value[0];
} else {
return d[kk];
.push(function (arr) {
if (arr[0] && arr[0].length !== 0) {
schema.properties.DataSourceInfo = {
title: " ",
oneOf: arr[0]
};
}
} else {
if (!d.hasOwnProperty(kk)) {
if (value !== undefined) {
d[kk] = {};
} else {
return;
}
if (arr[1] && arr[1].length !== 0) {
schema.properties.Catalog = {
title: " ",
oneOf: arr[1]
};
}
d = d[kk];
}
}
if (arr[2] && arr[2].length !== 0) {
schema.properties.Cube = {
title: " ",
oneOf: arr[2]
};
}
return schema;
});
}
rJS(window)
......@@ -210,6 +148,8 @@
g.props = {};
g.props.xmla_connections = {};
})
.declareAcquiredMethod("request", "xmla_request")
.declareAcquiredMethod("getLevels", "xmla_getLevels")
.allowPublicAcquisition("notifyValid", function (arr, scope) {
})
.allowPublicAcquisition("notifyInvalid", function (arr, scope) {
......@@ -245,7 +185,7 @@
return gadget.getContent(settings_path);
})
.push(function (settings) {
return generateSchema(settings);
return generateSchema(g, settings);
})
.push(function (schema) {
return gadget_settings.rerender({
......@@ -289,14 +229,15 @@
return g.notifyChange();
})
.allowPublicAcquisition("resolveExternalReference", function (arr) {
var url = arr[0],
var g = this,
url = arr[0],
schema_path = arr[1],
path = arr[2],
connection_path = path.split('/').slice(0, -1).join('/');
if ("urn:jio:properties_from_xmla.connection.json" === url) {
return this.getContent(connection_path)
.push(function (settings) {
return generateSchema(settings);
return generateSchema(g, settings);
});
}
throw new Error("urn: '" + url + "' not supported");
......
......@@ -5,6 +5,18 @@
"use strict";
function getFromCache(cache, key) {
if (cache[key].hasOwnProperty("push") &&
typeof cache[key].push === "function") {
return cache[key]
.push(function () {
return cache[key];
});
} else {
return cache[key];
}
}
function xmla_request(func, prop) {
var xmla = new Xmla({async: true});
prop = JSON.parse(JSON.stringify(prop));
......@@ -54,89 +66,60 @@
return queue;
}
function discoverDimensions(schema, used_dimensions, opt) {
return xmla_request_retry("discoverMDDimensions", opt)
.push(undefined, function (error) {
console.log(error);
})
.push(function (response) {
var arr = [],
row;
if (response && response.numRows > 0) {
while (response.hasMoreRows()) {
row = response.readAsObject();
if (row["DIMENSION_TYPE"] !== 2) {
if (used_dimensions.indexOf(row["DIMENSION_UNIQUE_NAME"]) < 0) {
arr.push({
const: row["DIMENSION_UNIQUE_NAME"] || undefined,
title: row["DIMENSION_NAME"] || undefined
});
}
}
response.nextRow();
}
function request(g, function_name, settings, connection_name) {
var queue;
if (connection_name) {
queue = g.getConnectionSettings(connection_name);
} else {
queue = RSVP.Queue();
}
return queue
.push(function (connection_settings) {
if (!settings) {
settings = {};
}
if (arr.length !== 0) {
schema.properties.dimension = {
title: " ",
oneOf: arr
};
if (!settings.prop) {
settings.prop = {};
}
});
}
function discoverHierarchies(schema, opt) {
return xmla_request_retry("discoverMDHierarchies", opt)
.push(undefined, function (error) {
console.log(error);
})
.push(function (response) {
var arr = [],
row;
if (response && response.numRows > 0) {
while (response.hasMoreRows()) {
row = response.readAsObject();
arr.push({
const: row["HIERARCHY_UNIQUE_NAME"] || undefined,
title: row["HIERARCHY_NAME"] || undefined
});
response.nextRow();
}
if (!settings.prop.restrictions) {
settings.prop.restrictions = {};
}
if (arr.length !== 0) {
schema.properties.hierarchy = {
title: " ",
oneOf: arr
};
if (connection_settings) {
settings.urls = connection_settings.urls;
settings.prop.restrictions.CATALOG_NAME = connection_settings.properties.Catalog;
settings.prop.restrictions.CUBE_NAME = connection_settings.properties.Cube;
}
return xmla_request_retry(function_name, settings);
});
}
function discoverLevels(schema, opt) {
return xmla_request_retry("discoverMDLevels", opt)
.push(undefined, function (error) {
console.log(error);
})
.push(function (response) {
var arr = [],
row;
if (response && response.numRows > 0) {
while (response.hasMoreRows()) {
row = response.readAsObject();
arr.push({
const: row["LEVEL_UNIQUE_NAME"] || undefined,
title: row["LEVEL_NAME"] || undefined
});
response.nextRow();
}
}
if (arr.length !== 0) {
schema.properties.level = {
title: " ",
oneOf: arr
};
function levelDiscovery(g, connection_name, row) {
var level_uname = row["LEVEL_UNIQUE_NAME"],
cache = g.props.cache[connection_name],
queue,
LEVEL_CARDINALITY = row.LEVEL_CARDINALITY;
if (LEVEL_CARDINALITY < 0) {
// XXX LEVEL_CARDINALITY broken in saiku xmla
queue = g.getMembersOnLevel(connection_name, level_uname);
} else {
queue = RSVP.Queue();
}
queue
.push(function (members) {
var level;
if (LEVEL_CARDINALITY < 0 && members) {
LEVEL_CARDINALITY = members.length;
}
level = {
LEVEL_UNIQUE_NAME: row.LEVEL_UNIQUE_NAME,
LEVEL_TYPE: row.LEVEL_TYPE,
LEVEL_NAME: row.LEVEL_NAME || undefined,
LEVEL_CARDINALITY: LEVEL_CARDINALITY,
};
cache.levels[level_uname] = level;
return level;
});
return queue;
}
rJS(window)
......@@ -184,43 +167,92 @@
if (m_dict[key] !== null) {
g.props.cache[key] = {
members: {},
levels: {}
levels: {},
membersOnLevel: {}
};
g.props.connections[key] = JSON.parse(m_dict[key]);
}
}
}
})
.declareMethod("request", function (function_name, settings, connection_name) {
var queue;
if (connection_name) {
queue = this.getConnectionSettings(connection_name);
} else {
queue = RSVP.Queue();
}
return queue
.push(function (connection_settings) {
if (!settings) {
settings = {};
}
if (connection_settings) {
settings.urls = connection_settings.urls;
settings.prop.restrictions.CATALOG_NAME = connection_settings.properties.Catalog;
settings.prop.restrictions.CUBE_NAME = connection_settings.properties.Cube;
.declareMethod("request", function (function_name, connection_name, settings) {
return request(this, function_name, settings, connection_name)
.push(function (response) {
var ret = [];
while (response.hasMoreRows()) {
ret.push(response.readAsObject());
response.nextRow();
}
return xmla_request_retry(function_name, settings);
return ret;
})
.push(undefined, function (error) {
console.error(error);
});
})
.declareMethod("getMembersOnLevel", function (connection_name, level_uname) {
.declareMethod("getLevel", function (connection_name, level_uname) {
var g = this,
cache = g.props.cache[connection_name];
cache = g.props.cache[connection_name],
queue;
if (cache.levels.hasOwnProperty(level_uname)) {
return cache.levels[level_uname];
return getFromCache(cache.levels, level_uname);
}
return g.request("discoverMDMembers", {
queue = g.getLevels(connection_name, {
LEVEL_UNIQUE_NAME: level_uname
})
.push(function () {
return cache.levels[level_uname];
})
.push(undefined, function (err) {
console.error(err);
});
cache.levels[level_uname] = queue;
return queue;
})
.declareMethod("getLevels", function (connection_name, restrictions) {
var g = this,
cache = g.props.cache[connection_name];
return request(g, "discoverMDLevels", {
prop: {
restrictions: restrictions
}
}, connection_name)
.push(function (response) {
var ret = [],
row,
level,
level_uname;
if (response && response.numRows > 0) {
while (response.hasMoreRows()) {
row = response.readAsObject();
level_uname = row["LEVEL_UNIQUE_NAME"];
if (cache.levels.hasOwnProperty(level_uname)) {
if (cache.levels[level_uname].hasOwnProperty("LEVEL_UNIQUE_NAME")) {
level = cache.levels[level_uname];
} else {
level = levelDiscovery(g, connection_name, row);
}
} else {
level = levelDiscovery(g, connection_name, row);
cache.levels[level_uname] = level;
}
ret.push(level);
response.nextRow();
}
}
return RSVP.all(ret);
})
.push(undefined, function (err) {
console.error(err);
});
})
.declareMethod("getMembersOnLevel", function (connection_name, level_uname) {
var g = this,
cache = g.props.cache[connection_name],
queue;
if (cache.membersOnLevel.hasOwnProperty(level_uname)) {
return getFromCache(cache.membersOnLevel, level_uname);
}
queue = request(g,"discoverMDMembers", {
prop: {
restrictions: {
LEVEL_UNIQUE_NAME: level_uname
......@@ -231,7 +263,7 @@
var uname,
member,
i,
level = [];
members = [];
while (r.hasMoreRows()) {
uname = r["getMemberUniqueName"]();
if (level_uname !== r["getLevelUniqueName"]()) {
......@@ -246,7 +278,7 @@
};
r.nextRow();
cache.members[uname] = member;
level.push(member);
members.push(member);
}
function compare(a, b) {
......@@ -259,21 +291,27 @@
return 0;
}
level.sort(compare);
for (i = 0; i < level.length; i += 1) {
level[i].level_index = i;
members.sort(compare);
for (i = 0; i < members.length; i += 1) {
members[i].level_index = i;
}
cache.levels[level_uname] = level;
return level;
cache.membersOnLevel[level_uname] = members;
return members;
})
.push(undefined, function (err) {
console.error(err);
});
}, {mutex: 'getMembersOnLevel'})
cache.membersOnLevel[level_uname] = queue;
return queue;
})
.declareMethod("getMember", function (connection_name, memeber_uname) {
var g = this,
cache = g.props.cache[connection_name];
cache = g.props.cache[connection_name],
queue;
if (cache.members.hasOwnProperty(memeber_uname)) {
return cache.members[memeber_uname];
return getFromCache(cache.members, memeber_uname);
}
return g.request("discoverMDMembers", {
queue = request(g, "discoverMDMembers", {
prop: {
restrictions: {
MEMBER_UNIQUE_NAME: memeber_uname,
......@@ -283,18 +321,25 @@
}
}, connection_name)
.push(function (r) {
if (r.length === 0) {
if (r.rowCount() === 0) {
return;
}
return g.getMembersOnLevel(connection_name, r["getLevelUniqueName"]());
})
.push(function (level) {
if (!level) {
.push(function (members) {
if (!members) {
// cache.members[memeber_uname] = false;
return;
}
return cache.members[memeber_uname];
})
.push(undefined, function (err) {
console.error(err);
// throw err;
});
}, {mutex: 'getMember'})
cache.members[memeber_uname] = queue;
return queue;
})
.declareMethod("getMemberWithOffset", function (connection_name, memeber_uname, offset) {
var g = this,
member;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment