func newHarmonizationConfig()

in wstl1/tools/notebook/extensions/wstl/service/wstlserver/context.go [78:157]


func newHarmonizationConfig(wstl string, libraryConfigs []*wspb.Location, codeConfigs []*wspb.Location, unitConfig *wspb.Location) *dhpb.DataHarmonizationConfig {
	libConfig := []*lpb.LibraryConfig{}
	if len(libraryConfigs) > 0 {
		for _, libraryConfig := range libraryConfigs {
			switch l := libraryConfig.GetLocation().(type) {
			case *wspb.Location_LocalPath:
				names := ioutil.MustReadGlob(l.LocalPath, "library_config")
				for _, f := range names {
					if !strings.HasSuffix(f, ".wstl") {
						continue
					}
					tLibConfig := &lpb.LibraryConfig{}
					tLibConfig.UserLibraries = []*lpb.UserLibrary{
						&lpb.UserLibrary{
							Type: hpb.MappingType_MAPPING_LANGUAGE,
							Path: &httppb.Location{
								Location: &httppb.Location_LocalPath{
									LocalPath: f,
								},
							},
						},
					}
					libConfig = append(libConfig, tLibConfig)
				}
			case *wspb.Location_GcsLocation:
				tLibConfig := &lpb.LibraryConfig{}
				tLibConfig.UserLibraries = []*lpb.UserLibrary{
					&lpb.UserLibrary{
						Type: hpb.MappingType_MAPPING_LANGUAGE,
						Path: &httppb.Location{
							Location: &httppb.Location_GcsLocation{
								GcsLocation: l.GcsLocation,
							},
						},
					},
				}
				libConfig = append(libConfig, tLibConfig)
			}
		}
	}

	var codeConfigLocs []*httppb.Location
	if len(codeConfigs) > 0 {
		for _, cConfig := range codeConfigs {
			switch l := cConfig.GetLocation().(type) {
			case *wspb.Location_LocalPath:
				names := ioutil.MustReadGlob(l.LocalPath, "code_config")
				for _, f := range names {
					if !strings.HasSuffix(f, ".json") {
						continue
					}
					codeConfigLocs = append(codeConfigLocs, &httppb.Location{Location: &httppb.Location_LocalPath{LocalPath: f}})
				}
			case *wspb.Location_GcsLocation:
				codeConfigLocs = append(codeConfigLocs, &httppb.Location{Location: &httppb.Location_GcsLocation{GcsLocation: l.GcsLocation}})
			}
		}
	}

	uConfig := &hpb.UnitHarmonizationConfig{}
	if unitConfig != nil {
		switch l := unitConfig.GetLocation().(type) {
		case *wspb.Location_LocalPath:
			uConfig.UnitConversion = &httppb.Location{Location: &httppb.Location_LocalPath{LocalPath: l.LocalPath}}
		case *wspb.Location_GcsLocation:
			uConfig.UnitConversion = &httppb.Location{Location: &httppb.Location_GcsLocation{GcsLocation: l.GcsLocation}}
		}
	}

	return &dhpb.DataHarmonizationConfig{
		StructureMappingConfig: &hpb.StructureMappingConfig{
			Mapping: &hpb.StructureMappingConfig_MappingLanguageString{
				MappingLanguageString: wstl,
			},
		},
		LibraryConfig:           libConfig,
		HarmonizationConfig:     &hpb.CodeHarmonizationConfig{CodeLookup: codeConfigLocs},
		UnitHarmonizationConfig: uConfig,
	}
}