Fix compilation errors after changes in play-cms

parent f5ad9c79
Pipeline #11668 failed with stages
in 10 minutes and 22 seconds
......@@ -7,7 +7,6 @@ import crud.data.entity.Brand;
import crud.data.entity.Car;
import crud.permission.CarPermission;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.AuthorizationException;
import play.db.jpa.JPAApi;
import javax.inject.Inject;
......@@ -29,6 +28,7 @@ public class CarDatatableService extends AbstractDatatableService<Car> {
@Inject
public CarDatatableService(JPAApi jpaApi, PlayAuthApi playAuthApi, PlayAuth playAuth) {
super(jpaApi);
this.jpaApi = jpaApi;
this.playAuthApi = playAuthApi;
}
......@@ -110,4 +110,33 @@ public class CarDatatableService extends AbstractDatatableService<Car> {
}
);
}
@Override
protected CriteriaQuery buildSearchCriteria(CriteriaQuery query, CriteriaBuilder builder, Root root, String keywords,
String orderByField, String orderByDirection) {
Root<Car> cars = (Root<Car>) root;
List<Predicate> conditionsAnd = new ArrayList<>();
List<String> searchFields = Arrays.asList(SEARCHABLE_FIELDS);
for (String keyword : StringUtils.split(keywords)) {
Predicate[] likeConditions = searchFields.stream()
.map(field -> builder.like(builder.lower(cars.get(field)), "%" + keyword.trim().toLowerCase() + "%"))
.toArray(Predicate[]::new);
conditionsAnd.add(builder.or(likeConditions));
}
Expression orderByFieldExpression;
orderByField = StringUtils.defaultIfEmpty(orderByField, "model");
orderByFieldExpression = cars.get(orderByField);
return query
.where(builder.and(conditionsAnd.toArray(new Predicate[]{})))
.orderBy(StringUtils.defaultIfEmpty(orderByDirection, "desc").equals("desc")
? builder.desc(orderByFieldExpression)
: builder.asc(orderByFieldExpression));
}
}
......@@ -3,11 +3,15 @@ package service;
import ch.insign.cms.CMSApi;
import ch.insign.cms.services.PartyDatatableService;
import ch.insign.playauth.PlayAuthApi;
import ch.insign.playauth.party.support.DefaultParty;
import org.apache.commons.lang3.StringUtils;
import party.User;
import play.db.jpa.JPAApi;
import javax.inject.Inject;
import javax.persistence.criteria.*;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
......@@ -50,4 +54,38 @@ public class UserDatatableService extends PartyDatatableService<User> {
private Function<User, String> getUserLoginCount() {
return user -> Optional.ofNullable(user.getLoginCount()).map(Object::toString).get();
}
@Override
protected CriteriaQuery buildSearchCriteria(CriteriaQuery query, CriteriaBuilder builder, Root root, String keywords,
String orderByField, String orderByDirection) {
Root<DefaultParty> users = (Root<DefaultParty>) root;
List<Predicate> conditionsAnd = new ArrayList<>();
List<String> searchFields = Arrays.asList("name", "email", "roleName", "lastLogin", "loginCount", "");
for (String keyword : StringUtils.split(keywords)) {
Predicate[] likeConditions = searchFields.stream()
.map(field -> builder.like(builder.lower(users.get(field)), "%" + keyword.trim().toLowerCase() + "%"))
.toArray(Predicate[]::new);
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);
}
return query
.where(builder.and(conditionsAnd.toArray(new Predicate[]{})))
.orderBy(StringUtils.defaultIfEmpty(orderByDirection, "desc").equals("desc")
? builder.desc(orderByFieldExpression)
: builder.asc(orderByFieldExpression));
}
}
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