Skip to content

Commit

Permalink
Be more permissive
Browse files Browse the repository at this point in the history
  • Loading branch information
labkey-nicka committed Dec 12, 2024
1 parent b8e4c8b commit 1f891ad
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 19 deletions.
54 changes: 37 additions & 17 deletions api/src/org/labkey/api/assay/plate/FilterCriteria.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,33 +45,53 @@ public record FilterCriteria(
for (int i = 0; i < filterCriteria.size(); i++)
{
var criterion = filterCriteria.get(i);
Integer propertyId = criterion.getPropertyId();
var propertyId = criterion.getPropertyId();

if (propertyId != null && propertyId <= 0)
throw new ValidationException(errorMessage(referencePropertyName, i, "Invalid \"propertyId\" value."));
if (propertyId != null)
{
if (propertyId == 0)
throw new ValidationException(errorMessage(referencePropertyName, i, "Invalid \"propertyId\" value."));
else if (propertyId < 0)
propertyId = null;
}

String name = StringUtils.trimToNull(criterion.getName());

// Attempt to resolve the field by name
if (propertyId == null && name != null)
if (propertyId == null)
{
if (replicateStatsDomain != null)
// Attempt to resolve the field by name
if (name != null)
{
var property = replicateStatsDomain.getPropertyByName(name);
if (property != null)
propertyId = property.getPropertyId();
if (replicateStatsDomain != null)
{
var property = replicateStatsDomain.getPropertyByName(name);
if (property != null)
{
propertyId = property.getPropertyId();
name = property.getName();
}
}
else if (name.equalsIgnoreCase(referencePropertyName))
{
propertyId = referencePropertyId;
name = referencePropertyName;
}

if (propertyId == null)
throw new ValidationException(errorMessage(referencePropertyName, i, String.format("Unable to resolve field from name \"%s\".", name)));
}
else if (name.equalsIgnoreCase(referencePropertyName))
{
propertyId = referencePropertyId;
}
else
{
if (propertyId == referencePropertyId)
name = referencePropertyName;
else if (replicateStatsDomain != null)
{
var property = replicateStatsDomain.getProperty(propertyId);
if (property == null)
throw new ValidationException(errorMessage(referencePropertyName, i, "Invalid \"propertyId\" value. Cannot specify criteria against other fields."));
}

if (propertyId == null)
throw new ValidationException(errorMessage(referencePropertyName, i, String.format("Unable to resolve field from name \"%s\".", name)));
}
else if (propertyId != null && propertyId != referencePropertyId)
throw new ValidationException(errorMessage(referencePropertyName, i, "Invalid \"propertyId\" value. Cannot specify criteria against other fields."));

if (propertyId == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1341,7 +1341,7 @@ public void applyHitSelectionCriteria(
var url = new ActionURL();
var replicateDomain = AssayPlateMetadataService.get().getPlateReplicateStatsDomain(protocol);

for (var criteria : filterCriteria) // TODO: Need to validate filterCriteria compare types coming in
for (var criteria : filterCriteria)
{
var domainProperty = domain.getProperty(criteria.propertyId());
boolean isReplicateProperty = false;
Expand All @@ -1364,7 +1364,7 @@ public void applyHitSelectionCriteria(
else
fieldKey = FieldKey.fromParts(domainProperty.getName());

CompareType ct = CompareType.getByURLKey(criteria.operation());
var ct = CompareType.getByURLKey(criteria.operation());
if (ct == null)
{
LOG.error("Automatic hit selection failed. Unable to resolve filter comparison type from operation \"{}\".", criteria.operation());
Expand All @@ -1377,6 +1377,13 @@ public void applyHitSelectionCriteria(
// The referenced plate well must have a sample value
var filter = new SimpleFilter(FieldKey.fromParts("Well", "SampleId"), null, CompareType.NONBLANK);

// TODO: Filter out rows that are excluded and filter not in AssayResultDomainKind.STATE_COLUMN_NAME
// var states = PlateDataStateManager.get().getStates(container);
// for (var state : states)
// {
// if (PlateDataStateManager.get().isOperationPermitted(state, hitSelection));
// }

// Applying filters via ActionURL allows for automatic type coercion of the filter value
filter.addUrlFilters(url, null);

Expand Down

0 comments on commit 1f891ad

Please sign in to comment.