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

BHBC-1530: Update Moose transformations to account for all fields. #680

Merged
merged 7 commits into from
Dec 21, 2021
Merged
Show file tree
Hide file tree
Changes from 6 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
68 changes: 50 additions & 18 deletions api/src/json-schema/transformation-schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ describe('example submission transformation schema', () => {
{
condition: {
if: {
columns: ['Lone Cows']
columns: ['Lone Cows'],
not: true
}
},
transformations: [
Expand Down Expand Up @@ -208,40 +209,71 @@ describe('example submission transformation schema', () => {
{
fileName: 'event',
columns: [
{ source: 'id', target: 'id' },
{ source: 'eventID', target: 'eventID' },
{ source: 'eventDate', target: 'eventDate' },
{ source: ['verbatimCoordinatesUTM', 'verbatimCoordinatesLatLong'], target: 'verbatimCoordinates' }
{ source: { columns: ['id'] }, target: 'id' },
{ source: { columns: ['eventID'] }, target: 'eventID' },
{ source: { columns: ['eventDate'] }, target: 'eventDate' },
{
source: { columns: ['verbatimCoordinatesUTM', 'verbatimCoordinatesLatLong'] },
target: 'verbatimCoordinates'
}
]
},
{
fileName: 'occurrence',
conditionalFields: ['individualCount'],
columns: [
{ source: 'id', target: 'id' },
{ source: 'occurrenceID', target: 'occurrenceID' },
{ source: 'individualCount', target: 'individualCount' },
{ source: 'vernacularName', target: 'associatedTaxa' },
{ source: 'lifeStage', target: 'lifeStage' },
{ source: 'sex', target: 'sex' }
{ source: { columns: ['id'] }, target: 'id' },
{ source: { columns: ['occurrenceID'] }, target: 'occurrenceID' },
{ source: { columns: ['individualCount'] }, target: 'individualCount' },
{ source: { columns: ['vernacularName'] }, target: 'associatedTaxa' },
{ source: { columns: ['lifeStage'] }, target: 'lifeStage' },
{ source: { columns: ['sex'] }, target: 'sex' },
{ source: { value: 'Approved' }, target: 'Status' }
]
},
{
fileName: 'taxon',
columns: [
{ source: 'id', target: 'id' },
{ source: 'occurrenceID', target: 'occurrenceID' },
{ source: 'vernacularName', target: 'vernacularName' }
{ source: { columns: ['id'] }, target: 'id' },
{ source: { columns: ['occurrenceID'] }, target: 'occurrenceID' },
{ source: { columns: ['vernacularName'] }, target: 'vernacularName' }
]
},
{
fileName: 'resourcerelationship',
conditionalFields: ['resourceID'],
columns: [
{ source: 'id', target: 'id' },
{ source: 'resourceID', target: 'resourceID' },
{ source: 'relatedResourceID', target: 'relatedResourceID' },
{ source: 'relationshipOfResource', target: 'relationshipOfResource' }
{ source: { columns: ['id'] }, target: 'id' },
{ source: { columns: ['resourceID'] }, target: 'resourceID' },
{ source: { columns: ['relatedResourceID'] }, target: 'relatedResourceID' },
{ source: { columns: ['relationshipOfResource'] }, target: 'relationshipOfResource' }
]
},
{
fileName: 'measurementorfact',
columns: [
{ source: { columns: ['id'] }, target: 'id' },
{ source: { columns: ['eventID'] }, target: 'measurementID' },
{ source: { value: 'Habitat Description' }, target: 'measurementType' },
{ source: { columns: ['effort_habitat_description'] }, target: 'measurementValue' }
]
},
{
fileName: 'measurementorfact',
columns: [
{ source: { columns: ['id'] }, target: 'id' },
{ source: { columns: ['occurrenceID'] }, target: 'measurementID' },
{ source: { value: 'Stratum' }, target: 'measurementType' },
{ source: { columns: ['summary_stratum'] }, target: 'measurementValue' }
]
},
{
fileName: 'measurementorfact',
columns: [
{ source: { columns: ['id'] }, target: 'id' },
{ source: { columns: ['occurrenceID'] }, target: 'measurementID' },
{ source: { value: 'Activity' }, target: 'measurementType' },
{ source: { columns: ['observation_activity'] }, target: 'measurementValue' }
]
}
]
Expand Down
41 changes: 32 additions & 9 deletions api/src/json-schema/transformation-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,16 @@ export const submissionTransformationSchema = {
properties: {
if: {
type: 'object',
required: ['columns'],
properties: {
columns: {
type: 'array',
items: {
type: 'string'
}
},
not: {
type: 'boolean'
}
},
additionalProperties: false
Expand Down Expand Up @@ -112,7 +116,8 @@ export const submissionTransformationSchema = {
}
]
}
}
},
additionalProperties: false
}
},
additionalProperties: false
Expand Down Expand Up @@ -164,23 +169,41 @@ export const submissionTransformationSchema = {
source: {
oneOf: [
{
type: 'string',
description: 'The name of a source property'
type: 'object',
required: ['columns'],
properties: {
columns: {
type: 'array',
items: {
type: 'string'
}
},
separator: {
type: 'string'
},
unique: {
type: 'string'
}
},
additionalProperties: false
},
{
type: 'array',
items: {
type: 'string'
type: 'object',
required: ['value'],
properties: {
value: {
type: ['string', 'number']
}
},
description:
'An array of source properties. The first property with a defined value will be used.'
additionalProperties: false
}
]
},
target: {
type: 'string'
}
}
},
additionalProperties: false
}
},
conditionalFields: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ GET.apiDoc = {
type: 'string'
}
},

rows: {
type: 'array',
items: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type TransformationFieldsSchema = {
export type Condition = {
if: {
columns: string[];
not?: boolean;
};
};

Expand All @@ -41,7 +42,7 @@ export type TransformSchema = {
postTransformations?: PostTransformationRelatopnshipSchema[];
};

export type ParseColumnSchema = { source: string; target: string };
export type ParseColumnSchema = { source: { columns?: string[]; value?: any }; target: string };

export type ParseSchema = {
fileName: string;
Expand All @@ -59,8 +60,12 @@ export class TransformationSchemaParser {
}
}

getAllFlattenSchemas(): FlattenSchema[] | [] {
return jsonpath.query(this.transformationSchema, this.getFlattenJsonPath())?.[0] || [];
}

getFlattenSchemas(fileName: string): FlattenSchema | null {
return jsonpath.query(this.transformationSchema, this.getFlattenJsonPath(fileName))?.[0] || null;
return jsonpath.query(this.transformationSchema, this.getFlattenJsonPathByFileName(fileName))?.[0] || null;
}

getTransformSchemas(): TransformSchema[] {
Expand All @@ -71,7 +76,11 @@ export class TransformationSchemaParser {
return jsonpath.query(this.transformationSchema, this.getParseJsonPath())?.[0] || [];
}

getFlattenJsonPath(fileName: string): string {
getFlattenJsonPath(): string {
return `$.flatten`;
}

getFlattenJsonPathByFileName(fileName: string): string {
return `$.flatten[?(@.fileName == '${fileName}')]`;
}

Expand Down
Loading