Skip to content

Commit

Permalink
Merge pull request #145 from pixlise/development
Browse files Browse the repository at this point in the history
Merge DOI changes to main
  • Loading branch information
pnemere authored May 15, 2023
2 parents 45895cf + 4e9cf5b commit 07a6762
Show file tree
Hide file tree
Showing 19 changed files with 1,111 additions and 48 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,14 @@ jobs:
with:
go-version: '1.18.0'
- name: Test
run: make test
run: echo $PIXLISE_API_TEST_ZENODO_URI && make test
env:
PIXLISE_API_TEST_AUTH0_CLIENT_ID: ${{ secrets.PIXLISE_API_TEST_AUTH0_CLIENT_ID }}
PIXLISE_API_TEST_AUTH0_DOMAIN: ${{ secrets.PIXLISE_API_TEST_AUTH0_DOMAIN }}
PIXLISE_API_TEST_AUTH0_SECRET: ${{ secrets.PIXLISE_API_TEST_AUTH0_SECRET }}
PIXLISE_API_TEST_AUTH0_NEWUSER_ROLE_ID: ${{ secrets.PIXLISE_API_TEST_AUTH0_NEWUSER_ROLE_ID }}
PIXLISE_API_TEST_ZENODO_URI: ${{ secrets.ZENODO_URI }}
PIXLISE_API_TEST_ZENODO_ACCESS_TOKEN: ${{ secrets.ZENODO_ACCESS_TOKEN }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_DEFAULT_REGION: us-east-1
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
Expand Down
3 changes: 3 additions & 0 deletions api/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ type APIConfig struct {

UsersBucket string

ZenodoURI string
ZenodoAccessToken string

// Vars not set by environment
NodeCountOverride int32
MaxQuantNodes int32
Expand Down
22 changes: 22 additions & 0 deletions api/endpoints/DataExpression.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func registerDataExpressionHandler(router *apiRouter.ApiObjectRouter) {
router.AddJSONHandler(handlers.MakeEndpointPath(pathPrefix+"/execution-stat", idIdentifier), apiRouter.MakeMethodPermission("PUT", permission.PermWriteDataAnalysis), dataExpressionExecutionStatPut)

router.AddShareHandler(handlers.MakeEndpointPath(shareURLRoot+"/"+pathPrefix, idIdentifier), apiRouter.MakeMethodPermission("POST", permission.PermWriteSharedExpression), dataExpressionShare)
router.AddShareHandler(handlers.MakeEndpointPath(shareURLRoot+"/doi/"+pathPrefix, idIdentifier), apiRouter.MakeMethodPermission("POST", permission.PermWriteSharedExpression), publishDataExpressionToZenodo)
}

func toWire(expr expressions.DataExpression) expressions.DataExpressionWire {
Expand All @@ -69,6 +70,7 @@ func toWire(expr expressions.DataExpression) expressions.DataExpressionWire {
ModuleReferences: expr.ModuleReferences,
APIObjectItem: &orig,
RecentExecStats: expr.RecentExecStats,
DOIMetadata: expr.DOIMetadata,
}
return resultItem
}
Expand Down Expand Up @@ -278,6 +280,26 @@ func dataExpressionShare(params handlers.ApiHandlerParams) (interface{}, error)
return sharedIDs[0], nil
}

func publishDataExpressionToZenodo(params handlers.ApiHandlerParams) (interface{}, error) {
expressionID := params.PathParams[idIdentifier]

// Get the uploaded zip data
zipData, err := ioutil.ReadAll(params.Request.Body)
if err != nil {
return nil, err
}

zenodoURI := params.Svcs.Config.ZenodoURI
zenodoToken := params.Svcs.Config.ZenodoAccessToken

expression, err := params.Svcs.Expressions.PublishExpressionToZenodo(expressionID, zipData, zenodoURI, zenodoToken)
if err != nil {
return nil, err
}

return expression, nil
}

func shareExpressions(svcs *services.APIServices, userID string, expressionIDs []string) ([]string, error) {
generatedIDs := []string{}

Expand Down
158 changes: 152 additions & 6 deletions api/endpoints/DataExpression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/pixlise/core/v3/core/awsutil"
expressionDB "github.com/pixlise/core/v3/core/expressions/database"
"github.com/pixlise/core/v3/core/expressions/expressions"
zenodoModels "github.com/pixlise/core/v3/core/expressions/zenodo-models"
"github.com/pixlise/core/v3/core/pixlUser"
"github.com/pixlise/core/v3/core/timestamper"
"go.mongodb.org/mongo-driver/bson"
Expand Down Expand Up @@ -64,11 +65,13 @@ func makeExprDBList(idx int, includeSource bool) bson.D {
340.5,
1234568888,
},
zenodoModels.DOIMetadata{},
},
{
"def456", "Iron Error", "element(\"Fe\", \"err\")", "PIXLANG", "comments for def456 expression", []string{}, []expressions.ModuleReference{},
makeOrigin("999", "Peter N", "[email protected]", false, 1668100001, 1668100001),
nil,
zenodoModels.DOIMetadata{},
},
{
"ghi789", "Iron %", "element(\"Fe\", \"%\")", "PIXLANG", "", []string{}, []expressions.ModuleReference{},
Expand All @@ -78,6 +81,7 @@ func makeExprDBList(idx int, includeSource bool) bson.D {
20,
1234568999,
},
zenodoModels.DOIMetadata{},
},
// Same as first item, but with real user id and different ID
{
Expand All @@ -88,6 +92,7 @@ func makeExprDBList(idx int, includeSource bool) bson.D {
340,
1234568888,
},
zenodoModels.DOIMetadata{},
},
// Same as above item, but shared
{
Expand All @@ -98,6 +103,7 @@ func makeExprDBList(idx int, includeSource bool) bson.D {
340,
1234568888,
},
zenodoModels.DOIMetadata{},
},
}

