Skip to content

Commit

Permalink
Code review
Browse files Browse the repository at this point in the history
  • Loading branch information
samleeflang committed Nov 12, 2024
1 parent 843a9f9 commit 94d6c25
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,23 +73,21 @@ private static List<DefaultMapping> buildDefaultMapping(
return mappedList;
}

private static List<TermMapping> buildFieldMapping(
DataMappingRequest dataMappingRequest) {
private static List<TermMapping> buildTermMapping(DataMappingRequest dataMappingRequest) {
var mappedList = new ArrayList<TermMapping>();
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())
Expand Down Expand Up @@ -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()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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)
Expand All @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -13,7 +13,7 @@
@Slf4j
public class ControllerUtils {

private static final String ORCID = "orcid";
public static final String ORCID = "orcid";

private ControllerUtils() {
}
Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ private static Stream<Arguments> 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<String, Object>(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<String, Object>(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)
));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ class ProvenanceServiceTest {

private static List<Agent> 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)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 94d6c25

Please sign in to comment.