• 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

92.86
/account/src/main/java/org/fiware/tmforum/account/rest/BillFormatApiController.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.BillFormatApi;
7
import org.fiware.account.api.BillFormatApi;
8
import org.fiware.account.model.BillFormatCreateVO;
9
import org.fiware.account.model.BillFormatUpdateVO;
10
import org.fiware.account.model.BillFormatVO;
11
import org.fiware.tmforum.common.notification.EventHandler;
12
import org.fiware.tmforum.common.exception.TmForumException;
13
import org.fiware.tmforum.common.exception.TmForumExceptionReason;
14
import org.fiware.tmforum.common.mapping.IdHelper;
15
import org.fiware.tmforum.common.querying.QueryParser;
16
import org.fiware.tmforum.common.repository.TmForumRepository;
17
import org.fiware.tmforum.common.rest.AbstractApiController;
18
import org.fiware.tmforum.common.validation.ReferenceValidationService;
19
import org.fiware.tmforum.common.validation.ReferencedEntity;
20
import org.fiware.tmforum.account.TMForumMapper;
21
import org.fiware.tmforum.account.domain.BillFormat;
22
import reactor.core.publisher.Mono;
23

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

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

33
    private final TMForumMapper tmForumMapper;
34

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

41
    @Override
42
    public Mono<HttpResponse<BillFormatVO>> createBillFormat(BillFormatCreateVO billFormatVo) {
43
        BillFormat billFormat = tmForumMapper.map(
1✔
44
                tmForumMapper.map(billFormatVo, IdHelper.toNgsiLd(UUID.randomUUID().toString(), BillFormat.TYPE_BILLF)));
1✔
45

46
        return create(getCheckingMono(billFormat), BillFormat.class)
1✔
47
                .map(tmForumMapper::map)
1✔
48
                .map(HttpResponse::created);
1✔
49
    }
50

51
    private Mono<BillFormat> getCheckingMono(BillFormat billFormat) {
52
        List<List<? extends ReferencedEntity>> references = new ArrayList<>();
1✔
53
        return getCheckingMono(billFormat, references)
1✔
54
                .onErrorMap(throwable -> new TmForumException(
1✔
55
                        String.format("Was not able to create billFormat %s", billFormat.getId()), throwable,
×
56
                        TmForumExceptionReason.INVALID_RELATIONSHIP));
57
    }
58

59
    @Override
60
    public Mono<HttpResponse<Object>> deleteBillFormat(String id) {
61
        return delete(id);
1✔
62
    }
63

64
    @Override
65
    public Mono<HttpResponse<List<BillFormatVO>>> listBillFormat(@Nullable String fields, @Nullable Integer offset,
66
                                                           @Nullable Integer limit) {
67
        return list(offset, limit, BillFormat.TYPE_BILLF, BillFormat.class)
1✔
68
                .map(categoryStream -> categoryStream.map(tmForumMapper::map).toList())
1✔
69
                .switchIfEmpty(Mono.just(List.of()))
1✔
70
                .map(HttpResponse::ok);
1✔
71
    }
72

73
    @Override
74
    public Mono<HttpResponse<BillFormatVO>> patchBillFormat(String id, BillFormatUpdateVO billFormatUpdateVO) {
75
        // non-ngsi-ld ids cannot exist.
76
        if (!IdHelper.isNgsiLdId(id)) {
1✔
77
            throw new TmForumException("Did not receive a valid id, such billFormat cannot exist.",
×
78
                    TmForumExceptionReason.NOT_FOUND);
79
        }
80
        BillFormat updatedBillFormat = tmForumMapper.map(tmForumMapper.map(billFormatUpdateVO, id));
1✔
81

82
        return patch(id, updatedBillFormat, getCheckingMono(updatedBillFormat), BillFormat.class)
1✔
83
                .map(tmForumMapper::map)
1✔
84
                .map(HttpResponse::ok);
1✔
85
    }
86

87
    @Override
88
    public Mono<HttpResponse<BillFormatVO>> retrieveBillFormat(String id, @Nullable String fields) {
89
        return retrieve(id, BillFormat.class)
1✔
90
                .switchIfEmpty(Mono.error(new TmForumException("No such billFormat exists.",
1✔
91
                        TmForumExceptionReason.NOT_FOUND)))
92
                .map(tmForumMapper::map)
1✔
93
                .map(HttpResponse::ok);
1✔
94
    }
95
}
96

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