Skip to content

Commit

Permalink
Added ChangeType to ProjectChangeForEntity and RevisionsEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
soimugeo committed Nov 11, 2024
1 parent 2bb6604 commit f38f7c9
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package edu.stanford.protege.webprotegeeventshistory.uiHistoryConcern.dto;

public enum ChangeType {
CREATE_ENTITY,
DELETE_ENTITY,
UPDATE_ENTITY
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,28 @@

import edu.stanford.protege.webprotege.change.ProjectChange;

import javax.annotation.Nonnull;

public record ProjectChangeForEntity(String whoficEntityIri,
ProjectChange projectChange) {
ChangeType changeType,
ProjectChange projectChange) implements Comparable<ProjectChangeForEntity> {

public static ProjectChangeForEntity create(String whoficEntityIri,
ChangeType changeType,
ProjectChange projectChange) {
return new ProjectChangeForEntity(whoficEntityIri, changeType, projectChange);
}

//All linearization/postcoordination changes are updates made on the whoficEntityIri.
// From this microservice we don't create or delete entities. that is the responsibility of the backend-service.
public static ProjectChangeForEntity create(String whoficEntityIri,
ProjectChange projectChange) {
return new ProjectChangeForEntity(whoficEntityIri, projectChange);
return new ProjectChangeForEntity(whoficEntityIri, ChangeType.UPDATE_ENTITY, projectChange);
}

@Override
public int compareTo(@Nonnull ProjectChangeForEntity other) {
return Long.compare(this.projectChange.getTimestamp(), other.projectChange.getTimestamp());

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

import com.google.common.base.Objects;
import edu.stanford.protege.webprotege.common.ProjectId;
import edu.stanford.protege.webprotegeeventshistory.uiHistoryConcern.dto.ChangeType;
import org.springframework.data.mongodb.core.index.*;
import org.springframework.data.mongodb.core.mapping.Document;

@Document(collection = "RevisionsEvents")
public record RevisionsEvent(
ProjectId projectId,
String whoficEntityIri,
ChangeType changeType,
@Indexed(name = "timestamp", direction = IndexDirection.DESCENDING) long timestamp,
org.bson.Document projectChange
) {

public static final String WHOFIC_ENTITY_IRI = "whoficEntityIri";
public static final String PROJECT_ID = "projectId";
public static final String TIMESTAMP = "timestamp";
public static final String CHANGE_TYPE = "changeType";
public static final String PROJECT_CHANGE = "projectChange";

public static RevisionsEvent create(ProjectId projectId,
String whoficEntityIri,
ChangeType changeType,
long timestamp,
org.bson.Document projectChange) {
return new RevisionsEvent(projectId, whoficEntityIri, timestamp, projectChange);
return new RevisionsEvent(projectId, whoficEntityIri, changeType, timestamp, projectChange);
}

@Override
Expand All @@ -33,11 +37,12 @@ public boolean equals(Object o) {
return timestamp == that.timestamp &&
Objects.equal(projectId, that.projectId) &&
Objects.equal(whoficEntityIri, that.whoficEntityIri) &&
Objects.equal(changeType, that.changeType) &&
Objects.equal(projectChange, that.projectChange);
}

@Override
public int hashCode() {
return Objects.hashCode(projectId, whoficEntityIri, timestamp, projectChange);
return Objects.hashCode(projectId, whoficEntityIri, changeType, timestamp, projectChange);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import edu.stanford.protege.webprotege.change.ProjectChange;
import edu.stanford.protege.webprotegeeventshistory.uiHistoryConcern.dto.ChangeType;
import edu.stanford.protege.webprotegeeventshistory.uiHistoryConcern.events.*;
import org.bson.Document;
import org.springframework.stereotype.Component;
Expand All @@ -23,11 +24,12 @@ public List<RevisionsEvent> mapNewRevisionsEventToRevisionsEvents(NewRevisionsEv
List<RevisionsEvent> revisionsEvents = newRevisionsEvent.changes().stream()
.flatMap(projectChangeForEntity -> {
String whoficIri = projectChangeForEntity.whoficEntityIri();
ChangeType changeType = projectChangeForEntity.changeType();
ProjectChange projectChange = projectChangeForEntity.projectChange();
long timestamp = projectChange.getTimestamp();
var projectChangeDocument = objectMapper.convertValue(projectChange, Document.class);

return Stream.of(RevisionsEvent.create(newRevisionsEvent.projectId(), whoficIri, timestamp, projectChangeDocument));
return Stream.of(RevisionsEvent.create(newRevisionsEvent.projectId(), whoficIri, changeType, timestamp, projectChangeDocument));
})
.toList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import edu.stanford.protege.webprotege.change.ProjectChange;
import edu.stanford.protege.webprotege.common.Page;
import edu.stanford.protege.webprotege.common.*;
import edu.stanford.protege.webprotegeeventshistory.config.events.UpdateUiHistoryEvent;
import edu.stanford.protege.webprotegeeventshistory.uiHistoryConcern.events.*;
import edu.stanford.protege.webprotegeeventshistory.uiHistoryConcern.mappers.*;
import edu.stanford.protege.webprotegeeventshistory.uiHistoryConcern.repositories.RevisionsEventRepository;
Expand Down Expand Up @@ -45,13 +44,15 @@ public Page<ProjectChange> fetchPaginatedProjectChanges(ProjectId projectId, Opt
RevisionsEvent probe = new RevisionsEvent(
projectId,
entityIriSubject,
null,
0,
null
);
ExampleMatcher matcher = ExampleMatcher.matching()
.withMatcher(PROJECT_ID, ExampleMatcher.GenericPropertyMatchers.exact())
.withIgnorePaths(TIMESTAMP)
.withMatcher(WHOFIC_ENTITY_IRI, ExampleMatcher.GenericPropertyMatchers.exact())
.withIgnorePaths(CHANGE_TYPE)
.withIgnoreNullValues();

Example<RevisionsEvent> example = Example.of(probe, matcher);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import edu.stanford.protege.webprotege.common.*;
import edu.stanford.protege.webprotege.revision.RevisionNumber;
import edu.stanford.protege.webprotegeeventshistory.*;
import edu.stanford.protege.webprotegeeventshistory.uiHistoryConcern.dto.ChangeType;
import edu.stanford.protege.webprotegeeventshistory.uiHistoryConcern.events.RevisionsEvent;
import org.bson.Document;
import org.junit.jupiter.api.*;
Expand Down Expand Up @@ -132,7 +133,7 @@ private OWLEntity mockOWLEntity(String iri) {
private ProjectChange insertMockRevisionsEvent(ProjectId projectId, String whoficEntityIri, long timestamp) {
ProjectChange projectChange = ProjectChange.get(RevisionNumber.getRevisionNumber(1), UserId.valueOf("user1"), timestamp, "Description1", 0, Page.emptyPage());
org.bson.Document projectChangeDocument = objectMapper.convertValue(projectChange, Document.class);
RevisionsEvent revisionsEvent = RevisionsEvent.create(projectId, whoficEntityIri, timestamp, projectChangeDocument);
RevisionsEvent revisionsEvent = RevisionsEvent.create(projectId, whoficEntityIri, ChangeType.UPDATE_ENTITY, timestamp, projectChangeDocument);
mongoTemplate.save(revisionsEvent);

return projectChange;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import edu.stanford.protege.webprotege.change.ProjectChange;
import edu.stanford.protege.webprotege.common.Page;
import edu.stanford.protege.webprotege.common.*;
import edu.stanford.protege.webprotegeeventshistory.uiHistoryConcern.dto.ProjectChangeForEntity;
import edu.stanford.protege.webprotegeeventshistory.uiHistoryConcern.dto.*;
import edu.stanford.protege.webprotegeeventshistory.uiHistoryConcern.events.*;
import edu.stanford.protege.webprotegeeventshistory.uiHistoryConcern.mappers.*;
import edu.stanford.protege.webprotegeeventshistory.uiHistoryConcern.repositories.RevisionsEventRepository;
Expand Down Expand Up @@ -43,7 +43,7 @@ public void GIVEN_validNewLinearizationRevisionsEvent_WHEN_registerEventCalled_T
Set<ProjectChangeForEntity> changes = Set.of(mock(ProjectChangeForEntity.class));
NewRevisionsEvent event = NewRevisionsEvent.create(EventId.generate(), projectId, changes);

RevisionsEvent mockRevisionsEvent = RevisionsEvent.create(projectId, "whoficEntityIri", 12345L, new Document());
RevisionsEvent mockRevisionsEvent = RevisionsEvent.create(projectId, "whoficEntityIri", ChangeType.UPDATE_ENTITY, 12345L, new Document());
when(revisionEventMapper.mapNewRevisionsEventToRevisionsEvents(event))
.thenReturn(List.of(mockRevisionsEvent));

Expand All @@ -60,7 +60,7 @@ public void GIVEN_validProjectIdAndSubject_WHEN_fetchPaginatedProjectChangesCall
IRI mockIri = IRI.create("http://example.com/entity");
when(mockEntity.getIRI()).thenReturn(mockIri);

RevisionsEvent mockRevisionsEvent = RevisionsEvent.create(projectId, mockIri.toString(), 12345L, new Document());
RevisionsEvent mockRevisionsEvent = RevisionsEvent.create(projectId, mockIri.toString(), ChangeType.UPDATE_ENTITY,12345L, new Document());
PageRequest pageRequest = PageRequest.of(0, 1, Sort.by(Sort.Direction.DESC, "timestamp"));
org.springframework.data.domain.Page<RevisionsEvent> mockPage = new PageImpl<>(List.of(mockRevisionsEvent), pageRequest, 1);

Expand All @@ -83,7 +83,7 @@ public void GIVEN_validProjectIdAndSubject_WHEN_fetchPaginatedProjectChangesCall
public void GIVEN_nullSubject_WHEN_fetchPaginatedProjectChangesCalled_THEN_returnPaginatedProjectChanges() {
ProjectId projectId = new ProjectId("testProjectId");

RevisionsEvent mockRevisionsEvent = RevisionsEvent.create(projectId, null, 12345L, new Document());
RevisionsEvent mockRevisionsEvent = RevisionsEvent.create(projectId, null, ChangeType.CREATE_ENTITY,12345L, new Document());
PageRequest pageRequest = PageRequest.of(0, 1, Sort.by(Sort.Direction.DESC, "timestamp"));
org.springframework.data.domain.Page<RevisionsEvent> mockPage = new PageImpl<>(List.of(mockRevisionsEvent), pageRequest, 1);

Expand Down

0 comments on commit f38f7c9

Please sign in to comment.