All files JenkinsChangeSet.ts

100% Statements 31/31
100% Branches 22/22
100% Functions 4/4
100% Lines 31/31
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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90    50x 50x     2x     24x 24x 24x     48x 48x 26x   48x 26x 26x 52x     48x 26x   48x 26x   48x 26x   48x 26x   48x 26x   48x 26x   48x 26x   48x 26x   48x 26x                                                                                
 
 
import { IJenkinsChangeSet }    from './jenkins-api-ts-typings';
import { IJenkinsUser }         from './jenkins-api-ts-typings';
 
export class JenkinsChangeSet implements IJenkinsChangeSet {
    jsonData:           JSON;
    
    _class:             string;
    affectedPaths:      Array<string>;
    commitId:           string;
    timestamp:          number;
    authorEmail:        string;
    comment:            string;
    date:               Date;
    id:                 string;
    msg:                string;
    
    paths:              Array<any>;
    authorData:         any;
    author:             IJenkinsUser;
    
    constructor() {
        this.affectedPaths = new Array<string>();
        this.paths = new Array<string>();
    }
    
    getJsonData(): string {
        return JSON.stringify(this.jsonData);
    }
    
    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"];
        }
        
        if(data.hasOwnProperty("affectedPaths")) {
            let paths:Array<string> = ((data as any)["affectedPaths"]) as Array<string>;
            
            for(let affectedPath of paths) {
                this.affectedPaths.push(affectedPath);
            }
        }
        
        if(data.hasOwnProperty("commitId")) {
            this.commitId = (data as any)["commitId"];
        }
        
        if(data.hasOwnProperty("timestamp")) {
            this.timestamp = (data as any)["timestamp"];
        }
        
        if(data.hasOwnProperty("authorEmail")) {
            this.authorEmail = (data as any)["authorEmail"];
        }
        
        if(data.hasOwnProperty("comment")) {
            this.comment = (data as any)["comment"];
        }
        
        if(data.hasOwnProperty("date")) {
            this.date = new Date((data as any)["date"]);
        }
        
        if(data.hasOwnProperty("id")) {
            this.id = (data as any)["id"];
        }
        
        if(data.hasOwnProperty("msg")) {
            this.msg = (data as any)["msg"];
        }
        
        if(data.hasOwnProperty("author")) {
            this.authorData = (data as any)["author"];
        }
        
        if(data.hasOwnProperty("paths")) {
            this.paths = (data as any)["paths"];
        }
    }
}