Skip to content

Commit

Permalink
Fixing creator for EM imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Nemere committed Nov 12, 2024
1 parent 1e2c76c commit 9a4fa23
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions api/dataimport/internal/converters/pixlem/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ func (p PIXLEM) Import(importPath string, pseudoIntensityRangesPath string, data
return nil, "", err
}

creatorId, err := readCreator(filepath.Join(importPath, "creator.json"), &fs)
if err != nil {
return nil, "", err
}

// Extract RTTs from each beam location file name and import a dataset for each RTT
zipName, err := extractZipName(append(msaFiles, imageFiles...))
if err != nil {
Expand Down Expand Up @@ -138,7 +143,7 @@ func (p PIXLEM) Import(importPath string, pseudoIntensityRangesPath string, data
beamPath := filepath.Join(importPath, beamName)
// HK file should be here too...
hkPath := filepath.Join(importPath, "HK-"+rttStr+".csv")
data, err := importEMData(rttStr, beamPath, hkPath, imageList, bulkMaxList, msaList, &fs, log)
data, err := importEMData(creatorId, rttStr, beamPath, hkPath, imageList, bulkMaxList, msaList, &fs, log)
if err != nil {
log.Errorf("Import failed for %v: %v", beamName, err)
continue
Expand All @@ -153,6 +158,19 @@ func (p PIXLEM) Import(importPath string, pseudoIntensityRangesPath string, data
return nil, "", fmt.Errorf("Expected RTT %v was not found in uploaded data", datasetIDExpected)
}

func readCreator(creatorPath string, fs fileaccess.FileAccess) (string, error) {
var creator = protos.UserInfo{}
err := fs.ReadJSON(creatorPath, "", &creator, false)
if err != nil {
return "", nil
}

if len(creator.Id) <= 0 {
return "", fmt.Errorf("Failed to read creator id from %v", creatorPath)
}
return creator.Id, nil
}

func extractZipName(files []string) (string, error) {
zipName := ""
pathSep := string(os.PathSeparator)
Expand All @@ -179,7 +197,7 @@ func extractZipName(files []string) (string, error) {

return zipName, nil
}
func importEMData(rtt string, beamLocPath string, hkPath string, imagePathList []string, bulkMaxList []string, msaList []string, fs fileaccess.FileAccess, logger logger.ILogger) (*dataConvertModels.OutputData, error) {
func importEMData(creatorId string, rtt string, beamLocPath string, hkPath string, imagePathList []string, bulkMaxList []string, msaList []string, fs fileaccess.FileAccess, logger logger.ILogger) (*dataConvertModels.OutputData, error) {
// Read MSAs
locSpectraLookup, err := jplbreadboard.MakeSpectraLookup("", msaList, true, false, "", false, logger)
if err != nil {
Expand Down Expand Up @@ -246,7 +264,7 @@ func importEMData(rtt string, beamLocPath string, hkPath string, imagePathList [
return nil, err
}

return importerutils.MakeFMDatasetOutput(
outData, err := importerutils.MakeFMDatasetOutput(
beamLookup,
hkData,
locSpectraLookup,
Expand All @@ -265,4 +283,7 @@ func importEMData(rtt string, beamLocPath string, hkPath string, imagePathList [
uint32(3),
logger,
)

outData.CreatorUserId = creatorId
return outData, err
}

0 comments on commit 9a4fa23

Please sign in to comment.