Merge pull request #9 from bsinno/MECS-1438_CREATE_FILTER_OPTIONS_FOR_MAP
ok
This commit is contained in:
@@ -36,16 +36,50 @@ public enum DistributionSetFields implements FieldNameProvider {
|
||||
/**
|
||||
* The id field.
|
||||
*/
|
||||
ID("id");
|
||||
ID("id"),
|
||||
|
||||
/**
|
||||
* The tags field.
|
||||
*/
|
||||
TAG("tags.name"),
|
||||
|
||||
/**
|
||||
* The sw type key field.
|
||||
*/
|
||||
TYPE("type.key"),
|
||||
|
||||
/**
|
||||
* The metadata.
|
||||
*/
|
||||
METADATA("metadata", "key", "value");
|
||||
|
||||
private final String fieldName;
|
||||
private String keyFieldName;
|
||||
private String valueFieldName;
|
||||
|
||||
private DistributionSetFields(final String fieldName) {
|
||||
this(fieldName, null, null);
|
||||
}
|
||||
|
||||
private DistributionSetFields(final String fieldName, final String keyFieldName, final String valueFieldName) {
|
||||
this.fieldName = fieldName;
|
||||
this.keyFieldName = keyFieldName;
|
||||
this.valueFieldName = valueFieldName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValueFieldName() {
|
||||
return valueFieldName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKeyFieldName() {
|
||||
return keyFieldName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFieldName() {
|
||||
return fieldName;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,18 +8,87 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* fields over REST.
|
||||
*
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface FieldNameProvider {
|
||||
/**
|
||||
* Seperator for the sub attributes
|
||||
*/
|
||||
public static final String SUB_ATTRIBUTE_SEPERATOR = ".";
|
||||
|
||||
/**
|
||||
* @return the string representation of the underlying persistence field
|
||||
* name e.g. in case of sorting. Never {@code null}.
|
||||
*/
|
||||
String getFieldName();
|
||||
|
||||
default boolean containsSubEntityAttribute(final String propertyField) {
|
||||
return FieldNameProvider.containsSubEntityAttribute(propertyField, getSubEntityAttributes());
|
||||
};
|
||||
|
||||
default List<String> getSubEntityAttributes() {
|
||||
return Collections.emptyList();
|
||||
};
|
||||
|
||||
/**
|
||||
* the database column for the key
|
||||
*
|
||||
* @return key fieldname
|
||||
*/
|
||||
default String getKeyFieldName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* the database column for the value
|
||||
*
|
||||
* @return key fieldname
|
||||
*/
|
||||
default String getValueFieldName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the entity field a {@link Map}.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
default boolean isMap() {
|
||||
return getKeyFieldName() != null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if a sub attribute exists.
|
||||
*
|
||||
* @param propertyField
|
||||
* the sub property field.
|
||||
* @param subEntityAttribues
|
||||
* the list of available properties
|
||||
* @return <true> property exists <false> not exists
|
||||
*/
|
||||
static boolean containsSubEntityAttribute(final String propertyField, final List<String> subEntityAttribues) {
|
||||
if (subEntityAttribues.contains(propertyField)) {
|
||||
return true;
|
||||
}
|
||||
for (final String attribute : subEntityAttribues) {
|
||||
final String[] graph = attribute.split("\\" + SUB_ATTRIBUTE_SEPERATOR);
|
||||
|
||||
for (final String subAttribute : graph) {
|
||||
if (subAttribute.equalsIgnoreCase(propertyField)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -36,16 +36,38 @@ public enum SoftwareModuleFields implements FieldNameProvider {
|
||||
/**
|
||||
* The id field.
|
||||
*/
|
||||
ID("id");
|
||||
ID("id"),
|
||||
/**
|
||||
* The metadata.
|
||||
*/
|
||||
METADATA("metadata", "key", "value");
|
||||
|
||||
private final String fieldName;
|
||||
private String keyFieldName;
|
||||
private String valueFieldName;
|
||||
|
||||
private SoftwareModuleFields(final String fieldName) {
|
||||
this(fieldName, null, null);
|
||||
}
|
||||
|
||||
private SoftwareModuleFields(final String fieldName, final String keyFieldName, final String valueFieldName) {
|
||||
this.fieldName = fieldName;
|
||||
this.keyFieldName = keyFieldName;
|
||||
this.valueFieldName = valueFieldName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFieldName() {
|
||||
return fieldName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKeyFieldName() {
|
||||
return keyFieldName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValueFieldName() {
|
||||
return valueFieldName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,15 +8,22 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Describing the fields of the Target model which can be used in the REST API
|
||||
* e.g. for sorting etc.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public enum TargetFields implements FieldNameProvider {
|
||||
|
||||
/**
|
||||
* The controllerId field.
|
||||
*/
|
||||
ID("controllerId"),
|
||||
|
||||
/**
|
||||
* The name field.
|
||||
*/
|
||||
@@ -37,12 +44,49 @@ public enum TargetFields implements FieldNameProvider {
|
||||
/**
|
||||
* The ip-address field.
|
||||
*/
|
||||
IPADDRESS("targetInfo.ipAddress");
|
||||
IPADDRESS("targetInfo.address"),
|
||||
|
||||
/**
|
||||
* The attribute map of target info.
|
||||
*/
|
||||
ATTRIBUTE("targetInfo.controllerAttributes", true),
|
||||
|
||||
ASSIGNEDDS("assignedDistributionSet", "name", "version"),
|
||||
/**
|
||||
* The tags field.
|
||||
*/
|
||||
TAG("tags.name");
|
||||
|
||||
private final String fieldName;
|
||||
private List<String> subEntityAttribues;
|
||||
private boolean mapField;
|
||||
|
||||
private TargetFields(final String fieldName) {
|
||||
this(fieldName, false, Collections.emptyList());
|
||||
}
|
||||
|
||||
private TargetFields(final String fieldName, final boolean isMapField) {
|
||||
this(fieldName, isMapField, Collections.emptyList());
|
||||
}
|
||||
|
||||
private TargetFields(final String fieldName, final String... subEntityAttribues) {
|
||||
this(fieldName, false, Arrays.asList(subEntityAttribues));
|
||||
}
|
||||
|
||||
private TargetFields(final String fieldName, final boolean mapField, final List<String> subEntityAttribues) {
|
||||
this.fieldName = fieldName;
|
||||
this.mapField = mapField;
|
||||
this.subEntityAttribues = subEntityAttribues;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSubEntityAttributes() {
|
||||
return subEntityAttribues;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMap() {
|
||||
return mapField;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user