use of com.odysseusinc.arachne.portal.exception.NotExistException in project ArachneCentralAPI by OHDSI.
the class BaseAnalysisServiceImpl method sendAnalysisUnlockRequest.
@Override
public AnalysisUnlockRequest sendAnalysisUnlockRequest(Long analysisId, AnalysisUnlockRequest analysisUnlockRequest) throws NotExistException, AlreadyExistException {
final Optional<A> analysisOptional = analysisRepository.findByIdAndAndLockedTrue(analysisId);
final Analysis analysis = analysisOptional.orElseThrow(() -> new NotExistException(ANALYSIS_NOT_FOUND_EXCEPTION, Analysis.class));
IUser user = analysisUnlockRequest.getUser();
final AnalysisUnlockRequest existUnlockRequest = analysisUnlockRequestRepository.findByAnalysisAndStatus(analysis, AnalysisUnlockRequestStatus.PENDING);
if (existUnlockRequest != null) {
String message = String.format(UNLOCK_REQUEST_ALREADY_EXISTS_EXCEPTION, analysis.getId(), user.getId());
throw new AlreadyExistException(message);
}
analysisUnlockRequest.setAnalysis(analysis);
final AnalysisUnlockRequest savedUnlockRequest = analysisUnlockRequestRepository.save(analysisUnlockRequest);
studyService.findLeads((S) savedUnlockRequest.getAnalysis().getStudy()).forEach(lead -> mailSender.send(new UnlockAnalysisRequestMailMessage(WebSecurityConfig.getDefaultPortalURI(), lead, savedUnlockRequest)));
return savedUnlockRequest;
}
use of com.odysseusinc.arachne.portal.exception.NotExistException in project ArachneCentralAPI by OHDSI.
the class BaseAnalysisServiceImpl method update.
@Override
@PreAuthorize("hasPermission(#analysis, 'Analysis', " + "T(com.odysseusinc.arachne.portal.security.ArachnePermission).EDIT_ANALYSIS)")
public A update(A analysis) throws NotUniqueException, NotExistException, ValidationException {
A forUpdate = analysisRepository.findOne(analysis.getId());
if (forUpdate == null) {
throw new NotExistException("update: analysis with id=" + analysis.getId() + " not exist", Analysis.class);
}
if (analysis.getTitle() != null && !analysis.getTitle().equals(forUpdate.getTitle())) {
List<A> analyses = analysisRepository.findByTitleAndStudyId(analysis.getTitle(), forUpdate.getStudy().getId());
if (!analyses.isEmpty()) {
throw new NotUniqueException("title", "Not unique");
}
forUpdate.setTitle(analysis.getTitle());
}
if (analysis.getDescription() != null) {
forUpdate.setDescription(analysis.getDescription());
}
final CommonAnalysisType analysisType = analysis.getType();
if (analysisType != null) {
forUpdate.setType(analysisType);
}
final A saved = super.update(forUpdate);
solrService.indexBySolr(saved);
return saved;
}
use of com.odysseusinc.arachne.portal.exception.NotExistException in project ArachneCentralAPI by OHDSI.
the class BaseDataNodeServiceImpl method unlinkUserToDataNode.
@Transactional
@Override
@PreAuthorize("#dataNode == authentication.principal")
public void unlinkUserToDataNode(DN dataNode, IUser user) throws NotExistException {
LOGGER.info(UNLINKING_USER_LOG, user.getId(), dataNode.getId());
final DataNodeUser existDataNodeUser = dataNodeUserRepository.findByDataNodeAndUserId(dataNode, user.getId()).orElseThrow(() -> {
final String message = String.format(USER_IS_NOT_LINKED_EXC, user.getId(), dataNode.getId());
return new NotExistException(message, User.class);
});
dataNodeUserRepository.delete(existDataNodeUser);
}
use of com.odysseusinc.arachne.portal.exception.NotExistException in project ArachneCentralAPI by OHDSI.
the class BaseStudyServiceImpl method update.
@Override
@PreAuthorize("hasPermission(#study, " + "T(com.odysseusinc.arachne.portal.security.ArachnePermission).EDIT_STUDY)")
@PostAuthorize("@ArachnePermissionEvaluator.addPermissions(principal, returnObject )")
public T update(T study) throws NotExistException, NotUniqueException, ValidationException {
if (study.getId() == null) {
throw new NotExistException("id is null", getType());
}
List<T> byTitle = studyRepository.findByTitle(study.getTitle());
if (!byTitle.isEmpty()) {
throw new NotUniqueException("title", "not unique");
}
T forUpdate = studyRepository.findOne(study.getId());
if (forUpdate == null) {
throw new NotExistException(getType());
}
if (study.getType() != null && study.getType().getId() != null) {
forUpdate.setType(studyTypeService.getById(study.getType().getId()));
}
if (study.getStatus() != null && study.getStatus().getId() != null && studyStateMachine.canTransit(forUpdate, studyStatusService.getById(study.getStatus().getId()))) {
forUpdate.setStatus(studyStatusService.getById(study.getStatus().getId()));
}
forUpdate.setTitle(study.getTitle() != null ? study.getTitle() : forUpdate.getTitle());
forUpdate.setDescription(study.getDescription() != null ? study.getDescription() : forUpdate.getDescription());
forUpdate.setStartDate(study.getStartDate() != null ? study.getStartDate() : forUpdate.getStartDate());
forUpdate.setEndDate(study.getEndDate() != null ? study.getEndDate() : forUpdate.getEndDate());
if (forUpdate.getStartDate() != null && forUpdate.getEndDate() != null && forUpdate.getStartDate().getTime() > forUpdate.getEndDate().getTime()) {
throw new ValidationException("end date before start date ");
}
forUpdate.setPrivacy(study.getPrivacy() != null ? study.getPrivacy() : forUpdate.getPrivacy());
forUpdate.setUpdated(new Date());
forUpdate.setPrivacy(study.getPrivacy() != null ? study.getPrivacy() : forUpdate.getPrivacy());
T updatedStudy = studyRepository.save(forUpdate);
// mb too frequently
solrService.indexBySolr(forUpdate);
return updatedStudy;
}
use of com.odysseusinc.arachne.portal.exception.NotExistException in project ArachneCentralAPI by OHDSI.
the class BaseStudyServiceImpl method removeDataSourceUnsecured.
@Override
public void removeDataSourceUnsecured(Long studyId, Long dataSourceId) {
Study study = studyRepository.findOne(studyId);
if (study == null) {
throw new NotExistException("study does not exist.", Study.class);
}
StudyDataSourceLink studyDataSourceLink = studyDataSourceLinkRepository.findByStudyIdAndDataSourceId(study.getId(), dataSourceId);
if (studyDataSourceLink == null) {
throw new NotExistException("studyDataSourceLink does not exist.", StudyDataSourceLink.class);
}
studyDataSourceLinkRepository.delete(studyDataSourceLink.getId());
}
Aggregations