Permalink
Browse files

feat(dao): use JSON against modern (19+) OpenNMS instead of XML

  • Loading branch information...
RangerRick committed Aug 1, 2017
1 parent 55028cb commit c17db2c5e4d183c8870108f4602d85617f07fa6d
Showing with 19 additions and 2 deletions.
  1. +5 −0 src/api/ServerMetadata.ts
  2. +14 −2 src/dao/AbstractDAO.ts
@@ -51,6 +51,11 @@ export class ServerMetadata {
return this.version.ge('15.0.2');
}
/** Is it safe to use JSON for most operations? */
public useJson() {
return this.version.ge('19.0.0');
}
/** What version of the ReST API does this server support? */
public apiVersion() {
if (this.type && this.type === ServerTypes.MERIDIAN) {
View
@@ -156,8 +156,13 @@ export abstract class AbstractDAO<K, T> {
*/
protected getOptions(filter?: Filter): OnmsHTTPOptions {
const ret = new OnmsHTTPOptions();
// always use application/xml for now in DAO calls
ret.headers.accept = 'application/xml';
if (this.useJson()) {
ret.headers.accept = 'application/json';
} else {
// always use application/xml in DAO calls when we're not sure how
// usable JSON output will be.
ret.headers.accept = 'application/xml';
}
if (filter) {
ret.parameters = this.filterProcessor.getParameters(filter);
}
@@ -182,6 +187,13 @@ export abstract class AbstractDAO<K, T> {
return isNaN(ret) ? undefined : ret;
}
protected useJson(): boolean {
if (this.http === undefined || this.http.server === undefined || this.http.server.metadata === undefined) {
throw new OnmsError('Server meta-data must be populated prior to making DAO calls.');
}
return this.http.server.metadata.useJson();
}
/**
* Generate a [[SearchProperty]] from the given dictionary.
* @hidden

0 comments on commit c17db2c

Please sign in to comment.