Skip to content
Draft
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
69 changes: 37 additions & 32 deletions api/src/org/labkey/api/data/ConditionalFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,42 @@ public String getCssStyle()
return sb.toString();
}

/**
* Converts the XML filter entries for a single conditional format into a URL query string suitable for
* use as a {@link GWTConditionalFormat} filter value.
*/
@Nullable
public static String buildFilterQueryString(@Nullable ConditionalFormatFiltersType filters)
{
SimpleFilter simpleFilter = new SimpleFilter();
if (null != filters)
{
ConditionalFormatFilterType[] filterArray = filters.getFilterArray();
if (filterArray != null)
{
for (ConditionalFormatFilterType filter : filterArray)
{
CompareType compareType = CompareType.getByURLKey(filter.getOperator().toString());
if (compareType != null)
simpleFilter.addClause(compareType.createFilterClause(FieldKey.fromParts(COLUMN_NAME), filter.getValue()));
else
LOG.warn("Could not find CompareType for " + filter.getOperator() + ", ignoring");
}
}
}
try
{
// Process it through a URL to get the query string equivalent
URLHelper url = new URLHelper("/test");
simpleFilter.applyToURL(url, DATA_REGION_NAME);
return url.getQueryString();
}
catch (URISyntaxException e)
{
throw UnexpectedException.wrap(e);
}
}

/** Converts from the XMLBean representation to our standard class. Does not save to the database */
@NotNull
public static List<ConditionalFormat> convertFromXML(ConditionalFormatsType conditionalFormats)
Expand All @@ -200,38 +236,7 @@ public static List<ConditionalFormat> convertFromXML(ConditionalFormatsType cond
for (ConditionalFormatType xmlFormat : conditionalFormats.getConditionalFormatArray())
{
ConditionalFormat format = new ConditionalFormat();
SimpleFilter simpleFilter = new SimpleFilter();
ConditionalFormatFiltersType filters = xmlFormat.getFilters();
if (null != filters)
{
ConditionalFormatFilterType[] filterArray = filters.getFilterArray();
if (filterArray != null)
{
for (ConditionalFormatFilterType filter : filterArray)
{
CompareType compareType = CompareType.getByURLKey(filter.getOperator().toString());
if (compareType != null)
{
simpleFilter.addClause(compareType.createFilterClause(FieldKey.fromParts(COLUMN_NAME), filter.getValue()));
}
else
{
LOG.warn("Could not find CompareType for " + filter.getOperator() + ", ignoring");
}
}
}
}
try
{
// Process it through a URL to get the query string equivalent
URLHelper url = new URLHelper("/test");
simpleFilter.applyToURL(url, DATA_REGION_NAME);
format.setFilter(url.getQueryString());
}
catch (URISyntaxException e)
{
throw UnexpectedException.wrap(e);
}
format.setFilter(buildFilterQueryString(xmlFormat.getFilters()));
if (xmlFormat.isSetBold() && xmlFormat.getBold())
{
format.setBold(true);
Expand Down
6 changes: 1 addition & 5 deletions api/src/org/labkey/api/exp/property/DomainUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import org.labkey.api.data.TableInfo;
import org.labkey.api.data.TableInfo.IndexDefinition;
import org.labkey.api.data.TableSelector;
import org.labkey.api.dataiterator.DataIteratorUtil;
import org.labkey.api.defaults.DefaultValueService;
import org.labkey.api.exp.ChangePropertyDescriptorException;
import org.labkey.api.exp.DomainDescriptor;
Expand Down Expand Up @@ -97,7 +96,6 @@
import org.labkey.api.util.StringUtilsLabKey;
import org.labkey.api.view.UnauthorizedException;
import org.labkey.data.xml.ColumnType;
import org.labkey.data.xml.ConditionalFormatFilterType;
import org.labkey.data.xml.ConditionalFormatType;
import org.labkey.data.xml.TableType;

Expand Down Expand Up @@ -661,9 +659,7 @@ public static GWTPropertyDescriptor getPropertyDescriptor(ColumnType columnXml)
gwtFormat.setStrikethrough(formatType.getStrikethrough());
gwtFormat.setTextColor(formatType.getTextColor());
gwtFormat.setBackgroundColor(formatType.getBackgroundColor());
for (ConditionalFormatFilterType filterType : formatType.getFilters().getFilterArray())
gwtFormat.setFilter("format.column%7E" + filterType.getOperator().toString() + "=" + filterType.getValue());

gwtFormat.setFilter(ConditionalFormat.buildFilterQueryString(formatType.getFilters())); // GitHub Issue #1056
formats.add(gwtFormat);
}
gwtProp.setConditionalFormats(formats);
Expand Down
Loading