Skip to content

Commit

Permalink
Added page related code
Browse files Browse the repository at this point in the history
  • Loading branch information
cgendreau committed Feb 14, 2024
1 parent 918b080 commit f60b92b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dina-base-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
<dependency>
<groupId>io.github.aafc-bicoe</groupId>
<artifactId>dina-filter</artifactId>
<version>0.115-SNAPSHOT</version>
<version>0.118-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.github.aafc-bicoe</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@
import ca.gc.aafc.dina.filter.simple.SimpleSearchFilterBaseListener;
import ca.gc.aafc.dina.filter.simple.SimpleSearchFilterParser;

public class AntlBasedSimpleSearchFilterListener extends SimpleSearchFilterBaseListener {
public class AntlrBasedSimpleSearchFilterListener extends SimpleSearchFilterBaseListener {

private final List<FilterComponent> components = new ArrayList<>();
private final List<String> includes = new ArrayList<>();
private final List<String> sortAttributes = new ArrayList<>();

private Integer pageOffset;
private Integer pageLimit;

@Override
public void exitFilter(SimpleSearchFilterParser.FilterContext ctx) {
// more than 1 value means a OR
Expand All @@ -32,6 +35,7 @@ public void exitFilter(SimpleSearchFilterParser.FilterContext ctx) {
}
}

@Override
public void exitInclude(SimpleSearchFilterParser.IncludeContext ctx) {
for(var attribute : ctx.propertyName()) {
includes.add(attribute.getText());
Expand All @@ -45,6 +49,15 @@ public void exitSort(SimpleSearchFilterParser.SortContext ctx) {
}
}

@Override
public void exitPage(SimpleSearchFilterParser.PageContext ctx) {
if (ctx.getText().contains("offset")) {
pageOffset = Integer.valueOf(ctx.pageValue().getText());
} else if (ctx.getText().contains("limit")) {
pageLimit = Integer.valueOf(ctx.pageValue().getText());
}
}

/**
* Build the FilterComponent object once the filter is parsed.
* @return
Expand All @@ -68,6 +81,14 @@ public List<String> getSort() {
return sortAttributes;
}

public Integer getPageOffset() {
return pageOffset;
}

public Integer getPageLimit() {
return pageLimit;
}

public Ops translateOperator(String op) {
return switch (op) {
case "EQ" -> Ops.EQ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void onFilterAsString_structureReturned() {
ParseTree tree = parser.simpleFilter();

ParseTreeWalker walker = new ParseTreeWalker();
AntlBasedSimpleSearchFilterListener listener= new AntlBasedSimpleSearchFilterListener();
AntlrBasedSimpleSearchFilterListener listener= new AntlrBasedSimpleSearchFilterListener();
walker.walk(listener, tree);


Expand All @@ -38,6 +38,9 @@ public void onFilterAsString_structureReturned() {
assertEquals("position", listener.getSort().get(0));
assertEquals("-name", listener.getSort().get(1));
assertEquals("author.name", listener.getInclude().get(0));

assertEquals(5, listener.getPageOffset());
assertEquals(1, listener.getPageLimit());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ filter: 'filter' '[' propertyName ']'( '[' comparison ']' )? '=' attributeValue

sort: 'sort' '=' sortPropertyName ( ',' sortPropertyName )*;

page: 'page' '[' ( 'limit' | 'offset' ) ']' '=' INT;
page: 'page' '[' ( 'limit' | 'offset' ) ']' '=' pageValue;

include: 'include' '=' propertyName ( ',' propertyName )*;

Expand All @@ -28,6 +28,8 @@ attributeValue: (
| DASH
| SYMBOLS)+;

pageValue: INT;

// lexer rules in order
INT: [0-9]+;
LETTERS: [a-zA-Z]+;
Expand Down

0 comments on commit f60b92b

Please sign in to comment.