[midPoint] Problem with java script with dates

Andrea Picconi andrea.picconi at innovery.net
Mon Jan 11 09:21:14 CET 2021


Hi Richard,

thanks to your answer we have solved the problem. Here is the code, maybe it will be useful for someone else:

<script xmlns:org="http://midpoint.evolveum.com/xml/ns/public/common/org-3">
    <code>
        import java.text.SimpleDateFormat;
        import java.text.DateFormat;

        date1 = yourAttribute1;
        date2 = yourAttribute2;
        date3 = yourAttribute3;

        if (date1 != null) {
        if (date3 != null) {
        int result1 = date1.toGregorianCalendar().compareTo(date3.toGregorianCalendar());
        if (result1  >  0) {
            date3 = date1; }
            }
        else {
        date3 = date1; }
        }

        if (date2 != null) {
        if (date3 != null) {
        int result2 = date2.toGregorianCalendar().compareTo(date3.toGregorianCalendar());
        if (result2  >  0) {
            date3 = date2; }
            }
        else {
        date3 = date2; }
        }
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
        return df.format(com.evolveum.midpoint.util.MiscUtil.asDate(date3));
    </code>
</script>

Regards,

Andrea Picconi
IAM (Identity Access Management)

[Innovery]
Skype: precons
T:  +39 06 51963439 (int. 196)

Strada Quattro Palazzina A6 c/o Centro Direzionale Milanofiori, 20057 Assago (MI).
www.innovery.net<http://www.innovery.net/> |  T: +39 06 519 63 439



From: midPoint <midpoint-bounces at lists.evolveum.com> On Behalf Of Richard Richter via midPoint
Sent: Wednesday, January 6, 2021 2:00 AM
To: midPoint General Discussion <midpoint at lists.evolveum.com>
Cc: Richard Richter <virgo at evolveum.com>
Subject: Re: [midPoint] Problem with java script with dates

Hello

Couple of points here:

  *   If possible, errors as copy/pasted text are better than images, it is easier to copy/paste from it for us too when Googling error messages.
  *   The script code is "nearly Java", it's actually Groovy and the message "Cannot compare" is error from Groovy language/runtime.
  *   As for the problem, this answer may help: https://stackoverflow.com/a/1333733/658826
The issue is that XMLGregorianCalendar really is not comparable, so it can't be used with > operator (which is Groovy extension, Java would not allow this between two objects).

Regards

Richard Richter
midPoint developer

________________________________
From: "midPoint General Discussion" <midpoint at lists.evolveum.com<mailto:midpoint at lists.evolveum.com>>
To: "midPoint General Discussion" <midpoint at lists.evolveum.com<mailto:midpoint at lists.evolveum.com>>
Cc: "Andrea Picconi" <andrea.picconi at innovery.net<mailto:andrea.picconi at innovery.net>>, "Marianna De Biasio" <marianna.debiasio at innovery.net<mailto:marianna.debiasio at innovery.net>>, "Jacopo Giuliano" <jacopo.giuliano at innovery.net<mailto:jacopo.giuliano at innovery.net>>
Sent: Tuesday, January 5, 2021 3:51:50 PM
Subject: [midPoint] Problem with java script with dates

Hi all,

we have a problem with an operation that should lead to outbound on an Oracle DB the furthest date in time between three dates that we have as values on MIDPOINT.
First example below just works if only one of the three (dates) attribute field is populated, when we have two fields populated it gives us an error:

<script xmlns:org="http://midpoint.evolveum.com/xml/ns/public/common/org-3">
    <code>
        import java.text.SimpleDateFormat;
        import java.text.DateFormat;

        graceful = Date1;
        if (Date2 != null) {
            if (graceful == null || Date2 > graceful) {
            graceful = Date2; }
            }
        else if (Date3 != null) {
            if (graceful == null || Date3 > graceful) {
            graceful = Date3; }
            }
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
        return df.format(com.evolveum.midpoint.util.MiscUtil.asDate(graceful));
    </code>
</script>

Below, instead, the error when we try with two or more fields populated:

[cid:image001.png at 01D6E7F9.9CB13360]

Any idea how to resolve it?

Thank you and regards,

Andrea Picconi
IAM (Identity Access Management)
[Innovery]
Skype: precons
T:  +39 06 51963439 (int. 196)

Strada Quattro Palazzina A6 c/o Centro Direzionale Milanofiori, 20057 Assago (MI).
www.innovery.net<http://www.innovery.net/> |  T: +39 06 519 63 439


_______________________________________________
midPoint mailing list
midPoint at lists.evolveum.com<mailto:midPoint at lists.evolveum.com>
https://lists.evolveum.com/mailman/listinfo/midpoint

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.evolveum.com/pipermail/midpoint/attachments/20210111/30753fb7/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 47210 bytes
Desc: image001.png
URL: <https://lists.evolveum.com/pipermail/midpoint/attachments/20210111/30753fb7/attachment-0003.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image002.png
Type: image/png
Size: 8058 bytes
Desc: image002.png
URL: <https://lists.evolveum.com/pipermail/midpoint/attachments/20210111/30753fb7/attachment-0004.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image004.png
Type: image/png
Size: 8058 bytes
Desc: image004.png
URL: <https://lists.evolveum.com/pipermail/midpoint/attachments/20210111/30753fb7/attachment-0005.png>


More information about the midPoint mailing list