use of org.akaza.openclinica.domain.rule.AuditableBeanWrapper in project OpenClinica by OpenClinica.
the class RulesPostImportContainerService method validateRuleDefs.
public RulesPostImportContainer validateRuleDefs(RulesPostImportContainer importContainer) {
for (RuleBean ruleBean : importContainer.getRuleDefs()) {
AuditableBeanWrapper<RuleBean> ruleBeanWrapper = new AuditableBeanWrapper<RuleBean>(ruleBean);
ruleBeanWrapper.getAuditableBean().setStudy(currentStudy);
// Remove illegal characters from expression value
ruleBeanWrapper.getAuditableBean().getExpression().setValue(ruleBeanWrapper.getAuditableBean().getExpression().getValue().trim().replaceAll("(\n|\t|\r)", " "));
if (isRuleOidValid(ruleBeanWrapper) && isRuleExpressionValid(ruleBeanWrapper, null)) {
RuleBean persistentRuleBean = getRuleDao().findByOid(ruleBeanWrapper.getAuditableBean());
if (persistentRuleBean != null) {
String name = ruleBeanWrapper.getAuditableBean().getName();
String expressionValue = ruleBeanWrapper.getAuditableBean().getExpression().getValue();
String expressionContextName = ruleBeanWrapper.getAuditableBean().getExpression().getContextName();
String description = ruleBeanWrapper.getAuditableBean().getDescription();
Context context = expressionContextName != null ? Context.getByName(expressionContextName) : Context.OC_RULES_V1;
persistentRuleBean.setUpdaterAndDate(getUserAccount());
ruleBeanWrapper.setAuditableBean(persistentRuleBean);
ruleBeanWrapper.getAuditableBean().setName(name);
ruleBeanWrapper.getAuditableBean().setDescription(description);
ruleBeanWrapper.getAuditableBean().getExpression().setValue(expressionValue);
ruleBeanWrapper.getAuditableBean().getExpression().setContext(context);
doesPersistentRuleBeanBelongToCurrentStudy(ruleBeanWrapper);
// ruleBeanWrapper.getAuditableBean().setId(persistentRuleBean.getId());
// ruleBeanWrapper.getAuditableBean().getExpression().setId(persistentRuleBean.getExpression().getId());
} else {
ruleBeanWrapper.getAuditableBean().setOwner(getUserAccount());
}
}
putRuleInCorrectContainer(ruleBeanWrapper, importContainer);
}
logger.info("# of Valid RuleDefs : {} , # of InValid RuleDefs : {} , # of Overwritable RuleDefs : {}", new Object[] { importContainer.getValidRuleDefs().size(), importContainer.getInValidRuleDefs().size(), importContainer.getDuplicateRuleDefs().size() });
return importContainer;
}
use of org.akaza.openclinica.domain.rule.AuditableBeanWrapper in project OpenClinica by OpenClinica.
the class RulesPostImportContainerService method validateRuleSetRuleDefs.
public RulesPostImportContainer validateRuleSetRuleDefs(RulesPostImportContainer importContainer, RuleSetRuleBean ruleSetRuleForm) {
RuleSetBean ruleSetBean = ruleSetRuleForm.getRuleSetBean();
RuleSetRuleBean ruleSetRuleBean = ruleSetRuleForm;
AuditableBeanWrapper<RuleSetBean> ruleSetBeanWrapper = new AuditableBeanWrapper<RuleSetBean>(ruleSetBean);
ruleSetBeanWrapper.getAuditableBean().setStudy(currentStudy);
if (isRuleSetExpressionValid(ruleSetBeanWrapper)) {
RuleSetBean persistentRuleSetBean = getRuleSetDao().findByExpressionAndStudy(ruleSetBean, currentStudy.getId());
if (persistentRuleSetBean != null) {
List<RuleSetRuleBean> importedRuleSetRules = ruleSetBeanWrapper.getAuditableBean().getRuleSetRules();
persistentRuleSetBean.setUpdaterAndDate(getUserAccount());
ruleSetBeanWrapper.setAuditableBean(persistentRuleSetBean);
for (RuleSetRuleBean persistentruleSetRuleBean : persistentRuleSetBean.getRuleSetRules()) {
if (persistentruleSetRuleBean.getStatus() != Status.DELETED && ruleSetRuleBean.equals(persistentruleSetRuleBean)) {
persistentruleSetRuleBean.setRuleSetRuleBeanImportStatus(RuleSetRuleBeanImportStatus.EXACT_DOUBLE);
// itr.remove();
break;
} else if (persistentruleSetRuleBean.getStatus() != Status.DELETED && ruleSetRuleBean.getRuleBean() != null && ruleSetRuleBean.getRuleBean().equals(persistentruleSetRuleBean.getRuleBean())) {
// persistentruleSetRuleBean.setActions(ruleSetRuleBean.getActions());
persistentruleSetRuleBean.setRuleSetRuleBeanImportStatus(RuleSetRuleBeanImportStatus.TO_BE_REMOVED);
// itr.remove();
break;
}
ruleSetRuleBean.setRuleSetRuleBeanImportStatus(RuleSetRuleBeanImportStatus.LINE);
}
ruleSetBeanWrapper.getAuditableBean().addRuleSetRules(importedRuleSetRules);
// ruleSetBeanWrapper.getAuditableBean().setId(persistentRuleSetBean.getId());
} else {
ruleSetBeanWrapper.getAuditableBean().setOwner(getUserAccount());
ruleSetBeanWrapper.getAuditableBean().setStudyEventDefinition(getExpressionService().getStudyEventDefinitionFromExpression(ruleSetBean.getTarget().getValue()));
ruleSetBeanWrapper.getAuditableBean().setCrf(getExpressionService().getCRFFromExpression(ruleSetBean.getTarget().getValue()));
ruleSetBeanWrapper.getAuditableBean().setCrfVersion(getExpressionService().getCRFVersionFromExpression(ruleSetBean.getTarget().getValue()));
ruleSetBeanWrapper.getAuditableBean().setItem(getExpressionService().getItemBeanFromExpression(ruleSetBean.getTarget().getValue()));
ruleSetBeanWrapper.getAuditableBean().setItemGroup(getExpressionService().getItemGroupExpression(ruleSetBean.getTarget().getValue()));
}
List<RuleSetBean> eventActionsRuleSetBean = getRuleSetDao().findAllEventActions(currentStudy);
isRuleSetRuleValid(importContainer, ruleSetBeanWrapper, eventActionsRuleSetBean);
}
putRuleSetInCorrectContainer(ruleSetBeanWrapper, importContainer);
logger.info("# of Valid RuleSetDefs : " + importContainer.getValidRuleSetDefs().size());
logger.info("# of InValid RuleSetDefs : " + importContainer.getInValidRuleSetDefs().size());
logger.info("# of Overwritable RuleSetDefs : " + importContainer.getDuplicateRuleSetDefs().size());
return importContainer;
}
use of org.akaza.openclinica.domain.rule.AuditableBeanWrapper in project OpenClinica by OpenClinica.
the class RulesPostImportContainerService method isRuleSetRuleValid.
/**
* If the RuleSet contains any RuleSetRule object with an invalid RuleRef OID (OID that is not in DB or in the Valid Rule Lists) , Then add an error to the
* ruleSetBeanWrapper, which in terms will make the RuleSet inValid.
*
* @param importContainer
* @param ruleSetBeanWrapper
*/
private void isRuleSetRuleValid(RulesPostImportContainer importContainer, AuditableBeanWrapper<RuleSetBean> ruleSetBeanWrapper, List<RuleSetBean> eventActionsRuleSetBean) {
for (RuleSetRuleBean ruleSetRuleBean : ruleSetBeanWrapper.getAuditableBean().getRuleSetRules()) {
String ruleDefOid = ruleSetRuleBean.getOid();
if (ruleSetRuleBean.getId() == null || ruleSetRuleBean.getRuleSetRuleBeanImportStatus() == RuleSetRuleBeanImportStatus.EXACT_DOUBLE) {
EventDefinitionCRFBean eventDefinitionCRFBean = getExpressionService().getEventDefinitionCRF(ruleSetBeanWrapper.getAuditableBean().getTarget().getValue());
if (eventDefinitionCRFBean != null && eventDefinitionCRFBean.getStatus().isDeleted()) {
ruleSetBeanWrapper.error(createError("OCRERR_0026"));
}
if (importContainer.getInValidRules().get(ruleDefOid) != null || importContainer.getValidRules().get(ruleDefOid) == null && getRuleDao().findByOid(ruleDefOid, ruleSetBeanWrapper.getAuditableBean().getStudyId()) == null) {
ruleSetBeanWrapper.error(createError("OCRERR_0025"));
}
if (importContainer.getValidRules().get(ruleDefOid) != null) {
AuditableBeanWrapper<RuleBean> r = importContainer.getValidRules().get(ruleDefOid);
if (!isRuleExpressionValid(r, ruleSetBeanWrapper.getAuditableBean()))
ruleSetBeanWrapper.error(createError("OCRERR_0027"));
}
if (importContainer.getValidRules().get(ruleDefOid) == null) {
RuleBean rule = getRuleDao().findByOid(ruleDefOid, ruleSetBeanWrapper.getAuditableBean().getStudyId());
AuditableBeanWrapper<RuleBean> r = new AuditableBeanWrapper<RuleBean>(rule);
if (rule == null || !isRuleExpressionValid(r, ruleSetBeanWrapper.getAuditableBean()))
ruleSetBeanWrapper.error(createError("OCRERR_0027"));
}
if (ruleSetRuleBean.getActions().size() == 0) {
ruleSetBeanWrapper.error(createError("OCRERR_0027"));
}
for (RuleActionBean ruleActionBean : ruleSetRuleBean.getActions()) {
isRuleActionValid(ruleActionBean, ruleSetBeanWrapper, eventDefinitionCRFBean, eventActionsRuleSetBean);
}
}
}
}
use of org.akaza.openclinica.domain.rule.AuditableBeanWrapper in project OpenClinica by OpenClinica.
the class RulesPostImportContainerService method validateRuleSetDefs.
public RulesPostImportContainer validateRuleSetDefs(RulesPostImportContainer importContainer) {
List<RuleSetBean> eventActionsRuleSetBean = getRuleSetDao().findAllEventActions(currentStudy);
for (RuleSetBean ruleSetBean : importContainer.getRuleSets()) {
AuditableBeanWrapper<RuleSetBean> ruleSetBeanWrapper = new AuditableBeanWrapper<RuleSetBean>(ruleSetBean);
ruleSetBeanWrapper.getAuditableBean().setStudy(currentStudy);
if (isRuleSetExpressionValid(ruleSetBeanWrapper)) {
RuleSetBean persistentRuleSetBean = getRuleSetDao().findByExpressionAndStudy(ruleSetBean, currentStudy.getId());
if (persistentRuleSetBean != null) {
List<RuleSetRuleBean> importedRuleSetRules = ruleSetBeanWrapper.getAuditableBean().getRuleSetRules();
if (ruleSetBean.getRunTime() != null) {
if (ruleSetBean.getRunOnSchedule() == null) {
ruleSetBean.setRunOnSchedule(new RunOnSchedule(ruleSetBean.getRunTime()));
}
}
if (ruleSetBean.getRunOnSchedule() != null) {
persistentRuleSetBean.setRunSchedule(true);
if (ruleSetBean.getRunOnSchedule().getRunTime() != null) {
if (isRunTimeValid(ruleSetBeanWrapper, ruleSetBean.getRunOnSchedule().getRunTime())) {
persistentRuleSetBean.setRunTime(ruleSetBean.getRunOnSchedule().getRunTime());
}
} else {
// supposed to act like 23:00
persistentRuleSetBean.setRunTime(null);
}
} else {
persistentRuleSetBean.setRunSchedule(false);
persistentRuleSetBean.setRunTime(null);
}
persistentRuleSetBean.setUpdaterAndDate(getUserAccount());
ruleSetBeanWrapper.setAuditableBean(persistentRuleSetBean);
Iterator<RuleSetRuleBean> itr = importedRuleSetRules.iterator();
while (itr.hasNext()) {
RuleSetRuleBean ruleSetRuleBean = itr.next();
ruleSetRuleBean.setRuleBean(getRuleDao().findByOid(ruleSetRuleBean.getOid(), persistentRuleSetBean.getStudyId()));
// ruleSetRuleBean.setRuleSetBean(ruleSetBeanWrapper.getAuditableBean());
for (RuleSetRuleBean persistentruleSetRuleBean : persistentRuleSetBean.getRuleSetRules()) {
if (persistentruleSetRuleBean.getStatus() != Status.DELETED && ruleSetRuleBean.equals(persistentruleSetRuleBean)) {
persistentruleSetRuleBean.setRuleSetRuleBeanImportStatus(RuleSetRuleBeanImportStatus.EXACT_DOUBLE);
itr.remove();
break;
} else if (persistentruleSetRuleBean.getStatus() != Status.DELETED && ruleSetRuleBean.getRuleBean() != null && ruleSetRuleBean.getRuleBean().equals(persistentruleSetRuleBean.getRuleBean())) {
// persistentruleSetRuleBean.setActions(ruleSetRuleBean.getActions());
persistentruleSetRuleBean.setRuleSetRuleBeanImportStatus(RuleSetRuleBeanImportStatus.TO_BE_REMOVED);
// itr.remove();
break;
}
ruleSetRuleBean.setRuleSetRuleBeanImportStatus(RuleSetRuleBeanImportStatus.LINE);
}
}
ruleSetBeanWrapper.getAuditableBean().addRuleSetRules(importedRuleSetRules);
// ruleSetBeanWrapper.getAuditableBean().setId(persistentRuleSetBean.getId());
} else {
if (importContainer.getValidRuleSetExpressionValues().contains(ruleSetBeanWrapper.getAuditableBean().getTarget().getValue())) {
ruleSetBeanWrapper.error(createError("OCRERR_0031"));
}
ruleSetBeanWrapper.getAuditableBean().setOwner(getUserAccount());
ruleSetBeanWrapper.getAuditableBean().setStudyEventDefinition(getExpressionService().getStudyEventDefinitionFromExpression(ruleSetBean.getTarget().getValue()));
ruleSetBeanWrapper.getAuditableBean().setCrf(getExpressionService().getCRFFromExpression(ruleSetBean.getTarget().getValue()));
ruleSetBeanWrapper.getAuditableBean().setCrfVersion(getExpressionService().getCRFVersionFromExpression(ruleSetBean.getTarget().getValue()));
ruleSetBeanWrapper.getAuditableBean().setItem(getExpressionService().getItemBeanFromExpression(ruleSetBean.getTarget().getValue()));
ruleSetBeanWrapper.getAuditableBean().setItemGroup(getExpressionService().getItemGroupExpression(ruleSetBean.getTarget().getValue()));
if (ruleSetBean.getRunTime() != null) {
if (ruleSetBean.getRunOnSchedule() == null) {
ruleSetBeanWrapper.getAuditableBean().setRunOnSchedule(new RunOnSchedule(ruleSetBean.getRunTime()));
}
}
if (ruleSetBean.getRunOnSchedule() != null) {
ruleSetBeanWrapper.getAuditableBean().setRunSchedule(true);
if (ruleSetBean.getRunOnSchedule().getRunTime() != null) {
//validate Time isRunTimeValid
if (isRunTimeValid(ruleSetBeanWrapper, ruleSetBean.getRunOnSchedule().getRunTime())) {
ruleSetBeanWrapper.getAuditableBean().setRunTime(ruleSetBean.getRunOnSchedule().getRunTime());
}
} else {
// supposed to act like DEFAULT_TIME
ruleSetBeanWrapper.getAuditableBean().setRunTime(null);
}
} else {
ruleSetBeanWrapper.getAuditableBean().setRunSchedule(false);
ruleSetBeanWrapper.getAuditableBean().setRunTime(null);
}
}
isRuleSetRuleValid(importContainer, ruleSetBeanWrapper, eventActionsRuleSetBean);
}
putRuleSetInCorrectContainer(ruleSetBeanWrapper, importContainer);
}
logger.info("# of Valid RuleSetDefs : " + importContainer.getValidRuleSetDefs().size());
logger.info("# of InValid RuleSetDefs : " + importContainer.getInValidRuleSetDefs().size());
logger.info("# of Overwritable RuleSetDefs : " + importContainer.getDuplicateRuleSetDefs().size());
return importContainer;
}
use of org.akaza.openclinica.domain.rule.AuditableBeanWrapper in project OpenClinica by OpenClinica.
the class RuleController method validateAndSave.
@RequestMapping(value = "/studies/{study}/validateAndSaveRule", method = RequestMethod.POST)
@ResponseBody
public Response validateAndSave(@RequestBody org.openclinica.ns.rules.v31.Rules rules, Model model, HttpSession session, @PathVariable("study") String studyOid, @RequestParam("ignoreDuplicates") Boolean ignoreDuplicates) throws Exception {
ResourceBundleProvider.updateLocale(new Locale("en_US"));
RulesPostImportContainer rpic = mapRulesToRulesPostImportContainer(rules);
StudyDAO studyDao = new StudyDAO(dataSource);
StudyBean currentStudy = studyDao.findByOid(studyOid);
UserAccountBean userAccount = getUserAccount();
mayProceed(userAccount, currentStudy);
getRulePostImportContainerService(currentStudy, userAccount);
rpic = getRulePostImportContainerService(currentStudy, userAccount).validateRuleDefs(rpic);
rpic = getRulePostImportContainerService(currentStudy, userAccount).validateRuleSetDefs(rpic);
Response response = new Response();
response.setValid(Boolean.TRUE);
if (rpic.getInValidRuleDefs().size() > 0 || rpic.getInValidRuleSetDefs().size() > 0) {
response.setValid(Boolean.FALSE);
for (AuditableBeanWrapper<RuleBean> beanWrapper : rpic.getInValidRuleDefs()) {
for (String error : beanWrapper.getImportErrors()) {
org.openclinica.ns.response.v31.MessagesType messageType = new MessagesType();
messageType.setMessage(error);
response.getMessages().add(messageType);
}
}
for (AuditableBeanWrapper<RuleSetBean> beanWrapper : rpic.getInValidRuleSetDefs()) {
for (String error : beanWrapper.getImportErrors()) {
org.openclinica.ns.response.v31.MessagesType messageType = new MessagesType();
messageType.setMessage(error);
response.getMessages().add(messageType);
}
}
} else if ((rpic.getDuplicateRuleDefs().size() > 0) && !ignoreDuplicates) {
response.setValid(Boolean.FALSE);
for (AuditableBeanWrapper<RuleBean> beanWrapper : rpic.getDuplicateRuleDefs()) {
org.openclinica.ns.response.v31.MessagesType messageType = new MessagesType();
messageType.setMessage(DUPLICATE_MESSAGE);
response.getMessages().add(messageType);
}
} else {
getRuleSetService().saveImportFromDesigner(rpic);
}
logger.debug("RPIC READY");
return response;
}
Aggregations