diff --git a/sda-admin/README.md b/sda-admin/README.md index 1da6997f6..fe9851036 100644 --- a/sda-admin/README.md +++ b/sda-admin/README.md @@ -46,10 +46,10 @@ sda-admin file set-accession -filepath /path/to/file.c4gh -user test-user@exampl ## Create a dataset from a list of accession IDs and a dataset ID -Use the following command to create a dataset `dataset001` from accession IDs `my-accession-id-1` and `my-accession-id-2` +Use the following command to create a dataset `dataset001` from accession IDs `my-accession-id-1` and `my-accession-id-2` for files that belongs to the user `test-user@example.org` ```sh -sda-admin dataset create -dataset-id dataset001 my-accession-id-1 my-accession-id-2 +sda-admin dataset create -user test-user@example.org -dataset-id dataset001 my-accession-id-1 my-accession-id-2 ``` ## Release a dataset for downloading diff --git a/sda-admin/dataset/dataset.go b/sda-admin/dataset/dataset.go index 457b35b2a..180090cf0 100644 --- a/sda-admin/dataset/dataset.go +++ b/sda-admin/dataset/dataset.go @@ -12,10 +12,11 @@ import ( type RequestBodyDataset struct { AccessionIDs []string `json:"accession_ids"` DatasetID string `json:"dataset_id"` + User string `json:"user"` } // Create creates a dataset from a list of accession IDs and a dataset ID. -func Create(apiURI, token, datasetID string, accessionIDs []string) error { +func Create(apiURI, token, datasetID, username string, accessionIDs []string) error { parsedURL, err := url.Parse(apiURI) if err != nil { return err @@ -25,6 +26,7 @@ func Create(apiURI, token, datasetID string, accessionIDs []string) error { requestBody := RequestBodyDataset{ AccessionIDs: accessionIDs, DatasetID: datasetID, + User: username, } jsonBody, err := json.Marshal(requestBody) diff --git a/sda-admin/dataset/dataset_test.go b/sda-admin/dataset/dataset_test.go index c0309b9d7..22fbb059b 100644 --- a/sda-admin/dataset/dataset_test.go +++ b/sda-admin/dataset/dataset_test.go @@ -28,13 +28,14 @@ func TestCreate_Success(t *testing.T) { expectedURL := "http://example.com/dataset/create" token := "test-token" + user := "test-user@example.com" datasetID := "dataset-123" accessionIDs := []string{"accession-1", "accession-2"} - jsonBody := []byte(`{"accession_ids":["accession-1","accession-2"],"dataset_id":"dataset-123"}`) + jsonBody := []byte(`{"accession_ids":["accession-1","accession-2"],"dataset_id":"dataset-123","user":"test-user@example.com"}`) mockHelpers.On("PostRequest", expectedURL, token, jsonBody).Return([]byte(`{}`), nil) - err := Create("http://example.com", token, datasetID, accessionIDs) + err := Create("http://example.com", token, datasetID, user, accessionIDs) assert.NoError(t, err) mockHelpers.AssertExpectations(t) } @@ -47,13 +48,14 @@ func TestCreate_PostRequestFailure(t *testing.T) { expectedURL := "http://example.com/dataset/create" token := "test-token" + user := "test-user@example.com" datasetID := "dataset-123" accessionIDs := []string{"accession-1", "accession-2"} - jsonBody := []byte(`{"accession_ids":["accession-1","accession-2"],"dataset_id":"dataset-123"}`) + jsonBody := []byte(`{"accession_ids":["accession-1","accession-2"],"dataset_id":"dataset-123","user":"test-user@example.com"}`) mockHelpers.On("PostRequest", expectedURL, token, jsonBody).Return([]byte(nil), errors.New("failed to send request")) - err := Create("http://example.com", token, datasetID, accessionIDs) + err := Create("http://example.com", token, datasetID, user, accessionIDs) assert.Error(t, err) assert.EqualError(t, err, "failed to send request") mockHelpers.AssertExpectations(t) diff --git a/sda-admin/main.go b/sda-admin/main.go index 247d7cde0..560874f3b 100644 --- a/sda-admin/main.go +++ b/sda-admin/main.go @@ -30,7 +30,7 @@ Commands: Trigger ingestion of a given file. file set-accession -filepath FILEPATH -user USERNAME -accession-id accessionID Assign accession ID to a file. - dataset create -dataset-id DATASET_ID accessionID [accessionID ...] + dataset create -user SUBMISSION_USER -dataset-id DATASET_ID accessionID [accessionID ...] Create a dataset from a list of accession IDs and a dataset ID. dataset release -dataset-id DATASET_ID Release a dataset for downloading. @@ -92,7 +92,7 @@ Options: -accession-id ID Specify the accession ID to assign to the file.` var datasetUsage = `Create a dataset: - Usage: sda-admin dataset create -dataset-id DATASET_ID [ACCESSION_ID ...] + Usage: sda-admin dataset create -user SUBMISSION_USER -dataset-id DATASET_ID [ACCESSION_ID ...] Create a dataset from a list of accession IDs and a dataset ID. Release a dataset: @@ -105,8 +105,8 @@ Options: Use 'sda-admin help dataset ' for information on a specific command.` -var datasetCreateUsage = `Usage: sda-admin dataset create -dataset-id DATASET_ID [ACCESSION_ID ...] - Create a dataset from a list of accession IDs and a dataset ID. +var datasetCreateUsage = `Usage: sda-admin dataset create -user SUBMISSION_USER -dataset-id DATASET_ID [ACCESSION_ID ...] + Create a dataset from a list of accession IDs and a dataset ID belonging to a given user. Options: -dataset-id DATASET_ID Specify the unique identifier for the dataset. @@ -410,8 +410,9 @@ func handleDatasetCommand() error { func handleDatasetCreateCommand() error { datasetCreateCmd := flag.NewFlagSet("create", flag.ExitOnError) - var datasetID string + var datasetID, username string datasetCreateCmd.StringVar(&datasetID, "dataset-id", "", "ID of the dataset to create") + datasetCreateCmd.StringVar(&username, "user", "", "Username to associate with the file") if err := datasetCreateCmd.Parse(flag.Args()[2:]); err != nil { return fmt.Errorf("error: failed to parse command line arguments, reason: %v", err) @@ -423,7 +424,11 @@ func handleDatasetCreateCommand() error { return fmt.Errorf("error: -dataset-id and at least one accession ID are required.\n%s", datasetCreateUsage) } - err := dataset.Create(apiURI, token, datasetID, accessionIDs) + if username == "" { + return fmt.Errorf("error: -user is required.\n%s", datasetCreateUsage) + } + + err := dataset.Create(apiURI, token, datasetID, username, accessionIDs) if err != nil { return fmt.Errorf("error: failed to create dataset, reason: %v", err) }