Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public class EventConstants {
public static final String EVENT_GROUP_USAGE = "Usage";
public static final String EVENT_GROUP_USAGE_SPECIFICATION = "UsageSpecification";
public static final String EVENT_GROUP_PARTY_ROLE = "PartyRole";
public static final String EVENT_GROUP_CUSTOMER_BILL = "CustomerBill";
public static final String EVENT_GROUP_CUSTOMER_BILL_ON_DEMAND = "CustomerBillOnDemand";

public static final String CREATE_EVENT_SUFFIX = "CreateEvent";
public static final String ATTRIBUTE_VALUE_CHANGE_EVENT_SUFFIX = "AttributeValueChangeEvent";
Expand Down Expand Up @@ -136,6 +138,10 @@ public class EventConstants {
entry(EVENT_GROUP_SERVICE, List.of(CREATE_EVENT_SUFFIX, CHANGE_EVENT_SUFFIX,
DELETE_EVENT_SUFFIX)),
entry(EVENT_GROUP_QUOTE, List.of(CREATE_EVENT_SUFFIX, STATE_CHANGE_EVENT_SUFFIX,
DELETE_EVENT_SUFFIX, ATTRIBUTE_VALUE_CHANGE_EVENT_SUFFIX, INFORMATION_REQUIRED_EVENT_SUFFIX))
DELETE_EVENT_SUFFIX, ATTRIBUTE_VALUE_CHANGE_EVENT_SUFFIX, INFORMATION_REQUIRED_EVENT_SUFFIX)),
entry(EVENT_GROUP_CUSTOMER_BILL, List.of(CREATE_EVENT_SUFFIX, ATTRIBUTE_VALUE_CHANGE_EVENT_SUFFIX,
STATE_CHANGE_EVENT_SUFFIX, DELETE_EVENT_SUFFIX)),
entry(EVENT_GROUP_CUSTOMER_BILL_ON_DEMAND, List.of(CREATE_EVENT_SUFFIX, ATTRIBUTE_VALUE_CHANGE_EVENT_SUFFIX,
STATE_CHANGE_EVENT_SUFFIX, DELETE_EVENT_SUFFIX))
);
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
package org.fiware.tmforum.customerbillmanagement;

import lombok.RequiredArgsConstructor;
import org.fiware.customerbillmanagement.model.CustomerBillVO;
import org.fiware.customerbillmanagement.model.CustomerBillOnDemandVO;
import org.fiware.tmforum.common.exception.TmForumException;
import org.fiware.tmforum.common.exception.TmForumExceptionReason;
import org.fiware.tmforum.common.mapping.EventMapping;
import org.fiware.tmforum.common.notification.EventMapper;
import org.fiware.tmforum.customerbillmanagement.domain.CustomerBill;
import org.fiware.tmforum.customerbillmanagement.domain.CustomerBillOnDemand;

import javax.inject.Singleton;
import java.util.Map;

import static java.util.Map.entry;

