Skip to content
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

Merged
merged 76 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
37df94d
feat(table.go): add field creation functionality and refactor table f…
cybersiddhu Feb 20, 2024
694c2c6
refactor(table.go): rename function and variable names for clarity an…
cybersiddhu Feb 20, 2024
c33fa4d
refactor(table.go): extract logic from LoadOntologyToTable to CreateO…
cybersiddhu Feb 20, 2024
22fa5de
refactor(cli): move flag functions from table.go to new file flag.go …
cybersiddhu Feb 20, 2024
d3ff5b6
refactor(cli): move CreateAccessTokenFlag and CreateDatabaseTokenFlag…
cybersiddhu Feb 20, 2024
eb6fd00
refactor: move database related functions from cli to database package
cybersiddhu Feb 20, 2024
e059125
feat(database): add table.go for handling database table fields
cybersiddhu Feb 20, 2024
0905f43
feat(.golangci.yml): enable unused linter's local-variables-are-used …
cybersiddhu Feb 20, 2024
e985838
feat(cli/action.go): add new functions for database token creation, a…
cybersiddhu Feb 20, 2024
7814f2b
refactor(action.go): rename function parameter from 'c' to 'cltx' for…
cybersiddhu Feb 20, 2024
f23c625
refactor(database/table.go): move fieldMap from CreateOntologyTableFi…
cybersiddhu Feb 20, 2024
1afa73b
feat(flag.go): add 'input' flag for json formatted ontology file
cybersiddhu Feb 20, 2024
c3523c5
feat(action.go): add loadOntology function to handle ontology loading
cybersiddhu Feb 20, 2024
b975d2b
feat(load.go): add commonHeader function to set request headers
cybersiddhu Feb 20, 2024
3111461
feat(load.go): add reqToResponse function to handle HTTP requests and…
cybersiddhu Feb 20, 2024
abc328d
feat(load.go): add termStatus function to check if term is deprecated
cybersiddhu Feb 20, 2024
cfae340
feat(load.go): add addTermRow function to post term data to baserow
cybersiddhu Feb 20, 2024
4524b72
feat(load.go): add LoadNew function to load new ontology terms
cybersiddhu Feb 20, 2024
4d6b261
fix(action.go): correct error handling in LoadOntologyToTable function
cybersiddhu Feb 20, 2024
3e4607a
feat(load.go): add existTermRow function to check term presence in da…
cybersiddhu Feb 21, 2024
9a13a6c
feat(load.go): add updateTermRow function to update term row
cybersiddhu Feb 21, 2024
36da26c
feat(load.go): add support for checking if term row exists and is dep…
cybersiddhu Feb 21, 2024
3a9b4c3
feat(load.go): add addTermRow function to add new term rows
cybersiddhu Feb 21, 2024
c75f6ac
refactor(load.go): rename LoadNew to LoadNewOrUpdate and refactor its…
cybersiddhu Feb 21, 2024
2a29868
refactor(load.go): simplify termStatus function call in updateTermRow…
cybersiddhu Feb 21, 2024
43d0498
feat(load.go): add check for term existence and deprecation status be…
cybersiddhu Feb 21, 2024
3dd1d30
refactor(table.go): modify CreateOntologyTableFields function to retu…
cybersiddhu Feb 21, 2024
0380405
feat(action.go): add ontology loading functionality to LoadOntologyTo…
cybersiddhu Feb 21, 2024
7e421a3
feat(httpapi): add new httpapi package with common header and request…
cybersiddhu Feb 23, 2024
5e79f30
feat(database): add ontology.go for managing ontology tables
cybersiddhu Feb 23, 2024
cc3b5d7
refactor(action.go): streamline table creation and field checking pro…
cybersiddhu Feb 23, 2024
3b480e2
feat(ontology.go): add FieldNames function to return field names
cybersiddhu Feb 23, 2024
7281356
refactor(flag.go): rename CreateTableFlag to CreateOntologyTableFlag …
cybersiddhu Feb 23, 2024
8d8be35
refactor(action.go): replace manual field extraction with FieldNames …
cybersiddhu Feb 23, 2024
4f6d3a3
refactor(action.go): rearrange the order of struct fields for better …
cybersiddhu Feb 23, 2024
2e5a8ad
refactor(main.go): rename 'create-table' command to 'create-ontology-…
cybersiddhu Feb 23, 2024
57d7541
remove(table.go): delete the table.go file from the baserow/database …
cybersiddhu Feb 23, 2024
4e56951
refactor(load.go): move commonHeader and reqToResponse functions to h…
cybersiddhu Feb 23, 2024
e7c5aae
refactor(ontology.go): replace API call with direct HTTP request for …
cybersiddhu Feb 23, 2024
5ee39da
refactor(action.go): add token field to LoadOntologyToTable function
cybersiddhu Feb 23, 2024
c0bcd90
fix(action.go): remove table name from error message in LoadOntologyT…
cybersiddhu Feb 23, 2024
1cb579b
refactor(load.go): update ontologyRow struct to improve data represen…
cybersiddhu Feb 23, 2024
01494ab
fix(load.go): change authentication type from Bearer to Token in Comm…
cybersiddhu Feb 23, 2024
e9d2625
fix(load.go): ensure secure HTTPS protocol for API requests
cybersiddhu Feb 23, 2024
a0da8a5
refactor(load.go): change payload keys to snake_case for consistency
cybersiddhu Feb 23, 2024
0fadc36
feat(database): add TableManager struct and CreateTable method in tab…
cybersiddhu Feb 23, 2024
58342b5
refactor(ontology.go): simplify OntologyTableManager struct and remov…
cybersiddhu Feb 23, 2024
a3fa318
refactor(ontology.go): replace tableId and fields parameters with a s…
cybersiddhu Feb 23, 2024
6827e1c
refactor(action.go): encapsulate common fields into TableManager stru…
cybersiddhu Feb 23, 2024
45c41bd
feat(table.go): add TableFieldsResp function to fetch table fields
cybersiddhu Feb 23, 2024
ed82f1a
refactor(ontology.go): extract HTTP request creation and execution to…
cybersiddhu Feb 23, 2024
0743abe
feat(httpapi/api.go): add JWT and Token authorization support
cybersiddhu Feb 23, 2024
cecdd44
feat(table.go): add TableFieldsDelURL and TableFieldsURL methods for …
cybersiddhu Feb 26, 2024
45e6f9f
feat(table.go): add fields parameter to CreateTable function and set …
cybersiddhu Feb 26, 2024
175151f
feat(ontology.go): add new types and functions to handle field deleti…
cybersiddhu Feb 26, 2024
9bc6a38
feat(ontology.go): add RemoveExtraField function to handle deletion o…
cybersiddhu Feb 26, 2024
310aa72
refactor(ontology.go): move FieldNames and FieldDefs functions to Ont…
cybersiddhu Feb 26, 2024
5e5a5f9
refactor(action.go): modify CreateTable function to include field names
cybersiddhu Feb 26, 2024
3040675
refactor(table.go): rename TableFieldsDelURL to TableFieldsChangeURL …
cybersiddhu Feb 26, 2024
345be4c
feat(ontology.go): add ListTableFields function to list all table fields
cybersiddhu Feb 26, 2024
cdb27cc
refactor(database): move table related functions from ontology.go to …
cybersiddhu Feb 26, 2024
543013f
feat(table.go): add HasField function to check if a field exists in t…
cybersiddhu Feb 26, 2024
c2a7317
refactor(ontology.go): rename RemoveExtraField to RemoveField and add…
cybersiddhu Feb 26, 2024
e5508d8
refactor(ontology.go, table.go): move RemoveField function from ontol…
cybersiddhu Feb 26, 2024
0f778c6
refactor(ontology.go): change success message for field deletion
cybersiddhu Feb 26, 2024
98e9f90
refactor(database): move field deletion related functions and types f…
cybersiddhu Feb 26, 2024
d5668db
feat(table.go): introduce FieldDefinition interface to abstract field…
cybersiddhu Feb 26, 2024
1b45b79
feat(table.go): add UpdateField method to update table fields
cybersiddhu Feb 27, 2024
130149c
feat(table.go): modify ResToReqTableFields to ResToReqTableWithParams…
cybersiddhu Feb 27, 2024
76d723b
refactor(table.go): rename functions and variables for clarity and co…
cybersiddhu Feb 27, 2024
a6c6264
refactor(table.go): modify CreateTable function to use HTTP request i…
cybersiddhu Feb 27, 2024
c3b25ab
refactor(database): move functional handlers from table.go to functio…
cybersiddhu Feb 27, 2024
15e76c0
refactor(table.go): rename 'req' parameter to 'field' for clarity
cybersiddhu Feb 27, 2024
cc713c1
feat(action.go): enhance error messages and add field update function…
cybersiddhu Feb 27, 2024
2f66cee
Merge branch 'develop' into feat/baserow-upload
cybersiddhu Feb 27, 2024
91ae54c
refactor(functional_handlers.go): change function name from ReadJson …
cybersiddhu Feb 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ run:
allow-parallel-runners: true
timeout: 5m
linters-settings:
unused:
local-variables-are-used: true
gosec:
excludes:
- G402
Expand Down
8 changes: 4 additions & 4 deletions cmd/baserow/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ func main() {
Action: baserow.CreateAccessToken,
},
{
Name: "create-table",
Usage: "Create a baserow database table",
Flags: baserow.CreateTableFlag(),
Action: baserow.CreateTable,
Name: "create-ontology-table",
Usage: "Create a baserow table with ontology fields preset",
Flags: baserow.CreateOntologyTableFlag(),
Action: baserow.CreateOntologyTableHandler,
},
{
Name: "load-ontology",
Expand Down
160 changes: 160 additions & 0 deletions internal/baserow/cli/action.go
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 {
Copy link

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).

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CreateDatabaseToken has 52 lines of code (exceeds 50 allowed). Consider refactoring.

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 {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function LoadOntologyToTable has 5 return statements (exceeds 4 allowed).

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
}
147 changes: 0 additions & 147 deletions internal/baserow/cli/database.go

This file was deleted.

Loading
Loading