use of org.akaza.openclinica.bean.submit.ItemBean in project OpenClinica by OpenClinica.
the class InsertActionValidator method validateValueExpressionInPropertyBean.
public void validateValueExpressionInPropertyBean(PropertyBean propertyBean, Errors e, String p) {
if (getExpressionService().isExpressionPartial(getRuleSetBean().getTarget().getValue())) {
if (getExpressionService().getExpressionSize(propertyBean.getValueExpression().getValue()).intValue() > 2) {
e.rejectValue(p + "valueExpression", "valueExpression.invalid", "Value provided for ValueExpression is Invalid");
}
try {
getExpressionService().isExpressionValid(propertyBean.getValueExpression().getValue());
} catch (OpenClinicaSystemException ose) {
e.rejectValue(p + "valueExpression", "valueExpression.invalid", "Value provided for ValueExpression is Invalid");
}
// Use ValueExression in destinationProperty to get CRF
ItemBean item = getExpressionService().getItemBeanFromExpression(propertyBean.getValueExpression().getValue());
if (item == null)
return;
CRFBean destinationPropertyValueExpressionCrf = getCrfDAO().findByItemOid(item.getOid());
// Use Target to get CRF
CRFBean targetCrf = getExpressionService().getCRFFromExpression(getRuleSetBean().getTarget().getValue());
if (targetCrf == null) {
ItemBean targetItem = getExpressionService().getItemBeanFromExpression(getRuleSetBean().getTarget().getValue());
targetCrf = getCrfDAO().findByItemOid(targetItem.getOid());
}
if (destinationPropertyValueExpressionCrf.getId() != targetCrf.getId()) {
e.rejectValue(p + "valueExpression", "valueExpression.invalid", "Value provided for ValueExpression is Invalid");
}
} else {
String valueExpression = getExpressionService().constructFullExpressionIfPartialProvided(propertyBean.getValueExpression().getValue(), getRuleSetBean().getTarget().getValue());
ItemBean item = getExpressionService().getItemBeanFromExpression(valueExpression);
if (!getExpressionService().isExpressionValid(propertyBean.getValueExpression().getValue(), getRuleSetBean(), 2) || item == null) {
e.rejectValue(p + "valueExpression", "valueExpression.invalid", "Value provided for ValueExpression is Invalid");
}
}
}
use of org.akaza.openclinica.bean.submit.ItemBean in project OpenClinica by OpenClinica.
the class RandomizeActionValidator 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().isRandomizeActionExpressionValid(propertyBean.getOid(), getRuleSetBean(), 3) || item == null) {
e.rejectValue(p + "oid", "oid.invalid", "OID: " + propertyBean.getOid() + " is Invalid.");
}
}
}
use of org.akaza.openclinica.bean.submit.ItemBean in project OpenClinica by OpenClinica.
the class ExpressionService method evaluateExpression.
public String evaluateExpression(String expression) throws OpenClinicaSystemException {
String value = null;
Map<Integer, ItemBean> itemBeansI = new HashMap<Integer, ItemBean>();
if (items != null) {
Iterator<ItemBean> iter = items.values().iterator();
while (iter.hasNext()) {
ItemBean item = iter.next();
itemBeansI.put(item.getId(), item);
}
}
if (expressionWrapper.getRuleSet() != null) {
if (checkIfExpressionIsForScheduling(expression)) {
StudyEvent studyEvent;
if (expression.endsWith(this.STARTDATE)) {
String oid = expression.substring(0, expression.indexOf(this.STARTDATE));
studyEvent = getStudyEventFromOID(oid);
if (studyEvent != null) {
logger.debug("Study Event Start Date: " + studyEvent.getDateStart().toString().substring(0, 10).trim());
return studyEvent.getDateStart().toString().substring(0, 10).trim();
} else
return "";
} else {
String oid = expression.substring(0, expression.indexOf(this.STATUS));
studyEvent = getStudyEventFromOID(oid);
if (studyEvent != null) {
logger.debug("Status: " + SubjectEventStatus.getSubjectEventStatusName(studyEvent.getSubjectEventStatusId()));
return SubjectEventStatus.getSubjectEventStatusName(studyEvent.getSubjectEventStatusId());
} else
return "";
}
}
if (isExpressionPartial(expression)) {
String fullExpression = constructFullExpressionIfPartialProvided(expression, expressionWrapper.getRuleSet().getTarget().getValue());
List<ItemDataBean> itemDatas = getItemDatas(fullExpression);
fullExpression = fixGroupOrdinal(fullExpression, expressionWrapper.getRuleSet().getTarget().getValue(), itemDatas, expressionWrapper.getEventCrf());
if (checkSyntax(fullExpression)) {
String valueFromForm = null;
if (items == null) {
valueFromForm = getValueFromForm(fullExpression);
} else {
valueFromForm = getValueFromForm(fullExpression, items);
}
String valueFromDb = null;
if (itemBeansI == null) {
valueFromDb = getValueFromDb(fullExpression, itemDatas);
} else {
valueFromDb = getValueFromDb(fullExpression, itemDatas, itemBeansI);
}
logger.debug("valueFromForm : {} , valueFromDb : {}", valueFromForm, valueFromDb);
if (valueFromForm == null && valueFromDb == null) {
throw new OpenClinicaSystemException("OCRERR_0017", new Object[] { fullExpression, expressionWrapper.getRuleSet().getTarget().getValue() });
}
/*
* if (valueFromForm != null) { // TODO: Do this if type a
* date String dateFormat =
* ResourceBundleProvider.getFormatBundle
* ().getString("date_format_string"); String dateRegexp =
* ResourceBundleProvider
* .getFormatBundle().getString("date_regexp");
* valueFromForm =
* ExpressionTreeHelper.isValidDate(valueFromForm,
* dateFormat, dateRegexp); }
*/
value = valueFromForm == null ? valueFromDb : valueFromForm;
}
} else {
// So Expression is not Partial
HashMap<String, String> map = getValueFromDbb(expression);
String valueFromDb = null;
String matchEvents = null;
String valueFromForm = null;
if (checkSyntax(expression)) {
valueFromDb = map.get("value");
matchEvents = map.get("match");
// if se_id are a match go in , otherwise nothing
if (matchEvents != null && matchEvents.equals("true")) {
if (items == null) {
valueFromForm = getValueFromForm(expression);
} else {
valueFromForm = getValueFromForm(expression, items);
}
}
logger.debug("valueFromDb : {}", valueFromDb);
value = valueFromForm == null ? valueFromDb : valueFromForm;
if (value == null) {
logger.info("The value is " + value + " for expression" + expression);
throw new OpenClinicaSystemException("OCRERR_0018", new Object[] { expression });
}
}
}
}
return value;
}
use of org.akaza.openclinica.bean.submit.ItemBean in project OpenClinica by OpenClinica.
the class CRFVersionDAO method generateDeleteQueries.
/**
* Generates all the delete queries for deleting a version
*
* @param versionId
* @param items
*/
public ArrayList generateDeleteQueries(int versionId, ArrayList items) {
ArrayList sqls = new ArrayList();
String sql = digester.getQuery("deleteScdItemMetadataByVersion") + versionId + ")";
sqls.add(sql);
sql = digester.getQuery("deleteItemMetaDataByVersion") + versionId;
sqls.add(sql);
sql = digester.getQuery("deleteSectionsByVersion") + versionId;
sqls.add(sql);
sql = digester.getQuery("deleteItemMapByVersion") + versionId;
sqls.add(sql);
sql = digester.getQuery("deleteItemGroupMetaByVersion") + versionId;
sqls.add(sql);
for (int i = 0; i < items.size(); i++) {
ItemBean item = (ItemBean) items.get(i);
sql = digester.getQuery("deleteItemsByVersion") + item.getId();
sqls.add(sql);
}
sql = digester.getQuery("deleteResponseSetByVersion") + versionId;
sqls.add(sql);
sql = digester.getQuery("delete") + versionId;
sqls.add(sql);
return sqls;
}
use of org.akaza.openclinica.bean.submit.ItemBean in project OpenClinica by OpenClinica.
the class CRFVersionDAO method findItemFromMap.
public Collection findItemFromMap(int versionId) {
this.unsetTypeExpected();
this.setTypeExpected(1, TypeNames.INT);
this.setTypeExpected(2, TypeNames.STRING);
this.setTypeExpected(3, TypeNames.INT);
HashMap variables = new HashMap();
variables.put(new Integer(1), new Integer(versionId));
String sql = digester.getQuery("findItemFromMap");
ArrayList alist = this.select(sql, variables);
ArrayList al = new ArrayList();
Iterator it = alist.iterator();
while (it.hasNext()) {
ItemBean eb = new ItemBean();
HashMap hm = (HashMap) it.next();
eb.setId(((Integer) hm.get("item_id")).intValue());
eb.setName((String) hm.get("name"));
Integer ownerId = (Integer) hm.get("owner_id");
eb.setOwnerId(ownerId.intValue());
al.add(eb);
}
return al;
}
Aggregations