use of de.metas.ui.web.window.model.DocumentQueryOrderBy in project metasfresh-webui-api by metasfresh.
the class SqlViewSelectionQueryBuilder method buildSqlCreateSelectionFromSelectionLines.
public SqlAndParams buildSqlCreateSelectionFromSelectionLines(final ViewEvaluationCtx viewEvalCtx, final ViewId newViewId, final List<DocumentQueryOrderBy> orderBys) {
final String lineTableName = getTableName();
final String lineTableAlias = getTableAlias();
final SqlViewKeyColumnNamesMap keyColumnNamesMap = getSqlViewKeyColumnNamesMap();
final String lineKeyColumnName = keyColumnNamesMap.getSingleKeyColumnName();
final SqlOrderByBindings sqlOrderByBindings = fieldName -> {
if (keyColumnNamesMap.isKeyPartFieldName(fieldName)) {
return ConstantStringExpression.of("sl." + keyColumnNamesMap.getWebuiSelectionColumnNameForKeyColumnName(fieldName));
} else if (isGroupBy(fieldName)) {
return getFieldOrderBy(fieldName);
} else if (isAggregated(fieldName)) {
return ConstantStringExpression.of(getSqlAggregatedColumn(fieldName));
} else {
// shall not happen
return null;
}
};
final List<DocumentQueryOrderBy> orderBysEffective = orderBys.stream().flatMap(this::flatMapEffectiveFieldNames).filter(orderBy -> keyColumnNamesMap.isKeyPartFieldName(orderBy.getFieldName()) || isGroupBy(orderBy.getFieldName()) || isAggregated(orderBy.getFieldName())).collect(ImmutableList.toImmutableList());
final IStringExpression sqlOrderByExpr = SqlDocumentOrderByBuilder.newInstance(sqlOrderByBindings).buildSqlOrderBy(orderBysEffective);
final String sqlOrderBy;
if (sqlOrderByExpr == null || sqlOrderByExpr.isNullExpression()) {
sqlOrderBy = keyColumnNamesMap.getWebuiSelectionColumnNamesCommaSeparated("sl");
} else {
sqlOrderBy = sqlOrderByExpr.evaluate(viewEvalCtx.toEvaluatee(), OnVariableNotFound.Fail);
}
final String sqlFrom = "SELECT " + "\n sl." + I_T_WEBUI_ViewSelectionLine.COLUMNNAME_UUID + "\n, " + keyColumnNamesMap.getWebuiSelectionColumnNamesCommaSeparated("sl") + "\n FROM " + I_T_WEBUI_ViewSelectionLine.Table_Name + " sl " + "\n INNER JOIN " + lineTableName + " " + lineTableAlias + " ON (" + lineTableAlias + "." + lineKeyColumnName + " = sl." + I_T_WEBUI_ViewSelectionLine.COLUMNNAME_Line_ID + // join lines
")" + "\n WHERE " + I_T_WEBUI_ViewSelectionLine.COLUMNNAME_UUID + "=?" + "\n GROUP BY " + "\n sl." + I_T_WEBUI_ViewSelectionLine.COLUMNNAME_UUID + "\n, " + keyColumnNamesMap.getWebuiSelectionColumnNamesCommaSeparated("sl") + "\n, " + getGroupByFieldNamesCommaSeparated() + "\n ORDER BY " + sqlOrderBy;
final String sqlCreateSelectionFromLines = "INSERT INTO " + I_T_WEBUI_ViewSelection.Table_Name + "(" + "\n " + I_T_WEBUI_ViewSelection.COLUMNNAME_UUID + "\n, " + keyColumnNamesMap.getWebuiSelectionColumnNamesCommaSeparated() + "\n, " + // SeqNo
I_T_WEBUI_ViewSelection.COLUMNNAME_Line + "\n)" + "\n SELECT " + "\n sl." + I_T_WEBUI_ViewSelectionLine.COLUMNNAME_UUID + "\n , " + keyColumnNamesMap.getWebuiSelectionColumnNamesCommaSeparated("sl") + // SeqNo
"\n , row_number() OVER ()" + "\n FROM (" + sqlFrom + ") sl";
final List<Object> sqlCreateSelectionFromLinesParams = Arrays.asList(newViewId.getViewId());
return SqlAndParams.of(sqlCreateSelectionFromLines, sqlCreateSelectionFromLinesParams);
}
use of de.metas.ui.web.window.model.DocumentQueryOrderBy in project metasfresh-webui-api by metasfresh.
the class WindowRestController method getData.
@GetMapping("/{windowId}/{documentId}/{tabId}/{rowId}")
public List<JSONDocument> getData(//
@PathVariable("windowId") final String windowIdStr, //
@PathVariable("documentId") final String documentIdStr, //
@PathVariable("tabId") final String tabIdStr, //
@PathVariable("rowId") final String rowIdStr, //
@RequestParam(name = PARAM_FieldsList, required = false) @ApiParam("comma separated field names") final String fieldsListStr, //
@RequestParam(name = PARAM_Advanced, required = false, defaultValue = PARAM_Advanced_DefaultValue) final boolean advanced) {
final WindowId windowId = WindowId.fromJson(windowIdStr);
final DocumentPath documentPath = DocumentPath.includedDocumentPath(windowId, documentIdStr, tabIdStr, rowIdStr);
final List<DocumentQueryOrderBy> orderBys = ImmutableList.of();
return getData(documentPath, fieldsListStr, advanced, orderBys);
}
use of de.metas.ui.web.window.model.DocumentQueryOrderBy in project metasfresh-webui-api by metasfresh.
the class HUEditorViewBuffer_HighVolume method huIdsPageFetcher.
private PageFetcher<Integer> huIdsPageFetcher(final List<DocumentQueryOrderBy> orderBys) {
final ViewEvaluationCtx viewEvalCtx = getViewEvaluationCtx();
final ViewRowIdsOrderedSelection selection = getSelection(orderBys);
return (firstRow, maxRows) -> huEditorRepo.retrieveHUIdsPage(viewEvalCtx, selection, firstRow, maxRows);
}
use of de.metas.ui.web.window.model.DocumentQueryOrderBy in project metasfresh-webui-api by metasfresh.
the class ViewRestController method createView.
@PostMapping
public JSONViewResult createView(//
@PathVariable(PARAM_WindowId) final String windowIdStr, //
@RequestBody final JSONCreateViewRequest jsonRequest) {
userSession.assertLoggedIn();
final WindowId windowId = extractWindowId(windowIdStr, jsonRequest.getWindowId());
final CreateViewRequest request = CreateViewRequest.builder(windowId, jsonRequest.getViewType()).setProfileId(jsonRequest.getProfileId()).setReferencingDocumentPaths(jsonRequest.getReferencingDocumentPaths()).setFiltersFromJSON(jsonRequest.getFilters()).setFilterOnlyIds(jsonRequest.getFilterOnlyIds()).setUseAutoFilters(true).build();
final IView view = viewsRepo.createView(request);
//
// Fetch result if requested
final ViewResult result;
if (jsonRequest.getQueryPageLength() > 0) {
final List<DocumentQueryOrderBy> orderBys = ImmutableList.of();
result = view.getPage(jsonRequest.getQueryFirstRow(), jsonRequest.getQueryPageLength(), orderBys);
} else {
result = ViewResult.ofView(view);
}
final IViewRowOverrides rowOverrides = ViewRowOverridesHelper.getViewRowOverrides(view);
return JSONViewResult.of(result, rowOverrides, userSession.getAD_Language());
}
Aggregations