Project

General

Profile

1
import { Component, OnInit, ViewChild } from '@angular/core';
2
import { ActivatedRoute } from '@angular/router';
3
import { CompatibilityValidateStep1Component } from './compatibility-validate-forms/compatibility-validate-step1.component';
4
import { RepositoryService } from '../../services/repository.service';
5
import { InterfaceInformation, JobForValidation, Repository, RuleSet } from '../../domain/typeScriptClasses';
6
import { AuthenticationService } from '../../services/authentication.service';
7
import {
8
  identifyingUrl, invalidCustomBaseUrl,
9
  loadingReposMessage, loadingRuleSets, loadingRuleSetsError,
10
  loadingUserRepoInfoError, loadingValSets, loadingValSetsError, noRuleSets
11
} from '../../domain/shared-messages';
12
import { ValidatorService } from '../../services/validator.service';
13
import { CompatibilityValidateStep2Component } from './compatibility-validate-forms/compatibility-validate-step2.component';
14
import { CompatibilityValidateStep3Component } from './compatibility-validate-forms/compatibility-validate-step3.component';
15
import { CompatibilityValidateStep3CrisComponent } from './compatibility-validate-forms/compatibility-validate-step3-cris.component';
16

    
17
@Component ({
18
  selector: 'compatibility-validate-literature',
19
  templateUrl: 'compatibility-validate-type.component.html'
20
})
21

    
22
export class CompatibilityValidateTypeComponent implements OnInit {
23
  type: string = '';
24

    
25
  showDatasource: boolean;
26
  showGuidelines: boolean;
27
  showParameters: boolean;
28
  showCrisEntities: boolean;
29
  showFinish: boolean;
30

    
31
  step2: string = '';
32
  step3: string = '';
33
  step4: string = '';
34

    
35
  baseUrlList: string[] = [];
36
  ruleSets: RuleSet[] = [];
37
  valSets: string[] = [];
38

    
39
  chosenUrl: string;
40
  identifiedUrl: boolean;
41
  chosenContentRules: number[];
42
  chosenUsageRules: number[];
43
  chosenValSet: string;
44
  noOfRecords: number;
45
  xPath: string;
46
  chosenCrisEntities: string[];
47
  crisRefIntegrity: boolean;
48

    
49
  errorMessage: string;
50
  loadingMessage: string;
51

    
52
  @ViewChild('step1ChooseBaseUrl') step1ChooseBaseUrl : CompatibilityValidateStep1Component;
53
  @ViewChild('step2ChooseGuidelines') step2ChooseGuidelines : CompatibilityValidateStep2Component;
54
  @ViewChild('step3ChooseParameters') step3ChooseParameters : CompatibilityValidateStep3Component;
55
  @ViewChild('step3ChooseCrisEntities') step3ChooseCrisEntities : CompatibilityValidateStep3CrisComponent;
56

    
57
  constructor(private route: ActivatedRoute,
58
              private authService: AuthenticationService,
59
              private repoService: RepositoryService,
60
              private valService: ValidatorService) {}
61

    
62
  ngOnInit() {
63
    this.readType();
64
    this.getBaseUrlList();
65
  }
66

    
67
  readType() {
68
    this.type = this.route.snapshot.paramMap.get('type');
69
    console.log(this.type);
70
  }
71

    
72
  /* retrieves the baseUrl list for the registered repositories of the user */
73
  getBaseUrlList() {
74
    this.loadingMessage = loadingReposMessage;
75
    this.repoService.getUrlsOfUserRepos(this.authService.getUserEmail())
76
      .subscribe(
77
        repos => this.baseUrlList = repos.sort( function(a , b){
78
          if(a < b ){
79
            return -1;
80
          } else if(a > b ){
81
            return 1;
82
          } else {
83
            return 0;
84
          }
85
        }),
86
        error => {
87
          console.log(error);
88
          this.loadingMessage = '';
89
          this.errorMessage = loadingUserRepoInfoError;
90
        },
91
        () => {
92
          this.loadingMessage = '';
93
          this.showDatasource = true;
94
        }
95
      );
96
  }
97

    
98
  moveAStep() {
99
    this.errorMessage = '';
100
    if (this.showDatasource) {
101
      if ( this.step1ChooseBaseUrl.submitForm() ) {
102
        this.identifyUrl();
103
      }
104
    } else if (this.showGuidelines) {
105
      this.step2ChooseGuidelines.saveChanges();
106
      if (this.type == 'cris'){
107
        this.showCrisEntities = true;
108
      } else {
109
        this.getValidationSets();
110
        this.showParameters = true;
111
      }
112
      this.showGuidelines = false;
113
      this.step3 = 'active';
114
    } else if (this.showParameters) {
115
      this.step3ChooseParameters.submitChanges();
116
      //save all changes
117
      //this.submitForValidation();
118
      this.showFinish = true;
119
      this.showParameters = false;
120
      this.step4 = 'active';
121
    } else if (this.showCrisEntities) {
122
      this.step3ChooseCrisEntities.saveChanges();
123
      //save all changes
124
      //this.submitForValidation();
125
      this.showFinish = true;
126
      this.showCrisEntities = false;
127
      this.step4 = 'active';
128
    }
129
  }
130

    
131
  moveBackAStep () {
132
    if (this.showGuidelines) {
133
      this.showDatasource = true;
134
      this.showGuidelines = false;
135
      this.step2 = '';
136
      this.errorMessage = '';
137
    } else if (this.showParameters) {
138
      this.step3 = '';
139
      this.showGuidelines = true;
140
      this.showParameters = false;
141
      this.errorMessage = '';
142
    } else if (this.showCrisEntities) {
143
      this.step3 = '';
144
      this.showGuidelines = true;
145
      this.showCrisEntities = false;
146
      this.errorMessage = '';
147
    }
148
  }
149

    
150
  identifyUrl() {
151
    this.loadingMessage = identifyingUrl;
152
    console.log(`identifying ${this.chosenUrl}`);
153
    this.valService.identifyRepository(this.chosenUrl).subscribe(
154
      res => {
155
        this.identifiedUrl = res;
156
        console.log(`identifyRepository responded: ${this.identifiedUrl}`);
157
      },
158
      error =>  {
159
        console.log(error);
160
        this.loadingMessage = '';
161
        this.identifiedUrl = false;
162
        this.errorMessage = invalidCustomBaseUrl;
163
      }, () => {
164
        this.loadingMessage = '';
165
        if (this.identifiedUrl) {
166
          this.getRuleSetsForType();
167
        }
168
      }
169
    );
170
  }
171

    
172
  getRuleSetsForType() {
173
    this.loadingMessage = loadingRuleSets;
174
    this.valService.getRuleSets(this.type)
175
      .subscribe(
176
        rules => this.ruleSets = rules,
177
        error => {
178
          this.loadingMessage = '';
179
          this.errorMessage = loadingRuleSetsError;
180
        },
181
        () => {
182
          this.loadingMessage = '';
183
          this.showDatasource = false;
184
          this.step2 = 'active';
185
          if (this.ruleSets.length) {
186
            this.showGuidelines = true;
187
          } else {
188
            this.errorMessage = noRuleSets;
189
          }
190
        }
191
      );
192
  }
193

    
194
  getValidationSets() {
195
    this.loadingMessage = loadingValSets;
196
    this.valService.getSetsOfRepository(this.chosenUrl)
197
      .subscribe(
198
        sets => this.valSets = sets,
199
        error => {
200
          this.errorMessage = loadingValSetsError
201
        },
202
        () => {
203
          this.loadingMessage = '';
204
          this.step2 = 'active';
205
          this.showParameters = true;
206
        }
207
      );
208
  }
209

    
210
  getChosenUrl(url: string) {
211
    this.chosenUrl = url;
212
  }
213

    
214
  getChosenRules(rules: any[]) {
215
    this.chosenContentRules = rules[0];
216
    this.chosenUsageRules = rules[1];
217
  }
218

    
219
  getChosenParameters (params: string[]) {
220
    this.chosenValSet = params[0];
221
    this.noOfRecords = +params[1];
222
    this.xPath = params[2];
223
  }
224

    
225
  getChosenCrisEntities (crisParams: any[]) {
226
    this.chosenCrisEntities = crisParams[0];
227
    console.log(this.chosenCrisEntities);
228
    this.crisRefIntegrity = crisParams[1];
229
  }
230

    
231

    
232
  submitForValidation() {
233
    let isCris: boolean;
234
    if (this.type == 'cris') {
235
      isCris = true;
236
    } else {
237
      isCris = false;
238
      this.crisRefIntegrity = null;
239
      this.chosenCrisEntities = null;
240
    }
241
    let newJob: JobForValidation = {
242
      selectedCrisEntities: this.chosenCrisEntities,
243
      selectedContentRules: this.chosenContentRules,
244
      selectedUsageRules: this.chosenUsageRules,
245

    
246
      validationSet: this.chosenValSet,
247
      records: this.noOfRecords,
248
      groupByXpath: this.xPath,
249

    
250
      cris: isCris,
251
      crisReferentialChecks: this.crisRefIntegrity,
252

    
253
      adminEmails: [],
254
      officialName: '',
255
      baseUrl: '',
256
      userEmail: '',
257
      datasourceId: '',
258
      interfaceId: '',
259
      desiredCompatibilityLevel: '',
260
      activationId: '',
261
      repoType: '',
262
      interfaceIdOld: '',
263
      metadataPrefix: '',
264

    
265
      registration: null,
266
      updateExisting: null
267
    }
268
  }
269

    
270
}
(6-6/15)