@Override public String toString() { List<PathElement> elements = path.getPathElements(); StringBuilder formattedPath = new StringBuilder(); if (!elements.isEmpty()) { formattedPath.append(StringUtils.uncapitalize(EntityDictionary.getSimpleName(elements.get(0).getType()))); } for (PathElement element : elements) { formattedPath.append(PERIOD).append(element.getFieldName()); } return formattedPath.append(' ').append(operator).append(' ').append(values).toString(); }
@Override public String toString() { List<PathElement> elements = path.getPathElements(); StringBuilder formattedPath = new StringBuilder(); if (!elements.isEmpty()) { formattedPath.append(StringUtils.uncapitalize(EntityDictionary.getSimpleName(elements.get(0).getType()))); } for (PathElement element : elements) { formattedPath.append(PERIOD).append(element.getFieldName()); } return formattedPath.append(' ').append(operator).append(' ').append(values).toString(); }
@Override public String toString() { return pathElements.size() == 0 ? "EMPTY" : pathElements.stream() .map(e -> '[' + EntityDictionary.getSimpleName(e.getType()) + ']' + PERIOD + e.getFieldName()) .collect(Collectors.joining("/")); }
@Override public FilterExpression parseGlobalExpression(String path, MultivaluedMap<String, String> filterParams) throws ParseException { List<FilterPredicate> filterPredicates; filterPredicates = extractPredicates(filterParams); /* Extract the first collection in the URL */ String normalizedPath = JsonApiParser.normalizePath(path); String[] pathComponents = normalizedPath.split("/"); String firstPathComponent = ""; if (pathComponents.length > 0) { firstPathComponent = pathComponents[0]; } /* Comma separated filter parameters are joined with logical AND. */ FilterExpression joinedExpression = null; for (FilterPredicate filterPredicate : filterPredicates) { Class firstClass = filterPredicate.getPath().getPathElements().get(0).getType(); /* The first type in the predicate must match the first collection in the URL */ if (!dictionary.getJsonAliasFor(firstClass).equals(firstPathComponent)) { throw new ParseException(String.format("Invalid predicate: %s", filterPredicate)); } if (joinedExpression == null) { joinedExpression = filterPredicate; } else { joinedExpression = new AndFilterExpression(joinedExpression, filterPredicate); } } return joinedExpression; }
@Override public FilterExpression parseGlobalExpression(String path, MultivaluedMap<String, String> filterParams) throws ParseException { List<FilterPredicate> filterPredicates; filterPredicates = extractPredicates(filterParams); /* Extract the first collection in the URL */ String normalizedPath = JsonApiParser.normalizePath(path); String[] pathComponents = normalizedPath.split("/"); String firstPathComponent = ""; if (pathComponents.length > 0) { firstPathComponent = pathComponents[0]; } /* Comma separated filter parameters are joined with logical AND. */ FilterExpression joinedExpression = null; for (FilterPredicate filterPredicate : filterPredicates) { Class firstClass = filterPredicate.getPath().getPathElements().get(0).getType(); /* The first type in the predicate must match the first collection in the URL */ if (!dictionary.getJsonAliasFor(firstClass).equals(firstPathComponent)) { throw new ParseException(String.format("Invalid predicate: %s", filterPredicate)); } if (joinedExpression == null) { joinedExpression = filterPredicate; } else { joinedExpression = new AndFilterExpression(joinedExpression, filterPredicate); } } return joinedExpression; }
/** * Validates that none of the provided path's relationships are to-many * @param path The path to validate * @param dictionary The elide entity dictionary * @return True if the path is valid. False otherwise. */ protected static boolean isValidSortRulePath(Path path, EntityDictionary dictionary) { //Validate that none of the relationships are to-many for (Path.PathElement pathElement : path.getPathElements()) { if (! dictionary.isRelation(pathElement.getType(), pathElement.getFieldName())) { continue; } if (dictionary.getRelationshipType(pathElement.getType(), pathElement.getFieldName()).isToMany()) { return false; } } return true; }
/** * Validates that none of the provided path's relationships are to-many * @param path The path to validate * @param dictionary The elide entity dictionary * @return True if the path is valid. False otherwise. */ protected static boolean isValidSortRulePath(Path path, EntityDictionary dictionary) { //Validate that none of the relationships are to-many for (Path.PathElement pathElement : path.getPathElements()) { if (! dictionary.isRelation(pathElement.getType(), pathElement.getFieldName())) { continue; } if (dictionary.getRelationshipType(pathElement.getType(), pathElement.getFieldName()).isToMany()) { return false; } } return true; }
/** * Returns an alias that uniquely identifies the last collection of entities in the path. * @return An alias for the path. */ public String getAlias() { List<PathElement> elements = path.getPathElements(); PathElement last = elements.get(elements.size() - 1); if (elements.size() == 1) { return getTypeAlias(last.getType()); } PathElement previous = elements.get(elements.size() - 2); return getTypeAlias(previous.getType()) + UNDERSCORE + previous.getFieldName(); }
/** * Returns an alias that uniquely identifies the last collection of entities in the path. * @return An alias for the path. */ public String getAlias() { if (pathElements.size() < 2) { return lastElement() .map(e -> getTypeAlias(e.getType())) .orElse(null); } PathElement previous = pathElements.get(pathElements.size() - 2); return getTypeAlias(previous.getType()) + UNDERSCORE + previous.getFieldName(); }
/** * Returns an alias that uniquely identifies the last collection of entities in the path. * @return An alias for the path. */ public String getAlias() { if (pathElements.size() < 2) { return lastElement() .map(e -> getTypeAlias(e.getType())) .orElse(null); } PathElement previous = pathElements.get(pathElements.size() - 2); return getTypeAlias(previous.getType()) + UNDERSCORE + previous.getFieldName(); }
public Class getEntityType() { List<PathElement> elements = path.getPathElements(); PathElement first = elements.get(0); return first.getType(); }
/** * Returns an alias that uniquely identifies the last collection of entities in the path. * @return An alias for the path. */ public String getAlias() { List<PathElement> elements = path.getPathElements(); PathElement last = elements.get(elements.size() - 1); if (elements.size() == 1) { return getTypeAlias(last.getType()); } PathElement previous = elements.get(elements.size() - 2); return getTypeAlias(previous.getType()) + UNDERSCORE + previous.getFieldName(); }
@Override public String toString() { return pathElements.size() == 0 ? "EMPTY" : pathElements.stream() .map(e -> '[' + EntityDictionary.getSimpleName(e.getType()) + ']' + PERIOD + e.getFieldName()) .collect(Collectors.joining("/")); }
public static boolean toManyInPath(EntityDictionary dictionary, Path path) { return path.getPathElements().stream() .map(element -> dictionary.getRelationshipType(element.getType(), element.getFieldName())) .anyMatch(RelationshipType::isToMany); }
public Class getEntityType() { List<PathElement> elements = path.getPathElements(); PathElement first = elements.get(0); return first.getType(); }
public static boolean toManyInPath(EntityDictionary dictionary, Path path) { return path.getPathElements().stream() .map(element -> dictionary.getRelationshipType(element.getType(), element.getFieldName())) .anyMatch(RelationshipType::isToMany); }