From 05bcebc0f99a689a54d8f9c82219f8b437b4196e Mon Sep 17 00:00:00 2001 From: Avgustin Marinov Date: Thu, 15 May 2025 15:34:07 +0300 Subject: [PATCH] Remove ParseExceptionWrapper (unused) (#2403) Signed-off-by: Avgustin Marinov --- .../jpa/rsql/ParseExceptionWrapper.java | 180 ------------------ .../repository/jpa/rsql/RSQLToSQLTest.java | 27 +++ 2 files changed, 27 insertions(+), 180 deletions(-) delete mode 100644 hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/ParseExceptionWrapper.java diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/ParseExceptionWrapper.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/ParseExceptionWrapper.java deleted file mode 100644 index 74efddcc2..000000000 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/ParseExceptionWrapper.java +++ /dev/null @@ -1,180 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.eclipse.hawkbit.repository.jpa.rsql; - -import java.lang.reflect.Field; -import java.util.Arrays; - -import cz.jirutka.rsql.parser.ParseException; -import org.springframework.util.ReflectionUtils; - -/** - * A {@link ParseException} wrapper which allows to access the parsing - * information from the exception using reflection due there is no other access - * of this information. See issue for requesting feature - * https://github.com - * /jirutka/rsql-parser/issues/22 - */ -public class ParseExceptionWrapper { - - private final ParseException parseException; - - /** - * Constructor. - * - * @param parseException the original parsing exception object to access its field - * using reflection - */ - public ParseExceptionWrapper(final ParseException parseException) { - this.parseException = parseException; - } - - public int[][] getExpectedTokenSequence() { - return (parseException.expectedTokenSequences != null) // unclear if this can happen - ? parseException.expectedTokenSequences - : new int[0][0]; - } - - /** - * Get the current token - * - * @return the current token or {@code null} if there is non. - */ - public TokenWrapper getCurrentToken() { - return (parseException.currentToken != null) // unclear if this can happen - ? new TokenWrapper(parseException.currentToken) - : null; - - } - - @Override - public String toString() { - return "ParseExceptionWrapper [getExpectedTokenSequence()=" + Arrays.toString(getExpectedTokenSequence()) - + ", getCurrentToken()=" + getCurrentToken() + "]"; - } - - /** - * A {@link TokenWrapper} which wraps the - * {@code cz.jirutka.rsql.parser.Token} class of the {@link ParseException} - * which otherwise is not accessible. - */ - public static final class TokenWrapper { - - private static final String FIELD_NEXT = "next"; - private static final String FIELD_KIND = "kind"; - private static final String FIELD_IMAGE = "image"; - private static final String FIELD_BEGIN_COL = "beginColumn"; - private static final String FIELD_END_COL = "endColumn"; - - private final Object tokenInstance; - - private Field nextTokenField; - private Field kindTokenField; - private Field imageTokenField; - private Field beginColumnTokenField; - private Field endColumnTokenField; - - private TokenWrapper(final Object tokenField) { - this.tokenInstance = tokenField; - - try { - nextTokenField = getAccessibleField(FIELD_NEXT); - } catch (@SuppressWarnings("squid:S1166") final NoSuchFieldException e) { - nextTokenField = null; - } - try { - kindTokenField = getAccessibleField(FIELD_KIND); - } catch (@SuppressWarnings("squid:S1166") final NoSuchFieldException e) { - kindTokenField = null; - } - - try { - imageTokenField = getAccessibleField(FIELD_IMAGE); - } catch (@SuppressWarnings("squid:S1166") final NoSuchFieldException e) { - imageTokenField = null; - } - - try { - beginColumnTokenField = getAccessibleField(FIELD_BEGIN_COL); - } catch (@SuppressWarnings("squid:S1166") final NoSuchFieldException e) { - beginColumnTokenField = null; - } - - try { - endColumnTokenField = getAccessibleField(FIELD_END_COL); - } catch (@SuppressWarnings("squid:S1166") final NoSuchFieldException e) { - endColumnTokenField = null; - } - } - - public TokenWrapper getNext() { - final Object nextToken = getValue(nextTokenField); - return nextToken != null ? new TokenWrapper(nextToken) : null; - - } - - public int getKind() { - if (kindTokenField == null) { - return 0; - } - return (int) getValue(kindTokenField); - } - - public String getImage() { - if (imageTokenField == null) { - return null; - } - return (String) getValue(imageTokenField); - } - - public int getBeginColumn() { - if (beginColumnTokenField == null) { - return 0; - } - return (int) getValue(beginColumnTokenField); - } - - public int getEndColumn() { - if (endColumnTokenField == null) { - return 0; - } - return (int) getValue(endColumnTokenField); - } - - @Override - public String toString() { - return "TokenWrapper [tokenInstance=" + tokenInstance + ", getNext()=" + getNext() + ", getKind()=" - + getKind() + ", getImage()=" + getImage() + ", getBeginColumn()=" + getBeginColumn() - + ", getEndColumn()=" + getEndColumn() + "]"; - } - - private Field getAccessibleField(final String field) throws NoSuchFieldException { - final Field declaredField = tokenInstance.getClass().getDeclaredField(field); - ReflectionUtils.makeAccessible(declaredField); - return declaredField; - } - - private Object getValue(final Field field) { - try { - return field.get(tokenInstance); - } catch (IllegalArgumentException | IllegalAccessException e) { - throw new IllegalFieldAccessExeption(e); - } - } - } - - static class IllegalFieldAccessExeption extends RuntimeException { - - public IllegalFieldAccessExeption(Throwable e) { - super(e); - } - } -} - diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLToSQLTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLToSQLTest.java index fd094e280..c578ed0dc 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLToSQLTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLToSQLTest.java @@ -49,6 +49,33 @@ class RSQLToSQLTest { print(JpaTarget.class, TargetFields.class, "(tag!=TAG1 or tag !=TAG2)"); } + @Test + void printSimple() { + print(JpaTarget.class, TargetFields.class, "controllerId==ctrlr1"); + print(JpaTarget.class, TargetFields.class, "targettype.key==type1"); + print(JpaTarget.class, TargetFields.class, "tag==tag1"); + print(JpaTarget.class, TargetFields.class, "metadata.key1==value1"); + print(JpaTarget.class, TargetFields.class, "attribute.key1==value1"); + } + + @Test + void printAnd() { + print(JpaTarget.class, TargetFields.class, "controllerId==ctrlr1 and controllerId==ctrlr2"); + print(JpaTarget.class, TargetFields.class, "targettype.key==type1 and targettype.key==type2"); + print(JpaTarget.class, TargetFields.class, "tag==tag1 and tag==tag2 and tag=tag3"); + print(JpaTarget.class, TargetFields.class, "metadata.key1==value1 and metadata.key2==value2"); + print(JpaTarget.class, TargetFields.class, "attribute.key1==value1 and attribute.key2==value2"); + } + + @Test + void printOr() { + print(JpaTarget.class, TargetFields.class, "controllerId==ctrlr1 or controllerId==ctrlr2"); + print(JpaTarget.class, TargetFields.class, "targettype.key==type1 or targettype.key==type2"); + print(JpaTarget.class, TargetFields.class, "tag==tag1 or tag==tag2 or tag==tag3"); + print(JpaTarget.class, TargetFields.class, "metadata.key1==value1 or metadata.key2==value2"); + print(JpaTarget.class, TargetFields.class, "attribute.key1==value1 or attribute.key2==value2"); + } + @Test void printSameTableMultiJoin() { print(JpaTarget.class, TargetFields.class, "installedds.version==1.0.0 or assignedds.version==2.0.0");