Decision Management (ODM,ADS)

 View Only
Expand all | Collapse all

How to add a CustomExceptionHandler to a rule project through the Decision Center API (ODM 8.11)

  • 1.  How to add a CustomExceptionHandler to a rule project through the Decision Center API (ODM 8.11)

    Posted Tue October 18, 2022 08:54 AM
    Hi experts!

    Is there any way to add a CustomExceptionHandler to a rule project through the Decision Center API in ODM 8.11?
    From RuleDesigner I can do this by updating the Custom Exception Handler field when I select the DE rule engine.


    But when I create a rule project through the Decision Center API I don't see a way to do it.

    Any ideas?

    Thanks!


    ------------------------------
    Charo Álvarez Martínez
    Automation Architect
    DECIDE
    Madrid
    ------------------------------


  • 2.  RE: How to add a CustomExceptionHandler to a rule project through the Decision Center API (ODM 8.11)
    Best Answer

    Posted Tue October 18, 2022 07:54 PM
    The exception handler and the automatic exception handling are ruleset properties in the rule project info.
    You can modify then with the API as illustrated in this method

      private void updateProject(IlrSession dataProvider, IlrBaseline baseline, String useAEH, String exceptionHandlerClass) throws IlrApplicationException {
    IlrProjectInfo info = baseline.getProjectInfo();
    IlrCommitableObject co = new IlrCommitableObject((IlrElementHandle)info);
    co.setRootDetails((IlrElementDetails)info);
    IlrBrmPackage brm = dataProvider.getBrmPackage();
    List<IlrRulesetProperty> properties = info.getRulesetProperties();
    // delete existing properties
    for (IlrRulesetProperty ilrRulesetProperty : properties) {
    if (ilrRulesetProperty.getKey().equals("AutomaticExceptionHandler"))
    co.addDeletedElement(brm.getProjectInfo_RulesetProperties(), (IlrElementDetails)ilrRulesetProperty);
    if (ilrRulesetProperty.getKey().equals("CustomExceptionHandler"))
    co.addDeletedElement(brm.getProjectInfo_RulesetProperties(), (IlrElementDetails)ilrRulesetProperty);
    }
    // add automatic exception handling
    if ("true".equals(useAEH)) {
    IlrRulesetProperty aProp = (IlrRulesetProperty)((IlrSessionEx)dataProvider).createElementDetails(brm.getRulesetProperty());
    aProp.setRawValue((EStructuralFeature)brm.getRulesetProperty_Key(), "AutomaticExceptionHandler");
    aProp.setRawValue((EStructuralFeature)brm.getRulesetProperty_Value(), "true");
    co.addModifiedElement(brm.getProjectInfo_RulesetProperties(), (IlrElementDetails)aProp);
    }
    // add a custom exception handler
    if (exceptionHandlerClass != null) {
    IlrRulesetProperty aProp = (IlrRulesetProperty)((IlrSessionEx)dataProvider).createElementDetails(brm.getRulesetProperty());
    aProp.setRawValue((EStructuralFeature)brm.getRulesetProperty_Key(), "CustomExceptionHandler");
    aProp.setRawValue((EStructuralFeature)brm.getRulesetProperty_Value(), exceptionHandlerClass);
    co.addModifiedElement(brm.getProjectInfo_RulesetProperties(), (IlrElementDetails)aProp);
    }
    // save in the repository
    dataProvider.commit(co);
    }

    Hope this helps


    ------------------------------
    Alain Robert
    ------------------------------



  • 3.  RE: How to add a CustomExceptionHandler to a rule project through the Decision Center API (ODM 8.11)

    Posted Wed October 19, 2022 01:05 PM
    Hi Alain,

    It works! Thank you very much.

    I just had to modify the line (deprecated):
    dataProvider.commit(co);

    to:

    connection.addCommitableObject(co);​

    Thanks!

    ------------------------------
    Charo Álvarez Martínez
    Automation Architect
    DECIDE
    Madrid
    ------------------------------