situation

package
v5.4.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildSituationsFromFile

func BuildSituationsFromFile(path string, file string) (map[int64]*Situation, []error)

BuildSituationsFromFile reads an ensemble of situations from the provided file and returns them Deprecated: Situation loading from YAML file has been replaced by standard REST API

func ReplaceGlobals

func ReplaceGlobals(repository Repository) func()

ReplaceGlobals affect a new repository to the global repository singleton

func ReplaceKeysWithValues added in v5.3.5

func ReplaceKeysWithValues(m map[string]string, variables map[string]interface{})

func UpdateParametersWithConfig added in v5.3.5

func UpdateParametersWithConfig(params map[string]string)

Types

type ExpressionFact

type ExpressionFact struct {
	Name       string `json:"name"`
	Expression string `json:"expression"`
}

ExpressionFact represent a custom calculated fact based on gval expression

type PostgresRepository

type PostgresRepository struct {
	// contains filtered or unexported fields
}

PostgresRepository is a repository containing the situation definition based on a PSQL database and implementing the repository interface

func (*PostgresRepository) AddRule

func (r *PostgresRepository) AddRule(tx *sqlx.Tx, id int64, ruleID int64) error

AddRule adds a rule ad the end of the situation rule list

func (*PostgresRepository) Create

func (r *PostgresRepository) Create(situation Situation) (int64, error)

Create creates a new situation in the database using the given situation object

func (*PostgresRepository) CreateTemplateInstance

func (r *PostgresRepository) CreateTemplateInstance(situationID int64, instance TemplateInstance) (int64, error)

CreateTemplateInstance creates a situation template instance

func (*PostgresRepository) Delete

func (r *PostgresRepository) Delete(id int64) error

Delete deletes an entity from the repository by its name

func (*PostgresRepository) DeleteTemplateInstance

func (r *PostgresRepository) DeleteTemplateInstance(instanceID int64) error

DeleteTemplateInstance deletes a situation template instance

func (*PostgresRepository) Get

func (r *PostgresRepository) Get(id int64, parseGlobalVariables ...bool) (Situation, bool, error)

Get retrieve the specified situation definition

func (*PostgresRepository) GetAll

func (r *PostgresRepository) GetAll(parseGlobalVariables ...bool) (map[int64]Situation, error)

GetAll returns all entities in the repository

func (*PostgresRepository) GetAllByIDs

func (r *PostgresRepository) GetAllByIDs(ids []int64, parseGlobalVariables ...bool) (map[int64]Situation, error)

GetAllByIDs returns all entities filtered by IDs in the repository

func (*PostgresRepository) GetAllByRuleID

func (r *PostgresRepository) GetAllByRuleID(ruleID int64, parseGlobalVariables ...bool) (map[int64]Situation, error)

GetAllByRuleID returns all entities in the repository based on a rule ID

func (*PostgresRepository) GetAllTemplateInstances

func (r *PostgresRepository) GetAllTemplateInstances(situationID int64, parseGlobalVariables ...bool) (map[int64]TemplateInstance, error)

GetAllTemplateInstances returns the list of template instances of the situation

func (*PostgresRepository) GetByName

func (r *PostgresRepository) GetByName(name string, parseGlobalVariables ...bool) (Situation, bool, error)

GetByName retrieve the specified situation definition by it's name

func (*PostgresRepository) GetFacts

func (r *PostgresRepository) GetFacts(id int64) ([]int64, error)

GetFacts returns the list of facts

func (*PostgresRepository) GetRules

func (r *PostgresRepository) GetRules(id int64) ([]int64, error)

GetRules returns the list of rules used in to evaluate the situation

func (*PostgresRepository) GetSituationsByFactID

func (r *PostgresRepository) GetSituationsByFactID(factID int64, ignoreIsObject bool, parseGlobalVariables ...bool) ([]Situation, error)

GetSituationsByFactID returns the situations in which the fact is required

func (*PostgresRepository) GetTemplateInstance

func (r *PostgresRepository) GetTemplateInstance(instanceID int64, parseGlobalVariables ...bool) (TemplateInstance, bool, error)

