Class AutomationProjectManager

java.lang.Object
io.github.jspinak.brobot.runner.project.AutomationProjectManager

@Component public class AutomationProjectManager extends Object
Manages the active project configuration in the Brobot framework.

AutomationProjectManager serves as the central repository for project-level configuration, maintaining the currently active Project and providing mechanisms to load new projects from JSON definitions. A Project in Brobot encapsulates all the configuration, states, transitions, and settings needed for a complete automation solution.

Key responsibilities:

  • Project Loading: Deserializes project definitions from JSON format
  • Active Project Management: Maintains reference to the current project
  • Configuration Parsing: Leverages JsonParser for robust JSON handling
  • Project Switching: Supports changing active projects at runtime

Project lifecycle:

  1. Load project configuration from JSON string or file
  2. Parse and validate the project structure
  3. Set as active project for the automation framework
  4. All services access configuration through this manager

JSON project format:

  • States and their configurations
  • State transitions and navigation paths
  • Project-specific settings and parameters
  • Image resources and recognition patterns

Common usage patterns:

  • Load project at application startup
  • Switch projects for different automation tasks
  • Access project configuration from various services
  • Reload project after external modifications

Error handling:

  • Throws ConfigurationException for invalid JSON
  • Validates project structure during loading
  • Maintains previous project on load failure

In the model-based approach, AutomationProjectManager is the gateway to the automation model. It transforms declarative project definitions into the runtime configuration that drives all automation behavior. This separation of configuration from code enables non-programmers to create and modify automation projects through visual tools or direct JSON editing.

Since:
1.0
See Also:
  • Constructor Details

    • AutomationProjectManager

      public AutomationProjectManager(ConfigurationParser jsonParser)
      Constructs an AutomationProjectManager with required JSON parsing capability.
      Parameters:
      jsonParser - Parser for handling project JSON deserialization
  • Method Details

    • loadProject

      public void loadProject(String json) throws ConfigurationException
      Loads a project from a JSON string representation.

      Deserializes the JSON into a Project object and sets it as the active project. The JSON must conform to the Project schema with all required fields properly defined.

      Side effects:

      • Replaces the current active project
      • Does not backup previous project
      • May leave activeProject unchanged on parse failure

      Example JSON structure:

       {
         "name": "MyAutomation",
         "states": [...],
         "transitions": [...],
         "settings": {...}
       }
       
      Parameters:
      json - JSON string containing project definition
      Throws:
      ConfigurationException - if JSON is invalid or missing required fields
      See Also:
    • getAvailableProjects

      public List<String> getAvailableProjects()
      Gets the list of available projects. For now, returns a simple list with a default project.
      Returns:
      List of available project names
    • getCurrentProject

      public AutomationProject getCurrentProject()
      Gets the currently active project.
      Returns:
      The current AutomationProject or null if none is loaded
    • refreshProjects

      public void refreshProjects()
      Refreshes the list of available projects. For now, this is a no-op.
    • getJsonParser

      public ConfigurationParser getJsonParser()
      Parser for deserializing JSON project definitions. Handles complex project structures with polymorphic types.
    • getActiveProject

      public AutomationProject getActiveProject()
      The currently active project configuration.

      Contains all states, transitions, and settings for the current automation task. May be null before initial project loading.

    • setActiveProject

      public void setActiveProject(AutomationProject activeProject)
      The currently active project configuration.

      Contains all states, transitions, and settings for the current automation task. May be null before initial project loading.