MCPcopy
hub / github.com/daptin/daptin / UpdateStateMachineDescriptions

Function UpdateStateMachineDescriptions

server/resource/dbfunctions_update.go:510–602  ·  view source on GitHub ↗
(initConfig *CmsConfig, db *sqlx.Tx)

Source from the content-addressed store, hash-verified

508}
509
510func UpdateStateMachineDescriptions(initConfig *CmsConfig, db *sqlx.Tx) {
511
512 log.Debugf("We have %d state machine descriptions", len(initConfig.StateMachineDescriptions))
513
514 adminUserId, _ := GetAdminUserIdAndUserGroupId(db)
515
516 for i := range initConfig.Tables {
517 ar := make([]fsm.LoopbookFsmDescription, 0)
518 initConfig.Tables[i].StateMachines = ar
519 }
520
521 for _, smd := range initConfig.StateMachineDescriptions {
522
523 log.Tracef("Update StateMachineDescriptions: [%s]", smd.Name)
524 s, v, err := statementbuilder.Squirrel.
525 Select("reference_id").
526 Prepared(true).From("smd").Where(goqu.Ex{"name": smd.Name}).ToSQL()
527 if err != nil {
528 log.Errorf("Failed to create select smd query: %v", err)
529 continue
530 }
531
532 var refId daptinid.DaptinReferenceId
533
534 stmt1, err := db.Preparex(s)
535 if err != nil {
536 log.Errorf("[541] failed to prepare statment: %v", err)
537 }
538 defer stmt1.Close()
539 err = stmt1.QueryRowx(v...).Scan(&refId)
540 if err != nil {
541
542 // no existing row
543
544 eventsDescription, err := json.Marshal(smd.Events)
545 if err != nil {
546 log.Errorf("Failed to convert to json: %v", err)
547 continue
548 }
549 u, _ := uuid.NewV7()
550
551 insertMap := map[string]interface{}{}
552 insertMap["name"] = smd.Name
553 insertMap["label"] = smd.Label
554 insertMap["initial_state"] = smd.InitialState
555 insertMap["events"] = eventsDescription
556 insertMap["reference_id"] = u[:]
557 insertMap["permission"] = auth.DEFAULT_PERMISSION
558 insertMap[USER_ACCOUNT_ID_COLUMN] = adminUserId
559 s, v, err := statementbuilder.Squirrel.Insert("smd").Prepared(true).Rows(insertMap).ToSQL()
560
561 if err != nil {
562 log.Errorf("Failed to create update smd query: %v", err)
563 continue
564 }
565
566 _, err = db.Exec(s, v...)
567 if err != nil {

Callers 2

GetResourceFunction · 0.92

Calls 10

makeFunction · 0.85
ScanMethod · 0.80
QueryRowxMethod · 0.80
ExecMethod · 0.80
SetMethod · 0.80
SelectMethod · 0.65
PreparexMethod · 0.65
CloseMethod · 0.65
UpdateMethod · 0.65

Tested by 1

GetResourceFunction · 0.74