Search in sources :

Example 1 with SqlDocumentFilterConverter

use of de.metas.ui.web.document.filter.sql.SqlDocumentFilterConverter in project metasfresh-webui-api by metasfresh.

the class SqlHUEditorViewRepository method retrieveHUIdsEffective.

@Override
public List<Integer> retrieveHUIdsEffective(@NonNull final HUIdsFilterData huIdsFilter, @NonNull final List<DocumentFilter> filters) {
    final ImmutableList<Integer> onlyHUIds = extractHUIds(huIdsFilter);
    if (filters.isEmpty() && !huIdsFilter.hasInitialHUQuery() && onlyHUIds != null) {
        // shortcut: don't bother the DB but return the list of IDs that we already have
        return onlyHUIds;
    }
    // Create HU query
    IHUQueryBuilder huQuery = huIdsFilter.getInitialHUQueryOrNull();
    if (huQuery == null) {
        huQuery = Services.get(IHandlingUnitsDAO.class).createHUQueryBuilder();
    }
    huQuery.setContext(PlainContextAware.newOutOfTrx());
    // Only HUs
    if (onlyHUIds != null) {
        huQuery.addOnlyHUIds(onlyHUIds);
    }
    // Exclude HUs
    huQuery.addHUIdsToExclude(huIdsFilter.getShallNotHUIds());
    // Convert the "filters" to SQL
    if (!filters.isEmpty()) {
        final SqlDocumentFilterConverter sqlFilterConverter = SqlDocumentFilterConverters.createEntityBindingEffectiveConverter(sqlViewBinding);
        huQuery.addFilter(sqlFilterConverter.createQueryFilter(filters, SqlOptions.usingTableAlias(sqlViewBinding.getTableAlias())));
    }
    return huQuery.createQuery().listIds();
}
Also used : IHUQueryBuilder(de.metas.handlingunits.IHUQueryBuilder) SqlDocumentFilterConverter(de.metas.ui.web.document.filter.sql.SqlDocumentFilterConverter)

Aggregations

IHUQueryBuilder (de.metas.handlingunits.IHUQueryBuilder)1 SqlDocumentFilterConverter (de.metas.ui.web.document.filter.sql.SqlDocumentFilterConverter)1