Skip to content

Commit 0adaa33

Browse files
committed
MODHAADM-93 sort log lines of previous jobs
1 parent 5674952 commit 0adaa33

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/main/java/org/folio/harvesteradmin/moduledata/LogLine.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.folio.harvesteradmin.moduledata;
22

33
import io.vertx.core.json.JsonObject;
4+
import io.vertx.ext.web.RoutingContext;
45
import io.vertx.sqlclient.templates.RowMapper;
56
import io.vertx.sqlclient.templates.TupleMapper;
67
import java.util.Arrays;
@@ -212,6 +213,12 @@ public PgCqlDefinition getQueryableFields() {
212213
return pgCqlDefinition;
213214
}
214215

216+
public SqlQuery makeSqlFromCqlQuery(RoutingContext routingContext, String schemaDotTable) {
217+
SqlQuery sql = super.makeSqlFromCqlQuery(routingContext, schemaDotTable);
218+
sql.withAdditionalOrderByField(LogLineField.TIME_STAMP.columnName());
219+
sql.withAdditionalOrderByField(LogLineField.SEQUENCE_NUMBER.columnName());
220+
return sql;
221+
}
215222

216223
public String toString() {
217224
return String.format("%s %-5s %s %s",this.timeStamp, this.logLevel, this.jobLabel, this.line);

src/main/java/org/folio/harvesteradmin/moduledata/SqlQuery.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public class SqlQuery {
77
private final String select;
88
private final String from;
99
private String where;
10-
private final String orderBy;
10+
private String orderBy;
1111
private final String offset;
1212
private final String limit;
1313
private String defaultLimit = null;
@@ -40,8 +40,8 @@ public String getCountingSql() {
4040
public String getQueryWithLimits() {
4141
return select
4242
+ from
43-
+ where
44-
+ orderBy
43+
+ (where.isEmpty() ? "" : " WHERE " + where)
44+
+ (orderBy.isEmpty() ? "" : " ORDER BY " + orderBy)
4545
+ limits(offset, (limit == null ? defaultLimit : limit));
4646
}
4747

@@ -51,14 +51,25 @@ public String getQueryWithLimits() {
5151
public SqlQuery withAdditionalWhereClause(String clause) {
5252
if (clause != null && !clause.isEmpty()) {
5353
if (where.isEmpty()) {
54-
where = " where (" + clause + ")";
54+
where = " (" + clause + ")";
5555
} else {
5656
where += " AND " + "(" + clause + ") ";
5757
}
5858
}
5959
return this;
6060
}
6161

62+
public SqlQuery withAdditionalOrderByField(String clause) {
63+
if (clause != null && !clause.isEmpty()) {
64+
if (orderBy.isEmpty()) {
65+
orderBy = clause;
66+
} else {
67+
orderBy += ", " + clause;
68+
}
69+
}
70+
return this;
71+
}
72+
6273
public SqlQuery withDefaultLimit(String defaultLimit) {
6374
this.defaultLimit = defaultLimit;
6475
return this;

0 commit comments

Comments
 (0)