diff --git a/cwms-data-api/src/main/java/cwms/cda/data/dao/ClobDao.java b/cwms-data-api/src/main/java/cwms/cda/data/dao/ClobDao.java index 270656fa4..70328b642 100644 --- a/cwms-data-api/src/main/java/cwms/cda/data/dao/ClobDao.java +++ b/cwms-data-api/src/main/java/cwms/cda/data/dao/ClobDao.java @@ -68,12 +68,13 @@ public Optional getByUniqueName(String uniqueName, String office) { public Clobs getClobs(String cursor, int pageSize, String officeLike, boolean includeValues, String idRegex) { int total = 0; - String clobCursor = "*"; + String cursorOffice = null; + String cursorClobId = null; AV_CLOB v_clob = AV_CLOB.AV_CLOB; AV_OFFICE v_office = AV_OFFICE.AV_OFFICE; Condition whereClause = JooqDao.caseInsensitiveLikeRegex(v_clob.ID, idRegex) - .and(officeLike == null ? noCondition() : JooqDao.caseInsensitiveLikeRegex(v_office.OFFICE_ID, officeLike)); + .and(JooqDao.caseInsensitiveLikeRegexNullTrue(v_office.OFFICE_ID, officeLike)); if (cursor == null || cursor.isEmpty()) { SelectConditionStep> count = dsl.select(count(asterisk())) .from(v_clob) @@ -92,9 +93,8 @@ public Clobs getClobs(String cursor, int pageSize, String officeLike, } if (parts.length > 1) { - clobCursor = parts[0].split(";")[0]; - clobCursor = clobCursor.substring(clobCursor.indexOf("/") + 1); // ditch the - // officeId that's embedded in + cursorOffice = Clobs.getOffice(cursor); + cursorClobId = Clobs.getId(cursor); total = Integer.parseInt(parts[1]); pageSize = Integer.parseInt(parts[2]); } @@ -109,12 +109,15 @@ public Clobs getClobs(String cursor, int pageSize, String officeLike, .from(v_clob) .join(v_office).on(v_clob.OFFICE_CODE.eq(v_office.OFFICE_CODE)) .where(whereClause) - .and(DSL.upper(v_clob.ID).greaterThan(clobCursor)) + .and(cursorClobId == null ? DSL.noCondition() : + DSL.upper(v_clob.ID).greaterThan(cursorClobId.toUpperCase())) + .and(cursorOffice == null ? DSL.noCondition() : + DSL.upper(v_office.OFFICE_ID).greaterThan(cursorOffice.toUpperCase())) .orderBy(v_office.OFFICE_ID, v_clob.ID) .limit(pageSize); - Clobs.Builder builder = new Clobs.Builder(clobCursor, pageSize, total); + Clobs.Builder builder = new Clobs.Builder(cursor, pageSize, total); logger.atFine().log(query.getSQL(ParamType.INLINED)); diff --git a/cwms-data-api/src/main/java/cwms/cda/data/dto/Clobs.java b/cwms-data-api/src/main/java/cwms/cda/data/dto/Clobs.java index 14c143473..dd2dc5728 100644 --- a/cwms-data-api/src/main/java/cwms/cda/data/dto/Clobs.java +++ b/cwms-data-api/src/main/java/cwms/cda/data/dto/Clobs.java @@ -44,19 +44,53 @@ private void addClob(Clob clob) { clobs.add(clob); } + /** + * Extract the office from the cursor. + * + * @param cursor the cursor + * @return office + */ + public static String getOffice(String cursor) { + String[] parts = CwmsDTOPaginated.decodeCursor(cursor); + if (parts.length > 1) { + String[] idAndOffice = CwmsDTOPaginated.decodeCursor(parts[0]); + if (idAndOffice.length > 0) { + return idAndOffice[0]; + } + } + return null; + } + + /** + * Extract the id from the cursor. + * + * @param cursor the cursor + * @return id + */ + public static String getId(String cursor) { + String[] parts = CwmsDTOPaginated.decodeCursor(cursor); + if (parts.length > 1) { + String[] idAndOffice = CwmsDTOPaginated.decodeCursor(parts[0]); + if (idAndOffice.length > 1) { + return idAndOffice[1]; + } + } + return null; + } + public static class Builder { - private Clobs workingClobs; + private final Clobs workingClobs; public Builder(String cursor, int pageSize, int total) { workingClobs = new Clobs(cursor, pageSize, total); } public Clobs build() { - if (this.workingClobs.clobs.size() == this.workingClobs.pageSize) { - this.workingClobs.nextPage = encodeCursor( - this.workingClobs.clobs.get(this.workingClobs.clobs.size() - 1).toString().toUpperCase(), - this.workingClobs.pageSize, - this.workingClobs.total); + if (this.workingClobs.clobs.size() == this.workingClobs.pageSize && !this.workingClobs.clobs.isEmpty()) { + Clob lastClob = this.workingClobs.clobs.get(this.workingClobs.clobs.size() - 1); + String cursor = encodeCursor(CwmsDTOPaginated.delimiter, lastClob.getOfficeId(), + lastClob.getId()); + this.workingClobs.nextPage = encodeCursor(cursor, this.workingClobs.pageSize, this.workingClobs.total); } else { this.workingClobs.nextPage = null; }