use of de.metas.ui.web.document.filter.DocumentFilter in project metasfresh-webui-api by metasfresh.
the class DocumentFilterToHuTraceQueryTest method createTraceQueryFromDocumentFilter_eventdate.
@Test
public void createTraceQueryFromDocumentFilter_eventdate() {
final Date date = TimeUtil.parseTimestamp("2017-10-13");
final Date dateTo = TimeUtil.parseTimestamp("2017-10-15");
final DocumentFilter filter = DocumentFilter.builder().setFilterId("filter").addParameter(createEventTimeBetweenParameter(date, dateTo)).build();
final HUTraceEventQuery huTraceQuery = HuTraceQueryCreator.createTraceQueryFromDocumentFilter(filter);
assertThat(huTraceQuery.getRecursionMode()).isEqualTo(RecursionMode.BOTH);
assertThat(huTraceQuery.getEventTime()).isEqualTo(date.toInstant());
assertThat(huTraceQuery.getEventTimeOperator()).isEqualTo(EventTimeOperator.BETWEEN);
assertThat(huTraceQuery.getEventTimeTo()).isEqualTo(dateTo.toInstant());
}
use of de.metas.ui.web.document.filter.DocumentFilter in project metasfresh-webui-api by metasfresh.
the class HUIdsFilterHelperTest method testEmptyHUIdsCollection.
/**
* Verifies that if {@link HUIdsFilterHelper#createFilter(java.util.Collection)} is called with an empty list,
* then the filter's SQL does <b>not</b> select every single f**king HU on this planet.
*/
@Test
public void testEmptyHUIdsCollection() {
final DocumentFilter noHusFilter = HUIdsFilterHelper.createFilter(ImmutableList.of());
final String sql = HUIdsFilterHelper.SQL_DOCUMENT_FILTER_CONVERTER.getSql(SqlParamsCollector.newInstance(), noHusFilter, SqlOptions.usingTableAlias("dummyTableAlias"));
assertThat(sql).doesNotContain(HUIdsSqlDocumentFilterConverter.SQL_TRUE);
}
use of de.metas.ui.web.document.filter.DocumentFilter in project metasfresh-webui-api by metasfresh.
the class MaterialCockpitFilters method extractDocumentFilters.
public ImmutableList<DocumentFilter> extractDocumentFilters(@NonNull final CreateViewRequest request) {
final DocumentFilterDescriptorsProvider provider = getFilterDescriptors();
final List<DocumentFilter> filters = request.getOrUnwrapFilters(provider);
return ImmutableList.copyOf(filters);
}
use of de.metas.ui.web.document.filter.DocumentFilter in project metasfresh-webui-api by metasfresh.
the class JSONDocumentFilter method unwrapUsingDescriptor.
private static DocumentFilter unwrapUsingDescriptor(final JSONDocumentFilter jsonFilter, final DocumentFilterDescriptor filterDescriptor) {
final DocumentFilter.Builder filter = DocumentFilter.builder().setFilterId(jsonFilter.getFilterId());
final Map<String, JSONDocumentFilterParam> jsonParams = Maps.uniqueIndex(jsonFilter.getParameters(), JSONDocumentFilterParam::getParameterName);
for (final DocumentFilterParamDescriptor paramDescriptor : filterDescriptor.getParameters()) {
final String parameterName = paramDescriptor.getParameterName();
final JSONDocumentFilterParam jsonParam = jsonParams.get(parameterName);
// If parameter is missing: skip it if no required, else throw exception
if (jsonParam == null) {
if (paramDescriptor.isMandatory()) {
throw new IllegalArgumentException("Parameter '" + parameterName + "' was not provided");
}
continue;
}
final Object value = paramDescriptor.convertValueFromJson(jsonParam.getValue());
final Object valueTo = paramDescriptor.convertValueFromJson(jsonParam.getValueTo());
// If there was no value/valueTo provided: skip it if no required, else throw exception
if (value == null && valueTo == null) {
if (paramDescriptor.isMandatory()) {
throw new IllegalArgumentException("Parameter '" + parameterName + "' has no value");
}
continue;
}
filter.addParameter(DocumentFilterParam.builder().setFieldName(paramDescriptor.getFieldName()).setOperator(paramDescriptor.getOperator()).setValue(value).setValueTo(valueTo).build());
}
for (final DocumentFilterParam internalParam : filterDescriptor.getInternalParameters()) {
filter.addParameter(internalParam);
}
return filter.build();
}
use of de.metas.ui.web.document.filter.DocumentFilter 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