-
Notifications
You must be signed in to change notification settings - Fork 0
/
resources.go
87 lines (75 loc) · 2.01 KB
/
resources.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
package entities
import (
"errors"
"fmt"
)
var _ = fmt.Println // remove after test
func makeResourceTypeSet() map[string]struct{} {
a := map[string]struct{}{}
a["Equipment"] = struct{}{}
a["Service"] = struct{}{}
return a
}
var ResourceTypeSet = makeResourceTypeSet()
type Resource struct {
Key *Key
Name string
ResourceType string
Description string
Contact *Person
Admin *Organization
}
func NewResource(t string, n string) (*Resource,error) {
p := new(Resource)
p.Key = makeKey("Resource")
_,ok := ResourceTypeSet[t]
if !ok {
err := errors.New("Unknown resource type: "+t)
return nil, err
}
p.ResourceType = t
p.Name = n
return p, nil
}
func NewEquipment(n string) (*Resource,error) {return NewResource("Equipment", n)}
func NewService(n string) (*Resource,error) {return NewResource("Service", n)}
func (a *Resource) Triples () [][3]string {
var t [][3]string
t = append(t, makeTriple(Triple{(*a).Key,"hasType","Resource",nil}))
t = append(t, makeTriple(Triple{(*a).Key,"hasResourceType",(*a).ResourceType,nil}))
t = append(t, makeTriple(Triple{(*a).Key,"hasName",(*a).Name,nil}))
if (*a).Description != "" {t = append(t, makeTriple(Triple{(*a).Key,"hasDescription",(*a).Description,nil}))}
if (*a).Contact != nil {t = append(t, makeTriple(Triple{(*a).Key,"hasContact","",(*a.Contact).Key}))}
if (*a).Admin != nil {t = append(t, makeTriple(Triple{(*a).Key,"hasAdmin","",(*a.Admin).Key}))}
return t
}
func FindResourceKey (kf *Key) int {
for i,a := range Resources {
if kf.s == a.Key.s {
return i
}
}
return -1
}
func AddResourceFact(a []string) {
key := new(Key)
key.s = a[0]
i := FindResourceKey(key)
switch a[1] {
case "ResourceType":
Resources[i].ResourceType = a[2]
case "Name":
Resources[i].Name = a[2]
case "Description":
Resources[i].Description = a[2]
case "Contact":
key.s = a[2]
j := FindPersonKey(key)
Resources[i].Contact = People[j]
case "Admin":
key.s = a[2]
j := FindOrganizationKey(key)
Resources[i].Admin = Organizations[j]
}
}
var Resources []*Resource