Class SampleService

java.lang.Object
ai.nervemind.app.service.SampleService
All Implemented Interfaces:
ai.nervemind.common.service.SampleServiceInterface

@Service public class SampleService extends Object implements ai.nervemind.common.service.SampleServiceInterface
Service for loading, searching, and managing sample workflows. Samples are loaded from classpath resources and user's samples directory.
  • Constructor Details

    • SampleService

      public SampleService(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
      Creates a new SampleService with the given ObjectMapper.
      Parameters:
      objectMapper - the ObjectMapper for JSON processing
  • Method Details

    • loadSamples

      @PostConstruct public void loadSamples()
      Loads sample workflows from both user directory and classpath. User samples take priority over bundled samples.
    • reloadSamples

      public void reloadSamples()
      Reload all samples (e.g., after user adds new samples).
      Specified by:
      reloadSamples in interface ai.nervemind.common.service.SampleServiceInterface
    • getAllSamples

      public List<ai.nervemind.common.domain.SampleWorkflow> getAllSamples()
      Get all available samples.
      Specified by:
      getAllSamples in interface ai.nervemind.common.service.SampleServiceInterface
    • searchSamples

      public List<ai.nervemind.common.domain.SampleWorkflow> searchSamples(String query, String category, String language, ai.nervemind.common.domain.SampleWorkflow.Difficulty difficulty)
      Search samples with filters.
      Specified by:
      searchSamples in interface ai.nervemind.common.service.SampleServiceInterface
      Parameters:
      query - Search query (matches name, description, tags)
      category - Filter by category (null for all)
      language - Filter by language (null for all)
      difficulty - Filter by difficulty (null for all)
      Returns:
      Filtered list of samples
    • getCategories

      public List<String> getCategories()
      Get unique categories from all samples.
      Specified by:
      getCategories in interface ai.nervemind.common.service.SampleServiceInterface
    • getLanguages

      public List<String> getLanguages()
      Get unique languages from all samples.
      Specified by:
      getLanguages in interface ai.nervemind.common.service.SampleServiceInterface
    • findById

      public Optional<ai.nervemind.common.domain.SampleWorkflow> findById(String sampleId)
      Find a sample by ID.
      Specified by:
      findById in interface ai.nervemind.common.service.SampleServiceInterface
    • getWorkflowFromSample

      public ai.nervemind.common.domain.Workflow getWorkflowFromSample(String sampleId)
      Get the workflow from a sample (for importing).
      Specified by:
      getWorkflowFromSample in interface ai.nervemind.common.service.SampleServiceInterface
    • getSamplesByCategory

      public List<ai.nervemind.common.domain.SampleWorkflow> getSamplesByCategory(String category)
      Get samples by category.
      Parameters:
      category - the category to filter by
      Returns:
      list of samples in the specified category, sorted by difficulty
    • getSampleCountByDifficulty

      public Map<ai.nervemind.common.domain.SampleWorkflow.Difficulty, Long> getSampleCountByDifficulty()
      Get sample count by difficulty level.
      Returns:
      map of difficulty levels to sample counts
    • getFeaturedSamples

      public List<ai.nervemind.common.domain.SampleWorkflow> getFeaturedSamples(int limit)
      Get featured/recommended samples (e.g., for home screen).
      Specified by:
      getFeaturedSamples in interface ai.nervemind.common.service.SampleServiceInterface