-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): add full DAO filtering support
- Loading branch information
Benjamin Reed
committed
Jun 14, 2017
1 parent
c064d07
commit fe2204c
Showing
23 changed files
with
476 additions
and
122 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
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
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,47 @@ | ||
import {OnmsEnum} from '../internal/OnmsEnum'; | ||
|
||
/** | ||
* Represents a filter comparator. | ||
* @module Comparator | ||
*/ /** */ | ||
export class Comparator extends OnmsEnum { | ||
/** aliases for the command-line */ | ||
private aliases = [] as string[]; | ||
|
||
constructor(id: number, label: string, ...aliases: string[]) { | ||
super(id, label); | ||
this.aliases = aliases; | ||
} | ||
|
||
/** whether this comparator matches the given comparator string */ | ||
public matches(comparator: string) { | ||
return (comparator.toLowerCase() === this.label.toLowerCase()) | ||
|| this.aliases.indexOf(comparator) >= 0; | ||
} | ||
} | ||
|
||
/* tslint:disable:object-literal-sort-keys */ | ||
|
||
/** @hidden */ | ||
export const COMPARATORS = Object.freeze({ | ||
EQ: new Comparator(1, 'EQ', '=', '=='), | ||
NE: new Comparator(2, 'NE', '!='), | ||
ILIKE: new Comparator(3, 'ILIKE'), | ||
LIKE: new Comparator(4, 'LIKE'), | ||
GT: new Comparator(5, 'GT', '>'), | ||
LT: new Comparator(6, 'LT', '<'), | ||
GE: new Comparator(7, 'GE', '>='), | ||
LE: new Comparator(8, 'LE', '<='), | ||
NULL: new Comparator(9, 'NULL'), | ||
NOTNULL: new Comparator(10, 'NOTNULL'), | ||
|
||
/* | ||
ALL: new Comparator(9, 'ALL'), | ||
ANY: new Comparator(10, 'ANY'), | ||
BETWEEN: new Comparator(15, 'BETWEEN'), | ||
NOT: new Comparator(14, 'NOT'), | ||
IN: new Comparator(13, 'IN'), | ||
IPLIKE: new Comparator(17, 'IPLIKE'), | ||
SQL: new Comparator(16, 'SQL'), | ||
*/ | ||
}); |
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,15 @@ | ||
import {OnmsHTTPOptions} from '../api/OnmsHTTPOptions'; | ||
import {Restriction} from './Restriction'; | ||
|
||
/** | ||
* A query filter for DAOs. | ||
* @module Filter | ||
* @param T the model type (OnmsAlarm, OnmsEvent, etc.) | ||
*/ /** */ | ||
export class Filter<T> { | ||
/** how many results to get back by default */ | ||
public limit = 1000; | ||
|
||
/** the query restrictions to use when making requests */ | ||
public restrictions = [] as Restriction[]; | ||
} |
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,12 @@ | ||
import {Filter} from './Filter'; | ||
import {IHash} from '../internal/IHash'; | ||
|
||
/** | ||
* Interface that represents a filter processor | ||
* @module IFilterProcessor | ||
* @interface | ||
*/ /** */ | ||
export interface IFilterProcessor { | ||
/** given a filter, return a hash of URL parameters */ | ||
getParameters(filter: Filter<any>): IHash<string>; | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import {Comparator, COMPARATORS} from './Comparator'; | ||
|
||
/** | ||
* A query restriction. | ||
* @module Restriction | ||
*/ /** */ | ||
export class Restriction { | ||
/** the model attribute (name, id, etc.) to query */ | ||
public attribute: string; | ||
|
||
/** the comparator to use when querying */ | ||
public comparator: Comparator; | ||
|
||
/** the value to compare the attribute property to */ | ||
public value?: any; | ||
|
||
constructor(attribute: string, comparator: Comparator, value?: any) { | ||
this.attribute = attribute; | ||
this.comparator = comparator; | ||
this.value = value; | ||
} | ||
|
||
/** human-readable string for this restriction */ | ||
public toString() { | ||
return this.attribute + ' ' + this.comparator.label + (this.value === undefined ? '' : ' ' + this.value); | ||
} | ||
} |
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
Oops, something went wrong.