@@ -32,7 +32,9 @@ type Node struct {
32
32
Indexes map [string ]string `bson:"indexes" json:"indexes"`
33
33
Acl acl `bson:"acl" json:"-"`
34
34
VersionParts map [string ]string `bson:"version_parts" json:"-"`
35
- Type string `bson:"type" json:"-"`
35
+ Type []string `bson:"type" json:"type"`
36
+ Parent parent `bson:"parent" json:"parent"`
37
+ Children map [string ]string `bson:"children" json:"children"` //map[nodeid]operation
36
38
}
37
39
38
40
type file struct {
@@ -51,6 +53,11 @@ type partsList struct {
51
53
Parts []partsFile `json:"parts"`
52
54
}
53
55
56
+ type parent struct {
57
+ Operation string `bson:"operation" json:"operation"`
58
+ ParentNodes []string `bson:"parent_nodes" json:"parent_nodes"`
59
+ }
60
+
54
61
type partsFile []string
55
62
56
63
type FormFiles map [string ]FormFile
@@ -82,6 +89,13 @@ func (node *Node) HasIndex(index string) bool {
82
89
return false
83
90
}
84
91
92
+ func (node * Node ) HasParent () bool {
93
+ if len (node .Parent .ParentNodes ) > 0 {
94
+ return true
95
+ }
96
+ return false
97
+ }
98
+
85
99
// Path functions
86
100
func (node * Node ) Path () string {
87
101
return getPath (node .Id )
@@ -422,6 +436,35 @@ func (node *Node) Update(params map[string]string, files FormFiles) (err error)
422
436
}
423
437
}
424
438
}
439
+
440
+ // update parent (provenance info)
441
+ if _ , hasParent := params ["parents" ]; hasParent {
442
+ if node .HasParent () {
443
+ return errors .New (e .ProvenanceImut )
444
+ }
445
+ var operation string = ""
446
+ if _ , hasOp := params ["operation" ]; hasOp {
447
+ operation = params ["operation" ]
448
+ }
449
+ if err = node .SetParents (params ["parents" ], operation ); err != nil {
450
+ return err
451
+ }
452
+ }
453
+
454
+ //add child
455
+ if _ , hasChild := params ["child" ]; hasChild {
456
+ if err = node .SetChild (params ["child" ]); err != nil {
457
+ return err
458
+ }
459
+ }
460
+
461
+ //delete child
462
+ if _ , deleteChild := params ["deletechild" ]; deleteChild {
463
+ if err = node .DeleteChild (params ["deletechild" ]); err != nil {
464
+ return err
465
+ }
466
+ }
467
+
425
468
return
426
469
}
427
470
@@ -501,6 +544,44 @@ func (node *Node) SetFile(file FormFile) (err error) {
501
544
return
502
545
}
503
546
547
+ func (node * Node ) SetParents (parents string , operation string ) (err error ) {
548
+ node .Parent .Operation = operation
549
+ parentList := strings .Split (parents , "," )
550
+ for _ , parent := range parentList {
551
+ node .Parent .ParentNodes = append (node .Parent .ParentNodes , parent )
552
+ }
553
+ err = node .Save ()
554
+ return
555
+ }
556
+
557
+ func (node * Node ) SetChild (child string ) (err error ) {
558
+ segs := strings .Split (child , "," )
559
+ if len (segs ) > 2 {
560
+ return errors .New ("invalid child string" )
561
+ }
562
+ childId := segs [0 ]
563
+ if _ , hasKey := node .Children [childId ]; hasKey {
564
+ return errors .New ("child id already existed" )
565
+ }
566
+ var op string
567
+ if len (segs ) == 1 {
568
+ op = "unknown_operation"
569
+ } else if len (segs ) == 2 {
570
+ op = segs [1 ]
571
+ }
572
+ node .Children [childId ] = op
573
+ err = node .Save ()
574
+ return
575
+ }
576
+
577
+ func (node * Node ) DeleteChild (child string ) (err error ) {
578
+ if _ , ok := node .Children [child ]; ok {
579
+ delete (node .Children , child )
580
+ }
581
+ err = node .Save ()
582
+ return
583
+ }
584
+
504
585
func (node * Node ) SetAttributes (attr FormFile ) (err error ) {
505
586
attributes , err := ioutil .ReadFile (attr .Path )
506
587
if err != nil {
0 commit comments