use of com.odysseusinc.arachne.portal.exception.NotUniqueException 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.NotUniqueException in project ArachneCentralAPI by OHDSI.
the class BaseStudyServiceImpl method create.
@Override
public T create(IUser owner, T study) throws NotUniqueException, NotExistException {
List<T> studies = studyRepository.findByTitle(study.getTitle());
if (!studies.isEmpty()) {
throw new NotUniqueException("title", "not unique");
}
Date date = new Date();
study.setCreated(date);
study.setUpdated(date);
Date startDate = new Date(System.currentTimeMillis());
study.setStartDate(startDate);
study.setType(studyTypeService.getById(study.getType().getId()));
study.setStatus(studyStatusService.findByName("Initiate"));
study.setTenant(owner.getActiveTenant());
if (study.getPrivacy() == null) {
study.setPrivacy(true);
}
T savedStudy = studyRepository.save(study);
solrService.indexBySolr(study);
// Set Lead of the Study
addDefaultLead(savedStudy, owner);
return savedStudy;
}
use of com.odysseusinc.arachne.portal.exception.NotUniqueException 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.NotUniqueException in project ArachneCentralAPI by OHDSI.
the class BaseUserServiceImpl method create.
@Override
public U create(@NotNull final U user) throws NotUniqueException, NotExistException, PasswordValidationException {
user.setUsername(user.getEmail());
if (Objects.isNull(user.getEnabled())) {
user.setEnabled(userEnableDefault);
}
Date date = new Date();
user.setCreated(date);
user.setUpdated(date);
user.setLastPasswordReset(date);
user.setProfessionalType(professionalTypeService.getById(user.getProfessionalType().getId()));
String password = user.getPassword();
final String username = user.getUsername();
final String firstName = user.getFirstname();
final String lastName = user.getLastname();
final String middleName = user.getMiddlename();
validatePassword(username, firstName, lastName, middleName, password);
user.setPassword(passwordEncoder.encode(password));
user.setTenants(tenantService.getDefault());
if (user.getTenants().size() > 0) {
user.setActiveTenant(user.getTenants().iterator().next());
}
// The existing user check should come last:
// it is muted in public registration form, so we need to show other errors ahead
U byEmail = getByUnverifiedEmail(user.getEmail());
if (byEmail != null) {
throw new NotUniqueException("email", messageSource.getMessage("validation.email.already.used", null, null));
}
return userRepository.save(user);
}
use of com.odysseusinc.arachne.portal.exception.NotUniqueException in project ArachneCentralAPI by OHDSI.
the class StudyTypeController method create.
@ApiOperation(value = "Register new study type.", hidden = true)
@RequestMapping(value = "/api/v1/admin/study-types", method = RequestMethod.POST)
public JsonResult create(@RequestBody @Valid CreateStudyTypeDTO studyTypeDTO, BindingResult binding) {
JsonResult result;
if (binding.hasErrors()) {
result = new JsonResult<>(JsonResult.ErrorCode.VALIDATION_ERROR);
for (FieldError fieldError : binding.getFieldErrors()) {
result.getValidatorErrors().put(fieldError.getField(), fieldError.getDefaultMessage());
}
} else {
try {
StudyType studyType = conversionService.convert(studyTypeDTO, StudyType.class);
studyType = studyTypeService.create(studyType);
result = new JsonResult<>(JsonResult.ErrorCode.NO_ERROR);
result.setResult(studyType);
} catch (ConverterNotFoundException ex) {
log.error(ex.getMessage(), ex);
result = new JsonResult<>(JsonResult.ErrorCode.SYSTEM_ERROR);
result.setErrorMessage(ex.getMessage());
} catch (NotUniqueException ex) {
log.error(ex.getMessage(), ex);
result = new JsonResult<>(JsonResult.ErrorCode.VALIDATION_ERROR);
result.getValidatorErrors().put(ex.getField(), ex.getMessage());
result.setErrorMessage(ex.getMessage());
} catch (Exception ex) {
log.error(ex.getMessage(), ex);
result = new JsonResult<>(JsonResult.ErrorCode.SYSTEM_ERROR);
result.setErrorMessage(ex.getMessage());
}
}
return result;
}
Aggregations