use of com.odysseusinc.arachne.portal.model.PublishState in project ArachneCentralAPI by OHDSI.
the class PaperSpecification method toPredicate.
@Override
public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
final Path<Long> id = root.get(Paper_.id);
final Path<Study> study = root.get(Paper_.study);
final Path<Long> studyId = study.get(Study_.id);
final Path<String> studyTitle = study.get(Study_.title);
final Path<PublishState> publishState = root.get(Paper_.publishState);
Expression<List> followers = root.get(Paper_.followers);
List<Predicate> predicates = new ArrayList<>();
predicates.add(getAdditionalPredicates(root, query, cb, studyId, id));
if (criteria.getPublishState() != null) {
predicates.add(cb.equal(publishState, criteria.getPublishState()));
}
if (criteria.getFavourite() != null) {
predicates.add(criteria.getFavourite() ? cb.isMember(user, followers) : cb.isNotMember(user, followers));
}
if (criteria.getQuery() != null) {
predicates.add(cb.like(cb.lower(studyTitle), getLowerPostfixPrefixLikeForm(criteria.getQuery().toLowerCase())));
}
final String sortBy = criteria.getSortBy();
if (sortBy != null) {
boolean sortAsc = criteria.getSortAsc();
Expression<String> path;
switch(sortBy) {
case FAVOURITE:
path = cb.size(followers).as(String.class);
sortAsc = !sortAsc;
break;
default:
Path relative = root;
for (String field : sortBy.split("\\.")) {
relative = relative.get(field);
}
path = relative;
}
Order order;
if (sortAsc) {
order = cb.asc(path);
} else {
order = cb.desc(path);
}
query.orderBy(order);
}
return cb.and(predicates.toArray(new Predicate[predicates.size()]));
}
use of com.odysseusinc.arachne.portal.model.PublishState in project ArachneCentralAPI by OHDSI.
the class BasePaperServiceImpl method update.
@PreAuthorize("hasPermission(#paper.id, 'Paper', " + "T(com.odysseusinc.arachne.portal.security.ArachnePermission).EDIT_PAPER)")
@PostAuthorize("@ArachnePermissionEvaluator.processPermissions(principal, returnObject )")
@Override
public P update(P paper) {
final P exists = getPaperByIdOrThrow(paper.getId());
final PublishState publishState = paper.getPublishState();
if (publishState != null && validatePublishStateTransition(publishState, exists)) {
exists.setPublishState(publishState);
exists.setPublishedDate(publishState == PublishState.PUBLISHED ? new Date() : null);
}
beforePaperUpdate(exists, paper);
P save = paperRepository.save(exists);
afterPaperUpdate(exists, paper);
return save;
}
Aggregations