use of org.akaza.openclinica.bean.submit.ItemDataBean in project OpenClinica by OpenClinica.
the class DoubleDataEntryServlet method validateDisplayItemBean.
@Override
protected DisplayItemBean validateDisplayItemBean(DiscrepancyValidator v, DisplayItemBean dib, String inputName, HttpServletRequest request) {
org.akaza.openclinica.bean.core.ResponseType rt = dib.getMetadata().getResponseSet().getResponseType();
HttpSession session = request.getSession();
EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
boolean isSingleItem = false;
if (StringUtil.isBlank(inputName)) {
// for single items
inputName = getInputName(dib);
isSingleItem = true;
}
// we only give warning to user if data entered in DDE is different from
// IDE when the first
// time user hits 'save'
int keyId = ecb.getId();
Integer validationCount = (Integer) session.getAttribute(COUNT_VALIDATE + keyId);
// @pgawade 12-Aug-2011 issue 10601:
// 1. Moved the call to loadFormValue method setting values
// from form here. It was at the end
// of this method before that is after validations and so an extra
// validation for checking value entered
// against the data type was getting implemented for non-repeating group
// items.
// 2. Copying the form data into new object for non repeating items to
// pass to validation
// for matching IDE and DDE values. Id same reference is used, the way
// code here was written, it affetcs
// the value used in validation of data entered in DDE against the
// related data type
ItemDataBean valueToCompareTmp = dib.getData();
ItemDataBean valueToCompare = copyItemDataBean(valueToCompareTmp);
if (!isSingleItem) {
valueToCompare = dib.getDbData();
}
// see formGroups = loadFormValueForItemGroup(digb,digbs,formGroups);
if (isSingleItem) {
dib = loadFormValue(dib, request);
}
// was dib.getData()
boolean showOriginalItem = getItemMetadataService().isShown(dib.getItem().getId(), ecb, valueToCompare);
boolean showItem = dib.getMetadata().isShowItem();
if (!showItem && dib.getScdData().getScdItemMetadataBean().getScdItemFormMetadataId() > 0) {
showItem = true;
}
//.isShown(dib.getItem().getId(), ecb, dib.getDbData());// where is the set db data?
boolean showDuplicateItem = getItemMetadataService().hasPassedDDE(dib.getMetadata(), ecb, valueToCompare);
LOGGER.debug("*** show original item has value " + dib.getData().getValue() + " and show item has value " + valueToCompare.getValue());
LOGGER.debug("--- show original: " + showOriginalItem + " show duplicate: " + showDuplicateItem + " and just show item: " + showItem);
LOGGER.debug("VALIDATION COUNT " + validationCount);
if (showOriginalItem && showDuplicateItem || showItem) {
if (rt.equals(org.akaza.openclinica.bean.core.ResponseType.TEXT) || rt.equals(org.akaza.openclinica.bean.core.ResponseType.TEXTAREA)) {
dib = validateDisplayItemBeanText(v, dib, inputName, request);
if (validationCount == null || validationCount.intValue() == 0) {
v.addValidation(inputName, Validator.MATCHES_INITIAL_DATA_ENTRY_VALUE, valueToCompare, false);
v.setErrorMessage(respage.getString("value_you_specified") + " " + valueToCompare.getValue() + " " + respage.getString("from_initial_data_entry"));
}
} else if (rt.equals(org.akaza.openclinica.bean.core.ResponseType.FILE)) {
dib = validateDisplayItemBeanText(v, dib, inputName, request);
if (validationCount == null || validationCount.intValue() == 0) {
// we want to check if the current uploaded file matched the initial data file, quick way to do it is by using the hash
// value of the file content that was added to the filename
// cloned for prosperity
ItemDataBean pathStrippedValueToCompare;
try {
pathStrippedValueToCompare = (ItemDataBean) BeanUtils.cloneBean(valueToCompare);
} catch (Throwable e) {
e.printStackTrace();
return dib;
}
// the value we want to check only has filename with no path, so we strip path from the one stored in database, and compare
pathStrippedValueToCompare.setValue(FilenameUtils.getName(valueToCompare.getValue()));
v.addValidation(inputName, Validator.MATCHES_INITIAL_DATA_ENTRY_VALUE, pathStrippedValueToCompare, false);
v.setErrorMessage(respage.getString("value_you_specified") + " " + pathStrippedValueToCompare.getValue() + " " + respage.getString("from_initial_data_entry"));
}
} else if (rt.equals(org.akaza.openclinica.bean.core.ResponseType.RADIO) || rt.equals(org.akaza.openclinica.bean.core.ResponseType.SELECT)) {
dib = validateDisplayItemBeanSingleCV(v, dib, inputName);
if (validationCount == null || validationCount.intValue() == 0) {
v.addValidation(inputName, Validator.MATCHES_INITIAL_DATA_ENTRY_VALUE, valueToCompare, false);
String errorValue = valueToCompare.getValue();
java.util.ArrayList options = dib.getMetadata().getResponseSet().getOptions();
for (int u = 0; u < options.size(); u++) {
ResponseOptionBean rob = (ResponseOptionBean) options.get(u);
if (rob.getValue().equals(errorValue)) {
errorValue = rob.getText();
}
}
v.setErrorMessage(respage.getString("value_you_specified") + " " + errorValue + " " + respage.getString("from_initial_data_entry"));
}
} else if (rt.equals(org.akaza.openclinica.bean.core.ResponseType.CHECKBOX) || rt.equals(org.akaza.openclinica.bean.core.ResponseType.SELECTMULTI)) {
dib = validateDisplayItemBeanMultipleCV(v, dib, inputName);
if (validationCount == null || validationCount.intValue() == 0) {
v.addValidation(inputName, Validator.MATCHES_INITIAL_DATA_ENTRY_VALUE, valueToCompare, true);
// repeated from above, tbh 112007
String errorValue = valueToCompare.getValue();
String errorTexts = "";
java.util.ArrayList options = dib.getMetadata().getResponseSet().getOptions();
for (int u = 0; u < options.size(); u++) {
ResponseOptionBean rob = (ResponseOptionBean) options.get(u);
if (errorValue.contains(rob.getValue())) {
errorTexts = errorTexts + rob.getText();
if (u < options.size() - 1) {
// the values for multi-select are seperated by
// comma
errorTexts = errorTexts + ", ";
}
}
}
v.setErrorMessage(respage.getString("value_you_specified") + " " + errorTexts + " " + respage.getString("from_initial_data_entry"));
}
}
}
return dib;
}
use of org.akaza.openclinica.bean.submit.ItemDataBean in project OpenClinica by OpenClinica.
the class DoubleDataEntryServlet method validateDisplayItemBean.
@Override
protected DisplayItemBean validateDisplayItemBean(DiscrepancyValidator v, DisplayItemBean dib, String inputName, RuleValidator rv, HashMap<String, ArrayList<String>> groupOrdinalPLusItemOid, Boolean fireRuleValidation, ArrayList<String> messages, HttpServletRequest request) {
org.akaza.openclinica.bean.core.ResponseType rt = dib.getMetadata().getResponseSet().getResponseType();
EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
boolean isSingleItem = false;
if (StringUtil.isBlank(inputName)) {
// for single items
inputName = getInputName(dib);
isSingleItem = true;
}
// we only give warning to user if data entered in DDE is different from
// IDE when the first
// time user hits 'save'
int keyId = ecb.getId();
Integer validationCount = (Integer) request.getSession().getAttribute(COUNT_VALIDATE + keyId);
ItemDataBean valueToCompare = dib.getData();
if (!isSingleItem) {
valueToCompare = dib.getDbData();
}
if (isSingleItem) {
dib = loadFormValue(dib, request);
}
if (groupOrdinalPLusItemOid.containsKey(dib.getItem().getOid()) || fireRuleValidation) {
messages = messages == null ? groupOrdinalPLusItemOid.get(dib.getItem().getOid()) : messages;
dib = validateDisplayItemBeanSingleCV(rv, dib, inputName, messages);
}
return dib;
}
use of org.akaza.openclinica.bean.submit.ItemDataBean in project OpenClinica by OpenClinica.
the class DataEntryServlet method prepareSectionItemDataBeans.
protected HashMap<String, String> prepareSectionItemDataBeans(int sectionId, HttpServletRequest request) {
EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
HashMap<String, String> scoreItemdata = new HashMap<String, String>();
ItemDataDAO iddao = new ItemDataDAO(getDataSource(), locale);
ArrayList<ItemDataBean> idbs = iddao.findAllActiveBySectionIdAndEventCRFId(sectionId, ecb.getId());
for (ItemDataBean idb : idbs) {
if (idb.getId() > 0) {
int ordinal = idb.getOrdinal();
ordinal = ordinal > 0 ? ordinal : 1;
scoreItemdata.put(idb.getItemId() + "_" + ordinal, idb.getValue().length() > 0 ? idb.getValue() : "");
}
}
return scoreItemdata;
}
use of org.akaza.openclinica.bean.submit.ItemDataBean in project OpenClinica by OpenClinica.
the class DataEntryServlet method validateSCDItemBean.
protected void validateSCDItemBean(DiscrepancyValidator v, DisplayItemBean dib) {
ItemFormMetadataBean ibMeta = dib.getMetadata();
ItemDataBean idb = dib.getData();
if (StringUtil.isBlank(idb.getValue())) {
//if (ibMeta.isRequired() && showSCDItemIds.contains(ibMeta.getId())) {
if (ibMeta.isRequired() && dib.getIsSCDtoBeShown()) {
v.addValidation(this.getInputName(dib), Validator.IS_REQUIRED);
/*if(dib.getIsSCDtoBeShown()) {
v.addValidation(this.getInputName(dib), Validator.IS_REQUIRED);
} else {
validateShownSCDToBeHiddenSingle(v,dib);
}*/
}
} else {
validateShownSCDToBeHiddenSingle(v, dib);
}
}
use of org.akaza.openclinica.bean.submit.ItemDataBean in project OpenClinica by OpenClinica.
the class DataEntryServlet method ensureSelectedOption.
private void ensureSelectedOption(DisplayItemBean displayItemBean) {
if (displayItemBean == null || displayItemBean.getData() == null) {
return;
}
ItemDataBean itemDataBean = displayItemBean.getData();
String dataName = itemDataBean.getName();
String dataValue = itemDataBean.getValue();
if ("".equalsIgnoreCase(dataValue)) {
return;
}
List<ResponseOptionBean> responseOptionBeans = new ArrayList<ResponseOptionBean>();
ResponseSetBean responseSetBean = displayItemBean.getMetadata().getResponseSet();
if (responseSetBean == null) {
return;
}
responseOptionBeans = responseSetBean.getOptions();
String tempVal = "";
for (ResponseOptionBean responseOptionBean : responseOptionBeans) {
tempVal = responseOptionBean.getValue();
if (tempVal != null && tempVal.equalsIgnoreCase(dataValue)) {
responseOptionBean.setSelected(true);
}
}
}
Aggregations