Search in sources :

Example 1 with ParameterType

use of org.openclinica.ns.rules_test.v31.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);
}
Also used : VisibleBehaviour(com.evolveum.midpoint.web.component.util.VisibleBehaviour) EmptyOnBlurAjaxFormUpdatingBehaviour(com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnBlurAjaxFormUpdatingBehaviour) SearchFilterParameterType(com.evolveum.midpoint.xml.ns._public.common.common_3.SearchFilterParameterType) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) List(java.util.List) Component(org.apache.wicket.Component) LookupTableType(com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType) ParameterType(com.evolveum.midpoint.xml.ns._public.common.common_3.ParameterType) SearchFilterParameterType(com.evolveum.midpoint.xml.ns._public.common.common_3.SearchFilterParameterType) IModel(org.apache.wicket.model.IModel) QName(javax.xml.namespace.QName) InputPanel(com.evolveum.midpoint.web.component.prism.InputPanel) PropertyModel(org.apache.wicket.model.PropertyModel) CheckPanel(com.evolveum.midpoint.web.component.input.CheckPanel) MutablePrismReferenceDefinition(com.evolveum.midpoint.prism.MutablePrismReferenceDefinition) OnChangeAjaxBehavior(org.apache.wicket.ajax.form.OnChangeAjaxBehavior) AutoCompleteTextPanel(com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteTextPanel) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget)

Example 2 with ParameterType

use of org.openclinica.ns.rules_test.v31.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;
}
Also used : Locale(java.util.Locale) HashMap(java.util.HashMap) DateTime(org.joda.time.DateTime) ExpressionProcessor(org.akaza.openclinica.domain.rule.expression.ExpressionProcessor) org.openclinica.ns.rules.v31(org.openclinica.ns.rules.v31) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) RulesTestMessagesType(org.openclinica.ns.rules_test.v31.RulesTestMessagesType) ParameterType(org.openclinica.ns.rules_test.v31.ParameterType) PeriodFormatter(org.joda.time.format.PeriodFormatter) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) MessagesType(org.openclinica.ns.response.v31.MessagesType) RulesTestMessagesType(org.openclinica.ns.rules_test.v31.RulesTestMessagesType) Duration(org.joda.time.Duration) MessagesType(org.openclinica.ns.response.v31.MessagesType) Response(org.openclinica.ns.response.v31.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) RulesPostImportContainer(org.akaza.openclinica.domain.rule.RulesPostImportContainer) PeriodFormatterBuilder(org.joda.time.format.PeriodFormatterBuilder) ExpressionObjectWrapper(org.akaza.openclinica.domain.rule.expression.ExpressionObjectWrapper) Map(java.util.Map) HashMap(java.util.HashMap) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean) RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean) RuleBean(org.akaza.openclinica.domain.rule.RuleBean) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

AutoCompleteTextPanel (com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteTextPanel)1 MutablePrismReferenceDefinition (com.evolveum.midpoint.prism.MutablePrismReferenceDefinition)1 CheckPanel (com.evolveum.midpoint.web.component.input.CheckPanel)1 InputPanel (com.evolveum.midpoint.web.component.prism.InputPanel)1 VisibleBehaviour (com.evolveum.midpoint.web.component.util.VisibleBehaviour)1 EmptyOnBlurAjaxFormUpdatingBehaviour (com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnBlurAjaxFormUpdatingBehaviour)1 LookupTableType (com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType)1 ParameterType (com.evolveum.midpoint.xml.ns._public.common.common_3.ParameterType)1 SearchFilterParameterType (com.evolveum.midpoint.xml.ns._public.common.common_3.SearchFilterParameterType)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 QName (javax.xml.namespace.QName)1 UserAccountBean (org.akaza.openclinica.bean.login.UserAccountBean)1 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)1 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)1 RuleBean (org.akaza.openclinica.domain.rule.RuleBean)1 RuleSetBean (org.akaza.openclinica.domain.rule.RuleSetBean)1