<commit_before>import { Component, OnInit, OnDestroy } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Response } from '@angular/http';

import { NgbActiveModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
import { EventManager, AlertService, JhiLanguageService } from 'ng-jhipster';

import { OAuthClient } from './oauth-client.model';
import { OAuthClientService } from './oauth-client.service';
import { OAuthClientPopupService } from './oauth-client-popup.service';

@Component({
    selector: 'jhi-oauth-client-dialog',
    templateUrl: './oauth-client-dialog.component.html'
})
export class OAuthClientDialogComponent implements OnInit  {

    client: OAuthClient;
    isSaving: boolean;
    authorities: any[];
    grantTypes: any[];
    scopeList: string;
    resourcesList: string;
    autoApproveScopeList: string;
    availableGrants: string[];
    dynamicRegistration: boolean;
    dynamicRegistrationKey: string;
    newClient: boolean;
    protectedClient: boolean;

    constructor(
        public activeModal: NgbActiveModal,
        private jhiLanguageService: JhiLanguageService,
        private alertService: AlertService,
        private oauthClientSerivce: OAuthClientService,
        private eventManager: EventManager
    ) {
        this.jhiLanguageService.addLocation('oauthClient');
        this.availableGrants = ['authorization_code', 'implicit', 'client_credentials', 'refresh_token', 'password'];
    }

    ngOnInit() {
        this.isSaving = false;
        // transform array of authorized grant types to array of objects with name and authorized property, so we can bind a checkbox to the authorized property
        this.grantTypes = [];
        this.availableGrants.forEach((grant) => {
            this.grantTypes.push({"name": grant, "authorized": this.client.authorizedGrantTypes.indexOf(grant) > -1});
        });
        // transform array of scopes to a comma seperated string so we can bind a single text box to it
        this.scopeList = this.client.scope.join(", ");
        // transform array of resources to a comma seperated string so we can bind a single text box to it
        this.resourcesList = this.client.resourceIds.join(", ");
        // transform array of auto-approve scopes to a comma seperated string so we can bind a single text box to it
        this.autoApproveScopeList = this.client.autoApproveScopes.join(", ");
        this.dynamicRegistrationKey = 'dynamic_registration';
        this.dynamicRegistration = this.client.additionalInformation[this.dynamicRegistrationKey] == 'true';
        this.authorities = ['ROLE_SYS_ADMIN'];
        // are we creating a new client?
        this.newClient = this.client.clientId == '';
        this.protectedClient = this.client.additionalInformation['protected'] == 'true';
    }
    clear() {
        this.activeModal.dismiss('cancel');
    }

    save() {
        this.isSaving = true;
        // transform the authorized grant objects back to an array of authorized grants
        this.client.authorizedGrantTypes = [];
        this.grantTypes.forEach((grant) => {
            if (grant.authorized) {
                this.client.authorizedGrantTypes.push(grant.name);
            }
        });
        // transform the scope string back to an array
        this.client.scope = this.listStringToArray(this.scopeList);
        // transform the resources string back to an array
        this.client.resourceIds = this.listStringToArray(this.resourcesList);
        // transform the auto approve scopes back to an array<commit_msg>Check for null value in autoApproveScopes<commit_after>import { Component, OnInit, OnDestroy } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Response } from '@angular/http';

import { NgbActiveModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
import { EventManager, AlertService, JhiLanguageService } from 'ng-jhipster';

import { OAuthClient } from './oauth-client.model';
import { OAuthClientService } from './oauth-client.service';
import { OAuthClientPopupService } from './oauth-client-popup.service';

@Component({
    selector: 'jhi-oauth-client-dialog',
    templateUrl: './oauth-client-dialog.component.html'
})
export class OAuthClientDialogComponent implements OnInit  {

    client: OAuthClient;
    isSaving: boolean;
    authorities: any[];
    grantTypes: any[];
    scopeList: string;
    resourcesList: string;
    autoApproveScopeList: string;
    availableGrants: string[];
    dynamicRegistration: boolean;
    dynamicRegistrationKey: string;
    newClient: boolean;
    protectedClient: boolean;

    constructor(
        public activeModal: NgbActiveModal,
        private jhiLanguageService: JhiLanguageService,
        private alertService: AlertService,
        private oauthClientSerivce: OAuthClientService,
        private eventManager: EventManager
    ) {
        this.jhiLanguageService.addLocation('oauthClient');
        this.availableGrants = ['authorization_code', 'implicit', 'client_credentials', 'refresh_token', 'password'];
    }

    ngOnInit() {
        this.isSaving = false;
        // transform array of authorized grant types to array of objects with name and authorized property, so we can bind a checkbox to the authorized property
        this.grantTypes = [];
        this.availableGrants.forEach((grant) => {
            this.grantTypes.push({"name": grant, "authorized": this.client.authorizedGrantTypes.indexOf(grant) > -1});
        });
        // transform array of scopes to a comma seperated string so we can bind a single text box to it
        this.scopeList = this.client.scope.join(", ");
        // transform array of resources to a comma seperated string so we can bind a single text box to it
        this.resourcesList = this.client.resourceIds.join(", ");
        // transform array of auto-approve scopes to a comma seperated string so we can bind a single text box to it
        this.autoApproveScopeList = this.client.autoApproveScopes ? this.client.autoApproveScopes.join(", ") : "";
        this.dynamicRegistrationKey = 'dynamic_registration';
        this.dynamicRegistration = this.client.additionalInformation[this.dynamicRegistrationKey] == 'true';
        this.authorities = ['ROLE_SYS_ADMIN'];
        // are we creating a new client?
        this.newClient = this.client.clientId == '';
        this.protectedClient = this.client.additionalInformation['protected'] == 'true';
    }
    clear() {
        this.activeModal.dismiss('cancel');
    }

    save() {
        this.isSaving = true;
        // transform the authorized grant objects back to an array of authorized grants
        this.client.authorizedGrantTypes = [];
        this.grantTypes.forEach((grant) => {
            if (grant.authorized) {
                this.client.authorizedGrantTypes.push(grant.name);
            }
        });
        // transform the scope string back to an array
        this.client.scope = this.listStringToArray(this.scopeList);
        // transform the resources string back to an array
        this.client.resourceIds = this.listStringToArray(this.resourcesList);
        // transform the auto approve scopes back to an array
{'fraction_non_alphanumeric': 0.10311850311850312, 'fraction_numerical': 0.0002772002772002772, 'mean_word_length': 3.1566820276497696, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2372689', 'n_tokens_mistral': 1924, 'n_tokens_neox': 1885, 'n_words': 529}