Skip to content

Commit

Permalink
1644 - added support of eq:null to the policies
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladysl committed Mar 5, 2024
1 parent b0ffca7 commit 43fcf2f
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@ public boolean match(final String value, final T context) {

@Override
public boolean equals(final String value, final T context) {
return fieldExtractor.apply(context).stream()
.anyMatch(value::equals);
final List<String> listOfElements = fieldExtractor.apply(context)
.stream()
.toList();

return value == null
? listOfElements.isEmpty()
: listOfElements.stream().anyMatch(value::equals);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ public boolean match(final String value, final T context) {
}

@Override
public boolean equals(final String value, final T context) {
return value.equals(fieldExtractor.apply(context));
public boolean equals(final String value, final T context) {
return value == null
? fieldExtractor.apply(context) == null
: value.equals(fieldExtractor.apply(context));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public DataEntityDataSourceFieldComparer(final Function<DataSourcePojo, String>
}

private static DataSourcePojo getDataEntityDataSource(final DataEntityPolicyResolverContext context) {
return context.dataEntity().getDataSource();
return context.dataEntity().getDataSource() == null
? new DataSourcePojo()
: context.dataEntity().getDataSource();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public DataEntityFieldComparer(final Function<DataEntityPojo, String> fieldExtra
}

private static DataEntityPojo getDataEntity(final DataEntityPolicyResolverContext context) {
return context.dataEntity().getDataEntity();
return context.dataEntity().getDataEntity() == null
? new DataEntityPojo()
: context.dataEntity().getDataEntity();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public DataEntityNamespaceFieldComparer(final Function<NamespacePojo, String> fi
}

private static NamespacePojo getDataEntityNamespace(final DataEntityPolicyResolverContext context) {
return context.dataEntity().getNamespace();
return context.dataEntity().getNamespace() == null
? new NamespacePojo()
: context.dataEntity().getNamespace();
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package org.opendatadiscovery.oddplatform.service.policy.comparer.queryexample;

import java.util.List;
import java.util.function.Function;
import org.opendatadiscovery.oddplatform.dto.QueryExampleDto;
import org.opendatadiscovery.oddplatform.dto.policy.QueryExamplePolicyResolverContext;
import org.opendatadiscovery.oddplatform.model.tables.pojos.QueryExamplePojo;
import org.opendatadiscovery.oddplatform.service.policy.comparer.SimpleFieldComparer;

public class QueryExampleFieldComparer extends SimpleFieldComparer<QueryExamplePolicyResolverContext> {
Expand All @@ -11,6 +13,8 @@ public QueryExampleFieldComparer(final Function<QueryExampleDto, String> fieldEx
}

private static QueryExampleDto getQueryExample(final QueryExamplePolicyResolverContext context) {
return context.detailsDto();
return context.detailsDto() == null
? new QueryExampleDto(new QueryExamplePojo(), List.of())
: context.detailsDto();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public TermFieldComparer(final Function<TermPojo, String> fieldExtractor) {
}

private static TermPojo getTerm(final TermPolicyResolverContext context) {
return context.detailsDto().getTermDto().getTermRefDto().getTerm();
return context.detailsDto().getTermDto().getTermRefDto().getTerm() == null
? new TermPojo()
: context.detailsDto().getTermDto().getTermRefDto().getTerm();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public TermNamespaceFieldComparer(final Function<NamespacePojo, String> fieldExt
}

private static NamespacePojo getTermNamespace(final TermPolicyResolverContext context) {
return context.detailsDto().getTermDto().getTermRefDto().getNamespace();
return context.detailsDto().getTermDto().getTermRefDto().getNamespace() == null
? new NamespacePojo()
: context.detailsDto().getTermDto().getTermRefDto().getNamespace();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import org.opendatadiscovery.oddplatform.dto.policy.PolicyConditionDto;
import org.opendatadiscovery.oddplatform.dto.policy.PolicyConditionKeyDto;
Expand All @@ -22,7 +23,7 @@ public boolean resolve(final PolicyConditionDto condition, final T context) {
return resolveAny(condition.getAny(), context);
} else if (condition.getEq() != null) {
final Map.Entry<PolicyConditionKeyDto, Object> entry = getUnaryCondition(condition.getEq());
return resolveEquals(entry.getKey(), entry.getValue().toString(), context);
return resolveEquals(entry.getKey(), Objects.toString(entry.getValue(), null), context);
} else if (condition.getNotEq() != null) {
final Map.Entry<PolicyConditionKeyDto, Object> entry = getUnaryCondition(condition.getNotEq());
return resolveNotEquals(entry.getKey(), entry.getValue().toString(), context);
Expand Down

0 comments on commit 43fcf2f

Please sign in to comment.