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

Validate mandatory parameter mismatch in annotation. #1362

Merged
merged 1 commit into from
Jul 1, 2019
Merged
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 @@ -26,7 +26,10 @@

import java.text.MessageFormat;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;

/**
Expand Down Expand Up @@ -134,8 +137,12 @@ public void parameterOverloadValidation(ParameterOverload[] parameterOverloads,
throws AnnotationValidationException {

Map<String, Parameter> parameterMap = new HashMap<>();
Set<String> mandatoryParameterSet = new HashSet<>();
for (Parameter parameter : parameters) {
parameterMap.put(parameter.name(), parameter);
if (!parameter.optional()) {
mandatoryParameterSet.add(parameter.name());
}
}

for (ParameterOverload parameterOverload : parameterOverloads) {
Expand All @@ -161,6 +168,33 @@ public void parameterOverloadValidation(ParameterOverload[] parameterOverloads,
}
}
}

if (parameterOverloads.length > 0) {
Set<String> mandatoryParameterSetViaOverload = new HashSet<>(parameterMap.keySet());
for (Iterator<String> iterator = mandatoryParameterSetViaOverload.iterator(); iterator.hasNext(); ) {
String parameter = iterator.next();
for (ParameterOverload parameterOverload : parameterOverloads) {
boolean contains = false;
for (String parameterName : parameterOverload.parameterNames()) {
if (parameter.equalsIgnoreCase(parameterName)) {
contains = true;
break;
}
}
if (!contains) {
iterator.remove();
break;
}
}
}

if (!mandatoryParameterSetViaOverload.equals(mandatoryParameterSet)) {
throw new AnnotationValidationException("Mandatory parameter information in ParameterOverload " +
"and based on 'optional' annotation is a mismatch. The parameters '" +
mandatoryParameterSetViaOverload + "' always appearing in ParameterOverload, but '" +
mandatoryParameterSet + "' are defined as not 'optional' in the annotations.");
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
defaultValue = "If z value is not given, drop the third parameter of the output.")
},
parameterOverloads = {
@ParameterOverload(),
@ParameterOverload(parameterNames = {"theta", "rho"}),
@ParameterOverload(parameterNames = {"theta", "rho", "z"})
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
type = {DataType.DOUBLE}),
@Parameter(name = "error.bound",
description = "The error bound value.",
optional = true,
defaultValue = "`support.threshold`/10",
type = {DataType.DOUBLE}),
@Parameter(name = "attribute",
description = "The attributes to group the events. If no attributes are given, " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
description = "The attribute that should be checked for the order.",
type = {DataType.STRING, DataType.DOUBLE, DataType.INT, DataType.LONG, DataType.FLOAT,
DataType.LONG},
optional = true,
dynamic = true,
defaultValue = "The concatenation of all the attributes of the event is considered."),
@Parameter(name = "order",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,8 @@ public static void validateExpressionExecutors(Object objectHavingAnnotation,
for (ParameterOverload aParameterOverload : parameterOverloads) {
String[] overloadParameterNames = aParameterOverload.parameterNames();
if (overloadParameterNames.length == attributeExpressionExecutors.length &&
((overloadParameterNames.length == 0) || (overloadParameterNames.length > 0)
&& !(overloadParameterNames[overloadParameterNames.length - 1].
equals(REPETITIVE_PARAMETER_NOTATION)))) {
(overloadParameterNames.length == 0 || !overloadParameterNames[overloadParameterNames.length - 1].
equals(REPETITIVE_PARAMETER_NOTATION))) {
boolean isExpectedParameterOverload = true;
for (int i = 0; i < overloadParameterNames.length; i++) {
String overloadParameterName = overloadParameterNames[i];
Expand Down