-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added GetChangedEntitiesCommandHandler. Added more tests to NewRevisi…
…onsEventServiceTest. Created GetChangedEntitiesCommandHandlerIT integration test.
- Loading branch information
Showing
9 changed files
with
271 additions
and
10 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
...va/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/dto/ChangedEntities.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,8 @@ | ||
package edu.stanford.protege.webprotegeeventshistory.uiHistoryConcern.dto; | ||
|
||
import java.util.List; | ||
|
||
public record ChangedEntities(List<String> createdEntities, | ||
List<String> updatedEntities, | ||
List<String> deletedEntities) { | ||
} |
37 changes: 37 additions & 0 deletions
37
...e/webprotegeeventshistory/uiHistoryConcern/handlers/GetChangedEntitiesCommandHandler.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,37 @@ | ||
package edu.stanford.protege.webprotegeeventshistory.uiHistoryConcern.handlers; | ||
|
||
import edu.stanford.protege.webprotege.ipc.*; | ||
import edu.stanford.protege.webprotegeeventshistory.uiHistoryConcern.services.NewRevisionsEventService; | ||
import org.springframework.stereotype.Component; | ||
import reactor.core.publisher.Mono; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
|
||
@Component | ||
public class GetChangedEntitiesCommandHandler implements CommandHandler<GetChangedEntitiesRequest, GetChangedEntitiesResponse> { | ||
|
||
private final NewRevisionsEventService service; | ||
|
||
public GetChangedEntitiesCommandHandler(NewRevisionsEventService service) { | ||
this.service = service; | ||
} | ||
|
||
|
||
@Nonnull | ||
@Override | ||
public String getChannelName() { | ||
return GetChangedEntitiesRequest.CHANNEL; | ||
} | ||
|
||
@Override | ||
public Class<GetChangedEntitiesRequest> getRequestClass() { | ||
return GetChangedEntitiesRequest.class; | ||
} | ||
|
||
@Override | ||
public Mono<GetChangedEntitiesResponse> handleRequest(GetChangedEntitiesRequest request, ExecutionContext executionContext) { | ||
var entityChanges = service.getChangedEntitiesAfterTimestamp(request.projectId(), request.timestamp()); | ||
return Mono.just(GetChangedEntitiesResponse.create(entityChanges)); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
.../protege/webprotegeeventshistory/uiHistoryConcern/handlers/GetChangedEntitiesRequest.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,25 @@ | ||
package edu.stanford.protege.webprotegeeventshistory.uiHistoryConcern.handlers; | ||
|
||
import com.fasterxml.jackson.annotation.*; | ||
import edu.stanford.protege.webprotege.common.*; | ||
|
||
import java.sql.Timestamp; | ||
|
||
@JsonTypeName(GetChangedEntitiesRequest.CHANNEL) | ||
public record GetChangedEntitiesRequest( | ||
@JsonProperty("projectId") ProjectId projectId, | ||
@JsonProperty("timestamp") Timestamp timestamp | ||
) implements Request<GetChangedEntitiesResponse> { | ||
|
||
public static final String CHANNEL = "webprotege.history.GetChangedEntities"; | ||
|
||
@Override | ||
public String getChannel() { | ||
return CHANNEL; | ||
} | ||
|
||
public static GetChangedEntitiesRequest create(ProjectId projectId, | ||
Timestamp timestamp) { | ||
return new GetChangedEntitiesRequest(projectId, timestamp); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...protege/webprotegeeventshistory/uiHistoryConcern/handlers/GetChangedEntitiesResponse.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,15 @@ | ||
package edu.stanford.protege.webprotegeeventshistory.uiHistoryConcern.handlers; | ||
|
||
import com.fasterxml.jackson.annotation.*; | ||
import edu.stanford.protege.webprotege.common.Response; | ||
import edu.stanford.protege.webprotegeeventshistory.uiHistoryConcern.dto.ChangedEntities; | ||
|
||
import static edu.stanford.protege.webprotegeeventshistory.uiHistoryConcern.handlers.GetChangedEntitiesRequest.CHANNEL; | ||
|
||
@JsonTypeName(CHANNEL) | ||
public record GetChangedEntitiesResponse( | ||
@JsonProperty("changedEntities") ChangedEntities changedEntities) implements Response { | ||
public static GetChangedEntitiesResponse create(ChangedEntities changedEntities) { | ||
return new GetChangedEntitiesResponse(changedEntities); | ||
} | ||
} |
8 changes: 6 additions & 2 deletions
8
...otege/webprotegeeventshistory/uiHistoryConcern/repositories/RevisionsEventRepository.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 |
---|---|---|
@@ -1,7 +1,11 @@ | ||
package edu.stanford.protege.webprotegeeventshistory.uiHistoryConcern.repositories; | ||
|
||
import edu.stanford.protege.webprotegeeventshistory.uiHistoryConcern.events.RevisionsEvent; | ||
import org.springframework.data.mongodb.repository.MongoRepository; | ||
import org.springframework.data.mongodb.repository.*; | ||
|
||
public interface RevisionsEventRepository extends MongoRepository<RevisionsEvent,String> { | ||
import java.util.List; | ||
|
||
public interface RevisionsEventRepository extends MongoRepository<RevisionsEvent, String> { | ||
@Query("{ 'projectId.id': ?0, 'timestamp': { $gt: ?1 } }") | ||
List<RevisionsEvent> findByProjectIdAndTimestampAfter(String projectId, long timestamp); | ||
} |
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
73 changes: 73 additions & 0 deletions
73
...webprotegeeventshistory/uiHistoryConcern/handlers/GetChangedEntitiesCommandHandlerIT.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,73 @@ | ||
package edu.stanford.protege.webprotegeeventshistory.uiHistoryConcern.handlers; | ||
|
||
import edu.stanford.protege.webprotege.common.ProjectId; | ||
import edu.stanford.protege.webprotegeeventshistory.*; | ||
import edu.stanford.protege.webprotegeeventshistory.uiHistoryConcern.dto.*; | ||
import edu.stanford.protege.webprotegeeventshistory.uiHistoryConcern.events.RevisionsEvent; | ||
import org.bson.Document; | ||
import org.junit.jupiter.api.*; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.data.mongodb.core.MongoTemplate; | ||
import org.springframework.test.annotation.DirtiesContext; | ||
import org.springframework.test.context.junit.jupiter.SpringExtension; | ||
import reactor.core.publisher.Mono; | ||
|
||
import java.sql.Timestamp; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
@SpringBootTest | ||
@ExtendWith({SpringExtension.class, RabbitTestExtension.class, MongoTestExtension.class}) | ||
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS) | ||
@Import({WebprotegeEventsHistoryApplication.class}) | ||
public class GetChangedEntitiesCommandHandlerIT { | ||
|
||
@Autowired | ||
private GetChangedEntitiesCommandHandler commandHandler; | ||
|
||
@Autowired | ||
private MongoTemplate mongoTemplate; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
mongoTemplate.dropCollection(RevisionsEvent.class); | ||
} | ||
|
||
@Test | ||
public void GIVEN_eventsAfterTimestamp_WHEN_handleRequestCalled_THEN_returnChangedEntities() { | ||
ProjectId projectId = ProjectId.generate(); | ||
Timestamp timestamp = new Timestamp(System.currentTimeMillis() - 10000); | ||
|
||
insertMockRevisionsEvent(projectId, "entity1", timestamp.getTime() - 5000, ChangeType.CREATE_ENTITY); | ||
insertMockRevisionsEvent(projectId, "entity2", timestamp.getTime() + 5000, ChangeType.UPDATE_ENTITY); | ||
insertMockRevisionsEvent(projectId, "entity3", timestamp.getTime() + 6000, ChangeType.DELETE_ENTITY); | ||
|
||
GetChangedEntitiesRequest request = GetChangedEntitiesRequest.create(projectId, timestamp); | ||
|
||
Mono<GetChangedEntitiesResponse> responseMono = commandHandler.handleRequest(request, null); | ||
GetChangedEntitiesResponse response = responseMono.block(); | ||
|
||
assertNotNull(response); | ||
ChangedEntities changedEntities = response.changedEntities(); | ||
assertEquals(0, changedEntities.createdEntities().size()); | ||
assertEquals(1, changedEntities.updatedEntities().size()); | ||
assertEquals(1, changedEntities.deletedEntities().size()); | ||
|
||
assertEquals("entity2", changedEntities.updatedEntities().get(0)); | ||
assertEquals("entity3", changedEntities.deletedEntities().get(0)); | ||
} | ||
|
||
private void insertMockRevisionsEvent(ProjectId projectId, String entityIri, long timestamp, ChangeType changeType) { | ||
RevisionsEvent revisionsEvent = RevisionsEvent.create( | ||
projectId, | ||
entityIri, | ||
changeType, | ||
timestamp, | ||
new Document() | ||
); | ||
mongoTemplate.save(revisionsEvent); | ||
} | ||
} |
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