Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:usdot-jpo-ode/jpo-conflictvisual…
Browse files Browse the repository at this point in the history
…izer into bug-fixes-2024-2-14
  • Loading branch information
John-Wiens committed Feb 28, 2024
2 parents 7da5e7b + 7b22f41 commit df987e4
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 76 deletions.
2 changes: 1 addition & 1 deletion jpo-conflictmonitor
Submodule jpo-conflictmonitor updated from 3b6020 to 644f45
39 changes: 36 additions & 3 deletions jpo-conflictvisualizer-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
<description>Conflict Visualizer</description>
<properties>
<java.version>21</java.version>
<jacoco.version>0.8.7</jacoco.version>
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.coverage.jacoco.xmlReportPaths>${project.basedir}/target/site/jacoco/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
<sonar.language>java</sonar.language>
<!-- <thymeleaf.version>3.0.3.RELEASE</thymeleaf.version>
<thymeleaf-layout-dialect.version>2.2.1</thymeleaf-layout-dialect.version> -->
</properties>
Expand Down Expand Up @@ -87,7 +91,7 @@
<dependency>
<groupId>usdot.jpo.ode</groupId>
<artifactId>jpo-ode-core</artifactId>
<version>1.6.0-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
<!-- required exclusion to preserve keycloak versions -->
<exclusions>
<exclusion>
Expand All @@ -99,7 +103,7 @@
<dependency>
<groupId>usdot.jpo.ode</groupId>
<artifactId>jpo-ode-plugins</artifactId>
<version>1.6.0-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>usdot.jpo.ode</groupId>
Expand Down Expand Up @@ -209,6 +213,35 @@
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>generate-report</id>
<phase>verify</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/site/jacoco</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
Expand Down Expand Up @@ -246,4 +279,4 @@
</plugins>
</build>

