Search in sources :

Example 1 with PublishState

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()]));
}
Also used : Path(javax.persistence.criteria.Path) Order(javax.persistence.criteria.Order) Study(com.odysseusinc.arachne.portal.model.Study) ArrayList(java.util.ArrayList) PublishState(com.odysseusinc.arachne.portal.model.PublishState) Predicate(javax.persistence.criteria.Predicate) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with PublishState

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;
}
Also used : Date(java.util.Date) PublishState(com.odysseusinc.arachne.portal.model.PublishState) PostAuthorize(org.springframework.security.access.prepost.PostAuthorize) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

PublishState (com.odysseusinc.arachne.portal.model.PublishState)2 Study (com.odysseusinc.arachne.portal.model.Study)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1 Order (javax.persistence.criteria.Order)1 Path (javax.persistence.criteria.Path)1 Predicate (javax.persistence.criteria.Predicate)1 PostAuthorize (org.springframework.security.access.prepost.PostAuthorize)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1