{"size": 2248, "ext": "js", "max_stars_repo_path": "clustersController/strategies/jenkinsController.js", "max_stars_repo_name": "RomSoftIasi/governance-workspace", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "clustersController/strategies/jenkinsController.js", "max_issues_repo_name": "RomSoftIasi/governance-workspace", "max_issues_repo_issues_event_min_datetime": "2021-06-24T06:35:58.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-02T07:59:33.000Z", "max_forks_repo_path": "clustersController/strategies/jenkinsController.js", "max_forks_repo_name": "RomSoftIasi/governance-workspace", "max_forks_repo_forks_event_min_datetime": "2021-05-10T12:40:54.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-25T15:00:23.000Z"}
{"max_stars_count": null, "max_issues_count": 9, "max_forks_count": 2, "avg_line_length": 31.661971831, "max_line_length": 95, "alphanum_fraction": 0.5409252669}
class jenkinsController{
    constructor(jenkinsOperationStatus) {
        const jenkinsService = require('../strategies/jenkinsService');
        this.jenkinsServiceInstance = new jenkinsService(jenkinsOperationStatus);
    }

    InitiateClusterOperation(request, response){
        this.jenkinsServiceInstance.executeClusterOperation(request.body,(err, result) => {
            if (err) {
                return response.send(500, {err: err});
            }

            response.send(202, result);
        });
    };

    GetOperationStatus(request, response){
        const blockchainNetwork = request.params.networkId;
        this.jenkinsServiceInstance.getOperationStatus(blockchainNetwork, (err, result) => {
            if (err) {
                return response.send(500, {});
            }
            if (result.status && result.status === 'Pending')
            {
                response.send(202, result);
            }else{
                response.send(201, result);
            }
        });
    };

    DeleteOperationStatus(request, response){
        const blockchainNetwork = request.params.networkId;
        this.jenkinsServiceInstance.deleteOperationStatus(blockchainNetwork, (err, result) => {
            if (err) {
                console.log(err);
                return response.send(500, {});
            }

            response.send(201, result);
        });
    }

    ExecuteCommandCluster(request, response){
        this.jenkinsServiceInstance.executeCommandCluster(request.body, (err, result) => {
            if (err) {
                if (err.code === 'EACCES') {
                    return response.send(409);
                }
                return response.send(500);
            }
            if ( typeof result.on === 'function')
            {
                console.log('raw handling with headers');

                response.statusCode = result.statusCode;
                response.headers = result.headers;
                response.setHeader('Content-Type','application/raw');
                result.pipe(response);

            }else {
                console.log('json handling')
                response.send(201, result);
            }

        });
    }
}

module.exports = jenkinsController;
