1
|
|
|
package com.hltech.judged.server.interfaces.rest.validation; |
2
|
|
|
|
3
|
|
|
import com.google.common.collect.Ordering; |
4
|
|
|
import com.hltech.judged.server.domain.ServiceVersion; |
5
|
|
|
import com.hltech.judged.server.domain.validation.EnvironmentValidatorResult; |
6
|
|
|
|
7
|
|
|
import java.util.Collection; |
8
|
|
|
import java.util.Comparator; |
9
|
|
|
import java.util.List; |
10
|
|
|
import java.util.Map; |
11
|
|
|
import java.util.stream.Collectors; |
12
|
|
|
|
13
|
|
|
import static com.google.common.collect.Maps.newHashMap; |
14
|
|
|
|
15
|
|
|
public class Converters { |
16
|
|
|
|
17
|
|
|
private Converters() { |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public static List<ContractValidationReportDto> toDtos(ServiceVersion serviceVersion, Collection<EnvironmentValidatorResult> validationResults) { |
21
|
|
|
Map<ConsumerAndProviderDto, ContractValidationReportDto> result = newHashMap(); |
22
|
|
|
validationResults |
23
|
|
|
.stream() |
24
|
|
|
.forEach(environmentValidatorResult -> { |
25
|
|
|
environmentValidatorResult.getCapabilitiesValidationResults() |
26
|
|
|
.stream() |
27
|
|
|
.forEach(cvr -> { |
28
|
|
|
ConsumerAndProviderDto key = new ConsumerAndProviderDto(cvr.getConsumerName(), cvr.getConsumerVersion(), serviceVersion.getName(), serviceVersion.getVersion()); |
29
|
|
|
if (!result.containsKey(key)) { |
30
|
|
|
result.put( |
31
|
|
|
key, |
32
|
|
|
new ContractValidationReportDto(key) |
33
|
|
|
); |
34
|
|
|
} |
35
|
|
|
result.get(key).addInteractions( |
36
|
|
|
cvr.getInteractionValidationResults() |
37
|
|
|
.stream() |
38
|
|
|
.map(ivr -> new InteractionValidationReportDto( |
39
|
|
|
environmentValidatorResult.getCommunicationInterface(), |
40
|
|
|
ivr.getName(), |
41
|
|
|
ivr.getStatus(), |
42
|
|
|
ivr.getErrors() |
43
|
|
|
)) |
44
|
|
|
.collect(Collectors.toList()) |
45
|
|
|
); |
46
|
|
|
}); |
47
|
|
|
environmentValidatorResult.getExpectationValidationResults() |
48
|
|
|
.stream() |
49
|
|
|
.forEach(evr -> { |
50
|
|
|
ConsumerAndProviderDto key = new ConsumerAndProviderDto(serviceVersion.getName(), serviceVersion.getVersion(), evr.getProviderName(), evr.getProviderVersion()); |
51
|
|
|
if (!result.containsKey(key)) { |
52
|
|
|
result.put( |
53
|
|
|
key, |
54
|
|
|
new ContractValidationReportDto(key) |
55
|
|
|
); |
56
|
|
|
} |
57
|
|
|
result.get(key).addInteractions( |
58
|
|
|
evr.getInteractionValidationResults() |
59
|
|
|
.stream() |
60
|
|
|
.map(ivr -> new InteractionValidationReportDto( |
61
|
|
|
environmentValidatorResult.getCommunicationInterface(), |
62
|
|
|
ivr.getName(), |
63
|
|
|
ivr.getStatus(), |
64
|
|
|
ivr.getErrors() |
65
|
|
|
)) |
66
|
|
|
.collect(Collectors.toList()) |
67
|
|
|
); |
68
|
|
|
}); |
69
|
|
|
}); |
70
|
|
|
|
71
|
|
|
return Ordering |
72
|
|
|
.from((Comparator<ContractValidationReportDto>) (o1, o2) -> o1.getConsumerAndProvider().toString().compareTo(o2.getConsumerAndProvider().toString())) |
73
|
|
|
.sortedCopy(result.values()); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|