use of org.akaza.openclinica.domain.datamap.ResponseSet in project OpenClinica by OpenClinica.
the class ResponseSetValidator method validate.
@Override
public void validate(Object target, Errors errors) {
ResponseSet responseSet = (ResponseSet) target;
if (responseSet.getResponseSetId() == 0) {
errors.rejectValue("label", "found_unsupported_usercontrol", item.getName());
return;
}
List<String> newTexts = Arrays.asList(responseSet.getOptionsText().split("(?<!\\\\),"));
List<String> newValues = Arrays.asList(responseSet.getOptionsValues().split("(?<!\\\\),"));
// Look up existing response sets derived from the same item in existing crf versions
List<ResponseSet> existingSets = responseSetDao.findAllByItemId(item.getItemId());
for (int i = 0; i < existingSets.size(); i++) {
ResponseSet existingSet = existingSets.get(i);
List<String> existingTexts = Arrays.asList(existingSet.getOptionsText().split("(?<!\\\\),"));
List<String> existingValues = Arrays.asList(existingSet.getOptionsValues().split("(?<!\\\\),"));
// Verify response set label has not changed
if (!existingSet.getLabel().equals(responseSet.getLabel())) {
errors.rejectValue("label", "crf_val_responseset_difflabel", item.getName());
return;
}
for (int j = 0; j < existingTexts.size(); j++) {
for (int k = 0; k < newTexts.size(); k++) {
// Verify a text is not changed on an exist value or vice versa
if (existingTexts.get(j).equalsIgnoreCase(newTexts.get(k)) && !existingValues.get(j).equals(newValues.get(k))) {
logger.debug("Found modified response value (not allowed). Old value: " + existingValues.get(j) + " - New value: " + newValues.get(k));
errors.rejectValue("optionsValues", "crf_val_responseset_diffoptionvalues", item.getName());
return;
} else if (!existingTexts.get(j).equalsIgnoreCase(newTexts.get(k)) && existingValues.get(j).equals(newValues.get(k))) {
logger.debug("Found modified response text (not allowed). Old text: " + existingValues.get(j) + " - New text: " + newValues.get(k));
errors.rejectValue("optionsText", "crf_val_responseset_diffoptiontext", item.getName());
return;
}
}
}
}
}
use of org.akaza.openclinica.domain.datamap.ResponseSet in project OpenClinica by OpenClinica.
the class ResponseSetService method getResponseSet.
public ResponseSet getResponseSet(XformItem xformItem, CrfVersion crfVersion, ResponseType responseType, org.akaza.openclinica.domain.datamap.Item item, Errors errors) throws Exception {
ResponseSet responseSet = responseSetDao.findByLabelVersion(xformItem.getItemName(), crfVersion.getCrfVersionId());
String optionText = xformItem.getOptionsText();
if (responseSet == null) {
// Create the response set
responseSet = new ResponseSet();
responseSet.setLabel(xformItem.getItemName());
if (optionText != null) {
responseSet.setOptionsText(optionText);
responseSet.setOptionsValues(xformItem.getOptionsValues());
responseSet.setResponseType(responseType);
responseSet.setVersionId(crfVersion.getCrfVersionId());
responseSet = responseSetDao.saveOrUpdate(responseSet);
}
} else {
if (optionText != null) {
responseSet.setOptionsText(optionText);
responseSet.setOptionsValues(xformItem.getOptionsValues());
responseSet.setResponseType(responseType);
responseSet = responseSetDao.saveOrUpdate(responseSet);
}
}
return responseSet;
}
use of org.akaza.openclinica.domain.datamap.ResponseSet in project OpenClinica by OpenClinica.
the class XformMetaDataService method createGroups.
private void createGroups(XformContainer container, CrfBean crf, CrfVersion crfVersion, FormLayout formLayout, Section section, UserAccountBean ub, Errors errors) throws Exception {
Integer itemOrdinal = 1;
ArrayList<String> usedGroupOids = new ArrayList<String>();
ArrayList<String> usedItemOids = new ArrayList<String>();
// for (Group htmlGroup : htmlGroups) {
for (XformGroup xformGroup : container.getGroups()) {
// XformGroup xformGroup = container.findGroupByRef(htmlGroup.getRef());
ItemGroup itemGroup = itemGroupDao.findByNameCrfId(xformGroup.getGroupName(), crf);
if (itemGroup == null) {
itemGroup = new ItemGroup();
itemGroup.setName(xformGroup.getGroupName());
itemGroup.setLayoutGroupPath(xformGroup.getGroupPath());
itemGroup.setCrf(crf);
itemGroup.setStatus(org.akaza.openclinica.domain.Status.AVAILABLE);
itemGroup.setUserAccount(userDao.findById(ub.getId()));
itemGroup.setOcOid(xformGroup.getGroupOid());
usedGroupOids.add(itemGroup.getOcOid());
itemGroup = itemGroupDao.saveOrUpdate(itemGroup);
} else {
itemGroup.setName(xformGroup.getGroupName());
itemGroup = itemGroupDao.saveOrUpdate(itemGroup);
}
boolean isRepeating = xformGroup.isRepeating();
for (XformItem xformItem : xformGroup.getItems()) {
Item item = createItem(xformGroup, xformItem, crf, ub, usedItemOids, errors);
if (item != null) {
ResponseType responseType = getResponseType(xformItem);
ResponseSet responseSet = responseSetService.getResponseSet(xformItem, crfVersion, responseType, item, errors);
// add if statement
ItemFormMetadata ifmd = itemFormMetadataDao.findByItemCrfVersion(item.getItemId(), crfVersion.getCrfVersionId());
if (ifmd == null) {
ifmd = createItemFormMetadata(xformItem, item, responseSet, section, crfVersion, itemOrdinal);
} else {
ifmd.setRequired(xformItem.isRequired());
ifmd.setLeftItemText(xformItem.getLeftItemText());
ifmd.setItem(item);
ifmd.setResponseSet(responseSet);
ifmd = itemFormMetadataDao.saveOrUpdate(ifmd);
}
ArrayList<VersioningMap> vm = versioningMapDao.findByVersionIdFormLayoutIdAndItemId(crfVersion.getCrfVersionId(), formLayout.getFormLayoutId(), item.getItemId(), itemOrdinal);
if (vm.size() == 0) {
createVersioningMap(crfVersion, item, formLayout, xformItem.getItemOrderInForm());
}
//
ItemGroupMetadata igmd = itemGroupMetadataDao.findByItemCrfVersion(item.getItemId(), crfVersion.getCrfVersionId());
if (igmd == null) {
igmd = createItemGroupMetadata(item, crfVersion, itemGroup, isRepeating, itemOrdinal);
}
itemOrdinal++;
}
}
}
}
Aggregations