Skip to content

Commit

Permalink
Add possibility to turn off 'Area Search' filter (#1364)
Browse files Browse the repository at this point in the history
* Add possibility to turn off 'Area Search' filter
refs: #1363

* refs: metasfresh/metasfresh#6156
  • Loading branch information
pvpurcarcosmin committed Feb 11, 2020
1 parent 2d18326 commit fbdd0b4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ public interface DocumentFilterDescriptorsProviderFactory
{
@Nullable
DocumentFilterDescriptorsProvider createFiltersProvider(AdTabId adTabId, String tableName, Collection<DocumentFieldDescriptor> fields);

default boolean isActive() { return true; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,12 @@ public DocumentFilterDescriptorsProvider createFiltersProvider(
@Nullable final String tableName,
@NonNull final Collection<DocumentFieldDescriptor> fields)
{
final List<DocumentFilterDescriptorsProvider> providers = new ArrayList<>();
for (DocumentFilterDescriptorsProviderFactory providerFactory : providerFactories)
{
final DocumentFilterDescriptorsProvider provider = providerFactory.createFiltersProvider(adTabId, tableName, fields);
if (NullDocumentFilterDescriptorsProvider.isNull(provider))
{
continue;
}

providers.add(provider);
}
final ImmutableList<DocumentFilterDescriptorsProvider> providers = providerFactories
.stream()
.filter(DocumentFilterDescriptorsProviderFactory::isActive)
.map(provider -> provider.createFiltersProvider(adTabId, tableName, fields))
.filter(NullDocumentFilterDescriptorsProvider::isNotNull)
.collect(ImmutableList.toImmutableList());

return CompositeDocumentFilterDescriptorsProvider.compose(providers);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.Collection;
import java.util.Map;

import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;

import com.fasterxml.jackson.annotation.JsonValue;
Expand Down Expand Up @@ -38,12 +39,12 @@ public final class NullDocumentFilterDescriptorsProvider implements DocumentFilt
{
public static final transient NullDocumentFilterDescriptorsProvider instance = new NullDocumentFilterDescriptorsProvider();

public static boolean isNull(final DocumentFilterDescriptorsProvider provider)
public static boolean isNull(@Nullable final DocumentFilterDescriptorsProvider provider)
{
return provider == null || provider == instance;
}

public static boolean isNotNull(final DocumentFilterDescriptorsProvider provider)
public static boolean isNotNull(@Nullable final DocumentFilterDescriptorsProvider provider)
{
return !isNull(provider);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import org.adempiere.ad.element.api.AdTabId;
import org.adempiere.exceptions.AdempiereException;
import org.adempiere.service.ISysConfigBL;
import org.compiere.model.I_C_BPartner_Location;
import org.compiere.model.I_C_Country;
import org.compiere.model.I_C_Location;
Expand Down Expand Up @@ -59,8 +60,10 @@
public class GeoLocationDocumentService implements DocumentFilterDescriptorsProviderFactory
{
private final transient IMsgBL msgBL = Services.get(IMsgBL.class);
private final transient ISysConfigBL sysConfigBL = Services.get(ISysConfigBL.class);

private static final String MSG_FILTER_CAPTION = "LocationAreaSearch";
private static final String SYS_CONFIG_ENABLE_GEO_LOCATION_SEARCH = "de.metas.ui.web.document.geo_location.filter_enabled";

private static final GeoLocationDocumentDescriptor DESCRIPTOR_FOR_LocationId = GeoLocationDocumentDescriptor.builder()
.type(LocationColumnNameType.LocationId)
Expand Down Expand Up @@ -121,6 +124,10 @@ public boolean hasGeoLocationSupport(@NonNull final Set<String> fieldNames)
return getGeoLocationDocumentDescriptorOrNull(fieldNames) != null;
}

public boolean isActive() {
return sysConfigBL.getBooleanValue(SYS_CONFIG_ENABLE_GEO_LOCATION_SEARCH, Boolean.TRUE);
}

@Nullable
private static GeoLocationDocumentDescriptor getGeoLocationDocumentDescriptorOrNull(@NonNull final Set<String> fieldNames)
{
Expand Down

0 comments on commit fbdd0b4

Please sign in to comment.