GetTemplateInstance returns the situation template instance

func (*PostgresRepository) RemoveRule

func (r *PostgresRepository) RemoveRule(tx *sqlx.Tx, id int64, ruleID int64) error

RemoveRule removes a rule ad the end of the situation rule list

func (*PostgresRepository) SetRules

func (r *PostgresRepository) SetRules(id int64, rules []int64) error

SetRules sets the list of rules for the situation evaluation

func (*PostgresRepository) Update

func (r *PostgresRepository) Update(id int64, situation Situation) error

Update updates an entity in the repository by its name

func (*PostgresRepository) UpdateTemplateInstance

func (r *PostgresRepository) UpdateTemplateInstance(instanceID int64, instance TemplateInstance) error

UpdateTemplateInstance updates a situation template instance

type Repository

type Repository interface {
	Get(id int64, parseGlobalVariables ...bool) (Situation, bool, error)
	GetByName(name string, parseGlobalVariables ...bool) (Situation, bool, error)
	Create(situation Situation) (int64, error)
	Update(id int64, situation Situation) error
	Delete(id int64) error
	GetAll(parseGlobalVariables ...bool) (map[int64]Situation, error)
	GetAllByIDs(ids []int64, parseGlobalVariables ...bool) (map[int64]Situation, error)
	GetAllByRuleID(ruleID int64, parseGlobalVariables ...bool) (map[int64]Situation, error)

	GetRules(id int64) ([]int64, error)
	SetRules(id int64, rules []int64) error
	AddRule(tx *sqlx.Tx, id int64, ruleID int64) error
	RemoveRule(tx *sqlx.Tx, id int64, ruleID int64) error
	GetSituationsByFactID(factID int64, ignoreIsObject bool, parseGlobalVariables ...bool) ([]Situation, error)
	GetFacts(id int64) ([]int64, error)

	CreateTemplateInstance(situationID int64, instance TemplateInstance) (int64, error)
	UpdateTemplateInstance(instanceID int64, instance TemplateInstance) error
	DeleteTemplateInstance(instanceID int64) error
	GetTemplateInstance(instanceID int64, parseGlobalVariables ...bool) (TemplateInstance, bool, error)
	GetAllTemplateInstances(situationID int64, parseGlobalVariables ...bool) (map[int64]TemplateInstance, error)
}

Repository is a storage interface which can be implemented by multiple backend (in-memory map, sql database, in-memory cache, file system, ...) It allows standard CRUD operation on situations

func NewPostgresRepository

func NewPostgresRepository(dbClient *sqlx.DB) Repository

NewPostgresRepository returns a new instance of PostgresRepository

func R

func R() Repository

R is used to access the global repository singleton

type Situation

type Situation struct {
	ID              int64             `json:"id,omitempty"`
	Name            string            `json:"name"`
	Facts           []int64           `json:"facts"`
	CalendarID      int64             `json:"calendarId"`
	Parameters      map[string]string `json:"parameters"`
	ExpressionFacts []ExpressionFact  `json:"expressionFacts"`
	IsTemplate      bool              `json:"isTemplate"`
	IsObject        bool              `json:"isObject"`
}

Situation is a struct used to represent a situation (or an ensemble of fact)

func (Situation) IsValid

func (s Situation) IsValid() (bool, error)

IsValid checks if an internal schedule definition is valid and has no missing mandatory fields

func (Situation) MarshalJSON

func (s Situation) MarshalJSON() ([]byte, error)

MarshalJSON marshals a Situation as a json object

type TemplateInstance

type TemplateInstance struct {
	ID                  int64             `json:"id"`
	Name                string            `json:"name"`
	SituationID         int64             `json:"situationId"`
	Parameters          map[string]string `json:"parameters"`
	CalendarID          int64             `json:"calendarId"`
	EnableDependsOn     bool              `json:"enableDependsOn"`
	DependsOnParameters map[string]string `json:"dependsOnParameters"`
}

TemplateInstance is a struct used to represent a situation template instance

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL