@@ -64,25 +64,43 @@ public static Function<Sort.Order, SortItem> sortAdapterFor(NodeDescription<?> n
64
64
return order -> {
65
65
66
66
String domainProperty = order .getProperty ();
67
- boolean propertyIsQualified = domainProperty .contains ("." );
67
+ boolean propertyIsQualifiedOrComposite = domainProperty .contains ("." );
68
68
SymbolicName root ;
69
- if (!propertyIsQualified ) {
69
+ if (!propertyIsQualifiedOrComposite ) {
70
70
root = Constants .NAME_OF_TYPED_ROOT_NODE .apply (nodeDescription );
71
71
} else {
72
- int indexOfSeparator = domainProperty .indexOf ("." );
73
- root = Cypher .name (domainProperty .substring (0 , indexOfSeparator ));
74
- domainProperty = domainProperty .substring (indexOfSeparator + 1 );
72
+ // need to check first if this is really a qualified name or the "qualifier" is a composite property
73
+ if (nodeDescription .getGraphProperty (domainProperty .split ("\\ ." )[0 ]).isEmpty ()) {
74
+ int indexOfSeparator = domainProperty .indexOf ("." );
75
+ root = Cypher .name (domainProperty .substring (0 , indexOfSeparator ));
76
+ domainProperty = domainProperty .substring (indexOfSeparator + 1 );
77
+ } else {
78
+ root = Constants .NAME_OF_TYPED_ROOT_NODE .apply (nodeDescription );
79
+ }
75
80
}
76
81
77
82
var optionalGraphProperty = nodeDescription .getGraphProperty (domainProperty );
83
+ // try to resolve if this is a composite property
84
+ if (optionalGraphProperty .isEmpty ()) {
85
+ var domainPropertyPrefix = domainProperty .split ("\\ ." )[0 ];
86
+ optionalGraphProperty = nodeDescription .getGraphProperty (domainPropertyPrefix );
87
+ }
78
88
if (optionalGraphProperty .isEmpty ()) {
79
- throw new IllegalStateException (String .format ("Cannot order by the unknown graph property: '%s'" , order . getProperty () ));
89
+ throw new IllegalStateException (String .format ("Cannot order by the unknown graph property: '%s'" , domainProperty ));
80
90
}
81
91
var graphProperty = optionalGraphProperty .get ();
82
92
Expression expression ;
83
93
if (graphProperty .isInternalIdProperty ()) {
84
94
// Not using the id expression here, as the root will be referring to the constructed map being returned.
85
95
expression = property (root , Constants .NAME_OF_INTERNAL_ID );
96
+ } else if (graphProperty .isComposite () && !domainProperty .contains ("." )) {
97
+ throw new IllegalStateException (String .format ("Cannot order by composite property: '%s'. Only ordering by its nested fields is allowed." , domainProperty ));
98
+ } else if (graphProperty .isComposite ()) {
99
+ if (nodeDescription .containsPossibleCircles (rpp -> true )) {
100
+ expression = property (root , domainProperty );
101
+ } else {
102
+ expression = property (root , Constants .NAME_OF_ALL_PROPERTIES , domainProperty );
103
+ }
86
104
} else {
87
105
expression = property (root , graphProperty .getPropertyName ());
88
106
if (order .isIgnoreCase ()) {
0 commit comments