use of com.evolveum.midpoint.xml.ns._public.common.common_3.ParameterType in project OpenClinica by OpenClinica.
the class RuleController method create.
@RequestMapping(value = "/studies/{study}/validateAndTestRule", method = RequestMethod.POST)
@ResponseBody
public org.openclinica.ns.rules_test.v31.RulesTest create(@RequestBody org.openclinica.ns.rules_test.v31.RulesTest ruleTest, Model model, HttpSession session, @PathVariable("study") String studyOid) throws Exception {
ResourceBundleProvider.updateLocale(new Locale("en_US"));
RulesPostImportContainer rpic = mapRulesToRulesPostImportContainer(ruleTest.getRules());
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);
}
}
}
HashMap<String, String> p = new HashMap<String, String>();
for (ParameterType parameterType : ruleTest.getParameters()) {
p.put(parameterType.getKey(), parameterType.getValue());
}
ExpressionObjectWrapper eow = new ExpressionObjectWrapper(dataSource, currentStudy, rpic.getRuleDefs().get(0).getExpression(), rpic.getRuleSets().get(0));
ExpressionProcessor ep = ExpressionProcessorFactory.createExpressionProcessor(eow);
// Run expression with populated HashMap
DateTime start = new DateTime();
HashMap<String, String> result = ep.testEvaluateExpression(p);
DateTime end = new DateTime();
Duration dur = new Duration(start, end);
PeriodFormatter yearsAndMonths = new PeriodFormatterBuilder().printZeroAlways().appendSecondsWithMillis().appendSuffix(" second", " seconds").toFormatter();
yearsAndMonths.print(dur.toPeriod());
// Run expression with empty HashMap to check rule validity, because
// using illegal test values will cause invalidity
HashMap<String, String> k = new HashMap<String, String>();
HashMap<String, String> theResult = ep.testEvaluateExpression(k);
ruleTest.getParameters().clear();
for (Map.Entry<String, String> entry : result.entrySet()) {
ParameterType parameterType = new ParameterType();
parameterType.setKey(entry.getKey());
parameterType.setValue(entry.getValue());
ruleTest.getParameters().add(parameterType);
}
// if (theResult.get("ruleValidation").equals("rule_valid") && result.get("ruleValidation").equals("rule_invalid")) {
// result.put("ruleValidation", "rule_valid");
// result.put("ruleEvaluatesTo", resword.getString("test_rules_rule_fail") + " " +
// result.get("ruleValidationFailMessage"));
// result.remove("ruleValidationFailMessage");
// }
// Put on screen
// request.setAttribute("duration", yearsAndMonths.print(dur.toPeriod()));
RulesTestMessagesType messageType = new RulesTestMessagesType();
messageType.setKey("duration");
messageType.setValue(yearsAndMonths.print(dur.toPeriod()));
ruleTest.getRulesTestMessages().add(messageType);
return ruleTest;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ParameterType in project midpoint by Evolveum.
the class SearchFilterPanel method initSearchItemField.
protected void initSearchItemField(WebMarkupContainer searchItemContainer) {
CheckPanel checkPanel = new CheckPanel(ID_CHECK_DISABLE_FIELD, new PropertyModel<>(getModel(), FilterSearchItem.F_APPLY_FILTER));
(checkPanel).getBaseFormComponent().add(new OnChangeAjaxBehavior() {
private static final long serialVersionUID = 1L;
@Override
protected void onUpdate(AjaxRequestTarget ajaxRequestTarget) {
searchPerformed(ajaxRequestTarget);
}
});
checkPanel.getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
checkPanel.add(new VisibleBehaviour(this::canRemoveSearchItem));
checkPanel.setOutputMarkupId(true);
searchItemContainer.add(checkPanel);
ParameterType functionParameter = getModelObject().getPredefinedFilter().getParameter();
QName returnType = functionParameter != null ? functionParameter.getType() : null;
Component inputPanel;
if (returnType == null) {
inputPanel = new WebMarkupContainer(ID_SEARCH_ITEM_FIELD);
} else {
Class<?> inputClass = getPrismContext().getSchemaRegistry().determineClassForType(returnType);
Validate.notNull(inputClass, "Couldn't find class for type " + returnType);
SearchItem.Type inputType = getModelObject().getInputType(inputClass, getPageBase());
IModel<List<DisplayableValue<?>>> choices = null;
switch(inputType) {
case REFERENCE:
SearchFilterParameterType parameter = getModelObject().getPredefinedFilter().getParameter();
MutablePrismReferenceDefinition def = null;
if (parameter != null) {
Class<?> clazz = getPrismContext().getSchemaRegistry().determineClassForType(parameter.getType());
QName type = getPrismContext().getSchemaRegistry().determineTypeForClass(clazz);
def = getPrismContext().definitionFactory().createReferenceDefinition(new QName(parameter.getName()), type);
def.setTargetTypeName(parameter.getTargetType());
}
inputPanel = new ReferenceValueSearchPanel(ID_SEARCH_ITEM_FIELD, new PropertyModel<>(getModel(), FilterSearchItem.F_INPUT_VALUE), def);
break;
case BOOLEAN:
choices = (IModel) createBooleanChoices();
case ENUM:
if (choices == null) {
choices = CollectionUtils.isEmpty(getModelObject().getAllowedValues(getPageBase())) ? createEnumChoices((Class<? extends Enum>) inputClass) : Model.ofList(getModelObject().getAllowedValues(getPageBase()));
}
if (choices != null) {
inputPanel = WebComponentUtil.createDropDownChoices(ID_SEARCH_ITEM_FIELD, new PropertyModel(getModel(), FilterSearchItem.F_INPUT), (IModel) choices, true, getPageBase());
break;
}
case DATE:
inputPanel = new DateSearchPanel(ID_SEARCH_ITEM_FIELD, new PropertyModel(getModel(), FilterSearchItem.F_INPUT_VALUE));
break;
case ITEM_PATH:
inputPanel = new ItemPathSearchPanel(ID_SEARCH_ITEM_FIELD, new PropertyModel(getModel(), FilterSearchItem.F_INPUT_VALUE));
break;
case TEXT:
LookupTableType lookupTable = getModelObject().getLookupTable(getPageBase());
if (lookupTable != null) {
inputPanel = createAutoCompetePanel(ID_SEARCH_ITEM_FIELD, new PropertyModel<>(getModel(), FilterSearchItem.F_INPUT_VALUE), lookupTable);
break;
}
default:
inputPanel = new TextPanel<String>(ID_SEARCH_ITEM_FIELD, new PropertyModel<>(getModel(), FilterSearchItem.F_INPUT_VALUE));
}
if (inputPanel instanceof InputPanel && !(inputPanel instanceof AutoCompleteTextPanel)) {
((InputPanel) inputPanel).getBaseFormComponent().add(WebComponentUtil.getSubmitOnEnterKeyDownBehavior("searchSimple"));
((InputPanel) inputPanel).getBaseFormComponent().add(AttributeAppender.append("style", "width: 140px; max-width: 400px !important;"));
((InputPanel) inputPanel).getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
}
inputPanel.setOutputMarkupId(true);
searchItemContainer.add(inputPanel);
}
searchItemContainer.add(inputPanel);
}
Aggregations