Skip to content

Commit

Permalink
[mapper] user id not part of filepath
Browse files Browse the repository at this point in the history
  • Loading branch information
MalinAhlberg committed Dec 5, 2024
1 parent ecad2fc commit 62b8839
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
11 changes: 6 additions & 5 deletions sda/cmd/mapper/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/neicnordic/sensitive-data-archive/internal/broker"
"github.com/neicnordic/sensitive-data-archive/internal/config"
"github.com/neicnordic/sensitive-data-archive/internal/database"
"github.com/neicnordic/sensitive-data-archive/internal/helper"
"github.com/neicnordic/sensitive-data-archive/internal/schema"
"github.com/neicnordic/sensitive-data-archive/internal/storage"

Expand Down Expand Up @@ -102,14 +103,14 @@ func main() {
}

for _, aID := range mappings.AccessionIDs {
log.Debugf("Mapped file to dataset (corr-id: %s, datasetid: %s, accessionid: %s)", delivered.CorrelationId, mappings.DatasetID, aID)
filePath, err := db.GetInboxPath(aID)
fileInfo, err := db.GetFileInfoFromAccessionID(aID)
if err != nil {
log.Errorf("failed to get inbox path for file with stable ID: %s", aID)
log.Errorf("failed to get file info for file with stable ID: %s", aID)
}
err = inbox.RemoveFile(filePath)

err = inbox.RemoveFile(helper.UnanonymizeFilepath(fileInfo.FilePath, fileInfo.User))
if err != nil {
log.Errorf("Remove file from inbox failed, reason: %v", err)
log.Errorf("Remove file from inbox %s failed, reason: %v", fileInfo.FilePath, err)
}
}

Expand Down
33 changes: 33 additions & 0 deletions sda/internal/database/db_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,39 @@ func (dbs *SDAdb) GetHeaderForStableID(stableID string) ([]byte, error) {
return header, nil
}

// GetFileInfoFromAccessionID retrieves the file information needed for mapping
func (dbs *SDAdb) GetFileInfoFromAccessionID(accessionID string) (SyncData, error) {
var (
s SyncData
err error
)

for count := 1; count <= RetryTimes; count++ {
s, err = dbs.getFileInfoFromAccessionID(accessionID)
if err == nil {
break
}
time.Sleep(time.Duration(math.Pow(3, float64(count))) * time.Second)
}

return s, err
}

// getFileInfoFromAccessionID is the actual function performing work for GetFileInfoFromAccessionID
func (dbs *SDAdb) getFileInfoFromAccessionID(accessionID string) (SyncData, error) {
dbs.checkAndReconnectIfNeeded()

const query = "SELECT submission_user, submission_file_path from sda.files WHERE stable_id = $1;"
var data SyncData
if err := dbs.DB.QueryRow(query, accessionID).Scan(&data.User, &data.FilePath); err != nil {
log.Warnf("Error while searching for id %s: %v", accessionID, err)

return SyncData{}, err
}

return data, nil
}

// GetSyncData retrieves the file information needed to sync a dataset
func (dbs *SDAdb) GetSyncData(accessionID string) (SyncData, error) {
var (
Expand Down

0 comments on commit 62b8839

Please sign in to comment.