Skip to content

Commit

Permalink
UI-8803 - Support namespaces in XML calculated members (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinetissier authored Oct 16, 2023
1 parent 71f31eb commit ed4a00a
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/4.3_to_5.0/__snapshots__/getCalculatedMeasures.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`getCalculatedMeasures parses an XML calculated measure with a namespace 1`] = `
[
{
"expression": "[Measures].[deltaMTM]",
"formatStringExpression": ""#,###,,"",
"owners": [
"43890025",
],
"readers": [
"43890025",
],
"uniqueName": "[Measures].[CC Impact MtM]",
},
]
`;

exports[`getCalculatedMeasures returns the parsed calculated measure objects 1`] = `
[
{
Expand Down
41 changes: 41 additions & 0 deletions src/4.3_to_5.0/getCalculatedMeasures.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,45 @@ describe("getCalculatedMeasures", () => {

expect(result).toMatchSnapshot();
});

// https://activeviam.atlassian.net/browse/UI-8803
it("parses an XML calculated measure with a namespace", async () => {
// The "calculateMember" tag has a namespace: "ns2".
const legacyCalculatedMeasuresFolder = {
entry: {
isDirectory: true,
owners: ["ROLE_CS_ROOT"],
readers: ["ROLE_CS_ROOT"],
},
children: {
EquityDerivativesCube: {
entry: {
isDirectory: true,
owners: ["ROLE_CS_ROOT"],
readers: ["ROLE_CS_ROOT"],
},

children: {
"[Measures].[CC Impact MtM]": {
entry: {
content:
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n<ns2:calculatedMember expression="[Measures].[deltaMTM]" formatStringExpression="&quot;#,###,,&quot;" uniqueName="[Measures].[CC Impact MtM]" xmlns:ns2="http://www.quartetfs.com">\n <ns2:additionalProperties/>\n</ns2:calculatedMember>\n',
isDirectory: false,
owners: ["43890025"],
readers: ["43890025"],
timestamp: 1569424639841,
lastEditor: "43890025",
canRead: true,
canWrite: true,
},
},
},
},
},
};

const result = await getCalculatedMeasures(legacyCalculatedMeasuresFolder);

expect(result).toMatchSnapshot();
});
});
3 changes: 2 additions & 1 deletion src/4.3_to_5.0/getCalculatedMeasures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import { ContentRecord } from "@activeviam/activeui-sdk-5.0";
import xml2js from "xml2js";
import _flatMap from "lodash/flatMap";
import { LegacyCalculatedMeasure } from "./migrateCalculatedMeasures";
import { stripPrefix } from "xml2js/lib/processors";

/**
* Extracts and parses the XML calculated measure objects from the /pivot/entitlements/cm folder.
*/
export const getCalculatedMeasures = async (
calculatedMeasuresFolder: ContentRecord,
): Promise<LegacyCalculatedMeasure[]> => {
const parser = new xml2js.Parser();
const parser = new xml2js.Parser({ tagNameProcessors: [stripPrefix] });

const calculatedMeasures: LegacyCalculatedMeasure[] = [];

Expand Down

0 comments on commit ed4a00a

Please sign in to comment.