Search in sources :

Example 21 with OpenClinicaSystemException

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

the class ExpressionService method getItemDataBeanFromDb.

public ItemDataBean getItemDataBeanFromDb(String expression) throws OpenClinicaSystemException {
    if (isExpressionPartial(expression)) {
        throw new OpenClinicaSystemException("getItemDataBeanFromDb:We cannot get the ItemData of a PARTIAL expression : " + expression);
    }
    String studyEventId = getStudyEventDefinitionOidOrdinalFromExpression(expression);
    Integer index = getItemGroupOidOrdinalFromExpression(expression).equals("") ? 0 : Integer.valueOf(getItemGroupOidOrdinalFromExpression(expression)) - 1;
    List<ItemDataBean> itemData = getItemDataDao().findByStudyEventAndOids(Integer.valueOf(studyEventId), getItemOidFromExpression(expression), getItemGroupOidFromExpression(expression));
    ItemDataBean itemDataBean = itemData.size() > index ? itemData.get(index) : null;
    return itemDataBean;
// << tbh 04/28/2010
}
Also used : ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException)

Example 22 with OpenClinicaSystemException

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

the class ExpressionService method getValueFromDbb.

public HashMap<String, String> getValueFromDbb(String expression) throws OpenClinicaSystemException {
    HashMap<String, String> map = new HashMap<>();
    if (isExpressionPartial(expression)) {
        throw new OpenClinicaSystemException("getValueFromDb:We cannot get the Value of a PARTIAL expression : " + expression);
    }
    try {
        // Get the studyEventId from RuleSet Target so we can know which
        // StudySubject we are dealing with.
        String ruleSetExpression = expressionWrapper.getRuleSet().getTarget().getValue();
        String ruleSetExpressionStudyEventId = getStudyEventDefinitionOidOrdinalFromExpression(ruleSetExpression);
        StudyEventBean studyEvent = (StudyEventBean) getStudyEventDao().findByPK(Integer.valueOf(ruleSetExpressionStudyEventId));
        // Prepare Method arguments
        String studyEventDefinitionOid = getStudyEventDefinitionOidFromExpression(expression);
        String crfOrCrfVersionOid = getCrfOidFromExpression(expression);
        String studyEventDefinitionOrdinal = getStudyEventDefinitionOidOrdinalFromExpression(expression);
        studyEventDefinitionOrdinal = studyEventDefinitionOrdinal.equals("") ? "1" : studyEventDefinitionOrdinal;
        String studySubjectId = String.valueOf(studyEvent.getStudySubjectId());
        System.out.println("studySubjectId:  " + studySubjectId);
        logger.debug("ruleSet studyEventId  {} , studyEventDefinitionOid {} , crfOrCrfVersionOid {} , studyEventDefinitionOrdinal {} ,studySubjectId {}", new Object[] { studyEvent.getId(), studyEventDefinitionOid, crfOrCrfVersionOid, studyEventDefinitionOrdinal, studySubjectId });
        StudyEventBean studyEventofThisExpression = getStudyEventDao().findAllByStudyEventDefinitionAndCrfOidsAndOrdinal(studyEventDefinitionOid, crfOrCrfVersionOid, studyEventDefinitionOrdinal, studySubjectId);
        if (studyEvent.getId() == studyEventofThisExpression.getId())
            map.put("match", "true");
        logger.debug("studyEvent : {} , itemOid {} , itemGroupOid {}", new Object[] { studyEventofThisExpression.getId(), getItemOidFromExpression(expression), getItemGroupOidFromExpression(expression) });
        List<ItemDataBean> itemData = getItemDataDao().findByStudyEventAndOids(Integer.valueOf(studyEventofThisExpression.getId()), getItemOidFromExpression(expression), getItemGroupOidFromExpression(expression));
        expression = fixGroupOrdinal(expression, ruleSetExpression, itemData, expressionWrapper.getEventCrf());
        Integer index = getItemGroupOidOrdinalFromExpression(expression).equals("") ? 0 : Integer.valueOf(getItemGroupOidOrdinalFromExpression(expression)) - 1;
        ItemDataBean itemDataBean = itemData.get(index);
        ItemBean itemBean = (ItemBean) getItemDao().findByPK(itemDataBean.getItemId());
        String value = itemData.get(index).getValue();
        value = ifValueIsDate(itemBean, value);
        map.put("value", value);
        return map;
    } catch (Exception e) {
        return map;
    }
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) HashMap(java.util.HashMap) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException)

