Slight improvements in RSQL to SQL logic (#1833)

Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2024-09-09 16:10:31 +03:00
committed by GitHub
parent 3e1965a13b
commit a31028ee19
5 changed files with 104 additions and 87 deletions

View File

@@ -46,14 +46,12 @@ public interface FieldNameProvider {
default String[] getSubAttributes(final String propertyFieldName) {
if (isMap()) {
final String[] subAttributes = propertyFieldName.split(SUB_ATTRIBUTE_SPLIT_REGEX, 2);
// [0] field name | [1] key name
// [0] field name | [1] key name (could miss, e.g. for target attributes)
final String mapKeyName = subAttributes.length == 2 ? subAttributes[1] : null;
if (ObjectUtils.isEmpty(mapKeyName)) {
return new String[] { getFieldName() };
}
return new String[] { getFieldName(), mapKeyName };
return ObjectUtils.isEmpty(mapKeyName) ? new String[] { getFieldName() } : new String[] { getFieldName(), mapKeyName };
} else {
return propertyFieldName.split(SUB_ATTRIBUTE_SPLIT_REGEX);
}
return propertyFieldName.split(SUB_ATTRIBUTE_SPLIT_REGEX);
}
/**

View File

@@ -0,0 +1,48 @@
/**
* Copyright (c) 2024 Contributors to the Eclipse Foundation
*
* 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;
import io.github.classgraph.ClassGraph;
import io.github.classgraph.ClassInfo;
import io.github.classgraph.ScanResult;
import io.qameta.allure.Description;
import org.junit.jupiter.api.Test;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
public class FileNameFieldsTest {
@Test
@Description("Verifies that fields classes are correctly implemented")
@SuppressWarnings("unchecked")
public void repositoryManagementMethodsArePreAuthorizedAnnotated() {
final String packageName = getClass().getPackage().getName();
try (final ScanResult scanResult = new ClassGraph().acceptPackages(packageName).scan()) {
final List<? extends Class<? extends FieldNameProvider>> matchingClasses = scanResult.getAllClasses()
.stream()
.filter(classInPackage -> classInPackage.implementsInterface(FieldNameProvider.class))
.map(ClassInfo::loadClass)
.map(clazz -> (Class<? extends FieldNameProvider>) clazz)
.toList();
assertThat(matchingClasses).isNotEmpty();
matchingClasses.forEach(providerClass -> {
assertThat(providerClass.getEnumConstants()).isNotEmpty();
for (final FieldNameProvider provider : providerClass.getEnumConstants()) {
if (provider.isMap() && !provider.getSubEntityAttributes().isEmpty()) {
throw new UnsupportedOperationException(
"Currently sub-entity attributes for maps are not supported, alternatively you could use the key/value tuple, defined by SimpleImmutableEntry class");
}
}
});
}
}
}