Skip to content

Commit

Permalink
implement conversion of DocumentFilter into HUTraceQuery
Browse files Browse the repository at this point in the history
HU-Trace: show all connected records #632
  • Loading branch information
metas-ts committed Oct 13, 2017
1 parent 66f19b9 commit 3f89c82
Show file tree
Hide file tree
Showing 10 changed files with 568 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,6 @@
@EqualsAndHashCode // required for (ETag) caching
public class DocumentFilterParam
{
public static final Builder builder()
{
return new Builder();
}

public static final DocumentFilterParam ofSqlWhereClause(final boolean joinAnd, final String sqlWhereClause)
{
// NOTE: avoid having sqlWhereClauseParams because they might introduce issues when we have to convert to SQL code without params.
final List<Object> sqlWhereClauseParams = ImmutableList.of();
return new DocumentFilterParam(joinAnd, sqlWhereClause, sqlWhereClauseParams);
}


public static enum Operator
{
EQUAL, NOT_EQUAL, //
Expand Down Expand Up @@ -84,10 +71,31 @@ public boolean isRangeOperator()
private final String sqlWhereClause;
private final List<Object> sqlWhereClauseParams;

private DocumentFilterParam(final Builder builder)
public static final Builder builder()
{
super();
return new Builder();
}

public static final DocumentFilterParam ofSqlWhereClause(final boolean joinAnd, final String sqlWhereClause)
{
// NOTE: avoid having sqlWhereClauseParams because they might introduce issues when we have to convert to SQL code without params.
final List<Object> sqlWhereClauseParams = ImmutableList.of();
return new DocumentFilterParam(joinAnd, sqlWhereClause, sqlWhereClauseParams);
}

/**
* Shortcut to create an often-used kind of parameters.
*/
public static final DocumentFilterParam ofNameOperatorValue(
@NonNull final String fieldName,
@NonNull final Operator operator,
@NonNull final Object value)
{
return builder().setFieldName(fieldName).setOperator(operator).setValue(value).build();
}

private DocumentFilterParam(final Builder builder)
{
joinAnd = builder.joinAnd;

fieldName = builder.fieldName;
Expand All @@ -105,8 +113,6 @@ private DocumentFilterParam(final Builder builder)

private DocumentFilterParam(final boolean joinAnd, final String sqlWhereClause, final List<Object> sqlWhereClauseParams)
{
super();

this.joinAnd = joinAnd;

fieldName = null;
Expand Down Expand Up @@ -147,7 +153,7 @@ public String getSqlWhereClause()
{
return sqlWhereClause;
}

public List<Object> getSqlWhereClauseParams()
{
return sqlWhereClauseParams;
Expand Down Expand Up @@ -191,8 +197,8 @@ public <T> List<T> getValueAsList(@NonNull final Function<Object, T> itemConvert
{
throw new IllegalStateException("Cannot convert null value to List<Integer>");
}
if(valueAsCollection.isEmpty())

if (valueAsCollection.isEmpty())
{
return ImmutableList.of();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ public String toString()

/** Build document filter where clause */
@Override
public String getSql(final SqlParamsCollector sqlParams, final DocumentFilter filter, final SqlOptions sqlOpts)
public String getSql(
@NonNull final SqlParamsCollector sqlParams,
@NonNull final DocumentFilter filter,
@NonNull final SqlOptions sqlOpts)
{
final StringBuilder sql = new StringBuilder();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import de.metas.printing.esb.base.util.Check;
import de.metas.ui.web.document.filter.DocumentFilter;
import de.metas.ui.web.window.model.sql.SqlOptions;
import lombok.NonNull;

/*
* #%L
Expand Down Expand Up @@ -50,7 +51,10 @@ public interface SqlDocumentFilterConverter
*/
String getSql(SqlParamsCollector sqlParamsOut, DocumentFilter filter, final SqlOptions sqlOpts);

default String getSql(final SqlParamsCollector sqlParamsOut, final List<DocumentFilter> filters, final SqlOptions sqlOpts)
default String getSql(
@NonNull final SqlParamsCollector sqlParamsOut,
@NonNull final List<DocumentFilter> filters,
@NonNull final SqlOptions sqlOpts)
{
if (filters.isEmpty())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
*/
public interface SqlDocumentFilterConverterDecorator
{
public WindowId getWindowId();
WindowId getWindowId();

public SqlDocumentFilterConverter decorate(SqlDocumentFilterConverter converter);
SqlDocumentFilterConverter decorate(SqlDocumentFilterConverter converter);
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ private SqlDocumentFilterConvertersListWithFallback(@NonNull final SqlDocumentFi
}

@Override
public String getSql(final SqlParamsCollector sqlParamsOut, final DocumentFilter filter, final SqlOptions sqlOpts)
public String getSql(
@NonNull final SqlParamsCollector sqlParamsOut,
@NonNull final DocumentFilter filter,
@NonNull final SqlOptions sqlOpts)
{
// Find the effective converter to be used for given filter
final String filterId = filter.getFilterId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,10 @@ private HUBarcodeSqlDocumentFilterConverter()
}

@Override
public String getSql(final SqlParamsCollector sqlParamsOut, final DocumentFilter filter, final SqlOptions sqlOpts_NOTUSED)
public String getSql(
@NonNull final SqlParamsCollector sqlParamsOut,
@NonNull final DocumentFilter filter,
final SqlOptions sqlOpts_NOTUSED)
{
final Object barcodeObj = filter.getParameter(PARAM_Barcode).getValue();
if (barcodeObj == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,10 @@ private HUIdsSqlDocumentFilterConverter()
}

@Override
public String getSql(final SqlParamsCollector sqlParamsOut, final DocumentFilter filter, final SqlOptions sqlOpts_NOTUSED)
public String getSql(
@NonNull final SqlParamsCollector sqlParamsOut,
@NonNull final DocumentFilter filter,
final SqlOptions sqlOpts_NOTUSED)
{
final HUIdsFilterData huIdsFilter = extractFilterData(filter);
final ImmutableList<Integer> onlyHUIds;
Expand Down
Loading

0 comments on commit 3f89c82

Please sign in to comment.