-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Glaucio Jannotti
committed
Jun 28, 2024
1 parent
7f86700
commit 3df5a4b
Showing
10 changed files
with
419 additions
and
181 deletions.
There are no files selected for viewing
168 changes: 0 additions & 168 deletions
168
...t/src/main/java/com/truzzt/extension/logginghouse/client/IdsClearingHouseServiceImpl.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
...t/src/main/java/com/truzzt/extension/logginghouse/client/LoggingHouseEventSubscriber.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
* Copyright (c) 2022 sovity GmbH | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Contributors: | ||
* sovity GmbH - initial API and implementation | ||
* | ||
*/ | ||
|
||
package com.truzzt.extension.logginghouse.client; | ||
|
||
import com.truzzt.extension.logginghouse.client.spi.store.LoggingHouseMessageStore; | ||
import com.truzzt.extension.logginghouse.client.spi.types.LoggingHouseMessage; | ||
import org.eclipse.edc.connector.contract.spi.event.contractnegotiation.ContractNegotiationFinalized; | ||
import org.eclipse.edc.connector.contract.spi.negotiation.store.ContractNegotiationStore; | ||
import org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement; | ||
import org.eclipse.edc.connector.transfer.spi.event.TransferProcessEvent; | ||
import org.eclipse.edc.connector.transfer.spi.store.TransferProcessStore; | ||
import org.eclipse.edc.connector.transfer.spi.types.TransferProcess; | ||
import org.eclipse.edc.spi.event.Event; | ||
import org.eclipse.edc.spi.event.EventEnvelope; | ||
import org.eclipse.edc.spi.event.EventSubscriber; | ||
import org.eclipse.edc.spi.monitor.Monitor; | ||
|
||
import java.time.ZonedDateTime; | ||
import java.util.Objects; | ||
|
||
public class LoggingHouseEventSubscriber implements EventSubscriber { | ||
|
||
private final LoggingHouseMessageStore loggingHouseMessageStore; | ||
private final ContractNegotiationStore contractNegotiationStore; | ||
private final TransferProcessStore transferProcessStore; | ||
private final Monitor monitor; | ||
|
||
public LoggingHouseEventSubscriber( | ||
LoggingHouseMessageStore loggingHouseMessageStore, | ||
ContractNegotiationStore contractNegotiationStore, | ||
TransferProcessStore transferProcessStore, | ||
Monitor monitor) { | ||
this.loggingHouseMessageStore = loggingHouseMessageStore; | ||
this.contractNegotiationStore = contractNegotiationStore; | ||
this.transferProcessStore = transferProcessStore; | ||
this.monitor = monitor; | ||
} | ||
|
||
public void storeContractAgreement(ContractAgreement contractAgreement) { | ||
monitor.info("Storing ContractAgreement to send to LoggingHouse"); | ||
|
||
var message = LoggingHouseMessage.Builder.newInstance() | ||
.eventToLog(contractAgreement) | ||
.createdAt(ZonedDateTime.now()) | ||
.build(); | ||
loggingHouseMessageStore.save(message); | ||
} | ||
|
||
public void storeTransferProcess(TransferProcess transferProcess) { | ||
monitor.info("Storing TransferProcess to send to LoggingHouse"); | ||
|
||
var message = LoggingHouseMessage.Builder.newInstance() | ||
.eventToLog(transferProcess) | ||
.createdAt(ZonedDateTime.now()) | ||
.build(); | ||
loggingHouseMessageStore.save(message); | ||
} | ||
|
||
@Override | ||
public <E extends Event> void on(EventEnvelope<E> event) { | ||
if (event.getPayload() instanceof ContractNegotiationFinalized contractNegotiationFinalized) { | ||
monitor.debug("Storing ContractNegotiationFinalized event with id " + event.getId()); | ||
|
||
var contractAgreement = resolveContractAgreement(contractNegotiationFinalized); | ||
try { | ||
storeContractAgreement(contractAgreement); | ||
} catch (Exception e) { | ||
monitor.warning("Could not store ContractNegotiation: " + e.getMessage()); | ||
} | ||
} else if (event.getPayload() instanceof TransferProcessEvent transferProcessEvent) { | ||
monitor.debug("Storing TransferProcess event with id " + event.getId()); | ||
|
||
var transferProcess = resolveTransferProcess(transferProcessEvent); | ||
try { | ||
storeTransferProcess(transferProcess); | ||
} catch (Exception e) { | ||
monitor.warning("Could not store TransferProcess: " + e.getMessage()); | ||
} | ||
} | ||
} | ||
|
||
private ContractAgreement resolveContractAgreement(ContractNegotiationFinalized contractNegotiationFinalized) throws NullPointerException { | ||
var contractNegotiationId = contractNegotiationFinalized.getContractNegotiationId(); | ||
var contractNegotiation = contractNegotiationStore.findById(contractNegotiationId); | ||
return Objects.requireNonNull(contractNegotiation).getContractAgreement(); | ||
} | ||
|
||
private TransferProcess resolveTransferProcess(TransferProcessEvent transferProcessEvent) { | ||
var transferProcessId = transferProcessEvent.getTransferProcessId(); | ||
return transferProcessStore.findById(transferProcessId); | ||
} | ||
} |
Oops, something went wrong.