Expand Down Expand Up @@ -249,6 +255,20 @@ func Test_dataExpressionHandler_List_OK(t *testing.T) {
],
"runtimeMs": 340.5,
"mod_unix_time_sec": 1234568888
},
"doiMetadata": {
"title": "",
"creators": null,
"description": "",
"keywords": "",
"notes": "",
"relatedIdentifiers": null,
"contributors": null,
"references": "",
"version": "",
"doi": "",
"doiBadge": "",
"doiLink": ""
}
},
"def456": {
Expand All @@ -265,7 +285,21 @@ func Test_dataExpressionHandler_List_OK(t *testing.T) {
"email": "[email protected]"
},
"create_unix_time_sec": 1668100001,
"mod_unix_time_sec": 1668100001
"mod_unix_time_sec": 1668100001,
"doiMetadata": {
"title": "",
"creators": null,
"description": "",
"keywords": "",
"notes": "",
"relatedIdentifiers": null,
"contributors": null,
"references": "",
"version": "",
"doi": "",
"doiBadge": "",
"doiLink": ""
}
},
"shared-ghi789": {
"id": "shared-ghi789",
Expand All @@ -289,6 +323,20 @@ func Test_dataExpressionHandler_List_OK(t *testing.T) {
],
"runtimeMs": 20,
"mod_unix_time_sec": 1234568999
},
"doiMetadata": {
"title": "",
"creators": null,
"description": "",
"keywords": "",
"notes": "",
"relatedIdentifiers": null,
"contributors": null,
"references": "",
"version": "",
"doi": "",
"doiBadge": "",
"doiLink": ""
}
}
}
Expand Down Expand Up @@ -438,6 +486,20 @@ func Test_dataExpressionHandler_Get_OK(t *testing.T) {
],
"runtimeMs": 340.5,
"mod_unix_time_sec": 1234568888
},
"doiMetadata": {
"title": "",
"creators": null,
"description": "",
"keywords": "",
"notes": "",
"relatedIdentifiers": null,
"contributors": null,
"references": "",
"version": "",
"doi": "",
"doiBadge": "",
"doiLink": ""
}
}
`)
Expand Down Expand Up @@ -467,6 +529,20 @@ func Test_dataExpressionHandler_Get_OK(t *testing.T) {
],
"runtimeMs": 20,
"mod_unix_time_sec": 1234568999
},
"doiMetadata": {
"title": "",
"creators": null,
"description": "",
"keywords": "",
"notes": "",
"relatedIdentifiers": null,
"contributors": null,
"references": "",
"version": "",
"doi": "",
"doiBadge": "",
"doiLink": ""
}
}
`)
Expand Down Expand Up @@ -547,7 +623,21 @@ func Test_dataExpressionHandler_Post(t *testing.T) {
"email": "[email protected]"
},
"create_unix_time_sec": 1668142579,
"mod_unix_time_sec": 1668142579
"mod_unix_time_sec": 1668142579,
"doiMetadata": {
"title": "",
"creators": null,
"description": "",
"keywords": "",
"notes": "",
"relatedIdentifiers": null,
"contributors": null,
"references": "",
"version": "",
"doi": "",
"doiBadge": "",
"doiLink": ""
}
}
`)
})
Expand Down Expand Up @@ -662,7 +752,21 @@ func Test_dataExpressionHandler_Put(t *testing.T) {
"email": "[email protected]"
},
"create_unix_time_sec": 1668100000,
"mod_unix_time_sec": 1668100000
"mod_unix_time_sec": 1668100000,
"doiMetadata": {
"title": "",
"creators": null,
"description": "",
"keywords": "",
"notes": "",
"relatedIdentifiers": null,
"contributors": null,
"references": "",
"version": "",
"doi": "",
"doiBadge": "",
"doiLink": ""
}
}
`)

