opennms
Version:
Client API for the OpenNMS network monitoring platform
34 lines (28 loc) • 1.03 kB
text/typescript
import {Operator} from './Operator';
import {Restriction} from './Restriction';
import {NestedRestriction} from './NestedRestriction';
/**
* A restriction and boolean operator pair.
* @category Filtering
*/
export class Clause {
/** Given a clause JSON structure, return a Clause object. */
public static fromJson(clause: any) {
const operator = Operator.forLabel(clause.operator.label);
if (clause.restriction.clauses) {
const nestedRestriction = NestedRestriction.fromJson(clause.restriction);
return new Clause(nestedRestriction, operator);
} else {
const restriction = Restriction.fromJson(clause.restriction);
return new Clause(restriction, operator);
}
}
/** The associated restriction. */
public restriction: Restriction|NestedRestriction;
/** The boolean operator to apply. */
public operator: Operator;
constructor(restriction: Restriction|NestedRestriction, operator: Operator) {
this.restriction = restriction;
this.operator = operator;
}
}