-
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
1 parent
f4125e7
commit 9947cdb
Showing
25 changed files
with
623 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
edc-chat-app-backend/src/main/java/com/smartsense/chat/EdcChatApplication.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,18 @@ | ||
package com.smartsense.chat; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.context.properties.ConfigurationPropertiesScan; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.cloud.openfeign.EnableFeignClients; | ||
|
||
@SpringBootApplication | ||
@ConfigurationPropertiesScan | ||
@EnableFeignClients | ||
public class EdcChatApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(EdcChatApplication.class, args); | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
edc-chat-app-backend/src/main/java/com/smartsense/chat/ServletInitializer.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,13 @@ | ||
package com.smartsense.chat; | ||
|
||
import org.springframework.boot.builder.SpringApplicationBuilder; | ||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; | ||
|
||
public class ServletInitializer extends SpringBootServletInitializer { | ||
|
||
@Override | ||
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { | ||
return application.sources(EdcChatApplication.class); | ||
} | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
edc-chat-app-backend/src/main/java/com/smartsense/chat/dao/entity/BusinessPartner.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,51 @@ | ||
package com.smartsense.chat.dao.entity; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import jakarta.persistence.*; | ||
import lombok.*; | ||
|
||
import java.util.Date; | ||
import java.util.UUID; | ||
|
||
@Getter | ||
@Setter | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Entity | ||
@Table(name = "raw_data_master") | ||
public class BusinessPartner { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.UUID) | ||
@Column(name = "id", nullable = false, updatable = false, insertable = false) | ||
private final UUID id = UUID.randomUUID(); | ||
|
||
@Column(name = "name") | ||
private String name; | ||
|
||
@Column(name = "bpn") | ||
private String bpn; | ||
|
||
@Column(name = "edc_url") | ||
private String edcUrl; | ||
|
||
@Temporal(TemporalType.TIMESTAMP) | ||
@Column(name = "created_at", updatable = false, nullable = false) | ||
private Date createdAt; | ||
|
||
@Temporal(TemporalType.TIMESTAMP) | ||
@Column(name = "updated_at") | ||
@JsonIgnore | ||
private Date updatedAt; | ||
|
||
@PrePersist | ||
void createdAt() { | ||
this.createdAt = new Date(); | ||
} | ||
|
||
@PreUpdate | ||
void updatedAt() { | ||
this.updatedAt = new Date(); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...p-backend/src/main/java/com/smartsense/chat/dao/repository/BusinessPartnerRepository.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,11 @@ | ||
package com.smartsense.chat.dao.repository; | ||
|
||
import com.smartsense.chat.dao.entity.BusinessPartner; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.UUID; | ||
|
||
@Repository | ||
public interface BusinessPartnerRepository extends JpaRepository<BusinessPartner, UUID> { | ||
} |
37 changes: 37 additions & 0 deletions
37
edc-chat-app-backend/src/main/java/com/smartsense/chat/edc/EDCService.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,37 @@ | ||
package com.smartsense.chat.edc; | ||
|
||
import com.smartsense.chat.edc.operation.PublicUrlHandlerService; | ||
import com.smartsense.chat.edc.operation.TransferProcessService; | ||
import com.smartsense.chat.utils.request.ChatMessage; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.net.URI; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class EDCService { | ||
|
||
|
||
private final TransferProcessService transferProcessService; | ||
private final PublicUrlHandlerService publicUrlHandlerService; | ||
|
||
public void initProcess(URI edcUri, ChatMessage chatMessage) { | ||
// TODO query catalog | ||
//TODO start negotiation | ||
//TODO get agreement | ||
|
||
|
||
String agreementId = null; | ||
|
||
// Initiate the transfer process | ||
String transferProcessId = transferProcessService.initiateTransfer(edcUri, agreementId); | ||
|
||
// sent the message to public url | ||
publicUrlHandlerService.getAuthCodeAndPublicUrl(edcUri, transferProcessId, chatMessage); | ||
} | ||
|
||
|
||
} |
44 changes: 44 additions & 0 deletions
44
edc-chat-app-backend/src/main/java/com/smartsense/chat/edc/client/EDCConnectorClient.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,44 @@ | ||
package com.smartsense.chat.edc.client; | ||
|
||
import org.springframework.cloud.openfeign.FeignClient; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.net.URI; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; | ||
|
||
@FeignClient(name = "edc", url = "http://localhost:8182") | ||
public interface EDCConnectorClient { | ||
|
||
@PostMapping(value = "/management/v2/catalog/request", consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE) | ||
Map<String, Object> queryCatalog(URI baseUri, | ||
@RequestBody Map<String, Object> request, | ||
@RequestHeader("X-Api-Key") String auth); | ||
|
||
@PostMapping(value = "/management/v2/edrs", consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE) | ||
Map<String, Object> initNegotiation(URI baseUri, | ||
@RequestBody Map<String, Object> request, | ||
@RequestHeader("X-Api-Key") String auth); | ||
|
||
@GetMapping(value = "/management/v2/contractnegotiations/{negotiationId}", produces = APPLICATION_JSON_VALUE) | ||
Map<String, Object> getAgreement(URI baseUri, | ||
@PathVariable("negotiationId") String negotiationId, | ||
@RequestHeader("X-Api-Key") String auth); | ||
|
||
|
||
@PostMapping(value = "/management/v2/edrs/request", consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE) | ||
List<Map<String, Object>> initTransferProcess(URI baseUri, | ||
@RequestBody Map<String, Object> request, | ||
@RequestHeader("X-Api-Key") String auth); | ||
|
||
@GetMapping(value = "management/v2/edrs/{transferProcessId}/dataaddress", produces = APPLICATION_JSON_VALUE) | ||
Map<String, Object> getAuthCodeAndPublicUrl(URI baseUri, | ||
@PathVariable("transferProcessId") String transferProcessId, | ||
@RequestHeader("X-Api-Key") String auth); | ||
|
||
@PostMapping(consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE) | ||
Map<String, Object> sendMessage(URI baseUri, @RequestBody String message, @RequestHeader("Authorization") String authorization); | ||
|
||
} |
4 changes: 4 additions & 0 deletions
4
...-app-backend/src/main/java/com/smartsense/chat/edc/operation/AgreementFetcherService.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,4 @@ | ||
package com.smartsense.chat.edc.operation; | ||
|
||
public class AgreementFetcherService { | ||
} |
4 changes: 4 additions & 0 deletions
4
...p-backend/src/main/java/com/smartsense/chat/edc/operation/ContractNegotiationService.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,4 @@ | ||
package com.smartsense.chat.edc.operation; | ||
|
||
public class ContractNegotiationService { | ||
} |
50 changes: 50 additions & 0 deletions
50
...-app-backend/src/main/java/com/smartsense/chat/edc/operation/PublicUrlHandlerService.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,50 @@ | ||
package com.smartsense.chat.edc.operation; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.smartsense.chat.edc.client.EDCConnectorClient; | ||
import com.smartsense.chat.utils.request.ChatMessage; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.net.URI; | ||
import java.util.Map; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class PublicUrlHandlerService { | ||
private final EDCConnectorClient edc; | ||
private final ObjectMapper mapper; | ||
@Value("${edc.auth.code:password}") | ||
private String authCode; | ||
|
||
public void getAuthCodeAndPublicUrl(URI edcUri, String transferProcessId, ChatMessage message) { | ||
try { | ||
log.info("Initiate to get auth code based on transfer process id " + transferProcessId); | ||
Map<String, Object> response = edc.getAuthCodeAndPublicUrl(edcUri, transferProcessId, authCode); | ||
log.info("Auth code and public url response -> {}", response); | ||
|
||
// Retrieve public path and authorization code | ||
String publicPath = response.get("tx-auth:refreshEndpoint").toString(); | ||
String authorization = response.get("authorization").toString(); | ||
|
||
// Call the public path with authorization code | ||
callPublicUri(publicPath, mapper.writeValueAsString(message), authorization); | ||
|
||
log.info("Initiate to get auth code based on transfer process id {} is done.", transferProcessId); | ||
} catch (Exception ex) { | ||
log.error("Error occurred in get auth code based on transfer process id {} ", transferProcessId, ex); | ||
} | ||
} | ||
|
||
private void callPublicUri(String publicPath, String message, String authorization) { | ||
try { | ||
Map<String, Object> publicUriResponse = edc.sendMessage(URI.create(publicPath), message, authorization); | ||
log.info("Received public uri response -> {}", publicUriResponse); | ||
} catch (Exception ex) { | ||
log.error("Error occurred while calling public uri {} and auth code {} ", publicPath, authorization, ex); | ||
} | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
...chat-app-backend/src/main/java/com/smartsense/chat/edc/operation/QueryCatalogService.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,4 @@ | ||
package com.smartsense.chat.edc.operation; | ||
|
||
public class QueryCatalogService { | ||
} |
57 changes: 57 additions & 0 deletions
57
...t-app-backend/src/main/java/com/smartsense/chat/edc/operation/TransferProcessService.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,57 @@ | ||
package com.smartsense.chat.edc.operation; | ||
|
||
import com.smartsense.chat.edc.client.EDCConnectorClient; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.net.URI; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class TransferProcessService { | ||
|
||
private final EDCConnectorClient edc; | ||
@Value("${edc.auth.code:password}") | ||
private String authCode; | ||
|
||
public String initiateTransfer(URI edcUri, String agreementId) { | ||
try { | ||
log.info("Initiate transfer process for agreement Id {}", agreementId); | ||
|
||
// prepare transfer request | ||
Map<String, Object> transferRequest = prepareTransferRequest(agreementId); | ||
// initiate the transfer process | ||
List<Map<String, Object>> transferResponse = edc.initTransferProcess(edcUri, transferRequest, authCode); | ||
log.info("Received transfer response -> {}", transferResponse); | ||
|
||
// get the transfer process id from response | ||
String transferProcessId = transferResponse.get(0).get("transferProcessId").toString(); | ||
log.info("Transfer process id: {}", transferProcessId); | ||
|
||
log.info("Transfer process is complete successfully for agreement Id {}", agreementId); | ||
return transferProcessId; | ||
} catch (Exception ex) { | ||
log.error("Error occurred in transfer process for agreement Id {}", agreementId, ex); | ||
return null; | ||
} | ||
} | ||
|
||
private Map<String, Object> prepareTransferRequest(String agreementId) { | ||
Map<String, Object> transferRequest = new HashMap<>(); | ||
transferRequest.put("@context", Map.of("@vocab", "https://w3id.org/edc/v0.0.1/ns/")); | ||
transferRequest.put("@type", "QuerySpec"); | ||
transferRequest.put("offset", 0); | ||
transferRequest.put("limit", 1); | ||
transferRequest.put("filterExpression", List.of(Map.of("operandLeft", "agreementId", | ||
"operator", "=", | ||
"operandRight", agreementId))); | ||
log.info("Transfer request looks like: {}", transferRequest); | ||
return transferRequest; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
edc-chat-app-backend/src/main/java/com/smartsense/chat/edc/settings/EDCConfigurations.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,8 @@ | ||
package com.smartsense.chat.edc.settings; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
@ConfigurationProperties("chat.edc") | ||
public record EDCConfigurations(String authCode, | ||
String assetId) { | ||
} |
29 changes: 29 additions & 0 deletions
29
edc-chat-app-backend/src/main/java/com/smartsense/chat/service/BusinessPartnerService.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,29 @@ | ||
package com.smartsense.chat.service; | ||
|
||
import com.smartsense.chat.dao.entity.BusinessPartner; | ||
import com.smartsense.chat.dao.repository.BusinessPartnerRepository; | ||
import com.smartsense.chat.utils.request.BusinessPartnerRequest; | ||
import com.smartsense.chat.web.BusinessPartnerResource; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class BusinessPartnerService { | ||
|
||
private final BusinessPartnerRepository businessPartnerRepository; | ||
|
||
|
||
public BusinessPartnerResource createBusinessPartner(BusinessPartnerRequest request) { | ||
log.info("Creating BusinessPartner. name: {}", request.name()); | ||
BusinessPartner businessPartner = BusinessPartner.builder() | ||
.name(request.name()) | ||
.edcUrl(request.edcUrl()) | ||
.bpn(request.bpn()) | ||
.build(); | ||
businessPartnerRepository.save(businessPartner); | ||
return null; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
edc-chat-app-backend/src/main/java/com/smartsense/chat/utils/exception/BadDataException.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,25 @@ | ||
package com.smartsense.chat.utils.exception; | ||
|
||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.io.Serial; | ||
|
||
@NoArgsConstructor | ||
@Getter | ||
public class BadDataException extends RuntimeException { | ||
@Serial | ||
private static final long serialVersionUID = 5732404099105408974L; | ||
|
||
private String code; | ||
private String message; | ||
|
||
public BadDataException(String message) { | ||
this.message = message; | ||
} | ||
|
||
public BadDataException(String message, String code) { | ||
this.message = message; | ||
this.code = code; | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...t-app-backend/src/main/java/com/smartsense/chat/utils/request/BusinessPartnerRequest.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,6 @@ | ||
package com.smartsense.chat.utils.request; | ||
|
||
public record BusinessPartnerRequest(String name, | ||
String bpn, | ||
String edcUrl) { | ||
} |
7 changes: 7 additions & 0 deletions
7
edc-chat-app-backend/src/main/java/com/smartsense/chat/utils/request/ChatMessage.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,7 @@ | ||
package com.smartsense.chat.utils.request; | ||
|
||
public record ChatMessage(String senderBpn, | ||
String receiverBpn, | ||
String message, | ||
String messageId) { | ||
} |
9 changes: 9 additions & 0 deletions
9
...app-backend/src/main/java/com/smartsense/chat/utils/response/BusinessPartnerResponse.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,9 @@ | ||
package com.smartsense.chat.utils.response; | ||
|
||
import java.util.UUID; | ||
|
||
public record BusinessPartnerResponse(UUID id, | ||
String name, | ||
String bpn, | ||
String edcUrl) { | ||
} |
Oops, something went wrong.