-
Notifications
You must be signed in to change notification settings - Fork 26
T shanim/enable multiple queries #83
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
Open
shanialbeck
wants to merge
13
commits into
main
Choose a base branch
from
t-shanim/enable-multiple-queries
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
5b6e1af
add connection only queries to workbook
712a80d
support connectiononly queries in mashupdoc
a7897b9
refactor - extract logic to separate funcs, constants
fff99ab
change API to contain queryInfo array, not mashupdoc
b5cf0a3
fix no connection-only queries scenario
da41789
add missing stablentries from metadata
b844a9c
trim whitespace in queryname validation
c843087
fix query name not case-sensitive
5eddb15
fixed generated unique name to be case insensitive
2c6382a
name changes + comments
9684355
small logic changes in mashupdoc editing
8580874
add testing
7589b5e
small fixes
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ import { | |
divider, | ||
elementAttributes, | ||
elementAttributesValues, | ||
itemPathTextContext, | ||
} from "./constants"; | ||
import { arrayUtils } from "."; | ||
import { Metadata } from "../types"; | ||
|
@@ -42,6 +43,14 @@ export const replaceSingleQuery = async (base64Str: string, queryName: string, q | |
return base64.fromByteArray(newMashup); | ||
}; | ||
|
||
export const addConnectionOnlyQueries = async (base64Str: string, connectionOnlyQueryNames: string[]): Promise<string> => { | ||
var { version, packageOPC, permissionsSize, permissions, metadata, endBuffer } = getPackageComponents(base64Str); | ||
const newMetadataBuffer: Uint8Array = addConnectionOnlyQueryMetadata(metadata, connectionOnlyQueryNames); | ||
const newMashup: Uint8Array = arrayUtils.concatArrays(version, arrayUtils.getInt32Buffer(packageOPC.byteLength), packageOPC, arrayUtils.getInt32Buffer(permissionsSize), permissions, arrayUtils.getInt32Buffer(newMetadataBuffer.byteLength), newMetadataBuffer, endBuffer); | ||
|
||
return base64.fromByteArray(newMashup); | ||
}; | ||
|
||
type PackageComponents = { | ||
version: Uint8Array; | ||
packageOPC: Uint8Array; | ||
|
@@ -150,3 +159,93 @@ export const editSingleQueryMetadata = (metadataArray: Uint8Array, metadata: Met | |
|
||
return newMetadataArray; | ||
}; | ||
|
||
const addConnectionOnlyQueryMetadata = (metadataArray: Uint8Array, connectionOnlyQueryNames: string[]) => { | ||
|
||
// extract metadataXml | ||
const mashupArray: ArrayReader = new arrayUtils.ArrayReader(metadataArray.buffer); | ||
shanialbeck marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const metadataVersion: Uint8Array = mashupArray.getBytes(4); | ||
const metadataXmlSize: number = mashupArray.getInt32(); | ||
const metadataXml: Uint8Array = mashupArray.getBytes(metadataXmlSize); | ||
const endBuffer: Uint8Array = mashupArray.getBytes(); | ||
|
||
// parse metadataXml | ||
const metadataString: string = new TextDecoder("utf-8").decode(metadataXml); | ||
const newMetadataString: string = updateConnectionOnlyMetadataStr(metadataString, connectionOnlyQueryNames); | ||
const encoder: TextEncoder = new TextEncoder(); | ||
const newMetadataXml: Uint8Array = encoder.encode(newMetadataString); | ||
const newMetadataXmlSize: Uint8Array = arrayUtils.getInt32Buffer(newMetadataXml.byteLength); | ||
const newMetadataArray: Uint8Array = arrayUtils.concatArrays( | ||
metadataVersion, | ||
newMetadataXmlSize, | ||
newMetadataXml, | ||
endBuffer | ||
); | ||
|
||
return newMetadataArray; | ||
}; | ||
|
||
const updateConnectionOnlyMetadataStr = (metadataString: string, connectionOnlyQueryNames: string[]) => { | ||
shanialbeck marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
const parser: DOMParser = new DOMParser(); | ||
let metadataDoc: Document = parser.parseFromString(metadataString, xmlTextResultType); | ||
connectionOnlyQueryNames.forEach((queryName: string) => { | ||
const items: Element = metadataDoc.getElementsByTagName(element.items)[0]; | ||
const stableEntriesItem: Element = createStableEntriesItem(metadataDoc, queryName); | ||
shanialbeck marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
items.appendChild(stableEntriesItem); | ||
const sourceItem: Element = metadataDoc.createElementNS(metadataDoc.documentElement.namespaceURI, element.item); | ||
sourceItem.appendChild(createItemLocation(metadataDoc, queryName, true)); | ||
const stableEntries: Element = metadataDoc.createElementNS(metadataDoc.documentElement.namespaceURI, element.stableEntries); | ||
sourceItem.appendChild(stableEntries); | ||
items.appendChild(sourceItem); | ||
}); | ||
|
||
const updatedMetdataString: string = new XMLSerializer().serializeToString(metadataDoc); | ||
|
||
return updatedMetdataString; | ||
}; | ||
|
||
const createItemLocation = (metadataDoc: Document, queryName: string, isSource: boolean) => { | ||
const newItemLocation: Element = metadataDoc.createElementNS(metadataDoc.documentElement.namespaceURI, element.itemLocation); | ||
const newItemType: Element = metadataDoc.createElementNS(metadataDoc.documentElement.namespaceURI, element.itemType); | ||
newItemType.textContent = "Formula"; | ||
const newItemPath: Element = metadataDoc.createElementNS(metadataDoc.documentElement.namespaceURI, element.itemPath); | ||
newItemPath.textContent = itemPathTextContext(queryName, isSource); | ||
newItemLocation.appendChild(newItemType); | ||
newItemLocation.appendChild(newItemPath); | ||
|
||
return newItemLocation; | ||
}; | ||
|
||
const createStableEntriesItem = (metadataDoc: Document, queryName: string) => { | ||
const newItem: Element = metadataDoc.createElementNS(metadataDoc.documentElement.namespaceURI, element.item); | ||
newItem.appendChild(createItemLocation(metadataDoc, queryName, false)); | ||
const stableEntries: Element = createConnectionOnlyEntries(metadataDoc); | ||
shanialbeck marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
newItem.appendChild(stableEntries); | ||
|
||
return newItem; | ||
}; | ||
|
||
const createElementObject = (metadataDoc: Document, type: string, value: string) => { | ||
const elementObject: Element = metadataDoc.createElementNS(metadataDoc.documentElement.namespaceURI, element.entry); | ||
elementObject.setAttribute(elementAttributes.type, type); | ||
elementObject.setAttribute(elementAttributes.value, value); | ||
|
||
return elementObject; | ||
}; | ||
|
||
const createConnectionOnlyEntries = (metadataDoc: Document) => { | ||
shanialbeck marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
const stableEntries: Element = metadataDoc.createElementNS(metadataDoc.documentElement.namespaceURI, element.stableEntries); | ||
shanialbeck marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
const nowTime: string = new Date().toISOString(); | ||
|
||
stableEntries.appendChild(createElementObject(metadataDoc, elementAttributes.isPrivate, "l0")); | ||
stableEntries.appendChild(createElementObject(metadataDoc, elementAttributes.fillEnabled, "l0")); | ||
stableEntries.appendChild(createElementObject(metadataDoc, elementAttributes.fillObjectType, elementAttributesValues.connectionOnlyResultType())); | ||
stableEntries.appendChild(createElementObject(metadataDoc, elementAttributes.fillToDataModelEnabled, "l0")); | ||
stableEntries.appendChild(createElementObject(metadataDoc, elementAttributes.fillLastUpdated, (elementAttributes.day + nowTime).replace(/Z/, "0000Z"))); | ||
stableEntries.appendChild(createElementObject(metadataDoc, elementAttributes.resultType, elementAttributesValues.tableResultType())); | ||
stableEntries.appendChild(createElementObject(metadataDoc, elementAttributes.filledCompleteResultToWorksheet, "l0")); | ||
stableEntries.appendChild(createElementObject(metadataDoc, elementAttributes.addedToDataModel, "l0")); | ||
stableEntries.appendChild(createElementObject(metadataDoc, elementAttributes.fillErrorCode, elementAttributesValues.fillErrorCodeUnknown())); | ||
stableEntries.appendChild(createElementObject(metadataDoc, elementAttributes.fillStatus, elementAttributesValues.fillStatusComplete())); | ||
|
||
return stableEntries; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.