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

fixes for https://github.com/who-icatx/icatx-project/issues/142 #26

Merged
merged 2 commits into from
Jan 7, 2025
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
15 changes: 15 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,21 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<systemPropertyVariables>
<spring.profiles.active>test</spring.profiles.active>
</systemPropertyVariables>
<includes>
<include>**/*TestCase.java</include>
<include>**/*Test.java</include>
<include>**/*IT.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package edu.stanford.protege.gateway.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import edu.stanford.protege.webprotege.common.UserId;

import java.time.LocalDateTime;

public record EntityChange(String changeSummary,
UserId userId,
LocalDateTime dateTime) {
@JsonProperty("timestamp") LocalDateTime timestamp) {
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package edu.stanford.protege.gateway.dto;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.*;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

public record OWLEntityDto(String entityIRI,
public record OWLEntityDto(@JsonProperty("entityUri") String entityIRI,

EntityLanguageTerms languageTerms,
EntityLinearizationWrapperDto entityLinearizations,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public CompletableFuture<LocalDateTime> getEntityLatestChangeTime(String project
return entityHistorySummaryExecutor.execute(new GetEntityHistorySummaryRequest(projectId, entityIri), executionContext)
.thenApply(response -> {
if (response.entityHistorySummary() != null && response.entityHistorySummary().changes() != null && response.entityHistorySummary().changes().size() > 0) {
response.entityHistorySummary().changes().sort(Comparator.comparing(EntityChange::dateTime).reversed());
return response.entityHistorySummary().changes().get(0).dateTime();
response.entityHistorySummary().changes().sort(Comparator.comparing(EntityChange::timestamp).reversed());
return response.entityHistorySummary().changes().get(0).timestamp();
}
return LocalDateTime.MIN;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ public CompletableFuture<EntityLinearizationWrapperDto> getEntityLinearizationDt
@Async
public CompletableFuture<EntityLinearizationWrapperDto> getEntityLinearizationDto(String entityIri, String projectId, ExecutionContext executionContext) {
try {
List<LinearizationDefinition> linDef = this.getDefinitionList(executionContext);
return entityLinearizationCommand.execute(new GetEntityLinearizationsRequest(entityIri, ProjectId.valueOf(projectId)), executionContext)
.thenApply(response -> LinearizationMapper.mapFromResponse(response.linearizationSpecification(), response.lastRevisionDate()));
.thenApply(response -> LinearizationMapper.mapFromResponse(response.linearizationSpecification(), response.lastRevisionDate(), linDef));
} catch (Exception e) {
LOGGER.error("Error fetching linearization of entity " + entityIri, e);
throw new ApplicationException("Error fetching linearization of entity " + entityIri);
Expand All @@ -60,7 +61,8 @@ public List<LinearizationDefinition> getDefinitionList(ExecutionContext executio

public void updateEntityLinearization(OWLEntityDto owlEntityDto, ProjectId projectId, ChangeRequestId changeRequestId) {
try {
WhoficEntityLinearizationSpecification linearizationSpecification = LinearizationMapper.mapFromDto(owlEntityDto.entityIRI(), owlEntityDto.entityLinearizations());
List<LinearizationDefinition> linDef = this.getDefinitionList(SecurityContextHelper.getExecutionContext());
WhoficEntityLinearizationSpecification linearizationSpecification = LinearizationMapper.mapFromDto(owlEntityDto.entityIRI(), owlEntityDto.entityLinearizations(), linDef);
saveLinearizationCommand.execute(new SaveEntityLinearizationRequest(projectId, linearizationSpecification, changeRequestId), SecurityContextHelper.getExecutionContext()).get();
} catch (Exception e) {
LOGGER.error("Error updating linearization for entity " + owlEntityDto.entityIRI(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
public class LinearizationDefinition {


@JsonProperty("Id")
private final String id;
@JsonProperty("linearizationId")
private final String linearizationId;

@JsonProperty("whoficEntityIri")
private final String whoficEntityIri;
@JsonProperty("linearizationUri")
private final String linearizationUri;

@JsonProperty("Description")
@JsonProperty("description")
private final String description;

@JsonProperty("linearizationMode")
Expand All @@ -28,25 +28,25 @@ public class LinearizationDefinition {
@JsonProperty("sortingCode")
private final String sortingCode;

@JsonProperty("DisplayLabel")
@JsonProperty("displayLabel")
private final String displayLabel;

@JsonProperty("oldId")
private final String oldId;


@JsonCreator
public LinearizationDefinition(@JsonProperty("Id") String id,
@JsonProperty("whoficEntityIri") String whoficEntityIri,
public LinearizationDefinition(@JsonProperty("linearizationId") String linearizationId,
@JsonProperty("linearizationUri") String linearizationUri,
@JsonProperty("oldId") String oldId,
@JsonProperty("Description")String description,
@JsonProperty("LinearizationMode") String linearizationMode,
@JsonProperty("DisplayLabel") String displayLabel,
@JsonProperty("description")String description,
@JsonProperty("linearizationMode") String linearizationMode,
@JsonProperty("displayLabel") String displayLabel,
@JsonProperty("rootId") String rootId,
@JsonProperty("CoreLinId") String coreLinId,
@JsonProperty("coreLinId") String coreLinId,
@JsonProperty("sortingCode") String sortingCode) {
this.id = id;
this.whoficEntityIri = whoficEntityIri;
this.linearizationId = linearizationId;
this.linearizationUri = linearizationUri;
this.description = description;
this.linearizationMode = linearizationMode;
this.rootId = rootId;
Expand All @@ -58,12 +58,12 @@ public LinearizationDefinition(@JsonProperty("Id") String id,


@JsonIgnore
public String getId() {
return id;
public String getLinearizationId() {
return linearizationId;
}

public String getWhoficEntityIri() {
return whoficEntityIri;
public String getLinearizationUri() {
return linearizationUri;
}

public String getLinearizationMode() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
package edu.stanford.protege.gateway.linearization.commands;

import edu.stanford.protege.gateway.dto.EntityLinearization;
import edu.stanford.protege.gateway.dto.EntityLinearizationWrapperDto;
import edu.stanford.protege.gateway.dto.LinearizationTitle;
import edu.stanford.protege.gateway.dto.*;
import org.semanticweb.owlapi.model.IRI;

import java.util.Date;
import java.util.List;
import java.util.*;

public class LinearizationMapper {


public static EntityLinearizationWrapperDto mapFromResponse(WhoficEntityLinearizationSpecification whoficSpecification, Date latsRevisionDate) {
public static EntityLinearizationWrapperDto mapFromResponse(WhoficEntityLinearizationSpecification whoficSpecification, Date latsRevisionDate, List<LinearizationDefinition> linDef) {
List<EntityLinearization> linearizations = whoficSpecification.linearizationSpecifications()
.stream().map(LinearizationMapper::mapFromSpecification).toList();
.stream()
.map(specification -> LinearizationMapper.mapFromSpecification(specification, linDef))
.toList();
if (whoficSpecification.linearizationResiduals() != null) {
String suppressOtherResiduals = whoficSpecification.linearizationResiduals().suppressOtherSpecifiedResiduals() == null ? null : whoficSpecification.linearizationResiduals().suppressOtherSpecifiedResiduals().toString();
String suppressUnspecified = whoficSpecification.linearizationResiduals().suppressUnspecifiedResiduals() == null ? null : whoficSpecification.linearizationResiduals().suppressUnspecifiedResiduals().toString();
Expand All @@ -33,33 +32,55 @@ public static EntityLinearizationWrapperDto mapFromResponse(WhoficEntityLineariz
}


public static WhoficEntityLinearizationSpecification mapFromDto(String entityIri, EntityLinearizationWrapperDto dto) {
public static WhoficEntityLinearizationSpecification mapFromDto(String entityIri, EntityLinearizationWrapperDto dto, List<LinearizationDefinition> linDef) {
LinearizationResiduals residuals = new LinearizationResiduals(LinearizationSpecificationStatus.getStatusFromString(dto.suppressOtherSpecifiedResiduals()),
LinearizationSpecificationStatus.getStatusFromString(dto.suppressUnspecifiedResiduals()),
dto.otherSpecifiedResidualTitle() != null ? dto.otherSpecifiedResidualTitle().label() : null,
dto.unspecifiedResidualTitle() != null ? dto.unspecifiedResidualTitle().label() : null);

List<LinearizationSpecification> specifications = dto.linearizations().stream().map(LinearizationMapper::mapFromDto).toList();
List<LinearizationSpecification> specifications = dto.linearizations().stream().map(lin -> mapFromDto(lin, linDef)).toList();

return new WhoficEntityLinearizationSpecification(IRI.create(entityIri), residuals, specifications);
}


private static LinearizationSpecification mapFromDto(EntityLinearization dto) {
private static LinearizationSpecification mapFromDto(EntityLinearization dto, List<LinearizationDefinition> linDef) {
return new LinearizationSpecification(LinearizationSpecificationStatus.getStatusFromString(dto.isAuxiliaryAxisChild()),
LinearizationSpecificationStatus.getStatusFromString(dto.isGrouping()),
LinearizationSpecificationStatus.getStatusFromString(dto.isIncludedInLinearization()),
dto.linearizationPathParent() == null ? null : IRI.create(dto.linearizationPathParent()),
IRI.create(dto.linearizationId()),
IRI.create(getLinView(dto, linDef)),
dto.codingNote());
}

private static EntityLinearization mapFromSpecification(LinearizationSpecification specification) {
private static EntityLinearization mapFromSpecification(LinearizationSpecification specification, List<LinearizationDefinition> linDef) {

return new EntityLinearization(specification.isAuxiliaryAxisChild().toString(),
specification.isGrouping().toString(),
specification.isIncludedInLinearization().toString(),
specification.linearizationParent() == null ? "" : specification.linearizationParent().toString(),
specification.linearizationView() == null ? "" : specification.linearizationView().toString(),
getLinId(specification, linDef),
specification.codingNote());
}

private static String getLinId(LinearizationSpecification linSpec, List<LinearizationDefinition> linDef) {
return linDef.stream()
.filter(lindef -> {
if (linSpec.linearizationView() != null) {
return lindef.getLinearizationUri().equals(linSpec.linearizationView().toString());
}
return false;
})
.findAny()
.map(LinearizationDefinition::getLinearizationId)
.orElse("");
}

private static String getLinView(EntityLinearization lin, List<LinearizationDefinition> linDef) {
return linDef.stream()
.filter(lindef -> lin.linearizationId().equals(lindef.getLinearizationId()))
.findAny()
.map(LinearizationDefinition::getLinearizationUri)
.orElse("");
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package edu.stanford.protege.gateway.postcoordination;

import edu.stanford.protege.gateway.dto.EntityPostCoordinationCustomScalesDto;
import edu.stanford.protege.gateway.dto.EntityPostCoordinationSpecificationDto;
import edu.stanford.protege.gateway.linearization.commands.LinearizationDefinition;
import edu.stanford.protege.gateway.postcoordination.commands.*;
Expand All @@ -15,7 +14,7 @@ public static List<EntityPostCoordinationSpecificationDto> mapFromResponse(GetEn
List<EntityPostCoordinationSpecificationDto> resp = new ArrayList<>();
for (PostCoordinationSpecification specification : response.postCoordinationSpecification().postcoordinationSpecifications()) {
LinearizationDefinition definition = gedDefinitionByView(specification.getLinearizationView(), definitions);
EntityPostCoordinationSpecificationDto dto = new EntityPostCoordinationSpecificationDto(definition.getId(),
EntityPostCoordinationSpecificationDto dto = new EntityPostCoordinationSpecificationDto(definition.getLinearizationId(),
new ArrayList<>(),
new ArrayList<>(),
new ArrayList<>(),
Expand Down Expand Up @@ -48,7 +47,7 @@ public static WhoficEntityPostCoordinationSpecification mapFromDtoList(String en

List<PostCoordinationSpecification> specifications = dtos.stream().map(dto -> {
LinearizationDefinition definition = getDefinitionByLinearizationId(dto.linearizationId(), definitions);
PostCoordinationSpecification spec = new PostCoordinationSpecification(definition.getWhoficEntityIri(),
PostCoordinationSpecification spec = new PostCoordinationSpecification(definition.getLinearizationUri(),
new ArrayList<>(),
new ArrayList<>(),
new ArrayList<>(),
Expand Down Expand Up @@ -98,13 +97,13 @@ private static boolean isMainAxis(LinearizationDefinition linearizationDefinitio
}

private static LinearizationDefinition getDefinitionByLinearizationId(String linearizationId, List<LinearizationDefinition> definitions) {
return definitions.stream().filter(def -> def.getId().equalsIgnoreCase(linearizationId))
return definitions.stream().filter(def -> def.getLinearizationId().equalsIgnoreCase(linearizationId))
.findFirst()
.orElseThrow(() -> new RuntimeException("Error finding definition with id " + linearizationId));
}

private static LinearizationDefinition gedDefinitionByView(String linearizationView, List<LinearizationDefinition> definitions) {
return definitions.stream().filter(def -> def.getWhoficEntityIri().equalsIgnoreCase(linearizationView))
return definitions.stream().filter(def -> def.getLinearizationUri().equalsIgnoreCase(linearizationView))
.findFirst()
.orElseThrow(() -> new RuntimeException("Error finding definition with id " + linearizationView));
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ logging:
root: DEBUG

icatx:
formId: 013d9d4a-9dac-4d2f-aa52-2a40fad73b77
formId: 0612d01f-a60f-4fe7-8421-d404915685d7

springdoc:
swagger-ui:
Expand All @@ -18,7 +18,7 @@ spring:
application:
name: icatx-api-gateway
rabbitmq:
host: localhost
host: rabbitmq
port: 5672
username: guest
password: guest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,44 @@
package edu.stanford.protege.gateway.linearization;

import edu.stanford.protege.gateway.dto.EntityLinearization;
import edu.stanford.protege.gateway.dto.EntityLinearizationWrapperDto;
import edu.stanford.protege.gateway.dto.LinearizationTitle;
import edu.stanford.protege.gateway.linearization.commands.LinearizationMapper;
import edu.stanford.protege.gateway.linearization.commands.LinearizationSpecificationStatus;
import edu.stanford.protege.gateway.linearization.commands.WhoficEntityLinearizationSpecification;
import org.junit.jupiter.api.Test;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import edu.stanford.protege.gateway.config.ApplicationBeans;
import edu.stanford.protege.gateway.dto.*;
import edu.stanford.protege.gateway.linearization.commands.*;
import org.junit.jupiter.api.*;

import java.util.Collections;
import java.io.*;
import java.util.*;

import static org.junit.jupiter.api.Assertions.*;

public class EntityLinearizationMapperTest {

private List<LinearizationDefinition> definitionList;

@BeforeEach
public void setUp() throws IOException {
ObjectMapper objectMapper = new ApplicationBeans().objectMapper();
File defFile = new File("src/test/resources/LinearizationDefinitions.json");
definitionList = objectMapper.readValue(defFile, new TypeReference<>() {
});
}


@Test
public void GIVEN_scrambledLinearizationDTO_WHEN_mapToRequest_THEN_fieldsAreCorrectlyMapped() {
EntityLinearization entityLinearization = new EntityLinearization("true",
"fAlSE",
"unKnown",null,
"http://id.who.int/icd/release/11/pcl",null);
"unKnown", null,
"PCL", null);

EntityLinearizationWrapperDto dto = new EntityLinearizationWrapperDto(null,
"UnKnown",
null,
null,
new LinearizationTitle("test"), Collections.singletonList(entityLinearization));

WhoficEntityLinearizationSpecification spec = LinearizationMapper.mapFromDto("http://id.who.int/icd/entity/694903163", dto);
WhoficEntityLinearizationSpecification spec = LinearizationMapper.mapFromDto("http://id.who.int/icd/entity/694903163", dto, definitionList);

assertNotNull(spec);
assertNotNull(spec.linearizationResiduals());
Expand Down
Loading