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

Fix migrate websocket #2

Merged
merged 4 commits into from
May 10, 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
29 changes: 18 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>
<groupId>edu.stanford.protege</groupId>
<artifactId>webprotege-event-history-service</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>
<name>webprotege-event-history-service</name>
<description>Service that contains business specific events in order to be queried</description>
<properties>
Expand Down Expand Up @@ -43,6 +43,18 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-messaging</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
</dependency>-->
<dependency>
<groupId>edu.stanford.protege</groupId>
<artifactId>webprotege-entity-frames</artifactId>
Expand All @@ -53,6 +65,11 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.12.4</version>
</dependency>
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-rabbit-test</artifactId>
Expand Down Expand Up @@ -115,16 +132,6 @@
<artifactId>rabbitmq</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-messaging</artifactId>
</dependency>


</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import org.bson.Document;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -28,23 +26,16 @@ public class HighLevelBusinessEventsService {

private final SequenceService sequenceService;

private final SimpMessagingTemplate simpMessagingTemplate;

public HighLevelBusinessEventsService(HighLevelBusinessEventsRepository repository, ObjectMapper objectMapper, SequenceService sequenceService, SimpMessagingTemplate simpMessagingTemplate) {
public HighLevelBusinessEventsService(HighLevelBusinessEventsRepository repository, ObjectMapper objectMapper, SequenceService sequenceService) {
this.repository = repository;
this.objectMapper = objectMapper;
this.sequenceService = sequenceService;
this.simpMessagingTemplate = simpMessagingTemplate;
}


@Transactional
void registerEvent(PackagedProjectChangeEvent projectEvent) {
sendEventsToWebsocket(projectEvent);
saveEventsIntoDatabase(projectEvent);
}

private void saveEventsIntoDatabase(PackagedProjectChangeEvent projectEvent) {
try {
var nextDocument = objectMapper.convertValue(projectEvent, Document.class);

Expand All @@ -56,17 +47,6 @@ private void saveEventsIntoDatabase(PackagedProjectChangeEvent projectEvent) {
}
}

private void sendEventsToWebsocket(PackagedProjectChangeEvent event) {
try {
ProjectEventsQueryResponse response = new ProjectEventsQueryResponse();
response.events = new EventList(EventTag.getFirst(), event.projectEvents(), EventTag.get(1));
simpMessagingTemplate.send("/topic/project-events/" + event.projectId().id(), new GenericMessage<>(objectMapper.writeValueAsBytes(response)));

} catch (Exception e) {
LOGGER.error("Error forwarding the events through websocket");
}
}

ProjectEventsQueryResponse fetchEvents(ProjectEventsQueryRequest request) {

ProjectEventsQueryResponse response = new ProjectEventsQueryResponse();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
package edu.stanford.protege.webprotegeeventshistory.dto;


import com.google.common.base.CaseFormat;
import edu.stanford.protege.webprotege.authorization.ActionId;

/**
* Matthew Horridge
* Stanford Center for Biomedical Informatics Research
* 5 Jan 2017
*/
public enum BuiltInAction {


CREATE_ACCOUNT,

CREATE_EMPTY_PROJECT,

UPLOAD_PROJECT,

VIEW_ANY_USER_DETAILS,

DELETE_ANY_ACCOUNT,

RESET_ANY_USER_PASSWORD,

MOVE_ANY_PROJECT_TO_TRASH,

SUBSTITUTE_USER,

EDIT_APPLICATION_SETTINGS,

REBUILD_PERMISSIONS,



VIEW_PROJECT,

VIEW_CHANGES,

WATCH_CHANGES,

DOWNLOAD_PROJECT,

REVERT_CHANGES,

EDIT_ONTOLOGY,

EDIT_ONTOLOGY_ANNOTATIONS,

CREATE_CLASS,

DELETE_CLASS,

CREATE_PROPERTY,

DELETE_PROPERTY,

CREATE_INDIVIDUAL,

DELETE_INDIVIDUAL,

CREATE_DATATYPE,

DELETE_DATATYPE,

MERGE_ENTITIES,

EDIT_ENTITY_TAGS,


CREATE_ISSUE,

CLOSE_OWN_ISSUE,

ASSIGN_OWN_ISSUE_TO_SELF,

ASSIGN_ANY_ISSUE_TO_ANYONE,

COMMENT_ON_ISSUE,

VIEW_ANY_ISSUE,

UPDATE_ANY_ISSUE_TITLE,

UPDATE_ANY_ISSUE_BODY,

CLOSE_ANY_ISSUE,


VIEW_OBJECT_COMMENT,

CREATE_OBJECT_COMMENT,

EDIT_OWN_OBJECT_COMMENT,

EDIT_ANY_OBJECT_COMMENT,

SET_OBJECT_COMMENT_STATUS,


ADD_OR_REMOVE_VIEW,

ADD_OR_REMOVE_PERSPECTIVE,

SAVE_DEFAULT_PROJECT_LAYOUT,

EDIT_PROJECT_SETTINGS,

EDIT_DEFAULT_VISUALIZATION_SETTINGS,

EDIT_SHARING_SETTINGS,

EDIT_NEW_ENTITY_SETTINGS,

EDIT_PROJECT_PREFIXES,

EDIT_PROJECT_TAGS,

UPLOAD_AND_MERGE,

UPLOAD_AND_MERGE_ADDITIONS,

EDIT_FORMS;




private final ActionId actionId;

BuiltInAction() {
this.actionId = new ActionId(CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name()));
}

public ActionId getActionId() {
return actionId;
}
}

2 changes: 2 additions & 0 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
server:
port: 7761

logging.level.root: DEBUG

spring:
application:
name: EventsHistoryService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void setUp(){
}

@Test
public void GIVEN_newEvent_WHEN_register_THEN_eventIsSavedInDb() throws InterruptedException, com.fasterxml.jackson.core.JsonProcessingException {
public void GIVEN_newEvent_WHEN_register_THEN_eventIsSavedInDb() throws InterruptedException {

var entityTagsChangedEvent = new EntityTagsChangedEvent(new EventId("eventId"),
projectId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ public class HighLevelBusinessEventsServiceTest {
@Mock
private SequenceService sequenceService;

@Mock
private SimpMessagingTemplate simpMessagingTemplate;

private HighLevelBusinessEventsService service;

private PackagedProjectChangeEvent packagedProjectChangeEvent;
Expand All @@ -56,12 +53,11 @@ public class HighLevelBusinessEventsServiceTest {
private ObjectMapper objectMapper;
private final ArgumentCaptor<HighLevelBusinessEvent> captor = ArgumentCaptor.forClass(HighLevelBusinessEvent.class);

private final ArgumentCaptor<GenericMessage> websocketCaptor = ArgumentCaptor.forClass(GenericMessage.class);

@Before
public void setUp() {
objectMapper = new ObjectMapperConfiguration().objectMapper();
service = new HighLevelBusinessEventsService(repository, objectMapper, sequenceService, simpMessagingTemplate);
service = new HighLevelBusinessEventsService(repository, objectMapper, sequenceService);
projectId = ProjectId.generate();
eventId = EventId.generate();
entityTagsChangedEvent = new EntityTagsChangedEvent(new EventId("eventId"),
Expand All @@ -87,23 +83,6 @@ public void GIVEN_entityTagsChangedEvent_WHEN_registerEvent_THEN_correctTagIsUse
assertEquals(projectId.id(), highLevelEvent.projectId());
}

@Test
public void GIVEN_entityTagsChangedEvent_WHEN_registerEvent_THEN_eventIsPushedToWebsocket() throws JsonProcessingException {
service.registerEvent(packagedProjectChangeEvent);


verify(simpMessagingTemplate).send(eq("/topic/project-events/" + projectId.id()), websocketCaptor.capture());

var capturedMessage = websocketCaptor.getValue();
ProjectEventsQueryResponse response = new ProjectEventsQueryResponse();
response.events = new EventList(EventTag.getFirst(), packagedProjectChangeEvent.projectEvents(), EventTag.get(1));

String expectedEvent = objectMapper.writeValueAsString(response);


assertEquals(objectMapper.readTree(expectedEvent), objectMapper.readTree(new String( (byte[]) capturedMessage.getPayload())));

}
@Test
public void GIVEN_entityTagsChangedEvent_WHEN_registerEvent_THEN_eventIsMapped() {
service.registerEvent(packagedProjectChangeEvent);
Expand Down
Loading