All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.fivefaces.cloud.workflow.awsonprem.model.Execution Maven / Gradle / Ivy

There is a newer version: 1.0.0
Show newest version
package com.fivefaces.cloud.workflow.awsonprem.model;

import com.fivefaces.cloud.workflow.awsonprem.StateMachineConstants;
import com.fivefaces.cloud.workflow.awsonprem.utils.JsonUtil;
import com.jayway.jsonpath.DocumentContext;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;

import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Setter
@Getter
@RequiredArgsConstructor
public class Execution {

    private final JsonUtil jsonUtil;
    private Map context = new HashMap<>();
    private List logs = new ArrayList<>();
    private StateLog currentStateLog;
    private DocumentContext input;

    public void addLog(String stateName) {
        if (debug()) {
            finishLog();
            StateLog stateLog = new StateLog(stateName, jsonUtil.read(input.jsonString()));
            logs.add(stateLog);
            currentStateLog = stateLog;
        }
    }

    public void addSubProcessLogs(List logs) {
        if (debug() && currentStateLog != null) {
            currentStateLog.setSubProcessLogs(logs);
        }
    }

    public void finishLog() {
        if (debug() && currentStateLog != null && currentStateLog.getExecutionMilliseconds() == null) {
            currentStateLog.setExecutionMilliseconds(ChronoUnit.MILLIS.between(currentStateLog.getStartedAt(), Instant.now()));
            currentStateLog.setOutput(jsonUtil.read(input.jsonString()));
        }
    }

    public void addCondition(String condition) {
        if (debug() && currentStateLog != null) {
            currentStateLog.getConditions().add(condition);
        }
    }

    public boolean debug() {
        return Boolean.TRUE.equals(context.get(StateMachineConstants.DEBUG));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy