Skip to content

Commit

Permalink
Merge pull request #357 from pixlise/feature/em-import
Browse files Browse the repository at this point in the history
Fixing creator for EM imports
  • Loading branch information
pnemere authored Nov 12, 2024
2 parents 8d485d0 + 9a4fa23 commit c4ecd8a
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 c4ecd8a

Please sign in to comment.