http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/comparison/AbstractNumericComparison.java ---------------------------------------------------------------------- diff --git a/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/comparison/AbstractNumericComparison.java b/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/comparison/AbstractNumericComparison.java new file mode 100644 index 0000000..d74e9cf --- /dev/null +++ b/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/comparison/AbstractNumericComparison.java @@ -0,0 +1,68 @@ +/* + * 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.nifi.hl7.query.evaluator.comparison; + +import java.util.regex.Pattern; + +import org.apache.nifi.hl7.query.evaluator.Evaluator; + +public abstract class AbstractNumericComparison extends AbstractComparisonEvaluator { + + private static final Pattern NUMERIC_PATTERN = Pattern.compile("\\d+(\\.\\d+)?"); + + public AbstractNumericComparison(final Evaluator<?> lhs, final Evaluator<?> rhs) { + super(lhs, rhs); + } + + @Override + protected final boolean compare(final Object lhs, final Object rhs) { + final Double lhsDouble = toDouble(lhs); + if (lhsDouble == null) { + return false; + } + + final Double rhsDouble = toDouble(rhs); + if (rhsDouble == null) { + return false; + } + + return compareNumbers(lhsDouble, rhsDouble); + } + + private Double toDouble(final Object value) { + if (value == null) { + return null; + } + + if (value instanceof Double) { + return (Double) value; + } + if (value instanceof Number) { + return ((Number) value).doubleValue(); + } + + if (value instanceof String) { + if (NUMERIC_PATTERN.matcher((String) value).matches()) { + return Double.parseDouble((String) value); + } + } + + return null; + } + + protected abstract boolean compareNumbers(final Double lhs, final Double rhs); +}
http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/comparison/EqualsEvaluator.java ---------------------------------------------------------------------- diff --git a/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/comparison/EqualsEvaluator.java b/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/comparison/EqualsEvaluator.java new file mode 100644 index 0000000..fa6c57b --- /dev/null +++ b/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/comparison/EqualsEvaluator.java @@ -0,0 +1,32 @@ +/* + * 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.nifi.hl7.query.evaluator.comparison; + +import org.apache.nifi.hl7.query.evaluator.Evaluator; + +public class EqualsEvaluator extends AbstractComparisonEvaluator { + + public EqualsEvaluator(final Evaluator<?> lhs, final Evaluator<?> rhs) { + super(lhs, rhs); + } + + @Override + protected boolean compare(final Object lhs, final Object rhs) { + return lhs != null && rhs != null && ((lhs == rhs) || (lhs.equals(rhs)) || lhs.toString().equals(rhs.toString())); + } + +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/comparison/GreaterThanEvaluator.java ---------------------------------------------------------------------- diff --git a/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/comparison/GreaterThanEvaluator.java b/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/comparison/GreaterThanEvaluator.java new file mode 100644 index 0000000..cfef7b5 --- /dev/null +++ b/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/comparison/GreaterThanEvaluator.java @@ -0,0 +1,32 @@ +/* + * 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.nifi.hl7.query.evaluator.comparison; + +import org.apache.nifi.hl7.query.evaluator.Evaluator; + +public class GreaterThanEvaluator extends AbstractNumericComparison { + + public GreaterThanEvaluator(final Evaluator<?> lhs, final Evaluator<?> rhs) { + super(lhs, rhs); + } + + @Override + protected boolean compareNumbers(final Double lhs, final Double rhs) { + return lhs > rhs; + } + +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/comparison/GreaterThanOrEqualEvaluator.java ---------------------------------------------------------------------- diff --git a/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/comparison/GreaterThanOrEqualEvaluator.java b/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/comparison/GreaterThanOrEqualEvaluator.java new file mode 100644 index 0000000..d9da6f7 --- /dev/null +++ b/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/comparison/GreaterThanOrEqualEvaluator.java @@ -0,0 +1,32 @@ +/* + * 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.nifi.hl7.query.evaluator.comparison; + +import org.apache.nifi.hl7.query.evaluator.Evaluator; + +public class GreaterThanOrEqualEvaluator extends AbstractNumericComparison { + + public GreaterThanOrEqualEvaluator(final Evaluator<?> lhs, final Evaluator<?> rhs) { + super(lhs, rhs); + } + + @Override + protected boolean compareNumbers(final Double lhs, final Double rhs) { + return lhs >= rhs; + } + +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/comparison/IsNullEvaluator.java ---------------------------------------------------------------------- diff --git a/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/comparison/IsNullEvaluator.java b/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/comparison/IsNullEvaluator.java new file mode 100644 index 0000000..0f16dd9 --- /dev/null +++ b/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/comparison/IsNullEvaluator.java @@ -0,0 +1,70 @@ +/* + * 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.nifi.hl7.query.evaluator.comparison; + +import java.util.Collection; +import java.util.Map; + +import org.apache.nifi.hl7.model.HL7Component; +import org.apache.nifi.hl7.query.evaluator.BooleanEvaluator; +import org.apache.nifi.hl7.query.evaluator.Evaluator; + +public class IsNullEvaluator extends BooleanEvaluator { + + private final Evaluator<?> subjectEvaluator; + + public IsNullEvaluator(final Evaluator<?> subjectEvaluator) { + this.subjectEvaluator = subjectEvaluator; + } + + @Override + public Boolean evaluate(final Map<String, Object> objectMap) { + Object subjectValue = subjectEvaluator.evaluate(objectMap); + if (subjectValue == null) { + return true; + } + + return isNull(subjectValue); + } + + private boolean isNull(Object subjectValue) { + if (subjectValue == null) { + return true; + } + + if (subjectValue instanceof HL7Component) { + subjectValue = ((HL7Component) subjectValue).getValue(); + } + + if (subjectValue instanceof Collection) { + final Collection<?> collection = (Collection<?>) subjectValue; + if (collection.isEmpty()) { + return true; + } + + for (final Object obj : collection) { + if (!isNull(obj)) { + return false; + } + } + + return true; + } + + return subjectValue == null; + } +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/comparison/LessThanEvaluator.java ---------------------------------------------------------------------- diff --git a/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/comparison/LessThanEvaluator.java b/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/comparison/LessThanEvaluator.java new file mode 100644 index 0000000..2805860 --- /dev/null +++ b/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/comparison/LessThanEvaluator.java @@ -0,0 +1,32 @@ +/* + * 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.nifi.hl7.query.evaluator.comparison; + +import org.apache.nifi.hl7.query.evaluator.Evaluator; + +public class LessThanEvaluator extends AbstractNumericComparison { + + public LessThanEvaluator(final Evaluator<?> lhs, final Evaluator<?> rhs) { + super(lhs, rhs); + } + + @Override + protected boolean compareNumbers(final Double lhs, final Double rhs) { + return lhs < rhs; + } + +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/comparison/LessThanOrEqualEvaluator.java ---------------------------------------------------------------------- diff --git a/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/comparison/LessThanOrEqualEvaluator.java b/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/comparison/LessThanOrEqualEvaluator.java new file mode 100644 index 0000000..e7eb156 --- /dev/null +++ b/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/comparison/LessThanOrEqualEvaluator.java @@ -0,0 +1,32 @@ +/* + * 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.nifi.hl7.query.evaluator.comparison; + +import org.apache.nifi.hl7.query.evaluator.Evaluator; + +public class LessThanOrEqualEvaluator extends AbstractNumericComparison { + + public LessThanOrEqualEvaluator(final Evaluator<?> lhs, final Evaluator<?> rhs) { + super(lhs, rhs); + } + + @Override + protected boolean compareNumbers(final Double lhs, final Double rhs) { + return lhs <= rhs; + } + +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/comparison/NotEqualsEvaluator.java ---------------------------------------------------------------------- diff --git a/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/comparison/NotEqualsEvaluator.java b/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/comparison/NotEqualsEvaluator.java new file mode 100644 index 0000000..98715ff --- /dev/null +++ b/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/comparison/NotEqualsEvaluator.java @@ -0,0 +1,32 @@ +/* + * 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.nifi.hl7.query.evaluator.comparison; + +import org.apache.nifi.hl7.query.evaluator.Evaluator; + +public class NotEqualsEvaluator extends AbstractComparisonEvaluator { + + public NotEqualsEvaluator(final Evaluator<?> lhs, final Evaluator<?> rhs) { + super(lhs, rhs); + } + + @Override + protected boolean compare(final Object lhs, final Object rhs) { + return lhs != null && rhs != null && lhs != rhs && !lhs.equals(rhs) && !lhs.toString().equals(rhs.toString()); + } + +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/comparison/NotEvaluator.java ---------------------------------------------------------------------- diff --git a/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/comparison/NotEvaluator.java b/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/comparison/NotEvaluator.java new file mode 100644 index 0000000..3343c1c --- /dev/null +++ b/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/comparison/NotEvaluator.java @@ -0,0 +1,37 @@ +/* + * 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.nifi.hl7.query.evaluator.comparison; + +import java.util.Map; + +import org.apache.nifi.hl7.query.evaluator.BooleanEvaluator; + +public class NotEvaluator extends BooleanEvaluator { + + private final BooleanEvaluator subjectEvaluator; + + public NotEvaluator(final BooleanEvaluator subjectEvaluator) { + this.subjectEvaluator = subjectEvaluator; + } + + @Override + public Boolean evaluate(final Map<String, Object> objectMap) { + final Boolean subjectValue = subjectEvaluator.evaluate(objectMap); + return (subjectValue == null || Boolean.TRUE.equals(subjectValue)); + } + +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/comparison/NotNullEvaluator.java ---------------------------------------------------------------------- diff --git a/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/comparison/NotNullEvaluator.java b/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/comparison/NotNullEvaluator.java new file mode 100644 index 0000000..80d6c45 --- /dev/null +++ b/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/comparison/NotNullEvaluator.java @@ -0,0 +1,66 @@ +/* + * 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.nifi.hl7.query.evaluator.comparison; + +import java.util.Collection; +import java.util.Map; + +import org.apache.nifi.hl7.model.HL7Component; +import org.apache.nifi.hl7.query.evaluator.BooleanEvaluator; +import org.apache.nifi.hl7.query.evaluator.Evaluator; + +public class NotNullEvaluator extends BooleanEvaluator { + + private final Evaluator<?> subjectEvaluator; + + public NotNullEvaluator(final Evaluator<?> subjectEvaluator) { + this.subjectEvaluator = subjectEvaluator; + } + + @Override + public Boolean evaluate(final Map<String, Object> objectMap) { + Object subjectValue = subjectEvaluator.evaluate(objectMap); + if (subjectValue == null) { + return false; + } + + return isNotNull(subjectValue); + } + + private boolean isNotNull(Object subjectValue) { + if (subjectValue instanceof HL7Component) { + subjectValue = ((HL7Component) subjectValue).getValue(); + } + + if (subjectValue instanceof Collection) { + final Collection<?> collection = (Collection<?>) subjectValue; + if (collection.isEmpty()) { + return false; + } + + for (final Object obj : collection) { + if (isNotNull(obj)) { + return true; + } + } + + return false; + } + + return subjectValue != null; + } +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/literal/IntegerLiteralEvaluator.java ---------------------------------------------------------------------- diff --git a/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/literal/IntegerLiteralEvaluator.java b/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/literal/IntegerLiteralEvaluator.java new file mode 100644 index 0000000..dfceee4 --- /dev/null +++ b/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/literal/IntegerLiteralEvaluator.java @@ -0,0 +1,36 @@ +/* + * 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.nifi.hl7.query.evaluator.literal; + +import java.util.Map; + +import org.apache.nifi.hl7.query.evaluator.IntegerEvaluator; + +public class IntegerLiteralEvaluator extends IntegerEvaluator { + + private final Integer value; + + public IntegerLiteralEvaluator(final Integer value) { + this.value = value; + } + + @Override + public Integer evaluate(final Map<String, Object> objectMap) { + return value; + } + +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/literal/StringLiteralEvaluator.java ---------------------------------------------------------------------- diff --git a/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/literal/StringLiteralEvaluator.java b/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/literal/StringLiteralEvaluator.java new file mode 100644 index 0000000..278ac1d --- /dev/null +++ b/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/literal/StringLiteralEvaluator.java @@ -0,0 +1,36 @@ +/* + * 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.nifi.hl7.query.evaluator.literal; + +import java.util.Map; + +import org.apache.nifi.hl7.query.evaluator.StringEvaluator; + +public class StringLiteralEvaluator extends StringEvaluator { + + private final String value; + + public StringLiteralEvaluator(final String value) { + this.value = value; + } + + @Override + public String evaluate(final Map<String, Object> objectMap) { + return value; + } + +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/logic/AndEvaluator.java ---------------------------------------------------------------------- diff --git a/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/logic/AndEvaluator.java b/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/logic/AndEvaluator.java new file mode 100644 index 0000000..989cee4 --- /dev/null +++ b/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/logic/AndEvaluator.java @@ -0,0 +1,44 @@ +/* + * 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.nifi.hl7.query.evaluator.logic; + +import java.util.Map; + +import org.apache.nifi.hl7.query.evaluator.BooleanEvaluator; + +public class AndEvaluator extends BooleanEvaluator { + + private final BooleanEvaluator lhs; + private final BooleanEvaluator rhs; + + public AndEvaluator(final BooleanEvaluator lhs, final BooleanEvaluator rhs) { + this.lhs = lhs; + this.rhs = rhs; + } + + @Override + public Boolean evaluate(final Map<String, Object> objectMap) { + final Boolean lhsValue = lhs.evaluate(objectMap); + if (lhsValue == null || Boolean.FALSE.equals(lhsValue)) { + return false; + } + + final Boolean rhsValue = rhs.evaluate(objectMap); + return (rhsValue != null && Boolean.TRUE.equals(rhsValue)); + } + +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/logic/OrEvaluator.java ---------------------------------------------------------------------- diff --git a/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/logic/OrEvaluator.java b/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/logic/OrEvaluator.java new file mode 100644 index 0000000..e86daad --- /dev/null +++ b/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/logic/OrEvaluator.java @@ -0,0 +1,44 @@ +/* + * 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.nifi.hl7.query.evaluator.logic; + +import java.util.Map; + +import org.apache.nifi.hl7.query.evaluator.BooleanEvaluator; + +public class OrEvaluator extends BooleanEvaluator { + + private final BooleanEvaluator lhs; + private final BooleanEvaluator rhs; + + public OrEvaluator(final BooleanEvaluator lhs, final BooleanEvaluator rhs) { + this.lhs = lhs; + this.rhs = rhs; + } + + @Override + public Boolean evaluate(final Map<String, Object> objectMap) { + final Boolean lhsValue = lhs.evaluate(objectMap); + if (lhsValue != null && Boolean.TRUE.equals(lhsValue)) { + return true; + } + + final Boolean rhsValue = rhs.evaluate(objectMap); + return (rhsValue != null && Boolean.TRUE.equals(rhsValue)); + } + +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/message/DeclaredReferenceEvaluator.java ---------------------------------------------------------------------- diff --git a/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/message/DeclaredReferenceEvaluator.java b/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/message/DeclaredReferenceEvaluator.java new file mode 100644 index 0000000..bb3f203 --- /dev/null +++ b/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/message/DeclaredReferenceEvaluator.java @@ -0,0 +1,43 @@ +/* + * 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.nifi.hl7.query.evaluator.message; + +import java.util.Map; + +import org.apache.nifi.hl7.query.evaluator.Evaluator; +import org.apache.nifi.hl7.query.evaluator.StringEvaluator; + +public class DeclaredReferenceEvaluator implements Evaluator<Object> { + + private final StringEvaluator referenceNameEvaluator; + + public DeclaredReferenceEvaluator(final StringEvaluator referenceNameEvaluator) { + this.referenceNameEvaluator = referenceNameEvaluator; + } + + @Override + public Object evaluate(final Map<String, Object> objectMap) { + final String referenceName = referenceNameEvaluator.evaluate(objectMap); + return objectMap.get(referenceName); + } + + @Override + public Class<? extends Object> getType() { + return Object.class; + } + +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/message/DotEvaluator.java ---------------------------------------------------------------------- diff --git a/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/message/DotEvaluator.java b/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/message/DotEvaluator.java new file mode 100644 index 0000000..238b540 --- /dev/null +++ b/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/message/DotEvaluator.java @@ -0,0 +1,89 @@ +/* + * 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.nifi.hl7.query.evaluator.message; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; + +import org.apache.nifi.hl7.model.HL7Component; +import org.apache.nifi.hl7.model.HL7Message; +import org.apache.nifi.hl7.model.HL7Segment; +import org.apache.nifi.hl7.query.evaluator.Evaluator; +import org.apache.nifi.hl7.query.evaluator.IntegerEvaluator; + +public class DotEvaluator implements Evaluator<Object> { + + private final Evaluator<?> lhs; + private final IntegerEvaluator rhs; + + public DotEvaluator(final Evaluator<?> lhs, final IntegerEvaluator rhs) { + this.lhs = lhs; + this.rhs = rhs; + } + + @Override + public Object evaluate(final Map<String, Object> objectMap) { + final Object lhsValue = this.lhs.evaluate(objectMap); + final Integer rhsValue = this.rhs.evaluate(objectMap); + + if (lhsValue == null || rhsValue == null) { + return null; + } + + final List<Object> results = new ArrayList<>(); + if (lhsValue instanceof Collection) { + final Collection<?> lhsCollection = (Collection<?>) lhsValue; + for (final Object obj : lhsCollection) { + final Object val = getValue(obj, rhsValue); + results.add(val); + } + } else { + final Object val = getValue(lhsValue, rhsValue); + return val; + } + + return results; + } + + private Object getValue(final Object lhsValue, final int rhsValue) { + final List<?> list; + if (lhsValue instanceof HL7Message) { + list = ((HL7Message) lhsValue).getSegments(); + } else if (lhsValue instanceof HL7Segment) { + list = ((HL7Segment) lhsValue).getFields(); + } else if (lhsValue instanceof HL7Component) { + list = ((HL7Component) lhsValue).getComponents(); + } else { + return null; + } + + if (rhsValue > list.size()) { + return null; + } + + // convert from 0-based to 1-based + return list.get(rhsValue - 1); + } + + @Override + public Class<? extends Object> getType() { + return Object.class; + } + +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/message/FieldEvaluator.java ---------------------------------------------------------------------- diff --git a/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/message/FieldEvaluator.java b/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/message/FieldEvaluator.java new file mode 100644 index 0000000..bc8046e --- /dev/null +++ b/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/message/FieldEvaluator.java @@ -0,0 +1,68 @@ +/* + * 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.nifi.hl7.query.evaluator.message; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import org.apache.nifi.hl7.model.HL7Field; +import org.apache.nifi.hl7.model.HL7Segment; +import org.apache.nifi.hl7.query.evaluator.Evaluator; +import org.apache.nifi.hl7.query.evaluator.IntegerEvaluator; + +@SuppressWarnings("rawtypes") +public class FieldEvaluator implements Evaluator<List> { + + private final SegmentEvaluator segmentEvaluator; + private final IntegerEvaluator indexEvaluator; + + public FieldEvaluator(final SegmentEvaluator segmentEvaluator, final IntegerEvaluator indexEvaluator) { + this.segmentEvaluator = segmentEvaluator; + this.indexEvaluator = indexEvaluator; + } + + public List<HL7Field> evaluate(final Map<String, Object> objectMap) { + final List<HL7Segment> segments = segmentEvaluator.evaluate(objectMap); + if (segments == null) { + return Collections.emptyList(); + } + + final Integer index = indexEvaluator.evaluate(objectMap); + if (index == null) { + return Collections.emptyList(); + } + + final List<HL7Field> fields = new ArrayList<>(); + for (final HL7Segment segment : segments) { + final List<HL7Field> segmentFields = segment.getFields(); + if (segmentFields.size() <= index) { + continue; + } + + fields.add(segmentFields.get(index)); + } + + return fields; + } + + public Class<? extends List> getType() { + return List.class; + } + +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/message/MessageEvaluator.java ---------------------------------------------------------------------- diff --git a/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/message/MessageEvaluator.java b/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/message/MessageEvaluator.java new file mode 100644 index 0000000..f430b50 --- /dev/null +++ b/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/message/MessageEvaluator.java @@ -0,0 +1,34 @@ +/* + * 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.nifi.hl7.query.evaluator.message; + +import java.util.Map; + +import org.apache.nifi.hl7.model.HL7Message; +import org.apache.nifi.hl7.query.evaluator.Evaluator; + +public class MessageEvaluator implements Evaluator<HL7Message> { + + public HL7Message evaluate(final Map<String, Object> objectMap) { + return (HL7Message) objectMap.get(Evaluator.MESSAGE_KEY); + } + + public Class<? extends HL7Message> getType() { + return HL7Message.class; + } + +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/message/SegmentEvaluator.java ---------------------------------------------------------------------- diff --git a/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/message/SegmentEvaluator.java b/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/message/SegmentEvaluator.java new file mode 100644 index 0000000..9840461 --- /dev/null +++ b/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/evaluator/message/SegmentEvaluator.java @@ -0,0 +1,52 @@ +/* + * 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.nifi.hl7.query.evaluator.message; + +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import org.apache.nifi.hl7.model.HL7Message; +import org.apache.nifi.hl7.model.HL7Segment; +import org.apache.nifi.hl7.query.evaluator.Evaluator; +import org.apache.nifi.hl7.query.evaluator.StringEvaluator; + +@SuppressWarnings("rawtypes") +public class SegmentEvaluator implements Evaluator<List> { + + private final StringEvaluator segmentTypeEvaluator; + + public SegmentEvaluator(final StringEvaluator segmentTypeEvaluator) { + this.segmentTypeEvaluator = segmentTypeEvaluator; + } + + public List<HL7Segment> evaluate(final Map<String, Object> objectMap) { + final String segmentType = segmentTypeEvaluator.evaluate(objectMap); + if (segmentType == null) { + return Collections.emptyList(); + } + + final HL7Message message = (HL7Message) objectMap.get(Evaluator.MESSAGE_KEY); + final List<HL7Segment> segments = message.getSegments(segmentType); + return (segments == null) ? Collections.<HL7Segment>emptyList() : segments; + } + + public Class<? extends List> getType() { + return List.class; + } + +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/exception/HL7QueryParsingException.java ---------------------------------------------------------------------- diff --git a/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/exception/HL7QueryParsingException.java b/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/exception/HL7QueryParsingException.java new file mode 100644 index 0000000..e27dd58 --- /dev/null +++ b/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/exception/HL7QueryParsingException.java @@ -0,0 +1,38 @@ +/* + * 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.nifi.hl7.query.exception; + +public class HL7QueryParsingException extends RuntimeException { + + private static final long serialVersionUID = 1L; + + public HL7QueryParsingException() { + super(); + } + + public HL7QueryParsingException(final Throwable cause) { + super(cause); + } + + public HL7QueryParsingException(final String message) { + super(message); + } + + public HL7QueryParsingException(final String message, final Throwable cause) { + super(message, cause); + } +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/result/MissedResult.java ---------------------------------------------------------------------- diff --git a/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/result/MissedResult.java b/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/result/MissedResult.java new file mode 100644 index 0000000..1043ab6 --- /dev/null +++ b/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/result/MissedResult.java @@ -0,0 +1,57 @@ +/* + * 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.nifi.hl7.query.result; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.nifi.hl7.query.QueryResult; +import org.apache.nifi.hl7.query.ResultHit; +import org.apache.nifi.hl7.query.Selection; + +public class MissedResult implements QueryResult { + + private final List<Selection> selections; + + public MissedResult(final List<Selection> selections) { + this.selections = selections; + } + + @Override + public List<String> getLabels() { + final List<String> labels = new ArrayList<>(); + for (final Selection selection : selections) { + labels.add(selection.getName()); + } + return labels; + } + + @Override + public boolean isMatch() { + return false; + } + + @Override + public ResultHit nextHit() { + return null; + } + + @Override + public int getHitCount() { + return 0; + } +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/result/StandardQueryResult.java ---------------------------------------------------------------------- diff --git a/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/result/StandardQueryResult.java b/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/result/StandardQueryResult.java new file mode 100644 index 0000000..bcba697 --- /dev/null +++ b/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/result/StandardQueryResult.java @@ -0,0 +1,70 @@ +/* + * 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.nifi.hl7.query.result; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.nifi.hl7.query.QueryResult; +import org.apache.nifi.hl7.query.ResultHit; +import org.apache.nifi.hl7.query.Selection; + +public class StandardQueryResult implements QueryResult { + + private final List<Selection> selections; + private final Set<Map<String, Object>> hits; + private final Iterator<Map<String, Object>> hitIterator; + + public StandardQueryResult(final List<Selection> selections, final Set<Map<String, Object>> hits) { + this.selections = selections; + this.hits = hits; + + hitIterator = hits.iterator(); + } + + @Override + public boolean isMatch() { + return !hits.isEmpty(); + } + + @Override + public List<String> getLabels() { + final List<String> labels = new ArrayList<>(); + for (final Selection selection : selections) { + labels.add(selection.getName()); + } + return labels; + } + + @Override + public int getHitCount() { + return hits.size(); + } + + @Override + public ResultHit nextHit() { + if (hitIterator.hasNext()) { + return new StandardResultHit(hitIterator.next()); + } else { + return null; + } + } + +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/result/StandardResultHit.java ---------------------------------------------------------------------- diff --git a/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/result/StandardResultHit.java b/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/result/StandardResultHit.java new file mode 100644 index 0000000..7fe9205 --- /dev/null +++ b/nifi-commons/nifi-hl7-query-language/src/main/java/org/apache/nifi/hl7/query/result/StandardResultHit.java @@ -0,0 +1,42 @@ +/* + * 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.nifi.hl7.query.result; + +import java.util.Collections; +import java.util.Map; + +import org.apache.nifi.hl7.query.ResultHit; + +public class StandardResultHit implements ResultHit { + + private final Map<String, Object> values; + + public StandardResultHit(final Map<String, Object> values) { + this.values = values; + } + + @Override + public Object getValue(final String label) { + return values.get(label); + } + + @Override + public Map<String, Object> getSelectedValues() { + return Collections.unmodifiableMap(values); + } + +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-commons/nifi-hl7-query-language/src/test/java/org/apache/nifi/hl7/query/TestHL7Query.java ---------------------------------------------------------------------- diff --git a/nifi-commons/nifi-hl7-query-language/src/test/java/org/apache/nifi/hl7/query/TestHL7Query.java b/nifi-commons/nifi-hl7-query-language/src/test/java/org/apache/nifi/hl7/query/TestHL7Query.java new file mode 100644 index 0000000..f78f82b --- /dev/null +++ b/nifi-commons/nifi-hl7-query-language/src/test/java/org/apache/nifi/hl7/query/TestHL7Query.java @@ -0,0 +1,306 @@ +/* + * 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.nifi.hl7.query; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import org.apache.nifi.hl7.hapi.HapiMessage; +import org.apache.nifi.hl7.model.HL7Field; +import org.apache.nifi.hl7.model.HL7Message; +import org.junit.Test; + +import ca.uhn.hl7v2.DefaultHapiContext; +import ca.uhn.hl7v2.HL7Exception; +import ca.uhn.hl7v2.HapiContext; +import ca.uhn.hl7v2.model.Message; +import ca.uhn.hl7v2.parser.PipeParser; +import ca.uhn.hl7v2.validation.impl.ValidationContextFactory; + +@SuppressWarnings("resource") +public class TestHL7Query { + + @Test + public void testAssignAliases() { + final LinkedHashMap<String, List<Object>> possibleValueMap = new LinkedHashMap<>(); + + final List<Object> valuesA = new ArrayList<>(); + valuesA.add("a"); + valuesA.add("b"); + valuesA.add("c"); + + final List<Object> valuesB = new ArrayList<>(); + valuesB.add("d"); + + final List<Object> valuesC = new ArrayList<>(); + valuesC.add("e"); + valuesC.add("f"); + + final List<Object> valuesD = new ArrayList<>(); + valuesD.add("g"); + valuesD.add("h"); + + possibleValueMap.put("A", valuesA); + possibleValueMap.put("B", valuesB); + possibleValueMap.put("C", valuesC); + possibleValueMap.put("D", valuesD); + + for (int i = 0; i < valuesA.size() * valuesB.size() * valuesC.size() * valuesD.size(); i++) { + System.out.println(i + " : " + HL7Query.assignAliases(possibleValueMap, i)); + } + + verifyAssignments(HL7Query.assignAliases(possibleValueMap, 0), "a", "d", "e", "g"); + verifyAssignments(HL7Query.assignAliases(possibleValueMap, 1), "b", "d", "e", "g"); + verifyAssignments(HL7Query.assignAliases(possibleValueMap, 2), "c", "d", "e", "g"); + verifyAssignments(HL7Query.assignAliases(possibleValueMap, 3), "a", "d", "f", "g"); + verifyAssignments(HL7Query.assignAliases(possibleValueMap, 4), "b", "d", "f", "g"); + verifyAssignments(HL7Query.assignAliases(possibleValueMap, 5), "c", "d", "f", "g"); + verifyAssignments(HL7Query.assignAliases(possibleValueMap, 6), "a", "d", "e", "h"); + verifyAssignments(HL7Query.assignAliases(possibleValueMap, 7), "b", "d", "e", "h"); + verifyAssignments(HL7Query.assignAliases(possibleValueMap, 8), "c", "d", "e", "h"); + verifyAssignments(HL7Query.assignAliases(possibleValueMap, 9), "a", "d", "f", "h"); + verifyAssignments(HL7Query.assignAliases(possibleValueMap, 10), "b", "d", "f", "h"); + verifyAssignments(HL7Query.assignAliases(possibleValueMap, 11), "c", "d", "f", "h"); + } + + private void verifyAssignments(final Map<String, Object> map, final String a, final String b, final String c, final String d) { + assertEquals(a, map.get("A")); + assertEquals(b, map.get("B")); + assertEquals(c, map.get("C")); + assertEquals(d, map.get("D")); + } + + @Test + public void testSelectMessage() throws HL7Exception, IOException { + final HL7Query query = HL7Query.compile("SELECT MESSAGE"); + final HL7Message msg = createMessage(new File("src/test/resources/hypoglycemia")); + final QueryResult result = query.evaluate(msg); + assertTrue(result.isMatch()); + final List<String> labels = result.getLabels(); + assertEquals(1, labels.size()); + assertEquals("MESSAGE", labels.get(0)); + + assertEquals(1, result.getHitCount()); + assertEquals(msg, result.nextHit().getValue("MESSAGE")); + } + + @Test + @SuppressWarnings({"unchecked", "rawtypes"}) + public void testSelectField() throws HL7Exception, IOException { + final HL7Query query = HL7Query.compile("SELECT PID.5"); + final HL7Message msg = createMessage(new File("src/test/resources/hypoglycemia")); + final QueryResult result = query.evaluate(msg); + assertTrue(result.isMatch()); + final List<String> labels = result.getLabels(); + assertEquals(1, labels.size()); + assertEquals(1, result.getHitCount()); + + final Object names = result.nextHit().getValue("PID.5"); + assertTrue(names instanceof List); + final List<Object> nameList = (List) names; + assertEquals(1, nameList.size()); + final HL7Field nameField = (HL7Field) nameList.get(0); + assertEquals("SMITH^JOHN", nameField.getValue()); + } + + @Test + public void testSelectAbnormalTestResult() throws HL7Exception, IOException { + final String query = "DECLARE result AS REQUIRED OBX SELECT result WHERE result.7 != 'N' AND result.1 = 1"; + + final HL7Query hl7Query = HL7Query.compile(query); + final QueryResult result = hl7Query.evaluate(createMessage(new File("src/test/resources/hypoglycemia"))); + assertTrue(result.isMatch()); + } + + @Test + public void testFieldEqualsString() throws HL7Exception, IOException { + HL7Query hl7Query = HL7Query.compile("DECLARE result AS REQUIRED OBX SELECT MESSAGE WHERE result.7 = 'L'"); + QueryResult result = hl7Query.evaluate(createMessage(new File("src/test/resources/hypoglycemia"))); + assertTrue(result.isMatch()); + + hl7Query = HL7Query.compile("DECLARE result AS REQUIRED OBX SELECT MESSAGE WHERE result.7 = 'H'"); + result = hl7Query.evaluate(createMessage(new File("src/test/resources/hypoglycemia"))); + assertFalse(result.isMatch()); + } + + @Test + public void testLessThan() throws HL7Exception, IOException { + HL7Query hl7Query = HL7Query.compile("DECLARE result AS REQUIRED OBX SELECT MESSAGE WHERE result.4 < 600"); + QueryResult result = hl7Query.evaluate(createMessage(new File("src/test/resources/hypoglycemia"))); + assertTrue(result.isMatch()); + + hl7Query = HL7Query.compile("DECLARE result AS REQUIRED OBX SELECT MESSAGE WHERE result.4 < 59"); + result = hl7Query.evaluate(createMessage(new File("src/test/resources/hypoglycemia"))); + assertFalse(result.isMatch()); + } + + @Test + public void testCompareTwoFields() throws HL7Exception, IOException { + HL7Query hl7Query = HL7Query.compile("DECLARE result AS REQUIRED OBX SELECT MESSAGE WHERE result.4 < result.6.2"); + QueryResult result = hl7Query.evaluate(createMessage(new File("src/test/resources/hypoglycemia"))); + assertTrue(result.isMatch()); + + hl7Query = HL7Query.compile("DECLARE result AS REQUIRED OBX SELECT MESSAGE WHERE NOT(result.4 > result.6.3)"); + result = hl7Query.evaluate(createMessage(new File("src/test/resources/hypoglycemia"))); + assertFalse(result.isMatch()); + } + + @Test + public void testLessThanOrEqual() throws HL7Exception, IOException { + HL7Query hl7Query = HL7Query.compile("DECLARE result AS REQUIRED OBX SELECT MESSAGE WHERE result.4 <= 59"); + QueryResult result = hl7Query.evaluate(createMessage(new File("src/test/resources/hypoglycemia"))); + assertTrue(result.isMatch()); + + hl7Query = HL7Query.compile("DECLARE result AS REQUIRED OBX SELECT MESSAGE WHERE result.4 <= 600"); + result = hl7Query.evaluate(createMessage(new File("src/test/resources/hypoglycemia"))); + assertTrue(result.isMatch()); + + hl7Query = HL7Query.compile("DECLARE result AS REQUIRED OBX SELECT MESSAGE WHERE result.4 <= 58"); + result = hl7Query.evaluate(createMessage(new File("src/test/resources/hypoglycemia"))); + assertFalse(result.isMatch()); + } + + @Test + public void testGreaterThanOrEqual() throws HL7Exception, IOException { + HL7Query hl7Query = HL7Query.compile("DECLARE result AS REQUIRED OBX SELECT MESSAGE WHERE result.4 >= 59"); + QueryResult result = hl7Query.evaluate(createMessage(new File("src/test/resources/hypoglycemia"))); + assertTrue(result.isMatch()); + + hl7Query = HL7Query.compile("DECLARE result AS REQUIRED OBX SELECT MESSAGE WHERE result.4 >= 6"); + result = hl7Query.evaluate(createMessage(new File("src/test/resources/hypoglycemia"))); + assertTrue(result.isMatch()); + + hl7Query = HL7Query.compile("DECLARE result AS REQUIRED OBX SELECT MESSAGE WHERE result.4 >= 580"); + result = hl7Query.evaluate(createMessage(new File("src/test/resources/hypoglycemia"))); + assertFalse(result.isMatch()); + } + + @Test + public void testGreaterThan() throws HL7Exception, IOException { + HL7Query hl7Query = HL7Query.compile("DECLARE result AS REQUIRED OBX SELECT MESSAGE WHERE result.4 > 58"); + QueryResult result = hl7Query.evaluate(createMessage(new File("src/test/resources/hypoglycemia"))); + assertTrue(result.isMatch()); + + hl7Query = HL7Query.compile("DECLARE result AS REQUIRED OBX SELECT MESSAGE WHERE result.4 > 6"); + result = hl7Query.evaluate(createMessage(new File("src/test/resources/hypoglycemia"))); + assertTrue(result.isMatch()); + + hl7Query = HL7Query.compile("DECLARE result AS REQUIRED OBX SELECT MESSAGE WHERE result.4 > 580"); + result = hl7Query.evaluate(createMessage(new File("src/test/resources/hypoglycemia"))); + assertFalse(result.isMatch()); + } + + @Test + public void testDistinctValuesReturned() throws HL7Exception, IOException { + HL7Query hl7Query = HL7Query.compile("DECLARE result1 AS REQUIRED OBX, result2 AS REQUIRED OBX SELECT MESSAGE WHERE result1.7 = 'L' OR result2.7 != 'H'"); + QueryResult result = hl7Query.evaluate(createMessage(new File("src/test/resources/hypoglycemia"))); + assertTrue(result.isMatch()); + assertEquals(1, result.getHitCount()); + } + + @Test + public void testAndWithParens() throws HL7Exception, IOException { + HL7Query hl7Query = HL7Query.compile("DECLARE result AS REQUIRED OBX SELECT MESSAGE WHERE result.7 = 'L' AND result.3.1 = 'GLU'"); + QueryResult result = hl7Query.evaluate(createMessage(new File("src/test/resources/hypoglycemia"))); + assertTrue(result.isMatch()); + + hl7Query = HL7Query.compile("DECLARE result AS REQUIRED OBX SELECT MESSAGE WHERE result.7 = 'L' AND result.3.1 = 'GLU'"); + result = hl7Query.evaluate(createMessage(new File("src/test/resources/hyperglycemia"))); + assertFalse(result.isMatch()); + + hl7Query = HL7Query.compile("DECLARE result AS REQUIRED OBX SELECT MESSAGE WHERE result.7 = 'H' AND result.3.1 = 'GLU'"); + result = hl7Query.evaluate(createMessage(new File("src/test/resources/hypoglycemia"))); + assertFalse(result.isMatch()); + + hl7Query = HL7Query.compile("DECLARE result AS REQUIRED OBX SELECT MESSAGE WHERE result.7 = 'H' AND result.3.1 = 'GLU'"); + result = hl7Query.evaluate(createMessage(new File("src/test/resources/hyperglycemia"))); + assertTrue(result.isMatch()); + + hl7Query = HL7Query.compile("DECLARE result AS REQUIRED OBX SELECT MESSAGE WHERE (result.7 = 'H') AND (result.3.1 = 'GLU')"); + result = hl7Query.evaluate(createMessage(new File("src/test/resources/hyperglycemia"))); + assertTrue(result.isMatch()); + + hl7Query = HL7Query.compile("DECLARE result AS REQUIRED OBX SELECT MESSAGE WHERE ((result.7 = 'H') AND (result.3.1 = 'GLU'))"); + result = hl7Query.evaluate(createMessage(new File("src/test/resources/hyperglycemia"))); + assertTrue(result.isMatch()); + + hl7Query = HL7Query.compile("DECLARE result AS REQUIRED OBX SELECT MESSAGE WHERE (( ((result.7 = 'H')) AND ( ((result.3.1 = 'GLU')) )))"); + result = hl7Query.evaluate(createMessage(new File("src/test/resources/hyperglycemia"))); + assertTrue(result.isMatch()); + + } + + @Test + public void testIsNull() throws HL7Exception, IOException { + HL7Query hl7Query = HL7Query.compile("DECLARE result AS REQUIRED OBX SELECT MESSAGE WHERE result.999 IS NULL"); + QueryResult result = hl7Query.evaluate(createMessage(new File("src/test/resources/hypoglycemia"))); + assertTrue(result.isMatch()); + + hl7Query = HL7Query.compile("DECLARE result AS REQUIRED OBX SELECT MESSAGE WHERE result.1 IS NULL"); + result = hl7Query.evaluate(createMessage(new File("src/test/resources/hypoglycemia"))); + assertFalse(result.isMatch()); + + hl7Query = HL7Query.compile("SELECT MESSAGE WHERE ZZZ IS NULL"); + result = hl7Query.evaluate(createMessage(new File("src/test/resources/hypoglycemia"))); + assertTrue(result.isMatch()); + + hl7Query = HL7Query.compile("SELECT MESSAGE WHERE OBX IS NULL"); + result = hl7Query.evaluate(createMessage(new File("src/test/resources/hypoglycemia"))); + assertFalse(result.isMatch()); + } + + @Test + public void testNotNull() throws HL7Exception, IOException { + HL7Query hl7Query = HL7Query.compile("DECLARE result AS REQUIRED OBX SELECT MESSAGE WHERE result.999 NOT NULL"); + QueryResult result = hl7Query.evaluate(createMessage(new File("src/test/resources/hypoglycemia"))); + assertFalse(result.isMatch()); + + hl7Query = HL7Query.compile("DECLARE result AS REQUIRED OBX SELECT MESSAGE WHERE result.1 NOT NULL"); + result = hl7Query.evaluate(createMessage(new File("src/test/resources/hypoglycemia"))); + assertTrue(result.isMatch()); + + hl7Query = HL7Query.compile("SELECT MESSAGE WHERE ZZZ NOT NULL"); + result = hl7Query.evaluate(createMessage(new File("src/test/resources/hypoglycemia"))); + assertFalse(result.isMatch()); + + hl7Query = HL7Query.compile("SELECT MESSAGE WHERE OBX NOT NULL"); + result = hl7Query.evaluate(createMessage(new File("src/test/resources/hypoglycemia"))); + assertTrue(result.isMatch()); + } + + private HL7Message createMessage(final File file) throws HL7Exception, IOException { + final byte[] bytes = Files.readAllBytes(file.toPath()); + final String msgText = new String(bytes, "UTF-8"); + + final HapiContext hapiContext = new DefaultHapiContext(); + hapiContext.setValidationContext(ValidationContextFactory.noValidation()); + + final PipeParser parser = hapiContext.getPipeParser(); + final Message message = parser.parse(msgText); + return new HapiMessage(message); + } + +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-commons/nifi-hl7-query-language/src/test/resources/hyperglycemia ---------------------------------------------------------------------- diff --git a/nifi-commons/nifi-hl7-query-language/src/test/resources/hyperglycemia b/nifi-commons/nifi-hl7-query-language/src/test/resources/hyperglycemia new file mode 100644 index 0000000..cae413b --- /dev/null +++ b/nifi-commons/nifi-hl7-query-language/src/test/resources/hyperglycemia @@ -0,0 +1,5 @@ +MSH|^~\&|XXXXXX||HealthOrg01||||ORU^R01|Q1111111111111111111|P|2.3| +PID|||000000001||SMITH^JOHN||19700101|M||||||||||999999999999|123456789| +PD1||||1234567890^LAST^FIRST^M^^^^^NPI| +OBR|1|341856649^HNAM_ORDERID|000000000000000000|648088^Basic Metabolic Panel|||20150101000100|||||||||1620^Johnson^John^R||||||20150101000100|||M|||||||||||20150101000100| +OBX|1|NM|GLU^Glucose Lvl|159|mg/dL|65-99^65^99|H|||F|||20150101000100| \ No newline at end of file http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-commons/nifi-hl7-query-language/src/test/resources/hypoglycemia ---------------------------------------------------------------------- diff --git a/nifi-commons/nifi-hl7-query-language/src/test/resources/hypoglycemia b/nifi-commons/nifi-hl7-query-language/src/test/resources/hypoglycemia new file mode 100644 index 0000000..764ffcc --- /dev/null +++ b/nifi-commons/nifi-hl7-query-language/src/test/resources/hypoglycemia @@ -0,0 +1,5 @@ +MSH|^~\&|XXXXXX||HealthOrg01||||ORU^R01|Q1111111111111111111|P|2.3| +PID|||000000001||SMITH^JOHN||19700101|M||||||||||999999999999|123456789| +PD1||||1234567890^LAST^FIRST^M^^^^^NPI| +OBR|1|341856649^HNAM_ORDERID|000000000000000000|648088^Basic Metabolic Panel|||20150101000100|||||||||1620^Johnson^John^R||||||20150101000100|||M|||||||||||20150101000100| +OBX|1|NM|GLU^Glucose Lvl|59|mg/dL|65-99^65^99|L|||F|||20150101000100| \ No newline at end of file http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-commons/nifi-logging-utils/pom.xml ---------------------------------------------------------------------- diff --git a/nifi-commons/nifi-logging-utils/pom.xml b/nifi-commons/nifi-logging-utils/pom.xml new file mode 100644 index 0000000..8f268ea --- /dev/null +++ b/nifi-commons/nifi-logging-utils/pom.xml @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.nifi</groupId> + <artifactId>nifi-commons</artifactId> + <version>0.3.0-SNAPSHOT</version> + </parent> + <artifactId>nifi-logging-utils</artifactId> + <description>Utilities for logging</description> + <dependencies> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + </dependency> + </dependencies> +</project> http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-commons/nifi-logging-utils/src/main/java/org/apache/nifi/logging/NiFiLog.java ---------------------------------------------------------------------- diff --git a/nifi-commons/nifi-logging-utils/src/main/java/org/apache/nifi/logging/NiFiLog.java b/nifi-commons/nifi-logging-utils/src/main/java/org/apache/nifi/logging/NiFiLog.java new file mode 100644 index 0000000..3de8518 --- /dev/null +++ b/nifi-commons/nifi-logging-utils/src/main/java/org/apache/nifi/logging/NiFiLog.java @@ -0,0 +1,366 @@ +/* + * 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.nifi.logging; + +import org.slf4j.Logger; +import org.slf4j.Marker; + +/** + * + */ +public class NiFiLog implements Logger { + + private final Logger logger; + + public NiFiLog(final Logger logger) { + this.logger = logger; + } + + public Logger getWrappedLog() { + return logger; + } + + @Override + public void warn(Marker marker, String string, Throwable thrwbl) { + if (logger.isDebugEnabled()) { + logger.warn(marker, string, thrwbl); + } else { + logger.warn(marker, string); + } + } + + @Override + public void warn(Marker marker, String string, Object[] os) { + logger.warn(marker, string, os); + } + + @Override + public void warn(Marker marker, String string, Object o, Object o1) { + logger.warn(marker, string, o, o1); + } + + @Override + public void warn(Marker marker, String string, Object o) { + logger.warn(marker, string, o); + } + + @Override + public void warn(Marker marker, String string) { + logger.warn(marker, string); + } + + @Override + public void warn(String string, Throwable thrwbl) { + if (logger.isDebugEnabled()) { + logger.warn(string, thrwbl); + } else { + logger.warn(string); + } + } + + @Override + public void warn(String string, Object o, Object o1) { + logger.warn(string, o, o1); + } + + @Override + public void warn(String string, Object[] os) { + logger.warn(string, os); + } + + @Override + public void warn(String string, Object o) { + logger.warn(string, o); + } + + @Override + public void warn(String string) { + logger.warn(string); + } + + @Override + public void trace(Marker marker, String string, Throwable thrwbl) { + logger.trace(marker, string, thrwbl); + } + + @Override + public void trace(Marker marker, String string, Object[] os) { + logger.trace(marker, string, os); + } + + @Override + public void trace(Marker marker, String string, Object o, Object o1) { + logger.trace(marker, string, o, o1); + } + + @Override + public void trace(Marker marker, String string, Object o) { + logger.trace(marker, string, o); + } + + @Override + public void trace(Marker marker, String string) { + logger.trace(marker, string); + } + + @Override + public void trace(String string, Throwable thrwbl) { + logger.trace(string, thrwbl); + } + + @Override + public void trace(String string, Object[] os) { + logger.trace(string, os); + } + + @Override + public void trace(String string, Object o, Object o1) { + logger.trace(string, o, o1); + } + + @Override + public void trace(String string, Object o) { + logger.trace(string, o); + } + + @Override + public void trace(String string) { + logger.trace(string); + } + + @Override + public boolean isWarnEnabled(Marker marker) { + return logger.isWarnEnabled(marker); + } + + @Override + public boolean isWarnEnabled() { + return logger.isWarnEnabled(); + } + + @Override + public boolean isTraceEnabled(Marker marker) { + return logger.isTraceEnabled(marker); + } + + @Override + public boolean isTraceEnabled() { + return logger.isTraceEnabled(); + } + + @Override + public boolean isInfoEnabled(Marker marker) { + return logger.isInfoEnabled(marker); + } + + @Override + public boolean isInfoEnabled() { + return logger.isInfoEnabled(); + } + + @Override + public boolean isErrorEnabled(Marker marker) { + return logger.isErrorEnabled(marker); + } + + @Override + public boolean isErrorEnabled() { + return logger.isErrorEnabled(); + } + + @Override + public boolean isDebugEnabled(Marker marker) { + return logger.isDebugEnabled(marker); + } + + @Override + public boolean isDebugEnabled() { + return logger.isDebugEnabled(); + } + + @Override + public void info(Marker marker, String string, Throwable thrwbl) { + if (logger.isDebugEnabled()) { + logger.info(marker, string, thrwbl); + } else { + logger.info(marker, string); + } + } + + @Override + public void info(Marker marker, String string, Object[] os) { + logger.info(marker, string, os); + } + + @Override + public void info(Marker marker, String string, Object o, Object o1) { + logger.info(marker, string, o, o1); + } + + @Override + public void info(Marker marker, String string, Object o) { + logger.info(marker, string, o); + } + + @Override + public void info(Marker marker, String string) { + logger.info(marker, string); + } + + @Override + public void info(String string, Throwable thrwbl) { + if (logger.isDebugEnabled()) { + logger.info(string, thrwbl); + } else { + logger.info(string); + } + } + + @Override + public void info(String string, Object[] os) { + logger.info(string, os); + } + + @Override + public void info(String string, Object o, Object o1) { + logger.info(string, o, o1); + } + + @Override + public void info(String string, Object o) { + logger.info(string, o); + } + + @Override + public void info(String string) { + logger.info(string); + } + + @Override + public String getName() { + return logger.getName(); + } + + @Override + public void error(Marker marker, String string, Throwable thrwbl) { + if (logger.isDebugEnabled()) { + logger.error(marker, string, thrwbl); + } else { + logger.error(marker, string); + } + } + + @Override + public void error(Marker marker, String string, Object[] os) { + logger.error(marker, string, os); + } + + @Override + public void error(Marker marker, String string, Object o, Object o1) { + logger.error(marker, string, o, o1); + } + + @Override + public void error(Marker marker, String string, Object o) { + logger.error(marker, string, o); + } + + @Override + public void error(Marker marker, String string) { + logger.error(marker, string); + } + + @Override + public void error(String string, Throwable thrwbl) { + if (logger.isDebugEnabled()) { + logger.error(string, thrwbl); + } else { + logger.error(string); + } + } + + @Override + public void error(String string, Object[] os) { + logger.error(string, os); + } + + @Override + public void error(String string, Object o, Object o1) { + logger.error(string, o, o1); + } + + @Override + public void error(String string, Object o) { + logger.error(string, o); + } + + @Override + public void error(String string) { + logger.error(string); + } + + @Override + public void debug(Marker marker, String string, Throwable thrwbl) { + logger.debug(marker, string, thrwbl); + } + + @Override + public void debug(Marker marker, String string, Object[] os) { + logger.debug(marker, string, os); + } + + @Override + public void debug(Marker marker, String string, Object o, Object o1) { + logger.debug(marker, string, o, o1); + } + + @Override + public void debug(Marker marker, String string, Object o) { + logger.debug(marker, string, o); + } + + @Override + public void debug(Marker marker, String string) { + logger.debug(marker, string); + } + + @Override + public void debug(String string, Throwable thrwbl) { + logger.debug(string, thrwbl); + } + + @Override + public void debug(String string, Object[] os) { + logger.debug(string, os); + } + + @Override + public void debug(String string, Object o, Object o1) { + logger.debug(string, o, o1); + } + + @Override + public void debug(String string, Object o) { + logger.debug(string, o); + } + + @Override + public void debug(String string) { + logger.debug(string); + } + +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-commons/nifi-processor-utilities/pom.xml ---------------------------------------------------------------------- diff --git a/nifi-commons/nifi-processor-utilities/pom.xml b/nifi-commons/nifi-processor-utilities/pom.xml new file mode 100644 index 0000000..2352c27 --- /dev/null +++ b/nifi-commons/nifi-processor-utilities/pom.xml @@ -0,0 +1,40 @@ +<?xml version="1.0"?> +<!-- + 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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.nifi</groupId> + <artifactId>nifi-commons</artifactId> + <version>0.3.0-SNAPSHOT</version> + </parent> + <artifactId>nifi-processor-utils</artifactId> + <packaging>jar</packaging> + <dependencies> + <dependency> + <groupId>org.apache.nifi</groupId> + <artifactId>nifi-api</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.nifi</groupId> + <artifactId>nifi-utils</artifactId> + </dependency> + <dependency> + <groupId>org.apache.nifi</groupId> + <artifactId>nifi-security-utils</artifactId> + </dependency> + </dependencies> +</project>