Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possibility to turn off 'Area Search' filter #1364

Merged
merged 2 commits into from
Feb 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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