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

RootWebPageId in Entity Data Map for V1 and V2 data model #756

Merged
merged 8 commits into from
Nov 7, 2023
6 changes: 4 additions & 2 deletions src/web/client/WebExtensionContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,8 @@ class WebExtensionContext implements IWebExtensionContext {
attributePath: IAttributePath,
attributeContent: string,
mappingEntityId?: string,
fileUri?: string
fileUri?: string,
rootWebPageId?: string,
) {
this.entityDataMap.setEntity(
entityId,
Expand All @@ -376,7 +377,8 @@ class WebExtensionContext implements IWebExtensionContext {
attributePath,
attributeContent,
mappingEntityId,
fileUri);
fileUri,
rootWebPageId);
}

public async updateSingleFileUrisInContext(uri: vscode.Uri) {
Expand Down
8 changes: 7 additions & 1 deletion src/web/client/context/entityData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class EntityData implements IEntityData {
private _entityColumn!: Map<string, string | Uint8Array>;
private _mappingEntityId?: string;
private _filePath?: Set<string>;
private _rootWebPageId?: string;

public get entityName(): string {
return this._entityName;
Expand All @@ -38,6 +39,9 @@ export class EntityData implements IEntityData {
public get filePath(): Set<string> | undefined {
return this._filePath;
}
public get rootWebPageId(): string | undefined {
return this._rootWebPageId;
}

// Setters
public set setEntityEtag(value: string) {
Expand All @@ -50,13 +54,15 @@ export class EntityData implements IEntityData {
entityEtag: string,
entityColumn: Map<string, string | Uint8Array>,
mappingEntityId?: string,
filePath?: Set<string>
filePath?: Set<string>,
rootWebPageId?: string
) {
this._entityId = entityId;
this._entityName = entityName;
this._entityEtag = entityEtag;
this._entityColumn = entityColumn;
this._mappingEntityId = mappingEntityId;
this._filePath = filePath;
this._rootWebPageId = rootWebPageId;
}
}
6 changes: 4 additions & 2 deletions src/web/client/context/entityDataMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export class EntityDataMap {
attributePath: IAttributePath,
attributeContent: string,
mappingEntityId?: string,
fileUri?: string
fileUri?: string,
rootWebPageId?: string
) {
let entityColumnMap = new Map<string, string | Uint8Array>();
const existingEntity = this.entityMap.get(entityId);
Expand All @@ -56,7 +57,8 @@ export class EntityDataMap {
odataEtag,
entityColumnMap,
mappingEntityId,
filePath
filePath,
rootWebPageId
);
this.entityMap.set(entityId, entityData);
}
Expand Down
37 changes: 28 additions & 9 deletions src/web/client/dal/remoteFetchProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import * as vscode from "vscode";
import {
convertContentToUint8Array,
GetFileContent,
GetFileNameWithExtension,
getAttributeContent,
getSanitizedFileName,
isPortalVersionV1,
isPortalVersionV2,
Expand Down Expand Up @@ -271,6 +271,10 @@ async function createContentFiles(
}

const attributeArray = attributes.split(",");

// Get rootpage id Attribute
const rootWebPageIdAttribute = entityDetails?.get(schemaEntityKey.ROOT_WEB_PAGE_ID);

await processDataAndCreateFile(attributeArray,
attributeExtension,
entityName,
Expand All @@ -282,7 +286,8 @@ async function createContentFiles(
languageCode,
filePathInPortalFS,
portalsFS,
defaultFileInfo)
defaultFileInfo,
rootWebPageIdAttribute)

} catch (error) {
const errorMsg = (error as Error)?.message;
Expand Down Expand Up @@ -312,6 +317,7 @@ async function processDataAndCreateFile(
filePathInPortalFS: string,
portalsFS: PortalsFS,
defaultFileInfo?: IFileInfo,
rootWebPageIdAttribute?: string
) {
const attributeExtensionMap = attributeExtension as unknown as Map<
string,
Expand All @@ -330,7 +336,7 @@ async function processDataAndCreateFile(
);

if (fileExtension === undefined) {
const expandedContent = GetFileContent(result, attributePath, entityName, entityId);
const expandedContent = getAttributeContent(result, attributePath, entityName, entityId);

if (expandedContent !== Constants.NO_CONTENT) {
await processExpandedData(
Expand All @@ -351,6 +357,14 @@ async function processDataAndCreateFile(
fileNameWithExtension = defaultFileInfo?.fileName;
}

// Get rootpage id
let rootWebPageId = undefined;

if (rootWebPageIdAttribute) {
const rootWebPageIdPath : IAttributePath = getAttributePath(rootWebPageIdAttribute);
rootWebPageId = getAttributeContent(result, rootWebPageIdPath, entityName, entityId);
}

if (fileCreationValid) {
fileUri = filePathInPortalFS + fileNameWithExtension;
await createFile(
Expand All @@ -363,7 +377,8 @@ async function processDataAndCreateFile(
mappingEntityFetchQuery,
entityId,
dataverseOrgUrl,
portalsFS
portalsFS,
rootWebPageId,
);
}
}
Expand Down Expand Up @@ -409,7 +424,8 @@ async function createFile(
mappingEntityFetchQuery: string | undefined,
entityId: string,
dataverseOrgUrl: string,
portalsFS: PortalsFS
portalsFS: PortalsFS,
rootWebPageId?: string
) {
const base64Encoded: boolean = isBase64Encoded(
entityName,
Expand Down Expand Up @@ -440,7 +456,7 @@ async function createFile(
mimeType = getMimeType(mappingContent);
fileContent = getMappingEntityContent(entityName, mappingContent, attribute);
} else {
fileContent = GetFileContent(result, attributePath, entityName, entityId);
fileContent = getAttributeContent(result, attributePath, entityName, entityId);
}

await createVirtualFile(
Expand All @@ -458,7 +474,8 @@ async function createFile(
mimeType ?? result[Constants.MIMETYPE],
isPreloadedContent,
mappingEntityId,
getLogicalEntityName(result, logicalEntityName)
getLogicalEntityName(result, logicalEntityName),
rootWebPageId,
);
}

Expand Down Expand Up @@ -562,7 +579,7 @@ export async function preprocessData(

// eslint-disable-next-line @typescript-eslint/no-explicit-any
data?.forEach((dataItem: any) => {
const webFormSteps = GetFileContent(dataItem, attributePath, entityType, fetchedFileId as string) as [];
const webFormSteps = getAttributeContent(dataItem, attributePath, entityType, fetchedFileId as string) as [];

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const steps: any[] = [];
Expand Down Expand Up @@ -608,7 +625,8 @@ async function createVirtualFile(
mimeType?: string,
isPreloadedContent?: boolean,
mappingEntityId?: string,
logicalEntityName?: string
logicalEntityName?: string,
rootWebPageId?: string,
) {
// Maintain file information in context
await WebExtensionContext.updateFileDetailsInContext(
Expand Down Expand Up @@ -642,5 +660,6 @@ async function createVirtualFile(
originalAttributeContent,
mappingEntityId,
fileUri,
rootWebPageId,
);
}
1 change: 1 addition & 0 deletions src/web/client/schema/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export enum schemaEntityKey {
MAPPING_ENTITY_FETCH_QUERY = "_mappingEntityFetchQuery",
EXPORT_TYPE = "_exporttype",
ATTRIBUTES = "_attributes",
ROOT_WEB_PAGE_ID = "_rootwebpageid",
ritikramuka marked this conversation as resolved.
Show resolved Hide resolved
}

export enum schemaEntityName {
Expand Down
6 changes: 4 additions & 2 deletions src/web/client/schema/portalSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,16 @@ export const portal_schema_V1 = {
_languagefield: "_adx_webpagelanguageid_value",
_languagegroupby: "adx_rootwebpageid",
_fetchQueryParameters:
"?$filter=adx_webpageid eq {entityId} &$select=adx_name,adx_copy,adx_customcss,adx_customjavascript,adx_partialurl,_adx_webpagelanguageid_value&$count=true",
"?$filter=adx_webpageid eq {entityId} &$select=adx_name,adx_copy,adx_customcss,adx_customjavascript,adx_partialurl,_adx_webpagelanguageid_value,_adx_rootwebpageid_value&$count=true",
_multiFileFetchQueryParameters:
"?$filter=_adx_websiteid_value eq {websiteId} and _adx_webpagelanguageid_value ne null &$select=adx_webpageid,_adx_webpagelanguageid_value,adx_name,adx_copy,adx_customcss,adx_customjavascript,adx_partialurl&$count=true",
"?$filter=_adx_websiteid_value eq {websiteId} and _adx_webpagelanguageid_value ne null &$select=adx_webpageid,_adx_webpagelanguageid_value,adx_name,adx_copy,adx_customcss,adx_customjavascript,adx_partialurl,_adx_rootwebpageid_value&$count=true",
_attributes: "adx_customcss,adx_customjavascript,adx_copy",
_attributesExtension: new Map([
["adx_customcss", "customcss.css"],
["adx_customjavascript", "customjs.js"],
["adx_copy", "webpage.copy.html"],
]),
_rootwebpageid: "_adx_rootwebpageid_value",
ritikramuka marked this conversation as resolved.
Show resolved Hide resolved
},
{
relationships: "",
Expand Down Expand Up @@ -307,6 +308,7 @@ export const portal_schema_V2 = {
["content.customjavascript", "customjs.js"],
["content.copy", "webpage.copy.html"],
]),
_rootwebpageid: "content.rootwebpageid"
},
{
relationships: "",
Expand Down
4 changes: 2 additions & 2 deletions src/web/client/services/etagHandlerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { httpMethod, ODATA_ETAG, queryParameters } from "../common/constants";
import { IAttributePath } from "../common/interfaces";
import { PortalsFS } from "../dal/fileSystemProvider";
import { telemetryEventNames } from "../telemetry/constants";
import { GetFileContent } from "../utilities/commonUtil";
import { getAttributeContent } from "../utilities/commonUtil";
import {
getFileEntityEtag,
getFileEntityId,
Expand Down Expand Up @@ -85,7 +85,7 @@ export class EtagHandlerService {
const currentContent = new TextDecoder().decode(
await portalFs.readFile(vscode.Uri.parse(fileFsPath))
);
const latestContent = GetFileContent(result, attributePath, entityName, entityId);
const latestContent = getAttributeContent(result, attributePath, entityName, entityId);
updateEntityEtag(entityId, result[ODATA_ETAG]);

if (currentContent !== latestContent) {
Expand Down
4 changes: 2 additions & 2 deletions src/web/client/telemetry/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export enum telemetryEventNames {
WEB_EXTENSION_CREATE_ENTITY_FOLDER_FAILED = "webExtensionCreateEntityFolderFailed",
WEB_EXTENSION_PREPROCESS_DATA_FAILED = "webExtensionPreprocessDataFailed",
WEB_EXTENSION_PREPROCESS_DATA_SUCCESS = "webExtensionPreprocessDataSuccess",
WEB_EXTENSION_GET_FILE_CONTENT_ERROR = "webExtensionGetFileContentError",
WEB_EXTENSION_ATTRIBUTE_CONTENT_ERROR = "webExtensionAttributeContentError",
WEB_EXTENSION_SET_FILE_CONTENT_ERROR = "webExtensionSetFileContentError",
WEB_EXTENSION_FAILED_TO_PREPARE_WORKSPACE = "webExtensionFailedToPrepareWorkspace",
WEB_EXTENSION_BULKHEAD_QUEUE_FULL = "webExtensionBulkheadQueueFull",
Expand Down Expand Up @@ -98,5 +98,5 @@ export enum telemetryEventNames {
WEB_EXTENSION_BACK_TO_STUDIO_TRIGGERED = 'webExtensionBackToStudioTriggered',
WEB_EXTENSION_PREVIEW_SITE_TRIGGERED = 'webExtensionPreviewSiteTriggered',
WEB_EXTENSION_IMAGE_EDIT_SUPPORTED_FILE_EXTENSION = 'webExtensionImageEditSupportedFileExtension',
WEB_EXTENSION_SAVE_IMAGE_FILE_TRIGGERED = 'webExtensionSaveImageFileTriggered'
WEB_EXTENSION_SAVE_IMAGE_FILE_TRIGGERED = 'webExtensionSaveImageFileTriggered',
}
12 changes: 6 additions & 6 deletions src/web/client/utilities/commonUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,23 @@ export function isExtensionNeededInFileName(entity: string) {
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function GetFileContent(result: any, attributePath: IAttributePath, entityName: string, entityId: string) {
let fileContent = result[attributePath.source] ?? NO_CONTENT;
export function getAttributeContent(result: any, attributePath: IAttributePath, entityName: string, entityId: string) {
let value = result[attributePath.source] ?? NO_CONTENT;

try {
if (result[attributePath.source] && attributePath.relativePath.length) {
fileContent =
value =
JSON.parse(result[attributePath.source])[attributePath.relativePath] ?? NO_CONTENT;
}
}
catch (error) {
const errorMsg = (error as Error)?.message;
WebExtensionContext.telemetry.sendErrorTelemetry(telemetryEventNames.WEB_EXTENSION_GET_FILE_CONTENT_ERROR,
GetFileContent.name,
WebExtensionContext.telemetry.sendErrorTelemetry(telemetryEventNames.WEB_EXTENSION_ATTRIBUTE_CONTENT_ERROR,
getAttributeContent.name,
`For ${entityName} with entityId ${entityId} and attributePath ${JSON.stringify(attributePath)} error: ${errorMsg}`);
}

return fileContent;
return value;
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
Loading