Search in sources :

Example 36 with OpenClinicaSystemException

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;
}
Also used : StudyUserRoleBean(org.akaza.openclinica.bean.login.StudyUserRoleBean) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException)

Example 37 with OpenClinicaSystemException

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;
    }
}
Also used : OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 38 with OpenClinicaSystemException

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());
    }
}
Also used : MessagingException(javax.mail.MessagingException) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException)

Example 39 with OpenClinicaSystemException

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());
    }
}
Also used : MimeMessage(javax.mail.internet.MimeMessage) MessagingException(javax.mail.MessagingException) MailException(org.springframework.mail.MailException) MimeMessageHelper(org.springframework.mail.javamail.MimeMessageHelper) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) Date(java.util.Date)

Example 40 with OpenClinicaSystemException

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 });
    }
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) ItemGroupBean(org.akaza.openclinica.bean.submit.ItemGroupBean) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean)

Aggregations

OpenClinicaSystemException (org.akaza.openclinica.exception.OpenClinicaSystemException)76 IOException (java.io.IOException)19 File (java.io.File)13 HashMap (java.util.HashMap)11 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)11 OpenClinicaExpressionParser (org.akaza.openclinica.logic.expressionTree.OpenClinicaExpressionParser)11 ArrayList (java.util.ArrayList)10 ItemBean (org.akaza.openclinica.bean.submit.ItemBean)10 FileNotFoundException (java.io.FileNotFoundException)8 MessageFormat (java.text.MessageFormat)8 RuleSetBean (org.akaza.openclinica.domain.rule.RuleSetBean)7 RuleActionBean (org.akaza.openclinica.domain.rule.action.RuleActionBean)7 ExpressionBean (org.akaza.openclinica.domain.rule.expression.ExpressionBean)7 ExpressionObjectWrapper (org.akaza.openclinica.domain.rule.expression.ExpressionObjectWrapper)7 FileOutputStream (java.io.FileOutputStream)6 Date (java.util.Date)6 CRFBean (org.akaza.openclinica.bean.admin.CRFBean)6 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)6 RuleBean (org.akaza.openclinica.domain.rule.RuleBean)6 RuleSetRuleBean (org.akaza.openclinica.domain.rule.RuleSetRuleBean)6