Skip to content

Commit

Permalink
Add measure def existence check
Browse files Browse the repository at this point in the history
  • Loading branch information
smailliwcs committed Feb 22, 2024
1 parent 1799a09 commit 18543dc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,7 @@ private void checkMeasureIdentifier(ListResource list) {
}
Identifier measureIdentifier = list.getIdentifier().get(0);

MeasureDefinition measureDefinition = this.sharedService.getMeasureDefinition(measureIdentifier.getValue());

if (measureDefinition == null) {
if (this.sharedService.measureDefinitionExists(measureIdentifier.getValue())) {
String msg = String.format("Measure %s (%s) not found on data store", measureIdentifier.getValue(), measureIdentifier.getSystem());
logger.error(msg);
throw new ResponseStatusException(HttpStatus.NOT_FOUND, msg);
Expand Down
19 changes: 19 additions & 0 deletions core/src/main/java/com/lantanagroup/link/db/SharedService.java
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,25 @@ public void saveTenantConfig(Tenant tenant){
}
}

public boolean measureDefinitionExists(String measureId) {
try (Connection conn = this.getSQLConnection()) {
assert conn != null;

PreparedStatement ps = conn.prepareStatement("SELECT COUNT(*) FROM [dbo].[measureDef] WHERE measureId = ?");
ps.setNString(1, measureId);

ResultSet rs = ps.executeQuery();

if (rs.next()) {
return rs.getInt(1) > 0;
}

return false;
} catch (SQLException | NullPointerException e) {
throw new RuntimeException(e);
}
}

public MeasureDefinition getMeasureDefinition(String measureId) {
try (Connection conn = this.getSQLConnection()) {
assert conn != null;
Expand Down

0 comments on commit 18543dc

Please sign in to comment.