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());
}
}
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());
}
}
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;
}
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 });
}
}
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;
}
Aggregations