diff --git a/src/main/java/eu/dissco/orchestration/backend/service/DataMappingService.java b/src/main/java/eu/dissco/orchestration/backend/service/DataMappingService.java index b0eed2b..11234ff 100644 --- a/src/main/java/eu/dissco/orchestration/backend/service/DataMappingService.java +++ b/src/main/java/eu/dissco/orchestration/backend/service/DataMappingService.java @@ -73,23 +73,21 @@ private static List buildDefaultMapping( return mappedList; } - private static List buildFieldMapping( - DataMappingRequest dataMappingRequest) { + private static List buildTermMapping(DataMappingRequest dataMappingRequest) { var mappedList = new ArrayList(); for (var odsDefaultMapping : dataMappingRequest.getOdsHasTermMapping()) { - var mappedOdsFieldMapping = new TermMapping(); + var mappedOdsTermMapping = new TermMapping(); for (var property : odsDefaultMapping.getAdditionalProperties() .entrySet()) { - mappedOdsFieldMapping.setAdditionalProperty(property.getKey(), property.getValue()); + mappedOdsTermMapping.setAdditionalProperty(property.getKey(), property.getValue()); } - mappedList.add(mappedOdsFieldMapping); + mappedList.add(mappedOdsTermMapping); } return mappedList; } private static DataMapping buildTombstoneDataMapping(DataMapping dataMapping, - Agent tombstoningAgent, - Instant timestamp) { + Agent tombstoningAgent, Instant timestamp) { return new DataMapping() .withId(dataMapping.getId()) .withType(dataMapping.getType()) @@ -143,7 +141,7 @@ private DataMapping buildDataMapping(DataMappingRequest dataMappingRequest, int .withSchemaDateModified(Date.from(Instant.now())) .withSchemaCreator(agent) .withOdsHasDefaultMapping(buildDefaultMapping(dataMappingRequest)) - .withOdsHasTermMapping(buildFieldMapping(dataMappingRequest)) + .withOdsHasTermMapping(buildTermMapping(dataMappingRequest)) .withOdsMappingDataStandard(OdsMappingDataStandard.fromValue( dataMappingRequest.getOdsMappingDataStandard().value())); } diff --git a/src/main/java/eu/dissco/orchestration/backend/service/ProvenanceService.java b/src/main/java/eu/dissco/orchestration/backend/service/ProvenanceService.java index a971efc..d7db92f 100644 --- a/src/main/java/eu/dissco/orchestration/backend/service/ProvenanceService.java +++ b/src/main/java/eu/dissco/orchestration/backend/service/ProvenanceService.java @@ -4,7 +4,8 @@ import static eu.dissco.orchestration.backend.domain.AgentRoleType.PROCESSING_SERVICE; import static eu.dissco.orchestration.backend.schema.Agent.Type.PROV_PERSON; import static eu.dissco.orchestration.backend.schema.Agent.Type.PROV_SOFTWARE_AGENT; -import static eu.dissco.orchestration.backend.utils.AgentUtils.createMachineAgent; +import static eu.dissco.orchestration.backend.utils.AgentUtils.createAgent; +import static eu.dissco.orchestration.backend.utils.ControllerUtils.ORCID; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.JsonNode; @@ -95,9 +96,8 @@ private CreateUpdateTombstoneEvent generateCreateUpdateTombStoneEvent( .withProvValue(mapEntityToProvValue(digitalObject)) .withProvWasGeneratedBy(activityID)) .withOdsHasAgents( - List.of(createMachineAgent(agent.getSchemaName(), agent.getId(), CREATOR, - "orcid", PROV_PERSON), - createMachineAgent(properties.getName(), properties.getPid(), + List.of(createAgent(agent.getSchemaName(), agent.getId(), CREATOR, ORCID, PROV_PERSON), + createAgent(properties.getName(), properties.getPid(), PROCESSING_SERVICE, DctermsType.DOI.value(), PROV_SOFTWARE_AGENT))); } diff --git a/src/main/java/eu/dissco/orchestration/backend/utils/AgentUtils.java b/src/main/java/eu/dissco/orchestration/backend/utils/AgentUtils.java index f1ef47b..8c751f7 100644 --- a/src/main/java/eu/dissco/orchestration/backend/utils/AgentUtils.java +++ b/src/main/java/eu/dissco/orchestration/backend/utils/AgentUtils.java @@ -1,9 +1,9 @@ package eu.dissco.orchestration.backend.utils; import static eu.dissco.orchestration.backend.schema.Identifier.DctermsType.DOI; -import static eu.dissco.orchestration.backend.schema.Identifier.DctermsType.HANDLE; import static eu.dissco.orchestration.backend.schema.Identifier.OdsGupriLevel.GLOBALLY_UNIQUE_STABLE_PERSISTENT_RESOLVABLE_FDO_COMPLIANT; import static eu.dissco.orchestration.backend.schema.Identifier.OdsIdentifierStatus.PREFERRED; +import static eu.dissco.orchestration.backend.utils.ControllerUtils.ORCID; import eu.dissco.orchestration.backend.domain.AgentRoleType; import eu.dissco.orchestration.backend.schema.Agent; @@ -18,8 +18,8 @@ public class AgentUtils { private AgentUtils() { } - public static eu.dissco.orchestration.backend.schema.Agent createMachineAgent(String name, - String pid, AgentRoleType role, String idTitle, Type agentType) { + public static Agent createAgent(String name, String pid, AgentRoleType role, String idTitle, + Type agentType) { var agent = new Agent() .withType(agentType) .withId(pid) @@ -36,13 +36,10 @@ public static eu.dissco.orchestration.backend.schema.Agent createMachineAgent(St .withOdsIdentifierStatus(PREFERRED) .withOdsGupriLevel( GLOBALLY_UNIQUE_STABLE_PERSISTENT_RESOLVABLE_FDO_COMPLIANT); - if (idTitle.equals(DOI.value())) { + if (DOI.value().equals(idTitle)) { identifier.withDctermsType(DOI); identifier.withDctermsTitle("DOI"); - } else if (idTitle.equals(HANDLE.value())) { - identifier.withDctermsType(HANDLE); - identifier.withDctermsTitle("HANDLE"); - } else if (idTitle.equals("orcid")) { + } else if (idTitle.equals(ORCID)) { identifier.withDctermsType(DctermsType.URL); identifier.withDctermsTitle("ORCID"); } diff --git a/src/main/java/eu/dissco/orchestration/backend/utils/ControllerUtils.java b/src/main/java/eu/dissco/orchestration/backend/utils/ControllerUtils.java index ccfe3de..3c5d58f 100644 --- a/src/main/java/eu/dissco/orchestration/backend/utils/ControllerUtils.java +++ b/src/main/java/eu/dissco/orchestration/backend/utils/ControllerUtils.java @@ -1,6 +1,6 @@ package eu.dissco.orchestration.backend.utils; -import static eu.dissco.orchestration.backend.utils.AgentUtils.createMachineAgent; +import static eu.dissco.orchestration.backend.utils.AgentUtils.createAgent; import eu.dissco.orchestration.backend.domain.AgentRoleType; import eu.dissco.orchestration.backend.exception.ForbiddenException; @@ -13,7 +13,7 @@ @Slf4j public class ControllerUtils { - private static final String ORCID = "orcid"; + public static final String ORCID = "orcid"; private ControllerUtils() { } @@ -33,7 +33,7 @@ public static Agent getAgent(Authentication authentication, AgentRoleType roleTy fullName.append(claims.get("family_name")); } var nameString = fullName.toString().isEmpty() ? null : fullName.toString(); - return createMachineAgent(nameString, (String) claims.get(ORCID), roleType, ORCID, + return createAgent(nameString, (String) claims.get(ORCID), roleType, ORCID, Type.SCHEMA_PERSON); } else { log.error("Missing ORCID in token"); diff --git a/src/test/java/eu/dissco/orchestration/backend/controller/ControllerUtilsTest.java b/src/test/java/eu/dissco/orchestration/backend/controller/ControllerUtilsTest.java index 4c875f3..17a1d16 100644 --- a/src/test/java/eu/dissco/orchestration/backend/controller/ControllerUtilsTest.java +++ b/src/test/java/eu/dissco/orchestration/backend/controller/ControllerUtilsTest.java @@ -38,19 +38,19 @@ private static Stream claimsAndNames() { "orcid", OBJECT_CREATOR, "family_name", "Attenborough", "given_name", "David")), - AgentUtils.createMachineAgent("David Attenborough", OBJECT_CREATOR, CREATOR, "orcid", + AgentUtils.createAgent("David Attenborough", OBJECT_CREATOR, CREATOR, "orcid", Type.SCHEMA_PERSON) ), Arguments.of(new HashMap(Map.of( "orcid", OBJECT_CREATOR, "given_name", "David")), - AgentUtils.createMachineAgent("David", OBJECT_CREATOR, CREATOR, "orcid", + AgentUtils.createAgent("David", OBJECT_CREATOR, CREATOR, "orcid", Type.SCHEMA_PERSON) ), Arguments.of(new HashMap(Map.of( "orcid", OBJECT_CREATOR, "family_name", "Attenborough")), - AgentUtils.createMachineAgent("Attenborough", OBJECT_CREATOR, CREATOR, "orcid", + AgentUtils.createAgent("Attenborough", OBJECT_CREATOR, CREATOR, "orcid", Type.SCHEMA_PERSON) )); } diff --git a/src/test/java/eu/dissco/orchestration/backend/service/ProvenanceServiceTest.java b/src/test/java/eu/dissco/orchestration/backend/service/ProvenanceServiceTest.java index 50a3427..1f883a8 100644 --- a/src/test/java/eu/dissco/orchestration/backend/service/ProvenanceServiceTest.java +++ b/src/test/java/eu/dissco/orchestration/backend/service/ProvenanceServiceTest.java @@ -46,9 +46,9 @@ class ProvenanceServiceTest { private static List givenExpectedAgents() { return List.of( - AgentUtils.createMachineAgent(null, OBJECT_CREATOR, CREATOR, + AgentUtils.createAgent(null, OBJECT_CREATOR, CREATOR, "orcid", Type.PROV_PERSON), - AgentUtils.createMachineAgent(APP_NAME, APP_HANDLE, PROCESSING_SERVICE, + AgentUtils.createAgent(APP_NAME, APP_HANDLE, PROCESSING_SERVICE, DctermsType.DOI.value(), Type.PROV_SOFTWARE_AGENT) ); } diff --git a/src/test/java/eu/dissco/orchestration/backend/testutils/TestUtils.java b/src/test/java/eu/dissco/orchestration/backend/testutils/TestUtils.java index 4d3b1ab..27150ea 100644 --- a/src/test/java/eu/dissco/orchestration/backend/testutils/TestUtils.java +++ b/src/test/java/eu/dissco/orchestration/backend/testutils/TestUtils.java @@ -446,7 +446,7 @@ public static TombstoneMetadata givenTombstoneMetadata(ObjectType objectType) { } public static Agent givenAgent() { - return AgentUtils.createMachineAgent(null, OBJECT_CREATOR, AgentRoleType.CREATOR, + return AgentUtils.createAgent(null, OBJECT_CREATOR, AgentRoleType.CREATOR, "orcid", Type.SCHEMA_PERSON); }