Decision Management (ODM,ADS)

 View Only
  • 1.  ODM 8.11 - JRE 8 Local Date Time Classes - Type Not Defined

    Posted Sun February 26, 2023 08:19 PM

    I am trying to switch several of my BOM fields from Date to LocalDateTime or ZonedDateTime, and both options generate GBRMO0012W errors, type not defined.  From my research I believe this was an issue around 8.9.2, however I assume these classes were integrated into 8.10 +.  I am using a JDK 1.8. 0_321, so that should also be compatible.  Please review, and let m know anything else I should be checking for this issue.



    ------------------------------
    Kevin Clark
    ------------------------------


  • 2.  RE: ODM 8.11 - JRE 8 Local Date Time Classes - Type Not Defined

    Posted Mon February 27, 2023 02:21 AM

    Hello Kevin,

    unfortunately, the Java time classes introduced in Java 8 are not supported in the ODM boot BOM, which still relies on java.util.Date. 

    The ODM team is considering adding support for Java time classes in a future release, but not in the short term. Can you explain why you've tried to switch your BOM fields to LocalDateTime or ZonedDateTime? Feel free to add a related Idea (request for enhancement) for ODM at https://ideas.ibm.com/



    ------------------------------
    Antony Viaud
    Product Manager, IBM Decision Automation
    ------------------------------



  • 3.  RE: ODM 8.11 - JRE 8 Local Date Time Classes - Type Not Defined

    Posted Mon March 06, 2023 10:41 AM

    This directive was mainly coming from our Dev Ops code scanning's, indicating our Java code needed to migrate to Java 8 LocalDateTimes.  I believe with this information, I should be able to get an exception for this rule, I appreciate your response!



    ------------------------------
    Kevin Clark
    ------------------------------



  • 4.  RE: ODM 8.11 - JRE 8 Local Date Time Classes - Type Not Defined

    Posted Mon February 27, 2023 02:54 PM

    Kevin,

    We've encountered this issue in the past and have had to come up with a workaround. While the boot BOM does not have those types, they can be easily added to the app BOM. 

    When creating the BOM Entry, use the JRE as the XOM entry. After creating this BOM entry, you can now access Domain attributes having these date types in your rules. ZonedDateTime is automagically treated as Date by ODM.
    Hope that helps.


    ------------------------------
    Raj Rao
    ------------------------------



  • 5.  RE: ODM 8.11 - JRE 8 Local Date Time Classes - Type Not Defined

    Posted Mon March 06, 2023 10:45 AM

    Raj,

    I attempted this, however when I try to select on any entry in eclipse, I get a Java.lang.NullPointerError, any ideas what that is?



    ------------------------------
    Kevin Clark
    ------------------------------



  • 6.  RE: ODM 8.11 - JRE 8 Local Date Time Classes - Type Not Defined

    Posted Mon March 13, 2023 05:13 PM
      |   view attached

    Kevin,

    There seems to be an issue in this version of Rule Designer that is causing the NPE. I'm attaching the java-time bom that I use -- you can reuse it. Just unzip to your bom folder and restart Rule Designer.



    ------------------------------
    Raj Rao
    ------------------------------

    Attachment(s)

    zip
    java time bom.zip   873 B 1 version


  • 7.  RE: ODM 8.11 - JRE 8 Local Date Time Classes - Type Not Defined

    Posted Wed March 01, 2023 05:59 AM
    Edited by Peter Warde Wed March 01, 2023 06:13 AM

    Hi Kevin,

    The usual use case for what you describe is that decision service consumers want to work in the Java 8 APIs, but ODM only works with the legacy java.util.Date etc. 

    If that is your case, the best solution is to convert between the two. If you are using Hosted Transparent Decision Services (HTDS) you can do this cleanly using the JAXB API and a javax.xml.bind.annotation.adapters.XmlAdapter. 

    For example:

    import javax.xml.bind.annotation.adapters.XmlAdapter;
    import javax.xml.datatype.DatatypeConfigurationException;
    import javax.xml.datatype.DatatypeFactory;
    import javax.xml.datatype.XMLGregorianCalendar;

    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;

    public class LocalDateTimeAdapter extends XmlAdapter<String, LocalDateTime> {

        private static final Logger LOG = LoggerFactory.getLogger(LocalDateTimeAdapter.class);

        @Override
        public String marshal(LocalDateTime dateTime) {
            Date date = java.util.Date.from(dateTime.atZone(ZoneId.systemDefault()).toInstant());
            GregorianCalendar gCal = new GregorianCalendar();
            gCal.setTime(date);
            XMLGregorianCalendar xmlCal = null;
            try {
                DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
                xmlCal = datatypeFactory.newXMLGregorianCalendar(gCal);
            } catch (DatatypeConfigurationException dce) {
                LOG.error("Unexpected problem converting date to XMLGregorianCalendar - date= {}", date.toString(), dce);
            }
            return xmlCal.toString();
        }

        @Override
        public LocalDateTime unmarshal(String dateTime) {
            DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
            try {
                Date date = formatter.parse(dateTime);
                return new java.sql.Timestamp(date.getTime()).toLocalDateTime();
            } catch (ParseException pe) {
                LOG.error("Unexpected problem parsing dateTime to LocalDateTime - dateTime= {}", dateTime, pe);
            }
            return null;
        }
    }

    After that you can use JAXB annotations to annotate your Java XOM (if you do not own the XOM code then extend it and override). You can also add Java helper methods for any additional functionality that you may need and use ODM annotations (@NotBusiness, @CustomProperties(names = { "dataio.default" }, values = { "true" }), etc) to control how they are mapped in the BOM and used in Decision Runner.

    In my experience these kinds of problems are best resolved in code and outside ODM. You can JUnit test them. JAXB works both with REST and SOAP so you should be good to go with both. It is a bit of work

    When you do the above the value editors and the BRL for rule authoring in Decision Center and Rules Designer with dates and time. This is an important consideration if you want business users to author rules and have "business rules under business jurisdiction" as per the SBVR standard. You also stay within the product scope.

    Peter Warde



    ------------------------------
    Peter Warde
    peterwarde@rulearchitect.com
    ------------------------------