Search in sources :

Example 71 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 72 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)

Example 73 with OpenClinicaSystemException

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

the class FileUploadHelper method processUploadedFile.

private File processUploadedFile(FileItem item, String dirToSaveUploadedFileIn) {
    dirToSaveUploadedFileIn = dirToSaveUploadedFileIn == null ? System.getProperty("java.io.tmpdir") : dirToSaveUploadedFileIn;
    String fileName = item.getName();
    // Some browsers IE 6,7 getName returns the whole path
    int startIndex = fileName.lastIndexOf('\\');
    if (startIndex != -1) {
        fileName = fileName.substring(startIndex + 1, fileName.length());
    }
    File uploadedFile = new File(dirToSaveUploadedFileIn + File.separator + fileName);
    if (fileRenamePolicy != null) {
        try {
            uploadedFile = fileRenamePolicy.rename(uploadedFile, item.getInputStream());
        } catch (IOException e) {
            throw new OpenClinicaSystemException(e.getMessage());
        }
    }
    try {
        item.write(uploadedFile);
    } catch (Exception e) {
        throw new OpenClinicaSystemException(e.getMessage());
    }
    return uploadedFile;
}
Also used : IOException(java.io.IOException) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) File(java.io.File) IOException(java.io.IOException) FileUploadException(org.apache.commons.fileupload.FileUploadException) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) FileSizeLimitExceededException(org.apache.commons.fileupload.FileUploadBase.FileSizeLimitExceededException)

Example 74 with OpenClinicaSystemException

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

the class FileProperties method isValidExtension.

public void isValidExtension(String uploadedFileExtension) {
    uploadedFileExtension = uploadedFileExtension.lastIndexOf(".") == -1 ? " " : uploadedFileExtension.substring(uploadedFileExtension.lastIndexOf(".") + 1, uploadedFileExtension.length()).trim().toUpperCase();
    ArrayList<String> extensionsList = new ArrayList<String>();
    Collections.addAll(extensionsList, extensions.trim().toUpperCase().split(","));
    if (extensions.trim().length() == 0) {
        // if no list is defined
        if (extensionSettings.equals(ExtensionSettings.VALID)) {
            return;
        } else {
            throw new OpenClinicaSystemException("prohibited_file_extensions", new Object[] { "ALL" });
        }
    }
    if (extensionSettings.equals(ExtensionSettings.VALID)) {
        // if the list is flagged as valid list
        if (// if valid list does not contain extension
        !extensionsList.contains(uploadedFileExtension))
            throw new OpenClinicaSystemException("permitted_file_extensions", new Object[] { extensions });
    } else {
        // if the list is flagged as prohibited list
        if (// if deny list contains extension
        extensionsList.contains(uploadedFileExtension))
            throw new OpenClinicaSystemException("prohibited_file_extensions", new Object[] { extensions });
    }
}
Also used : ArrayList(java.util.ArrayList) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException)

Example 75 with OpenClinicaSystemException

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

the class RuleSetBulkRuleRunner method runRulesBulkFromRuleSetScreen.

