use of org.apache.stanbol.entityhub.servicesapi.query.ValueConstraint in project stanbol by apache.
the class FieldMappingUtils method parseConstraint.
private static Constraint parseConstraint(String filterString) {
if (filterString.startsWith("d=")) {
String[] dataTypeStrings = filterString.substring(2).split(";");
Set<String> dataTypes = new HashSet<String>();
for (int i = 0; i < dataTypeStrings.length; i++) {
DataTypeEnum dataType = DataTypeEnum.getDataTypeByShortName(dataTypeStrings[i]);
if (dataType == null) {
dataType = DataTypeEnum.getDataType(dataTypeStrings[i]);
}
if (dataType != null) {
dataTypes.add(dataType.getUri());
} else {
log.warn(String.format("DataType %s not supported! Datatype get not used by this Filter", dataTypeStrings[i]));
}
}
if (dataTypes.isEmpty()) {
log.warn(String.format("Unable to parse a valied data type form \"%s\"! A data type filter MUST define at least a single dataType. No filter will be used.", filterString));
return null;
} else {
return new ValueConstraint(null, dataTypes);
}
} else if (filterString.startsWith("@=")) {
String[] langs = filterString.substring(2).split(";");
for (int i = 0; i < langs.length; i++) {
if (langs[i].length() < 1 || "null".equals(langs[i])) {
langs[i] = null;
}
}
if (langs.length < 1) {
log.warn("Unable to parse a language form \"%s\"! A language filter MUST define at least a singel language. No filter will be used." + filterString);
return null;
} else {
return new TextConstraint((String) null, langs);
}
} else {
log.warn(String.format("Filters need to start with \"p=\" (dataType) or \"@=\" (language). Parsed filter: \"%s\".", filterString));
return null;
}
}
Aggregations