-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Auto-generated Pull Request for feat/baserow-upload #363
Changes from all commits
37df94d
694c2c6
c33fa4d
22fa5de
d3ff5b6
eb6fd00
e059125
0905f43
e985838
7814f2b
f23c625
1afa73b
c3523c5
b975d2b
3111461
abc328d
cfae340
4524b72
4d6b261
3e4607a
9a13a6c
36da26c
3a9b4c3
c75f6ac
2a29868
43d0498
3dd1d30
0380405
7e421a3
5e79f30
cc3b5d7
3b480e2
7281356
8d8be35
4f6d3a3
2e5a8ad
57d7541
4e56951
e7c5aae
5ee39da
c0bcd90
1cb579b
01494ab
e9d2625
a0da8a5
0fadc36
58342b5
a3fa318
6827e1c
45c41bd
ed82f1a
0743abe
cecdd44
45e6f9f
175151f
9bc6a38
310aa72
5e5a5f9
3040675
345be4c
cdb27cc
543013f
c2a7317
e5508d8
0f778c6
98e9f90
d5668db
1b45b79
130149c
76d723b
a6c6264
c3b25ab
15e76c0
cc713c1
2f66cee
91ae54c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
package cli | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"slices" | ||
|
||
"github.com/dictyBase/modware-import/internal/baserow/client" | ||
"github.com/dictyBase/modware-import/internal/baserow/database" | ||
"github.com/dictyBase/modware-import/internal/baserow/ontology" | ||
"github.com/dictyBase/modware-import/internal/collection" | ||
"github.com/dictyBase/modware-import/internal/registry" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
func CreateDatabaseToken(cltx *cli.Context) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function |
||
atoken, err := database.AccessToken(&database.AccessTokenProperties{ | ||
Email: cltx.String("email"), | ||
Password: cltx.String("password"), | ||
Server: cltx.String("server"), | ||
}) | ||
if err != nil { | ||
return cli.Exit(fmt.Errorf("error in creating access token %s", err), 2) | ||
} | ||
bclient := database.BaserowClient(cltx.String("server")) | ||
authCtx := context.WithValue( | ||
context.Background(), | ||
client.ContextAccessToken, | ||
atoken, | ||
) | ||
wlist, r, err := bclient.WorkspacesApi.ListWorkspaces(authCtx). | ||
Execute() | ||
defer r.Body.Close() | ||
if err != nil { | ||
return cli.Exit( | ||
fmt.Errorf("error in executing list workspaces API call %s", err), | ||
2, | ||
) | ||
} | ||
wnames := collection.Map( | ||
wlist, | ||
func(w client.WorkspaceUserWorkspace) string { return w.GetName() }, | ||
) | ||
idx := slices.Index(wnames, cltx.String("workspace")) | ||
if idx == -1 { | ||
return cli.Exit( | ||
fmt.Errorf( | ||
"workspace %s cannot be found", | ||
cltx.String("workspace"), | ||
), | ||
2, | ||
) | ||
} | ||
tok, r, err := bclient.DatabaseTokensApi.CreateDatabaseToken(authCtx). | ||
TokenCreate(client.TokenCreate{ | ||
Name: cltx.String("name"), | ||
Workspace: wlist[idx].GetId(), | ||
}). | ||
Execute() | ||
defer r.Body.Close() | ||
if err != nil { | ||
return cli.Exit( | ||
fmt.Errorf("error in creating token %s", err), | ||
2, | ||
) | ||
} | ||
fmt.Printf("database token %s\n", tok.GetKey()) | ||
return nil | ||
} | ||
|
||
func CreateAccessToken(cltx *cli.Context) error { | ||
token, err := database.AccessToken(&database.AccessTokenProperties{ | ||
Email: cltx.String("email"), | ||
Password: cltx.String("password"), | ||
Server: cltx.String("server"), | ||
}) | ||
if err != nil { | ||
return cli.Exit(err, 2) | ||
} | ||
fmt.Println(token) | ||
return nil | ||
} | ||
|
||
func LoadOntologyToTable(cltx *cli.Context) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function |
||
logger := registry.GetLogger() | ||
bclient := database.BaserowClient(cltx.String("server")) | ||
authCtx := context.WithValue( | ||
context.Background(), | ||
client.ContextDatabaseToken, | ||
cltx.String("token"), | ||
) | ||
ontTbl := &database.OntologyTableManager{ | ||
TableManager: &database.TableManager{ | ||
Client: bclient, | ||
Logger: logger, | ||
Ctx: authCtx, | ||
Token: cltx.String("token"), | ||
DatabaseId: int32(cltx.Int("database-id")), | ||
}, | ||
} | ||
ok, err := ontTbl.CheckAllTableFields( | ||
&client.Table{Id: int32(cltx.Int("table-id"))}, | ||
) | ||
if err != nil { | ||
return cli.Exit(err.Error(), 2) | ||
} | ||
if !ok { | ||
return cli.Exit("table does not have the required fields", 2) | ||
} | ||
props := &ontology.LoadProperties{ | ||
File: cltx.String("input"), | ||
TableId: cltx.Int("table-id"), | ||
Token: cltx.String("token"), | ||
Client: bclient, | ||
Logger: logger, | ||
} | ||
if err := ontology.LoadNewOrUpdate(props); err != nil { | ||
return cli.Exit(err.Error(), 2) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func CreateOntologyTableHandler(cltx *cli.Context) error { | ||
logger := registry.GetLogger() | ||
bclient := database.BaserowClient(cltx.String("server")) | ||
authCtx := context.WithValue( | ||
context.Background(), | ||
client.ContextAccessToken, | ||
cltx.String("token"), | ||
) | ||
ontTbl := &database.OntologyTableManager{ | ||
TableManager: &database.TableManager{ | ||
Client: bclient, | ||
Logger: logger, | ||
Ctx: authCtx, | ||
Token: cltx.String("token"), | ||
DatabaseId: int32(cltx.Int("database-id")), | ||
}, | ||
} | ||
tbl, err := ontTbl.CreateTable(cltx.String("table"), ontTbl.FieldNames()) | ||
if err != nil { | ||
return cli.Exit(fmt.Sprintf("error in creating table %s", err), 2) | ||
} | ||
logger.Infof("created table with fields %s", tbl.GetName()) | ||
msg, err := ontTbl.UpdateField( | ||
tbl, | ||
"is_obsolete", | ||
map[string]interface{}{"name": "is_obsolete", "type": "boolean"}, | ||
) | ||
if err != nil { | ||
return cli.Exit( | ||
fmt.Sprintf("error in updating is_obsolete field %s", err), | ||
2, | ||
) | ||
} | ||
logger.Info(msg) | ||
return nil | ||
} |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
CreateDatabaseToken
has 6 return statements (exceeds 4 allowed).