Skip to content

Commit

Permalink
fix(rest): use negative offset for dates to work around a server issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Reed committed Aug 16, 2017
1 parent 9b79121 commit abdfc0b
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/dao/V2FilterProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class V2FilterProcessor implements IFilterProcessor {
* This must be explicitly set as the restriction value when using
* either the NULL or NOTNULL comparators on date fields.
*/
public static NULL_DATE = '1970-01-01T00:00:00.000+0000';
public static NULL_DATE = '1970-01-01T00:00:00.000-0000';

/** The accessor for Properties */
private searchPropertyAccessor: ISearchPropertyAccessor;
Expand Down
13 changes: 1 addition & 12 deletions src/internal/Util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,9 @@ export class Util {
public static toDateString(date: Date|Moment|number) {
const ret = Util.toMoment(date);
if (ret) {
return ret.utc().format(dateFormat);
return ret.utc().format(dateFormat).replace('+0000', '-0000');
} else {
return undefined;
}
}

/**
* Encodes the parameters.
* @param pramaters the parameters to encode
*/
public static encodeParameters(pramaters: any) {
Object.keys(pramaters).forEach((key, index) => {
pramaters[key] = encodeURIComponent(pramaters[key]);
});
return pramaters;
}
}
2 changes: 1 addition & 1 deletion src/rest/AxiosHTTP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export class AxiosHTTP extends AbstractHTTP {
}

if (allOptions.parameters) {
ret.params = Util.encodeParameters(clonedeep(allOptions.parameters));
ret.params = clonedeep(allOptions.parameters);
}

if (allOptions.data) {
Expand Down
2 changes: 1 addition & 1 deletion src/rest/GrafanaHTTP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export class GrafanaHTTP extends AbstractHTTP {
}

if (allOptions.parameters && Object.keys(allOptions.parameters).length > 0) {
ret.params = Util.encodeParameters(clonedeep(allOptions.parameters));
ret.params = clonedeep(allOptions.parameters);
}

if (allOptions.data) {
Expand Down
4 changes: 2 additions & 2 deletions test/dao/V1FilterProcessor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ describe('V1FilterProcessor', () => {
proc.getParameters(filter);
}).toThrow(OnmsError);
});
it('alarm filter: lastEventTime=1976-04-14T00:00:00.000+0000', () => {
it('alarm filter: lastEventTime=1976-04-14T00:00:00.000-0000', () => {
const filter = new Filter();
filter.withOrRestriction(new Restriction('lastEventTime', Comparators.EQ, new Date(198288000000)));
const proc = new V1FilterProcessor();
expect(proc.getParameters(filter)).toMatchObject({
lastEventTime: '1976-04-14T00:00:00.000+0000'
lastEventTime: '1976-04-14T00:00:00.000-0000'
});
});
});
16 changes: 8 additions & 8 deletions test/dao/V2FilterProcessor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('V2FilterProcessor', () => {
const filter = new Filter();
filter.withOrRestriction(new Restriction('id', Comparators.NOTNULL));
filter.withOrRestriction(new Restriction('ackTime', Comparators.NULL, V2FilterProcessor.NULL_DATE));
expect(toSearch(filter)).toEqual('id!=\u0000,ackTime==1970-01-01T00:00:00.000+0000');
expect(toSearch(filter)).toEqual('id!=\u0000,ackTime==1970-01-01T00:00:00.000-0000');
});
it('alarm filter: id=notnull OR severity="MINOR"', () => {
const filter = new Filter();
Expand Down Expand Up @@ -95,14 +95,14 @@ describe('V2FilterProcessor', () => {
);
expect(toSearch(filter)).toEqual('id!=0;(severity==5,uei==*somethingWentWrong)');
});
it('alarm filter: lastEventTime=1976-04-14T00:00:00.000+0000', () => {
const filter = new Filter();
filter.withAndRestriction(new Restriction('lastEventTime', Comparators.EQ, new Date(198288000000)));
expect(toSearch(filter)).toEqual('lastEventTime==1976-04-14T00:00:00.000+0000');
it('alarm filter: lastEventTime=1976-04-14T00:00:00.000-0000', () => {
const filter = new Filter();
filter.withAndRestriction(new Restriction('lastEventTime', Comparators.EQ, new Date(198288000000)));
expect(toSearch(filter)).toEqual('lastEventTime==1976-04-14T00:00:00.000-0000');
});
it('alarm filter: verify null replacement for EQ and NE comparators', () => {
// the filter does not make any sense, but is there to verify that null replacement works correctly
const filter = new Filter<OnmsAlarm>()
const filter = new Filter()
.withAndRestriction(new Restriction('alarmAckTime', Comparators.EQ, 'null'))
.withAndRestriction(new Restriction('alarmAckTime', Comparators.NE, 'null'))
.withAndRestriction(new Restriction('id', Comparators.EQ, 'null'))
Expand All @@ -112,8 +112,8 @@ describe('V2FilterProcessor', () => {
{ id: 'alarmAckTime', type: SearchPropertyTypes.TIMESTAMP } as SearchProperty,
]));
expect(toSearch(filter, proc)).toEqual(
'alarmAckTime==1970-01-01T00:00:00.000+0000'
+ ';alarmAckTime!=1970-01-01T00:00:00.000+0000'
'alarmAckTime==1970-01-01T00:00:00.000-0000'
+ ';alarmAckTime!=1970-01-01T00:00:00.000-0000'
+ ';id==\u0000;id!=\u0000');
});
});
8 changes: 4 additions & 4 deletions test/internal/Util.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {Moment} from 'moment';
const moment = require('moment');

/** @hidden */
const ARBITRARY_STRING = '2017-08-08T12:29:56.000+0000';
const ARBITRARY_STRING = '2017-08-08T12:29:56.000-0000';

/** @hidden */
const ARBITRARY_EPOCH = 1502195396000;
Expand Down Expand Up @@ -95,15 +95,15 @@ describe('Util.toDateString()', () => {
expect(Util.toDateString(null)).toBeUndefined();
});
it('moment(0)', () => {
expect(Util.toDateString(moment(0))).toEqual('1970-01-01T00:00:00.000+0000');
expect(Util.toDateString(moment(0))).toEqual('1970-01-01T00:00:00.000-0000');
});
it('0', () => {
expect(Util.toDateString(0)).toEqual('1970-01-01T00:00:00.000+0000');
expect(Util.toDateString(0)).toEqual('1970-01-01T00:00:00.000-0000');
});
it('new Date()', () => {
expect(Util.toDateString(new Date(ARBITRARY_EPOCH))).toEqual(ARBITRARY_STRING);
});
it('new Date(0)', () => {
expect(Util.toDateString(new Date(0))).toEqual('1970-01-01T00:00:00.000+0000');
expect(Util.toDateString(new Date(0))).toEqual('1970-01-01T00:00:00.000-0000');
});
});

0 comments on commit abdfc0b

Please sign in to comment.