use of de.metas.ui.web.view.descriptor.SqlViewBinding in project metasfresh-webui-api by metasfresh.
the class SqlViewFactory method createView.
@Override
public IView createView(final CreateViewRequest request) {
final WindowId windowId = request.getViewId().getWindowId();
final JSONViewDataType viewType = request.getViewType();
final ViewProfileId profileId = !ViewProfileId.isNull(request.getProfileId()) ? request.getProfileId() : getDefaultProfileIdByWindowId(windowId);
final SqlViewBindingKey sqlViewBindingKey = new SqlViewBindingKey(windowId, viewType.getRequiredFieldCharacteristic(), profileId);
final SqlViewBinding sqlViewBinding = getViewBinding(sqlViewBindingKey);
final IViewDataRepository viewDataRepository = new SqlViewDataRepository(sqlViewBinding);
final DefaultView.Builder viewBuilder = DefaultView.builder(viewDataRepository).setViewId(request.getViewId()).setViewType(viewType).setProfileId(profileId).setReferencingDocumentPaths(request.getReferencingDocumentPaths()).setParentViewId(request.getParentViewId()).setParentRowId(request.getParentRowId()).addStickyFilters(request.getStickyFilters()).addStickyFilter(extractReferencedDocumentFilter(windowId, request.getSingleReferencingDocumentPathOrNull())).viewInvalidationAdvisor(sqlViewBinding.getViewInvalidationAdvisor());
final DocumentFiltersList filters = request.getFilters();
if (filters.isJson()) {
viewBuilder.setFiltersFromJSON(filters.getJsonFilters());
} else {
viewBuilder.setFilters(filters.getFilters());
}
if (request.isUseAutoFilters()) {
final List<DocumentFilter> autoFilters = createAutoFilters(sqlViewBindingKey);
viewBuilder.addFiltersIfAbsent(autoFilters);
}
if (!request.getFilterOnlyIds().isEmpty()) {
final String keyColumnName = sqlViewBinding.getSqlViewKeyColumnNamesMap().getSingleKeyColumnName();
viewBuilder.addStickyFilter(DocumentFilter.inArrayFilter(keyColumnName, keyColumnName, request.getFilterOnlyIds()));
}
return viewBuilder.build();
}
Aggregations