@sis-cc/dotstatsuite-components 13.3.0 → 13.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.OBS_TYPE_STRING = exports.OBS_TYPE_NUMERICAL_STRING = exports.OBS_TYPE_NUMBER = exports.V8_SDMX_JSON = exports.DEFAULT_MAJOR_ATTRIBUTES = exports.DIMENSION_DISPLAY_PARTS = exports.DEFAULT_REJECTED_SUBTITLE_IDS = exports.DEFAULT_REJECTED_UPR_VALUES_IDS = exports.DEFAULT_UPR_IDS = exports.FREQ_M = exports.FREQ_Q = exports.FREQ_S = exports.FREQ_A = exports.TYPES = exports.VALUES = exports.PERCENT = exports.CHORO = exports.STACKED_ROW = exports.STACKED_BAR = exports.V_SYMBOL = exports.H_SYMBOL = exports.TIMELINE = exports.SCATTER = exports.ROW = exports.BAR = undefined;
6
+ exports.REPYEARSTART = exports.REPORTING_YEAR_START_DAY = exports.OBS_TYPE_STRING = exports.OBS_TYPE_NUMERICAL_STRING = exports.OBS_TYPE_NUMBER = exports.V8_SDMX_JSON = exports.DEFAULT_MAJOR_ATTRIBUTES = exports.DIMENSION_DISPLAY_PARTS = exports.DEFAULT_REJECTED_SUBTITLE_IDS = exports.DEFAULT_REJECTED_UPR_VALUES_IDS = exports.DEFAULT_UPR_IDS = exports.FREQ_M = exports.FREQ_Q = exports.FREQ_S = exports.FREQ_A = exports.TYPES = exports.VALUES = exports.PERCENT = exports.CHORO = exports.STACKED_ROW = exports.STACKED_BAR = exports.V_SYMBOL = exports.H_SYMBOL = exports.TIMELINE = exports.SCATTER = exports.ROW = exports.BAR = undefined;
7
7
 
8
8
  var _defineProperty2 = require('babel-runtime/helpers/defineProperty');
9
9
 
@@ -63,4 +63,6 @@ var V8_SDMX_JSON = exports.V8_SDMX_JSON = "application/vnd.sdmx.data+json;versio
63
63
 
64
64
  var OBS_TYPE_NUMBER = exports.OBS_TYPE_NUMBER = 'OBS_TYPE_NUMBER';
65
65
  var OBS_TYPE_NUMERICAL_STRING = exports.OBS_TYPE_NUMERICAL_STRING = 'OBS_TYPE_NUMERICAL_STRING';
66
- var OBS_TYPE_STRING = exports.OBS_TYPE_STRING = 'OBS_TYPE_STRING';
66
+ var OBS_TYPE_STRING = exports.OBS_TYPE_STRING = 'OBS_TYPE_STRING';
67
+ var REPORTING_YEAR_START_DAY = exports.REPORTING_YEAR_START_DAY = 'REPORTING_YEAR_START_DAY';
68
+ var REPYEARSTART = exports.REPYEARSTART = 'REPYEARSTART';
@@ -17,6 +17,8 @@ var _ramda = require('ramda');
17
17
 
18
18
  var R = _interopRequireWildcard(_ramda);
19
19
 
20
+ var _constants = require('../constants');
21
+
20
22
  function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
21
23
 
22
24
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -32,7 +34,11 @@ var getReportingYearStart = exports.getReportingYearStart = function getReportin
32
34
  return [].concat((0, _toConsumableArray3.default)(dataSet), (0, _toConsumableArray3.default)(observation), (0, _toConsumableArray3.default)(series));
33
35
  })(sdmxJson);
34
36
 
35
- var reportYearStartAttr = R.find(R.propEq('id', 'REPORTING_YEAR_START_DAY'), attributes) || {};
37
+ var reportYearStartAttr = R.find(function (_ref2) {
38
+ var id = _ref2.id;
39
+
40
+ return id === _constants.REPORTING_YEAR_START_DAY || id === _constants.REPYEARSTART;
41
+ }, attributes) || {};
36
42
  var reportYearStart = R.pathOr('--01-01', ['values', 0, 'name'], reportYearStartAttr);
37
43
 
38
44
  var _R$match = R.match(/[\d]{2}/g, reportYearStart),
@@ -9,6 +9,8 @@ var _ramda = require('ramda');
9
9
 
10
10
  var R = _interopRequireWildcard(_ramda);
11
11
 
12
+ var _constants = require('../../constants');
13
+
12
14
  function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
