Skip to content

Commit

Permalink
Merge branch 'master' into fix_patch_4502
Browse files Browse the repository at this point in the history
  • Loading branch information
scwlkq committed Oct 30, 2023
2 parents c7bfe8e + 11def17 commit 4a2ac92
Show file tree
Hide file tree
Showing 30 changed files with 168 additions and 73 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ subprojects {

dependency "com.h3xstream.findsecbugs:findsecbugs-plugin:1.11.0"
dependency "com.mebigfatguy.fb-contrib:fb-contrib:7.6.0"
dependency "com.jayway.jsonpath:json-path:2.7.0"

dependency "org.springframework.boot:spring-boot-starter-web:2.7.10"
dependency "io.openmessaging:registry-server:0.0.1"
Expand Down
4 changes: 2 additions & 2 deletions eventmesh-common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ dependencies {
api "org.apache.commons:commons-text"
api "org.apache.commons:commons-lang3"

implementation group: 'com.jayway.jsonpath', name: 'json-path', version: '2.7.0'
implementation 'commons-net:commons-net:3.9.0'
api "com.jayway.jsonpath:json-path"

api "io.cloudevents:cloudevents-core"
api "io.cloudevents:cloudevents-json-jackson"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,7 @@
* limitations under the License.
*/

package org.apache.eventmesh.common.transform;

import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class Variable {

private String name;
private String jsonPath;

dependencies {
implementation project(":eventmesh-common")
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
* limitations under the License.
*/

package org.apache.eventmesh.common.filter;
package org.apache.eventmesh.filter;

import org.apache.eventmesh.common.filter.condition.Condition;
import org.apache.eventmesh.filter.condition.Condition;

import java.util.ArrayList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.apache.eventmesh.common.filter.condition;
package org.apache.eventmesh.filter.condition;

import java.util.ArrayList;
import java.util.Iterator;
Expand All @@ -24,11 +24,11 @@

import com.fasterxml.jackson.databind.JsonNode;

class AnythingButCondition implements Condition {
public class AnythingButCondition implements Condition {

private List<Condition> conditionList = new ArrayList<>();

AnythingButCondition(JsonNode condition) {
public AnythingButCondition(JsonNode condition) {

if (condition.isValueNode()) {
this.conditionList.add(new SpecifiedCondition(condition));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.apache.eventmesh.common.filter.condition;
package org.apache.eventmesh.filter.condition;

import com.fasterxml.jackson.databind.JsonNode;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.apache.eventmesh.common.filter.condition;
package org.apache.eventmesh.filter.condition;

import com.fasterxml.jackson.databind.JsonNode;

Expand All @@ -38,7 +38,7 @@ public Condition build() {
Condition condition = null;
switch (this.key) {
case "prefix":
condition = new PrefixxCondition(this.jsonNode);
condition = new PrefixCondition(this.jsonNode);
break;
case "suffix":
condition = new SuffixCondition(this.jsonNode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
* limitations under the License.
*/

package org.apache.eventmesh.common.filter.condition;
package org.apache.eventmesh.filter.condition;

import com.fasterxml.jackson.databind.JsonNode;

class ExistsCondition implements Condition {
public class ExistsCondition implements Condition {

private JsonNode exists;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
* limitations under the License.
*/

package org.apache.eventmesh.common.filter.condition;
package org.apache.eventmesh.filter.condition;

import java.util.ArrayList;
import java.util.List;

import com.fasterxml.jackson.databind.JsonNode;

class NumericCondition implements Condition {
public class NumericCondition implements Condition {

List<String> operators = new ArrayList<>();
List<Double> nums = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
* limitations under the License.
*/

package org.apache.eventmesh.common.filter.condition;
package org.apache.eventmesh.filter.condition;

import com.fasterxml.jackson.databind.JsonNode;

class PrefixxCondition implements Condition {
public class PrefixCondition implements Condition {

private final String prefix;

public PrefixxCondition(JsonNode suffix) {
public PrefixCondition(JsonNode suffix) {
this.prefix = suffix.asText();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
* limitations under the License.
*/

package org.apache.eventmesh.common.filter.condition;
package org.apache.eventmesh.filter.condition;

import com.fasterxml.jackson.databind.JsonNode;

class SpecifiedCondition implements Condition {
public class SpecifiedCondition implements Condition {

private final JsonNode specified;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
* limitations under the License.
*/

package org.apache.eventmesh.common.filter.condition;
package org.apache.eventmesh.filter.condition;

import com.fasterxml.jackson.databind.JsonNode;

class SuffixCondition implements Condition {
public class SuffixCondition implements Condition {

private final String suffix;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
* limitations under the License.
*/

package org.apache.eventmesh.common.filter.pattern;
package org.apache.eventmesh.filter.pattern;

import org.apache.eventmesh.common.filter.PatternEntry;
import org.apache.eventmesh.common.utils.JsonPathUtils;
import org.apache.eventmesh.filter.PatternEntry;

import org.apache.commons.lang3.StringUtils;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
* limitations under the License.
*/

package org.apache.eventmesh.common.filter.patternbuild;
package org.apache.eventmesh.filter.patternbuild;

import org.apache.eventmesh.common.exception.JsonException;
import org.apache.eventmesh.common.filter.PatternEntry;
import org.apache.eventmesh.common.filter.condition.Condition;
import org.apache.eventmesh.common.filter.condition.ConditionsBuilder;
import org.apache.eventmesh.common.filter.pattern.Pattern;
import org.apache.eventmesh.filter.PatternEntry;
import org.apache.eventmesh.filter.condition.Condition;
import org.apache.eventmesh.filter.condition.ConditionsBuilder;
import org.apache.eventmesh.filter.pattern.Pattern;

import java.util.ArrayDeque;
import java.util.Iterator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
* limitations under the License.
*/

package org.apache.eventmesh.common.filter;
package org.apache.eventmesh.filter;

import org.apache.eventmesh.common.filter.pattern.Pattern;
import org.apache.eventmesh.common.filter.patternbuild.PatternBuilder;
import org.apache.eventmesh.filter.pattern.Pattern;
import org.apache.eventmesh.filter.patternbuild.PatternBuilder;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
Expand Down
21 changes: 21 additions & 0 deletions eventmesh-transformer/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/


dependencies {
implementation project(":eventmesh-common")
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@
* limitations under the License.
*/

package org.apache.eventmesh.common.transform;
package org.apache.eventmesh.transformer;

import org.apache.eventmesh.common.exception.EventMeshException;

class ConstantTransformer implements Transformer {
public class ConstantTransformer implements Transformer {

private final String jsonpath;

Expand All @@ -28,7 +26,7 @@ class ConstantTransformer implements Transformer {
}

@Override
public String transform(String json) throws EventMeshException {
public String transform(String json) throws TransformException {
return this.jsonpath;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
* limitations under the License.
*/

package org.apache.eventmesh.common.transform;
package org.apache.eventmesh.transformer;

import org.apache.eventmesh.common.exception.EventMeshException;
import org.apache.eventmesh.common.utils.JsonPathUtils;

import java.util.ArrayList;
Expand Down Expand Up @@ -52,7 +51,7 @@ public JsonPathParser(String jsonPathString) {
if (valueNode.isValueNode()) {
variablesList.add(new Variable(name, valueNode.asText()));
} else {
throw new EventMeshException("invalid config:" + jsonPathString);
throw new TransformException("invalid config:" + jsonPathString);
}

}
Expand All @@ -67,7 +66,6 @@ public JsonPathParser(String jsonPathString) {
*/

public List<Variable> match(String json) throws JsonProcessingException {

if (json == null || json.isEmpty()) {
return new ArrayList<>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.apache.eventmesh.common.transform;
package org.apache.eventmesh.transformer;

class OriginalTransformer implements Transformer {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,23 @@
* limitations under the License.
*/

package org.apache.eventmesh.common.transform;

import org.apache.eventmesh.common.exception.EventMeshException;
package org.apache.eventmesh.transformer;

import org.apache.commons.text.StringSubstitutor;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class Template {

private String template;

public String substitute(List<Variable> variables) throws EventMeshException {
public Template(String template) {
this.template = template;
}

public String substitute(List<Variable> variables) throws TransformException {

Map<String, String> valuesMap = variables.stream()
.filter(variable -> variable.getJsonPath() != null)
Expand All @@ -44,4 +41,12 @@ public String substitute(List<Variable> variables) throws EventMeshException {
return sub.replace(template);

}

public String getTemplate() {
return template;
}

public void setTemplate(String template) {
this.template = template;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.apache.eventmesh.common.transform;
package org.apache.eventmesh.transformer;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.eventmesh.transformer;

/**
* Transform exception
*/
public class TransformException extends RuntimeException {

private static final long serialVersionUID = -4351489859520642285L;

public TransformException(String message) {
super(message);
}

public TransformException(String message, Throwable cause) {
super(message, cause);
}

}
Loading

0 comments on commit 4a2ac92

Please sign in to comment.