aboutsummaryrefslogtreecommitdiff
path: root/jsonloader/parser2v2/parse_reviews.go
blob: 279e0b2e179b33345a3e57413361ae2aa69ca7f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later

package parser2v2

import (
	"fmt"
	"reflect"

	"github.com/spdx/tools-golang/spdx"
)

func (spec JSONSpdxDocument) parseJsonReviews2_2(key string, value interface{}, doc *spdxDocument2_2) error {
	//FIXME: Reviewer type property of review not specified in the spec
	if reflect.TypeOf(value).Kind() == reflect.Slice {
		reviews := reflect.ValueOf(value)
		for i := 0; i < reviews.Len(); i++ {
			reviewmap := reviews.Index(i).Interface().(map[string]interface{})
			review := spdx.Review2_2{}
			// Remove loop all properties are mandatory in annotations
			for k, v := range reviewmap {
				switch k {
				case "reviewer":
					subkey, subvalue, err := extractSubs(v.(string))
					if err != nil {
						return err
					}
					if subkey != "Person" && subkey != "Organization" && subkey != "Tool" {
						return fmt.Errorf("unrecognized Reviewer type %v", subkey)
					}
					review.ReviewerType = subkey
					review.Reviewer = subvalue
				case "comment":
					review.ReviewComment = v.(string)
				case "reviewDate":
					review.ReviewDate = v.(string)
				default:
					return fmt.Errorf("received unknown tag %v in Review Section section", k)
				}
			}
			doc.Reviews = append(doc.Reviews, &review)
		}

	}
	return nil
}