public List<RuleSetBasedViewContainer> runRulesBulkFromRuleSetScreen(List<RuleSetBean> ruleSets, ExecutionMode executionMode, StudyBean currentStudy, HashMap<String, String> variableAndValue, UserAccountBean ub) {
    if (variableAndValue == null || variableAndValue.isEmpty()) {
        logger.warn("You must be executing Rules in Batch");
        variableAndValue = new HashMap<String, String>();
    }
    List<RuleSetBasedViewContainer> ruleSetBasedView = new ArrayList<RuleSetBasedViewContainer>();
    HashMap<String, ArrayList<RuleActionContainer>> toBeExecuted = new HashMap<String, ArrayList<RuleActionContainer>>();
    for (RuleSetBean ruleSet : ruleSets) {
        String key = getExpressionService().getItemOid(ruleSet.getOriginalTarget().getValue());
        List<RuleActionContainer> allActionContainerListBasedOnRuleExecutionResult = null;
        if (toBeExecuted.containsKey(key)) {
            allActionContainerListBasedOnRuleExecutionResult = toBeExecuted.get(key);
        } else {
            toBeExecuted.put(key, new ArrayList<RuleActionContainer>());
            allActionContainerListBasedOnRuleExecutionResult = toBeExecuted.get(key);
        }
        ItemDataBean itemData = null;
        for (ExpressionBean expressionBean : ruleSet.getExpressions()) {
            ruleSet.setTarget(expressionBean);
            System.out.println("tg expression:" + ruleSet.getTarget().getValue());
            for (RuleSetRuleBean ruleSetRule : ruleSet.getRuleSetRules()) {
                String result = null;
                RuleBean rule = ruleSetRule.getRuleBean();
                ExpressionObjectWrapper eow = new ExpressionObjectWrapper(ds, currentStudy, rule.getExpression(), ruleSet, variableAndValue);
                try {
                    OpenClinicaExpressionParser oep = new OpenClinicaExpressionParser(eow);
                    result = (String) oep.parseAndEvaluateExpression(rule.getExpression().getValue());
                    itemData = getExpressionService().getItemDataBeanFromDb(ruleSet.getTarget().getValue());
                    System.out.println("The result: " + result);
                    List<RuleActionBean> actionListBasedOnRuleExecutionResult = ruleSetRule.getActions(result, Phase.BATCH);
                    if (itemData != null) {
                        Iterator<RuleActionBean> itr = actionListBasedOnRuleExecutionResult.iterator();
                        while (itr.hasNext()) {
                            RuleActionBean ruleActionBean = itr.next();
                            RuleActionRunLogBean ruleActionRunLog = new RuleActionRunLogBean(ruleActionBean.getActionType(), itemData, itemData.getValue(), ruleSetRule.getRuleBean().getOid());
                            if (getRuleActionRunLogDao().findCountByRuleActionRunLogBean(ruleActionRunLog) > 0) {
                                itr.remove();
                            }
                        }
                    }
                    for (RuleActionBean ruleActionBean : actionListBasedOnRuleExecutionResult) {
                        RuleActionContainer ruleActionContainer = new RuleActionContainer(ruleActionBean, expressionBean, itemData, ruleSet);
                        allActionContainerListBasedOnRuleExecutionResult.add(ruleActionContainer);
                    }
                    logger.info("RuleSet with target  : {} , Ran Rule : {}  The Result was : {} , Based on that {} action will be executed in {} mode. ", new Object[] { ruleSet.getTarget().getValue(), rule.getName(), result, actionListBasedOnRuleExecutionResult.size(), executionMode.name() });
                } catch (OpenClinicaSystemException osa) {
                // TODO: report something useful
                }
            }
        }
    }
    for (Map.Entry<String, ArrayList<RuleActionContainer>> entry : toBeExecuted.entrySet()) {
        // Sort the list of actions
        Collections.sort(entry.getValue(), new RuleActionContainerComparator());
        for (RuleActionContainer ruleActionContainer : entry.getValue()) {
            ruleActionContainer.getRuleSetBean().setTarget(ruleActionContainer.getExpressionBean());
            ruleActionContainer.getRuleAction().setCuratedMessage(curateMessage(ruleActionContainer.getRuleAction(), ruleActionContainer.getRuleAction().getRuleSetRule()));
            ActionProcessor ap = ActionProcessorFacade.getActionProcessor(ruleActionContainer.getRuleAction().getActionType(), ds, getMailSender(), dynamicsMetadataService, ruleActionContainer.getRuleSetBean(), getRuleActionRunLogDao(), ruleActionContainer.getRuleAction().getRuleSetRule());
            RuleActionBean rab = ap.execute(RuleRunnerMode.RULSET_BULK, executionMode, ruleActionContainer.getRuleAction(), ruleActionContainer.getItemDataBean(), DiscrepancyNoteBean.ITEM_DATA, currentStudy, ub, prepareEmailContents(ruleActionContainer.getRuleSetBean(), ruleActionContainer.getRuleAction().getRuleSetRule(), currentStudy, ruleActionContainer.getRuleAction()));
            System.out.println(" Action Trigger: " + ap.toString());
            if (rab != null) {
                ruleSetBasedView = populateForRuleSetBasedView(ruleSetBasedView, ruleActionContainer.getRuleSetBean(), ruleActionContainer.getRuleAction().getRuleSetRule().getRuleBean(), ruleActionContainer.getRuleAction().getExpressionEvaluatesTo().toString(), ruleActionContainer.getRuleAction());
            }
        }
    }
    return ruleSetBasedView;
}
Also used : RuleActionBean(org.akaza.openclinica.domain.rule.action.RuleActionBean) RuleSetBasedViewContainer(org.akaza.openclinica.domain.rule.RuleSetBasedViewContainer) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) OpenClinicaExpressionParser(org.akaza.openclinica.logic.expressionTree.OpenClinicaExpressionParser) RuleActionRunLogBean(org.akaza.openclinica.domain.rule.action.RuleActionRunLogBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) ExpressionBean(org.akaza.openclinica.domain.rule.expression.ExpressionBean) ExpressionObjectWrapper(org.akaza.openclinica.domain.rule.expression.ExpressionObjectWrapper) ActionProcessor(org.akaza.openclinica.domain.rule.action.ActionProcessor) HashMap(java.util.HashMap) Map(java.util.Map) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean) RuleBean(org.akaza.openclinica.domain.rule.RuleBean) RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean)

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