Java Code Examples for cz.jirutka.rsql.parser.ast.ComparisonNode#getSelector()
The following examples show how to use
cz.jirutka.rsql.parser.ast.ComparisonNode#getSelector() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RSQLUtility.java From hawkbit with Eclipse Public License 1.0 | 6 votes |
private void validateMapParameter(final A propertyEnum, final ComparisonNode node, final String[] graph) { if (!propertyEnum.isMap()) { return; } if (!propertyEnum.getSubEntityAttributes().isEmpty()) { throw new UnsupportedOperationException( "Currently subentity attributes for maps are not supported, alternatively you could use the key/value tuple, defined by SimpleImmutableEntry class"); } // enum.key final int minAttributeForMap = 2; if (graph.length != minAttributeForMap) { throw new RSQLParameterUnsupportedFieldException("The syntax of the given map search parameter field {" + node.getSelector() + "} is wrong. Syntax is: fieldname.keyname", new Exception()); } }
Example 2
Source File: RSQLUtility.java From hawkbit with Eclipse Public License 1.0 | 6 votes |
@SuppressWarnings({ "rawtypes", "unchecked", "squid:S2095" }) private static Object transformEnumValue(final ComparisonNode node, final String value, final Class<?> javaType) { final Class<? extends Enum> tmpEnumType = (Class<? extends Enum>) javaType; try { return Enum.valueOf(tmpEnumType, value.toUpperCase()); } catch (final IllegalArgumentException e) { // we could not transform the given string value into the enum // type, so ignore it and return null and do not filter LOGGER.info("given value {} cannot be transformed into the correct enum type {}", value.toUpperCase(), javaType); LOGGER.debug("value cannot be transformed to an enum", e); throw new RSQLParameterUnsupportedFieldException("field {" + node.getSelector() + "} must be one of the following values {" + Arrays.stream(tmpEnumType.getEnumConstants()) .map(v -> v.name().toLowerCase()).collect(Collectors.toList()) + "}", e); } }
Example 3
Source File: MolgenisRSQLVisitor.java From molgenis with GNU Lesser General Public License v3.0 | 6 votes |
private Attribute getAttribute(ComparisonNode node) { EntityType entityType = repository.getEntityType(); String attrName = node.getSelector(); String[] attrTokens = attrName.split("\\."); Attribute attr = entityType.getAttribute(attrTokens[0]); if (attr == null) { throw new UnknownAttributeException(entityType, attrName); } EntityType entityTypeAtDepth; for (int i = 1; i < attrTokens.length; ++i) { entityTypeAtDepth = attr.getRefEntity(); attr = entityTypeAtDepth.getAttribute(attrTokens[i]); if (attr == null) { throw new UnknownAttributeException(entityTypeAtDepth, attrName); } } return attr; }
Example 4
Source File: RSQLComplexConverter.java From rsql-jpa-specification with MIT License | 5 votes |
@Override public Void visit(ComparisonNode node, Map<String, MultiValueMap<String, String>> map) { log.debug("visit(node:{},map:{})", node, map); String key = node.getSelector(); ComparisonOperator operator = node.getOperator(); MultiValueMap<String, String> operatorMap = map.computeIfAbsent(key, k -> CollectionUtils.toMultiValueMap(new HashMap<>())); for (String ops : operator.getSymbols()) { operatorMap.addAll(ops, node.getArguments()); } return null; }
Example 5
Source File: RSQLUtility.java From hawkbit with Eclipse Public License 1.0 | 5 votes |
private RSQLParameterUnsupportedFieldException createRSQLParameterUnsupportedException( final ComparisonNode node) { return new RSQLParameterUnsupportedFieldException( "The given search parameter field {" + node.getSelector() + "} does not exist, must be one of the following fields {" + getExpectedFieldList() + "}", new Exception()); }
Example 6
Source File: RSQLUtility.java From hawkbit with Eclipse Public License 1.0 | 5 votes |
@Override // Exception squid:S2095 - see // https://jira.sonarsource.com/browse/SONARJAVA-1478 @SuppressWarnings({ "squid:S2095" }) public List<Predicate> visit(final ComparisonNode node, final String param) { A fieldName = null; try { fieldName = getFieldEnumByName(node); } catch (final IllegalArgumentException e) { throw new RSQLParameterUnsupportedFieldException("The given search parameter field {" + node.getSelector() + "} does not exist, must be one of the following fields {" + Arrays.stream(enumType.getEnumConstants()).map(v -> v.name().toLowerCase()) .collect(Collectors.toList()) + "}", e); } final String finalProperty = getAndValidatePropertyFieldName(fieldName, node); final List<String> values = node.getArguments(); final List<Object> transformedValues = new ArrayList<>(); final Path<Object> fieldPath = getFieldPath(fieldName, finalProperty); for (final String value : values) { transformedValues.add(convertValueIfNecessary(node, fieldName, value, fieldPath)); } this.joinsNeeded = this.joinsNeeded || areJoinsNeeded(node); return mapToPredicate(node, fieldPath, node.getArguments(), transformedValues, fieldName, finalProperty); }
Example 7
Source File: RSQLUtility.java From hawkbit with Eclipse Public License 1.0 | 5 votes |
private A getFieldEnumByName(final ComparisonNode node) { String enumName = node.getSelector(); final String[] graph = getSubAttributesFrom(enumName); if (graph.length != 0) { enumName = graph[0]; } LOGGER.debug("get fieldidentifier by name {} of enum type {}", enumName, enumType); return Enum.valueOf(enumType, enumName.toUpperCase()); }
Example 8
Source File: RSQLUtility.java From hawkbit with Eclipse Public License 1.0 | 5 votes |
private Object convertBooleanValue(final ComparisonNode node, final String value, final Class<?> javaType) { try { return simpleTypeConverter.convertIfNecessary(value, javaType); } catch (final TypeMismatchException e) { throw new RSQLParameterSyntaxException( "The value of the given search parameter field {" + node.getSelector() + "} is not well formed. Only a boolean (true or false) value will be expected {", e); } }
Example 9
Source File: RSQLUtility.java From hawkbit with Eclipse Public License 1.0 | 5 votes |
@SuppressWarnings({ "rawtypes", "unchecked" }) private Object convertFieldConverterValue(final ComparisonNode node, final A fieldName, final String value) { final Object convertedValue = ((FieldValueConverter) fieldName).convertValue(fieldName, value); if (convertedValue == null) { throw new RSQLParameterUnsupportedFieldException( "field {" + node.getSelector() + "} must be one of the following values {" + Arrays.toString(((FieldValueConverter) fieldName).possibleValues(fieldName)) + "}", null); } else { return convertedValue; } }
Example 10
Source File: PermissionRsqlVisitor.java From molgenis with GNU Lesser General Public License v3.0 | 5 votes |
private PermissionsQuery setQuery( ComparisonNode comparisonNode, PermissionsQuery permissionsQuery) { String key = comparisonNode.getSelector(); List<String> arguments = comparisonNode.getArguments(); if (key.equalsIgnoreCase("user")) { permissionsQuery.setUsers(arguments); } else if (key.equalsIgnoreCase("role")) { permissionsQuery.setRoles(arguments); } else { throw new UnknownPermissionQueryParamException(key); } return permissionsQuery; }
Example 11
Source File: AggregateQueryRsqlVisitor.java From molgenis with GNU Lesser General Public License v3.0 | 5 votes |
@Override public AggregateQuery visit(ComparisonNode node) { String symbol = node.getOperator().getSymbol(); if (!symbol.equals("==")) { throw new MolgenisQueryException( String.format( "RSQL query symbol [%s] not allowed in aggregates query, use ['==']", symbol)); } String selector = node.getSelector(); switch (selector) { case "x": aggsQ.setAttributeX(getAttribute(node)); break; case "y": aggsQ.setAttributeY(getAttribute(node)); break; case "distinct": aggsQ.setAttributeDistinct(getAttribute(node)); break; default: throw new MolgenisQueryException( String.format( "RSQL query selector [%s] not allowed in aggregates query, use ['x', 'y' or 'distinct']", selector)); } return aggsQ; }
Example 12
Source File: QueryRsqlVisitor.java From molgenis with GNU Lesser General Public License v3.0 | 4 votes |
private static @Nullable @CheckForNull String toItem(ComparisonNode node) { String selector = node.getSelector(); return selector.equals("*") ? null : selector; }
Example 13
Source File: MolgenisRSQLVisitor.java From molgenis with GNU Lesser General Public License v3.0 | 4 votes |
@Override public Query<Entity> visit(ComparisonNode node) { initQuery(); String attrName = node.getSelector(); String symbol = node.getOperator().getSymbol(); List<String> values = node.getArguments(); switch (symbol) { case "=notlike=": String notLikeValue = values.get(0); q.not().like(attrName, notLikeValue); break; case "=q=": String searchValue = values.get(0); if (attrName.equals("*")) { q.search(searchValue); } else { q.search(attrName, searchValue); } break; case "=sq=": String query = values.get(0); if (attrName.equals("*")) { q.searchQuery(query); } else { q.searchQuery(attrName, query); } break; case "==": Object eqValue = rsqlValueParser.parse(values.get(0), getAttribute(node)); q.eq(attrName, eqValue); break; case "=in=": Attribute inAttr = getAttribute(node); q.in( attrName, values.stream().map(value -> rsqlValueParser.parse(value, inAttr)).collect(toList())); break; case "=lt=": case "<": Attribute ltAttr = getAttribute(node); validateNumericOrDate(ltAttr); Object ltValue = rsqlValueParser.parse(values.get(0), ltAttr); q.lt(attrName, ltValue); break; case "=le=": case "<=": Attribute leAttr = getAttribute(node); validateNumericOrDate(leAttr); Object leValue = rsqlValueParser.parse(values.get(0), leAttr); q.le(attrName, leValue); break; case "=gt=": case ">": Attribute gtAttr = getAttribute(node); validateNumericOrDate(gtAttr); Object gtValue = rsqlValueParser.parse(values.get(0), gtAttr); q.gt(attrName, gtValue); break; case "=ge=": case ">=": Attribute geAttr = getAttribute(node); validateNumericOrDate(geAttr); Object geValue = rsqlValueParser.parse(values.get(0), geAttr); q.ge(attrName, geValue); break; case "=rng=": Attribute rngAttr = getAttribute(node); validateNumericOrDate(rngAttr); Object fromValue = values.get(0) != null ? rsqlValueParser.parse(values.get(0), rngAttr) : null; Object toValue = values.get(1) != null ? rsqlValueParser.parse(values.get(1), rngAttr) : null; q.rng(attrName, fromValue, toValue); break; case "=like=": String likeValue = values.get(0); q.like(attrName, likeValue); break; case "!=": Object notEqValue = rsqlValueParser.parse(values.get(0), getAttribute(node)); q.not().eq(attrName, notEqValue); break; case "=should=": throw new MolgenisQueryException("Unsupported RSQL query operator [" + symbol + "]"); case "=dismax=": throw new MolgenisQueryException("Unsupported RSQL query operator [" + symbol + "]"); case "=fuzzy=": throw new MolgenisQueryException("Unsupported RSQL query operator [" + symbol + "]"); default: throw new MolgenisQueryException("Unknown RSQL query operator [" + symbol + "]"); } return q; }