Search in sources :

Example 46 with OpenClinicaSystemException

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

the class ExpressionService method getValueFromDb.

private String getValueFromDb(String expression, List<ItemDataBean> itemData, Map<Integer, ItemBean> itemBeans) 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);
        String value = itemData.get(index).getValue();
        if (itemBeans.containsKey(itemDataBean.getItemId())) {
            value = ifValueIsDate(itemBeans.get(itemDataBean.getItemId()), 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 : ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException)

Example 47 with OpenClinicaSystemException

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

the class ExpressionService method getEventDefinitionCRF.

public EventDefinitionCRFBean getEventDefinitionCRF(String expression) {
    if (expression.split(ESCAPED_SEPERATOR).length < 4) {
        return null;
    }
    StudyEventDefinitionBean studyEventDefinition = getStudyEventDefinitionFromExpression(expression);
    CRFBean crf = getCRFFromExpression(expression);
    if (studyEventDefinition == null || crf == null)
        throw new OpenClinicaSystemException("OCRERR_0020");
    return getEventDefinitionCRFDao().findByStudyEventDefinitionIdAndCRFId(this.expressionWrapper.getStudyBean(), studyEventDefinition.getId(), crf.getId());
}
Also used : StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean)

Example 48 with OpenClinicaSystemException

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

the class SpringServletAccess method getPropertiesDir.

public static String getPropertiesDir(ServletContext servletContext) {
    String resource = "properties/placeholder.properties";
    ServletContextResource scr = (ServletContextResource) getApplicationContext(servletContext).getResource(resource);
    String absolutePath = null;
    try {
        absolutePath = scr.getFile().getAbsolutePath();
    } catch (IOException e) {
        throw new OpenClinicaSystemException(e.getMessage(), e.fillInStackTrace());
    }
    absolutePath = absolutePath.replaceAll("placeholder.properties", "");
    return absolutePath;
}
Also used : ServletContextResource(org.springframework.web.context.support.ServletContextResource) IOException(java.io.IOException) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException)

Example 49 with OpenClinicaSystemException

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

the class CoreResources method copyFiles.

/**
     * @deprecated. ByteArrayInputStream keeps the whole file in memory needlessly. Use Commons IO's
     *              {@link IOUtils#copy(java.io.InputStream, java.io.OutputStream)} instead.
     */
@Deprecated
private void copyFiles(ByteArrayInputStream fis, File dest) {
    FileOutputStream fos = null;
    // Buffer 4K at a time (you can change this).
    byte[] buffer = new byte[512];
    int bytesRead;
    logger.debug("fis?" + fis);
    try {
        fos = new FileOutputStream(dest);
        while ((bytesRead = fis.read(buffer)) >= 0) {
            fos.write(buffer, 0, bytesRead);
        }
    } catch (IOException ioe) {
        // error while copying files
        OpenClinicaSystemException oe = new OpenClinicaSystemException("Unable to copy file: " + fis + "to" + dest.getAbsolutePath() + "." + dest.getAbsolutePath() + ".");
        oe.initCause(ioe);
        oe.setStackTrace(ioe.getStackTrace());
        throw oe;
    } finally {
        // Ensure that the files are closed (if they were open).
        if (fis != null) {
            try {
                fis.close();
            } catch (IOException ioe) {
                OpenClinicaSystemException oe = new OpenClinicaSystemException("Unable to copy file: " + fis + "to" + dest.getAbsolutePath() + "." + dest.getAbsolutePath() + ".");
                oe.initCause(ioe);
                oe.setStackTrace(ioe.getStackTrace());
                logger.debug(ioe.getMessage());
                throw oe;
            }
        }
        if (fos != null) {
            try {
                fos.close();
            } catch (IOException ioe) {
                OpenClinicaSystemException oe = new OpenClinicaSystemException("Unable to copy file: " + fis + "to" + dest.getAbsolutePath() + "." + dest.getAbsolutePath() + ".");
                oe.initCause(ioe);
                oe.setStackTrace(ioe.getStackTrace());
                logger.debug(ioe.getMessage());
                throw oe;
            }
        }
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException)

Example 50 with OpenClinicaSystemException

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

the class CoreResources method setODM_MAPPING_DIR.

/**
     * @pgawade 18-April-2011 - Fix for issue 8394 Method to set the absolute file path value to point to "odm_mapping"
     *          in resources. cd_odm_mapping.xml file used by Castor API during CRF data import will be copied to this
     *          location during application initialization
     */
public void setODM_MAPPING_DIR() {
    String resource = "classpath:datainfo.properties";
    Resource scr = resourceLoader.getResource(resource);
    String absolutePath = null;
    try {
        absolutePath = scr.getFile().getAbsolutePath();
        ODM_MAPPING_DIR = getField("filePath");
    // System.out.println("ODM_MAPPING_DIR: " + ODM_MAPPING_DIR);
    } catch (IOException e) {
        throw new OpenClinicaSystemException(e.getMessage(), e.fillInStackTrace());
    }
}
Also used : Resource(org.springframework.core.io.Resource) IOException(java.io.IOException) 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