Search in sources :

Example 1 with DataSourceStatus

use of com.odysseusinc.arachne.portal.model.DataSourceStatus in project ArachneCentralAPI by OHDSI.

the class BaseDataSourceServiceImpl method suggestDataSource.

@Override
public Page<DS> suggestDataSource(final String query, final Long studyId, final Long userId, PageRequest pageRequest) {
    List<DataSourceStatus> BAD_STATUSES = Arrays.asList(DataSourceStatus.DELETED, DataSourceStatus.DECLINED);
    final String[] split = query.trim().split(" ");
    CriteriaBuilder cb = this.entityManager.getCriteriaBuilder();
    CriteriaQuery<DS> cq = cb.createQuery(getType());
    Root<DS> root = cq.from(getType());
    Subquery sq = cq.subquery(Long.class);
    Root<StudyDataSourceLink> dsLink = sq.from(StudyDataSourceLink.class);
    sq.select(dsLink.get("dataSource").get("id"));
    sq.where(cb.and(cb.equal(dsLink.get("study").get("id"), studyId), cb.not(dsLink.get("status").in(BAD_STATUSES))));
    cq.select(root);
    // TRUE
    Predicate nameClause = cb.conjunction();
    if (split.length > 1 || (split.length == 1 && !split[0].equals(""))) {
        List<Predicate> predictList = new ArrayList<>();
        for (String one : split) {
            predictList.add(cb.like(cb.lower(root.get("name")), one + "%"));
            predictList.add(cb.like(cb.lower(root.get("dataNode").get("name")), one + "%"));
        }
        nameClause = cb.or(predictList.toArray(new Predicate[] {}));
    }
    cq.where(cb.and(cb.not(root.get("id").in(sq)), nameClause, cb.isNull(root.get("deleted")), cb.isTrue(root.get("published")), cb.isFalse(root.get("dataNode").get("virtual"))));
    TypedQuery<DS> typedQuery = this.entityManager.createQuery(cq);
    List<DS> list = typedQuery.setFirstResult(pageRequest.getOffset()).setMaxResults(pageRequest.getPageSize()).getResultList();
    return new PageImpl<>(list, pageRequest, list.size());
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) PageImpl(org.springframework.data.domain.PageImpl) StudyDataSourceLink(com.odysseusinc.arachne.portal.model.StudyDataSourceLink) ArrayList(java.util.ArrayList) Subquery(javax.persistence.criteria.Subquery) Predicate(javax.persistence.criteria.Predicate) DataSourceStatus(com.odysseusinc.arachne.portal.model.DataSourceStatus)

Example 2 with DataSourceStatus

use of com.odysseusinc.arachne.portal.model.DataSourceStatus in project ArachneCentralAPI by OHDSI.

the class BaseStudyServiceImpl method processDataSourceInvitation.

@Override
public void processDataSourceInvitation(IUser user, Long id, Boolean accepted, String comment) {
    StudyDataSourceLink studyDataSourceLink = studyDataSourceLinkRepository.findByIdAndOwnerId(id, user.getId());
    if (studyDataSourceLink != null) {
        DataSourceStatus status = TRUE.equals(accepted) ? APPROVED : DECLINED;
        studyDataSourceLink.setStatus(status);
        if (DECLINED == status) {
            if (!StringUtils.isEmpty(comment)) {
                dataSourceCommentRepository.save(new StudyDataSourceComment(studyDataSourceLink.getId(), user.getId(), comment));
            }
        }
    }
}
Also used : StudyDataSourceComment(com.odysseusinc.arachne.portal.model.StudyDataSourceComment) StudyDataSourceLink(com.odysseusinc.arachne.portal.model.StudyDataSourceLink) DataSourceStatus(com.odysseusinc.arachne.portal.model.DataSourceStatus)

Aggregations

DataSourceStatus (com.odysseusinc.arachne.portal.model.DataSourceStatus)2 StudyDataSourceLink (com.odysseusinc.arachne.portal.model.StudyDataSourceLink)2 StudyDataSourceComment (com.odysseusinc.arachne.portal.model.StudyDataSourceComment)1 ArrayList (java.util.ArrayList)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 Predicate (javax.persistence.criteria.Predicate)1 Subquery (javax.persistence.criteria.Subquery)1 PageImpl (org.springframework.data.domain.PageImpl)1