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

Set entity from api adding transactionality #52

Merged
merged 8 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<dependency>
<groupId>edu.stanford.protege</groupId>
<artifactId>webprotege-ipc</artifactId>
<version>1.0.5</version>
<version>1.0.9</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
import edu.stanford.protege.webprotege.common.Response;
import edu.stanford.protege.webprotege.postcoordinationservice.model.WhoficCustomScalesValues;

import java.util.Date;

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


@JsonTypeName(CHANNEL)
public record GetEntityCustomScaleValueResponse(
@JsonProperty("lastRevisionDate") Date lastRevisionDate,
@JsonProperty("whoficCustomScaleValues") WhoficCustomScalesValues whoficCustomScalesValues
) implements Response {
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@
import edu.stanford.protege.webprotege.common.Response;
import edu.stanford.protege.webprotege.postcoordinationservice.model.WhoficEntityPostCoordinationSpecification;

import java.util.Date;

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

@JsonTypeName(CHANNEL)
public record GetEntityPostCoordinationResponse(@JsonProperty("entityIri")
String entityIri,

@JsonProperty("lastRevisionDate")
Date lastRevisionDate,

@JsonProperty("postCoordinationSpecification")
WhoficEntityPostCoordinationSpecification postCoordinationSpecification) implements Response {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package edu.stanford.protege.webprotege.postcoordinationservice.events;

import com.fasterxml.jackson.annotation.JsonProperty;
import edu.stanford.protege.webprotege.common.ChangeRequestId;
import edu.stanford.protege.webprotege.common.EventId;
import edu.stanford.protege.webprotege.common.ProjectEvent;
import edu.stanford.protege.webprotege.common.ProjectId;

import javax.annotation.Nonnull;

public record EntityUpdateFailedEvent(@JsonProperty("projectId") ProjectId projectId,
@JsonProperty("eventId") EventId eventId,

@JsonProperty("entityIri") String entityIri,
@JsonProperty("changeRequestId")ChangeRequestId changeRequestId) implements ProjectEvent {

public static String CHANNEL = "webprotege.api.EntityUpdateFailed";


@Nonnull
@Override
public ProjectId projectId() {
return projectId;
}

@Nonnull
@Override
public EventId eventId() {
return eventId;
}

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

import com.fasterxml.jackson.annotation.JsonProperty;
import edu.stanford.protege.webprotege.common.ChangeRequestId;
import edu.stanford.protege.webprotege.common.EventId;
import edu.stanford.protege.webprotege.common.ProjectEvent;
import edu.stanford.protege.webprotege.common.ProjectId;

import javax.annotation.Nonnull;

public record EntityUpdatedSuccessfullyEvent(@JsonProperty("projectId") ProjectId projectId,
@JsonProperty("eventId") EventId eventId,

@JsonProperty("entityIri") String entityIri,
@JsonProperty("changeRequestId") ChangeRequestId changeRequestId) implements ProjectEvent {

public static String CHANNEL = "webprotege.api.EntityUpdatedSuccessfully";


@Nonnull
@Override
public ProjectId projectId() {
return projectId;
}

@Nonnull
@Override
public EventId eventId() {
return eventId;
}

@Override
public String getChannel() {
return CHANNEL;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public Class<AddEntityCustomScalesRevisionRequest> getRequestClass() {
@Override
public Mono<AddEntityCustomScalesRevisionResponse> handleRequest(AddEntityCustomScalesRevisionRequest request, ExecutionContext executionContext) {

postCoordService.addCustomScaleRevision(request.entityCustomScaleValues(), request.projectId(), executionContext.userId());
postCoordService.addCustomScaleRevision(request.entityCustomScaleValues(), request.projectId(), executionContext.userId(), request.changeRequestId());

return Mono.just(new AddEntityCustomScalesRevisionResponse());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,26 @@
import edu.stanford.protege.webprotege.common.*;
import edu.stanford.protege.webprotege.postcoordinationservice.model.WhoficCustomScalesValues;

import javax.annotation.Nullable;

import static edu.stanford.protege.webprotege.postcoordinationservice.handlers.AddEntityCustomScalesRevisionRequest.CHANNEL;

@JsonTypeName(CHANNEL)
public record AddEntityCustomScalesRevisionRequest(@JsonProperty("projectId")
ProjectId projectId,
@JsonProperty("entityCustomScaleValues")
WhoficCustomScalesValues entityCustomScaleValues) implements Request<AddEntityCustomScalesRevisionResponse> {
WhoficCustomScalesValues entityCustomScaleValues,
@JsonProperty("changeRequestId") @Nullable ChangeRequestId changeRequestId) implements Request<AddEntityCustomScalesRevisionResponse> {

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

@JsonCreator
public static AddEntityCustomScalesRevisionRequest create(@JsonProperty("projectId")
ProjectId projectId,
@JsonProperty("entityCustomScaleValues")
WhoficCustomScalesValues entityCustomScaleValues) {
return new AddEntityCustomScalesRevisionRequest(projectId, entityCustomScaleValues);
WhoficCustomScalesValues entityCustomScaleValues,
@JsonProperty("changeRequestId") @Nullable ChangeRequestId changeRequestId) {
return new AddEntityCustomScalesRevisionRequest(projectId, entityCustomScaleValues, changeRequestId);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public Class<AddEntitySpecificationRevisionRequest> getRequestClass() {

@Override
public Mono<AddEntitySpecificationRevisionResponse> handleRequest(AddEntitySpecificationRevisionRequest request, ExecutionContext executionContext) {
postCoordService.addSpecificationRevision(request.entitySpecification(), executionContext.userId(), request.projectId());
postCoordService.addSpecificationRevision(request.entitySpecification(), executionContext.userId(), request.projectId(), request.changeRequestId());
return Mono.just(new AddEntitySpecificationRevisionResponse());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@

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

import javax.annotation.Nullable;

import static edu.stanford.protege.webprotege.postcoordinationservice.handlers.AddEntitySpecificationRevisionRequest.CHANNEL;

@JsonTypeName(CHANNEL)
public record AddEntitySpecificationRevisionRequest(@JsonProperty("projectId")
ProjectId projectId,
@JsonProperty("entitySpecification")
WhoficEntityPostCoordinationSpecification entitySpecification) implements Request<AddEntitySpecificationRevisionResponse> {
WhoficEntityPostCoordinationSpecification entitySpecification,
@JsonProperty("changeRequestId") @Nullable ChangeRequestId changeRequestId) implements Request<AddEntitySpecificationRevisionResponse> {

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package edu.stanford.protege.webprotege.postcoordinationservice.handlers;


import edu.stanford.protege.webprotege.ipc.EventHandler;
import edu.stanford.protege.webprotege.postcoordinationservice.events.EntityUpdatedSuccessfullyEvent;
import edu.stanford.protege.webprotege.postcoordinationservice.services.RevisionCommitService;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Component;

@Component
public class EntityUpdatedSuccessfullyHandler implements EventHandler<EntityUpdatedSuccessfullyEvent> {


private final RevisionCommitService revisionCommitService;

public EntityUpdatedSuccessfullyHandler(RevisionCommitService revisionCommitService) {
this.revisionCommitService = revisionCommitService;
}

@NotNull
@Override
public String getChannelName() {
return EntityUpdatedSuccessfullyEvent.CHANNEL;
}

@NotNull
@Override
public String getHandlerName() {
return this.getClass().getName();
}

@Override
public Class<EntityUpdatedSuccessfullyEvent> getEventClass() {
return EntityUpdatedSuccessfullyEvent.class;
}

@Override
public void handleEvent(EntityUpdatedSuccessfullyEvent event) {
revisionCommitService.commitRevision(event.changeRequestId(), event.projectId(), event.entityIri());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package edu.stanford.protege.webprotege.postcoordinationservice.handlers;


import edu.stanford.protege.webprotege.ipc.EventHandler;
import edu.stanford.protege.webprotege.postcoordinationservice.events.EntityUpdateFailedEvent;
import edu.stanford.protege.webprotege.postcoordinationservice.services.RevisionCommitService;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Component;

@Component
public class EventUpdateFailedHandler implements EventHandler<EntityUpdateFailedEvent> {

private final RevisionCommitService revisionCommitService;

public EventUpdateFailedHandler(RevisionCommitService revisionCommitService) {
this.revisionCommitService = revisionCommitService;
}

@NotNull
@Override
public String getChannelName() {
return EntityUpdateFailedEvent.CHANNEL;
}

@NotNull
@Override
public String getHandlerName() {
return EventUpdateFailedHandler.class.getName();
}

@Override
public Class<EntityUpdateFailedEvent> getEventClass() {
return EntityUpdateFailedEvent.class;
}

@Override
public void handleEvent(EntityUpdateFailedEvent event) {
revisionCommitService.rollbackRevision(event.changeRequestId(), event.projectId(), event.entityIri());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public Class<GetEntityCustomScaleValuesRequest> getRequestClass() {

@Override
public Mono<GetEntityCustomScaleValueResponse> handleRequest(GetEntityCustomScaleValuesRequest request, ExecutionContext executionContext) {
WhoficCustomScalesValues processedScales = postCoordService.fetchCustomScalesHistory(request.entityIRI(), request.projectId());
GetEntityCustomScaleValueResponse response = postCoordService.fetchCustomScalesHistory(request.entityIRI(), request.projectId());

return Mono.just(new GetEntityCustomScaleValueResponse(processedScales));
return Mono.just(response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public Class<GetEntityPostCoordinationRequest> getRequestClass() {
@Override
public Mono<GetEntityPostCoordinationResponse> handleRequest(GetEntityPostCoordinationRequest request, ExecutionContext executionContext) {

WhoficEntityPostCoordinationSpecification processedSpec = postCoordService.fetchHistory(request.entityIRI(), request.projectId());
GetEntityPostCoordinationResponse processedSpec = postCoordService.fetchHistory(request.entityIRI(), request.projectId());

return Mono.just(new GetEntityPostCoordinationResponse(request.entityIRI(), processedSpec));
return Mono.just(processedSpec);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package edu.stanford.protege.webprotege.postcoordinationservice.model;

public enum CommitStatus {
COMMITTED,
UNCOMMITTED;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package edu.stanford.protege.webprotege.postcoordinationservice.model;

import com.google.common.base.Objects;
import edu.stanford.protege.webprotege.common.ChangeRequestId;
import edu.stanford.protege.webprotege.common.UserId;
import edu.stanford.protege.webprotege.postcoordinationservice.events.PostCoordinationCustomScalesValueEvent;
import org.jetbrains.annotations.NotNull;
Expand All @@ -11,11 +12,22 @@

public record PostCoordinationCustomScalesRevision(UserId userId,
@Indexed(name = "rev_timestamp", direction = IndexDirection.DESCENDING) Long timestamp,
Set<PostCoordinationCustomScalesValueEvent> postCoordinationEvents) implements Comparable<PostCoordinationCustomScalesRevision> {
Set<PostCoordinationCustomScalesValueEvent> postCoordinationEvents,
CommitStatus commitStatus,
ChangeRequestId changeRequestId) implements Comparable<PostCoordinationCustomScalesRevision> {


public static PostCoordinationCustomScalesRevision create(UserId userId, Set<PostCoordinationCustomScalesValueEvent> postCoordinationEventList) {
return new PostCoordinationCustomScalesRevision(userId, Instant.now().toEpochMilli(), postCoordinationEventList);
return create(userId, postCoordinationEventList, null);
}

public static PostCoordinationCustomScalesRevision create(UserId userId, Set<PostCoordinationCustomScalesValueEvent> postCoordinationEventList, ChangeRequestId changeRequestId) {
CommitStatus status = changeRequestId != null && changeRequestId.id() != null ? CommitStatus.UNCOMMITTED : CommitStatus.COMMITTED;
return new PostCoordinationCustomScalesRevision(userId, Instant.now().toEpochMilli(), postCoordinationEventList, status, changeRequestId);
}

public static PostCoordinationCustomScalesRevision createCommittedClone(PostCoordinationCustomScalesRevision revision) {
return new PostCoordinationCustomScalesRevision(revision.userId(), revision.timestamp(), revision.postCoordinationEvents(), CommitStatus.COMMITTED, revision.changeRequestId());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import com.google.common.base.Objects;
import edu.stanford.protege.webprotege.common.ChangeRequestId;
import edu.stanford.protege.webprotege.common.UserId;
import org.jetbrains.annotations.NotNull;
import org.springframework.data.mongodb.core.index.*;
Expand All @@ -11,11 +12,21 @@

public record PostCoordinationSpecificationRevision(UserId userId,
@Indexed(name = "spec_timestamp", direction = IndexDirection.DESCENDING) Long timestamp,
Set<PostCoordinationViewEvent> postCoordinationEvents) implements Comparable<PostCoordinationSpecificationRevision>{
Set<PostCoordinationViewEvent> postCoordinationEvents,
CommitStatus commitStatus,
ChangeRequestId changeRequestId) implements Comparable<PostCoordinationSpecificationRevision>{


public static PostCoordinationSpecificationRevision create(UserId userId, Set<PostCoordinationViewEvent> postCoordinationEventList) {
return new PostCoordinationSpecificationRevision(userId, Instant.now().toEpochMilli(), postCoordinationEventList);
return create(userId, postCoordinationEventList, null);
}
public static PostCoordinationSpecificationRevision create(UserId userId, Set<PostCoordinationViewEvent> postCoordinationEventList, ChangeRequestId changeRequestId) {
CommitStatus status = changeRequestId != null && changeRequestId.id() != null ? CommitStatus.UNCOMMITTED : CommitStatus.COMMITTED;
return new PostCoordinationSpecificationRevision(userId, Instant.now().toEpochMilli(), postCoordinationEventList, status, changeRequestId);
}

public static PostCoordinationSpecificationRevision createCommittedClone(PostCoordinationSpecificationRevision revision) {
return new PostCoordinationSpecificationRevision(revision.userId, revision.timestamp, revision.postCoordinationEvents, CommitStatus.COMMITTED, revision.changeRequestId);
}

@Override
Expand Down
Loading
Loading