Documentation ¶
Index ¶
- func BuildSituationsFromFile(path string, file string) (map[int64]*Situation, []error)
- func GetHistoryMetadata(situationID int64, t time.Time, templateInstanceID int64) ([]models.MetaData, error)
- func GetLastHistoryMetadata(situationID int64, templateInstanceID int64) ([]models.MetaData, error)
- func Persist(record HistoryRecord, evaluated bool) error
- func ReplaceGlobals(repository Repository) func()
- func SetAsEvaluated(situationID int64, t time.Time, templateInstanceID int64) error
- func UpdateExpressionFacts(record HistoryRecord) error
- func UpdateHistoryMetadata(situationID int64, t time.Time, templateInstanceID int64, ...) error
- type ExpressionFact
- type HistoryRecord
- type PostgresRepository
- func (r *PostgresRepository) AddRule(tx *sqlx.Tx, id int64, ruleID int64) error
- func (r *PostgresRepository) Create(situation Situation) (int64, error)
- func (r *PostgresRepository) CreateTemplateInstance(situationID int64, instance TemplateInstance) (int64, error)
- func (r *PostgresRepository) Delete(id int64) error
- func (r *PostgresRepository) DeleteTemplateInstance(instanceID int64) error
- func (r *PostgresRepository) Get(id int64) (Situation, bool, error)
- func (r *PostgresRepository) GetAll() (map[int64]Situation, error)
- func (r *PostgresRepository) GetAllByIDs(ids []int64) (map[int64]Situation, error)
- func (r *PostgresRepository) GetAllByRuleID(ruleID int64) (map[int64]Situation, error)
- func (r *PostgresRepository) GetAllTemplateInstances(situationID int64) (map[int64]TemplateInstance, error)
- func (r *PostgresRepository) GetByName(name string) (Situation, bool, error)
- func (r *PostgresRepository) GetFacts(id int64) ([]int64, error)
- func (r *PostgresRepository) GetRules(id int64) ([]int64, error)
- func (r *PostgresRepository) GetSituationsByFactID(factID int64, ignoreIsObject bool) ([]Situation, error)
- func (r *PostgresRepository) GetTemplateInstance(instanceID int64) (TemplateInstance, bool, error)
- func (r *PostgresRepository) RemoveRule(tx *sqlx.Tx, id int64, ruleID int64) error
- func (r *PostgresRepository) SetRules(id int64, rules []int64) error
- func (r *PostgresRepository) Update(id int64, situation Situation) error
- func (r *PostgresRepository) UpdateTemplateInstance(instanceID int64, instance TemplateInstance) error
- type Repository
- type Situation
- type TemplateInstance
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildSituationsFromFile ¶
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 GetHistoryMetadata ¶
func GetHistoryMetadata(situationID int64, t time.Time, templateInstanceID int64) ([]models.MetaData, error)
GetHistoryMetadata returns metadatas for a specific history entry (based on situation ID and timestamp)
func GetLastHistoryMetadata ¶
GetLastHistoryMetadata returns the metadatas of the last evaluation of a situation
func Persist ¶
func Persist(record HistoryRecord, evaluated bool) error
Persist persists a situation history record in postgresql
func ReplaceGlobals ¶
func ReplaceGlobals(repository Repository) func()
ReplaceGlobals affect a new repository to the global repository singleton
func SetAsEvaluated ¶
SetAsEvaluated sets as evaluated the situation instance history
func UpdateExpressionFacts ¶
func UpdateExpressionFacts(record HistoryRecord) error
UpdateExpressionFacts update the expression facts result on a situation history record
Types ¶
type ExpressionFact ¶
ExpressionFact represent a custom calculated fact based on gval expression
type HistoryRecord ¶
type HistoryRecord struct { ID int64 TS time.Time TemplateInstanceID int64 FactsIDS map[int64]*time.Time Parameters map[string]string EvaluatedExpressionFacts map[string]interface{} }
HistoryRecord represents a single and unique situation history entry
func GetFromHistory ¶
func GetFromHistory(situationID int64, t time.Time, templateInstanceID int64, closest bool) (*HistoryRecord, error)
GetFromHistory returns a single situation entry from postgresql It can be based on an exact timestamp, or return the closest result
func (HistoryRecord) OverrideParameters ¶
func (hr HistoryRecord) OverrideParameters(p map[string]string)
OverrideParameters overrides the parameters of the History Record
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) 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) (Situation, bool, error)
Get retrieve the specified situation definition
func (*PostgresRepository) GetAll ¶
func (r *PostgresRepository) GetAll() (map[int64]Situation, error)
GetAll returns all entities in the repository
func (*PostgresRepository) GetAllByIDs ¶ added in v4.2.0
func (r *PostgresRepository) GetAllByIDs(ids []int64) (map[int64]Situation, error)
GetAllByIDs returns all entities filtered by IDs in the repository
func (*PostgresRepository) GetAllByRuleID ¶
func (r *PostgresRepository) GetAllByRuleID(ruleID int64) (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) (map[int64]TemplateInstance, error)
GetAllTemplateInstances returns the list of template instances of the situation
func (*PostgresRepository) GetByName ¶
func (r *PostgresRepository) GetByName(name string) (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) ([]Situation, error)
GetSituationsByFactID returns the situations in which the fact is required
func (*PostgresRepository) GetTemplateInstance ¶
func (r *PostgresRepository) GetTemplateInstance(instanceID int64) (TemplateInstance, bool, error)
GetTemplateInstance returns the situation template instance
func (*PostgresRepository) RemoveRule ¶
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) (Situation, bool, error) GetByName(name string) (Situation, bool, error) Create(situation Situation) (int64, error) Update(id int64, situation Situation) error Delete(id int64) error GetAll() (map[int64]Situation, error) GetAllByIDs(ids []int64) (map[int64]Situation, error) GetAllByRuleID(ruleID int64) (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) ([]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) (TemplateInstance, bool, error) GetAllTemplateInstances(situationID int64) (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
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 ¶
IsValid checks if an internal schedule definition is valid and has no missing mandatory fields
func (Situation) MarshalJSON ¶
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"` }
TemplateInstance is a struct used to represent a situation template instance