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

wistefan / tmforum-api / #62

19 Oct 2023 01:12PM UTC coverage: 68.167% (+0.5%) from 67.631%
#62

push

web-flow
Account management api implementation (#34)

* Creating the directories

* Adding pom

* now adding pom, error on last commit

* Account complete implementation, no testing

* Solving problems with git config

* Adding some left out classes and some tests

* Adding FinancialAccount Integration Test and solving some errors on the main classes

* adding Integration Test and solved errors for Party, Bill, Settlement and Financial Account, and BillFormat

* Adding final integration tests and adapting api to query format

* Fixing Event Subscription

* Cleaning the code from comments

---------

Co-authored-by: MVazquez <marcosvazquezcampos@MacBook-Air-de-Marcos.local>

475 of 475 new or added lines in 32 files covered. (100.0%)

3150 of 4621 relevant lines covered (68.17%)

0.68 hits per line

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

96.77
/account/src/main/java/org/fiware/tmforum/account/rest/PartyAccountApiController.java
1
package org.fiware.tmforum.account.rest;
2

3
import io.micronaut.http.HttpResponse;
4
import io.micronaut.http.annotation.Controller;
5
import lombok.extern.slf4j.Slf4j;
6
import org.fiware.account.api.PartyAccountApi;
7
import org.fiware.account.model.PartyAccountCreateVO;
8
import org.fiware.account.model.PartyAccountUpdateVO;
9
import org.fiware.account.model.PartyAccountVO;
10
import org.fiware.tmforum.common.notification.EventHandler;
11
import org.fiware.tmforum.common.exception.TmForumException;
12
import org.fiware.tmforum.common.exception.TmForumExceptionReason;
13
import org.fiware.tmforum.common.mapping.IdHelper;
14
import org.fiware.tmforum.common.querying.QueryParser;
15
import org.fiware.tmforum.common.repository.TmForumRepository;
16
import org.fiware.tmforum.common.rest.AbstractApiController;
17
import org.fiware.tmforum.common.validation.ReferenceValidationService;
18
import org.fiware.tmforum.common.validation.ReferencedEntity;
19
import org.fiware.tmforum.account.TMForumMapper;
20
import org.fiware.tmforum.account.domain.PartyAccount;
21
import reactor.core.publisher.Mono;
22

23
import javax.annotation.Nullable;
24
import java.util.ArrayList;
25
import java.util.List;
26
import java.util.Optional;
27
import java.util.UUID;
28

29
@Slf4j
1✔
30
@Controller("${general.basepath:/}")
31
public class PartyAccountApiController extends AbstractApiController<PartyAccount> implements PartyAccountApi {
32

33
    private final TMForumMapper tmForumMapper;
34

35

36
    public PartyAccountApiController(QueryParser queryParser, ReferenceValidationService validationService,
37
                                     TmForumRepository productPartyAccountRepository, TMForumMapper tmForumMapper, EventHandler eventHandler) {
38
        super(queryParser, validationService, productPartyAccountRepository, eventHandler);
1✔
39
        this.tmForumMapper = tmForumMapper;
1✔
40
    }
1✔
41

42
    @Override
43
    public Mono<HttpResponse<PartyAccountVO>> createPartyAccount(PartyAccountCreateVO partyAccountVo) {
44
        PartyAccount partyAccount = tmForumMapper.map(
1✔
45
                tmForumMapper.map(partyAccountVo, IdHelper.toNgsiLd(UUID.randomUUID().toString(), PartyAccount.TYPE_PARTYAC)));
1✔
46

47
        return create(getCheckingMono(partyAccount), PartyAccount.class)
1✔
48
                .map(tmForumMapper::map)
1✔
49
                .map(HttpResponse::created);
1✔
50
    }
51

52
    private Mono<PartyAccount> getCheckingMono(PartyAccount partyAccount) {
53
        List<List<? extends ReferencedEntity>> references = new ArrayList<>();
1✔
54
        references.add(partyAccount.getRelatedParty());
1✔
55
        Optional.ofNullable(partyAccount.getDefaultPaymentMethod()).map(List::of).ifPresent(references::add);
1✔
56
        Optional.ofNullable(partyAccount.getFinancialAccount()).map(List::of).ifPresent(references::add);
1✔
57
        return getCheckingMono(partyAccount, references)
1✔
58
                .onErrorMap(throwable -> new TmForumException(
1✔
59
                        String.format("Was not able to create partyAccount %s", partyAccount.getId()), throwable,
1✔
60
                        TmForumExceptionReason.INVALID_RELATIONSHIP));
61
    }
62

63
    @Override
64
    public Mono<HttpResponse<Object>> deletePartyAccount(String id) {
65
        return delete(id);
1✔
66
    }
67

68
    @Override
69
    public Mono<HttpResponse<List<PartyAccountVO>>> listPartyAccount(@Nullable String fields, @Nullable Integer offset,
70
                                                                             @Nullable Integer limit) {
71
        return list(offset, limit, PartyAccount.TYPE_PARTYAC, PartyAccount.class)
1✔
72
                .map(partyAccountStream -> partyAccountStream.map(tmForumMapper::map).toList())
1✔
73
                .switchIfEmpty(Mono.just(List.of()))
1✔
74
                .map(HttpResponse::ok);
1✔
75
    }
76

77
    @Override
78
    public Mono<HttpResponse<PartyAccountVO>> patchPartyAccount(String id, PartyAccountUpdateVO partyAccountUpdateVO) {
79
        // non-ngsi-ld ids cannot exist.
80
        if (!IdHelper.isNgsiLdId(id)) {
1✔
81
            throw new TmForumException("Did not receive a valid id, such partyAccount cannot exist.",
×
82
                    TmForumExceptionReason.NOT_FOUND);
83
        }
84
        PartyAccount updatedPartyAccount = tmForumMapper.map(tmForumMapper.map(partyAccountUpdateVO, id));
1✔
85

86
        return patch(id, updatedPartyAccount, getCheckingMono(updatedPartyAccount), PartyAccount.class)
1✔
87
                .map(tmForumMapper::map)
1✔
88
                .map(HttpResponse::ok);
1✔
89
    }
90

91
    @Override
92
    public Mono<HttpResponse<PartyAccountVO>> retrievePartyAccount(String id, @Nullable String fields) {
93
        return retrieve(id, PartyAccount.class)
1✔
94
                .switchIfEmpty(Mono.error(new TmForumException("No such partyAccount exists.",
1✔
95
                        TmForumExceptionReason.NOT_FOUND)))
96
                .map(tmForumMapper::map)
1✔
97
                .map(HttpResponse::ok);
1✔
98
    }
99
}
100

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

© 2025 Coveralls, Inc