Example 23 with OpenClinicaSystemException

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

the class ExpressionService method getValueFromDb.

public String getValueFromDb(String expression, List<ItemDataBean> itemData) throws OpenClinicaSystemException {
    if (isExpressionPartial(expression)) {
        throw new OpenClinicaSystemException("getValueFromDb:We cannot get the Value of a PARTIAL expression : " + expression);
    }
    try {
        Integer index = getItemGroupOidOrdinalFromExpression(expression).equals("") ? 0 : Integer.valueOf(getItemGroupOidOrdinalFromExpression(expression)) - 1;
        ItemDataBean itemDataBean = itemData.get(index);
        ItemBean itemBean = (ItemBean) getItemDao().findByPK(itemDataBean.getItemId());
        String value = itemData.get(index).getValue();
        value = ifValueIsDate(itemBean, value);
        return value;
    } catch (NullPointerException npe) {
        logger.error("NullPointerException was thrown ");
        return null;
    } catch (IndexOutOfBoundsException ioobe) {
        logger.error("IndexOutOfBoundsException was thrown ");
        return null;
    }
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException)

Example 24 with OpenClinicaSystemException

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

the class InsertActionValidator 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().isInsertActionExpressionValid(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 25 with OpenClinicaSystemException

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

the class XmlSchemaValidationHelper method validateAgainstSchema.

public void validateAgainstSchema(File xmlFile, InputStream xsdFile) {
    try {
        // parse an XML document into a DOM tree
        DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
        builderFactory.setNamespaceAware(true);
        DocumentBuilder parser = builderFactory.newDocumentBuilder();
        // parser.isNamespaceAware();
        Document document = parser.parse(xmlFile);
        // create a SchemaFactory capable of understanding WXS schemas
        SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        // load a WXS schema, represented by a Schema instance
        Source schemaFile = new StreamSource(xsdFile);
        Schema schema = factory.newSchema(schemaFile);
        // create a Validator instance, which can be used to validate an
        // instance document
        Validator validator = schema.newValidator();
        // validate the DOM tree
        validator.validate(new DOMSource(document));
    } catch (FileNotFoundException ex) {
        throw new OpenClinicaSystemException("File was not found", ex.getCause());
    } catch (IOException ioe) {
        throw new OpenClinicaSystemException("IO Exception", ioe.getCause());
    } catch (SAXParseException spe) {
        //spe.printStackTrace();
        throw new OpenClinicaSystemException("Line : " + spe.getLineNumber() + " - " + spe.getMessage(), spe.getCause());
    } catch (SAXException e) {
        throw new OpenClinicaSystemException(e.getMessage(), e.getCause());
    } catch (ParserConfigurationException pce) {
        throw new OpenClinicaSystemException(pce.getMessage(), pce.getCause());
    }
}
Also used : SchemaFactory(javax.xml.validation.SchemaFactory) DOMSource(javax.xml.transform.dom.DOMSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) StreamSource(javax.xml.transform.stream.StreamSource) Schema(javax.xml.validation.Schema) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Document(org.w3c.dom.Document) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) InputSource(org.xml.sax.InputSource) DOMSource(javax.xml.transform.dom.DOMSource) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) SAXException(org.xml.sax.SAXException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) SAXParseException(org.xml.sax.SAXParseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Validator(javax.xml.validation.Validator)

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