@RequiredArgsConstructor
@Singleton
public class CustomerBillManagementEventMapper implements EventMapper {
Expand All @@ -17,12 +23,20 @@ public class CustomerBillManagementEventMapper implements EventMapper {

@Override
public Map<String, EventMapping> getEntityClassMapping() {
return Map.ofEntries();
return Map.ofEntries(
entry(CustomerBill.TYPE_CUSTOMER_BILL, new EventMapping(CustomerBillVO.class, CustomerBill.class)),
entry(CustomerBillOnDemand.TYPE_CUSTOMER_BILL_ON_DEMAND, new EventMapping(CustomerBillOnDemandVO.class, CustomerBillOnDemand.class))
);
}

@Override
public Object mapPayload(Object rawPayload, Class<?> targetClass) {

public Object mapPayload(Object rawPayload, Class<?> rawClass) {
if (rawClass == CustomerBill.class) {
return tmForumMapper.map((CustomerBill) rawPayload);
}
if (rawClass == CustomerBillOnDemand.class) {
return tmForumMapper.map((CustomerBillOnDemand) rawPayload);
}
throw new TmForumException(String.format("Event-Payload %s is not supported.", rawPayload), TmForumExceptionReason.INVALID_DATA);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.fiware.customerbillmanagement.model.*;
import org.fiware.tmforum.common.domain.Money;
import org.fiware.tmforum.common.domain.subscription.TMForumSubscription;
import org.fiware.tmforum.common.mapping.BaseMapper;
import org.fiware.tmforum.common.mapping.IdHelper;
import org.fiware.tmforum.customerbillmanagement.domain.AppliedBillingRateCharacteristic;
Expand Down Expand Up @@ -73,6 +74,10 @@ public abstract class TMForumMapper extends BaseMapper {
@Mapping(target = "value", source = "tmfValue")
public abstract MoneyVO map(Money money);

// event subscription
@Mapping(target = "query", source = "rawQuery")
public abstract EventSubscriptionVO map(TMForumSubscription subscription);

public URL map(String value) {
if (value == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package org.fiware.tmforum.customerbillmanagement.rest;

import io.github.wistefan.mapping.EntityVOMapper;
import io.micronaut.core.annotation.NonNull;
import io.micronaut.http.HttpResponse;
import io.micronaut.http.annotation.Controller;
import lombok.extern.slf4j.Slf4j;
import org.fiware.customerbillmanagement.api.EventsSubscriptionApi;
import org.fiware.customerbillmanagement.model.EventSubscriptionInputVO;
import org.fiware.customerbillmanagement.model.EventSubscriptionVO;
import org.fiware.tmforum.common.configuration.GeneralProperties;
import org.fiware.tmforum.common.domain.subscription.TMForumSubscription;
import org.fiware.tmforum.common.mapping.SubscriptionMapper;
import org.fiware.tmforum.common.notification.NgsiLdEventHandler;
import org.fiware.tmforum.common.notification.TMForumEventHandler;
import org.fiware.tmforum.common.querying.QueryParser;
import org.fiware.tmforum.common.repository.TmForumRepository;
import org.fiware.tmforum.common.rest.AbstractSubscriptionApiController;
import org.fiware.tmforum.common.validation.ReferenceValidationService;
import org.fiware.tmforum.customerbillmanagement.TMForumMapper;
import org.fiware.tmforum.customerbillmanagement.domain.CustomerBill;
import org.fiware.tmforum.customerbillmanagement.domain.CustomerBillOnDemand;
import reactor.core.publisher.Mono;

import java.util.List;
import java.util.Map;

import static java.util.Map.entry;
import static org.fiware.tmforum.common.notification.EventConstants.EVENT_GROUP_CUSTOMER_BILL;
import static org.fiware.tmforum.common.notification.EventConstants.EVENT_GROUP_CUSTOMER_BILL_ON_DEMAND;

@Slf4j
@Controller("${general.basepath:/}")
public class EventSubscriptionApiController extends AbstractSubscriptionApiController implements EventsSubscriptionApi {
private final TMForumMapper tmForumMapper;
private static final Map<String, String> EVENT_GROUP_TO_ENTITY_NAME_MAPPING = Map.ofEntries(
entry(EVENT_GROUP_CUSTOMER_BILL, CustomerBill.TYPE_CUSTOMER_BILL),
entry(EVENT_GROUP_CUSTOMER_BILL_ON_DEMAND, CustomerBillOnDemand.TYPE_CUSTOMER_BILL_ON_DEMAND)
);
private static final List<String> EVENT_GROUPS = List.of(EVENT_GROUP_CUSTOMER_BILL, EVENT_GROUP_CUSTOMER_BILL_ON_DEMAND);

public EventSubscriptionApiController(QueryParser queryParser, ReferenceValidationService validationService,
TmForumRepository repository, TMForumMapper tmForumMapper,
TMForumEventHandler tmForumEventHandler, NgsiLdEventHandler ngsiLdEventHandler,
GeneralProperties generalProperties,
EntityVOMapper entityVOMapper,
SubscriptionMapper subscriptionMapper) {
super(queryParser, validationService, repository, EVENT_GROUP_TO_ENTITY_NAME_MAPPING, tmForumEventHandler, ngsiLdEventHandler,
generalProperties, entityVOMapper, subscriptionMapper);
this.tmForumMapper = tmForumMapper;
}

@Override
public Mono<HttpResponse<EventSubscriptionVO>> registerListener(
@NonNull EventSubscriptionInputVO eventSubscriptionInputVO) {
TMForumSubscription subscription = buildSubscription(eventSubscriptionInputVO.getCallback(),
eventSubscriptionInputVO.getQuery(), EVENT_GROUPS);

return create(subscription)
.map(tmForumMapper::map)
.map(HttpResponse::created);
}

@Override
public Mono<HttpResponse<Object>> unregisterListener(@NonNull String id) {
return delete(id);
}

}
Loading