13
15
 
14
16
  var registerAttrId = function registerAttrId(path, id) {
@@ -63,6 +65,7 @@ var parseAttributes = exports.parseAttributes = function parseAttributes(_ref) {
63
65
  if (R.isEmpty(values) || !R.propOr(true, 'display', attribute) || R.includes(attribute.id, R.propOr([], 'units', customAttributes))) {
64
66
  return acc;
65
67
  }
68
+ if (R.includes(attribute.id, [_constants.REPORTING_YEAR_START_DAY, _constants.REPYEARSTART])) return acc;
66
69
 
67
70
  var registers = getAttributeRegisters(R.pipe(R.assoc('index', attributeIndex), R.over(R.lensProp('values'), R.map(function (value) {
68
71
  if (!R.propOr(true, 'display', value)) {
@@ -27,12 +27,13 @@ var getMSDInformations = exports.getMSDInformations = function getMSDInformation
27
27
  var parseAttributes = function parseAttributes(parent) {
28
28
  return R.reduce(function (acc, attribute) {
29
29
  var id = attribute.id;
30
+ var hierarchicalId = parent === '#ROOT' ? id : parent + '.' + id;
30
31
  var format = R.path(['localRepresentation', 'textFormat', 'textType'], attribute);
31
32
  if (R.has('metadataAttributes', attribute)) {
32
- var collection = parseAttributes(attribute.id)(attribute.metadataAttributes);
33
- return (0, _extends4.default)({}, acc, collection, (0, _defineProperty3.default)({}, id, { format: format, parent: parent }));
33
+ var collection = parseAttributes(hierarchicalId)(attribute.metadataAttributes);
34
+ return (0, _extends4.default)({}, acc, collection, (0, _defineProperty3.default)({}, hierarchicalId, { format: format, parent: parent, id: id }));
34
35
  }
35
- return R.assoc(id, { format: format, parent: parent }, acc);
36
+ return R.assoc(hierarchicalId, { format: format, parent: parent, id: id }, acc);
36
37
  }, {});
37
38
  };
38
39
 
@@ -5,6 +5,10 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.parseMetadataSeries = undefined;
7
7
 
8
+ var _extends2 = require('babel-runtime/helpers/extends');
9
+
10
+ var _extends3 = _interopRequireDefault(_extends2);
11
+
8
12
  var _ramda = require('ramda');
9
13
 
10
14
  var R = _interopRequireWildcard(_ramda);
@@ -13,6 +17,8 @@ var _dotstatsuiteSdmxjs = require('@sis-cc/dotstatsuite-sdmxjs');
13
17
 
14
18
  function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
15
19
 
20
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
+
16
22
  var dimensionValueDisplay = function dimensionValueDisplay(display) {
17
23
  return function (data) {
18
24
  if (display === 'code') {
@@ -60,22 +66,50 @@ var parseMetadataSeries = exports.parseMetadataSeries = function parseMetadataSe
60
66
  return R.propOr('', '__index', originalVal);
61
67
  }), R.join(':'))(serieKey);
62
68
 
63
- var attributes = R.addIndex(R.reduce)(function (acc, valueIndex, attrIndex) {
64
- if (R.isNil(valueIndex)) {
69
+ var attributes = R.pipe(R.addIndex(R.reduce)(function (acc, valueIndex, attrIndex) {
70
+ var attribute = R.nth(attrIndex, metadataAttributes);
71
+ if (R.isNil(valueIndex) && !attribute.isPresentational) {
65
72
  return acc;
66
73
  }
67
- var attribute = R.nth(attrIndex, metadataAttributes);
68
- var label = dimensionValueDisplay(options.display)(attribute);
74
+ var attrOptions = R.pathOr({}, ['attributes', attribute.id], options);
75
+ var id = attrOptions.id;
76
+ var label = dimensionValueDisplay(options.display)((0, _extends3.default)({}, attribute, { id: id }));
69
77
 
70
- var value = R.prop('value', R.nth(valueIndex, attribute.values || []));
78
+ var _value = R.prop('value', R.nth(valueIndex, attribute.values || []));
79
+ var value = R.is(Object, _value) ? R.prop(options.locale, _value) : _value;
71
80
 
72
- return R.append({
81
+ return R.append((0, _extends3.default)({}, R.isNil(value) ? {} : { value: value }, {
73
82
  id: attribute.id,
74
83
  label: label,
75
- value: R.is(Object, value) ? R.prop(options.locale, value) : value,
76
- handlerProps: R.pathOr({}, ['attributes', attribute.id], options)
77
- }, acc);
78
- }, [], metaIndexes);
84
+ handlerProps: R.omit(['id'], R.pathOr({}, ['attributes', attribute.id], options))
85
+ }), acc);
86
+ }, []), function (attributes) {
87
+ // missing parents in metadata response
88
+ var groupedAttrs = R.groupBy(R.pathOr('#ROOT', ['handlerProps', 'parent']), attributes);
89
+ var indexedAttrs = R.indexBy(R.prop('id'), attributes);
90
+
91
+ return R.reduce(function (acc, id) {
92
+ if (R.has(id, indexedAttrs) || id === '#ROOT') {
93
+ return acc;
94
+ }
95
+ return R.append({
96
+ id: id,
97
+ label: dimensionValueDisplay(options.display)({ id: id }),
98
+ handlerProps: R.omit(['id'], R.pathOr({}, ['attributes', id], options))
99
+ }, acc);
100
+ }, attributes, R.keys(groupedAttrs));
101
+ }, function (attributes) {
102
+ var groupedAttrs = R.groupBy(R.pathOr('#ROOT', ['handlerProps', 'parent']), attributes);
103
+ var makeTree = R.map(function (attr) {
104
+ if (R.has(attr.id, groupedAttrs)) {
105
+ var children = makeTree(R.prop(attr.id, groupedAttrs));
106
+ return R.assoc('children', children, attr);
107
+ }
108
+ return attr;
109
+ });
110
+
111
+ return makeTree(R.propOr([], '#ROOT', groupedAttrs));
112
+ })(metaIndexes);
79
113
 
80
114
  return R.assoc(evolvedKey, attributes, acc);
81
115
  }, {}, R.keys(series));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sis-cc/dotstatsuite-components",
3
3
  "description": "Set components based on React.",
4
- "version": "13.3.0",
4
+ "version": "13.4.1",
5
5
  "main": "lib/index.js",
6
6
  "author": "OECD",
7
7
  "license": "MIT",
@@ -59,3 +59,6 @@ export const V8_SDMX_JSON = "application/vnd.sdmx.data+json;version=1.0.0-wd";
59
59
  export const OBS_TYPE_NUMBER = 'OBS_TYPE_NUMBER';
60
60
  export const OBS_TYPE_NUMERICAL_STRING = 'OBS_TYPE_NUMERICAL_STRING';
61
61
  export const OBS_TYPE_STRING = 'OBS_TYPE_STRING';
62
+ export const REPORTING_YEAR_START_DAY = 'REPORTING_YEAR_START_DAY';
63
+ export const REPYEARSTART = 'REPYEARSTART';
64
+
@@ -1,4 +1,5 @@
1
1
  import * as R from 'ramda';
2
+ import { REPORTING_YEAR_START_DAY, REPYEARSTART } from '../constants';
2
3
 
3
4
  export const getReportingYearStart = (sdmxJson) => {
4
5
  const attributes = R.pipe(
@@ -6,7 +7,9 @@ export const getReportingYearStart = (sdmxJson) => {
6
7
  ({ dataSet=[], observation=[], series=[] }) => [...dataSet, ...observation, ...series]
7
8
  )(sdmxJson);
8
9
 
9
- const reportYearStartAttr = R.find(R.propEq('id', 'REPORTING_YEAR_START_DAY'), attributes) || {};
10
+ const reportYearStartAttr = R.find(({ id }) => {
11
+ return id === REPORTING_YEAR_START_DAY || id === REPYEARSTART;
12
+ }, attributes) || {};
10
13
  const reportYearStart = R.pathOr('--01-01', ['values', 0, 'name'], reportYearStartAttr);
11
14
  const [month, day] = R.match(/[\d]{2}/g, reportYearStart);
12
15
  return ({ month, day });
@@ -1,4 +1,5 @@
1
1
  import * as R from 'ramda';
2
+ import { REPORTING_YEAR_START_DAY, REPYEARSTART } from '../../constants';
2
3
 
3
4
  const registerAttrId = (path, id) => R.over(
4
5
  R.lensPath(R.prepend('attributesIdsIndexedByTargets', path)),
@@ -85,6 +86,7 @@ export const parseAttributes = ({ attributes, parsedDimensionsIds, customAttribu
85
86
  if (R.isEmpty(values) || !R.propOr(true, 'display', attribute) || R.includes(attribute.id, R.propOr([], 'units', customAttributes))) {
86
87
  return acc;
87
88
  }
89
+ if (R.includes(attribute.id, [REPORTING_YEAR_START_DAY, REPYEARSTART])) return acc;
88
90
 
89
91
  const registers = getAttributeRegisters(
90
92
  R.pipe(
@@ -6,12 +6,13 @@ export const getMSDInformations = (msdJson) => {
6
6
  const parseAttributes = (parent) => R.reduce(
7
7
  (acc, attribute) => {
8
8
  const id = attribute.id;
9
+ const hierarchicalId = parent === '#ROOT' ? id : `${parent}.${id}`;
9
10
  const format = R.path(['localRepresentation', 'textFormat', 'textType'], attribute);
10
11
  if (R.has('metadataAttributes', attribute)) {
11
- const collection = parseAttributes(attribute.id)(attribute.metadataAttributes);
12
- return ({ ...acc, ...collection, [id]: { format, parent } });
12
+ const collection = parseAttributes(hierarchicalId)(attribute.metadataAttributes);
13
+ return ({ ...acc, ...collection, [hierarchicalId]: { format, parent, id } });
13
14
  }
14
- return R.assoc(id, { format, parent }, acc);
15
+ return R.assoc(hierarchicalId, { format, parent, id }, acc);
15
16
  },
16
17
  {}
17
18
  )
@@ -49,28 +49,63 @@ export const parseMetadataSeries = (metadataJson, options) => {
49
49
  return R.propOr('', '__index', originalVal);
50
50
  }),
51
51
  R.join(':')
52
- )(serieKey)
52
+ )(serieKey);
53
53
 
54
- const attributes = R.addIndex(R.reduce)(
55
- (acc, valueIndex, attrIndex) => {
56
- if (R.isNil(valueIndex)) {
57
- return acc;
58
- }
59
- const attribute = R.nth(attrIndex, metadataAttributes);
60
- const label = dimensionValueDisplay(options.display)(attribute);
54
+ const attributes = R.pipe(
55
+ R.addIndex(R.reduce)(
56
+ (acc, valueIndex, attrIndex) => {
57
+ const attribute = R.nth(attrIndex, metadataAttributes);
58
+ if (R.isNil(valueIndex) && !(attribute.isPresentational)) {
59
+ return acc;
60
+ }
61
+ const attrOptions = R.pathOr({}, ['attributes', attribute.id], options);
62
+ const id = attrOptions.id;
63
+ const label = dimensionValueDisplay(options.display)({ ...attribute, id });
64
+
65
+ const _value = R.prop('value', R.nth(valueIndex, attribute.values || []));
66
+ const value = R.is(Object, _value) ? R.prop(options.locale, _value) : _value;
61
67
 
62
- const value = R.prop('value', R.nth(valueIndex, attribute.values || []));
68
+ return R.append({
69
+ ...(R.isNil(value) ? {} : { value }),
70
+ id: attribute.id,
71
+ label,
72
+ handlerProps: R.omit(['id'], R.pathOr({}, ['attributes', attribute.id], options))
73
+ }, acc);
74
+ },
75
+ [],
76
+ ),
77
+ attributes => { // missing parents in metadata response
78
+ const groupedAttrs = R.groupBy(R.pathOr('#ROOT', ['handlerProps', 'parent']), attributes);
79
+ const indexedAttrs = R.indexBy(R.prop('id'), attributes);
80
+
81
+ return R.reduce(
82
+ (acc, id) => {
83
+ if (R.has(id, indexedAttrs) || id === '#ROOT') {
84
+ return acc;
85
+ }
86
+ return R.append({
87
+ id,
88
+ label: dimensionValueDisplay(options.display)({ id }),
89
+ handlerProps: R.omit(['id'], R.pathOr({}, ['attributes', id], options))
90
+ }, acc);
91
+ },
92
+ attributes,
93
+ R.keys(groupedAttrs)
94
+ );
95
+ },
96
+ attributes => {
97
+ const groupedAttrs = R.groupBy(R.pathOr('#ROOT', ['handlerProps', 'parent']), attributes);
98
+ const makeTree = R.map(attr => {
99
+ if (R.has(attr.id, groupedAttrs)) {
100
+ const children = makeTree(R.prop(attr.id, groupedAttrs));
101
+ return R.assoc('children', children, attr);
102
+ }
103
+ return attr;
104
+ });
63
105
 
64
- return R.append({
65
- id: attribute.id,
66
- label,
67
- value: R.is(Object, value) ? R.prop(options.locale, value) : value,
68
- handlerProps: R.pathOr({}, ['attributes', attribute.id], options)
69
- }, acc);
106
+ return makeTree(R.propOr([], '#ROOT', groupedAttrs));
70
107
  },
71
- [],
72
- metaIndexes
73
- );
108
+ )(metaIndexes);
74
109
 
75
110
  return R.assoc(evolvedKey, attributes, acc);
76
111
  },
@@ -6,27 +6,27 @@ describe('getMSDInformations tests', () => {
6
6
  it('complete test', () => {
7
7
  const expected = {
8
8
  attributes: {
9
- STRING_TYPE: { format: 'String', parent: '#ROOT' },
10
- STRING_MULTILANG_TYPE: { format: 'String', parent: '#ROOT' },
11
- ALPHANUMERIC_TYPE: { format: 'AlphaNumeric', parent: '#ROOT' },
12
- ALPHANUMERIC_MULTILANG_TYPE: { format: 'AlphaNumeric', parent: '#ROOT' },
13
- BOOLEAN_TYPE: { format: 'Boolean', parent: '#ROOT' },
14
- XHTML_TYPE: { format: 'XHTML', parent: '#ROOT' },
15
- XHTML_MULTILANG_TYPE: { format: 'XHTML', parent: '#ROOT' },
16
- INTEGER_TYPE: { format: 'Integer', parent: '#ROOT' },
17
- INTEGER_MULTILANG_TYPE: { format: 'Integer', parent: '#ROOT' },
18
- DECIMAL_TYPE: { format: 'Decimal', parent: '#ROOT' },
19
- DECIMAL_MULTILANG_TYPE: { format: 'Decimal', parent: '#ROOT' },
20
- DATETIME_TYPE: { format: 'DateTime', parent: '#ROOT' },
21
- TIME_TYPE: { format: 'Time', parent: '#ROOT' },
22
- GREGORIANDAY_TYPE: { format: 'GregorianDay', parent: '#ROOT' },
23
- GREGORIAN_YEAR_TYPE: { format: 'GregorianYear', parent: '#ROOT' },
24
- GREGORIAN_YEARMONTH_TYPE: { format: 'GregorianYearMonth', parent: '#ROOT' },
25
- CONTACT: { format: 'String', parent: '#ROOT' },
26
- CONTACT_NAME: { format: 'String', parent: 'CONTACT' },
27
- CONTACT_EMAIL: { format: 'String', parent: 'CONTACT' },
28
- CONTACT_PHONE: { format: 'Numeric', parent: 'CONTACT' },
29
- CONTACT_ORGANISATION: { format: 'String', parent: 'CONTACT' }
9
+ STRING_TYPE: { format: 'String', parent: '#ROOT', id: 'STRING_TYPE' },
10
+ STRING_MULTILANG_TYPE: { format: 'String', parent: '#ROOT', id: 'STRING_MULTILANG_TYPE' },
11
+ ALPHANUMERIC_TYPE: { format: 'AlphaNumeric', parent: '#ROOT', id: 'ALPHANUMERIC_TYPE' },
12
+ ALPHANUMERIC_MULTILANG_TYPE: { format: 'AlphaNumeric', parent: '#ROOT', id: 'ALPHANUMERIC_MULTILANG_TYPE' },
13
+ BOOLEAN_TYPE: { format: 'Boolean', parent: '#ROOT', id: 'BOOLEAN_TYPE' },
14
+ XHTML_TYPE: { format: 'XHTML', parent: '#ROOT', id: 'XHTML_TYPE' },
15
+ XHTML_MULTILANG_TYPE: { format: 'XHTML', parent: '#ROOT', id: 'XHTML_MULTILANG_TYPE' },
16
+ INTEGER_TYPE: { format: 'Integer', parent: '#ROOT', id: 'INTEGER_TYPE' },
17
+ INTEGER_MULTILANG_TYPE: { format: 'Integer', parent: '#ROOT', id: 'INTEGER_MULTILANG_TYPE' },
18
+ DECIMAL_TYPE: { format: 'Decimal', parent: '#ROOT', id: 'DECIMAL_TYPE' },
19
+ DECIMAL_MULTILANG_TYPE: { format: 'Decimal', parent: '#ROOT', id: 'DECIMAL_MULTILANG_TYPE' },
20
+ DATETIME_TYPE: { format: 'DateTime', parent: '#ROOT', id: 'DATETIME_TYPE' },
21
+ TIME_TYPE: { format: 'Time', parent: '#ROOT', id: 'TIME_TYPE' },
22
+ GREGORIANDAY_TYPE: { format: 'GregorianDay', parent: '#ROOT', id: 'GREGORIANDAY_TYPE' },
23
+ GREGORIAN_YEAR_TYPE: { format: 'GregorianYear', parent: '#ROOT', id: 'GREGORIAN_YEAR_TYPE' },
24
+ GREGORIAN_YEARMONTH_TYPE: { format: 'GregorianYearMonth', parent: '#ROOT', id: 'GREGORIAN_YEARMONTH_TYPE' },
25
+ CONTACT: { format: 'String', parent: '#ROOT', id: 'CONTACT' },
26
+ 'CONTACT.CONTACT_NAME': { format: 'String', parent: 'CONTACT', id: 'CONTACT_NAME' },
27
+ 'CONTACT.CONTACT_EMAIL': { format: 'String', parent: 'CONTACT', id: 'CONTACT_EMAIL' },
28
+ 'CONTACT.CONTACT_PHONE': { format: 'Numeric', parent: 'CONTACT', id: 'CONTACT_PHONE' },
29
+ 'CONTACT.CONTACT_ORGANISATION': { format: 'String', parent: 'CONTACT', id: 'CONTACT_ORGANISATION' }
30
30
  }
31
31
  };
32
32
 
@@ -0,0 +1,43 @@
1
+ import { expect } from 'chai';
2
+ import { getReportingYearStart } from '../src/rules/src/preparators/getReportingYearStart';
3
+
4
+ describe('getReportingYearStart tests', () => {
5
+ it('no data', () => {
6
+ expect(getReportingYearStart()).to.deep.equal({ month: '01', day: '01' });
7
+ });
8
+ it('REPORTING_YEAR_START_DAY', () => {
9
+ const dataReportingYearStartDay = {
10
+ data: {
11
+ structure: {
12
+ attributes: {
13
+ observation: [
14
+ {
15
+ "id": "REPORTING_YEAR_START_DAY",
16
+ "values": [{"name": "--07-01", "names": { "en": "--07-01" }}]
17
+ }
18
+ ]
19
+ }
20
+ }
21
+ }
22
+ };
23
+
24
+ expect(getReportingYearStart(dataReportingYearStartDay)).to.deep.equal({ month: '07', day: '01' });
25
+ });
26
+ it('REPYEARSTART', () => {
27
+ const dataReportingYearStart = {
28
+ data: {
29
+ structure: {
30
+ attributes: {
31
+ observation: [
32
+ {
33
+ "id": "REPYEARSTART",
34
+ "values": [{"name": "--08-09", "names": { "en": "--08-09" }}]
35
+ }
36
+ ]
37
+ }
38
+ }
39
+ }
40
+ };
41
+ expect(getReportingYearStart(dataReportingYearStart)).to.deep.equal({ month: '08', day: '09' });
42
+ });
43
+ });
@@ -41,7 +41,29 @@ describe('metadata parsing performance tests', () => {
41
41
  id: 'TIME_PERIOD',
42
42
  }
43
43
  ]
44
- expect(parseMetadataSeries(metadataMock, { locale: 'en', display: 'both', dimensions })).to.deep.equal({
44
+ const attributes = {
45
+ METADATA_ATTR_0: { id: 'METADATA_ATTR_0' },
46
+ METADATA_ATTR_1: { id: 'METADATA_ATTR_1' },
47
+ METADATA_ATTR_2: { id: 'METADATA_ATTR_2' },
48
+ METADATA_ATTR_3: { id: 'METADATA_ATTR_3' },
49
+ METADATA_ATTR_4: { id: 'METADATA_ATTR_4' },
50
+ METADATA_ATTR_5: { id: 'METADATA_ATTR_5' },
51
+ METADATA_ATTR_6: { id: 'METADATA_ATTR_6' },
52
+ METADATA_ATTR_7: { id: 'METADATA_ATTR_7' },
53
+ METADATA_ATTR_8: { id: 'METADATA_ATTR_8' },
54
+ METADATA_ATTR_9: { id: 'METADATA_ATTR_9' },
55
+ METADATA_ATTR_10: { id: 'METADATA_ATTR_10' },
56
+ METADATA_ATTR_11: { id: 'METADATA_ATTR_11' },
57
+ METADATA_ATTR_12: { id: 'METADATA_ATTR_12' },
58
+ METADATA_ATTR_13: { id: 'METADATA_ATTR_13' },
59
+ METADATA_ATTR_14: { id: 'METADATA_ATTR_14' },
60
+ METADATA_ATTR_15: { id: 'METADATA_ATTR_15' },
61
+ METADATA_ATTR_16: { id: 'METADATA_ATTR_16' },
62
+ METADATA_ATTR_17: { id: 'METADATA_ATTR_17' },
63
+ METADATA_ATTR_18: { id: 'METADATA_ATTR_18' },
64
+ METADATA_ATTR_19: { id: 'METADATA_ATTR_19' }
65
+ }
66
+ expect(parseMetadataSeries(metadataMock, { locale: 'en', display: 'both', dimensions, attributes })).to.deep.equal({
45
67
  ":::": [
46
68
  { id: 'METADATA_ATTR_0', label: 'METADATA_ATTR_0: Metadata Attribute 0', value: 'v0', handlerProps: {} },
47
69
  { id: 'METADATA_ATTR_1', label: 'METADATA_ATTR_1: Metadata Attribute 1', value: 'v0', handlerProps: {} },
@@ -25,6 +25,8 @@ const attributes = [
25
25
  { id: 'a20', relationship: { primaryMeasure: 'OBS_VALUE' }, values: [{ id: 'a20v1' }] }, // units attribute
26
26
  { id: 'a21', relationship: { dataflow: {} }, values: [{ id: 'a21v0' }] }, // alternative dataflow relationship
27
27
  { id: 'a22', relationship: { observation: {} }, values: [{ id: 'a22v0' }] }, // alternative observation relationship
28
+ { id: 'REPORTING_YEAR_START_DAY', relationship: { observation: {} }, values: [{ id: 'a22v0' }]},
29
+ { id: 'REPYEARSTART', relationship: { observation: {} }, values: [{ id: 'a22v0' }]},
28
30
  ];
29
31
 
30
32
  const customAttributes = {
@@ -14,11 +14,18 @@ const dimensions = [
14
14
  id: "MEASURE", values: [{ id: "V", __index: 0 }]
15
15
  },
16
16
  {
17
- id: "TIME_PERIOD"
17
+ id: "TIME_PERIOD"
18
18
  }
19
19
  ];
20
20
 
21
- const attributes = { DIRECT_SOURCE: { prop: 'test' }, RANDOM: { prop: 'invalid' } }
21
+ const attributes = {
22
+ DIRECT_SOURCE: { id: 'DIRECT_SOURCE', prop: 'test', parent: '#ROOT' },
23
+ KEY_STATISTICAL_CONCEPT: { id: 'KEY_STATISTICAL_CONCEPT', parent: '#ROOT' },
24
+ UNIT_OF_MEASURE_USED: { id: 'UNIT_OF_MEASURE_USED', parent: '#ROOT' },
25
+ POWER_CODE: { id: 'POWER_CODE', parent: '#ROOT' },
26
+ POREFERENCE_PERIODWER_CODE: { id: 'POREFERENCE_PERIODWER_CODE', parent: '#ROOT' },
27
+ RANDOM: { prop: 'invalid' }
28
+ }
22
29
 
23
30
  describe('parseMetadataSeries test', () => {
24
31
  it('complete case', () => {
@@ -28,13 +35,13 @@ describe('parseMetadataSeries test', () => {
28
35
  id: 'DIRECT_SOURCE',
29
36
  label: 'DIRECT_SOURCE: Direct source',
30
37
  value: "Reply to the National Accounts Questionnaire from the Australian Bureau of Statistics, Canberra. The official estimates are published in 'Australian system of national accounts', ABS, catalogue 5204.0.",
31
- handlerProps: { prop: 'test' }
38
+ handlerProps: { prop: 'test', parent: '#ROOT' }
32
39
  },
33
40
  {
34
41
  id: 'KEY_STATISTICAL_CONCEPT',
35
42
  label: 'KEY_STATISTICAL_CONCEPT: Key statistical concept',
36
43
  value: "As from December 2009, national accounts estimates are compiled according to the 2008 SNA ('System of National Accounts 2008', Commission of the European Communities-Eurostat, International Monetary Fund, Organisation for Economic Co-operation and Development, United Nations and World Bank, 2009).<br><br>Detailed information about the implementation of the 2008 SNA in Australian national accounts could be found in ABS website: <br><br><a href=\"http://www.abs.gov.au/ausstats/abs@.nsf/mf/5310.0.55.002\">ABS website</a><br><br>All the data refer to fiscal years beginning on the 1st July of the year indicated.<br><br>The financial intermediation services indirectly measured (FISIM) are allocated to industries and institutional sectors. <br><br>Original chain constant price estimates for main aggregates are referenced to fiscal year 2019-2020.",
37
- handlerProps: {}
44
+ handlerProps: { parent: '#ROOT' }
38
45
  }
39
46
  ],
40
47
  '0::0:': [
@@ -42,19 +49,78 @@ describe('parseMetadataSeries test', () => {
42
49
  id: 'UNIT_OF_MEASURE_USED',
43
50
  label: 'UNIT_OF_MEASURE_USED: Unit of measure used',
44
51
  value: 'Australian Dollar',
45
- handlerProps: {}
52
+ handlerProps: { parent: '#ROOT' }
46
53
  },
47
54
  {
48
55
  id: 'POWER_CODE',
49
56
  label: 'POWER_CODE: Power code',
50
57
  value: 6,
51
- handlerProps: {}
58
+ handlerProps: { parent: '#ROOT' }
52
59
  },
53
60
  {
54
61
  id: 'POREFERENCE_PERIODWER_CODE',
55
62
  label: 'POREFERENCE_PERIODWER_CODE: Reference period',
56
63
  value: '2019',
57
- handlerProps: {}
64
+ handlerProps: { parent: '#ROOT' }
65
+ }
66
+ ]
67
+ });
68
+ });
69
+ it('hierarchy test', () => {
70
+ const attributes = {
71
+ ROOT1: { id: 'ROOT1', parent: '#ROOT' },
72
+ ROOT2: { id: 'ROOT2', parent: '#ROOT' },
73
+ PARENT1: { id: 'PARENT1', parent: '#ROOT' },
74
+ 'PARENT1.CHILD1': { id: 'CHILD1', parent: 'PARENT1' },
75
+ 'PARENT1.CHILD2': { id: 'CHILD2', parent: 'PARENT1' },
76
+ PARENT2: { id: 'PARENT1', parent: '#ROOT' },
77
+ 'PARENT2.CHILD3': { id: 'CHILD3', parent: 'PARENT2' },
78
+ 'PARENT2.CHILD4': { id: 'CHILD4', parent: 'PARENT2' },
79
+ };
80
+ const metadata = {
81
+ data: {
82
+ dataSets: [{
83
+ dimensionGroupAttributes: {
84
+ '::': [0, 0, null, 0, 0, 0, 0]
85
+ }
86
+ }],
87
+ structures: [{
88
+ attributes: {
89
+ dimensionGroup: [
90
+ { id: 'ROOT1', name: 'Root 1', values: [{ value: 'v' }] },
91
+ { id: 'ROOT2', name: 'Root 2', values: [{ value: 'v' }] },
92
+ { id: 'PARENT1', name: 'Parent 1', isPresentational: true, values: [] },
93
+ { id: 'PARENT1.CHILD1', name: 'Child 1', values: [{ value: 'v' }] },
94
+ { id: 'PARENT1.CHILD2', name: 'Child 2', values: [{ value: 'v' }] },
95
+ { id: 'PARENT2.CHILD3', name: 'Child 3', values: [{ value: 'v' }] },
96
+ { id: 'PARENT2.CHILD4', name: 'Child 4', values: [{ value: 'v' }] },
97
+ ]
98
+ }
99
+ }]
100
+ }
101
+ };
102
+
103
+ expect(parseMetadataSeries(metadata, { display: 'name', locale: 'en', dimensions: [], attributes })).to.deep.equal({
104
+ '::': [
105
+ { id: 'ROOT1', label: 'Root 1', value: 'v', handlerProps: { parent: '#ROOT' } },
106
+ { id: 'ROOT2', label: 'Root 2', value: 'v', handlerProps: { parent: '#ROOT' } },
107
+ {
108
+ id: 'PARENT1',
109
+ label: 'Parent 1',
110
+ handlerProps: { parent: '#ROOT' },
111
+ children: [
112
+ { id: 'PARENT1.CHILD1', label: 'Child 1', value: 'v', handlerProps: { parent: 'PARENT1' } },
113
+ { id: 'PARENT1.CHILD2', label: 'Child 2', value: 'v', handlerProps: { parent: 'PARENT1' } },
114
+ ]
115
+ },
116
+ {
117
+ id: 'PARENT2',
118
+ label: '[PARENT2]',
119
+ handlerProps: { parent: '#ROOT' },
120
+ children: [
121
+ { id: 'PARENT2.CHILD3', label: 'Child 3', value: 'v', handlerProps: { parent: 'PARENT2' } },
122
+ { id: 'PARENT2.CHILD4', label: 'Child 4', value: 'v', handlerProps: { parent: 'PARENT2' } },
123
+ ]
58
124
  }
59
125
  ]
60
126
  });