Search in sources :

Example 66 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 {
        MimeMessage mimeMessage = mailSender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(mimeMessage);
        helper.setFrom(EmailEngine.getAdminEmail());
        helper.setTo(processMultipleImailAddresses(((EmailActionBean) ruleAction).getTo().trim()));
        helper.setSubject(subject);
        helper.setText(body);
        mailSender.send(mimeMessage);
        System.out.println("Sending Email thru Email Action");
        logger.debug("Email sent successfully on {}", new Date());
    } catch (MailException me) {
        logger.error("Email could not be sent");
        throw new OpenClinicaSystemException(me.getMessage());
    } catch (MessagingException me) {
        logger.error("Email could not be sent");
        throw new OpenClinicaSystemException(me.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 67 with OpenClinicaSystemException

use of org.akaza.openclinica.exception.OpenClinicaSystemException in project OpenClinica by OpenClinica.

the class NotificationActionProcessor method sendEmail.

private void sendEmail(RuleActionBean ruleAction, ParticipantDTO pDTO) throws OpenClinicaSystemException {
    logger.info("Sending email...");
    try {
        MimeMessage mimeMessage = mailSender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(mimeMessage);
        helper.setFrom(EmailEngine.getAdminEmail());
        helper.setTo(pDTO.getEmailAccount());
        helper.setSubject(pDTO.getEmailSubject());
        helper.setText(pDTO.getMessage());
        mailSender.send(mimeMessage);
        logger.debug("Email sent successfully on {}", new Date());
    } catch (MailException me) {
        logger.error("Email could not be sent");
        throw new OpenClinicaSystemException(me.getMessage());
    } catch (MessagingException me) {
        logger.error("Email could not be sent");
        throw new OpenClinicaSystemException(me.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 68 with OpenClinicaSystemException

use of org.akaza.openclinica.exception.OpenClinicaSystemException in project OpenClinica by OpenClinica.

the class InsertActionValidator method validateValueExpressionInPropertyBean.

public void validateValueExpressionInPropertyBean(PropertyBean propertyBean, Errors e, String p) {
    if (getExpressionService().isExpressionPartial(getRuleSetBean().getTarget().getValue())) {
        if (getExpressionService().getExpressionSize(propertyBean.getValueExpression().getValue()).intValue() > 2) {
            e.rejectValue(p + "valueExpression", "valueExpression.invalid", "Value provided for ValueExpression is Invalid");
        }
        try {
            getExpressionService().isExpressionValid(propertyBean.getValueExpression().getValue());
        } catch (OpenClinicaSystemException ose) {
            e.rejectValue(p + "valueExpression", "valueExpression.invalid", "Value provided for ValueExpression is Invalid");
        }
        // Use ValueExression in destinationProperty to get CRF
        ItemBean item = getExpressionService().getItemBeanFromExpression(propertyBean.getValueExpression().getValue());
        if (item == null)
            return;
        CRFBean destinationPropertyValueExpressionCrf = getCrfDAO().findByItemOid(item.getOid());
        // Use Target to get CRF
        CRFBean targetCrf = getExpressionService().getCRFFromExpression(getRuleSetBean().getTarget().getValue());
        if (targetCrf == null) {
            ItemBean targetItem = getExpressionService().getItemBeanFromExpression(getRuleSetBean().getTarget().getValue());
            targetCrf = getCrfDAO().findByItemOid(targetItem.getOid());
        }
        if (destinationPropertyValueExpressionCrf.getId() != targetCrf.getId()) {
            e.rejectValue(p + "valueExpression", "valueExpression.invalid", "Value provided for ValueExpression is Invalid");
        }
    } else {
        String valueExpression = getExpressionService().constructFullExpressionIfPartialProvided(propertyBean.getValueExpression().getValue(), getRuleSetBean().getTarget().getValue());
        ItemBean item = getExpressionService().getItemBeanFromExpression(valueExpression);
        if (!getExpressionService().isExpressionValid(propertyBean.getValueExpression().getValue(), getRuleSetBean(), 2) || item == null) {
            e.rejectValue(p + "valueExpression", "valueExpression.invalid", "Value provided for ValueExpression is Invalid");
        }
    }
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)

Example 69 with OpenClinicaSystemException

use of org.akaza.openclinica.exception.OpenClinicaSystemException in project OpenClinica by OpenClinica.

the class RandomizeActionValidator method validateOidInPropertyBean.

public void validateOidInPropertyBean(PropertyBean propertyBean, Errors e, String p) {
    if (getExpressionService().isExpressionPartial(getRuleSetBean().getTarget().getValue())) {
        if (getExpressionService().getExpressionSize(propertyBean.getOid()).intValue() > 3) {
            e.rejectValue(p + "oid", "oid.invalid", "OID: " + propertyBean.getOid() + " is Invalid.");
        }
        try {
            getExpressionService().isExpressionValid(propertyBean.getOid());
        } catch (OpenClinicaSystemException ose) {
            e.rejectValue(p + "oid", "oid.invalid", "OID: " + propertyBean.getOid() + " is Invalid.");
        }
        // Use OID in destinationProperty to get CRF
        CRFBean destinationPropertyOidCrf = getExpressionService().getCRFFromExpression(propertyBean.getOid());
        if (destinationPropertyOidCrf == null) {
            ItemBean item = getExpressionService().getItemBeanFromExpression(propertyBean.getOid());
            destinationPropertyOidCrf = getCrfDAO().findByItemOid(item.getOid());
        }
        // Use Target get CRF
        CRFBean targetCrf = getExpressionService().getCRFFromExpression(getRuleSetBean().getTarget().getValue());
        if (targetCrf == null) {
            ItemBean item = getExpressionService().getItemBeanFromExpression(getRuleSetBean().getTarget().getValue());
            targetCrf = getCrfDAO().findByItemOid(item.getOid());
        }
        // Get All event definitions the selected CRF belongs to
        List<StudyEventDefinitionBean> destinationPropertyStudyEventDefinitions = getStudyEventDefinitionDAO().findAllByCrf(destinationPropertyOidCrf);
        List<StudyEventDefinitionBean> targetStudyEventDefinitions = getStudyEventDefinitionDAO().findAllByCrf(targetCrf);
        Collection intersection = CollectionUtils.intersection(destinationPropertyStudyEventDefinitions, targetStudyEventDefinitions);
        if (intersection.size() == 0) {
            e.rejectValue(p + "oid", "oid.invalid", "OID: " + propertyBean.getOid() + " is Invalid.");
        }
    } else {
        String expression = getExpressionService().constructFullExpressionIfPartialProvided(propertyBean.getOid(), getRuleSetBean().getTarget().getValue());
        ItemBean item = getExpressionService().getItemBeanFromExpression(expression);
        if (!getExpressionService().isRandomizeActionExpressionValid(propertyBean.getOid(), getRuleSetBean(), 3) || item == null) {
            e.rejectValue(p + "oid", "oid.invalid", "OID: " + propertyBean.getOid() + " is Invalid.");
        }
    }
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) Collection(java.util.Collection) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)

Example 70 with OpenClinicaSystemException

use of org.akaza.openclinica.exception.OpenClinicaSystemException in project OpenClinica by OpenClinica.

the class ExpressionService method evaluateExpression.

public String evaluateExpression(String expression) throws OpenClinicaSystemException {
    String value = null;
    Map<Integer, ItemBean> itemBeansI = new HashMap<Integer, ItemBean>();
    if (items != null) {
        Iterator<ItemBean> iter = items.values().iterator();
        while (iter.hasNext()) {
            ItemBean item = iter.next();
            itemBeansI.put(item.getId(), item);
        }
    }
    if (expressionWrapper.getRuleSet() != null) {
        if (checkIfExpressionIsForScheduling(expression)) {
            StudyEvent studyEvent;
            if (expression.endsWith(this.STARTDATE)) {
                String oid = expression.substring(0, expression.indexOf(this.STARTDATE));
                studyEvent = getStudyEventFromOID(oid);
                if (studyEvent != null) {
                    logger.debug("Study Event Start Date: " + studyEvent.getDateStart().toString().substring(0, 10).trim());
                    return studyEvent.getDateStart().toString().substring(0, 10).trim();
                } else
                    return "";
            } else {
                String oid = expression.substring(0, expression.indexOf(this.STATUS));
                studyEvent = getStudyEventFromOID(oid);
                if (studyEvent != null) {
                    logger.debug("Status: " + SubjectEventStatus.getSubjectEventStatusName(studyEvent.getSubjectEventStatusId()));
                    return SubjectEventStatus.getSubjectEventStatusName(studyEvent.getSubjectEventStatusId());
                } else
                    return "";
            }
        }
        if (isExpressionPartial(expression)) {
            String fullExpression = constructFullExpressionIfPartialProvided(expression, expressionWrapper.getRuleSet().getTarget().getValue());
            List<ItemDataBean> itemDatas = getItemDatas(fullExpression);
            fullExpression = fixGroupOrdinal(fullExpression, expressionWrapper.getRuleSet().getTarget().getValue(), itemDatas, expressionWrapper.getEventCrf());
            if (checkSyntax(fullExpression)) {
                String valueFromForm = null;
                if (items == null) {
                    valueFromForm = getValueFromForm(fullExpression);
                } else {
                    valueFromForm = getValueFromForm(fullExpression, items);
                }
                String valueFromDb = null;
                if (itemBeansI == null) {
                    valueFromDb = getValueFromDb(fullExpression, itemDatas);
                } else {
                    valueFromDb = getValueFromDb(fullExpression, itemDatas, itemBeansI);
                }
                logger.debug("valueFromForm : {} , valueFromDb : {}", valueFromForm, valueFromDb);
                if (valueFromForm == null && valueFromDb == null) {
                    throw new OpenClinicaSystemException("OCRERR_0017", new Object[] { fullExpression, expressionWrapper.getRuleSet().getTarget().getValue() });
                }
                /*
                     * if (valueFromForm != null) { // TODO: Do this if type a
                     * date String dateFormat =
                     * ResourceBundleProvider.getFormatBundle
                     * ().getString("date_format_string"); String dateRegexp =
                     * ResourceBundleProvider
                     * .getFormatBundle().getString("date_regexp");
                     * valueFromForm =
                     * ExpressionTreeHelper.isValidDate(valueFromForm,
                     * dateFormat, dateRegexp); }
                     */
                value = valueFromForm == null ? valueFromDb : valueFromForm;
            }
        } else {
            // So Expression is not Partial
            HashMap<String, String> map = getValueFromDbb(expression);
            String valueFromDb = null;
            String matchEvents = null;
            String valueFromForm = null;
            if (checkSyntax(expression)) {
                valueFromDb = map.get("value");
                matchEvents = map.get("match");
                // if se_id are a match go in , otherwise nothing
                if (matchEvents != null && matchEvents.equals("true")) {
                    if (items == null) {
                        valueFromForm = getValueFromForm(expression);
                    } else {
                        valueFromForm = getValueFromForm(expression, items);
                    }
                }
                logger.debug("valueFromDb : {}", valueFromDb);
                value = valueFromForm == null ? valueFromDb : valueFromForm;
                if (value == null) {
                    logger.info("The value is " + value + "  for expression" + expression);
                    throw new OpenClinicaSystemException("OCRERR_0018", new Object[] { expression });
                }
            }
        }
    }
    return value;
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) HashMap(java.util.HashMap) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) StudyEvent(org.akaza.openclinica.domain.datamap.StudyEvent) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException)

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