-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
saving project revisions . add revert mechanism on fail.
- Loading branch information
1 parent
d94acb3
commit b873b8e
Showing
10 changed files
with
191 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/main/java/edu/stanford/protege/webprotege/events/EntityUpdateFailedEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package edu.stanford.protege.webprotege.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; | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
src/main/java/edu/stanford/protege/webprotege/project/ApiEventUpdateFailedHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package edu.stanford.protege.webprotege.project; | ||
|
||
import edu.stanford.protege.webprotege.change.RevertRevisionAction; | ||
import edu.stanford.protege.webprotege.change.RevertRevisionActionHandler; | ||
import edu.stanford.protege.webprotege.events.EntityUpdateFailedEvent; | ||
import edu.stanford.protege.webprotege.ipc.EventHandler; | ||
import edu.stanford.protege.webprotege.ipc.ExecutionContext; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.List; | ||
|
||
|
||
|
||
@Component | ||
public class ApiEventUpdateFailedHandler implements EventHandler<EntityUpdateFailedEvent> { | ||
|
||
|
||
private final ProjectRevisionRepository projectRevisionRepository; | ||
|
||
private final ProjectCache projectCache; | ||
|
||
|
||
public ApiEventUpdateFailedHandler(ProjectRevisionRepository projectRevisionRepository, ProjectCache projectCache) { | ||
this.projectRevisionRepository = projectRevisionRepository; | ||
this.projectCache = projectCache; | ||
} | ||
|
||
|
||
@NotNull | ||
@Override | ||
public String getChannelName() { | ||
return EntityUpdateFailedEvent.CHANNEL; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public String getHandlerName() { | ||
return ApiEventUpdateFailedHandler.class.getName(); | ||
} | ||
|
||
@Override | ||
public Class<EntityUpdateFailedEvent> getEventClass() { | ||
return EntityUpdateFailedEvent.class; | ||
} | ||
|
||
@Override | ||
public void handleEvent(EntityUpdateFailedEvent event) { | ||
throw new RuntimeException("Method not supported"); | ||
} | ||
|
||
@Override | ||
public void handleEvent(EntityUpdateFailedEvent event, ExecutionContext executionContext) { | ||
List<ProjectRevision> revisions = projectRevisionRepository.findByChangeRequest(event.projectId(), event.changeRequestId()); | ||
RevertRevisionActionHandler revertRevisionActionHandler = (RevertRevisionActionHandler) | ||
projectCache.getActionHandlerRegistry(event.projectId()).getActionHandler(new RevertRevisionAction(null ,null,null)); | ||
for(ProjectRevision projectRevision : revisions) { | ||
revertRevisionActionHandler.execute(new RevertRevisionAction(projectRevision.changeRequestId(), projectRevision.projectId(), projectRevision.revisionNumber()), executionContext); | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/edu/stanford/protege/webprotege/project/ProjectRevision.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package edu.stanford.protege.webprotege.project; | ||
|
||
import edu.stanford.protege.webprotege.common.ChangeRequestId; | ||
import edu.stanford.protege.webprotege.common.ProjectId; | ||
import edu.stanford.protege.webprotege.common.UserId; | ||
import edu.stanford.protege.webprotege.revision.RevisionNumber; | ||
|
||
public record ProjectRevision(ProjectId projectId, ChangeRequestId changeRequestId, UserId userId, RevisionNumber revisionNumber) { | ||
|
||
} |
62 changes: 62 additions & 0 deletions
62
src/main/java/edu/stanford/protege/webprotege/project/ProjectRevisionRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package edu.stanford.protege.webprotege.project; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.mongodb.client.MongoCollection; | ||
import edu.stanford.protege.webprotege.common.ChangeRequestId; | ||
import edu.stanford.protege.webprotege.common.ProjectId; | ||
import edu.stanford.protege.webprotege.inject.ApplicationSingleton; | ||
import edu.stanford.protege.webprotege.persistence.Repository; | ||
import org.bson.Document; | ||
import org.springframework.data.mongodb.core.MongoTemplate; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.inject.Inject; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
|
||
|
||
@ApplicationSingleton | ||
public class ProjectRevisionRepository implements Repository { | ||
|
||
public static final String CHANGE_REQUEST_ID = "changeRequestId"; | ||
public static final String PROJECTS_REVISIONS = "ProjectsRevisions"; | ||
public static final String PROJECT_ID = "projectId"; | ||
|
||
private final MongoCollection<Document> collection; | ||
private final ObjectMapper objectMapper; | ||
|
||
@Inject | ||
public ProjectRevisionRepository(MongoTemplate mongoTemplate, ObjectMapper objectMapper) { | ||
|
||
this.collection = mongoTemplate.getCollection(PROJECTS_REVISIONS); | ||
|
||
this.objectMapper = objectMapper; | ||
} | ||
|
||
@Override | ||
public void ensureIndexes() { | ||
|
||
} | ||
|
||
public void save(@Nonnull ProjectRevision projectRevision) { | ||
var document = objectMapper.convertValue(projectRevision, Document.class); | ||
collection.insertOne(document); | ||
} | ||
|
||
private static Document withProjectId(@Nonnull ProjectId projectId) { | ||
return new Document(PROJECT_ID, projectId.id()); | ||
} | ||
|
||
public List<ProjectRevision> findByChangeRequest(ProjectId projectId, ChangeRequestId changeRequestId) { | ||
ArrayList<ProjectRevision> result = new ArrayList<>(); | ||
collection.find(withProjectIdAndWithChangeRequestId(projectId, changeRequestId)) | ||
.map(d -> objectMapper.convertValue(d, ProjectRevision.class)).into(result); | ||
return result; | ||
} | ||
|
||
private static Document withProjectIdAndWithChangeRequestId(@Nonnull ProjectId projectId, | ||
@Nonnull ChangeRequestId changeRequestId) { | ||
return new Document(PROJECT_ID, projectId.id()).append(CHANGE_REQUEST_ID, changeRequestId.id()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters