/** * This method uses for validate @Extension / @Example elements. * * @param examples examples array which needs to be validate. * @throws AnnotationValidationException whenever if the validate rule violate, throws the annotation validate * exception with proper message. */ public void examplesValidation(Example[] examples) throws AnnotationValidationException { //Check if the @Example annotated in all the @Extension classes. if (examples.length == 0) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @Example " + "annotated in class {0} is null or empty.", extensionClassFullName)); } else { for (Example example : examples) { //Check if the @Example syntax is empty. if (example.syntax().isEmpty()) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> " + "@Example -> syntax annotated in class {0} is null or empty.", extensionClassFullName)); } //Check if the @Example description is empty. if (example.description().isEmpty()) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> " + "@Example -> description annotated in class {0} is null or empty.", extensionClassFullName)); } } } } }
if (returnAttributes.length == 0) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> " + "@ReturnAttribute annotated in class {0} is null or empty.", extensionClassFullName)); } else if (returnAttributes.length == 1) { String returnAttributeName = returnAttributes[0].name(); throw new AnnotationValidationException(MessageFormat.format("The @Extension -> " + "@ReturnAttribute -> name cannot be annotated in class {1}.", extensionClassFullName)); if (returnAttributes[0].description().isEmpty()) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> " + "@ReturnAttribute -> name:{0} -> description annotated in class {1} is null or empty.", returnAttributeName, extensionClassFullName)); if (returnAttributes[0].type().length == 0) { throw new AnnotationValidationException(MessageFormat.format("The @Extension ->" + " @ReturnAttribute -> name{0} -> type annotated in class {1} is null or empty.", returnAttributeName, extensionClassFullName)); throw new AnnotationValidationException(MessageFormat.format("Only one @Extension -> " + "@ReturnAttribute can be annotated in class {0}.", extensionClassFullName));
String systemParameterName = systemParameter.name(); throw new AnnotationValidationException(MessageFormat.format("The @Extension -> " + "@SystemParameter -> name annotated in class {0} is null or empty.", extensionClassFullName)); if (systemParameter.description().isEmpty()) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> " + "@SystemParameter -> name:{0} -> description annotated in class {1} is null or empty.", systemParameterName, extensionClassFullName)); if (systemParameter.defaultValue().isEmpty()) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> " + "@SystemParameter -> name:{0} -> defaultValue annotated in class {1} is null or empty.", systemParameterName, extensionClassFullName)); if (systemParameter.possibleParameters().length == 0) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> " + "@SystemParameter -> name:{0} -> possibleParameters annotated in class {1} is " + "null or empty.", systemParameterName, extensionClassFullName));
@Extension( name = "firstLengthBatch", namespace = "unique", @Parameter(name = "unique.key", description = "The attribute that should be checked for uniqueness.", type = {DataType.INT, DataType.LONG, DataType.FLOAT, DataType.BOOL, DataType.DOUBLE}), @Parameter(name = "window.length", description = "The number of events the window should tumble.", type = {DataType.INT}), }, examples = { @Example( syntax = "define window CseEventWindow (symbol string, price float, volume int) " + "from CseEventStream#window.unique:firstLengthBatch(symbol, 10)\n" +
String superClass = getMatchingSuperClass(element, new String[]{ AnnotationConstants.SINK_MAPPER_SUPER_CLASS, AnnotationConstants.SINK_SUPER_CLASS, AbstractAnnotationProcessor abstractAnnotationProcessor = null; Extension annotation = element.getAnnotation(Extension.class); String name = annotation.name(); String description = annotation.description(); String namespace = annotation.namespace(); Parameter[] parameters = annotation.parameters(); ReturnAttribute[] returnAttributes = annotation.returnAttributes(); SystemParameter[] systemParameters = annotation.systemParameter(); Example[] examples = annotation.examples(); String extensionClassFullName = element.asType().toString(); if (superClass != null) { case AnnotationConstants.DISTRIBUTION_STRATEGY_SUPER_CLASS: abstractAnnotationProcessor = new DistributionStrategyValidationAnnotationProcessor(extensionClassFullName); break; case AnnotationConstants.SINK_MAPPER_SUPER_CLASS: abstractAnnotationProcessor = new SinkMapperValidationAnnotationProcessor(extensionClassFullName); break; case AnnotationConstants.SINK_SUPER_CLASS: abstractAnnotationProcessor = new SinkValidationAnnotationProcessor(extensionClassFullName); break; case AnnotationConstants.FUNCTION_EXECUTOR_SUPER_CLASS:
@Override public void parameterValidation(Parameter[] parameters) throws AnnotationValidationException { for (Parameter parameter : parameters) { String parameterName = parameter.name(); throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @Parameter ->" + " name annotated in class {0} is null or empty.", extensionClassFullName)); } else if (!PARAMETER_NAME_PATTERN.matcher(parameterName).find()) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @Parameter ->" + " name:{0} annotated in class {1} is not in proper format ''abc.def.ghi''.", parameterName, extensionClassFullName)); if (parameter.description().isEmpty()) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @Parameter ->" + " name:{0} -> description annotated in class {1} is null or empty.", parameterName, extensionClassFullName)); if (parameter.type().length == 0) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @Parameter ->" + " name:{0} -> type annotated in class {1} is null or empty.", parameterName, extensionClassFullName)); if (parameter.dynamic()) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @Parameter ->" + " name:{0} -> dynamic property cannot be true annotated in class {1}.", parameterName, extensionClassFullName)); if (parameter.optional()) { if (parameter.defaultValue().isEmpty()) {
@Override public void parameterValidation(Parameter[] parameters) throws AnnotationValidationException { for (Parameter parameter : parameters) { String parameterName = parameter.name(); throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @Parameter " + "-> name annotated in class {0} is null or empty.", extensionClassFullName)); } else if (!PARAMETER_NAME_PATTERN.matcher(parameterName).find()) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @Parameter " + "-> name:{0} annotated in class {1} is not in proper format ''abc.def.ghi''.", parameterName, extensionClassFullName)); if (parameter.description().isEmpty()) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @Parameter ->" + " name:{0} -> description annotated in class {1} is null or empty.", parameterName, extensionClassFullName)); if (parameter.type().length == 0) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @Parameter ->" + " name:{0} -> type annotated in class {1} is null or empty.", parameterName, extensionClassFullName)); if (parameter.dynamic()) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @Parameter ->" + " name:{0} -> dynamic property cannot be true annotated in class {1}.", parameterName, extensionClassFullName));
@Override public void parameterValidation(Parameter[] parameters) throws AnnotationValidationException { for (Parameter parameter : parameters) { String parameterName = parameter.name(); throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @Parameter ->" + " name annotated in class {0} is null or empty.", extensionClassFullName)); } else if (!PARAMETER_NAME_PATTERN.matcher(parameterName).find()) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @Parameter ->" + " name:{0} annotated in class {1} is not in proper format ''abc.def.ghi''.", parameterName, extensionClassFullName)); if (parameter.description().isEmpty()) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @Parameter ->" + " name:{0} -> description annotated in class {1} is null or empty.", parameterName, extensionClassFullName)); if (parameter.type().length == 0) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @Parameter ->" + " name:{0} -> type annotated in class {1} is null or empty.", parameterName, extensionClassFullName)); if (parameter.dynamic()) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @Parameter ->" + " name:{0} -> dynamic property cannot be true annotated in class {1}.", parameterName, extensionClassFullName)); if (parameter.optional()) { if (parameter.defaultValue().isEmpty()) {
if (returnAttributes.length == 0) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> " + "@ReturnAttribute annotated in class {0} is null or empty.", extensionClassFullName)); } else if (returnAttributes.length == 1) { String returnAttributeName = returnAttributes[0].name(); throw new AnnotationValidationException(MessageFormat.format("The @Extension -> " + "@ReturnAttribute -> name cannot be annotated in class {1}.", extensionClassFullName)); if (returnAttributes[0].description().isEmpty()) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> " + "@ReturnAttribute -> name:{0} -> description annotated in class {1} is null or empty.", returnAttributeName, extensionClassFullName)); if (returnAttributes[0].type().length == 0) { throw new AnnotationValidationException(MessageFormat.format("The @Extension ->" + " @ReturnAttribute -> name{0} -> type annotated in class {1} is null or empty.", returnAttributeName, extensionClassFullName)); throw new AnnotationValidationException(MessageFormat.format("Only one @Extension -> " + "@ReturnAttribute can be annotated in class {0}.", extensionClassFullName));
@Override public void parameterValidation(Parameter[] parameters) throws AnnotationValidationException { for (Parameter parameter : parameters) { String parameterName = parameter.name(); throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @Parameter " + "-> name annotated in class {0} is null or empty.", extensionClassFullName)); } else if (!PARAMETER_NAME_PATTERN.matcher(parameterName).find()) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @Parameter " + "-> name:{0} annotated in class {1} is not in proper format ''abc.def.ghi''.", parameterName, extensionClassFullName)); if (parameter.description().isEmpty()) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @Parameter ->" + " name:{0} -> description annotated in class {1} is null or empty.", parameterName, extensionClassFullName)); if (parameter.type().length == 0) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @Parameter ->" + " name:{0} -> type annotated in class {1} is null or empty.", parameterName, extensionClassFullName)); if (parameter.dynamic()) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @Parameter ->" + " name:{0} -> dynamic property cannot be true annotated in class {1}.", parameterName, extensionClassFullName));
@Override public void parameterValidation(Parameter[] parameters) throws AnnotationValidationException { for (Parameter parameter : parameters) { String parameterName = parameter.name(); throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @Parameter ->" + " name annotated in class {0} is null or empty.", extensionClassFullName)); } else if (!PARAMETER_NAME_PATTERN.matcher(parameterName).find()) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @Parameter ->" + " name:{0} annotated in class {1} is not in proper format ''abc.def.ghi''.", parameterName, extensionClassFullName)); if (parameter.description().isEmpty()) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @Parameter ->" + " name:{0} -> description annotated in class {1} is null or empty.", parameterName, extensionClassFullName)); if (parameter.type().length == 0) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @Parameter ->" + " name:{0} -> type annotated in class {1} is null or empty.", parameterName, extensionClassFullName)); if (parameter.dynamic()) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @Parameter ->" + " name:{0} -> dynamic property cannot be true annotated in class {1}.", parameterName, extensionClassFullName)); if (parameter.optional()) { if (parameter.defaultValue().isEmpty()) {
if (returnAttributes.length == 0) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @ReturnAttribute " + "annotated in class {0} is null or empty.", extensionClassFullName)); } else if (returnAttributes.length == 1) { String returnAttributeName = returnAttributes[0].name(); throw new AnnotationValidationException(MessageFormat.format("The @Extension -> " + "@ReturnAttribute -> name cannot be annotated in class '{0}' extended by Function Executor " + "Processor.", extensionClassFullName)); if (returnAttributes[0].description().isEmpty()) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> " + "@ReturnAttribute -> name:{0} -> description annotated in class {1} is null or empty.", returnAttributeName, extensionClassFullName)); if (returnAttributes[0].type().length == 0) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> " + "@ReturnAttribute -> name{0} -> type annotated in class {1} is null or empty.", returnAttributeName, extensionClassFullName)); throw new AnnotationValidationException(MessageFormat.format("Only one @Extension -> " + "@ReturnAttribute can be annotated in class {0}.", extensionClassFullName));
@Override public void parameterValidation(Parameter[] parameters) throws AnnotationValidationException { for (Parameter parameter : parameters) { String parameterName = parameter.name(); throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @Parameter ->" + " name annotated in class {0} is null or empty.", extensionClassFullName)); } else if (!PARAMETER_NAME_PATTERN.matcher(parameterName).find()) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @Parameter ->" + " name:{0} annotated in class {1} is not in proper format ''abc.def.ghi''.", parameterName, extensionClassFullName)); if (parameter.description().isEmpty()) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @Parameter ->" + " name:{0} -> description annotated in class {1} is null or empty.", parameterName, extensionClassFullName)); if (parameter.type().length == 0) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @Parameter ->" + " name:{0} -> type annotated in class {1} is null or empty.", parameterName, extensionClassFullName)); if (parameter.dynamic()) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @Parameter ->" + " name:{0} -> dynamic property cannot be true annotated in class {1}.", parameterName, extensionClassFullName)); if (parameter.optional()) { if (parameter.defaultValue().isEmpty()) {
@Override public void returnAttributesValidation(ReturnAttribute[] returnAttributes) throws AnnotationValidationException { for (ReturnAttribute returnAttribute : returnAttributes) { String returnAttributeName = returnAttribute.name(); //Check if the @ReturnAttributes name is empty. if (returnAttributeName.isEmpty()) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> " + "@ReturnAttribute -> name annotated in class {0} is null or empty.", extensionClassFullName)); } else if (!CAMEL_CASE_PATTERN.matcher(returnAttributeName).find()) { //Check if the @Extension -> @ReturnAttribute -> name is in a correct camelCase // format using regex pattern. throw new AnnotationValidationException(MessageFormat.format("The @Extension -> " + "@ReturnAttribute -> name {0} annotated in class {1} is not in camelCase format.", returnAttributeName, extensionClassFullName)); } //Check if the @ReturnAttributes description is empty. if (returnAttribute.description().isEmpty()) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> " + "@ReturnAttribute -> name:{0} -> description annotated in class {1} is null or empty.", returnAttributeName, extensionClassFullName)); } //Check if the @ReturnAttributes type is empty. if (returnAttribute.type().length == 0) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> " + "@ReturnAttribute -> name:{0} -> type annotated in class {1} is null or empty.", returnAttributeName, extensionClassFullName)); } } } }
@Override public void parameterValidation(Parameter[] parameters) throws AnnotationValidationException { for (Parameter parameter : parameters) { String parameterName = parameter.name(); throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @Parameter " + "-> name annotated in class {0} is null or empty.", extensionClassFullName)); } else if (!PARAMETER_NAME_PATTERN.matcher(parameterName).find()) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @Parameter " + "-> name:{0} annotated in class {1} is not in proper format ''abc.def.ghi''.", parameterName, extensionClassFullName)); if (parameter.description().isEmpty()) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @Parameter " + "-> name:{0} -> description annotated in class {1} is null or empty.", parameterName, extensionClassFullName)); if (parameter.type().length == 0) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @Parameter " + "-> name:{0} -> type annotated in class {1} is null or empty.", parameterName, extensionClassFullName)); if (parameter.dynamic()) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @Parameter " + "-> name:{0} -> dynamic property cannot be true annotated in class {1}. " + "Only classes extending Sink and SinkMapper can have the dynamic parameters.", parameterName, extensionClassFullName)); if (parameter.optional()) {
@Override public void returnAttributesValidation(ReturnAttribute[] returnAttributes) throws AnnotationValidationException { for (ReturnAttribute returnAttribute : returnAttributes) { String returnAttributeName = returnAttribute.name(); //Check if the @ReturnAttributes name is empty. if (returnAttributeName.isEmpty()) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> " + "@ReturnAttribute -> name annotated in class {0} is null or empty.", extensionClassFullName)); } else if (!CAMEL_CASE_PATTERN.matcher(returnAttributeName).find()) { //Check if the @Extension -> @ReturnAttribute -> name is in a correct camelCase // format using regex pattern. throw new AnnotationValidationException(MessageFormat.format("The @Extension -> " + "@ReturnAttribute -> name {0} annotated in class {1} is not in camelCase format.", returnAttributeName, extensionClassFullName)); } //Check if the @ReturnAttributes description is empty. if (returnAttribute.description().isEmpty()) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> " + "@ReturnAttribute -> name:{0} -> description annotated in class {1} is null or empty.", returnAttributeName, extensionClassFullName)); } //Check if the @ReturnAttributes type is empty. if (returnAttribute.type().length == 0) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> " + "@ReturnAttribute -> name:{0} -> type annotated in class {1} is null or empty.", returnAttributeName, extensionClassFullName)); } } } }
String parameterName = parameter.name(); throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @Parameter -> " + "name annotated in class {0} is null or empty.", extensionClassFullName)); } else if (!PARAMETER_NAME_PATTERN.matcher(parameterName).find()) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @Parameter -> " + "name {0} annotated in class {1} is not in proper format ''abc.def.ghi''.", parameterName, extensionClassFullName)); if (parameter.description().isEmpty()) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @Parameter -> " + "name:{0} -> description annotated in class {1} is null or empty.", parameterName, extensionClassFullName)); if (parameter.type().length == 0) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @Parameter -> " + "name:{0} -> type annotated in class {1} is null or empty.", parameterName, extensionClassFullName)); if (parameter.optional()) { if (parameter.defaultValue().isEmpty()) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @Parameter -> " + "name:{0} -> defaultValue annotated in class {1} cannot be null or empty for the " + "optional parameter.", parameterName, extensionClassFullName));
String returnAttributeName = returnAttribute.name(); throw new AnnotationValidationException(MessageFormat.format("The @Extension -> " + "@ReturnAttribute -> name annotated in class {0} is null or empty.", extensionClassFullName)); } else if (!CAMEL_CASE_PATTERN.matcher(returnAttributeName).find()) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> " + "@ReturnAttribute -> name {0} annotated in class {1} is not in camelCase format.", returnAttributeName, extensionClassFullName)); if (returnAttribute.description().isEmpty()) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> " + "@ReturnAttribute -> name:{0} -> description annotated in class {1} is null or empty.", returnAttributeName, extensionClassFullName)); if (returnAttribute.type().length == 0) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> " + "@ReturnAttribute -> name:{0} -> type annotated in class {1} is null or empty.", returnAttributeName, extensionClassFullName));
@Override public void parameterValidation(Parameter[] parameters) throws AnnotationValidationException { for (Parameter parameter : parameters) { String parameterName = parameter.name(); throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @Parameter " + "-> name annotated in class {0} is null or empty.", extensionClassFullName)); } else if (!PARAMETER_NAME_PATTERN.matcher(parameterName).find()) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @Parameter ->" + " name:{0} annotated in class {1} is not in proper format ''abc.def.ghi''.", parameterName, extensionClassFullName)); if (parameter.description().isEmpty()) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @Parameter ->" + " name:{0} -> description annotated in class {1} is null or empty.", parameterName, extensionClassFullName)); if (parameter.type().length == 0) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @Parameter ->" + " name:{0} -> type annotated in class {1} is null or empty.", parameterName, extensionClassFullName)); if (parameter.dynamic()) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @Parameter ->" + " name:{0} -> dynamic property cannot be true annotated in class {1}.", parameterName, extensionClassFullName)); if (parameter.optional()) { if (parameter.defaultValue().isEmpty()) {
@Override public void parameterValidation(Parameter[] parameters) throws AnnotationValidationException { for (Parameter parameter : parameters) { String parameterName = parameter.name(); throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @Parameter ->" + " name annotated in class {0} is null or empty.", extensionClassFullName)); } else if (!PARAMETER_NAME_PATTERN.matcher(parameterName).find()) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @Parameter ->" + " name:{0} annotated in class {1} is not in proper format ''abc.def.ghi''.", parameterName, extensionClassFullName)); if (parameter.description().isEmpty()) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @Parameter ->" + " name:{0} -> description annotated in class {1} is null or empty.", parameterName, extensionClassFullName)); if (parameter.type().length == 0) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @Parameter ->" + " name:{0} -> type annotated in class {1} is null or empty.", parameterName, extensionClassFullName)); if (parameter.dynamic()) { throw new AnnotationValidationException(MessageFormat.format("The @Extension -> @Parameter ->" + " name:{0} -> dynamic property cannot be true annotated in class {1}.", parameterName, extensionClassFullName)); if (parameter.optional()) { if (parameter.defaultValue().isEmpty()) {