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

1644 - added support of eq:null to the policies #1647

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -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
Loading