Search in sources :

Example 1 with ViewCursor

use of io.lumeer.api.model.ViewCursor in project engine by Lumeer.

the class DelayedActionProcessor method processData.

// format due date to string according to attribute constraint format and user language
private Map<String, Object> processData(final DataDocument originalData, final Language language, final User receiverUser) {
    final Map<String, Object> data = new HashMap<>(originalData);
    if (originalData.getDate(DelayedAction.DATA_TASK_DUE_DATE) != null) {
        String format = translationManager.getDefaultDateFormat(language);
        if (StringUtils.isNotEmpty(originalData.getString(DelayedAction.DATA_DUE_DATE_FORMAT))) {
            format = originalData.getString(DelayedAction.DATA_DUE_DATE_FORMAT);
        }
        // we get the date in UTC and need to convert it to user's time zone, however, we send the date for parsing as an instant
        // instant is without a timezone, so we need to get epoch milli, as we were in UTC
        ZonedDateTime dueDate = ZonedDateTime.ofInstant(originalData.getDate(DelayedAction.DATA_TASK_DUE_DATE).toInstant(), ZoneOffset.UTC);
        if (receiverUser != null && StringUtils.isNotEmpty(receiverUser.getTimeZone())) {
            dueDate = dueDate.withZoneSameInstant(TimeZone.getTimeZone(receiverUser.getTimeZone()).toZoneId()).withZoneSameLocal(ZoneOffset.UTC);
        }
        data.put(DelayedAction.DATA_TASK_DUE_DATE, JsFunctionsParser.formatMomentJsDate(// originalData.getDate(DelayedAction.DATA_TASK_DUE_DATE).getTime(),
        dueDate.toInstant().toEpochMilli(), format, language.toString().toLowerCase(), false));
    }
    final String query = new Query(List.of(new QueryStem(originalData.getString(DelayedAction.DATA_COLLECTION_ID))), null, null, null).toQueryString();
    data.put(DelayedAction.DATA_COLLECTION_QUERY, Utils.encodeQueryParam(query));
    final String cursor = new ViewCursor(originalData.getString(DelayedAction.DATA_COLLECTION_ID), null, originalData.getString(DelayedAction.DATA_DOCUMENT_ID), null, originalData.getString(DelayedAction.DATA_TASK_NAME_ATTRIBUTE), true).toQueryString();
    data.put(DelayedAction.DATA_DOCUMENT_CURSOR, Utils.encodeQueryParam(cursor));
    data.remove(DelayedAction.DATA_ORIGINAL_ACTION_IDS);
    data.remove(DelayedAction.DATA_ORIGINAL_ACTION_TYPES);
    return data;
}
Also used : Query(io.lumeer.api.model.Query) HashMap(java.util.HashMap) ZonedDateTime(java.time.ZonedDateTime) QueryStem(io.lumeer.api.model.QueryStem) ViewCursor(io.lumeer.api.model.ViewCursor)

Aggregations

Query (io.lumeer.api.model.Query)1 QueryStem (io.lumeer.api.model.QueryStem)1 ViewCursor (io.lumeer.api.model.ViewCursor)1 ZonedDateTime (java.time.ZonedDateTime)1 HashMap (java.util.HashMap)1