2525package cwms .cda .data .dao ;
2626
2727import static com .google .common .flogger .LazyArgs .lazy ;
28-
2928import static java .util .stream .Collectors .toList ;
3029import static mil .army .usace .hec .metadata .IntervalFactory .equalsName ;
3130import static mil .army .usace .hec .metadata .IntervalFactory .isRegular ;
3231import static org .jooq .impl .DSL .asterisk ;
3332import static org .jooq .impl .DSL .field ;
3433import static usace .cwms .db .jooq .codegen .tables .AV_LOC_ALIAS .AV_LOC_ALIAS ;
3534
35+ import com .google .common .flogger .FluentLogger ;
3636import cwms .cda .api .enums .UnitSystem ;
3737import cwms .cda .api .enums .VersionType ;
3838import cwms .cda .api .errors .NotFoundException ;
7373import java .util .Objects ;
7474import java .util .Optional ;
7575import java .util .Set ;
76- import com .google .common .flogger .FluentLogger ;
7776import java .util .concurrent .TimeUnit ;
7877import java .util .regex .Pattern ;
7978import java .util .stream .Stream ;
80-
8179import mil .army .usace .hec .metadata .Interval ;
8280import mil .army .usace .hec .metadata .IntervalFactory ;
8381import mil .army .usace .hec .metadata .constants .NumericalConstants ;
106104import usace .cwms .db .jooq .codegen .udt .records .STR_TAB_TAB_T ;
107105import usace .cwms .db .jooq .codegen .udt .records .ZTSV_ARRAY ;
108106import usace .cwms .db .jooq .codegen .udt .records .ZTSV_TYPE ;
109- import usace .cwms .db .jooq .codegen_latest .tables .AV_LOCATION_LEVEL_VALUES ;
110107import usace .cwms .db .jooq .codegen_latest .tables .AV_LOCATION_LEVEL_REF ;
108+ import usace .cwms .db .jooq .codegen_latest .tables .AV_LOCATION_LEVEL_VALUES ;
111109
112110public class LocationLevelsDaoImpl extends JooqDao <LocationLevel > implements LocationLevelsDao {
113111 private static final FluentLogger logger = FluentLogger .forEnclosingClass ();
@@ -124,9 +122,6 @@ public class LocationLevelsDaoImpl extends JooqDao<LocationLevel> implements Loc
124122
125123 private static final String TABLE_ALIAS1 = "T1" ;
126124 private static final String TABLE_ALIAS2 = "T2" ;
127- private static final String ALIASED_ATTRIBUTE_ID = TABLE_ALIAS1 + ".ATTRIBUTE_ID" ;
128- private static final String ALIASED_LOCATION_LEVEL_ID = TABLE_ALIAS1 + ".LOCATION_LEVEL_ID" ;
129- private static final String ALIASED_OFFICE_ID = TABLE_ALIAS1 + ".OFFICE_ID" ;
130125
131126 static {
132127 buildLocationLevelSelectFields ();
@@ -183,17 +178,17 @@ public LocationLevels getLocationLevels(String cursor, int pageSize,
183178 AV_LOCATION_LEVEL_REF ref = AV_LOCATION_LEVEL_REF .AV_LOCATION_LEVEL_REF ;
184179 AV_LOCATION_LEVEL_VALUES values = AV_LOCATION_LEVEL_VALUES .AV_LOCATION_LEVEL_VALUES ;
185180
186- Condition whereCondition = mapping .getLocationLevelId (TABLE_ALIAS1 , ref ).isNotNull ();
181+ Condition whereCondition = mapping .getLocationLevelId (null , ref ).isNotNull ();
187182 Condition standardWhereCondition = ref .LOCATION_LEVEL_ID .isNotNull ();
188183
189184 if (office != null && !office .isEmpty ()) {
190- whereCondition = whereCondition .and (mapping .getOfficeId (TABLE_ALIAS1 , ref ).eq (office .toUpperCase ()));
185+ whereCondition = whereCondition .and (mapping .getOfficeId (null , ref ).eq (office .toUpperCase ()));
191186 standardWhereCondition = standardWhereCondition .and (DSL .upper (ref .OFFICE_ID ).eq (office .toUpperCase ()));
192187 }
193188
194189 if (levelIdMask != null && !levelIdMask .isEmpty ()) {
195190 whereCondition = whereCondition .and (
196- JooqDao .caseInsensitiveLikeRegex (mapping .getLocationLevelId (TABLE_ALIAS1 , ref ), levelIdMask ));
191+ JooqDao .caseInsensitiveLikeRegex (mapping .getLocationLevelId (null , ref ), levelIdMask ));
197192 standardWhereCondition = standardWhereCondition .and (
198193 JooqDao .caseInsensitiveLikeRegex (ref .LOCATION_LEVEL_ID , levelIdMask ));
199194 }
@@ -215,16 +210,14 @@ public LocationLevels getLocationLevels(String cursor, int pageSize,
215210
216211 if (includeAliases ) {
217212 query = dsl .select (asterisk ()).from (dsl .selectDistinct (LOCATION_ALIAS_FIELDS )
218- .from (dsl
219- .select (asterisk ())
220213 .from (ref )
214+ .join (values )
215+ .on (ref .LOCATION_LEVEL_CODE .eq (values .LOCATION_LEVEL_CODE .cast (Long .class )))
221216 .leftJoin (aliasView )
222217 .on (ref .OFFICE_ID .eq (aliasView .DB_OFFICE_ID ))
223218 .and (ref .LOCATION_ID .eq (aliasView .LOCATION_ID ))
224- .and (ref .LOCATION_CODE .eq (aliasView .LOCATION_CODE .cast (Long .class ))).asTable (TABLE_ALIAS1 ))
225- .fullOuterJoin (values )
226- .on (mapping .getLocationLevelCode ().eq (values .LOCATION_LEVEL_CODE .cast (Long .class )))
227- .where (whereCondition ).asTable (TABLE_ALIAS2 ))
219+ .and (ref .LOCATION_CODE .eq (aliasView .LOCATION_CODE .cast (Long .class )))
220+ .where (whereCondition ))
228221 .orderBy (mapping .getOfficeId (null , null ), mapping .getLocationLevelId (null , null ),
229222 field ("LOCATION_LEVEL_DATE" ), field ("CALENDAR_OFFSET" ), field ("TIME_OFFSET" )
230223 )
@@ -738,7 +731,7 @@ private void parseLevels(Record r, Map<LevelLookup, LocationLevel.Builder> build
738731 levelZdt = ZonedDateTime .ofInstant (levelDate .toInstant (), ZoneId .of ("UTC" ));
739732 }
740733
741- Double seasonalLevel = r .get (siUnits ? mapping .getSeasonalLevelSI () : mapping .getSeasonalLevelSI ());
734+ Double seasonalLevel = r .get (siUnits ? mapping .getSeasonalLevelSI () : mapping .getSeasonalLevelEN ());
742735 Double constantLevel = r .get (siUnits ? mapping .getConstantLevelSI () : mapping .getConstantLevelEN ());
743736 String tsId = r .get (mapping .getTsId ());
744737 String interp = r .get (mapping .getInterpolate ());
@@ -1235,144 +1228,147 @@ public Field<Timestamp> getIntervalOrigin() {
12351228 }
12361229
12371230 private static final class AliasedLocationParserFieldMapping implements LocationParserFieldMapping {
1231+ AV_LOCATION_LEVEL_REF ref = AV_LOCATION_LEVEL_REF .AV_LOCATION_LEVEL_REF ;
1232+ AV_LOCATION_LEVEL_VALUES values = AV_LOCATION_LEVEL_VALUES .AV_LOCATION_LEVEL_VALUES ;
1233+
12381234 @ Override
12391235 public Field <Timestamp > getLevelDate () {
1240- return DSL . field ( DSL . name ( TABLE_ALIAS2 , " LOCATION_LEVEL_DATE" ), Timestamp . class ) ;
1236+ return ref . LOCATION_LEVEL_DATE ;
12411237 }
12421238
12431239 @ Override
12441240 public Field <String > getAttributeId () {
1245- return DSL . field ( DSL . name ( TABLE_ALIAS2 , ALIASED_ATTRIBUTE_ID ), String . class ) ;
1241+ return ref . ATTRIBUTE_ID ;
12461242 }
12471243
12481244 @ Override
12491245 public Field <Double > getAttributeValueEN () {
1250- return DSL . field ( DSL . name ( TABLE_ALIAS2 , " ATTRIBUTE_VALUE_EN" ), Double . class ) ;
1246+ return values . ATTRIBUTE_VALUE_EN ;
12511247 }
12521248
12531249 @ Override
12541250 public Field <Double > getAttributeValueSI () {
1255- return DSL . field ( DSL . name ( TABLE_ALIAS2 , " ATTRIBUTE_VALUE_SI" ), Double . class ) ;
1251+ return values . ATTRIBUTE_VALUE_SI ;
12561252 }
12571253
12581254 @ Override
12591255 public Field <String > getLocationLevelId () {
1260- return DSL . field ( DSL . name ( TABLE_ALIAS2 , ALIASED_LOCATION_LEVEL_ID ), String . class ) ;
1256+ return ref . LOCATION_LEVEL_ID ;
12611257 }
12621258
12631259 @ Override
12641260 public Field <String > getOfficeId () {
1265- return DSL . field ( DSL . name ( TABLE_ALIAS2 , ALIASED_OFFICE_ID ), String . class ) ;
1261+ return ref . OFFICE_ID ;
12661262 }
12671263
12681264 @ Override
12691265 public Field <String > getLevelUnitEN () {
1270- return DSL . field ( DSL . name ( TABLE_ALIAS2 , " LEVEL_UNIT_EN" ), String . class ) ;
1266+ return values . LEVEL_UNIT_EN ;
12711267 }
12721268
12731269 @ Override
12741270 public Field <String > getLevelUnitSI () {
1275- return DSL . field ( DSL . name ( TABLE_ALIAS2 , " LEVEL_UNIT_SI" ), String . class ) ;
1271+ return values . LEVEL_UNIT_SI ;
12761272 }
12771273
12781274 @ Override
12791275 public Field <String > getAttributeUnitEN () {
1280- return DSL . field ( DSL . name ( TABLE_ALIAS2 , " ATTRIBUTE_UNIT_EN" ), String . class ) ;
1276+ return values . ATTRIBUTE_UNIT_EN ;
12811277 }
12821278
12831279 @ Override
12841280 public Field <String > getAttributeUnitSI () {
1285- return DSL . field ( DSL . name ( TABLE_ALIAS2 , " ATTRIBUTE_UNIT_SI" ), String . class ) ;
1281+ return values . ATTRIBUTE_UNIT_SI ;
12861282 }
12871283
12881284 @ Override
12891285 public Field <String > getConnections () {
1290- return DSL . field ( DSL . name ( TABLE_ALIAS2 , " CONNECTIONS" ), String . class ) ;
1286+ return values . CONNECTIONS ;
12911287 }
12921288
12931289 @ Override
12941290 public Field <Timestamp > getExpirationDate () {
1295- return DSL . field ( DSL . name ( TABLE_ALIAS2 , " EXPIRATION_DATE" ), Timestamp . class ) ;
1291+ return ref . EXPIRATION_DATE ;
12961292 }
12971293
12981294 @ Override
12991295 public Field <String > getAttrUnitEn () {
1300- return DSL . field ( DSL . name ( TABLE_ALIAS2 , " ATTRIBUTE_UNIT_EN" ), String . class ) ;
1296+ return values . ATTRIBUTE_UNIT_EN ;
13011297 }
13021298
13031299 @ Override
13041300 public Field <Double > getAttrValueEn () {
1305- return DSL . field ( DSL . name ( TABLE_ALIAS2 , " ATTRIBUTE_VALUE_EN" ), Double . class ) ;
1301+ return values . ATTRIBUTE_VALUE_EN ;
13061302 }
13071303
13081304 @ Override
13091305 public Field <String > getAttrUnitSi () {
1310- return DSL . field ( DSL . name ( TABLE_ALIAS2 , " ATTRIBUTE_UNIT_SI" ), String . class ) ;
1306+ return values . ATTRIBUTE_UNIT_SI ;
13111307 }
13121308
13131309 @ Override
13141310 public Field <Double > getAttrValueSi () {
1315- return DSL . field ( DSL . name ( TABLE_ALIAS2 , " ATTRIBUTE_VALUE_SI" ), Double . class ) ;
1311+ return values . ATTRIBUTE_VALUE_SI ;
13161312 }
13171313
13181314 @ Override
13191315 public Field <Double > getSeasonalLevelEN () {
1320- return DSL . field ( DSL . name ( TABLE_ALIAS2 , " SEASONAL_VALUE_EN" ), Double . class ) ;
1316+ return values . SEASONAL_VALUE_EN ;
13211317 }
13221318
13231319 @ Override
13241320 public Field <Double > getSeasonalLevelSI () {
1325- return DSL . field ( DSL . name ( TABLE_ALIAS2 , " SEASONAL_VALUE_SI" ), Double . class ) ;
1321+ return values . SEASONAL_VALUE_SI ;
13261322 }
13271323
13281324 @ Override
13291325 public Field <Double > getConstantLevelEN () {
1330- return DSL . field ( DSL . name ( TABLE_ALIAS2 , " CONSTANT_LEVEL_EN" ), Double . class ) ;
1326+ return values . CONSTANT_LEVEL_EN ;
13311327 }
13321328
13331329 @ Override
13341330 public Field <Double > getConstantLevelSI () {
1335- return DSL . field ( DSL . name ( TABLE_ALIAS2 , " CONSTANT_LEVEL_SI" ), Double . class ) ;
1331+ return values . CONSTANT_LEVEL_SI ;
13361332 }
13371333
13381334 @ Override
13391335 public Field <String > getTsId () {
1340- return DSL . field ( DSL . name ( TABLE_ALIAS2 , " TSID" ), String . class ) ;
1336+ return values . TSID ;
13411337 }
13421338
13431339 @ Override
13441340 public Field <String > getInterpolate () {
1345- return DSL . field ( DSL . name ( TABLE_ALIAS2 , " INTERPOLATE" ), String . class ) ;
1341+ return values . INTERPOLATE ;
13461342 }
13471343
13481344 @ Override
13491345 public Field <YearToMonth > getCalendarOffset () {
1350- return DSL . field ( DSL . name ( TABLE_ALIAS2 , " CALENDAR_OFFSET" ), YearToMonth . class ) ;
1346+ return values . CALENDAR_OFFSET ;
13511347 }
13521348
13531349 @ Override
13541350 public Field <DayToSecond > getTimeOffset () {
1355- return DSL . field ( DSL . name ( TABLE_ALIAS2 , " TIME_OFFSET" ), DayToSecond . class ) ;
1351+ return values . TIME_OFFSET ;
13561352 }
13571353
13581354 @ Override
13591355 public Field <String > getLevelComment () {
1360- return DSL . field ( DSL . name ( TABLE_ALIAS2 , " LOCATION_LEVEL_COMMENT" ), String . class ) ;
1356+ return ref . LOCATION_LEVEL_COMMENT ;
13611357 }
13621358
13631359 @ Override
13641360 public Field <DayToSecond > getTimeInterval () {
1365- return DSL . field ( DSL . name ( TABLE_ALIAS2 , " TIME_INTERVAL" ), DayToSecond . class ) ;
1361+ return values . TIME_INTERVAL ;
13661362 }
13671363
13681364 @ Override
13691365 public Field <YearToMonth > getCalendarInterval () {
1370- return DSL . field ( DSL . name ( TABLE_ALIAS2 , " CALENDAR_INTERVAL" ), YearToMonth . class ) ;
1366+ return values . CALENDAR_INTERVAL ;
13711367 }
13721368
13731369 @ Override
13741370 public Field <Timestamp > getIntervalOrigin () {
1375- return DSL . field ( DSL . name ( TABLE_ALIAS2 , " INTERVAL_ORIGIN" ), Timestamp . class ) ;
1371+ return values . INTERVAL_ORIGIN ;
13761372 }
13771373 }
13781374
@@ -1414,17 +1410,17 @@ private static void buildAliasedLocationLevelSelectFields() {
14141410 AV_LOCATION_LEVEL_REF ref = AV_LOCATION_LEVEL_REF .AV_LOCATION_LEVEL_REF ;
14151411 AV_LOCATION_LEVEL_VALUES values = AV_LOCATION_LEVEL_VALUES .AV_LOCATION_LEVEL_VALUES ;
14161412
1417- LOCATION_ALIAS_FIELDS .add (field (ALIASED_OFFICE_ID ));
1418- LOCATION_ALIAS_FIELDS .add (field (ALIASED_LOCATION_LEVEL_ID ));
1419- LOCATION_ALIAS_FIELDS .add (field (ALIASED_ATTRIBUTE_ID ));
1413+ LOCATION_ALIAS_FIELDS .add (field (ref . OFFICE_ID . getUnqualifiedName () ));
1414+ LOCATION_ALIAS_FIELDS .add (field (ref . LOCATION_LEVEL_ID . getUnqualifiedName () ));
1415+ LOCATION_ALIAS_FIELDS .add (field (ref . ATTRIBUTE_ID . getUnqualifiedName () ));
14201416 LOCATION_ALIAS_FIELDS .add (field (ref .LOCATION_LEVEL_DATE .getUnqualifiedName ()));
14211417 LOCATION_ALIAS_FIELDS .add (field (values .CONNECTIONS .getUnqualifiedName ()));
1422- LOCATION_ALIAS_FIELDS .add (field (DSL . name ( TABLE_ALIAS1 , " DURATION_ID" )));
1418+ LOCATION_ALIAS_FIELDS .add (field (ref . DURATION_ID . getUnqualifiedName ( )));
14231419 LOCATION_ALIAS_FIELDS .add (field (values .ATTRIBUTE_UNIT_EN .getUnqualifiedName ()));
14241420 LOCATION_ALIAS_FIELDS .add (field (values .ATTRIBUTE_VALUE_EN .getUnqualifiedName ()));
14251421 LOCATION_ALIAS_FIELDS .add (field (values .ATTRIBUTE_UNIT_SI .getUnqualifiedName ()));
14261422 LOCATION_ALIAS_FIELDS .add (field (values .ATTRIBUTE_VALUE_SI .getUnqualifiedName ()));
1427- LOCATION_ALIAS_FIELDS .add (field (DSL . name ( TABLE_ALIAS1 , " EXPIRATION_DATE" ) ));
1423+ LOCATION_ALIAS_FIELDS .add (field (ref . EXPIRATION_DATE ));
14281424 LOCATION_ALIAS_FIELDS .add (field (values .TSID .getUnqualifiedName ()));
14291425 LOCATION_ALIAS_FIELDS .add (field (values .CONSTANT_LEVEL_EN .getUnqualifiedName ()));
14301426 LOCATION_ALIAS_FIELDS .add (field (values .CONSTANT_LEVEL_SI .getUnqualifiedName ()));
@@ -1439,9 +1435,9 @@ private static void buildAliasedLocationLevelSelectFields() {
14391435 LOCATION_ALIAS_FIELDS .add (field (values .TIME_INTERVAL .getUnqualifiedName ()));
14401436 LOCATION_ALIAS_FIELDS .add (field (values .CALENDAR_OFFSET .getUnqualifiedName ()));
14411437 LOCATION_ALIAS_FIELDS .add (field (values .TIME_OFFSET .getUnqualifiedName ()));
1442- LOCATION_ALIAS_FIELDS .add (field (aliasView .LOCATION_ID . getUnqualifiedName () ));
1438+ LOCATION_ALIAS_FIELDS .add (field (aliasView .LOCATION_ID ));
14431439 LOCATION_ALIAS_FIELDS .add (field (aliasView .ALIAS_ID .getUnqualifiedName ()));
1444- LOCATION_ALIAS_FIELDS .add (field (aliasView .LOCATION_CODE . getUnqualifiedName () ));
1440+ LOCATION_ALIAS_FIELDS .add (field (aliasView .LOCATION_CODE ));
14451441 LOCATION_ALIAS_FIELDS .add (field (aliasView .DB_OFFICE_ID .getUnqualifiedName ()));
14461442 LOCATION_ALIAS_FIELDS .add (field (aliasView .CATEGORY_ID .getUnqualifiedName ()));
14471443 LOCATION_ALIAS_FIELDS .add (field (aliasView .GROUP_ID .getUnqualifiedName ()));
0 commit comments