Search in sources :

Example 41 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 42 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 43 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 44 with OpenClinicaSystemException

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

the class MetaDataReportBean method handleLoadCastor.

private String handleLoadCastor(RulesPostImportContainer rpic) {
    try {
        // Create Mapping
        Mapping mapping = new Mapping();
        mapping.loadMapping(getCoreResources().getURL("mappingMarshallerMetadata.xml"));
        // Create XMLContext
        XMLContext xmlContext = new XMLContext();
        xmlContext.setProperty(XMLConfiguration.NAMESPACES, "true");
        xmlContext.addMapping(mapping);
        StringWriter writer = new StringWriter();
        Marshaller marshaller = xmlContext.createMarshaller();
        // marshaller.setNamespaceMapping("castor", "http://castor.org/sample/mapping/");
        marshaller.setWriter(writer);
        marshaller.marshal(rpic);
        String result = writer.toString();
        String newResult = result.replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "");
        return newResult;
    } catch (FileNotFoundException ex) {
        throw new OpenClinicaSystemException(ex.getMessage(), ex.getCause());
    } catch (IOException ex) {
        throw new OpenClinicaSystemException(ex.getMessage(), ex.getCause());
    } catch (MarshalException e) {
        throw new OpenClinicaSystemException(e.getMessage(), e.getCause());
    } catch (ValidationException e) {
        throw new OpenClinicaSystemException(e.getMessage(), e.getCause());
    } catch (MappingException e) {
        throw new OpenClinicaSystemException(e.getMessage(), e.getCause());
    } catch (Exception e) {
        throw new OpenClinicaSystemException(e.getMessage(), e.getCause());
    }
}
Also used : Marshaller(org.exolab.castor.xml.Marshaller) MarshalException(org.exolab.castor.xml.MarshalException) ValidationException(org.exolab.castor.xml.ValidationException) StringWriter(java.io.StringWriter) XMLContext(org.exolab.castor.xml.XMLContext) FileNotFoundException(java.io.FileNotFoundException) Mapping(org.exolab.castor.mapping.Mapping) IOException(java.io.IOException) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) FileNotFoundException(java.io.FileNotFoundException) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) MappingException(org.exolab.castor.mapping.MappingException) ValidationException(org.exolab.castor.xml.ValidationException) MarshalException(org.exolab.castor.xml.MarshalException) IOException(java.io.IOException) MappingException(org.exolab.castor.mapping.MappingException)

Example 45 with OpenClinicaSystemException

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

the class FileUploadHelper method getFiles.

@SuppressWarnings("unchecked")
private List<File> getFiles(HttpServletRequest request, ServletContext context, String dirToSaveUploadedFileIn) {
    List<File> files = new ArrayList<File>();
    // FileCleaningTracker fileCleaningTracker =
    // FileCleanerCleanup.getFileCleaningTracker(context);
    // Create a factory for disk-based file items
    DiskFileItemFactory factory = new DiskFileItemFactory();
    // Create a new file upload handler
    ServletFileUpload upload = new ServletFileUpload(factory);
    upload.setFileSizeMax(getFileProperties().getFileSizeMax());
    try {
        // Parse the request
        List<FileItem> items = upload.parseRequest(request);
        // Process the uploaded items
        Iterator<FileItem> iter = items.iterator();
        while (iter.hasNext()) {
            FileItem item = iter.next();
            if (item.isFormField()) {
                request.setAttribute(item.getFieldName(), item.getString());
            // DO NOTHING , THIS SHOULD NOT BE Handled here
            } else {
                getFileProperties().isValidExtension(item.getName());
                files.add(processUploadedFile(item, dirToSaveUploadedFileIn));
            }
        }
        return files;
    } catch (FileSizeLimitExceededException slee) {
        throw new OpenClinicaSystemException("exceeds_permitted_file_size", new Object[] { String.valueOf(getFileProperties().getFileSizeMaxInMb()) }, slee.getMessage());
    } catch (FileUploadException fue) {
        throw new OpenClinicaSystemException("file_upload_error_occured", new Object[] { fue.getMessage() }, fue.getMessage());
    }
}
Also used : FileItem(org.apache.commons.fileupload.FileItem) ServletFileUpload(org.apache.commons.fileupload.servlet.ServletFileUpload) ArrayList(java.util.ArrayList) FileSizeLimitExceededException(org.apache.commons.fileupload.FileUploadBase.FileSizeLimitExceededException) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) File(java.io.File) DiskFileItemFactory(org.apache.commons.fileupload.disk.DiskFileItemFactory) FileUploadException(org.apache.commons.fileupload.FileUploadException)

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