Commit f940aab6 by Alexey Gobzhelyan

Merge branch 'PLAY-174' into 'master'

PLAY-174 Don't use default value for ORDER BY Closes PLAY-174 See merge request !101
parents 12305f87 314e8178
Pipeline #12195 passed with stages
in 21 minutes 34 seconds
package service;
import ch.insign.cms.services.AbstractDatatableService;
import ch.insign.playauth.PlayAuth;
import ch.insign.playauth.PlayAuthApi;
import crud.data.entity.Brand;
import crud.data.entity.Car;
......@@ -127,16 +126,16 @@ public class CarDatatableService extends AbstractDatatableService<Car> {
conditionsAnd.add(builder.or(likeConditions));
}
Expression orderByFieldExpression;
query.where(builder.and(conditionsAnd.toArray(new Predicate[]{})));
orderByField = StringUtils.defaultIfEmpty(orderByField, "model");
if (StringUtils.isNotEmpty(orderByField)) {
Expression orderByFieldExpression = cars.get(orderByField);
orderByFieldExpression = cars.get(orderByField);
query.orderBy(StringUtils.defaultIfEmpty(orderByDirection, "desc").equals("desc")
? builder.desc(orderByFieldExpression)
: builder.asc(orderByFieldExpression));
}
return query
.where(builder.and(conditionsAnd.toArray(new Predicate[]{})))
.orderBy(StringUtils.defaultIfEmpty(orderByDirection, "desc").equals("desc")
? builder.desc(orderByFieldExpression)
: builder.asc(orderByFieldExpression));
return query;
}
}
......@@ -71,21 +71,22 @@ public class UserDatatableService extends PartyDatatableService<User> {
conditionsAnd.add(builder.or(likeConditions));
}
Expression orderByFieldExpression;
orderByField = StringUtils.defaultIfEmpty(orderByField, "name");
if (orderByField.equals("roleName")) {
users.fetch("partyRoles", JoinType.LEFT);
orderByFieldExpression = users.get("partyRoles").get("name");
} else {
orderByFieldExpression = users.get(orderByField);
query.where(builder.and(conditionsAnd.toArray(new Predicate[]{})));
if (StringUtils.isNotEmpty(orderByField)) {
Expression orderByFieldExpression;
if (orderByField.equals("roleName")) {
users.fetch("partyRoles", JoinType.LEFT);
orderByFieldExpression = users.get("partyRoles").get("name");
} else {
orderByFieldExpression = users.get(orderByField);
}
query.orderBy(StringUtils.defaultIfEmpty(orderByDirection, "desc").equals("desc")
? builder.desc(orderByFieldExpression)
: builder.asc(orderByFieldExpression));
}
return query
.where(builder.and(conditionsAnd.toArray(new Predicate[]{})))
.orderBy(StringUtils.defaultIfEmpty(orderByDirection, "desc").equals("desc")
? builder.desc(orderByFieldExpression)
: builder.asc(orderByFieldExpression));
return query;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment