Ensure a '.' character is allowed to be used in target filter query for metadata key and attribute name (#1186)
* Adapted code to allow '.' inside of metadata key and attribute names Signed-off-by: Markus Block <markus.block@bosch-si.com> * added handling of corner cases Signed-off-by: Markus Block <markus.block@bosch-si.com> * Adapted metadata and attribute tests to check that dot is allowed Signed-off-by: Markus Block <markus.block@bosch-si.com> * fixed documentation Signed-off-by: Markus Block <markus.block@bosch-si.com> * Allow usage of dot in key names for every map attribute, e.g. also for metadata in distribution set Signed-off-by: Markus Block <markus.block@bosch-si.com> * fixed typo Signed-off-by: Markus Block <markus.block@bosch-si.com> * adapted test key to ensure a dot can be used Signed-off-by: Markus Block <markus.block@bosch-si.com> * fixed typo Signed-off-by: Markus Block <markus.block@bosch-si.com>
This commit is contained in:
@@ -14,6 +14,8 @@ import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* An interface for declaring the name of the field described in the database
|
||||
* which is used as string representation of the field, e.g. for sorting the
|
||||
@@ -25,7 +27,7 @@ public interface FieldNameProvider {
|
||||
/**
|
||||
* Separator for the sub attributes
|
||||
*/
|
||||
String SUB_ATTRIBUTE_SEPERATOR = ".";
|
||||
String SUB_ATTRIBUTE_SEPARATOR = ".";
|
||||
|
||||
/**
|
||||
* @return the string representation of the underlying persistence field
|
||||
@@ -33,6 +35,26 @@ public interface FieldNameProvider {
|
||||
*/
|
||||
String getFieldName();
|
||||
|
||||
/**
|
||||
* Returns the sub attributes
|
||||
*
|
||||
* @param propertyFieldName
|
||||
* the given field
|
||||
* @return array consisting of sub attributes
|
||||
*/
|
||||
default String[] getSubAttributes(final String propertyFieldName) {
|
||||
if (isMap()) {
|
||||
final String[] subAttributes = propertyFieldName.split("\\" + SUB_ATTRIBUTE_SEPARATOR, 2);
|
||||
// [0] fieldname |[1] keyname
|
||||
final String mapKeyName = subAttributes.length == 2 ? subAttributes[1] : null;
|
||||
if (StringUtils.isEmpty(mapKeyName)) {
|
||||
return new String[] { getFieldName() };
|
||||
}
|
||||
return new String[] { getFieldName(), mapKeyName };
|
||||
}
|
||||
return propertyFieldName.split("\\" + SUB_ATTRIBUTE_SEPARATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Contains the sub entity the given field.
|
||||
*
|
||||
@@ -47,7 +69,7 @@ public interface FieldNameProvider {
|
||||
return true;
|
||||
}
|
||||
for (final String attribute : subEntityAttributes) {
|
||||
final String[] graph = attribute.split("\\" + SUB_ATTRIBUTE_SEPERATOR);
|
||||
final String[] graph = attribute.split("\\" + SUB_ATTRIBUTE_SEPARATOR);
|
||||
|
||||
for (final String subAttribute : graph) {
|
||||
if (subAttribute.equalsIgnoreCase(propertyField)) {
|
||||
@@ -74,7 +96,7 @@ public interface FieldNameProvider {
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the entity field a {@link Map}.
|
||||
* Is the entity field a {@link Map} consisting of key-value pairs.
|
||||
*
|
||||
* @return <code>true</code> is a map <code>false</code> is not a map
|
||||
*/
|
||||
@@ -84,7 +106,7 @@ public interface FieldNameProvider {
|
||||
|
||||
/**
|
||||
* Returns the name of the field, that identifies the entity.
|
||||
*
|
||||
*
|
||||
* @return the name of the identifier, by default 'id'
|
||||
*/
|
||||
default String identifierFieldName() {
|
||||
|
||||
@@ -135,4 +135,4 @@ public enum TargetFields implements FieldNameProvider {
|
||||
public String getFieldName() {
|
||||
return fieldName;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user