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