-
Notifications
You must be signed in to change notification settings - Fork 54
/
Document.go
118 lines (109 loc) · 3.13 KB
/
Document.go
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package rdf2v1
import (
"github.com/deltamobile/goraptor"
)
type Document struct {
SPDXVersion ValueStr
DataLicense ValueStr
CreationInfo *CreationInfo
Review []*Review
DocumentName ValueStr
DocumentNamespace ValueStr
SPDXID ValueStr
DocumentComment ValueStr
ExtractedLicensingInfo []*ExtractedLicensingInfo
Relationship []*Relationship
License *License
Annotation []*Annotation
ExternalDocumentRef *ExternalDocumentRef
}
type ExternalDocumentRef struct {
ExternalDocumentId ValueStr
Checksum *Checksum
SPDXDocument ValueStr
}
func (p *Parser) requestDocument(node goraptor.Term) (*Document, error) {
obj, err := p.requestElementType(node, typeDocument)
if err != nil {
return nil, err
}
return obj.(*Document), err
}
func (p *Parser) requestExternalDocumentRef(node goraptor.Term) (*ExternalDocumentRef, error) {
obj, err := p.requestElementType(node, typeExternalDocumentRef)
if err != nil {
return nil, err
}
return obj.(*ExternalDocumentRef), err
}
func (p *Parser) MapDocument(doc *Document) *builder {
builder := &builder{t: typeDocument, ptr: doc}
doc.DocumentNamespace = DocumentNamespace
builder.updaters = map[string]updater{
"specVersion": update(&doc.SPDXVersion),
// Example: gets CC0-1.0 from "http://spdx.org/licenses/CC0-1.0"
"dataLicense": func(obj goraptor.Term) error {
lic, err := p.requestLicense(obj)
doc.License = lic
return err
},
"creationInfo": func(obj goraptor.Term) error {
ci, err := p.requestCreationInfo(obj)
doc.CreationInfo = ci
return err
},
"reviewed": func(obj goraptor.Term) error {
rev, err := p.requestReview(obj)
if err != nil {
return err
}
doc.Review = append(doc.Review, rev)
return err
},
"name": update(&doc.DocumentName),
"rdfs:comment": update(&doc.DocumentComment),
"hasExtractedLicensingInfo": func(obj goraptor.Term) error {
eli, err := p.requestExtractedLicensingInfo(obj)
if err != nil {
return err
}
doc.ExtractedLicensingInfo = append(doc.ExtractedLicensingInfo, eli)
return nil
},
"relationship": func(obj goraptor.Term) error {
rel, err := p.requestRelationship(obj)
if err != nil {
return err
}
doc.Relationship = append(doc.Relationship, rel)
return nil
},
"annotation": func(obj goraptor.Term) error {
an, err := p.requestAnnotation(obj)
if err != nil {
return err
}
doc.Annotation = append(doc.Annotation, an)
return err
},
"externalDocumentRef": func(obj goraptor.Term) error {
edr, err := p.requestExternalDocumentRef(obj)
doc.ExternalDocumentRef = edr
return err
},
}
return builder
}
func (p *Parser) MapExternalDocumentRef(edr *ExternalDocumentRef) *builder {
builder := &builder{t: typeExternalDocumentRef, ptr: edr}
builder.updaters = map[string]updater{
"externalDocumentId": update(&edr.ExternalDocumentId),
"checksum": func(obj goraptor.Term) error {
cksum, err := p.requestChecksum(obj)
edr.Checksum = cksum
return err
},
"spdxDocument": update(&edr.SPDXDocument),
}
return builder
}