JaxRsMethodRepresentationExtractor(Collection)   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 2
rs 10
1
package com.hltech.pact.gen.domain.client.jaxrs;
2
3
import com.hltech.pact.gen.domain.client.ClientMethodRepresentationExtractor;
4
import com.hltech.pact.gen.domain.client.annotation.handlers.AnnotatedMethodHandler;
5
import com.hltech.pact.gen.domain.client.model.ClientMethodRepresentation;
6
import com.hltech.pact.gen.domain.client.model.RequestRepresentation;
7
8
import java.lang.reflect.Method;
9
import java.util.Collection;
10
11
public class JaxRsMethodRepresentationExtractor implements ClientMethodRepresentationExtractor {
12
13
    private final Collection<AnnotatedMethodHandler> annotatedMethodHandlers;
14
15
    public JaxRsMethodRepresentationExtractor(Collection<AnnotatedMethodHandler> annotatedMethodHandlers) {
16
        this.annotatedMethodHandlers = annotatedMethodHandlers;
17
    }
18
19
    //TODO add response extraction
20
    @Override
21
    public ClientMethodRepresentation extractClientMethodRepresentation(Method clientMethod) {
22
        return ClientMethodRepresentation.builder()
23
                .requestRepresentation(extractRequestProperties(clientMethod))
24
                .responseRepresentationList(null)
25
                .build();
26
    }
27
28
    private RequestRepresentation extractRequestProperties(Method clientMethod) {
29
        return this.annotatedMethodHandlers.stream()
30
                .filter(annotationHandler -> annotationHandler.isSupported(clientMethod))
31
                .findFirst().orElseThrow(() -> new IllegalArgumentException("Unknown HTTP method"))
32
                .handleRequest(clientMethod);
33
    }
34
}
35