// Validates that a dataset is valid in the database. When posible canonical // values will be set. If the dataset is invalid it will return an error. func (d *datasets) validate(set *jdh.Dataset) error { set.Id = strings.TrimSpace(set.Id) set.Title = strings.Join(strings.Fields(set.Title), " ") if (len(set.Id) == 0) || (len(set.Title) == 0) { return errors.New("dataset without identification") } if _, ok := d.ids[set.Id]; ok { return fmt.Errorf("dataset id %s already in use", set.Id) } set.Citation = strings.Join(strings.Fields(set.Citation), " ") set.License = strings.Join(strings.Fields(set.License), " ") if u, err := url.Parse(set.Url); err != nil { set.Url = "" } else { set.Url = u.String() } ext := set.Extern set.Extern = nil for _, e := range ext { serv, id, err := jdh.ParseExtern(e) if err != nil { continue } if len(id) == 0 { continue } add := true for _, ex := range set.Extern { if strings.HasPrefix(ex, serv) { add = false break } } if !add { continue } if _, ok := d.ids[e]; !ok { set.Extern = append(set.Extern, e) } } return nil }