aboutsummaryrefslogtreecommitdiff
path: root/rdfloader/parser2v2/parse_creation_info.go
blob: dc4da77e83405c0c3a519fafb1e9c9e09b09b204 (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
46
47
48
49
50
51
52
53
54
55
56
// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later

package parser2v2

import (
	"fmt"
	gordfParser "github.com/spdx/gordf/rdfloader/parser"
	"github.com/spdx/tools-golang/spdx"
)

// Cardinality: Mandatory, one.
func (parser *rdfParser2_2) parseCreationInfoFromNode(ci *spdx.CreationInfo2_2, node *gordfParser.Node) error {
	for _, triple := range parser.nodeToTriples(node) {
		switch triple.Predicate.ID {
		case SPDX_LICENSE_LIST_VERSION: // 2.7
			// cardinality: max 1
			ci.LicenseListVersion = triple.Object.ID
		case SPDX_CREATOR: // 2.8
			// cardinality: min 1
			err := setCreator(triple.Object.ID, ci)
			if err != nil {
				return err
			}
		case SPDX_CREATED: // 2.9
			// cardinality: exactly 1
			ci.Created = triple.Object.ID
		case RDFS_COMMENT: // 2.10
			ci.CreatorComment = triple.Object.ID
		case RDF_TYPE:
			continue
		default:
			return fmt.Errorf("unknown predicate %v while parsing a creation info", triple.Predicate)
		}
	}
	return nil
}

func setCreator(creatorStr string, ci *spdx.CreationInfo2_2) error {
	entityType, entity, err := ExtractSubs(creatorStr, ":")
	if err != nil {
		return fmt.Errorf("error setting creator of a creation info: %s", err)
	}

	creator := spdx.Creator{Creator: entity}

	switch entityType {
	case "Person", "Organization", "Tool":
		creator.CreatorType = entityType
	default:
		return fmt.Errorf("unknown creatorType %v in a creation info", entityType)
	}

	ci.Creators = append(ci.Creators, creator)

	return nil
}