Skip to content

Commit

Permalink
feat: updated shp maping (#79)
Browse files Browse the repository at this point in the history
* feat: updated shp maping

* fix: update filed names in test
  • Loading branch information
cl-shaharshavit-rnd authored Jul 1, 2021
1 parent 0dfa791 commit cef3882
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 40 deletions.
18 changes: 10 additions & 8 deletions src/models/layerMetadata/decorators/property/shp.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import 'reflect-metadata';

const shpMappingMetadataKey = Symbol('shpmapping');
const inputDataMappingMetadataKey = Symbol('inputDataMapping');

export interface IShpMapping {
shpFile: ShapeFileType;
export interface IDataMapping {
dataFile: DataFileType;
valuePath: string;
isCustomLogic?: boolean;
}

export enum ShapeFileType {
export enum DataFileType {
FILES = 'Files',
PRODUCT = 'Product',
SHAPE_METADATA = 'ShapeMetadata',
TFW = 'TFW',
}

export function shpMapping(shpmapping: IShpMapping): PropertyDecorator {
return Reflect.metadata(shpMappingMetadataKey, shpmapping);
export function inputDataMapping(dataMapping: IDataMapping): PropertyDecorator {
return Reflect.metadata(inputDataMappingMetadataKey, dataMapping);
}

export function getShpMapping<T>(target: T, propertyKey: string): IShpMapping | undefined {
return Reflect.getMetadata(shpMappingMetadataKey, target, propertyKey) as IShpMapping;
export function getInputDataMapping<T>(target: T, propertyKey: string): IDataMapping | undefined {
return Reflect.getMetadata(inputDataMappingMetadataKey, target, propertyKey) as IDataMapping;
}
2 changes: 1 addition & 1 deletion src/models/layerMetadata/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export * from './layerMetadata';
export * from './layerMetadata-StatusFields';

export { IShpMapping, ShapeFileType } from './decorators/property/shp.decorator';
export { IDataMapping, DataFileType } from './decorators/property/shp.decorator';
export { TsTypes, IDescribeTsType, PropertiesTypes } from './decorators/property/tsTypes.decorator';
export { IPYCSWMapping } from './decorators/property/csw.decorator';
export { IColumnProps } from './decorators/property/catalogDB.decorator';
Expand Down
87 changes: 61 additions & 26 deletions src/models/layerMetadata/layerMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import { RecordType } from '../pycsw/coreEnums';
import { IMetadataCommonModel } from './interfaces/metadataCommonModel';
import { getPyCSWMapping, IPYCSWMapping, pycsw } from './decorators/property/csw.decorator';
import { getShpMapping, IShpMapping, ShapeFileType, shpMapping } from './decorators/property/shp.decorator';
import { getInputDataMapping, IDataMapping, DataFileType, inputDataMapping } from './decorators/property/shp.decorator';
import { getCatalogDBMapping, ICatalogDBMapping, catalogDB } from './decorators/property/catalogDB.decorator';
import { getTsTypesMapping, ITsTypesMapping, tsTypes, TsTypes } from './decorators/property/tsTypes.decorator';
import { SensorType } from './enums';
Expand All @@ -25,7 +25,7 @@ export interface ILayerMetadata {
rms: number | undefined;
scale: string | undefined;
}
export interface IPropSHPMapping extends IShpMapping, ITsTypesMapping {
export interface IPropSHPMapping extends IDataMapping, ITsTypesMapping {
prop: string;
}

Expand Down Expand Up @@ -101,6 +101,10 @@ export class LayerMetadata implements ILayerMetadata, IMetadataCommonModel {
nullable: true,
},
})
@inputDataMapping({
dataFile: DataFileType.SHAPE_METADATA,
valuePath: 'features[0].properties.SourceName',
})
@tsTypes({
mappingType: TsTypes.STRING,
})
Expand All @@ -126,8 +130,8 @@ export class LayerMetadata implements ILayerMetadata, IMetadataCommonModel {
nullable: true,
},
})
@shpMapping({
shpFile: ShapeFileType.SHAPE_METADATA,
@inputDataMapping({
dataFile: DataFileType.SHAPE_METADATA,
valuePath: 'features[0].properties.Dsc',
})
@tsTypes({
Expand Down Expand Up @@ -256,9 +260,10 @@ export class LayerMetadata implements ILayerMetadata, IMetadataCommonModel {
type: 'timestamp without time zone',
},
})
@shpMapping({
shpFile: ShapeFileType.SHAPE_METADATA,
valuePath: 'features[0].properties.UpdateDate',
@inputDataMapping({
isCustomLogic: true,
dataFile: DataFileType.SHAPE_METADATA,
valuePath: '***max(features[].properties.UpdateDate)***',
})
@tsTypes({
mappingType: TsTypes.DATE,
Expand All @@ -285,6 +290,11 @@ export class LayerMetadata implements ILayerMetadata, IMetadataCommonModel {
type: 'timestamp without time zone',
},
})
@inputDataMapping({
isCustomLogic: true,
dataFile: DataFileType.SHAPE_METADATA,
valuePath: '***min(features[].properties.UpdateDate)***',
})
@tsTypes({
mappingType: TsTypes.DATE,
})
Expand All @@ -310,6 +320,11 @@ export class LayerMetadata implements ILayerMetadata, IMetadataCommonModel {
type: 'timestamp without time zone',
},
})
@inputDataMapping({
isCustomLogic: true,
dataFile: DataFileType.SHAPE_METADATA,
valuePath: '***max(features[].properties.UpdateDate)***',
})
@tsTypes({
mappingType: TsTypes.DATE,
})
Expand All @@ -335,8 +350,8 @@ export class LayerMetadata implements ILayerMetadata, IMetadataCommonModel {
type: 'real',
},
})
@shpMapping({
shpFile: ShapeFileType.SHAPE_METADATA,
@inputDataMapping({
dataFile: DataFileType.SHAPE_METADATA,
valuePath: 'features[0].properties.Ep90',
})
@tsTypes({
Expand Down Expand Up @@ -367,9 +382,10 @@ export class LayerMetadata implements ILayerMetadata, IMetadataCommonModel {
overrideType: TsTypes.STRING,
},
})
@shpMapping({
shpFile: ShapeFileType.SHAPE_METADATA,
valuePath: 'features[0].properties.SensorType',
@inputDataMapping({
isCustomLogic: true,
dataFile: DataFileType.SHAPE_METADATA,
valuePath: '***features[].properties.SensorType***',
})
@tsTypes({
mappingType: TsTypes.SENSORTYPE_ARRAY,
Expand Down Expand Up @@ -426,6 +442,11 @@ export class LayerMetadata implements ILayerMetadata, IMetadataCommonModel {
nullable: false,
},
})
@inputDataMapping({
isCustomLogic: true,
dataFile: DataFileType.SHAPE_METADATA,
valuePath: '***features[0].properties.Source.Split(-)[0]***',
})
@tsTypes({
mappingType: TsTypes.STRING,
})
Expand All @@ -450,6 +471,11 @@ export class LayerMetadata implements ILayerMetadata, IMetadataCommonModel {
nullable: true,
},
})
@inputDataMapping({
isCustomLogic: true,
dataFile: DataFileType.SHAPE_METADATA,
valuePath: '***features[0].properties.Source.Split(-)[1]***',
})
@tsTypes({
mappingType: TsTypes.STRING,
})
Expand All @@ -476,6 +502,10 @@ export class LayerMetadata implements ILayerMetadata, IMetadataCommonModel {
nullable: true,
},
})
@inputDataMapping({
dataFile: DataFileType.PRODUCT,
valuePath: 'features[0].properties.Type',
})
@tsTypes({
mappingType: TsTypes.STRING,
})
Expand Down Expand Up @@ -525,9 +555,9 @@ export class LayerMetadata implements ILayerMetadata, IMetadataCommonModel {
type: 'real', // check if 'decimal' type is needed
},
})
@shpMapping({
shpFile: ShapeFileType.SHAPE_METADATA,
valuePath: 'features[0].properties.Resolution',
@inputDataMapping({
dataFile: DataFileType.TFW,
valuePath: '[0]',
})
@tsTypes({
mappingType: TsTypes.NUMBER,
Expand Down Expand Up @@ -555,8 +585,8 @@ export class LayerMetadata implements ILayerMetadata, IMetadataCommonModel {
nullable: true,
},
})
@shpMapping({
shpFile: ShapeFileType.SHAPE_METADATA,
@inputDataMapping({
dataFile: DataFileType.SHAPE_METADATA,
valuePath: 'features[0].properties.Rms',
})
@tsTypes({
Expand All @@ -582,8 +612,8 @@ export class LayerMetadata implements ILayerMetadata, IMetadataCommonModel {
nullable: true,
},
})
@shpMapping({
shpFile: ShapeFileType.SHAPE_METADATA,
@inputDataMapping({
dataFile: DataFileType.SHAPE_METADATA,
valuePath: 'features[0].properties.Scale',
})
@tsTypes({
Expand All @@ -609,8 +639,8 @@ export class LayerMetadata implements ILayerMetadata, IMetadataCommonModel {
nullable: true,
},
})
@shpMapping({
shpFile: ShapeFileType.SHAPE_METADATA,
@inputDataMapping({
dataFile: DataFileType.SHAPE_METADATA,
valuePath: 'features[0].geometry',
})
@tsTypes({
Expand All @@ -636,6 +666,11 @@ export class LayerMetadata implements ILayerMetadata, IMetadataCommonModel {
nullable: true,
},
})
@inputDataMapping({
isCustomLogic: true,
dataFile: DataFileType.SHAPE_METADATA,
valuePath: '***entire geo json feature collection***',
})
@tsTypes({
mappingType: TsTypes.OBJECT,
})
Expand All @@ -650,8 +685,8 @@ export class LayerMetadata implements ILayerMetadata, IMetadataCommonModel {
return getPyCSWMapping<LayerMetadata>(new LayerMetadata(), prop);
}

public static getShpMapping(prop: string): IShpMapping | undefined {
return getShpMapping<LayerMetadata>(new LayerMetadata(), prop);
public static getShpMapping(prop: string): IDataMapping | undefined {
return getInputDataMapping<LayerMetadata>(new LayerMetadata(), prop);
}

public static getCatalogDBMapping(prop: string): ICatalogDBMapping | undefined {
Expand Down Expand Up @@ -694,13 +729,13 @@ export class LayerMetadata implements ILayerMetadata, IMetadataCommonModel {
return ret;
}

public static getShpMappings(): IPropSHPMapping[] {
public static getShpMappings(includeCustomLogic = false): IPropSHPMapping[] {
const ret = [];
const layer = new LayerMetadata();
for (const prop in layer) {
const shpMap = getShpMapping<LayerMetadata>(layer, prop);
const shpMap = getInputDataMapping<LayerMetadata>(layer, prop);
const tsTypesMap = getTsTypesMapping<LayerMetadata>(layer, prop);
if (shpMap && tsTypesMap) {
if (shpMap && tsTypesMap && (includeCustomLogic || shpMap.isCustomLogic === undefined || !shpMap.isCustomLogic)) {
ret.push({
prop: prop,
...shpMap,
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/layerMetadata.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LayerMetadata, IPYCSWMapping, IShpMapping, IPropPYCSWMapping, IPropSHPMapping, Pycsw3DCatalogRecord } from '../../src/models';
import { LayerMetadata, IPYCSWMapping, IDataMapping, IPropPYCSWMapping, IPropSHPMapping, Pycsw3DCatalogRecord } from '../../src/models';
import { ICatalogDBMapping } from '../../src/models/layerMetadata/decorators/property/catalogDB.decorator';
import { PycswLayerCatalogRecord } from '../../src/models/layerMetadata/pycswLayerCatalogRecord';

Expand All @@ -20,15 +20,15 @@ describe('LayerMetadata class static methods', () => {

it('getShpMapping(): mapped to SHAPE prop', () => {
const PROPERTY_NAME = 'footprint';
const shpMapping: IShpMapping | undefined = LayerMetadata.getShpMapping(PROPERTY_NAME);
const shpMapping: IDataMapping | undefined = LayerMetadata.getShpMapping(PROPERTY_NAME);

expect(shpMapping).toHaveProperty('shpFile');
expect(shpMapping).toHaveProperty('dataFile');
expect(shpMapping).toHaveProperty('valuePath');
});

it('getShpMapping(): NOT mapped to SHAPE prop', () => {
const PROPERTY_NAME = 'dummy_footprint';
const shpMapping: IShpMapping | undefined = LayerMetadata.getShpMapping(PROPERTY_NAME);
const shpMapping: IDataMapping | undefined = LayerMetadata.getShpMapping(PROPERTY_NAME);

expect(shpMapping).toBeUndefined();
});
Expand All @@ -48,7 +48,7 @@ describe('LayerMetadata class static methods', () => {

expect(shpMappings.length).toBeGreaterThan(0);
expect(shpMappings[0]).toHaveProperty('prop');
expect(shpMappings[0]).toHaveProperty('shpFile');
expect(shpMappings[0]).toHaveProperty('dataFile');
expect(shpMappings[0]).toHaveProperty('valuePath');
expect(shpMappings[0]).toHaveProperty('mappingType');
});
Expand Down

0 comments on commit cef3882

Please sign in to comment.