Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI-8803 - Support namespaces in XML calculated members #120

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading