All files JenkinsAction.ts

100% Statements 26/26
100% Branches 10/10
100% Functions 10/10
100% Lines 25/25
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70    71x 71x     4x     18x 10x   8x 2x   6x     4x     6x 2x   4x     28x 2x   26x     12x 12x 12x     59x 59x 36x   59x 146x 110x   59x                                              
 
 
import { IJenkinsAction }       from './jenkins-api-ts-typings';
 
export class JenkinsAction implements IJenkinsAction {
    jsonData:           JSON;
    
    _class:             string;
    data:               Map<string, any>;
    
    private readonly timeInQueueClassName:string = "jenkins.metrics.impl.TimeInQueueAction";
    
    constructor() {
        this.data = new Map<string, any>();
    }
    
    getJsonData(): string {
        return JSON.stringify(this.jsonData);
    }
    
    public isClass(className: string):boolean {
        if (!this._class) {
            return false;
        }
        if (!className) {
            return false;
        }
        return this._class.toLowerCase().trim() === className.toLowerCase().trim();
    }
    
    public isTimeInQueueActionClass() {
        return this.isClass(this.timeInQueueClassName);
    }
    
    public has(keyName:string):boolean {
        if (!keyName) {
            return false;
        }
        return this.data.has(keyName);
    }
    
    public get(keyName:string):any {
        if (!keyName) {
            return undefined;
        }
        return this.data.get(keyName);
    }
    
    public fromJsonString(json: string) {
        let data:JSON = JSON.parse(json);
        this.jsonData = data;
        
        this.fromJson(data);
    }
    
    public fromJson(data: JSON) {
        this.jsonData = data;
        
        if(data.hasOwnProperty("_class")) {
            this._class = (data as any)["_class"];
        }
        
        let objectData:Map<string, any> = new Map<string, any>();
        Object.keys(data).filter(key => key !== "_class").forEach(function(key) {
            objectData.set(key, (data as any)[key]);
        });
        
        this.data = objectData;
    }
}