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 @@ -81,13 +81,14 @@ public EdcDataController(DataAccessService dataAccessService, ObjectMapper objec
public ResponseEntity<Void> uploadFile(@PathVariable Long participantId,
@PathVariable Long tenantId,
@PathVariable Long providerId,
@RequestPart("metadata") String metadata,
@RequestPart("publicMetadata") String publicMetadata,
@RequestPart("privateMetadata") String privateMetadata,
@RequestPart("file") MultipartFile file) {

try {
var metadataMap = objectMapper.readValue(metadata, new TypeReference<Map<String, Object>>() {
});
dataAccessService.uploadFileForParticipant(participantId, metadataMap, file.getInputStream(), file.getContentType(), file.getOriginalFilename());
var publicMetadataMap = objectMapper.readValue(publicMetadata, new TypeReference<Map<String, Object>>() {});
var privateMetadataMap = objectMapper.readValue(privateMetadata, new TypeReference<Map<String, Object>>() {});
dataAccessService.uploadFileForParticipant(participantId, publicMetadataMap, privateMetadataMap, file.getInputStream(), file.getContentType(), file.getOriginalFilename());
} catch (IOException e) {
return ResponseEntity.internalServerError().build();
}
Expand Down Expand Up @@ -123,7 +124,6 @@ public ResponseEntity<List<FileResource>> listFiles(@PathVariable Long participa
@Parameter(name = "providerId", description = "Database ID of the service provider", required = true)
@Parameter(name = "tenantId", description = "Database ID of the tenant", required = true)
@Parameter(name = "participantId", description = "Database ID of the participant", required = true)
@Parameter(name = "counterPartyIdentifier", description = "Identifier of the counter-party to request catalog from", required = true)
public ResponseEntity<Catalog> requestCatalog(@RequestHeader(name = "Cache-Control", required = false, defaultValue = "no-cache") String cacheControl,
@PathVariable Long providerId,
@PathVariable Long tenantId,
Expand Down Expand Up @@ -172,6 +172,7 @@ public ResponseEntity<List<Contract>> listContracts(@PathVariable Long providerI
.type(cn.getType());

if (cn.getContractAgreement() != null) {
builder.id(cn.getContractAgreement().getId());
builder.agreementId(cn.getContractAgreement().getAgreementId());
builder.assetId(cn.getContractAgreement().getAssetId());
builder.signingDate(Instant.ofEpochSecond(cn.getContractAgreement().getContractSigningDate()));
Expand All @@ -195,7 +196,7 @@ public ResponseEntity<List<Contract>> listContracts(@PathVariable Long providerI
@Parameter(name = "providerId", description = "Database ID of the service provider", required = true)
@Parameter(name = "tenantId", description = "Database ID of the tenant", required = true)
@Parameter(name = "participantId", description = "Database ID of the participant", required = true)
@PostMapping("service-providers/{providerId}/tenants/{tenantId}/participants/{participantId}/contracts")
@PostMapping(value = "service-providers/{providerId}/tenants/{tenantId}/participants/{participantId}/contracts", produces = "text/plain")
public ResponseEntity<String> requestContract(@PathVariable Long providerId,
@PathVariable Long tenantId,
@PathVariable Long participantId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

public class Contract {
private boolean isPending = true;

private String id;
private String counterParty;
private String type;
private String agreementId;
Expand All @@ -37,6 +39,14 @@ public void setPending(boolean pending) {
isPending = pending;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getCounterParty() {
return counterParty;
}
Expand Down Expand Up @@ -122,6 +132,11 @@ public Builder type(String type) {
return this;
}

public Builder id(String id) {
contract.setId(id);
return this;
}

public Builder agreementId(String agreementId) {
contract.setAgreementId(agreementId);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
import java.util.Set;
import java.util.UUID;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static com.metaformsystems.redline.domain.service.Constants.ASSET_PERMISSION;
import static com.metaformsystems.redline.domain.service.Constants.MEMBERSHIP_CONTRACT_DEFINITION;
Expand All @@ -70,21 +72,23 @@ public DataAccessService(DataPlaneApiClient dataPlaneApiClient, WebDidResolver w
}

@Transactional
public void uploadFileForParticipant(Long participantId, Map<String, Object> metadata, InputStream fileStream, String contentType, String originalFilename) {
public void uploadFileForParticipant(Long participantId, Map<String, Object> publicMetadata, Map<String, Object> privateMetadata, InputStream fileStream, String contentType, String originalFilename) {

var participant = participantRepository.findById(participantId).orElseThrow(() -> new ObjectNotFoundException("Participant not found with id: " + participantId));
var participantContextId = participant.getParticipantContextId();

//0. upload file to data plane
var assetId = UUID.randomUUID().toString();
metadata.put("assetId", assetId);
var response = dataPlaneApiClient.uploadMultipart(participantContextId, metadata, fileStream);
publicMetadata.put("assetId", assetId);
var combinedMetadata = Stream.of(publicMetadata, privateMetadata).flatMap(m -> m.entrySet().stream())
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
var response = dataPlaneApiClient.uploadMultipart(participantContextId, combinedMetadata, fileStream);
var fileId = response.id();

//1. create asset
metadata.put("fileId", fileId);
publicMetadata.put("fileId", fileId);

var asset = createAsset(assetId, metadata, contentType, originalFilename);
var asset = createAsset(assetId, publicMetadata, privateMetadata, contentType, originalFilename);
managementApiClient.createAsset(participantContextId, asset);

// create CEL expression
Expand Down Expand Up @@ -114,7 +118,7 @@ public void uploadFileForParticipant(Long participantId, Map<String, Object> met


//2. track uploaded file in DB
participant.getUploadedFiles().add(new UploadedFile(fileId, originalFilename, contentType, metadata));
participant.getUploadedFiles().add(new UploadedFile(fileId, originalFilename, contentType, publicMetadata));
}

@Transactional
Expand Down Expand Up @@ -261,22 +265,24 @@ private ContractNegotiation getAgreement(String participantContextId, ContractNe
return negotiation;
}

private Asset createAsset(String id, Map<String, Object> metadata, String contentType, String originalFilename) {
private Asset createAsset(String id, Map<String, Object> publicMetadata, Map<String, Object> privateMetadata, String contentType, String originalFilename) {

var properties = new HashMap<String, Object>(Map.of(
"description", "A file uploaded by Redline on " + Instant.now().toString(),
"contentType", contentType,
"originalFilename", originalFilename));
properties.putAll(metadata);
properties.putAll(publicMetadata);

privateMetadata.put("permission", ASSET_PERMISSION);

return Asset.Builder.aNewAsset()
.id(id)
.dataAddress(Map.of(
"type", "HttpCertData",
"@type", "DataAddress"
))
.privateProperties(Map.of("permission", ASSET_PERMISSION)) //this is targeted by the CEL expression, so it must be a private property
.properties(properties)
.privateProperties(privateMetadata) //this is targeted by the CEL expression, so it must be a private property
.properties(Map.of("properties", properties))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ public class Dataset {
@JsonProperty("distribution")
private List<Distribution> distribution;

@JsonProperty("description")
private String description;

@JsonProperty("properties")
@JsonProperty("edc:properties")
private Map<String, Object> properties = new HashMap<>();

public String getId() {
Expand Down Expand Up @@ -71,14 +68,6 @@ public void setDistribution(List<Distribution> distribution) {
this.distribution = distribution;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public Map<String, Object> getProperties() {
return properties;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ void testTransferFile() throws Exception {
baseRequest()
.contentType(ContentType.MULTIPART)
.multiPart("file", "testfile.txt", "This is a test file.".getBytes())
.multiPart("metadata", "{\"slug\": \"%s\"}".formatted(slug), "application/json")
.multiPart("publicMetadata", "{\"slug\": \"%s\"}".formatted(slug), "application/json")
.multiPart("privateMetadata", "{\"privateSlug\": \"%s\"}".formatted(slug), "application/json")
.post("/api/ui/service-providers/%s/tenants/%s/participants/%s/files".formatted(SERVICE_PROVIDER_ID, provider.tenantId(), provider.participantId()))
.then()
.statusCode(200);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,10 @@ void shouldUploadFile() throws Exception {
);

// Create metadata
var metadataPart = new MockPart("metadata", "{\"foo\": \"bar\"}".getBytes());
metadataPart.getHeaders().setContentType(MediaType.APPLICATION_JSON);
var publicMetadata = new MockPart("publicMetadata", "{\"foo\": \"bar\"}".getBytes());
publicMetadata.getHeaders().setContentType(MediaType.APPLICATION_JSON);
var privateMetadata = new MockPart("privateMetadata", "{\"private\": \"value\"}".getBytes());
privateMetadata.getHeaders().setContentType(MediaType.APPLICATION_JSON);

// Mock the upload response from the dataplane
mockWebServer.enqueue(new MockResponse()
Expand All @@ -189,7 +191,7 @@ void shouldUploadFile() throws Exception {
mockMvc.perform(multipart("/api/ui/service-providers/{providerId}/tenants/{tenantId}/participants/{participantId}/files",
serviceProvider.getId(), tenant.getId(), participant.getId())
.file(mockFile)
.part(metadataPart))
.part(publicMetadata, privateMetadata))
.andExpect(status().isOk());

assertThat(participantRepository.findById(participant.getId())).isPresent()
Expand Down
Loading