diff --git a/cwms-data-api/src/main/java/cwms/cda/data/dao/BlobDao.java b/cwms-data-api/src/main/java/cwms/cda/data/dao/BlobDao.java index d0875e4f5..c9bc1eea2 100644 --- a/cwms-data-api/src/main/java/cwms/cda/data/dao/BlobDao.java +++ b/cwms-data-api/src/main/java/cwms/cda/data/dao/BlobDao.java @@ -71,7 +71,7 @@ public Optional getByUniqueName(String id, String limitToOffice) { ResultQuery query; if (limitToOffice != null && !limitToOffice.isEmpty()) { queryStr = queryStr + " and CWMS_OFFICE.OFFICE_ID = ?"; - query = dsl.resultQuery(queryStr, id, limitToOffice); + query = dsl.resultQuery(queryStr, id, limitToOffice.toUpperCase()); } else { query = dsl.resultQuery(queryStr, id); } @@ -110,7 +110,7 @@ public void getBlob(String id, String office, StreamConsumer consumer, @Nullable } } else { try (PreparedStatement preparedStatement = connection.prepareStatement(BLOB_WITH_OFFICE)) { - preparedStatement.setString(1, office); + preparedStatement.setString(1, office.toUpperCase()); preparedStatement.setString(2, id); executeAndHandle(consumer, offset, end, preparedStatement, "Unable to find blob with id " + id + " in office " + office); 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 3603b6593..6debadcfc 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 @@ -51,7 +51,7 @@ public Optional getByUniqueName(String uniqueName, String office) { Condition cond = upper(vClob.ID).eq(upper(uniqueName)); if (office != null && !office.isEmpty()) { - cond = cond.and(vOffice.OFFICE_ID.eq(office)); + cond = cond.and(vOffice.OFFICE_ID.eq(office.toUpperCase())); } RecordMapper mapper = joinRecord -> @@ -76,14 +76,14 @@ public Clobs getClobs(String cursor, int pageSize, String officeLike, AV_OFFICE vOffice = AV_OFFICE.AV_OFFICE; Condition whereClause = JooqDao.caseInsensitiveLikeRegex(vClob.ID, idRegex) - .and(JooqDao.caseInsensitiveLikeRegexNullTrue(vOffice.OFFICE_ID, officeLike)); + .and(JooqDao.caseInsensitiveLikeRegexNullTrue(vOffice.OFFICE_ID, officeLike)); if (cursor == null || cursor.isEmpty()) { SelectConditionStep> count = dsl.select(count(asterisk())) - .from(vClob) - .join(vOffice).on(vClob.OFFICE_CODE.eq(vOffice.OFFICE_CODE)) - .where(whereClause); + .from(vClob) + .join(vOffice).on(vClob.OFFICE_CODE.eq(vOffice.OFFICE_CODE)) + .where(whereClause); Record1 rec = count.fetchOne(); - if(rec != null) { + if (rec != null) { total = rec.value1(); } } else { @@ -105,27 +105,27 @@ public Clobs getClobs(String cursor, int pageSize, String officeLike, Condition moreInSameOffice = cursorClobId == null || cursorOffice == null ? noCondition() : vOffice.OFFICE_ID.eq(cursorOffice.toUpperCase()) .and(upper(vClob.ID).greaterThan(cursorClobId.toUpperCase())); - Condition nextOffices = cursorOffice == null ? noCondition(): + Condition nextOffices = cursorOffice == null ? noCondition() : upper(vOffice.OFFICE_ID).greaterThan(cursorOffice.toUpperCase()); Condition pagingCondition = moreInSameOffice.or(nextOffices); SelectLimitPercentStep> query = dsl.select( - vOffice.OFFICE_ID, - vClob.ID, - vClob.DESCRIPTION, - includeValues ? vClob.VALUE : DSL.inline("").as(vClob.VALUE) - ) - .from(vClob) - .join(vOffice).on(vClob.OFFICE_CODE.eq(vOffice.OFFICE_CODE)) - .where(whereClause) - .and(pagingCondition) - .orderBy(vOffice.OFFICE_ID, vClob.ID) - .limit(pageSize); + vOffice.OFFICE_ID, + vClob.ID, + vClob.DESCRIPTION, + includeValues ? vClob.VALUE : DSL.inline("").as(vClob.VALUE) + ) + .from(vClob) + .join(vOffice).on(vClob.OFFICE_CODE.eq(vOffice.OFFICE_CODE)) + .where(whereClause) + .and(pagingCondition) + .orderBy(vOffice.OFFICE_ID, vClob.ID) + .limit(pageSize); Clobs.Builder builder = new Clobs.Builder(cursor, pageSize, total); - logger.atFine().log("%s", lazy(()->query.getSQL(ParamType.INLINED))); + logger.atFine().log("%s", lazy(() -> query.getSQL(ParamType.INLINED))); query.fetch().forEach(row -> { usace.cwms.db.jooq.codegen.tables.records.AV_CLOB clob = row.into(vClob); @@ -170,13 +170,13 @@ public void create(Clob clob, boolean failIfExists) { String pFailIfExists = getBoolean(failIfExists); connection(dsl, c -> - CWMS_TEXT_PACKAGE.call_STORE_TEXT( - getDslContext(c, clob.getOfficeId()).configuration(), - clob.getValue(), - clob.getId(), - clob.getDescription(), - pFailIfExists, - clob.getOfficeId())); + CWMS_TEXT_PACKAGE.call_STORE_TEXT( + getDslContext(c, clob.getOfficeId()).configuration(), + clob.getValue(), + clob.getId(), + clob.getDescription(), + pFailIfExists, + clob.getOfficeId())); } @NotNull @@ -191,8 +191,8 @@ public static String getBoolean(boolean failIfExists) { } public void delete(String officeId, String id) { - connection(dsl,c -> CWMS_TEXT_PACKAGE.call_DELETE_TEXT( - getDslContext(c,officeId).configuration(), id, officeId) + connection(dsl, c -> CWMS_TEXT_PACKAGE.call_DELETE_TEXT( + getDslContext(c, officeId).configuration(), id, officeId) ); } @@ -206,22 +206,22 @@ public void update(Clob clob, boolean ignoreNulls) { // it throws - ORA-20244: NULL_ARGUMENT: Argument P_TEXT is not allowed to be null // Also note: when pIgnoreNulls == 'F' and the value is "" (empty string) // it throws - ORA-20244: NULL_ARGUMENT: Argument P_TEXT is not allowed to be null - connection(dsl,c -> - CWMS_TEXT_PACKAGE.call_UPDATE_TEXT( - getDslContext(c,clob.getOfficeId()).configuration(), - clob.getValue(), - clob.getId(), - clob.getDescription(), - pIgnoreNulls, - clob.getOfficeId() - ) + connection(dsl, c -> + CWMS_TEXT_PACKAGE.call_UPDATE_TEXT( + getDslContext(c, clob.getOfficeId()).configuration(), + clob.getValue(), + clob.getId(), + clob.getDescription(), + pIgnoreNulls, + clob.getOfficeId() + ) ); } /** * - * @param clobId the id to search for - * @param officeId the office + * @param clobId the id to search for + * @param officeId the office * @param streamConsumer a consumer that should be handed the input stream and the length of the stream. */ public void getClob(String clobId, String officeId, StreamConsumer streamConsumer) { @@ -235,7 +235,7 @@ public void getClob(String clobId, String officeId, StreamConsumer streamConsume // We can't use the stream once the connection we get from jooq is closed, so we have to pass in // what we want javalin to do with the stream as a consumer. try (PreparedStatement preparedStatement = connection.prepareStatement(SELECT_CLOB_QUERY)) { - preparedStatement.setString(1, officeId); + preparedStatement.setString(1, officeId.toUpperCase()); preparedStatement.setString(2, clobId); try (ResultSet resultSet = preparedStatement.executeQuery()) { @@ -243,7 +243,7 @@ public void getClob(String clobId, String officeId, StreamConsumer streamConsume java.sql.Clob clob = resultSet.getClob("VALUE"); long length = clob.length(); - try (InputStream is = clob.getAsciiStream()){ + try (InputStream is = clob.getAsciiStream()) { streamConsumer.accept(is, 0, "text/plain", length); } finally { clob.free(); @@ -257,11 +257,11 @@ public void getClob(String clobId, String officeId, StreamConsumer streamConsume } public static String readFully(java.sql.Clob clob) throws IOException, SQLException { - try(Reader reader = clob.getCharacterStream(); - BufferedReader br = new BufferedReader(reader)) { + try (Reader reader = clob.getCharacterStream(); + BufferedReader br = new BufferedReader(reader)) { StringBuilder sb = new StringBuilder(); String line; - while(null != (line = br.readLine())) { + while (null != (line = br.readLine())) { sb.append(line); } return sb.toString(); diff --git a/cwms-data-api/src/main/java/cwms/cda/data/dao/ForecastInstanceDao.java b/cwms-data-api/src/main/java/cwms/cda/data/dao/ForecastInstanceDao.java index 610ecaedf..34297f33d 100644 --- a/cwms-data-api/src/main/java/cwms/cda/data/dao/ForecastInstanceDao.java +++ b/cwms-data-api/src/main/java/cwms/cda/data/dao/ForecastInstanceDao.java @@ -157,7 +157,12 @@ private static Map mapFromJson(String forecastInfo) { } public List getForecastInstances(int byteLimit, ReplaceUtils.OperatorBuilder urlBuilder, - String office, String name, String designator) { + String officeArg, String name, String designator) { + + if(officeArg != null){ + officeArg = officeArg.toUpperCase(); + } + String office = officeArg; String query = INSTANCE_QUERY + GET_ALL_CONDITIONS; return connectionResult(dsl, (Connection c) -> { @@ -264,8 +269,13 @@ private static ForecastInstance map(int byteLimit, ReplaceUtils.OperatorBuilder } public ForecastInstance getForecastInstance(int byteLimit, ReplaceUtils.OperatorBuilder urlBuilder, - String office, String name, String designator, + String officeArg, String name, String designator, Instant forecastDate, Instant issueDate) { + if(officeArg != null){ + officeArg = officeArg.toUpperCase(); + } + String office = officeArg; + String query = INSTANCE_QUERY + GET_ONE_CONDITIONS; return connectionResult(dsl, c -> { try (PreparedStatement preparedStatement = c.prepareStatement(query)) { diff --git a/cwms-data-api/src/main/java/cwms/cda/data/dao/ForecastSpecDao.java b/cwms-data-api/src/main/java/cwms/cda/data/dao/ForecastSpecDao.java index e11af998d..c189afc98 100644 --- a/cwms-data-api/src/main/java/cwms/cda/data/dao/ForecastSpecDao.java +++ b/cwms-data-api/src/main/java/cwms/cda/data/dao/ForecastSpecDao.java @@ -2,8 +2,8 @@ import cwms.cda.api.errors.NotFoundException; import cwms.cda.data.dto.forecast.ForecastSpec; -import cwms.cda.formatters.UnsupportedFormatException; +import org.jetbrains.annotations.NotNull; import org.jooq.SelectConditionStep; import usace.cwms.db.jooq.codegen.packages.CWMS_FCST_PACKAGE; import usace.cwms.db.jooq.codegen.tables.AV_FCST_LOCATION; @@ -111,11 +111,11 @@ private static ForecastSpec map(Record7> query = forecastSpecQuery(dsl) - .where(spec.OFFICE_ID.eq(office)) + .where(spec.OFFICE_ID.eq(office.toUpperCase())) .and(spec.FCST_SPEC_ID.eq(name)); if(designator != null) { query = query.and(spec.FCST_DESIGNATOR.eq(designator)); diff --git a/cwms-data-api/src/main/java/cwms/cda/data/dao/LocationCategoryDao.java b/cwms-data-api/src/main/java/cwms/cda/data/dao/LocationCategoryDao.java index e743f4495..6427805e1 100644 --- a/cwms-data-api/src/main/java/cwms/cda/data/dao/LocationCategoryDao.java +++ b/cwms-data-api/src/main/java/cwms/cda/data/dao/LocationCategoryDao.java @@ -27,6 +27,8 @@ import cwms.cda.data.dto.LocationCategory; import java.util.List; import java.util.Optional; + +import org.jetbrains.annotations.NotNull; import org.jooq.DSLContext; import org.jooq.Record3; import usace.cwms.db.jooq.codegen.packages.CWMS_LOC_PACKAGE; @@ -57,17 +59,17 @@ public List getLocationCategories(String officeId) { return dsl.selectDistinct(table.CAT_DB_OFFICE_ID, table.LOC_CATEGORY_ID, table.LOC_CATEGORY_DESC) .from(table) - .where(table.CAT_DB_OFFICE_ID.eq(officeId)) + .where(table.CAT_DB_OFFICE_ID.eq(officeId.toUpperCase())) .fetch().into(LocationCategory.class); } - public Optional getLocationCategory(String officeId, String categoryId) { + public Optional getLocationCategory(@NotNull String officeId, String categoryId) { AV_LOC_CAT_GRP table = AV_LOC_CAT_GRP.AV_LOC_CAT_GRP; Record3 fetchOne = dsl.selectDistinct(table.CAT_DB_OFFICE_ID, table.LOC_CATEGORY_ID, table.LOC_CATEGORY_DESC) .from(table) - .where(table.CAT_DB_OFFICE_ID.eq(officeId) + .where(table.CAT_DB_OFFICE_ID.eq(officeId.toUpperCase()) .and(table.LOC_CATEGORY_ID.eq(categoryId))) .fetchOne(); return fetchOne != null ? diff --git a/cwms-data-api/src/main/java/cwms/cda/data/dao/LocationGroupDao.java b/cwms-data-api/src/main/java/cwms/cda/data/dao/LocationGroupDao.java index 2cb07af51..ec8352873 100644 --- a/cwms-data-api/src/main/java/cwms/cda/data/dao/LocationGroupDao.java +++ b/cwms-data-api/src/main/java/cwms/cda/data/dao/LocationGroupDao.java @@ -90,6 +90,7 @@ public LocationGroupDao(DSLContext dsl) { */ public Optional getLocationGroup(@NotNull String officeId, @NotNull String categoryId, @NotNull String groupId) { + officeId = officeId.toUpperCase(); Condition joinCondition; if (CWMS.equalsIgnoreCase(officeId)) { @@ -344,6 +345,7 @@ public List getLocationGroups(String locationOfficeId, String gro Condition joinCondition = noCondition(); if (locationOfficeId != null) { + locationOfficeId = locationOfficeId.toUpperCase(); if (CWMS.equalsIgnoreCase(locationOfficeId)) { whereCondition = whereCondition.and(catGroupView.CAT_DB_OFFICE_ID.eq(CWMS) .and(catGroupView.GRP_DB_OFFICE_ID.eq(CWMS)) @@ -382,11 +384,11 @@ private List getGroupsWithoutAssignedLocations( Condition condition = catGroupView.LOC_GROUP_ID.isNotNull(); if (groupOfficeId != null && !groupOfficeId.isEmpty()) { - condition = condition.and(catGroupView.GRP_DB_OFFICE_ID.eq(groupOfficeId)); + condition = condition.and(catGroupView.GRP_DB_OFFICE_ID.eq(groupOfficeId.toUpperCase())); } if (categoryOfficeId != null && !categoryOfficeId.isEmpty()) { - condition = condition.and(catGroupView.CAT_DB_OFFICE_ID.eq(categoryOfficeId)); + condition = condition.and(catGroupView.CAT_DB_OFFICE_ID.eq(categoryOfficeId.toUpperCase())); } if (locCategoryLike != null && !locCategoryLike.isEmpty()) { @@ -436,9 +438,9 @@ public FeatureCollection buildFeatureCollectionForLocationGroup(String locationO groupAssignView.GROUP_ID, groupAssignView.ATTRIBUTE, groupAssignView.ALIAS_ID, groupAssignView.SHARED_REF_LOCATION_ID, groupAssignView.SHARED_ALIAS_ID) .from(al).join(groupAssignView).on(al.LOCATION_ID.eq(groupAssignView.LOCATION_ID)) - .where(groupAssignView.DB_OFFICE_ID.eq(locationOfficeId) - .and(groupAssignView.CATEGORY_OFFICE_ID.eq(categoryOfficeId)) - .and(groupAssignView.GROUP_OFFICE_ID.eq(groupOfficeId)) + .where(groupAssignView.DB_OFFICE_ID.eq(locationOfficeId.toUpperCase()) + .and(groupAssignView.CATEGORY_OFFICE_ID.eq(categoryOfficeId.toUpperCase())) + .and(groupAssignView.GROUP_OFFICE_ID.eq(groupOfficeId.toUpperCase())) .and(groupAssignView.CATEGORY_ID.eq(categoryId) .and(groupAssignView.GROUP_ID.eq(groupId)) .and(al.UNIT_SYSTEM.eq(units)))) diff --git a/cwms-data-api/src/main/java/cwms/cda/data/dao/LocationsDaoImpl.java b/cwms-data-api/src/main/java/cwms/cda/data/dao/LocationsDaoImpl.java index 5580a311c..538de18c2 100644 --- a/cwms-data-api/src/main/java/cwms/cda/data/dao/LocationsDaoImpl.java +++ b/cwms-data-api/src/main/java/cwms/cda/data/dao/LocationsDaoImpl.java @@ -36,11 +36,7 @@ import static java.util.stream.Collectors.groupingBy; import static java.util.stream.Collectors.toList; import static java.util.stream.Collectors.toSet; -import static org.jooq.impl.DSL.asterisk; -import static org.jooq.impl.DSL.count; -import static org.jooq.impl.DSL.field; -import static org.jooq.impl.DSL.name; -import static org.jooq.impl.DSL.select; +import static org.jooq.impl.DSL.*; import static usace.cwms.db.jooq.codegen.tables.AV_LOC.AV_LOC; import static usace.cwms.db.jooq.codegen.tables.AV_LOC_ALIAS.AV_LOC_ALIAS; @@ -118,7 +114,7 @@ public List getLocations(String nameRegex, String unitSystem, String d Condition whereCondition = JooqDao.caseInsensitiveLikeRegexNullTrue(AV_LOC.LOCATION_ID, nameRegex); if (officeId != null) { - whereCondition = whereCondition.and(AV_LOC.DB_OFFICE_ID.equalIgnoreCase(officeId)); + whereCondition = whereCondition.and(AV_LOC.DB_OFFICE_ID.eq(officeId.toUpperCase())); } if (unitSystem != null) { @@ -144,7 +140,7 @@ public List getLocationKinds(String idRegexMask, String kind .and(JooqDao.caseInsensitiveLikeRegexNullTrue(AV_LOC.LOCATION_KIND_ID, kindRegexMask)); if (officeId != null) { - whereCondition = whereCondition.and(AV_LOC.DB_OFFICE_ID.equalIgnoreCase(officeId)); + whereCondition = whereCondition.and(AV_LOC.DB_OFFICE_ID.eq(officeId.toUpperCase())); } return dsl.selectDistinct(AV_LOC.LOCATION_ID, AV_LOC.DB_OFFICE_ID, AV_LOC.LOCATION_KIND_ID) @@ -160,14 +156,16 @@ public Location getLocation(String locationName, String unitSystem, String offic } @Override - public Location getLocation(String locationName, String unitSystem, String officeId, boolean includeAliases) { + public Location getLocation(String locationName, String unitSystem, @NotNull String officeId, boolean includeAliases) { + officeId = officeId.toUpperCase(); + if (includeAliases) { List locs = dsl.select(asterisk()) .from(AV_LOC2.AV_LOC2) .leftJoin(AV_LOC_ALIAS) .on(AV_LOC2.AV_LOC2.BASE_LOCATION_ID.eq(AV_LOC_ALIAS.BASE_LOCATION_ID).and( AV_LOC2.AV_LOC2.LOCATION_CODE.eq(AV_LOC_ALIAS.LOCATION_CODE.cast(Long.class)))) - .where(AV_LOC2.AV_LOC2.DB_OFFICE_ID.equalIgnoreCase(officeId) + .where(AV_LOC2.AV_LOC2.DB_OFFICE_ID.eq(officeId) .and(AV_LOC2.AV_LOC2.UNIT_SYSTEM.equalIgnoreCase(unitSystem) .and(AV_LOC2.AV_LOC2.LOCATION_ID.equalIgnoreCase(locationName)))) .fetch(); @@ -179,7 +177,7 @@ public Location getLocation(String locationName, String unitSystem, String offic } else { Record loc = dsl.select(AV_LOC.asterisk()) .from(AV_LOC) - .where(AV_LOC.DB_OFFICE_ID.equalIgnoreCase(officeId) + .where(AV_LOC.DB_OFFICE_ID.eq(officeId) .and(AV_LOC.UNIT_SYSTEM.equalIgnoreCase(unitSystem) .and(AV_LOC.LOCATION_ID.equalIgnoreCase(locationName)))) .fetchOne(); @@ -380,9 +378,16 @@ public FeatureCollection buildFeatureCollection(String names, String units, Stri units = "SI"; } + Condition whereCondition; + if (officeId != null) { + whereCondition = AV_LOC.DB_OFFICE_ID.eq(officeId.toUpperCase()); + } else { + whereCondition = noCondition(); + } + SelectConditionStep selectQuery = dsl.select(asterisk()) .from(AV_LOC) - .where(AV_LOC.DB_OFFICE_ID.eq(officeId)) + .where(whereCondition) .and(AV_LOC.UNIT_SYSTEM.eq(units)); if (names != null && !names.isEmpty()) { diff --git a/cwms-data-api/src/main/java/cwms/cda/data/dao/RatingMetadataDao.java b/cwms-data-api/src/main/java/cwms/cda/data/dao/RatingMetadataDao.java index 25c9cb435..fe4a62236 100644 --- a/cwms-data-api/src/main/java/cwms/cda/data/dao/RatingMetadataDao.java +++ b/cwms-data-api/src/main/java/cwms/cda/data/dao/RatingMetadataDao.java @@ -155,7 +155,7 @@ public Set getRatingIds(String office, String templateIdMask, int offset Condition condition = specView.ALIASED_ITEM.isNull(); if (office != null) { - condition = condition.and(specView.OFFICE_ID.eq(office)); + condition = condition.and(specView.OFFICE_ID.eq(office.toUpperCase())); } if (templateIdMask != null) { diff --git a/cwms-data-api/src/main/java/cwms/cda/data/dao/RatingSpecDao.java b/cwms-data-api/src/main/java/cwms/cda/data/dao/RatingSpecDao.java index 7365bf10c..babf39f73 100644 --- a/cwms-data-api/src/main/java/cwms/cda/data/dao/RatingSpecDao.java +++ b/cwms-data-api/src/main/java/cwms/cda/data/dao/RatingSpecDao.java @@ -453,7 +453,7 @@ private Map> getRatingIds(String office, String templateIdM Condition condition = DSL.noCondition(); if (office != null && !office.isEmpty() && !office.equals("*")) { - condition = condition.and(specView.OFFICE_ID.eq(office)); + condition = condition.and(specView.OFFICE_ID.eq(office.toUpperCase())); } if (templateIdMask != null) { diff --git a/cwms-data-api/src/main/java/cwms/cda/data/dao/RatingTemplateDao.java b/cwms-data-api/src/main/java/cwms/cda/data/dao/RatingTemplateDao.java index cc8bec9c1..c38680376 100644 --- a/cwms-data-api/src/main/java/cwms/cda/data/dao/RatingTemplateDao.java +++ b/cwms-data-api/src/main/java/cwms/cda/data/dao/RatingTemplateDao.java @@ -47,7 +47,6 @@ import org.jooq.Record; import org.jooq.ResultQuery; import org.jooq.SelectForUpdateStep; -import org.jooq.TableField; import org.jooq.conf.ParamType; import usace.cwms.db.jooq.codegen.packages.CWMS_RATING_PACKAGE; @@ -69,7 +68,7 @@ public Set retrieveRatingTemplates(String office, String templat AV_RATING_TEMPLATE tempView = AV_RATING_TEMPLATE.AV_RATING_TEMPLATE; if (office != null) { - condition = condition.and(tempView.OFFICE_ID.eq(office)); + condition = condition.and(tempView.OFFICE_ID.eq(office.toUpperCase())); } if (templateIdMask != null) { @@ -119,7 +118,7 @@ public Optional retrieveRatingTemplate(String office, String tem .and(specView.ALIASED_ITEM.isNull()); if (office != null) { - condition = condition.and(tempView.OFFICE_ID.eq(office)); + condition = condition.and(tempView.OFFICE_ID.eq(office.toUpperCase())); } ResultQuery query = dsl.select( @@ -253,7 +252,7 @@ private Set getRatingTemplates(String office, String templateIdM Condition condition = specView.ALIASED_ITEM.isNull(); if (office != null) { - condition = condition.and(tempView.OFFICE_ID.eq(office)); + condition = condition.and(tempView.OFFICE_ID.eq(office.toUpperCase())); } if (templateIdMask != null) { diff --git a/cwms-data-api/src/main/java/cwms/cda/data/dao/TimeSeriesCategoryDao.java b/cwms-data-api/src/main/java/cwms/cda/data/dao/TimeSeriesCategoryDao.java index 20bd27b84..b153fc029 100644 --- a/cwms-data-api/src/main/java/cwms/cda/data/dao/TimeSeriesCategoryDao.java +++ b/cwms-data-api/src/main/java/cwms/cda/data/dao/TimeSeriesCategoryDao.java @@ -46,7 +46,7 @@ public Optional getTimeSeriesCategory(String officeId, Strin Record3 fetchOne = dsl.selectDistinct(view.CAT_DB_OFFICE_ID, view.TS_CATEGORY_ID, view.TS_CATEGORY_DESC) .from(view) - .where(view.CAT_DB_OFFICE_ID.eq(officeId)) + .where(view.CAT_DB_OFFICE_ID.eq(officeId.toUpperCase())) .and(view.TS_CATEGORY_ID.eq(categoryId)) .fetchOne(); @@ -63,7 +63,7 @@ public List getTimeSeriesCategories(String officeId) { Select select; if ( officeId != null && !officeId.isEmpty()) { - select = step.where(table.CAT_DB_OFFICE_ID.eq(officeId)); + select = step.where(table.CAT_DB_OFFICE_ID.eq(officeId.toUpperCase())); }else { select = step; } diff --git a/cwms-data-api/src/main/java/cwms/cda/data/dao/TimeSeriesDaoImpl.java b/cwms-data-api/src/main/java/cwms/cda/data/dao/TimeSeriesDaoImpl.java index bca30d2b1..6dabcad23 100644 --- a/cwms-data-api/src/main/java/cwms/cda/data/dao/TimeSeriesDaoImpl.java +++ b/cwms-data-api/src/main/java/cwms/cda/data/dao/TimeSeriesDaoImpl.java @@ -21,7 +21,6 @@ import static org.jooq.impl.DSL.select; import static org.jooq.impl.DSL.selectDistinct; -import org.jooq.ConnectionRunnable; import usace.cwms.db.jooq.codegen.tables.AV_CWMS_TS_ID; import static org.jooq.impl.DSL.table; import static usace.cwms.db.jooq.codegen.tables.AV_CWMS_TS_ID2.AV_CWMS_TS_ID2; @@ -65,7 +64,6 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.Set; import java.util.concurrent.TimeUnit; import com.google.common.flogger.FluentLogger; @@ -1040,7 +1038,7 @@ public TsvDqu findMostRecent(String officeId, String tsId, String unit, Condition nestedCondition = view.ALIASED_ITEM.isNull() .and(view.VALUE.isNotNull()) .and(view.CWMS_TS_ID.eq(tsId)) - .and(view.OFFICE_ID.eq(officeId)); + .and(view.OFFICE_ID.eq(officeId.toUpperCase())); if (twoWeeksFromNow != null) { nestedCondition = nestedCondition.and(view.DATE_TIME.lt(twoWeeksFromNow)); @@ -1062,7 +1060,7 @@ public TsvDqu findMostRecent(String officeId, String tsId, String unit, .from(view) .where(view.DATE_TIME.in(maxSelect)) .and(view.CWMS_TS_ID.eq(tsId)) - .and(view.OFFICE_ID.eq(officeId)) + .and(view.OFFICE_ID.eq(officeId.toUpperCase())) .and(view.UNIT_ID.eq(unit)) .and(view.VALUE.isNotNull()) .and(view.ALIASED_ITEM.isNull()) @@ -1133,7 +1131,7 @@ public List findMostRecentsInRange(String office, List tsId // build whereCondition depending on office Condition whereCondition = AV_CWMS_TS_ID2.CWMS_TS_ID.in(tsIds); if (office != null) { - whereCondition = whereCondition.and(AV_CWMS_TS_ID2.DB_OFFICE_ID.eq(office)); + whereCondition = whereCondition.and(AV_CWMS_TS_ID2.DB_OFFICE_ID.eq(office.toUpperCase())); } // create baseIds alias @@ -1285,7 +1283,7 @@ public List findRecentsInRange(String office, String categoryId, St whereCondition = whereCondition.and(AV_TS_GRP_ASSGN.AV_TS_GRP_ASSGN.GROUP_ID.eq(groupId)); } if (office != null) { - whereCondition = whereCondition.and(AV_TS_GRP_ASSGN.AV_TS_GRP_ASSGN.DB_OFFICE_ID.eq(office)); + whereCondition = whereCondition.and(AV_TS_GRP_ASSGN.AV_TS_GRP_ASSGN.DB_OFFICE_ID.eq(office.toUpperCase())); } CommonTableExpression baseIds = name("base_ids").as( diff --git a/cwms-data-api/src/main/java/cwms/cda/data/dao/TimeSeriesGroupDao.java b/cwms-data-api/src/main/java/cwms/cda/data/dao/TimeSeriesGroupDao.java index 45598cd39..a0e96b889 100644 --- a/cwms-data-api/src/main/java/cwms/cda/data/dao/TimeSeriesGroupDao.java +++ b/cwms-data-api/src/main/java/cwms/cda/data/dao/TimeSeriesGroupDao.java @@ -67,7 +67,7 @@ public List getTimeSeriesGroups() { public List getTimeSeriesGroups(String tsOfficeId, String groupOfficeId, String categoryOfficeId) { Condition whereCond = DSL.noCondition(); if (tsOfficeId != null) { - whereCond = AV_TS_CAT_GRP.AV_TS_CAT_GRP.GRP_DB_OFFICE_ID.eq(tsOfficeId); + whereCond = AV_TS_CAT_GRP.AV_TS_CAT_GRP.GRP_DB_OFFICE_ID.eq(tsOfficeId.toUpperCase()); } return getTimeSeriesGroupsWhere(whereCond, tsOfficeId, groupOfficeId, categoryOfficeId); @@ -122,7 +122,7 @@ private List getTimeSeriesGroupsWhere(Condition whereCond, Stri Condition joinCond = catGrp.TS_CATEGORY_ID.eq(grpAssgn.CATEGORY_ID) .and(catGrp.TS_GROUP_ID.eq(grpAssgn.GROUP_ID)); if (tsOfficeId != null) { - joinCond = joinCond.and(grpAssgn.DB_OFFICE_ID.eq(tsOfficeId)); + joinCond = joinCond.and(grpAssgn.DB_OFFICE_ID.eq(tsOfficeId.toUpperCase())); } SelectSeekStep4 getTimeSeriesIdentifier(String o result = dsl.select(view.CWMS_TS_ID, view.DB_OFFICE_ID, view.INTERVAL, view.TIME_ZONE_ID, view.TS_ACTIVE_FLAG) .from(view) - .where(view.CWMS_TS_ID.eq(timeseriesId).and(view.DB_OFFICE_ID.eq(office))).fetchOne(); + .where(view.CWMS_TS_ID.eq(timeseriesId).and(view.DB_OFFICE_ID.eq(office.toUpperCase()))).fetchOne(); Optional retval = Optional.empty(); if (result != null) { retval = Optional.of(toDto(result)); diff --git a/cwms-data-api/src/main/java/cwms/cda/data/dao/project/ProjectDao.java b/cwms-data-api/src/main/java/cwms/cda/data/dao/project/ProjectDao.java index 8b670c34e..4d3783673 100644 --- a/cwms-data-api/src/main/java/cwms/cda/data/dao/project/ProjectDao.java +++ b/cwms-data-api/src/main/java/cwms/cda/data/dao/project/ProjectDao.java @@ -142,6 +142,12 @@ public Projects retrieveProjects(String cursor, @Nullable String office, @Nullab final String cursorOffice; final String cursorProjectId; int total; + + if(office != null){ + office = office.toUpperCase(); + } + String finalOffice = office; + if (cursor == null || cursor.isEmpty()) { cursorOffice = null; cursorProjectId = null; @@ -149,8 +155,8 @@ public Projects retrieveProjects(String cursor, @Nullable String office, @Nullab Condition whereClause = JooqDao.caseInsensitiveLikeRegexNullTrue(AV_PROJECT.AV_PROJECT.PROJECT_ID, projectIdMask); - if (office != null) { - whereClause = whereClause.and(AV_PROJECT.AV_PROJECT.OFFICE_ID.eq(office)); + if (finalOffice != null) { + whereClause = whereClause.and(AV_PROJECT.AV_PROJECT.OFFICE_ID.eq(finalOffice)); } SelectConditionStep> count = @@ -168,13 +174,13 @@ public Projects retrieveProjects(String cursor, @Nullable String office, @Nullab // There are lots of ways the variables can be null or not so we need to build the query // based on the parameters. - String query = buildTableQuery(office, projectIdMask, cursorOffice != null || cursorProjectId != null); + String query = buildTableQuery(finalOffice, projectIdMask, cursorOffice != null || cursorProjectId != null); int finalPageSize = pageSize; List projs = connectionResult(dsl, c -> { List projects; try (PreparedStatement ps = c.prepareStatement(query)) { - fillTableQueryParameters(ps, cursorOffice, cursorProjectId, office, projectIdMask, finalPageSize); + fillTableQueryParameters(ps, cursorOffice, cursorProjectId, finalOffice, projectIdMask, finalPageSize); try (ResultSet resultSet = ps.executeQuery()) { projects = new ArrayList<>(); diff --git a/cwms-data-api/src/test/resources/ratings_db.txt b/cwms-data-api/src/test/resources/ratings_db.txt index ea69c920d..b690a8609 100644 --- a/cwms-data-api/src/test/resources/ratings_db.txt +++ b/cwms-data-api/src/test/resources/ratings_db.txt @@ -60,7 +60,7 @@ select "CWMS_20"."AV_OFFICE"."OFFICE_ID", "CWMS_20"."AV_CLOB".* from "CWMS_20"." > ----------------------------------------------------------------------------------------------------------------------------------------------------------------- > { "fields": [ {"name": "location", "type": "object"} ], "records": [ [ [{ "base_location_id": "Alder Springs", "sub_location_id": null, "office_id": "SPK" }, "CA", "Glenn", "PST8PDT", null, 0, 0, "WSG84", 30.48, "m", "NAVD88", "Alder Springs", "Alder Springs", "Climate Gage", "T", "SITE", null, null, null, null, null, "UNITED STATES", "Persque Isle"] ] ]} @ rows: 1 -select "CWMS_20"."AV_LOC".* from "CWMS_20"."AV_LOC" where (lower("CWMS_20"."AV_LOC"."DB_OFFICE_ID") = lower(?) and lower("CWMS_20"."AV_LOC"."UNIT_SYSTEM") = lower(?) and lower("CWMS_20"."AV_LOC"."LOCATION_ID") = lower(?)); +select "CWMS_20"."AV_LOC".* from "CWMS_20"."AV_LOC" where ("CWMS_20"."AV_LOC"."DB_OFFICE_ID" = ? and lower("CWMS_20"."AV_LOC"."UNIT_SYSTEM") = lower(?) and lower("CWMS_20"."AV_LOC"."LOCATION_ID") = lower(?)); > LOCATION_CODE BASE_LOCATION_CODE DB_OFFICE_ID BASE_LOCATION_ID SUB_LOCATION_ID LOCATION_ID LOCATION_TYPE UN ELEVATION UNIT_ID VERTICAL_DATUM LONGITUDE LATITUDE HORIZONTAL_DATUM TIME_ZONE_NAME COUNTY_NAME ST PUBLIC_NAME LONG_NAME DESCRIPTION B L LOCATION_KIND_ID MAP_LABEL PUBLISHED_LATITUDE PUBLISHED_LONGITUDE BOUNDING_OFFICE_ NATION_ID NEAREST_CITY A > ------------- ------------------ ---------------- ------------------------ -------------------------------- --------------------------------------------------------- -------------------------------- -- ---------- -------- ---------------- ---------- ---------- ---------------- ---------------------------- ---------------------------------------- -- --------------------------------------------------------- -------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - - -------------------------------- -------------------------------------------------- ------------------ ------------------- ---------------- ------------------------------------------------ -------------------------------------------------- - > 0 0 SPK Alder Springs {null} Alder Springs {null} EN 1.0E+002 ft NAVD88 0 0 WGS84 PST8PDT Glenn CA Alder Springs Alder Springs climate gage T T SITE {null} {null} {null} {null} UNITED STATES Presque Isle T