Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ID schema field to Contract Definition #498

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 @@ -38,7 +38,7 @@ void contractDefinitionPage(ContractDefinitionService contractDefinitionService)
// arrange
var client = TestUtils.edcClient();
var criterion = new Criterion("exampleLeft1", "EQ", "abc");
createContractDefinition(contractDefinitionService, "contractPolicy-id-1", "accessPolicy-id-1", criterion);
createContractDefinition(contractDefinitionService, "contractDefinition-id-1", "contractPolicy-id-1", "accessPolicy-id-1", criterion);

// act
var result = client.uiApi().contractDefinitionPage();
Expand All @@ -47,6 +47,7 @@ void contractDefinitionPage(ContractDefinitionService contractDefinitionService)
var contractDefinitions = result.getContractDefinitions();
assertThat(contractDefinitions).hasSize(1);
var contractDefinition = contractDefinitions.get(0);
assertThat(contractDefinition.getContractDefinitionId()).isEqualTo("contractDefinition-id-1");
assertThat(contractDefinition.getContractPolicyId()).isEqualTo("contractPolicy-id-1");
assertThat(contractDefinition.getAccessPolicyId()).isEqualTo("accessPolicy-id-1");
assertThat(contractDefinition.getAssetSelector()).hasSize(1);
Expand All @@ -64,18 +65,21 @@ void contractDefinitionPageSorting(ContractDefinitionService contractDefinitionS
var client = TestUtils.edcClient();
createContractDefinition(
contractDefinitionService,
"contractDefinition-id-1",
"contractPolicy-id-1",
"accessPolicy-id-1",
new Criterion("exampleLeft1", "EQ", "abc"),
1628956800000L);
createContractDefinition(
contractDefinitionService,
"contractDefinition-id-2",
"contractPolicy-id-2",
"accessPolicy-id-2",
new Criterion("exampleLeft1", "EQ", "abc"),
1628956801000L);
createContractDefinition(
contractDefinitionService,
"contractDefinition-id-3",
"contractPolicy-id-3",
"accessPolicy-id-3",
new Criterion("exampleLeft1", "EQ", "abc"),
Expand All @@ -101,6 +105,7 @@ void testContractDefinitionCreation(ContractDefinitionService contractDefinition
new UiCriterionLiteralDto(UiCriterionLiteralDto.TypeEnum.VALUE, "test", null));

var contractDefinition = ContractDefinitionRequest.builder()
.contractDefinitionId("contractDefinition-id-1")
.contractPolicyId("contractPolicy-id-1")
.accessPolicyId("accessPolicy-id-1")
.assetSelector(List.of(criterion))
Expand All @@ -114,6 +119,7 @@ void testContractDefinitionCreation(ContractDefinitionService contractDefinition
var contractDefinitions = contractDefinitionService.query(QuerySpec.max()).getContent().toList();
assertThat(contractDefinitions).hasSize(1);
var contractDefinitionEntry = contractDefinitions.get(0);
assertThat(contractDefinitionEntry.getId()).isEqualTo("contractDefinition-id-1");
assertThat(contractDefinitionEntry.getContractPolicyId()).isEqualTo("contractPolicy-id-1");
assertThat(contractDefinitionEntry.getAccessPolicyId()).isEqualTo("accessPolicy-id-1");

Expand All @@ -129,7 +135,7 @@ void testDeleteContractDefinition(ContractDefinitionService contractDefinitionSe
// arrange
var client = TestUtils.edcClient();
var criterion = new Criterion("exampleLeft1", "EQ", "exampleRight1");
createContractDefinition(contractDefinitionService, "contractPolicy-id-1", "accessPolicy-id-1", criterion);
createContractDefinition(contractDefinitionService, "contractDefinition-id-1", "contractPolicy-id-1", "accessPolicy-id-1", criterion);
assertThat(contractDefinitionService.query(QuerySpec.max()).getContent().toList()).hasSize(1);
var contractDefinition = contractDefinitionService.query(QuerySpec.max()).getContent().toList().get(0);

Expand All @@ -143,13 +149,15 @@ void testDeleteContractDefinition(ContractDefinitionService contractDefinitionSe

private void createContractDefinition(
ContractDefinitionService contractDefinitionService,
String contractDefinitionId,
String contractPolicyId,
String accessPolicyId,
Criterion criteria,
long createdAt
) {

var contractDefinition = ContractDefinition.Builder.newInstance()
.id(contractDefinitionId)
.contractPolicyId(contractPolicyId)
.accessPolicyId(accessPolicyId)
.assetsSelector(List.of(criteria))
Expand All @@ -160,11 +168,13 @@ private void createContractDefinition(

private void createContractDefinition(
ContractDefinitionService contractDefinitionService,
String contractDefinitionId,
String contractPolicyId,
String accessPolicyId,
Criterion criteria
) {
var contractDefinition = ContractDefinition.Builder.newInstance()
.id(contractDefinitionId)
.contractPolicyId(contractPolicyId)
.accessPolicyId(accessPolicyId)
.assetsSelector(List.of(criteria))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
@Schema(description = "Contract Definition List Entry for Contract Definition Page")
public class ContractDefinitionEntry {

@Schema(description = "Contract Definition ID", requiredMode = Schema.RequiredMode.REQUIRED)
private String contractDefinitionId;

@Schema(description = "Access Policy ID", requiredMode = Schema.RequiredMode.REQUIRED)
private String accessPolicyId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
@RequiredArgsConstructor
@Schema(description = "Data for creating a Contract Definition")
public class ContractDefinitionRequest {

@Schema(description = "Contract Definition ID", requiredMode = Schema.RequiredMode.REQUIRED)
private String contractDefinitionId;

@Schema(description = "Contract Policy ID", requiredMode = Schema.RequiredMode.REQUIRED)
private String contractPolicyId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public List<ContractDefinitionEntry> getContractDefinitions() {
.sorted(Comparator.comparing(ContractDefinition::getCreatedAt).reversed())
.map(definition -> {
var entry = new ContractDefinitionEntry();
entry.setContractDefinitionId(definition.getId());
entry.setAccessPolicyId(definition.getAccessPolicyId());
entry.setContractPolicyId(definition.getContractPolicyId());
entry.setAssetSelector(criterionMapper.mapToCriterionDtos(definition.getAssetsSelector()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ public class ContractDefinitionBuilder {
private final CriterionMapper criterionMapper;

public ContractDefinition buildContractDefinition(ContractDefinitionRequest request) {
var contractDefinitionId = request.getContractDefinitionId();
var contractPolicyId = request.getContractPolicyId();
var accessPolicyId = request.getAccessPolicyId();
var assetsSelector = request.getAssetSelector();

return ContractDefinition.Builder.newInstance()
.id(request.getContractPolicyId())
.id(contractDefinitionId)
.contractPolicyId(contractPolicyId)
.accessPolicyId(accessPolicyId)
.assetsSelector(criterionMapper.mapToCriteria(assetsSelector))
Expand Down
Loading