</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public class ConflictMonitorApiProperties {
private String cmServerURL = "";
private String emailBroker = "";
private String emailFromAddress = "noreply@cimms.com";
private long mongoTimeoutMs = 5000;
private int importProcessorBufferSize = OdePlugin.INPUT_STREAM_BUFFER_SIZE;
private String hostId;
private List<Path> uploadLocations = new ArrayList<>();
Expand Down Expand Up @@ -166,6 +167,15 @@ public void setEmailFromAddress(String emailFromAddress) {
this.emailFromAddress = emailFromAddress;
}

public long getMongoTimeoutMs() {
return mongoTimeoutMs;
}

@Value("${mongoTimeoutMs}")
public void setMongoTimeoutMs(long mongoTimeoutMs) {
this.mongoTimeoutMs = mongoTimeoutMs;
}

public String getKafkaBrokers() {
return kafkaBrokers;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ public class MongoConfig extends AbstractMongoClientConfiguration{
@Value("${spring.data.mongodb.port}")
private String port;

@Value("${spring.data.mongodb.username}")
private String username;

@Value("${spring.data.mongodb.password}")
private String password;

@Override
protected String getDatabaseName() {
return db;
Expand All @@ -42,7 +48,8 @@ protected String getDatabaseName() {
@Override
public void configureClientSettings(MongoClientSettings.Builder builder) {
// customization hook
String uri = "mongodb://"+host+":"+port+"/"+db;
String uri = "mongodb://"+username+":"+password+"@"+host+":"+port+"/"+db;
// String uri = "mongodb://"+host+":"+port+"/"+db;
System.out.println("Connecting to MongoDB at: " + uri);
builder.applyConnectionString(new ConnectionString(uri));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import org.bson.Document;
import org.bson.conversions.Bson;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
Expand All @@ -21,16 +24,19 @@
import org.springframework.stereotype.Component;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.mongodb.MongoException;
import com.mongodb.client.DistinctIterable;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoCursor;
import com.mongodb.client.model.Projections;
import com.mongodb.client.model.Sorts;


import static com.mongodb.client.model.Filters.eq;

import us.dot.its.jpo.geojsonconverter.pojos.geojson.map.ProcessedMap;
import us.dot.its.jpo.ode.api.ConflictMonitorApiProperties;
import us.dot.its.jpo.ode.api.controllers.AssessmentController;
import us.dot.its.jpo.ode.api.models.IDCount;
import us.dot.its.jpo.ode.api.models.IntersectionReferenceData;
import us.dot.its.jpo.geojsonconverter.DateJsonMapper;
Expand All @@ -47,6 +53,7 @@ public class ProcessedMapRepositoryImpl implements ProcessedMapRepository {

private String collectionName = "ProcessedMap";
private ObjectMapper mapper = DateJsonMapper.getInstance();
private Logger logger = LoggerFactory.getLogger(ProcessedMapRepositoryImpl.class);

public Query getQuery(Integer intersectionID, Long startTime, Long endTime, boolean latest) {
Query query = new Query();
Expand Down Expand Up @@ -97,30 +104,40 @@ public List<IntersectionReferenceData> getIntersectionIDs() {
DistinctIterable<Integer> docs = collection.distinct("properties.intersectionId", Integer.class);
MongoCursor<Integer> results = docs.iterator();
List<IntersectionReferenceData> referenceDataList = new ArrayList<>();

while (results.hasNext()) {
Integer intersectionId = results.next();
if (intersectionId != null){

Bson projectionFields = Projections.fields(
Projections.include("properties.intersectionId", "properties.originIp",
"properties.refPoint.latitude", "properties.refPoint.longitude"),
Projections.excludeId());
Document document = collection.find(eq("properties.intersectionId", intersectionId))
.projection(projectionFields).sort(Sorts.descending("properties.timeStamp")).first();
IntersectionReferenceData data = new IntersectionReferenceData();
Document properties = document.get("properties", Document.class);

if (properties != null) {
Document refPoint = properties.get("refPoint", Document.class);
data.setIntersectionID(intersectionId);
data.setRoadRegulatorID("-1");
data.setRsuIP(properties.getString("originIp"));
if (refPoint != null) {
data.setLatitude(refPoint.getDouble("latitude"));
data.setLongitude(refPoint.getDouble("longitude"));
try {
Document document = collection.find(eq("properties.intersectionId", intersectionId))
.projection(projectionFields).sort(Sorts.descending("properties.timeStamp")).maxTime(props.getMongoTimeoutMs(), TimeUnit.MILLISECONDS).first();

if(document != null){
IntersectionReferenceData data = new IntersectionReferenceData();
Document properties = document.get("properties", Document.class);

if (properties != null) {
Document refPoint = properties.get("refPoint", Document.class);
data.setIntersectionID(intersectionId);
data.setRoadRegulatorID("-1");
data.setRsuIP(properties.getString("originIp"));
if (refPoint != null) {
data.setLatitude(refPoint.getDouble("latitude"));
data.setLongitude(refPoint.getDouble("longitude"));
}
}
referenceDataList.add(data);
}
} catch (MongoException e){
logger.error("MongoDB Intersection Query Did not finish in allowed time window");
} catch (Exception e) {
logger.error("");
}
referenceDataList.add(data);

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public Query getQuery(Integer intersectionID, Integer roadRegulatorID, String no
query.addCriteria(Criteria.where("intersectionID").is(intersectionID));
}

if(roadRegulatorID != null){
query.addCriteria(Criteria.where("roadRegulatorID").is(roadRegulatorID));
}
// if(roadRegulatorID != null){
// query.addCriteria(Criteria.where("roadRegulatorID").is(roadRegulatorID));
// }

if(notificationType != null){
query.addCriteria(Criteria.where("notificationType").is(notificationType));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ server.port=8081
spring.data.mongodb.database=ConflictMonitor
spring.data.mongodb.host=${DOCKER_HOST_IP:localhost}
spring.data.mongodb.port=27017
spring.data.mongodb.username=${CM_MONGO_API_USERNAME:api}
spring.data.mongodb.password=${CM_MONGO_API_PASSWORD:api}

cmServerURL = ${CM_SERVER_URL:http://localhost:8082}
mongoTimeoutMs = ${CM_MONGO_TIMEOUT_MS:5000}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public void testGetQuery() {

// Assert IntersectionID
assertThat(query.getQueryObject().get("intersectionID")).isEqualTo(intersectionID);
assertThat(query.getQueryObject().get("roadRegulatorID")).isEqualTo(roadRegulatorID);
// Road Regulator ID is not being enforced yet. Therefore not verified here.
// assertThat(query.getQueryObject().get("roadRegulatorID")).isEqualTo(roadRegulatorID);
assertThat(query.getQueryObject().get("notificationType")).isEqualTo(notificationType);
assertThat(query.getQueryObject().get("key")).isEqualTo(key);

Expand Down

0 comments on commit df987e4

Please sign in to comment.