File: parse_creation_info.go

package info (click to toggle)
golang-github-spdx-tools-golang 0.5.5-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,252 kB
  • sloc: xml: 428; makefile: 22; ansic: 5; python: 2
file content (58 lines) | stat: -rw-r--r-- 1,534 bytes parent folder | download
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
57
58
// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later

package reader

import (
	"fmt"

	gordfParser "github.com/spdx/gordf/rdfloader/parser"
	"github.com/spdx/tools-golang/spdx/v2/common"
	"github.com/spdx/tools-golang/spdx/v2/v2_2"
)

// Cardinality: Mandatory, one.
func (parser *rdfParser2_2) parseCreationInfoFromNode(ci *v2_2.CreationInfo, 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 *v2_2.CreationInfo) error {
	entityType, entity, err := ExtractSubs(creatorStr, ":")
	if err != nil {
		return fmt.Errorf("error setting creator of a creation info: %s", err)
	}

	creator := common.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
}