Mercurial > gemma
comparison pkg/models/sr.go @ 1297:1c0c9190fcf2
Import sounding result: If uploading a zip with a meta.json which has
a dataset for bottleneck which already has a scan for a given date
issue a message.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 22 Nov 2018 18:16:47 +0100 |
parents | bc4b642c8d04 |
children | d753ce6cf588 |
comparison
equal
deleted
inserted
replaced
1296:99c039e86624 | 1297:1c0c9190fcf2 |
---|---|
44 checkDepthReferenceSQL = ` | 44 checkDepthReferenceSQL = ` |
45 SELECT true FROM depth_references WHERE depth_reference = $1` | 45 SELECT true FROM depth_references WHERE depth_reference = $1` |
46 | 46 |
47 checkBottleneckSQL = ` | 47 checkBottleneckSQL = ` |
48 SELECT true FROM waterway.bottlenecks WHERE objnam = $1` | 48 SELECT true FROM waterway.bottlenecks WHERE objnam = $1` |
49 | |
50 checkBottleneckDateUniqueSQL = ` | |
51 SELECT true FROM waterway.sounding_results sr JOIN | |
52 waterway.bottlenecks bn ON sr.bottleneck_id = bn.bottleneck_id | |
53 WHERE bn.objnam = $1 AND sr.date_info = $2` | |
49 ) | 54 ) |
50 | 55 |
51 func (srd *SoundingResultDate) UnmarshalJSON(data []byte) error { | 56 func (srd *SoundingResultDate) UnmarshalJSON(data []byte) error { |
52 var s string | 57 var s string |
53 if err := json.Unmarshal(data, &s); err != nil { | 58 if err := json.Unmarshal(data, &s); err != nil { |
83 errs = append(errs, err) | 88 errs = append(errs, err) |
84 case !b: | 89 case !b: |
85 errs = append(errs, errors.New("Unexpected depth reference")) | 90 errs = append(errs, errors.New("Unexpected depth reference")) |
86 } | 91 } |
87 | 92 |
88 err = conn.QueryRowContext(context.Background(), | 93 err = conn.QueryRowContext(ctx, |
89 checkBottleneckSQL, | 94 checkBottleneckSQL, |
90 m.Bottleneck).Scan(&b) | 95 m.Bottleneck).Scan(&b) |
91 switch { | 96 switch { |
92 case err == sql.ErrNoRows: | 97 case err == sql.ErrNoRows: |
93 errs = append(errs, fmt.Errorf("Unknown bottleneck '%s'\n", m.Bottleneck)) | 98 errs = append(errs, fmt.Errorf("Unknown bottleneck '%s'\n", m.Bottleneck)) |
95 errs = append(errs, err) | 100 errs = append(errs, err) |
96 case !b: | 101 case !b: |
97 errs = append(errs, errors.New("Unexpected bottleneck")) | 102 errs = append(errs, errors.New("Unexpected bottleneck")) |
98 } | 103 } |
99 | 104 |
105 err = conn.QueryRowContext(ctx, | |
106 checkBottleneckDateUniqueSQL, | |
107 m.Bottleneck, m.Date.Time).Scan(&b) | |
108 switch { | |
109 case err == sql.ErrNoRows: // good! -> unique. | |
110 case err != nil: | |
111 errs = append(errs, err) | |
112 case b: | |
113 errs = append(errs, | |
114 errors.New("Sounding result for this date already exists.")) | |
115 } | |
116 | |
100 return errs | 117 return errs |
101 } | 118 } |