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());
}
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));
}
}
}
}
Aggregations