Expand Down Expand Up @@ -807,7 +911,21 @@ func Test_dataExpressionHandler_Put_NoSourceCode(t *testing.T) {
"email": "[email protected]"
},
"create_unix_time_sec": 1668100000,
"mod_unix_time_sec": 1668100002
"mod_unix_time_sec": 1668100002,
"doiMetadata": {
"title": "",
"creators": null,
"description": "",
"keywords": "",
"notes": "",
"relatedIdentifiers": null,
"contributors": null,
"references": "",
"version": "",
"doi": "",
"doiBadge": "",
"doiLink": ""
}
}
`)

Expand Down Expand Up @@ -850,7 +968,21 @@ func Test_dataExpressionHandler_Put_NoSourceCode(t *testing.T) {
"email": "[email protected]"
},
"create_unix_time_sec": 1668100000,
"mod_unix_time_sec": 1668100003
"mod_unix_time_sec": 1668100003,
"doiMetadata": {
"title": "",
"creators": null,
"description": "",
"keywords": "",
"notes": "",
"relatedIdentifiers": null,
"contributors": null,
"references": "",
"version": "",
"doi": "",
"doiBadge": "",
"doiLink": ""
}
}
`)
})
Expand Down Expand Up @@ -962,7 +1094,21 @@ func Test_dataExpressionHandler_Put_Shared(t *testing.T) {
"email": "[email protected]"
},
"create_unix_time_sec": 1668100000,
"mod_unix_time_sec": 1668100004
"mod_unix_time_sec": 1668100004,
"doiMetadata": {
"title": "",
"creators": null,
"description": "",
"keywords": "",
"notes": "",
"relatedIdentifiers": null,
"contributors": null,
"references": "",
"version": "",
"doi": "",
"doiBadge": "",
"doiLink": ""
}
}
`)
})
Expand Down
10 changes: 8 additions & 2 deletions api/endpoints/DataModule.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ func dataModulePost(params handlers.ApiHandlerParams) (interface{}, error) {
return nil, err
}

// A new DOI is published to Zenodo if the "publish_doi" query parameter is true
publishDOI := params.Request.URL.Query().Get("publish_doi") == "true"

var req modules.DataModuleInput
err = json.Unmarshal(body, &req)
if err != nil {
Expand All @@ -90,12 +93,15 @@ func dataModulePost(params handlers.ApiHandlerParams) (interface{}, error) {
return modules.DataModuleSpecificVersionWire{}, api.MakeBadRequestError(errors.New("Source code field cannot be empty"))
}

return params.Svcs.Expressions.CreateModule(req, params.UserInfo)
return params.Svcs.Expressions.CreateModule(req, params.UserInfo, publishDOI)
}

func dataModulePut(params handlers.ApiHandlerParams) (interface{}, error) {
modID := params.PathParams[idIdentifier]

// A new DOI is published to Zenodo if the "publish_doi" query parameter is true
publishDOI := params.Request.URL.Query().Get("publish_doi") == "true"

body, err := ioutil.ReadAll(params.Request.Body)
if err != nil {
return nil, err
Expand All @@ -107,5 +113,5 @@ func dataModulePut(params handlers.ApiHandlerParams) (interface{}, error) {
return nil, api.MakeBadRequestError(err)
}

return params.Svcs.Expressions.AddModuleVersion(modID, req)
return params.Svcs.Expressions.AddModuleVersion(modID, req, publishDOI)
}
16 changes: 15 additions & 1 deletion api/endpoints/DataModule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,21 @@ func Test_Module_Listing(t *testing.T) {
"A"
],
"comments": "Module 1",
"mod_unix_time_sec": 1234567891
"mod_unix_time_sec": 1234567891,
"doiMetadata": {
"title": "",
"creators": null,
"description": "",
"keywords": "",
"notes": "",
"relatedIdentifiers": null,
"contributors": null,
"references": "",
"version": "",
"doi": "",
"doiBadge": "",
"doiLink": ""
}
}
]
}
Expand Down
Loading

0 comments on commit 07a6762

Please sign in to comment.