Skip to content

Commit 5ef6785

Browse files
committed
GitHub Issue #1056: ConditionalFormat applied via DomainUtil.getPropertyDescriptor() doesn't handle multiple filter conditions
- factor out XML metadata conditional format parsing and query string generation in ConditionalFormat.java to be reusable - use ConditionalFormat.buildFilterQueryString in DomainUtil.getPropertyDescriptor
1 parent e2bca85 commit 5ef6785

2 files changed

Lines changed: 38 additions & 37 deletions

File tree

api/src/org/labkey/api/data/ConditionalFormat.java

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,42 @@ public String getCssStyle()
188188
return sb.toString();
189189
}
190190

191+
/**
192+
* Converts the XML filter entries for a single conditional format into a URL query string suitable for
193+
* use as a {@link GWTConditionalFormat} filter value.
194+
*/
195+
@NotNull
196+
public static String buildFilterQueryString(@Nullable ConditionalFormatFiltersType filters)
197+
{
198+
SimpleFilter simpleFilter = new SimpleFilter();
199+
if (null != filters)
200+
{
201+
ConditionalFormatFilterType[] filterArray = filters.getFilterArray();
202+
if (filterArray != null)
203+
{
204+
for (ConditionalFormatFilterType filter : filterArray)
205+
{
206+
CompareType compareType = CompareType.getByURLKey(filter.getOperator().toString());
207+
if (compareType != null)
208+
simpleFilter.addClause(compareType.createFilterClause(FieldKey.fromParts(COLUMN_NAME), filter.getValue()));
209+
else
210+
LOG.warn("Could not find CompareType for " + filter.getOperator() + ", ignoring");
211+
}
212+
}
213+
}
214+
try
215+
{
216+
// Process it through a URL to get the query string equivalent
217+
URLHelper url = new URLHelper("/test");
218+
simpleFilter.applyToURL(url, DATA_REGION_NAME);
219+
return url.getQueryString();
220+
}
221+
catch (URISyntaxException e)
222+
{
223+
throw UnexpectedException.wrap(e);
224+
}
225+
}
226+
191227
/** Converts from the XMLBean representation to our standard class. Does not save to the database */
192228
@NotNull
193229
public static List<ConditionalFormat> convertFromXML(ConditionalFormatsType conditionalFormats)
@@ -200,38 +236,7 @@ public static List<ConditionalFormat> convertFromXML(ConditionalFormatsType cond
200236
for (ConditionalFormatType xmlFormat : conditionalFormats.getConditionalFormatArray())
201237
{
202238
ConditionalFormat format = new ConditionalFormat();
203-
SimpleFilter simpleFilter = new SimpleFilter();
204-
ConditionalFormatFiltersType filters = xmlFormat.getFilters();
205-
if (null != filters)
206-
{
207-
ConditionalFormatFilterType[] filterArray = filters.getFilterArray();
208-
if (filterArray != null)
209-
{
210-
for (ConditionalFormatFilterType filter : filterArray)
211-
{
212-
CompareType compareType = CompareType.getByURLKey(filter.getOperator().toString());
213-
if (compareType != null)
214-
{
215-
simpleFilter.addClause(compareType.createFilterClause(FieldKey.fromParts(COLUMN_NAME), filter.getValue()));
216-
}
217-
else
218-
{
219-
LOG.warn("Could not find CompareType for " + filter.getOperator() + ", ignoring");
220-
}
221-
}
222-
}
223-
}
224-
try
225-
{
226-
// Process it through a URL to get the query string equivalent
227-
URLHelper url = new URLHelper("/test");
228-
simpleFilter.applyToURL(url, DATA_REGION_NAME);
229-
format.setFilter(url.getQueryString());
230-
}
231-
catch (URISyntaxException e)
232-
{
233-
throw UnexpectedException.wrap(e);
234-
}
239+
format.setFilter(buildFilterQueryString(xmlFormat.getFilters()));
235240
if (xmlFormat.isSetBold() && xmlFormat.getBold())
236241
{
237242
format.setBold(true);

api/src/org/labkey/api/exp/property/DomainUtil.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
import org.labkey.api.data.TableInfo;
4949
import org.labkey.api.data.TableInfo.IndexDefinition;
5050
import org.labkey.api.data.TableSelector;
51-
import org.labkey.api.dataiterator.DataIteratorUtil;
5251
import org.labkey.api.defaults.DefaultValueService;
5352
import org.labkey.api.exp.ChangePropertyDescriptorException;
5453
import org.labkey.api.exp.DomainDescriptor;
@@ -97,7 +96,6 @@
9796
import org.labkey.api.util.StringUtilsLabKey;
9897
import org.labkey.api.view.UnauthorizedException;
9998
import org.labkey.data.xml.ColumnType;
100-
import org.labkey.data.xml.ConditionalFormatFilterType;
10199
import org.labkey.data.xml.ConditionalFormatType;
102100
import org.labkey.data.xml.TableType;
103101

@@ -661,9 +659,7 @@ public static GWTPropertyDescriptor getPropertyDescriptor(ColumnType columnXml)
661659
gwtFormat.setStrikethrough(formatType.getStrikethrough());
662660
gwtFormat.setTextColor(formatType.getTextColor());
663661
gwtFormat.setBackgroundColor(formatType.getBackgroundColor());
664-
for (ConditionalFormatFilterType filterType : formatType.getFilters().getFilterArray())
665-
gwtFormat.setFilter("format.column%7E" + filterType.getOperator().toString() + "=" + filterType.getValue());
666-
662+
gwtFormat.setFilter(ConditionalFormat.buildFilterQueryString(formatType.getFilters())); // GitHub Issue #1056
667663
formats.add(gwtFormat);
668664
}
669665
gwtProp.setConditionalFormats(formats);

0 commit comments

Comments
 (0)