R

36 Messages

 • 

400 Points

Thursday, February 15th, 2024 7:34 AM

add epoch based date to Collibra date attribute

Hi Guys

Once again I spend a lot of time trying to do something that should be very simple and supported with conscise docuementaion. Alas Collibra is not

I have a need to add a “Due Date” to a new Issue Asset. As I understand, from what I have read, the date must be in an Epoch representation

I have written this code and I was under the impression that it meets the criteria

import java.time.*

// get the current date in UTC
def date = LocalDate.now(ZoneId.of(‘UTC’))

// get the start of the day (midnight) in UTC
def startOfDay = date.atStartOfDay(ZoneId.of(‘UTC’))

// convert to epoch milliseconds
def epochMillis = startOfDay.toInstant().toEpochMilli()

// print the result
loggerApi.info("createIssue : CP 010 The value of epochMillis1 is " + epochMillis1)

When I run my code the date created is 1707955200000, looks fine to me

I next add this epoch date to my workflow script and run it
attribute = attributeApi.addAttribute(AddAttributeRequest.builder()
.assetId(newIssueUuid)
. typeId(string2Uuid(“018d9dd4-bbd5-71ae-b09f-3ca50428644f”))
.value(“1707955200000”) <<<<<<<
.build())

And I get the error message
Value not allowed
The date with time stamp 1,707,980,755 is not in UTC at midnight. Example correct date: Fri Feb 10 00:00:00 UTC 2017 which is equal to timestamp: 1486684800000.

Can someone please provide me with clear example of how to add a date to a date defined attribute in collibra or point me to the documentation that does this

Best Regard
Bobby

Accepted Solution

67 Messages

 • 

1.6K Points

3 months ago

I think the issue with the code is it is using a string to pass the date into the .value field. Instead, I think the field needs a long value.

The way I read it in the documentation – I think you can only use a string value when the date is formatted as an ISO calendar date and must use a long value for timestamps. I was able to get an example working correctly where I just passed the variable you defined as epochMillis directly to the asset and it was accepted as a due date (I attached a bpmn file with the code i used).I changed the typeId to match the resource code in my environment, so you’ll need to change it back.

import com.collibra.dgc.core.api.model.ResourceType
import com.collibra.dgc.core.api.dto.instance.attribute.AddAttributeRequest
import java.time.*

// get the current date in UTC
def date = LocalDate.now(ZoneId.of('UTC'))
loggerApi.info(date.toString())
// get the start of the day (midnight) in UTC
def startOfDay = date.atStartOfDay(ZoneId.of('UTC'))
loggerApi.info(startOfDay.toString())
// convert to epoch milliseconds
def epochMillis = startOfDay.toInstant().toEpochMilli()
// print the result
loggerApi.info(epochMillis.toString())

//add date as attribute to Issue asset.
attribute = attributeApi.addAttribute(AddAttributeRequest.builder()
.assetId(item.id) //used workflow bean here just to test
.typeId(string2Uuid("018dad73-8231-7ea2-ba27-958251b98b6a")) //ID for Due Date Asset Attribute
.value(epochMillis)
.build()
)

36 Messages

 • 

400 Points

3 months ago

Thanks Sean

I have now tried this and it worsk fine, even after I have manipulated the date. So thanks for this.

Can I suggest that this and other useful snippets of code (valid cron entries) are documented for others to see and use?

Regards
Bobby

Loading...