Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cwms-data-api/src/main/java/cwms/cda/data/dao/BlobDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public Optional<Blob> getByUniqueName(String id, String limitToOffice) {
ResultQuery<Record> 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);
}
Expand Down Expand Up @@ -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);
Expand Down
88 changes: 44 additions & 44 deletions cwms-data-api/src/main/java/cwms/cda/data/dao/ClobDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public Optional<Clob> 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<Record, Clob> mapper = joinRecord ->
Expand All @@ -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<Record1<Integer>> 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<Integer> rec = count.fetchOne();
if(rec != null) {
if (rec != null) {
total = rec.value1();
}
} else {
Expand All @@ -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<Record4<String, String, String, String>> 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);
Expand Down Expand Up @@ -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
Expand All @@ -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)
);
}

Expand All @@ -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) {
Expand All @@ -235,15 +235,15 @@ 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()) {
if (resultSet.next()) {
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();
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,12 @@ private static Map<String, String> mapFromJson(String forecastInfo) {
}

public List<ForecastInstance> 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) -> {
Expand Down Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -111,11 +111,11 @@ private static ForecastSpec map(Record7<String, String, String, String, String,
.build();
}

public ForecastSpec getForecastSpec(String office, String name, String designator) {
public ForecastSpec getForecastSpec(@NotNull String office, String name, String designator) {
AV_FCST_SPEC spec = AV_FCST_SPEC.AV_FCST_SPEC;
SelectConditionStep<Record7<String, String, String, String, String, String, String>> 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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -57,17 +59,17 @@ public List<LocationCategory> 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<LocationCategory> getLocationCategory(String officeId, String categoryId) {
public Optional<LocationCategory> getLocationCategory(@NotNull String officeId, String categoryId) {
AV_LOC_CAT_GRP table = AV_LOC_CAT_GRP.AV_LOC_CAT_GRP;

Record3<String, String, String> 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 ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public LocationGroupDao(DSLContext dsl) {
*/
public Optional<LocationGroup> getLocationGroup(@NotNull String officeId, @NotNull String categoryId,
@NotNull String groupId) {
officeId = officeId.toUpperCase();

Condition joinCondition;
if (CWMS.equalsIgnoreCase(officeId)) {
Expand Down Expand Up @@ -344,6 +345,7 @@ public List<LocationGroup> 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))
Expand Down Expand Up @@ -382,11 +384,11 @@ private List<LocationGroup> 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()) {
Expand Down Expand Up @@ -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))))
Expand Down
27 changes: 16 additions & 11 deletions cwms-data-api/src/main/java/cwms/cda/data/dao/LocationsDaoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -118,7 +114,7 @@ public List<Location> 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) {
Expand All @@ -144,7 +140,7 @@ public List<CwmsIdLocationKind> 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)
Expand All @@ -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<Record> 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();
Expand All @@ -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();
Expand Down Expand Up @@ -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<Record> 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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public Set<String> 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) {
Expand Down
Loading
Loading