Skip to content

Commit

Permalink
Adding roadRegulatorId to APIs and fixing infinite live data loop
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob6838 committed Jan 4, 2024
1 parent 560e8d9 commit ebd0992
Show file tree
Hide file tree
Showing 4 changed files with 198 additions and 162 deletions.
2 changes: 1 addition & 1 deletion jpo-conflictmonitor
Submodule jpo-conflictmonitor updated from e8187d to 8b615d
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package us.dot.its.jpo.ode.api.accessors.reports;


import java.util.List;

import org.springframework.data.mongodb.core.query.Query;
import us.dot.its.jpo.ode.api.models.DataLoader;
import us.dot.its.jpo.ode.api.models.ReportDocument;

public interface ReportRepository extends DataLoader<ReportDocument>{
Query getQuery(String reportName, Integer intersectionID, String roadRegulatorID, Long startTime, Long endTime, boolean includeReportContents, boolean latest);
public interface ReportRepository extends DataLoader<ReportDocument> {
Query getQuery(String reportName, Integer intersectionID, Integer roadRegulatorID, Long startTime, Long endTime,
boolean includeReportContents, boolean latest);

long getQueryResultCount(Query query);

List<ReportDocument> find(Query query);

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package us.dot.its.jpo.ode.api.accessors.reports;


import java.time.Instant;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -13,10 +12,8 @@
import us.dot.its.jpo.ode.api.ConflictMonitorApiProperties;
import us.dot.its.jpo.ode.api.models.ReportDocument;



@Component
public class ReportRepositoryImpl implements ReportRepository{
public class ReportRepositoryImpl implements ReportRepository {

@Autowired
private MongoTemplate mongoTemplate;
Expand All @@ -27,38 +24,39 @@ public class ReportRepositoryImpl implements ReportRepository{
private String collectionName = "CmReport";

@Override
public Query getQuery(String reportName, Integer intersectionID, String roadRegulatorID, Long startTime, Long endTime, boolean includeReportContents, boolean latest) {
public Query getQuery(String reportName, Integer intersectionID, Integer roadRegulatorID, Long startTime,
Long endTime, boolean includeReportContents, boolean latest) {
Query query = new Query();

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

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

if(roadRegulatorID != null && roadRegulatorID.length() > 0){
query.addCriteria(Criteria.where("intersectionID").is(intersectionID));
if (roadRegulatorID != null) {
query.addCriteria(Criteria.where("roadRegulatorID").is(intersectionID));
}

if(startTime == null){
if (startTime == null) {
startTime = 0L;
}
if(endTime == null){
if (endTime == null) {
endTime = Instant.now().toEpochMilli();
}

query.addCriteria(Criteria.where("reportGeneratedAt").gte(startTime).lte(endTime));

if(!includeReportContents){
if (!includeReportContents) {
query.fields().exclude("reportContents");
}

if (latest) {
query.with(Sort.by(Sort.Direction.DESC, "reportGeneratedAt"));
query.limit(1);
}else{
} else {
query.limit(props.getMaximumResponseSize());
}

Expand Down
Loading

0 comments on commit ebd0992

Please sign in to comment.