Skip to content

Commit

Permalink
feat: Add cold data access for data apis and allow MAT file uploading
Browse files Browse the repository at this point in the history
  • Loading branch information
wsy19961129 committed Nov 27, 2024
1 parent be8d006 commit 0d77e3f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
5 changes: 3 additions & 2 deletions packages/itmat-apis/src/trpc/dataProcedure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export class DataRouter {
fieldIds: z.optional(z.array(z.string())),
useCache: z.optional(z.boolean()),
forceUpdate: z.optional(z.boolean()),
formatted: z.optional(z.string())
fromCold: z.optional(z.boolean())
})).query(async (opts) => {
return await this.dataCore.getData(
opts.ctx.req.user,
Expand All @@ -207,7 +207,8 @@ export class DataRouter {
opts.input.versionId,
opts.input.aggregation,
opts.input.useCache,
opts.input.forceUpdate
opts.input.forceUpdate,
opts.input.fromCold
);
}),
/**
Expand Down
15 changes: 10 additions & 5 deletions packages/itmat-cores/src/coreFunc/dataCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ export class DataCore {
*
* @return Partial<IData>[] - The list of objects of Partial<IData>
*/
public async getData(requester: IUserWithoutToken | undefined, studyId: string, selectedFieldIds?: string[], dataVersion?: string | null | Array<string | null>, aggregation?: Record<string, Array<{ operationName: enumDataTransformationOperation, params: Record<string, unknown> }>>, useCache?: boolean, forceUpdate?: boolean) {
public async getData(requester: IUserWithoutToken | undefined, studyId: string, selectedFieldIds?: string[], dataVersion?: string | null | Array<string | null>, aggregation?: Record<string, Array<{ operationName: enumDataTransformationOperation, params: Record<string, unknown> }>>, useCache?: boolean, forceUpdate?: boolean, fromCold?: boolean) {
if (!requester) {
throw new CoreError(
enumCoreErrors.NOT_LOGGED_IN,
Expand Down Expand Up @@ -811,7 +811,7 @@ export class DataCore {
return await getJsonFileContents(this.objStore, 'cache', hashedInfo[0].uri);
} else {
// raw data by the permission
const data = await this.getDataByRoles(requester, roles, studyId, availableDataVersions, fieldIds);
const data = await this.getDataByRoles(requester, roles, studyId, availableDataVersions, fieldIds, fromCold);
// data transformation if aggregation is provided
const transformed = aggregation ? this.dataTransformationCore.transformationAggregate(data as unknown as IDataTransformationClipArray, aggregation) : data;
// write to minio and cache collection
Expand Down Expand Up @@ -843,7 +843,7 @@ export class DataCore {
}
} else {
// raw data by the permission
const data = await this.getDataByRoles(requester, roles, studyId, availableDataVersions, fieldIds);
const data = await this.getDataByRoles(requester, roles, studyId, availableDataVersions, fieldIds, fromCold);
// data transformation if aggregation is provided
const transformed = aggregation ? this.dataTransformationCore.transformationAggregate(data as unknown as IDataTransformationClipArray, aggregation) : data;
return transformed;
Expand Down Expand Up @@ -1275,12 +1275,14 @@ export class DataCore {
}


public async getDataByRoles(requester: IUserWithoutToken, roles: IRole[], studyId: string, dataVersions: Array<string | null>, fieldIds?: string[]) {
public async getDataByRoles(requester: IUserWithoutToken, roles: IRole[], studyId: string, dataVersions: Array<string | null>, fieldIds?: string[], fromCold?: boolean) {
const matchFilter: Filter<IData> = {
studyId: studyId,
dataVersion: { $in: dataVersions }
};

const dbCollection = fromCold ? this.db.collections.colddata_collection : this.db.collections.data_collection;

const roleArr: Filter<IData>[] = [];
for (const role of roles) {
const permissionArr: Filter<IData>[] = [];
Expand Down Expand Up @@ -1316,12 +1318,15 @@ export class DataCore {
const queryField = async (fieldId: string) => {
if (availableFieldIds.includes(fieldId) || availableFieldIds.some(el => new RegExp(el).test(fieldId))) {
const propertyFilter: Record<string, string> = {};
if (!availableFields[fieldId]) {
return [];
}
if (availableFields[fieldId].properties) {
for (const property of availableFields[fieldId].properties) {
propertyFilter[`${property.name}`] = `$properties.${property.name}`;
}
}
const data = await this.db.collections.data_collection.aggregate<IData>([{
const data = await dbCollection.aggregate<IData>([{
$match: {
...matchFilter,
fieldId: fieldId,
Expand Down
1 change: 1 addition & 0 deletions packages/itmat-types/src/types/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export enum enumFileTypes {
DOCX = 'DOCX',
XLSX = 'XLSX',
XLS = 'XLS',
MAT = 'MAT',
// images
JPG = 'JPG',
JPEG = 'JPEG',
Expand Down

0 comments on commit 0d77e3f

Please sign in to comment.