<commit_before>import { Location } from '@angular/common';
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';

import { Observable } from 'rxjs/Observable';

import { AlertService } from '../util/alert/alert.service';
import { forbiddenNameValidator, Validator } from '../util/validator.util';
import { RepoMirror, RepoMirrorHttpService } from '../util/http/repomirror.http.service';
import { Repo, RepoHttpService } from '../util/http/repo.http.service';

/**
  * Copyright 2017 Cinovo AG<br>
  * <br>
  *
  * @author psigloch
  */
@Component({
  selector: 'mirror-edit',
  templateUrl: './mirror.edit.comp.html'
})
export class MirrorEdit implements OnInit {

  public mode = 'edit';
  public repoName: string;
  public mirrorForm: FormGroup;

  constructor(private repoHttp: RepoHttpService,
              private mirrorHttp: RepoMirrorHttpService,
              private route: ActivatedRoute,
              private alerts: AlertService,
              private router: Router,
              private fb: FormBuilder,
              private location: Location) {
    this.mirrorForm = fb.group({
      id: '',
      description: ['', [Validators.required, forbiddenNameValidator('new')]],
      path: ['', Validators.required],
      indexerType: ['NONE'],
      providerType: ['NONE'],
      repoName: '',
      basePath: '',
      bucketName: '',
      awsRegion: '',
      accessKeyId: '',
      secretKey: ''
    });
  };

  ngOnInit(): void {
    this.route.url.subscribe((value) => {
      if (value[value.length - 1].path === 'new') {
        this.mode = 'new'
        if(window.location.port) {
          this.mirrorForm.patchValue({path: 'http://' + window.location.host + '/api/repos/'});
        }
      }
    });
    this.route.params.subscribe((params) => {
      this.repoName = params['repoName'];
      this.mirrorForm.controls.repoName.setValue(this.repoName);
      this.loadMirror(params['mirrorid'], this.repoName);
    });
  }

  get providerType() {
    return this.mirrorForm.controls.providerType.value;
  }

  save(formValue): void {
    const mirror: RepoMirror = {
      id: formValue.id,
      repo: formValue.repoName,
      description: formValue.description,
      path: formValue.path,
      indexerType: formValue.indexerType,
      providerType: formValue.providerType,
      basePath: formValue.basePath,
      bucketName: formValue.bucketName,
      awsRegion: formValue.awsRegion,
      accessKeyId: formValue.accessKeyId,
      secretKey: formValue.secretKey
    };
<commit_msg>adds a feature to prevent false mirror configurtation<commit_after>import { Location } from '@angular/common';
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';

import { Observable } from 'rxjs/Observable';

import { AlertService } from '../util/alert/alert.service';
import { forbiddenNameValidator, Validator } from '../util/validator.util';
import { RepoMirror, RepoMirrorHttpService } from '../util/http/repomirror.http.service';
import { RepoHttpService } from '../util/http/repo.http.service';

/**
 * Copyright 2017 Cinovo AG<br>
 * <br>
 *
 * @author psigloch
 */
@Component({
  selector: 'mirror-edit',
  templateUrl: './mirror.edit.comp.html'
})
export class MirrorEdit implements OnInit {

  public mode = 'edit';
  public repoName: string;
  public mirrorForm: FormGroup;

  constructor(private repoHttp: RepoHttpService,
              private mirrorHttp: RepoMirrorHttpService,
              private route: ActivatedRoute,
              private alerts: AlertService,
              private router: Router,
              private fb: FormBuilder,
              private location: Location) {
    this.mirrorForm = fb.group({
      id: '',
      description: ['', [Validators.required, forbiddenNameValidator('new')]],
      path: ['', Validators.required],
      indexerType: ['NONE'],
      providerType: ['NONE'],
      repoName: '',
      basePath: '',
      bucketName: '',
      awsRegion: '',
      accessKeyId: '',
      secretKey: ''
    });
  };

  ngOnInit(): void {
    this.route.url.subscribe((value) => {
      if (value[value.length - 1].path === 'new') {
        this.mode = 'new';
        if (window.location.port) {
          this.mirrorForm.patchValue({path: 'http://' + window.location.host + '/api/repos/'});
        }
      }
      this.mirrorForm.get('basePath').valueChanges.subscribe(val => {
        if (this.mirrorForm.controls.providerType.value == 'HTTP') {
          this.mirrorForm.controls.path.setValue(val);
          this.mirrorForm.patchValue({path: val});
        }
      });
    });
    this.route.params.subscribe((params) => {
      this.repoName = params['repoName'];
      this.mirrorForm.controls.repoName.setValue(this.repoName);
      this.loadMirror(params['mirrorid'], this.repoName);
    });
  }

  get providerType() {
    return this.mirrorForm.controls.providerType.value;
  }

  save(formValue): void {
    const mirror: RepoMirror = {
      id: formValue.id,
      repo: formValue.repoName,
      description: formValue.description,
      path: formValue.path,
      indexerType: formValue.indexerType,
      providerType: formValue.providerType,
      basePath: formValue.basePath,
      bucketName: formValue.bucketName,
      awsRegion: formValue.awsRegion,
      accessKeyId: formValue.accessKeyId,
      secretKey: formValue.secretKey
    };

{'fraction_non_alphanumeric': 0.13942652329749103, 'fraction_numerical': 0.0017921146953405018, 'mean_word_length': 2.9525495750708215, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 12, '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': '3947796', 'n_tokens_mistral': 1678, 'n_tokens_neox': 1632, 'n_words': 332}