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

Upload custom scales values #31

Merged
merged 7 commits into from
Oct 7, 2024
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 @@ -41,7 +41,9 @@ public MongoCustomConversions customConversions(ObjectMapper objectMapper) {
return new MongoCustomConversions(
List.of(
new PostcoordinationEventReadingConverter(objectMapper),
new PostcoordinationEventWritingConverter(objectMapper)
new PostcoordinationEventWritingConverter(objectMapper),
new PostCoordinationCustomScalesReadingConverter(objectMapper),
new PostCoordinationCustomScalesWritingConverter(objectMapper)
)
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package edu.stanford.protege.webprotege.postcoordinationservice.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import edu.stanford.protege.webprotege.postcoordinationservice.events.PostCoordinationCustomScalesValueEvent;
import org.bson.Document;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.convert.ReadingConverter;

@ReadingConverter
public class PostCoordinationCustomScalesReadingConverter implements Converter<Document, PostCoordinationCustomScalesValueEvent> {


private final ObjectMapper objectMapper;

public PostCoordinationCustomScalesReadingConverter(ObjectMapper objectMapper) {
this.objectMapper = objectMapper;
}

@Override
public PostCoordinationCustomScalesValueEvent convert(Document source) {
return objectMapper.convertValue(source, PostCoordinationCustomScalesValueEvent.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package edu.stanford.protege.webprotege.postcoordinationservice.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import edu.stanford.protege.webprotege.postcoordinationservice.events.PostCoordinationCustomScalesValueEvent;
import edu.stanford.protege.webprotege.postcoordinationservice.events.PostCoordinationSpecificationEvent;
import org.bson.Document;
import org.jetbrains.annotations.NotNull;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.convert.WritingConverter;

@WritingConverter
public class PostCoordinationCustomScalesWritingConverter implements Converter<PostCoordinationCustomScalesValueEvent, Document> {
private final ObjectMapper objectMapper;

public PostCoordinationCustomScalesWritingConverter(ObjectMapper objectMapper) {
this.objectMapper = objectMapper;
}


@Override
public Document convert(@NotNull PostCoordinationCustomScalesValueEvent source) {
return objectMapper.convertValue(source, Document.class);
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package edu.stanford.protege.webprotege.postcoordinationservice.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import edu.stanford.protege.webprotege.postcoordinationservice.events.PostCoordinationEvent;
import edu.stanford.protege.webprotege.postcoordinationservice.events.PostCoordinationSpecificationEvent;
import org.bson.Document;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.convert.ReadingConverter;

@ReadingConverter
public class PostcoordinationEventReadingConverter implements Converter<Document, PostCoordinationEvent> {
public class PostcoordinationEventReadingConverter implements Converter<Document, PostCoordinationSpecificationEvent> {


private final ObjectMapper objectMapper;
Expand All @@ -17,7 +17,7 @@ public PostcoordinationEventReadingConverter(ObjectMapper objectMapper) {
}

@Override
public PostCoordinationEvent convert(Document source) {
return objectMapper.convertValue(source, PostCoordinationEvent.class);
public PostCoordinationSpecificationEvent convert(Document source) {
return objectMapper.convertValue(source, PostCoordinationSpecificationEvent.class);
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package edu.stanford.protege.webprotege.postcoordinationservice.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import edu.stanford.protege.webprotege.postcoordinationservice.events.PostCoordinationEvent;
import edu.stanford.protege.webprotege.postcoordinationservice.events.PostCoordinationSpecificationEvent;
import org.bson.Document;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.convert.WritingConverter;


@WritingConverter
public class PostcoordinationEventWritingConverter implements Converter<PostCoordinationEvent, Document> {
public class PostcoordinationEventWritingConverter implements Converter<PostCoordinationSpecificationEvent, Document> {
private final ObjectMapper objectMapper;

public PostcoordinationEventWritingConverter(ObjectMapper objectMapper) {
Expand All @@ -17,7 +17,7 @@ public PostcoordinationEventWritingConverter(ObjectMapper objectMapper) {


@Override
public Document convert(PostCoordinationEvent source) {
public Document convert(PostCoordinationSpecificationEvent source) {
return objectMapper.convertValue(source, Document.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package edu.stanford.protege.webprotege.postcoordinationservice.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import edu.stanford.protege.webprotege.common.Response;
import edu.stanford.protege.webprotege.postcoordinationservice.model.WhoficCustomScalesValues;

import static edu.stanford.protege.webprotege.postcoordinationservice.dto.GetEntityCustomScaleValuesRequest.CHANNEL;


@JsonTypeName(CHANNEL)
public record GetEntityCustomScaleValueResponse (@JsonProperty("entityIri")
String entityIri,
@JsonProperty("postCoordinationScaleValues")
WhoficCustomScalesValues postCoordinationScaleValues) implements Response {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package edu.stanford.protege.webprotege.postcoordinationservice.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import edu.stanford.protege.webprotege.common.ProjectId;
import edu.stanford.protege.webprotege.common.Request;

import static edu.stanford.protege.webprotege.postcoordinationservice.dto.GetEntityCustomScaleValuesRequest.CHANNEL;


@JsonTypeName(CHANNEL)
public record GetEntityCustomScaleValuesRequest(@JsonProperty("entityIRI") String entityIRI,
@JsonProperty("projectId") ProjectId projectId) implements Request<GetEntityCustomScaleValueResponse> {

public static final String CHANNEL = "webprotege.postcoordination.GetEntityScaleValues";

@Override
public String getChannel() {
return CHANNEL;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package edu.stanford.protege.webprotege.postcoordinationservice.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import edu.stanford.protege.webprotege.common.ProjectId;
import edu.stanford.protege.webprotege.common.Request;

import static edu.stanford.protege.webprotege.postcoordinationservice.dto.GetEntityPostCoordinationRequest.CHANNEL;

@JsonTypeName(CHANNEL)
public record GetEntityPostCoordinationRequest(@JsonProperty("entityIRI") String entityIRI,
@JsonProperty("projectId") ProjectId projectId) implements Request<GetEntityPostCoordinationResponse> {

public static final String CHANNEL = "webprotege.postcoordination.GetEntityPostCoordinations";

@Override
public String getChannel() {
return CHANNEL;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package edu.stanford.protege.webprotege.postcoordinationservice.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import edu.stanford.protege.webprotege.common.Response;
import edu.stanford.protege.webprotege.postcoordinationservice.model.WhoficEntityPostCoordinationSpecification;

import static edu.stanford.protege.webprotege.postcoordinationservice.dto.GetEntityPostCoordinationRequest.CHANNEL;

@JsonTypeName(CHANNEL)
public record GetEntityPostCoordinationResponse(@JsonProperty("entityIri")
String entityIri,
@JsonProperty("postCoordinationSpecification")
WhoficEntityPostCoordinationSpecification postCoordinationSpecification) implements Response {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package edu.stanford.protege.webprotege.postcoordinationservice.dto;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import edu.stanford.protege.webprotege.postcoordinationservice.events.EventProcessableParameter;

import java.util.List;

public class PostCoordinationCustomScalesRequest extends EventProcessableParameter {

private final List<String> postCoordinationScalesValues;
private final String postCoordinationAxis;


@JsonCreator
public PostCoordinationCustomScalesRequest(@JsonProperty("postcoordinationScaleValues") List<String> postCoordinationScalesValues,
@JsonProperty("postcoordinationAxis") String postCoordinationAxis) {
this.postCoordinationScalesValues = postCoordinationScalesValues;
this.postCoordinationAxis = postCoordinationAxis;
}

public List<String> getPostCoordinationScalesValues() {
return postCoordinationScalesValues;
}

public String getPostCoordinationAxis() {
return postCoordinationAxis;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
import java.util.ArrayList;
import java.util.List;

public class PostCoordinationSpecificationRequest extends EventProcessableParameter {
public class PostCoordinationSpecification extends EventProcessableParameter {

private final String linearizationView;


private final List<String> allowedAxes;

private final List<String> defaultAxes;
Expand All @@ -21,11 +20,11 @@ public class PostCoordinationSpecificationRequest extends EventProcessableParame
private final List<String> requiredAxes;

@JsonCreator
public PostCoordinationSpecificationRequest(@JsonProperty("linearizationView") String linearizationView,
@JsonProperty("allowedAxes") List<String> allowedAxes,
@JsonProperty("defaultAxes") List<String> defaultAxes,
@JsonProperty("notAllowedAxes") List<String> notAllowedAxes,
@JsonProperty("requiredAxes") List<String> requiredAxes) {
public PostCoordinationSpecification(@JsonProperty("linearizationView") String linearizationView,
@JsonProperty("allowedAxes") List<String> allowedAxes,
@JsonProperty("defaultAxes") List<String> defaultAxes,
@JsonProperty("notAllowedAxes") List<String> notAllowedAxes,
@JsonProperty("requiredAxes") List<String> requiredAxes) {
this.linearizationView = linearizationView;
this.allowedAxes = allowedAxes == null ? new ArrayList<>() : allowedAxes;
this.defaultAxes = defaultAxes == null ? new ArrayList<>() : defaultAxes;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package edu.stanford.protege.webprotege.postcoordinationservice.events;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import edu.stanford.protege.webprotege.postcoordinationservice.dto.PostCoordinationCustomScalesRequest;
import edu.stanford.protege.webprotege.postcoordinationservice.model.PostCoordinationCustomScalesRevision;
import edu.stanford.protege.webprotege.postcoordinationservice.model.WhoficCustomScalesValues;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

public class AddCustomScaleValueEvent extends PostCoordinationCustomScalesValueEvent {
public final static String TYPE = "AddCustomScaleValue";

@JsonCreator
public AddCustomScaleValueEvent(@JsonProperty("postCoordinationAxis") String postCoordinationAxis,@JsonProperty("postCoordinationScaleValue") String postCoordinationScaleValue) {
super(postCoordinationAxis, postCoordinationScaleValue);
}

@Override
String getType() {
return TYPE;
}

@Override
public void applyEvent(WhoficCustomScalesValues whoficCustomScalesValues) {
Optional<PostCoordinationCustomScalesRequest> existingRequest = whoficCustomScalesValues.scaleCustomizations().stream()
.filter(scale -> scale.getPostCoordinationAxis().equalsIgnoreCase(this.getPostCoordinationAxis()))
.findFirst();
if(existingRequest.isPresent()) {
existingRequest.get().getPostCoordinationScalesValues().add(this.getPostCoordinationScaleValue());
} else {
List<String> scaleValues = new ArrayList<>();
scaleValues.add(this.getPostCoordinationScaleValue());
PostCoordinationCustomScalesRequest request = new PostCoordinationCustomScalesRequest(scaleValues, this.getPostCoordinationAxis());
whoficCustomScalesValues.scaleCustomizations().add(request);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import edu.stanford.protege.webprotege.postcoordinationservice.dto.PostCoordinationSpecificationRequest;
import edu.stanford.protege.webprotege.postcoordinationservice.dto.PostCoordinationSpecification;

public class AddToAllowedAxisEvent extends PostCoordinationEvent {
public class AddToAllowedAxisEvent extends PostCoordinationSpecificationEvent {


public final static String TYPE = "AddToAllowedAxis";
Expand All @@ -21,8 +21,9 @@ String getType() {
}

@Override
PostCoordinationSpecificationRequest applySpecificEvent(PostCoordinationSpecificationRequest input) {
return null;
PostCoordinationSpecification applySpecificEvent(PostCoordinationSpecification input) {
input.getAllowedAxes().add(this.getPostCoordinationAxis());
return input;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import edu.stanford.protege.webprotege.postcoordinationservice.dto.PostCoordinationSpecificationRequest;
import edu.stanford.protege.webprotege.postcoordinationservice.dto.PostCoordinationSpecification;

public class AddToDefaultAxisEvent extends PostCoordinationEvent {
public class AddToDefaultAxisEvent extends PostCoordinationSpecificationEvent {

public final static String TYPE = "AddToDefaultAxis";

Expand All @@ -20,7 +20,8 @@ String getType() {
}

@Override
PostCoordinationSpecificationRequest applySpecificEvent(PostCoordinationSpecificationRequest input) {
return null;
PostCoordinationSpecification applySpecificEvent(PostCoordinationSpecification input) {
input.getDefaultAxes().add(this.getPostCoordinationAxis());
return input;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import edu.stanford.protege.webprotege.postcoordinationservice.dto.PostCoordinationSpecificationRequest;
import edu.stanford.protege.webprotege.postcoordinationservice.dto.PostCoordinationSpecification;

public class AddToNotAllowedAxisEvent extends PostCoordinationEvent {
public class AddToNotAllowedAxisEvent extends PostCoordinationSpecificationEvent {

public final static String TYPE = "AddToNotAllowedAxis";

Expand All @@ -20,8 +20,9 @@ String getType() {
}

@Override
PostCoordinationSpecificationRequest applySpecificEvent(PostCoordinationSpecificationRequest input) {
return null;
PostCoordinationSpecification applySpecificEvent(PostCoordinationSpecification input) {
input.getNotAllowedAxes().add(this.getPostCoordinationAxis());
return input;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import edu.stanford.protege.webprotege.postcoordinationservice.dto.PostCoordinationSpecificationRequest;
import edu.stanford.protege.webprotege.postcoordinationservice.dto.PostCoordinationSpecification;

public class AddToRequiredAxisEvent extends PostCoordinationEvent {
public class AddToRequiredAxisEvent extends PostCoordinationSpecificationEvent {

public final static String TYPE = "AddToRequiredAxis";

Expand All @@ -20,7 +20,8 @@ String getType() {
}

@Override
PostCoordinationSpecificationRequest applySpecificEvent(PostCoordinationSpecificationRequest input) {
return null;
PostCoordinationSpecification applySpecificEvent(PostCoordinationSpecification input) {
input.getRequiredAxes().add(this.getPostCoordinationAxis());
return input;
}
}
Loading
Loading