Search in sources :

Example 1 with DocumentCommentedEvent

use of io.lumeer.engine.api.event.DocumentCommentedEvent in project engine by Lumeer.

the class AbstractPurposeChangeDetector method getData.

protected DataDocument getData(final DocumentEvent documentEvent, final Collection collection, final String currentAssignee, final Set<Assignee> assignees) {
    final DataDocument data = new DataDocument();
    if (selectedWorkspace.getOrganization().isPresent()) {
        final Organization organization = selectedWorkspace.getOrganization().get();
        data.append(DelayedAction.DATA_ORGANIZATION_ID, organization.getId());
    }
    if (selectedWorkspace.getProject().isPresent()) {
        final Project project = selectedWorkspace.getProject().get();
        data.append(DelayedAction.DATA_PROJECT_ID, project.getId());
    }
    data.append(DelayedAction.DATA_TASK_COMPLETED, isDoneState(documentEvent, collection));
    data.append(DelayedAction.DATA_TASK_STATE, getState(documentEvent, collection));
    data.append(DelayedAction.DATA_TASK_NAME, getDescription(documentEvent, collection));
    data.append(DelayedAction.DATA_TASK_NAME_ATTRIBUTE, getDescriptionAttribute(documentEvent, collection));
    var dueDate = getDueDate(documentEvent, collection);
    if (dueDate != null) {
        // update the time according to the user's time zone if there is also time stored
        if (!CollectionUtil.isDueDateInUTC(collection)) {
            final Optional<String> userTimeZone = assignees.stream().filter(a -> a.getEmail().equals(currentAssignee) && StringUtils.isNotEmpty(a.getTimeZone())).map(Assignee::getTimeZone).findFirst();
            if (userTimeZone.isPresent()) {
                final TimeZone tz = TimeZone.getTimeZone(userTimeZone.get());
                dueDate = dueDate.withZoneSameInstant(tz.toZoneId());
            }
        }
        data.append(DelayedAction.DATA_TASK_DUE_DATE, new Date(dueDate.toInstant().toEpochMilli()));
    }
    data.append(DelayedAction.DATA_DUE_DATE_FORMAT, getDueDateFormat(documentEvent, collection));
    // collect to set so that each value is present only once
    data.append(DelayedAction.DATA_ASSIGNEE, String.join(", ", assignees.stream().map(Assignee::getEmail).collect(Collectors.toSet())));
    data.append(DelayedAction.DATA_ASSIGNEE_VIA_TEAM_ONLY, assignees.contains(new Assignee(currentAssignee, true)) && !assignees.contains(new Assignee(currentAssignee, false)));
    data.append(DelayedAction.DATA_COLLECTION_ID, collection.getId());
    data.append(DelayedAction.DATA_DOCUMENT_ID, documentEvent.getDocument().getId());
    if (documentEvent instanceof DocumentCommentedEvent) {
        data.append(DelayedAction.DATA_TASK_COMMENT, ((DocumentCommentedEvent) documentEvent).getComment().getComment());
    }
    return data;
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) Project(io.lumeer.api.model.Project) TimeZone(java.util.TimeZone) Organization(io.lumeer.api.model.Organization) DocumentCommentedEvent(io.lumeer.engine.api.event.DocumentCommentedEvent) Date(java.util.Date)

Aggregations

Organization (io.lumeer.api.model.Organization)1 Project (io.lumeer.api.model.Project)1 DataDocument (io.lumeer.engine.api.data.DataDocument)1 DocumentCommentedEvent (io.lumeer.engine.api.event.DocumentCommentedEvent)1 Date (java.util.Date)1 TimeZone (java.util.TimeZone)1