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
|
chosenGuidelinesAcronym: string;
|
42
|
chosenContentRules: number[];
|
43
|
chosenUsageRules: number[];
|
44
|
chosenValSet: string;
|
45
|
noOfRecords: number;
|
46
|
xPath: string;
|
47
|
chosenCrisEntities: string[];
|
48
|
crisRefIntegrity: boolean;
|
49
|
|
50
|
errorMessage: string;
|
51
|
loadingMessage: string;
|
52
|
|
53
|
@ViewChild('step1ChooseBaseUrl') step1ChooseBaseUrl : CompatibilityValidateStep1Component;
|
54
|
@ViewChild('step2ChooseGuidelines') step2ChooseGuidelines : CompatibilityValidateStep2Component;
|
55
|
@ViewChild('step3ChooseParameters') step3ChooseParameters : CompatibilityValidateStep3Component;
|
56
|
@ViewChild('step3ChooseCrisEntities') step3ChooseCrisEntities : CompatibilityValidateStep3CrisComponent;
|
57
|
|
58
|
constructor(private route: ActivatedRoute,
|
59
|
private authService: AuthenticationService,
|
60
|
private repoService: RepositoryService,
|
61
|
private valService: ValidatorService) {}
|
62
|
|
63
|
ngOnInit() {
|
64
|
this.readType();
|
65
|
this.showDatasource = true;
|
66
|
this.getBaseUrlList();
|
67
|
}
|
68
|
|
69
|
readType() {
|
70
|
this.type = this.route.snapshot.paramMap.get('type');
|
71
|
console.log(this.type);
|
72
|
}
|
73
|
|
74
|
/* retrieves the baseUrl list for the registered repositories of the user */
|
75
|
getBaseUrlList() {
|
76
|
this.loadingMessage = loadingReposMessage;
|
77
|
this.repoService.getUrlsOfUserRepos(this.authService.getUserEmail())
|
78
|
.subscribe(
|
79
|
repos => this.baseUrlList = repos.sort( function(a , b){
|
80
|
if(a < b ){
|
81
|
return -1;
|
82
|
} else if(a > b ){
|
83
|
return 1;
|
84
|
} else {
|
85
|
return 0;
|
86
|
}
|
87
|
}),
|
88
|
error => {
|
89
|
console.log(error);
|
90
|
this.loadingMessage = '';
|
91
|
this.errorMessage = loadingUserRepoInfoError;
|
92
|
},
|
93
|
() => {
|
94
|
this.loadingMessage = '';
|
95
|
}
|
96
|
);
|
97
|
}
|
98
|
|
99
|
moveAStep() {
|
100
|
this.errorMessage = '';
|
101
|
if (this.showDatasource) {
|
102
|
if ( this.step1ChooseBaseUrl.submitForm() ) {
|
103
|
this.identifyUrl();
|
104
|
}
|
105
|
} else if (this.showGuidelines) {
|
106
|
this.step2ChooseGuidelines.saveChanges();
|
107
|
if (this.type == 'cris'){
|
108
|
this.showCrisEntities = true;
|
109
|
} else {
|
110
|
this.getValidationSets();
|
111
|
this.showParameters = true;
|
112
|
}
|
113
|
this.showGuidelines = false;
|
114
|
this.step3 = 'active';
|
115
|
} else if (this.showParameters) {
|
116
|
this.step3ChooseParameters.submitChanges();
|
117
|
//save all changes
|
118
|
//this.submitForValidation();
|
119
|
this.showFinish = true;
|
120
|
this.showParameters = false;
|
121
|
this.step4 = 'active';
|
122
|
} else if (this.showCrisEntities) {
|
123
|
this.step3ChooseCrisEntities.saveChanges();
|
124
|
//save all changes
|
125
|
//this.submitForValidation();
|
126
|
this.showFinish = true;
|
127
|
this.showCrisEntities = false;
|
128
|
this.step4 = 'active';
|
129
|
}
|
130
|
}
|
131
|
|
132
|
moveBackAStep () {
|
133
|
if (this.showGuidelines) {
|
134
|
this.showDatasource = true;
|
135
|
this.showGuidelines = false;
|
136
|
this.step2 = '';
|
137
|
this.errorMessage = '';
|
138
|
} else if (this.showParameters) {
|
139
|
this.step3 = '';
|
140
|
this.showGuidelines = true;
|
141
|
this.showParameters = false;
|
142
|
this.errorMessage = '';
|
143
|
} else if (this.showCrisEntities) {
|
144
|
this.step3 = '';
|
145
|
this.showGuidelines = true;
|
146
|
this.showCrisEntities = false;
|
147
|
this.errorMessage = '';
|
148
|
}
|
149
|
}
|
150
|
|
151
|
identifyUrl() {
|
152
|
this.loadingMessage = identifyingUrl;
|
153
|
console.log(`identifying ${this.chosenUrl}`);
|
154
|
this.valService.identifyRepository(this.chosenUrl).subscribe(
|
155
|
res => {
|
156
|
this.identifiedUrl = res;
|
157
|
console.log(`identifyRepository responded: ${this.identifiedUrl}`);
|
158
|
},
|
159
|
error => {
|
160
|
console.log(error);
|
161
|
this.loadingMessage = '';
|
162
|
this.identifiedUrl = false;
|
163
|
this.errorMessage = invalidCustomBaseUrl;
|
164
|
}, () => {
|
165
|
this.loadingMessage = '';
|
166
|
if (this.identifiedUrl) {
|
167
|
this.getRuleSetsForType();
|
168
|
}
|
169
|
}
|
170
|
);
|
171
|
}
|
172
|
|
173
|
getRuleSetsForType() {
|
174
|
this.loadingMessage = loadingRuleSets;
|
175
|
this.valService.getRuleSets(this.type)
|
176
|
.subscribe(
|
177
|
rules => this.ruleSets = rules,
|
178
|
error => {
|
179
|
this.loadingMessage = '';
|
180
|
this.errorMessage = loadingRuleSetsError;
|
181
|
},
|
182
|
() => {
|
183
|
this.loadingMessage = '';
|
184
|
this.showDatasource = false;
|
185
|
this.step2 = 'active';
|
186
|
if (this.ruleSets.length) {
|
187
|
this.showGuidelines = true;
|
188
|
} else {
|
189
|
this.errorMessage = noRuleSets;
|
190
|
}
|
191
|
}
|
192
|
);
|
193
|
}
|
194
|
|
195
|
getValidationSets() {
|
196
|
this.loadingMessage = loadingValSets;
|
197
|
this.valService.getSetsOfRepository(this.chosenUrl)
|
198
|
.subscribe(
|
199
|
sets => this.valSets = sets,
|
200
|
error => {
|
201
|
this.errorMessage = loadingValSetsError
|
202
|
},
|
203
|
() => {
|
204
|
this.loadingMessage = '';
|
205
|
this.step2 = 'active';
|
206
|
this.showParameters = true;
|
207
|
}
|
208
|
);
|
209
|
}
|
210
|
|
211
|
getChosenUrl(url: string) {
|
212
|
this.chosenUrl = url;
|
213
|
}
|
214
|
|
215
|
getChosenRules(rules: any[]) {
|
216
|
this.chosenGuidelinesAcronym = rules[0];
|
217
|
this.chosenContentRules = rules[1];
|
218
|
this.chosenUsageRules = rules[2];
|
219
|
}
|
220
|
|
221
|
getChosenParameters (params: string[]) {
|
222
|
this.chosenValSet = params[0];
|
223
|
this.noOfRecords = +params[1];
|
224
|
this.xPath = params[2];
|
225
|
}
|
226
|
|
227
|
getChosenCrisEntities (crisParams: any[]) {
|
228
|
this.chosenCrisEntities = crisParams[0];
|
229
|
console.log(this.chosenCrisEntities);
|
230
|
this.crisRefIntegrity = crisParams[1];
|
231
|
}
|
232
|
|
233
|
|
234
|
submitForValidation() {
|
235
|
let isCris: boolean;
|
236
|
if (this.type == 'cris') {
|
237
|
isCris = true;
|
238
|
} else {
|
239
|
isCris = false;
|
240
|
this.crisRefIntegrity = null;
|
241
|
this.chosenCrisEntities = null;
|
242
|
}
|
243
|
let newJob: JobForValidation = {
|
244
|
selectedCrisEntities: this.chosenCrisEntities,
|
245
|
selectedContentRules: this.chosenContentRules,
|
246
|
selectedUsageRules: this.chosenUsageRules,
|
247
|
|
248
|
desiredCompatibilityLevel: this.chosenGuidelinesAcronym,
|
249
|
baseUrl: this.chosenUrl,
|
250
|
|
251
|
validationSet: this.chosenValSet,
|
252
|
records: this.noOfRecords,
|
253
|
groupByXpath: this.xPath,
|
254
|
|
255
|
cris: isCris,
|
256
|
crisReferentialChecks: this.crisRefIntegrity,
|
257
|
|
258
|
userEmail: this.authService.userEmail,
|
259
|
|
260
|
adminEmails: [],
|
261
|
officialName: '',
|
262
|
datasourceId: '',
|
263
|
interfaceId: '',
|
264
|
activationId: '',
|
265
|
repoType: '',
|
266
|
interfaceIdOld: '',
|
267
|
metadataPrefix: '',
|
268
|
|
269
|
registration: false,
|
270
|
updateExisting: null
|
271
|
}
|
272
|
}
|
273
|
|
274
|
}
|