-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mapping-decorators): decorators hold mapping objects (#33)
* feat(mapping-decorators): decorators hold mapping objects * fix(pr-comments): fixed * fix(pr-comments): treated
- Loading branch information
Showing
7 changed files
with
206 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} |