diff --git a/pom.xml b/pom.xml
index 48b199f..74a48b9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
edu.stanford.protege
webprotege-event-history-service
- 2.0.5-WHO
+ 2.0.6-WHO
webprotege-event-history-service
Service that contains business specific events in order to be queried
@@ -97,7 +97,7 @@
edu.stanford.protege
webprotege-ipc
- 1.0.5
+ 1.0.10
org.keycloak
diff --git a/src/main/java/edu/stanford/protege/webprotegeeventshistory/config/MongoConfiguration.java b/src/main/java/edu/stanford/protege/webprotegeeventshistory/config/MongoConfiguration.java
index 10a2ad9..938df07 100644
--- a/src/main/java/edu/stanford/protege/webprotegeeventshistory/config/MongoConfiguration.java
+++ b/src/main/java/edu/stanford/protege/webprotegeeventshistory/config/MongoConfiguration.java
@@ -1,10 +1,48 @@
package edu.stanford.protege.webprotegeeventshistory.config;
+import com.mongodb.*;
+import edu.stanford.protege.webprotegeeventshistory.config.converters.*;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
+import org.springframework.data.mongodb.config.AbstractMongoClientConfiguration;
+import org.springframework.data.mongodb.core.convert.MongoCustomConversions;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
+import javax.annotation.Nonnull;
+import java.util.Arrays;
+
@Configuration
@EnableMongoRepositories(basePackages = "edu.stanford.protege.webprotegeeventshistory")
-public class MongoConfiguration {
+public class MongoConfiguration extends AbstractMongoClientConfiguration {
+
+ @Value("${spring.data.mongodb.database}")
+ private String databaseName;
+
+ @Value("${spring.data.mongodb.uri}")
+ private String mongoUri;
+
+ @Nonnull
+ @Override
+ protected String getDatabaseName() {
+ return databaseName;
+ }
+
+ @Nonnull
+ @Override
+ public MongoClientSettings mongoClientSettings() {
+ return MongoClientSettings.builder()
+ .applyConnectionString(new ConnectionString(mongoUri))
+ .build();
+ }
+
+ @Nonnull
+ @Override
+ public MongoCustomConversions customConversions() {
+ return new MongoCustomConversions(Arrays.asList(
+ new ProjectIdToStringConverter(),
+ new StringToProjectIdConverter()
+ ));
+ }
}
+
diff --git a/src/main/java/edu/stanford/protege/webprotegeeventshistory/config/converters/ProjectIdToStringConverter.java b/src/main/java/edu/stanford/protege/webprotegeeventshistory/config/converters/ProjectIdToStringConverter.java
new file mode 100644
index 0000000..ef087e0
--- /dev/null
+++ b/src/main/java/edu/stanford/protege/webprotegeeventshistory/config/converters/ProjectIdToStringConverter.java
@@ -0,0 +1,14 @@
+package edu.stanford.protege.webprotegeeventshistory.config.converters;
+
+import edu.stanford.protege.webprotege.common.ProjectId;
+import org.springframework.core.convert.converter.Converter;
+import org.springframework.data.convert.WritingConverter;
+
+@WritingConverter
+public class ProjectIdToStringConverter implements Converter {
+ @Override
+ public String convert(ProjectId projectId) {
+ return projectId.id();
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/java/edu/stanford/protege/webprotegeeventshistory/config/converters/StringToProjectIdConverter.java b/src/main/java/edu/stanford/protege/webprotegeeventshistory/config/converters/StringToProjectIdConverter.java
new file mode 100644
index 0000000..0d5341a
--- /dev/null
+++ b/src/main/java/edu/stanford/protege/webprotegeeventshistory/config/converters/StringToProjectIdConverter.java
@@ -0,0 +1,15 @@
+package edu.stanford.protege.webprotegeeventshistory.config.converters;
+
+import edu.stanford.protege.webprotege.common.ProjectId;
+import org.springframework.core.convert.converter.Converter;
+import org.springframework.data.convert.ReadingConverter;
+
+import javax.annotation.Nonnull;
+
+@ReadingConverter
+public class StringToProjectIdConverter implements Converter {
+ @Override
+ public ProjectId convert(@Nonnull String source) {
+ return ProjectId.valueOf(source);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/events/RevisionsEvent.java b/src/main/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/events/RevisionsEvent.java
index 42dc1c8..5555436 100644
--- a/src/main/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/events/RevisionsEvent.java
+++ b/src/main/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/events/RevisionsEvent.java
@@ -5,14 +5,12 @@
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;
+import org.springframework.data.mongodb.core.mapping.*;
@Document(collection = "RevisionsEvents")
public record RevisionsEvent(
-
@Indexed(name = "revisionEventProjectId")
- ProjectId projectId,
-
+ @Field("projectId") String projectId,
@Indexed(name = "revisionEventEntityIri")
String whoficEntityIri,
ChangeType changeType,
@@ -34,7 +32,7 @@ public static RevisionsEvent create(ProjectId projectId,
long timestamp,
org.bson.Document projectChange,
ChangeRequestId changeRequestId) {
- return new RevisionsEvent(projectId, whoficEntityIri, changeType, timestamp, changeRequestId != null ? changeRequestId.id() : null, projectChange);
+ return new RevisionsEvent(projectId.id(), whoficEntityIri, changeType, timestamp, changeRequestId != null ? changeRequestId.id() : null, projectChange);
}
@Override
diff --git a/src/main/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/repositories/RevisionsEventRepository.java b/src/main/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/repositories/RevisionsEventRepository.java
index 6f80cbc..88dea86 100644
--- a/src/main/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/repositories/RevisionsEventRepository.java
+++ b/src/main/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/repositories/RevisionsEventRepository.java
@@ -8,7 +8,7 @@
import java.util.List;
public interface RevisionsEventRepository extends MongoRepository {
- @Query("{ 'projectId.id': ?0, 'timestamp': { $gt: ?1 } }")
+ @Query("{ 'projectId': ?0, 'timestamp': { $gt: ?1 } }")
List findByProjectIdAndTimestampAfter(String projectId, long timestamp);
List findByProjectIdAndWhoficEntityIriOrderByTimestampDesc(ProjectId projectId, String whoficEntityIri);
diff --git a/src/main/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/services/NewRevisionsEventServiceImpl.java b/src/main/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/services/NewRevisionsEventServiceImpl.java
index 769f8ed..d4ac8ab 100644
--- a/src/main/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/services/NewRevisionsEventServiceImpl.java
+++ b/src/main/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/services/NewRevisionsEventServiceImpl.java
@@ -45,7 +45,7 @@ public void registerEvent(NewRevisionsEvent newRevEvent) {
@Override
public Page fetchPaginatedProjectChanges(ProjectId projectId, Optional subject, int pageNumber, int pageSize) {
String entityIriSubject = subject.map(sub -> sub.getIRI().toString()).orElse(null);
- RevisionsEvent probe = new RevisionsEvent(
+ RevisionsEvent probe = RevisionsEvent.create(
projectId,
entityIriSubject,
null,
diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml
index 5d0edb7..a898914 100644
--- a/src/main/resources/application.yaml
+++ b/src/main/resources/application.yaml
@@ -13,8 +13,10 @@ spring:
password: guest
data.mongodb:
host: mongo
+ port: 27017
database: webprotege
auto-index-creation: true
+ uri: mongodb://${spring.data.mongodb.host}:${spring.data.mongodb.port}/${spring.data.mongodb.database}
webprotege:
rabbitmq:
diff --git a/src/test/java/edu/stanford/protege/webprotegeeventshistory/HighLevelBusinessEventsIntegrationTest.java b/src/test/java/edu/stanford/protege/webprotegeeventshistory/HighLevelBusinessEventsIntegrationTest.java
index 2ce8364..b416324 100644
--- a/src/test/java/edu/stanford/protege/webprotegeeventshistory/HighLevelBusinessEventsIntegrationTest.java
+++ b/src/test/java/edu/stanford/protege/webprotegeeventshistory/HighLevelBusinessEventsIntegrationTest.java
@@ -19,6 +19,7 @@
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.messaging.simp.SimpMessagingTemplate;
+import org.springframework.test.context.ActiveProfiles;
import uk.ac.manchester.cs.owl.owlapi.OWLClassImpl;
import java.util.ArrayList;
@@ -28,7 +29,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-
+@ActiveProfiles("test")
public class HighLevelBusinessEventsIntegrationTest extends IntegrationTest {
@Autowired
diff --git a/src/test/java/edu/stanford/protege/webprotegeeventshistory/IntegrationTest.java b/src/test/java/edu/stanford/protege/webprotegeeventshistory/IntegrationTest.java
index 04e8427..e6b4c6e 100644
--- a/src/test/java/edu/stanford/protege/webprotegeeventshistory/IntegrationTest.java
+++ b/src/test/java/edu/stanford/protege/webprotegeeventshistory/IntegrationTest.java
@@ -40,12 +40,14 @@ public static void closeContainers(){
private static void setUpMongo(){
var imageName = DockerImageName.parse("mongo");
mongoDBContainer = new MongoDBContainer(imageName)
- .withExposedPorts(27017, 27017);
+ .withExposedPorts(27017);
mongoDBContainer.start();
- var mappedHttpPort = mongoDBContainer.getMappedPort(27017);
- LOGGER.info("MongoDB port 27017 is mapped to {}", mappedHttpPort);
- System.setProperty("spring.data.mongodb.port", Integer.toString(mappedHttpPort));
+ var mappedPort = mongoDBContainer.getMappedPort(27017);
+ var mongoUri = String.format("mongodb://localhost:%d", mappedPort);
+
+ System.setProperty("spring.data.mongodb.uri", mongoUri);
+ System.setProperty("spring.data.mongodb.port", Integer.toString(mappedPort));
}
private static void setUpRabbitMq(){
diff --git a/src/test/java/edu/stanford/protege/webprotegeeventshistory/MongoTestExtension.java b/src/test/java/edu/stanford/protege/webprotegeeventshistory/MongoTestExtension.java
index da3e789..c0aa89c 100644
--- a/src/test/java/edu/stanford/protege/webprotegeeventshistory/MongoTestExtension.java
+++ b/src/test/java/edu/stanford/protege/webprotegeeventshistory/MongoTestExtension.java
@@ -8,22 +8,27 @@
public class MongoTestExtension implements BeforeAllCallback, AfterAllCallback {
- private static MongoDBContainer mongoDBContainer;
+ private static MongoDBContainer mongoDBContainer;
@Override
public void beforeAll(ExtensionContext extensionContext) {
var imageName = DockerImageName.parse("mongo");
mongoDBContainer = new MongoDBContainer(imageName)
- .withExposedPorts(27017, 27017);
+ .withExposedPorts(27017);
mongoDBContainer.start();
- var mappedHttpPort = mongoDBContainer.getMappedPort(27017);
- System.setProperty("spring.data.mongodb.port", Integer.toString(mappedHttpPort));
+ var mappedPort = mongoDBContainer.getMappedPort(27017);
+ var mongoUri = String.format("mongodb://localhost:%d", mappedPort);
+ System.setProperty("spring.data.mongodb.uri", mongoUri);
+ System.setProperty("spring.data.mongodb.port", Integer.toString(mappedPort));
}
@Override
public void afterAll(ExtensionContext extensionContext) {
- mongoDBContainer.stop();
+ if (mongoDBContainer != null) {
+ mongoDBContainer.stop();
+ }
}
}
+
diff --git a/src/test/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/handlers/GetChangedEntitiesCommandHandlerIT.java b/src/test/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/handlers/GetChangedEntitiesCommandHandlerIT.java
index 6c8f371..a3c9425 100644
--- a/src/test/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/handlers/GetChangedEntitiesCommandHandlerIT.java
+++ b/src/test/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/handlers/GetChangedEntitiesCommandHandlerIT.java
@@ -13,6 +13,7 @@
import org.springframework.context.annotation.Import;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import reactor.core.publisher.Mono;
@@ -24,6 +25,7 @@
@ExtendWith({SpringExtension.class, RabbitTestExtension.class, MongoTestExtension.class})
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
@Import({WebprotegeEventsHistoryApplication.class})
+@ActiveProfiles("test")
public class GetChangedEntitiesCommandHandlerIT {
@Autowired
diff --git a/src/test/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/handlers/GetProjectChangesForHistoryViewCommandHandlerIntegrationTest.java b/src/test/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/handlers/GetProjectChangesForHistoryViewCommandHandlerIntegrationTest.java
index bb9bb54..3e5cb52 100644
--- a/src/test/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/handlers/GetProjectChangesForHistoryViewCommandHandlerIntegrationTest.java
+++ b/src/test/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/handlers/GetProjectChangesForHistoryViewCommandHandlerIntegrationTest.java
@@ -16,6 +16,7 @@
import org.springframework.context.annotation.Import;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import reactor.core.publisher.Mono;
@@ -28,6 +29,7 @@
@ExtendWith({SpringExtension.class, RabbitTestExtension.class, MongoTestExtension.class})
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
@Import({WebprotegeEventsHistoryApplication.class})
+@ActiveProfiles("test")
public class GetProjectChangesForHistoryViewCommandHandlerIntegrationTest {
@Autowired
diff --git a/src/test/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/handlers/NewRevisionsEventHandlerIntegrationTest.java b/src/test/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/handlers/NewRevisionsEventHandlerIntegrationTest.java
index eb8738b..06211a9 100644
--- a/src/test/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/handlers/NewRevisionsEventHandlerIntegrationTest.java
+++ b/src/test/java/edu/stanford/protege/webprotegeeventshistory/uiHistoryConcern/handlers/NewRevisionsEventHandlerIntegrationTest.java
@@ -59,12 +59,12 @@ public void GIVEN_validNewLinearizationRevisionsEvent_WHEN_handleEventCalled_THE
RevisionsEvent firstEvent = savedEvents.get(0);
assertEquals("whoficEntityIri1", firstEvent.whoficEntityIri());
- assertEquals(projectId, firstEvent.projectId());
+ assertEquals(projectId.id(), firstEvent.projectId());
assertEquals(12345L, firstEvent.timestamp());
RevisionsEvent secondEvent = savedEvents.get(1);
assertEquals("whoficEntityIri2", secondEvent.whoficEntityIri());
- assertEquals(projectId, secondEvent.projectId());
+ assertEquals(projectId.id(), secondEvent.projectId());
assertEquals(12346L, secondEvent.timestamp());
}
@@ -117,10 +117,10 @@ public void GIVEN_multipleValidEvents_WHEN_handleEventCalled_THEN_allEventsAreRe
RevisionsEvent firstSavedEvent = savedEvents.get(0);
assertEquals("whoficEntityIri1", firstSavedEvent.whoficEntityIri());
- assertEquals(projectId1, firstSavedEvent.projectId());
+ assertEquals(projectId1.id(), firstSavedEvent.projectId());
RevisionsEvent thirdSavedEvent = savedEvents.get(2);
assertEquals("whoficEntityIri3", thirdSavedEvent.whoficEntityIri());
- assertEquals(projectId2, thirdSavedEvent.projectId());
+ assertEquals(projectId2.id(), thirdSavedEvent.projectId());
}
}
diff --git a/src/test/resources/application-test.yaml b/src/test/resources/application-test.yaml
index 7ef5846..a719272 100644
--- a/src/test/resources/application-test.yaml
+++ b/src/test/resources/application-test.yaml
@@ -1,8 +1,8 @@
spring:
application:
- name: webprotege-linearization-service
+ name: EventsHistory
rabbitmq:
- host: rabbitmq
+ host: localhost
port: 5672
password: guest
username: guest
@@ -12,4 +12,12 @@ spring:
port: 27017
database: webprotege
auto-index-creation: true
- uri: mongodb://${spring.data.mongodb.host}:${spring.data.mongodb.port}/webprotege
\ No newline at end of file
+ uri: mongodb://${spring.data.mongodb.host}:${spring.data.mongodb.port}/webprotege
+
+webprotege:
+ rabbitmq:
+ requestqueue: webprotege-events-history-queue
+ responsequeue: webprotege-events-history-response
+ eventsqueue: webprotege-events-history-event-queue
+ timeout: 60000
+ event-subscribe: true
\ No newline at end of file