-
Notifications
You must be signed in to change notification settings - Fork 354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: Fix the table population problem when the skip outliers switch is activated/deactivated #16037
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,14 +37,18 @@ | |
import java.io.IOException; | ||
import javax.servlet.http.HttpServletResponse; | ||
import lombok.AllArgsConstructor; | ||
import org.hisp.dhis.analytics.common.TableInfoReader; | ||
import org.hisp.dhis.analytics.outlier.data.OutlierQueryParams; | ||
import org.hisp.dhis.analytics.outlier.data.OutlierQueryParser; | ||
import org.hisp.dhis.analytics.outlier.data.OutlierRequest; | ||
import org.hisp.dhis.analytics.outlier.data.OutlierRequestValidator; | ||
import org.hisp.dhis.analytics.outlier.service.AnalyticsOutlierService; | ||
import org.hisp.dhis.common.DhisApiVersion; | ||
import org.hisp.dhis.common.Grid; | ||
import org.hisp.dhis.common.IllegalQueryException; | ||
import org.hisp.dhis.common.OpenApi; | ||
import org.hisp.dhis.feedback.ErrorCode; | ||
import org.hisp.dhis.feedback.ErrorMessage; | ||
import org.hisp.dhis.webapi.mvc.annotation.ApiVersion; | ||
import org.hisp.dhis.webapi.utils.ContextUtils; | ||
import org.springframework.security.access.prepost.PreAuthorize; | ||
|
@@ -68,19 +72,22 @@ public class AnalyticsOutlierDetectionController { | |
private final ContextUtils contextUtils; | ||
private final OutlierQueryParser queryParser; | ||
private final OutlierRequestValidator validator; | ||
private final TableInfoReader tableInfoReader; | ||
|
||
@PreAuthorize("hasRole('ALL') or hasRole('F_PERFORM_ANALYTICS_EXPLAIN')") | ||
@GetMapping( | ||
value = RESOURCE_PATH + "/explain", | ||
produces = {APPLICATION_JSON_VALUE, "application/javascript"}) | ||
public @ResponseBody Grid getExplainOutliersJson(OutlierQueryParams query) { | ||
checkAnalyticsTableForOutliers(); | ||
OutlierRequest request = getFromQuery(query, true); | ||
|
||
return outlierService.getOutliersPerformanceMetrics(request); | ||
} | ||
|
||
@GetMapping(value = RESOURCE_PATH, produces = APPLICATION_JSON_VALUE) | ||
public Grid getOutliersJson(OutlierQueryParams queryParams) { | ||
checkAnalyticsTableForOutliers(); | ||
OutlierRequest request = getFromQuery(queryParams, false); | ||
|
||
Grid grid = outlierService.getOutliers(request); | ||
|
@@ -95,6 +102,7 @@ public Grid getOutliersJson(OutlierQueryParams queryParams) { | |
@GetMapping(value = RESOURCE_PATH + ".csv") | ||
public void getOutliersCsv(OutlierQueryParams queryParams, HttpServletResponse response) | ||
throws IOException { | ||
checkAnalyticsTableForOutliers(); | ||
OutlierRequest request = getFromQuery(queryParams, false); | ||
contextUtils.configureResponse(response, CONTENT_TYPE_CSV, NO_CACHE, "outlierdata.csv", true); | ||
|
||
|
@@ -104,6 +112,7 @@ public void getOutliersCsv(OutlierQueryParams queryParams, HttpServletResponse r | |
@GetMapping(value = RESOURCE_PATH + ".xml") | ||
public void getOutliersXml(OutlierQueryParams queryParams, HttpServletResponse response) | ||
throws IOException { | ||
checkAnalyticsTableForOutliers(); | ||
OutlierRequest request = getFromQuery(queryParams, false); | ||
contextUtils.configureResponse(response, CONTENT_TYPE_XML, NO_CACHE); | ||
|
||
|
@@ -113,6 +122,7 @@ public void getOutliersXml(OutlierQueryParams queryParams, HttpServletResponse r | |
@GetMapping(value = RESOURCE_PATH + ".xls") | ||
public void getOutliersXls(OutlierQueryParams queryParams, HttpServletResponse response) | ||
throws IOException { | ||
checkAnalyticsTableForOutliers(); | ||
OutlierRequest request = getFromQuery(queryParams, false); | ||
contextUtils.configureResponse(response, CONTENT_TYPE_EXCEL, NO_CACHE, "outlierdata.xls", true); | ||
|
||
|
@@ -122,6 +132,7 @@ public void getOutliersXls(OutlierQueryParams queryParams, HttpServletResponse r | |
@GetMapping(value = RESOURCE_PATH + ".html") | ||
public void getOutliersHtml(OutlierQueryParams queryParams, HttpServletResponse response) | ||
throws IOException { | ||
checkAnalyticsTableForOutliers(); | ||
OutlierRequest request = getFromQuery(queryParams, false); | ||
|
||
contextUtils.configureResponse(response, CONTENT_TYPE_HTML, NO_CACHE); | ||
|
@@ -132,6 +143,7 @@ public void getOutliersHtml(OutlierQueryParams queryParams, HttpServletResponse | |
@GetMapping(value = RESOURCE_PATH + ".html+css") | ||
public void getOutliersHtmlCss(OutlierQueryParams queryParams, HttpServletResponse response) | ||
throws IOException { | ||
checkAnalyticsTableForOutliers(); | ||
OutlierRequest request = getFromQuery(queryParams, false); | ||
contextUtils.configureResponse(response, CONTENT_TYPE_HTML, NO_CACHE); | ||
|
||
|
@@ -144,4 +156,11 @@ private OutlierRequest getFromQuery(OutlierQueryParams queryParams, boolean anal | |
|
||
return request; | ||
} | ||
|
||
private void checkAnalyticsTableForOutliers() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be nice to have a e2e to test this error. Please see the class There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. e2e is coming, there are no e2e for outliers at all now There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, if you prefer to add it as part of all others e2e for Outliers is fine. Just please add a TODO in the class There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
if (tableInfoReader.getInfo("analytics").getColumns().stream() | ||
.noneMatch("sourceid"::equalsIgnoreCase)) { | ||
throw new IllegalQueryException(new ErrorMessage(ErrorCode.E7180)); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method should be moved to the class
AnalyticsOutlierService
, with a proper Javadoc.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done