Skip to content

Commit

Permalink
feat(mapping-decorators): decorators hold mapping objects (#33)
Browse files Browse the repository at this point in the history
* feat(mapping-decorators): decorators hold mapping objects

* fix(pr-comments): fixed

* fix(pr-comments): treated
  • Loading branch information
alebinson authored Feb 15, 2021
1 parent d34d2d4 commit ded1f7e
Show file tree
Hide file tree
Showing 7 changed files with 206 additions and 34 deletions.
17 changes: 17 additions & 0 deletions models/layerMetadata/decorators/csw.decorator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import "reflect-metadata";

const pycswMappingMetadataKey = Symbol("pycswmapping");

export interface IPYCSWMapping {
xmlElement: string; // pycsw XML element
queryableField: string; // pycsw ProfileRepository Queryable field
pycswField?: string; // pycsw core field
}

export function pycsw(pycswmapping: IPYCSWMapping) {
return Reflect.metadata(pycswMappingMetadataKey, pycswmapping);
}

export function getPyCSWMapping(target: any, propertyKey: string) {
return Reflect.getMetadata(pycswMappingMetadataKey, target, propertyKey);
}
22 changes: 22 additions & 0 deletions models/layerMetadata/decorators/shp.decorator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import "reflect-metadata";

const shpMappingMetadataKey = Symbol("shpmapping");

export interface IShpMapping {
shpFile: ShapeFileType;
valuePath: string;
}

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

export function shpMapping(shpmapping: IShpMapping) {
return Reflect.metadata(shpMappingMetadataKey, shpmapping);
}

export function getShpMapping(target: any, propertyKey: string) {
return Reflect.getMetadata(shpMappingMetadataKey, target, propertyKey);
}
2 changes: 1 addition & 1 deletion models/layerMetadata/layerMetadata-StatusFields.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { LayerMetadata } from "./layerMetadata";

export interface StatusMetadata extends LayerMetadata {
export class StatusMetadata extends LayerMetadata {
/**
* Layer creation time
*/
Expand Down
156 changes: 139 additions & 17 deletions models/layerMetadata/layerMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,56 +1,178 @@
import { GeoJSON } from "geojson";
import { getPyCSWMapping, IPYCSWMapping, pycsw } from "./decorators/csw.decorator";
import { getShpMapping, IShpMapping, ShapeFileType, shpMapping } from "./decorators/shp.decorator";

export interface IPropSHPMapping extends IShpMapping{
prop: string
}

export interface IPropPYCSWMapping extends IPYCSWMapping{
prop: string
}

export enum SensorType {
VIS = "VIS",
RGB = "RGB",
Pan_Sharpen = "Pan_Sharpen",
OTHER = "OTHER",
VIS = 'VIS',
RGB = 'RGB',
Pan_Sharpen = 'Pan_Sharpen',
OTHER = 'OTHER',
}

export interface LayerMetadata {
export class LayerMetadata {
/**
* Layer's unique identifier
*/
source?: string;
@pycsw({
xmlElement: 'mc:source',
queryableField: 'mcgc:source',
pycswField: 'pycsw:Source',
})
@shpMapping({
shpFile: ShapeFileType.SHAPE_METADATA,
valuePath: 'features[0].properties.Source'
})
source?: string = undefined;

/**
* layer version
*/
version?: string;
version?: string = undefined;

/**
* Layer's source name
*/
sourceName?: string;
@shpMapping({
shpFile: ShapeFileType.SHAPE_METADATA,
valuePath: 'features[0].properties.SourceName'
})
sourceName?: string = undefined;

/**
* Layer creation time
*/
updateDate?: Date;
@shpMapping({
shpFile: ShapeFileType.SHAPE_METADATA,
valuePath: 'features[0].properties.UpdateDate'
})
updateDate?: Date = undefined;

/**
* Layer resolution
*/
resolution?: number;
@shpMapping({
shpFile: ShapeFileType.SHAPE_METADATA,
valuePath: 'features[0].properties.Resolution'
})
resolution?: number = undefined;

/**
* accuracy
*/
ep90?: number;
@shpMapping({
shpFile: ShapeFileType.SHAPE_METADATA,
valuePath: 'features[0].properties.Ep90'
})
ep90?: number = undefined;

/**
* Layer sensor type
*/
sensorType?: SensorType;
rms?: number;
@shpMapping({
shpFile: ShapeFileType.SHAPE_METADATA,
valuePath: 'features[0].properties.SensorType'
})
sensorType?: SensorType = undefined;

/**
* RMS
*/
@shpMapping({
shpFile: ShapeFileType.SHAPE_METADATA,
valuePath: 'features[0].properties.Rms'
})
rms?: number = undefined;

/**
* Scale of layer
*/
scale?: string;
@shpMapping({
shpFile: ShapeFileType.SHAPE_METADATA,
valuePath: 'features[0].properties.Scale'
})
scale?: string = undefined;

/**
* Layer description
*/
dsc?: string;
@pycsw({
xmlElement: 'mc:description',
queryableField: 'mcgc:description',
pycswField: 'pycsw:Abstract',
})
@shpMapping({
shpFile: ShapeFileType.SHAPE_METADATA,
valuePath: 'features[0].properties.Dsc'
})
dsc?: string = undefined;

/**
* List of URIs for the layer files
*/
fileUris?: string[];
fileUris?: string[] = undefined;

/**
* General geometry
*/
geometry?: GeoJSON;
@pycsw({
xmlElement: 'ows:BoundingBox',
queryableField: 'mcgc:boundingBox',
pycswField: 'pycsw:BoundingBox',
})
@shpMapping({
shpFile: ShapeFileType.SHAPE_METADATA,
valuePath: 'features[0].geometry'
})
geometry?: GeoJSON = undefined;

static getPyCSWMapping(prop: string): IPYCSWMapping {
return getPyCSWMapping(new LayerMetadata(), prop);
}

static getShpMapping(prop: string): IShpMapping {
return getShpMapping(new LayerMetadata(), prop);
}

static getPyCSWMappings(): IPropPYCSWMapping[] {
const ret = [];
const layer = new LayerMetadata();
for(const prop in layer){
if (layer.hasOwnProperty(prop)) {
const pycswMap = getPyCSWMapping(layer, prop);
if(pycswMap){
ret.push({
prop: prop,
...pycswMap
});
}
}
}
return ret;
}

static getShpMappings(): IPropSHPMapping[] {
const ret = [];
const layer = new LayerMetadata();
for(const prop in layer){
if (layer.hasOwnProperty(prop)) {
const shpMap = getShpMapping(layer, prop);
if(shpMap){
ret.push({
prop: prop,
...shpMap
});
}
}
}
return ret;
}

}
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"prepack": "npm run clean && npm run build && npm run copy"
},
"dependencies": {
"@types/geojson": "^7946.0.7"
"@types/geojson": "^7946.0.7",
"reflect-metadata": "^0.1.13"
},
"devDependencies": {
"@commitlint/cli": "^9.1.2",
Expand Down
34 changes: 19 additions & 15 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
{
"compilerOptions": {
"target": "ES5",
"module": "commonjs",
"declaration": true,
"outDir": "Schema",
"rootDir": ".",
"strict": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"moduleResolution": "node"
},
"include": ["models"],
"exclude": ["node_modules"]
}

"compilerOptions": {
"target": "ES5",
"module": "commonjs",
"experimentalDecorators": true,
"declaration": true,
"outDir": "Schema",
"rootDir": ".",
"strict": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"moduleResolution": "node"
},
"include": [
"models"
],
"exclude": [
"node_modules"
]
}

0 comments on commit ded1f7e

Please sign in to comment.