diff --git a/iris-client-bff/src/main/java/iris/client_bff/events/EventDataRequestService.java b/iris-client-bff/src/main/java/iris/client_bff/events/EventDataRequestService.java index dff61c093..5b21a79e3 100644 --- a/iris-client-bff/src/main/java/iris/client_bff/events/EventDataRequestService.java +++ b/iris-client-bff/src/main/java/iris/client_bff/events/EventDataRequestService.java @@ -14,10 +14,9 @@ *******************************************************************************/ package iris.client_bff.events; -import static iris.client_bff.search_client.eps.LocationMapper.*; +import static iris.client_bff.search_client.eps.LocationMapper.map; import static org.apache.commons.lang3.StringUtils.isNotEmpty; -import io.vavr.control.Option; import iris.client_bff.events.EventDataRequest.DataRequestIdentifier; import iris.client_bff.events.EventDataRequest.Status; import iris.client_bff.events.eps.DataProviderClient; @@ -28,7 +27,6 @@ import iris.client_bff.proxy.IRISAnnouncementException; import iris.client_bff.proxy.ProxyServiceClient; import iris.client_bff.search_client.SearchClient; -import iris.client_bff.search_client.eps.LocationMapper; import iris.client_bff.search_client.exceptions.IRISSearchException; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -37,7 +35,6 @@ import java.util.Optional; import java.util.UUID; -import org.apache.commons.lang3.StringUtils; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; @@ -148,6 +145,14 @@ public EventDataRequest update(EventDataRequest dataRequest, EventUpdateDTO patc if (patch.getStatus() != null) { var status = Status.valueOf(patch.getStatus().name()); dataRequest.setStatus(status); + + try { + proxyClient.abortAnnouncement(dataRequest.getAnnouncementToken()); + epsDataRequestClient.abortGuestListDataRequest(dataRequest); + } catch (IRISAnnouncementException | IRISDataRequestException e) { + e.printStackTrace(); + // TODO: Should we do something here? + } } return repository.save(dataRequest); diff --git a/iris-client-bff/src/main/java/iris/client_bff/events/eps/DataProviderClient.java b/iris-client-bff/src/main/java/iris/client_bff/events/eps/DataProviderClient.java index e43076269..bb99d8f64 100644 --- a/iris-client-bff/src/main/java/iris/client_bff/events/eps/DataProviderClient.java +++ b/iris-client-bff/src/main/java/iris/client_bff/events/eps/DataProviderClient.java @@ -4,5 +4,7 @@ import iris.client_bff.events.exceptions.IRISDataRequestException; public interface DataProviderClient { - void requestGuestListData(EventDataRequest request) throws IRISDataRequestException; + void requestGuestListData(EventDataRequest request) throws IRISDataRequestException; + + void abortGuestListDataRequest(EventDataRequest request) throws IRISDataRequestException; } diff --git a/iris-client-bff/src/main/java/iris/client_bff/events/eps/DataSubmissionRPCImpl.java b/iris-client-bff/src/main/java/iris/client_bff/events/eps/DataSubmissionRPCImpl.java index bf3d76dd7..44cdac703 100644 --- a/iris-client-bff/src/main/java/iris/client_bff/events/eps/DataSubmissionRPCImpl.java +++ b/iris-client-bff/src/main/java/iris/client_bff/events/eps/DataSubmissionRPCImpl.java @@ -1,44 +1,53 @@ package iris.client_bff.events.eps; -import com.googlecode.jsonrpc4j.spring.AutoJsonRpcServiceImpl; +import iris.client_bff.events.EventDataRequest; import iris.client_bff.events.EventDataRequestService; import iris.client_bff.events.EventDataSubmissionService; import iris.client_bff.events.web.dto.GuestList; -import java.util.UUID; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; + +import java.util.UUID; + import org.springframework.stereotype.Service; +import com.googlecode.jsonrpc4j.spring.AutoJsonRpcServiceImpl; + @Slf4j @Service @AutoJsonRpcServiceImpl @RequiredArgsConstructor public class DataSubmissionRPCImpl implements DataSubmissionRPC { - private final EventDataRequestService requestService; - private final EventDataSubmissionService dataSubmissionService; + private final EventDataRequestService requestService; + private final EventDataSubmissionService dataSubmissionService; + + public String submitGuestList(JsonRpcClientDto client, UUID dataAuthorizationToken, GuestList guestList) { + log.trace("Start submission {}", dataAuthorizationToken); - public String submitGuestList(JsonRpcClientDto client, UUID dataAuthorizationToken, GuestList guestList) { - log.trace("Start submission {}", dataAuthorizationToken); + // Todo check client.getName() vs. providerId - // Todo check client.getName() vs. providerId + return requestService.findById(dataAuthorizationToken).map(dataRequest -> { - return requestService.findById(dataAuthorizationToken).map(dataRequest -> { + if (dataRequest.getStatus().equals(EventDataRequest.Status.ABORTED)) { + log.trace("Submission {} for aborted event {}", dataAuthorizationToken, dataRequest.getId()); + return "Error: Submission not allowed for " + dataAuthorizationToken.toString() + ". Request was aborted."; + } - dataSubmissionService.save(dataRequest, guestList); + dataSubmissionService.save(dataRequest, guestList); - log.trace("Done submission {}", dataAuthorizationToken); + log.trace("Done submission {}", dataAuthorizationToken); - return "OK"; + return "OK"; - }).orElseGet(() -> { + }).orElseGet(() -> { - // TODO sufficient? - // probably throw exception + // TODO sufficient? + // probably throw exception - log.error("Data submission for unknown data request occurred: {}", dataAuthorizationToken); + log.error("Data submission for unknown data request occurred: {}", dataAuthorizationToken); - return "Unknown dataAuthorizationToken: " + dataAuthorizationToken.toString(); - }); - } + return "Unknown dataAuthorizationToken: " + dataAuthorizationToken.toString(); + }); + } } diff --git a/iris-client-bff/src/main/java/iris/client_bff/events/eps/EPSDataProviderClient.java b/iris-client-bff/src/main/java/iris/client_bff/events/eps/EPSDataProviderClient.java index 04a230318..8cd8492ee 100644 --- a/iris-client-bff/src/main/java/iris/client_bff/events/eps/EPSDataProviderClient.java +++ b/iris-client-bff/src/main/java/iris/client_bff/events/eps/EPSDataProviderClient.java @@ -1,18 +1,20 @@ package iris.client_bff.events.eps; -import com.fasterxml.jackson.annotation.JsonFormat; -import com.googlecode.jsonrpc4j.JsonRpcHttpClient; import iris.client_bff.events.EventDataRequest; import iris.client_bff.events.exceptions.IRISDataRequestException; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; import java.time.Instant; import java.util.Map; +import org.springframework.stereotype.Service; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.googlecode.jsonrpc4j.JsonRpcHttpClient; + @Slf4j @Service @AllArgsConstructor @@ -47,6 +49,32 @@ public void requestGuestListData(EventDataRequest request) throws IRISDataReques } } + @Override + public void abortGuestListDataRequest(EventDataRequest request) throws IRISDataRequestException { + var requestId = request.getId().toString(); + var methodName = request.getLocation().getProviderId() + ".abortDataRequest"; + + var payload = Map.of( + "dataRequest", SubmitPayload.builder() + .start(request.getRequestStart()) + .end(request.getRequestEnd()) + .dataAuthorizationToken(requestId) + .proxyEndpoint(request.getAnnouncementToken()) + .locationId(request.getLocation().getLocationId()) + .requestDetails(request.getRequestDetails()) + .build()); + + try { + log.trace("abortGuestListDataRequest start: method {}; request {}", methodName, requestId); + epsRpcClient.invoke(methodName, payload); + log.debug("abortGuestListDataRequest done: method {}; request {};", methodName, requestId); + + } catch (Throwable t) { + log.error("abortGuestListDataRequest error: method {}; request {}; error {}", methodName, requestId, t); + throw new IRISDataRequestException(t); + } + } + @Data @Builder public static class SubmitPayload { diff --git a/iris-client-bff/src/main/java/iris/client_bff/proxy/EPSProxyServiceServiceClient.java b/iris-client-bff/src/main/java/iris/client_bff/proxy/EPSProxyServiceServiceClient.java index ce56ed6dd..356f17ff8 100644 --- a/iris-client-bff/src/main/java/iris/client_bff/proxy/EPSProxyServiceServiceClient.java +++ b/iris-client-bff/src/main/java/iris/client_bff/proxy/EPSProxyServiceServiceClient.java @@ -1,6 +1,5 @@ package iris.client_bff.proxy; -import com.fasterxml.jackson.annotation.JsonFormat; import iris.client_bff.config.ProxyServiceConfig; import lombok.AllArgsConstructor; import lombok.Builder; @@ -14,6 +13,7 @@ import org.springframework.stereotype.Service; +import com.fasterxml.jackson.annotation.JsonFormat; import com.googlecode.jsonrpc4j.JsonRpcHttpClient; @Slf4j @@ -21,47 +21,59 @@ @AllArgsConstructor public class EPSProxyServiceServiceClient implements ProxyServiceClient { - private final ProxyServiceConfig config; - - private final JsonRpcHttpClient proxyRpcClient; + private final ProxyServiceConfig config; - @Override - public String announce() throws IRISAnnouncementException { + private final JsonRpcHttpClient proxyRpcClient; - var domain = UUID.randomUUID() - + "." - + config.getTargetSubdomain(); + private String sendAnnouncement(String domain, Instant expirationTime) throws IRISAnnouncementException { + var announcementDto = AnnouncementDto.builder() + .domain(domain) + .expiresAt(expirationTime) + .proxy(config.getTargetProxy()) + .build(); - var oneWeekFromNow = Instant.now().plus(7, ChronoUnit.DAYS); + var methodName = config.getEpsName() + + "." + + "announceConnection"; - var announcementDto = AnnouncementDto.builder() - .domain(domain) - .expiresAt(oneWeekFromNow) - .proxy(config.getTargetProxy()) - .build(); + try { + proxyRpcClient.invoke(methodName, announcementDto); + if (expirationTime.isBefore(Instant.now())) { + log.debug("Aborted announcement {} to {}", announcementDto.getDomain(), announcementDto.getProxy()); + } else { + log.debug("Announced {} to {} till {}", announcementDto.getDomain(), announcementDto.getProxy(), + announcementDto.getExpiresAt()); + } + } catch (Throwable throwable) { + throw new IRISAnnouncementException(throwable); + } - var methodName = config.getEpsName() - + "." - + "announceConnection"; + return domain; + } - try { - proxyRpcClient.invoke(methodName, announcementDto); - log.debug("Announced {} to {} till {}", announcementDto.getDomain(), announcementDto.getProxy(), announcementDto.getExpiresAt()); - } catch (Throwable throwable) { - throw new IRISAnnouncementException(throwable); - } + @Override + public String announce() throws IRISAnnouncementException { + var domain = UUID.randomUUID() + + "." + + config.getTargetSubdomain(); + var oneWeekFromNow = Instant.now().plus(7, ChronoUnit.DAYS); + return this.sendAnnouncement(domain, oneWeekFromNow); + } - return domain; - } + @Override + public String abortAnnouncement(String domain) throws IRISAnnouncementException { + var oneWeekAgo = Instant.now().minus(7, ChronoUnit.DAYS); + return this.sendAnnouncement(domain, oneWeekAgo); + } - @Data - @Builder - @NoArgsConstructor - @AllArgsConstructor - public static class AnnouncementDto { - private String domain; - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX", timezone = "UTC") - private Instant expiresAt; - private String proxy; - } + @Data + @Builder + @NoArgsConstructor + @AllArgsConstructor + public static class AnnouncementDto { + private String domain; + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX", timezone = "UTC") + private Instant expiresAt; + private String proxy; + } } diff --git a/iris-client-bff/src/main/java/iris/client_bff/proxy/ProxyServiceClient.java b/iris-client-bff/src/main/java/iris/client_bff/proxy/ProxyServiceClient.java index ef5e1ef66..2bf5ec128 100644 --- a/iris-client-bff/src/main/java/iris/client_bff/proxy/ProxyServiceClient.java +++ b/iris-client-bff/src/main/java/iris/client_bff/proxy/ProxyServiceClient.java @@ -1,7 +1,7 @@ package iris.client_bff.proxy; -import java.util.UUID; - public interface ProxyServiceClient { - String announce() throws IRISAnnouncementException; + String announce() throws IRISAnnouncementException; + + String abortAnnouncement(String domain) throws IRISAnnouncementException; }