Search in sources :

Example 11 with DocumentFilter

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());
}
Also used : HUTraceEventQuery(de.metas.handlingunits.trace.HUTraceEventQuery) DocumentFilter(de.metas.ui.web.document.filter.DocumentFilter) Date(java.util.Date) Test(org.junit.Test)

Example 12 with DocumentFilter

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);
}
Also used : DocumentFilter(de.metas.ui.web.document.filter.DocumentFilter) Test(org.junit.Test)

Example 13 with DocumentFilter

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);
}
Also used : DocumentFilter(de.metas.ui.web.document.filter.DocumentFilter) DocumentFilterDescriptorsProvider(de.metas.ui.web.document.filter.DocumentFilterDescriptorsProvider) ImmutableDocumentFilterDescriptorsProvider(de.metas.ui.web.document.filter.ImmutableDocumentFilterDescriptorsProvider)

Example 14 with DocumentFilter

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();
}
Also used : DocumentFilterParam(de.metas.ui.web.document.filter.DocumentFilterParam) DocumentFilterParamDescriptor(de.metas.ui.web.document.filter.DocumentFilterParamDescriptor) DocumentFilter(de.metas.ui.web.document.filter.DocumentFilter)

Example 15 with DocumentFilter

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();
}
Also used : DocumentFiltersList(de.metas.ui.web.document.filter.DocumentFiltersList) SqlViewBinding(de.metas.ui.web.view.descriptor.SqlViewBinding) DocumentFilter(de.metas.ui.web.document.filter.DocumentFilter) WindowId(de.metas.ui.web.window.datatypes.WindowId) JSONViewDataType(de.metas.ui.web.view.json.JSONViewDataType)

Aggregations

DocumentFilter (de.metas.ui.web.document.filter.DocumentFilter)15 Test (org.junit.Test)6 HUTraceEventQuery (de.metas.handlingunits.trace.HUTraceEventQuery)4 WindowId (de.metas.ui.web.window.datatypes.WindowId)3 ArrayList (java.util.ArrayList)3 ImmutableList (com.google.common.collect.ImmutableList)2 IMsgBL (de.metas.i18n.IMsgBL)2 ITranslatableString (de.metas.i18n.ITranslatableString)2 LogManager (de.metas.logging.LogManager)2 DocumentFilterDescriptorsProvider (de.metas.ui.web.document.filter.DocumentFilterDescriptorsProvider)2 ViewId (de.metas.ui.web.view.ViewId)2 DocumentPath (de.metas.ui.web.window.datatypes.DocumentPath)2 DocumentEntityDescriptor (de.metas.ui.web.window.descriptor.DocumentEntityDescriptor)2 DocumentFieldWidgetType (de.metas.ui.web.window.descriptor.DocumentFieldWidgetType)2 DocumentDescriptorFactory (de.metas.ui.web.window.descriptor.factory.DocumentDescriptorFactory)2 SqlDocumentEntityDataBindingDescriptor (de.metas.ui.web.window.descriptor.sql.SqlDocumentEntityDataBindingDescriptor)2 Collection (java.util.Collection)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2