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
------------------------------
Original Message:
Sent: Fri February 24, 2023 01:16 PM
From: Kevin Clark
Subject: ODM 8.11 - JRE 8 Local Date Time Classes - Type Not Defined
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
------------------------------