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