• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

FIWARE / contract-management / #29

02 Apr 2025 12:35PM UTC coverage: 1.242% (+0.3%) from 0.982%
#29

Pull #5

wistefan
fix testing
Pull Request #5: integrate contract negotiation

3 of 127 new or added lines in 5 files covered. (2.36%)

1 existing line in 1 file now uncovered.

417 of 33568 relevant lines covered (1.24%)

0.01 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

45.71
/src/main/java/org/fiware/iam/dsp/RainbowAdapter.java
1
package org.fiware.iam.dsp;
2

3
import com.fasterxml.jackson.databind.ObjectMapper;
4
import io.micronaut.http.HttpResponse;
5
import io.micronaut.http.HttpStatus;
6
import jakarta.inject.Singleton;
7
import lombok.RequiredArgsConstructor;
8
import lombok.extern.slf4j.Slf4j;
9
import org.fiware.iam.exception.RainbowException;
10
import org.fiware.rainbow.api.AgreementApiClient;
11
import org.fiware.rainbow.api.ContractApiClient;
12
import org.fiware.rainbow.model.*;
13
import reactor.core.publisher.Mono;
14

15

16
/**
17
 * Adapter to handle communication with Rainbow.
18
 */
19
@Singleton
20
@RequiredArgsConstructor
21
@Slf4j
1✔
22
public class RainbowAdapter {
23

24
        private final AgreementApiClient agreementApiClient;
25
        private final ContractApiClient contractApiClient;
26
        private final ObjectMapper objectMapper;
27

28
        /**
29
         * Create the agreement for the given organization and offer
30
         */
31
        public Mono<AgreementVO> createAgreement(String organizationId, String offeringId) {
32
                AgreementCreateVO agreementCreateVO = new AgreementCreateVO()
1✔
33
                                .identity(organizationId)
1✔
34
                                .dataServiceId(offeringId);
1✔
35

36
                return agreementApiClient
1✔
37
                                .createAgreement(agreementCreateVO)
1✔
38
                                .map(HttpResponse::body)
1✔
39
                                .map(body -> objectMapper.convertValue(body, AgreementVO.class))
1✔
40
                                .onErrorMap(t -> {
1✔
41
                                        throw new RainbowException("Was not able to create agreement");
1✔
42
                                });
43
        }
44

45
        /**
46
         * Delete the agreement with the given id
47
         */
48
        public Mono<Boolean> deleteAgreement(String agreementId) {
49
                return agreementApiClient.deleteAgreementById(agreementId)
1✔
50
                                .map(objectHttpResponse -> {
1✔
51
                                        if (objectHttpResponse.status().equals(HttpStatus.ACCEPTED)) {
1✔
52
                                                return true;
1✔
53
                                        }
54
                                        return false;
1✔
55
                                })
56
                                .onErrorResume(t -> {
1✔
57
                                        return Mono.just(false);
×
58
                                });
59
        }
60

61
        /**
62
         * Create the given negotiation request at rainbow and return the providerId
63
         */
64
        public Mono<String> createNegotiationRequest(NegotiationRequestVO negotiationRequestVO) {
NEW
65
                return contractApiClient.createRequest(negotiationRequestVO)
×
NEW
66
                                .map(HttpResponse::body)
×
NEW
67
                                .map(NegotiationVO::getDspaceColonProviderPid)
×
NEW
68
                                .onErrorMap(t -> new RainbowException("Was not able to create negotiation request.", t));
×
69
        }
70

71
        public Mono<String> getNegotiationProcessState(String providerId) {
NEW
72
                return contractApiClient.getProcessById(providerId)
×
NEW
73
                                .map(HttpResponse::body)
×
NEW
74
                                .map(ProviderNegotiationVO::getState)
×
NEW
75
                                .onErrorMap(t -> new RainbowException(String.format("Was not able to find negotiation process %s.", providerId), t));
×
76
        }
77

78
        public Mono<Object> updateNegotiationProcessByProviderId(String providerId, String state) {
NEW
79
                return contractApiClient.getProcessById(providerId)
×
NEW
80
                                .map(HttpResponse::body)
×
NEW
81
                                .flatMap(pn -> {
×
NEW
82
                                        NegotiationProcessVO negotiationProcessVO = new NegotiationProcessVO()
×
NEW
83
                                                        .dspaceColonConsumerPid(pn.getConsumerId())
×
NEW
84
                                                        .dspaceColonProviderPid(pn.getProviderId())
×
NEW
85
                                                        .dspaceColonState(state);
×
NEW
86
                                        return contractApiClient.updateProcessById(pn.getCnProcessId(), negotiationProcessVO);
×
87
                                })
NEW
88
                                .map(HttpResponse::body)
×
NEW
89
                                .onErrorMap(t -> new RainbowException(String.format("Was not able to update negotiation process %s to %s.", providerId, state), t));
×
90
        }
91

92

93
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc