-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
backend: endpoint for creating a filtered view
MAJOR DocumentFilter(s) refactoring #372
- Loading branch information
Showing
36 changed files
with
1,258 additions
and
289 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/main/java/de/metas/ui/web/document/filter/sql/SqlDocumentFilterConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package de.metas.ui.web.document.filter.sql; | ||
|
||
import java.util.List; | ||
|
||
import org.compiere.util.DB; | ||
|
||
import de.metas.printing.esb.base.util.Check; | ||
import de.metas.ui.web.document.filter.DocumentFilter; | ||
|
||
/* | ||
* #%L | ||
* metasfresh-webui-api | ||
* %% | ||
* Copyright (C) 2017 metas GmbH | ||
* %% | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as | ||
* published by the Free Software Foundation, either version 2 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public | ||
* License along with this program. If not, see | ||
* <http://www.gnu.org/licenses/gpl-2.0.html>. | ||
* #L% | ||
*/ | ||
|
||
/** | ||
* Converts and {@link DocumentFilter} to SQL. | ||
* | ||
* To create and manipulate {@link SqlDocumentFilterConverter}s please use {@link SqlDocumentFilterConverters}. | ||
* | ||
* @author metas-dev <dev@metasfresh.com> | ||
* | ||
*/ | ||
public interface SqlDocumentFilterConverter | ||
{ | ||
/** | ||
* Converts given <code>filter</code> to SQL and returns it. | ||
* In case the produced SQL requires parameters, those parameters will be added to <code>sqlParamsOut</code> parameter. | ||
* | ||
* @param sqlParamsOut | ||
* @param filter | ||
* @return SQL | ||
*/ | ||
String getSql(List<Object> sqlParamsOut, DocumentFilter filter); | ||
|
||
default String getSql(final List<Object> sqlParamsOut, final List<DocumentFilter> filters) | ||
{ | ||
if (filters.isEmpty()) | ||
{ | ||
return ""; | ||
} | ||
|
||
final StringBuilder sqlWhereClauseBuilder = new StringBuilder(); | ||
|
||
for (final DocumentFilter filter : filters) | ||
{ | ||
final String sqlFilter = getSql(sqlParamsOut, filter); | ||
if (Check.isEmpty(sqlFilter, true)) | ||
{ | ||
continue; | ||
} | ||
|
||
if (sqlWhereClauseBuilder.length() > 0) | ||
{ | ||
sqlWhereClauseBuilder.append("\n AND "); | ||
} | ||
sqlWhereClauseBuilder.append(DB.TO_COMMENT(filter.getFilterId())).append("(").append(sqlFilter).append(")"); | ||
} | ||
|
||
return sqlWhereClauseBuilder.toString(); | ||
} | ||
} |
Oops, something went wrong.