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

Added filepath in entity data map #732

Merged
merged 8 commits into from
Oct 18, 2023
8 changes: 5 additions & 3 deletions src/web/client/WebExtensionContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,15 +366,17 @@ class WebExtensionContext implements IWebExtensionContext {
odataEtag: string,
attributePath: IAttributePath,
attributeContent: string,
mappingEntityId?: string
mappingEntityId?: string,
filePath?: string[]
) {
this.entityDataMap.setEntity(
entityId,
entityName,
odataEtag,
attributePath,
attributeContent,
mappingEntityId);
mappingEntityId,
filePath);
}

public async updateSingleFileUrisInContext(uri: vscode.Uri) {
Expand Down Expand Up @@ -606,7 +608,7 @@ class WebExtensionContext implements IWebExtensionContext {
}

/**
* Store a value maintained in Extension context workspaceState.
* Store a value maintained in Extension context workspaceState.
*
* *Note* that using `undefined` as value removes the key from the underlying
* storage.
Expand Down
12 changes: 11 additions & 1 deletion src/web/client/context/entityData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface IEntityData extends IEntityInfo {
entityEtag: string;
entityColumn: Map<string, string | Uint8Array>;
mappingEntityId?: string;
filePath?: string[]
}

export class EntityData implements IEntityData {
Expand All @@ -17,6 +18,7 @@ export class EntityData implements IEntityData {
private _entityEtag!: string;
private _entityColumn!: Map<string, string | Uint8Array>;
private _mappingEntityId?: string;
private _filePath?: string[];

public get entityName(): string {
return this._entityName;
Expand All @@ -33,23 +35,31 @@ export class EntityData implements IEntityData {
public get mappingEntityId(): string | undefined {
return this._mappingEntityId;
}
public get filePath(): string[] | undefined {
return this._filePath;
}

// Setters
public set setEntityEtag(value: string) {
this._entityEtag = value;
}
public set setFilePath(value: string[] | undefined) {
this._filePath = value;
}

constructor(
entityId: string,
entityName: string,
entityEtag: string,
entityColumn: Map<string, string | Uint8Array>,
mappingEntityId?: string
mappingEntityId?: string,
filePath?: string[]
) {
this._entityId = entityId;
this._entityName = entityName;
this._entityEtag = entityEtag;
this._entityColumn = entityColumn;
this._mappingEntityId = mappingEntityId;
this._filePath = filePath;
}
}
6 changes: 4 additions & 2 deletions src/web/client/context/entityDataMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export class EntityDataMap {
odataEtag: string,
attributePath: IAttributePath,
attributeContent: string,
mappingEntityId?: string
mappingEntityId?: string,
filePath?: string[]
) {
let entityColumnMap = new Map<string, string | Uint8Array>();
const existingEntity = this.entityMap.get(entityId);
Expand All @@ -49,7 +50,8 @@ export class EntityDataMap {
entityName,
odataEtag,
entityColumnMap,
mappingEntityId
mappingEntityId,
filePath
ritikramuka marked this conversation as resolved.
Show resolved Hide resolved
);
this.entityMap.set(entityId, entityData);
}
Expand Down
22 changes: 17 additions & 5 deletions src/web/client/dal/remoteFetchProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ async function processDataAndCreateFile(
>;
let counter = 0;
let fileUri = "";
const entityFileMap = new Map<string, string[]>();

for (counter; counter < attributeArray.length; counter++) {
const fileExtension = attributeExtensionMap?.get(
Expand All @@ -345,6 +346,10 @@ async function processDataAndCreateFile(
let fileCreationValid = true;
let fileNameWithExtension = GetFileNameWithExtension(entityName, fileName, languageCode, fileExtension);

const filePath = entityFileMap.get(entityId) ?? [];
filePath.push(fileNameWithExtension);
ritikramuka marked this conversation as resolved.
Show resolved Hide resolved
entityFileMap.set(entityId, filePath);

if (defaultFileInfo?.fileName) {
fileCreationValid = defaultFileInfo?.fileName === fileNameWithExtension ||
(defaultFileInfo?.fileName.startsWith(fileName) && defaultFileInfo?.fileName.endsWith(fileExtension));
Expand All @@ -363,7 +368,8 @@ async function processDataAndCreateFile(
mappingEntityFetchQuery,
entityId,
dataverseOrgUrl,
portalsFS
portalsFS,
entityFileMap
);
}
}
Expand Down Expand Up @@ -409,7 +415,8 @@ async function createFile(
mappingEntityFetchQuery: string | undefined,
entityId: string,
dataverseOrgUrl: string,
portalsFS: PortalsFS
portalsFS: PortalsFS,
entityFileMap: Map<string, string[]>
ritikramuka marked this conversation as resolved.
Show resolved Hide resolved
) {
const base64Encoded: boolean = isBase64Encoded(
entityName,
Expand Down Expand Up @@ -443,6 +450,8 @@ async function createFile(
fileContent = GetFileContent(result, attributePath, entityName, entityId);
}

const filePath : string[] = entityFileMap.get(entityId) ?? [];

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

Expand Down Expand Up @@ -608,7 +618,8 @@ async function createVirtualFile(
mimeType?: string,
isPreloadedContent?: boolean,
mappingEntityId?: string,
logicalEntityName?: string
logicalEntityName?: string,
filePath?: string[]
) {
// Maintain file information in context
await WebExtensionContext.updateFileDetailsInContext(
Expand Down Expand Up @@ -640,6 +651,7 @@ async function createVirtualFile(
odataEtag,
attributePath,
originalAttributeContent,
mappingEntityId
mappingEntityId,
filePath,
);
}