use of org.akaza.openclinica.exception.OpenClinicaSystemException in project OpenClinica by OpenClinica.
the class StudySubjectEndpoint method validateRequestAndReturnStudy.
/**
* Validate the listStudySubjectsInStudy request.
*
* @param studyRef
* @return StudyBean
*/
private StudyBean validateRequestAndReturnStudy(StudyRefType studyRef) {
String studyIdentifier = studyRef == null ? null : studyRef.getIdentifier().trim();
String siteIdentifier = studyRef.getSiteRef() == null ? null : studyRef.getSiteRef().getIdentifier().trim();
if (studyIdentifier == null && siteIdentifier == null) {
throw new OpenClinicaSystemException("studySubjectEndpoint.provide_valid_study_site", "Provide a valid study/site.");
}
if (studyIdentifier != null && siteIdentifier == null) {
StudyBean study = getStudyDao().findByUniqueIdentifier(studyIdentifier);
if (study == null) {
throw new OpenClinicaSystemException("studySubjectEndpoint.invalid_study_identifier", "The study identifier you provided is not valid.");
}
StudyUserRoleBean studySur = getUserAccountDao().findRoleByUserNameAndStudyId(getUserAccount().getName(), study.getId());
if (studySur.getStatus() != Status.AVAILABLE) {
throw new OpenClinicaSystemException("studySubjectEndpoint.insufficient_permissions", "You do not have sufficient privileges to proceed with this operation.");
}
return study;
}
if (studyIdentifier != null && siteIdentifier != null) {
StudyBean study = getStudyDao().findByUniqueIdentifier(studyIdentifier);
StudyBean site = getStudyDao().findByUniqueIdentifier(siteIdentifier);
if (study == null || site == null || site.getParentStudyId() != study.getId()) {
throw new OpenClinicaSystemException("studySubjectEndpoint.invalid_study_site_identifier", "The study/site identifier you provided is not valid.");
}
StudyUserRoleBean siteSur = getUserAccountDao().findRoleByUserNameAndStudyId(getUserAccount().getName(), site.getId());
if (siteSur.getStatus() != Status.AVAILABLE) {
throw new OpenClinicaSystemException("studySubjectEndpoint.insufficient_permissions", "You do not have sufficient privileges to proceed with this operation.");
}
return site;
}
return null;
}
use of org.akaza.openclinica.exception.OpenClinicaSystemException in project OpenClinica by OpenClinica.
the class EventEndpoint method getDate.
/**
* Helper Method to resolve dates
*
* @param dateAsString
* @return
* @throws ParseException
*/
private Date getDate(String dateAsString, String hourMinuteAsString) throws ParseException {
Date d = null;
if (dateAsString != null && dateAsString.length() != 0) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
dateAsString += hourMinuteAsString == null ? " 00:00" : " " + hourMinuteAsString;
d = sdf.parse(dateAsString);
if (!sdf.format(d).equals(dateAsString)) {
throw new OpenClinicaSystemException("Date not parseable");
}
return sdf.parse(dateAsString);
} else {
return null;
}
}
use of org.akaza.openclinica.exception.OpenClinicaSystemException in project OpenClinica by OpenClinica.
the class EmailActionProcessor method sendEmail.
private void sendEmail(RuleActionBean ruleAction, UserAccountBean ub, String body, String subject) throws OpenClinicaSystemException {
logger.info("Sending email...");
try {
getEmailEngine().process(((EmailActionBean) ruleAction).getTo().trim(), EmailEngine.getAdminEmail(), subject, body);
logger.info("Sending email done..");
} catch (MessagingException me) {
logger.error("Email could not be sent");
throw new OpenClinicaSystemException(me.getMessage());
}
}
use of org.akaza.openclinica.exception.OpenClinicaSystemException in project OpenClinica by OpenClinica.
the class OpenClinicaMailSender method sendEmail.
public void sendEmail(String to, String from, String subject, String body, Boolean htmlEmail) throws OpenClinicaSystemException {
try {
MimeMessage mimeMessage = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, htmlEmail);
helper.setFrom(from);
helper.setTo(processMultipleImailAddresses(to.trim()));
helper.setSubject(subject);
helper.setText(body, true);
mailSender.send(mimeMessage);
logger.debug("Email sent successfully on {}", new Date());
} catch (MailException me) {
logger.debug("Email could not be sent on {} due to: {}", new Date(), me.toString());
throw new OpenClinicaSystemException(me.getMessage());
} catch (MessagingException e) {
logger.debug("Email could not be sent on {} due to: {}", new Date(), e.toString());
throw new OpenClinicaSystemException(e.getMessage());
}
}
use of org.akaza.openclinica.exception.OpenClinicaSystemException in project OpenClinica by OpenClinica.
the class ExpressionService method isExpressionValid.
/**
* Given a Complete Expression check business logic validity of each
* component. Will throw OpenClinicaSystemException with correct
* explanation. This might allow immediate communication of message to user
* .
*
* @param expression
*/
public void isExpressionValid(String expression) {
int length = expression.split(ESCAPED_SEPERATOR).length;
ItemBean item = null;
ItemGroupBean itemGroup = null;
CRFBean crf = null;
boolean isEventStartDateAndStatusParamExist = (expression.endsWith(STARTDATE) || expression.endsWith(STATUS));
if (length > 0 && !isEventStartDateAndStatusParamExist) {
item = getItemFromExpression(expression);
if (item == null)
throw new OpenClinicaSystemException("OCRERR_0023");
// throw new OpenClinicaSystemException("item is Invalid");
}
if (length > 1 && !isEventStartDateAndStatusParamExist) {
String itemGroupOid = getItemGroupOidFromExpression(expression);
itemGroup = getItemGroupDao().findByOid(itemGroupOid);
ArrayList<ItemGroupBean> igBean = (ArrayList<ItemGroupBean>) getItemGroupDao().findGroupsByItemID(item.getId());
if (itemGroup == null || itemGroup.getId() != igBean.get(0).getId())
throw new OpenClinicaSystemException("OCRERR_0022");
// throw new OpenClinicaSystemException("itemGroup is Invalid");
}
if (length > 2 && !isEventStartDateAndStatusParamExist) {
crf = getCRFFromExpression(expression);
if (crf == null || crf.getId() != itemGroup.getCrfId())
throw new OpenClinicaSystemException("OCRERR_0033");
// throw new OpenClinicaSystemException("CRF is Invalid");
}
if (length > 3 && !isEventStartDateAndStatusParamExist) {
StudyEventDefinitionBean studyEventDefinition = getStudyEventDefinitionFromExpression(expression);
crf = getCRFFromExpression(expression);
if (studyEventDefinition == null || crf == null)
throw new OpenClinicaSystemException("OCRERR_0034", new String[] { expression });
// throw new
// OpenClinicaSystemException("StudyEventDefinition is Invalid");
EventDefinitionCRFBean eventDefinitionCrf = getEventDefinitionCRFDao().findByStudyEventDefinitionIdAndCRFId(this.expressionWrapper.getStudyBean(), studyEventDefinition.getId(), crf.getId());
if (eventDefinitionCrf == null || eventDefinitionCrf.getId() == 0)
throw new OpenClinicaSystemException("OCRERR_0034", new String[] { expression });
// throw new
// OpenClinicaSystemException("StudyEventDefinition is Invalid");
}
if (length == 2 && isEventStartDateAndStatusParamExist) {
StudyEventDefinitionBean studyEventDefinition = getStudyEventDefinitionFromExpressionForEventScheduling(expression);
// studyEventDefinition.getOid());
if (studyEventDefinition == null)
throw new OpenClinicaSystemException("OCRERR_0034", new String[] { expression });
}
if (length != 2 && isEventStartDateAndStatusParamExist) {
throw new OpenClinicaSystemException("OCRERR_0034", new String[] { expression });
}
}
Aggregations