Class ProcessRunner

java.lang.Object
neqsim.mcp.runners.ProcessRunner

public class ProcessRunner extends Object
Stateless process simulation runner for MCP integration.

Accepts a JSON process definition, optionally pre-validates it using Validator, then builds and runs the process using ProcessSystem.fromJsonAndRun(String). Returns the simulation result as a JSON string in the standard envelope format.

Input JSON Format:

{ "fluid": { "model": "SRK", "temperature": 298.15, "pressure": 50.0, "mixingRule":
"classic", "components": {"methane": 0.85, "ethane": 0.10, "propane": 0.05} }, "process": [
{"type": "Stream", "name": "feed", "properties": {"flowRate": [50000.0, "kg/hr"]}}, {"type":
"Separator", "name": "HP Sep", "inlet": "feed"}, {"type": "Compressor", "name": "Comp", "inlet":
"HP Sep.gasOut", "properties": {"outletPressure": [80.0, "bara"]}} ] } 
Author:
Even Solbraa @version 1.0
  • Field Details

    • GSON

      private static final com.google.gson.Gson GSON
  • Constructor Details

    • ProcessRunner

      private ProcessRunner()
      Private constructor — all methods are static.
  • Method Details

    • run

      public static String run(String json)
      Runs a process simulation from a JSON definition string.

      Delegates to ProcessSystem.fromJsonAndRun(String) and returns the result in the standard JSON envelope format with status, report, and any warnings or errors.

      Parameters:
      json - the JSON process definition
      Returns:
      a JSON string with the simulation result
    • validateAndRun

      public static String validateAndRun(String json)
      Validates and then runs a process simulation.

      First performs pre-flight validation using Validator. If validation finds errors, returns them without running the simulation. If only warnings are found, proceeds with the simulation and includes the validation warnings in the response.

      Parameters:
      json - the JSON process definition
      Returns:
      a JSON string with validation issues and/or simulation results
    • runTyped

      public static ApiEnvelope<ProcessResult> runTyped(String json)
      Runs a process simulation and returns a typed result.

      This is the typed counterpart to run(String). It accepts a JSON string (same format) but returns a typed ApiEnvelope with a ProcessResult payload for direct Java consumers.

      Parameters:
      json - the JSON process definition
      Returns:
      an ApiEnvelope containing the ProcessResult on success, or errors on failure
    • extractModel

      private static String extractModel(String json)
      Extracts the EOS model name from the input JSON.
      Parameters:
      json - the input JSON string
      Returns:
      the model name, or "SRK" as default
    • extractMixingRule

      private static String extractMixingRule(String json)
      Extracts the mixing rule from the input JSON.
      Parameters:
      json - the input JSON string
      Returns:
      the mixing rule, or "classic" as default
    • extractEquipmentCount

      private static int extractEquipmentCount(String json)
      Counts the number of equipment entries in the process definition.
      Parameters:
      json - the input JSON string
      Returns:
      the equipment count, or 0 if not parseable
    • normalizeProcessJson

      private static String normalizeProcessJson(String json)
      Normalizes accepted process JSON variants to the canonical schema.

      Canonical schema expects process to be an array. Some legacy clients send {"process": {"equipment": [...]}}. This method converts the legacy shape to the canonical one while preserving all other fields.

      Parameters:
      json - raw process JSON
      Returns:
      canonical JSON string (or original input if not parseable)
    • normalizeLegacyPropertyObjects

      private static void normalizeLegacyPropertyObjects(com.google.gson.JsonObject properties)
      Converts legacy {value, unit} property objects to [value, unit] arrays expected by the JsonProcessBuilder reflection setter logic.
      Parameters:
      properties - mutable properties object
    • errorJson

      private static String errorJson(String code, String message, String remediation)
      Creates a standard error JSON response.
      Parameters:
      code - the error code
      message - the error message
      remediation - the fix suggestion
      Returns:
      JSON error string