Skip to content
Browse files

support provenance info in node: parent and children fields and updat…

…ing APIs
  • Loading branch information...
1 parent f3c4a21 commit 606cf02dec377831fd25e7c422031f95a32af7b4 @wtangiit wtangiit committed Nov 26, 2012
Showing with 84 additions and 1 deletion.
  1. +1 −0 errors/errors.go
  2. +82 −1 store/node.go
  3. +1 −0 store/store.go
View
1 errors/errors.go
@@ -15,6 +15,7 @@ const (
NoAuth = "No Authorization"
AttrImut = "node attributes immutable"
FileImut = "node file immutable"
+ ProvenanceImut = "provenance info immutable"
InvalidIndex = "Invalid Index"
InvalidFileTypeForFilter = "Invalid file type for filter"
)
View
83 store/node.go
@@ -32,7 +32,9 @@ type Node struct {
Indexes map[string]string `bson:"indexes" json:"indexes"`
Acl acl `bson:"acl" json:"-"`
VersionParts map[string]string `bson:"version_parts" json:"-"`
- Type string `bson:"type" json:"-"`
+ Type []string `bson:"type" json:"type"`
+ Parent parent `bson:"parent" json:"parent"`
+ Children map[string]string `bson:"children" json:"children"` //map[nodeid]operation
}
type file struct {
@@ -51,6 +53,11 @@ type partsList struct {
Parts []partsFile `json:"parts"`
}
+type parent struct {
+ Operation string `bson:"operation" json:"operation"`
+ ParentNodes []string `bson:"parent_nodes" json:"parent_nodes"`
+}
+
type partsFile []string
type FormFiles map[string]FormFile
@@ -82,6 +89,13 @@ func (node *Node) HasIndex(index string) bool {
return false
}
+func (node *Node) HasParent() bool {
+ if len(node.Parent.ParentNodes) > 0 {
+ return true
+ }
+ return false
+}
+
// Path functions
func (node *Node) Path() string {
return getPath(node.Id)
@@ -422,6 +436,35 @@ func (node *Node) Update(params map[string]string, files FormFiles) (err error)
}
}
}
+
+ // update parent (provenance info)
+ if _, hasParent := params["parents"]; hasParent {
+ if node.HasParent() {
+ return errors.New(e.ProvenanceImut)
+ }
+ var operation string = ""
+ if _, hasOp := params["operation"]; hasOp {
+ operation = params["operation"]
+ }
+ if err = node.SetParents(params["parents"], operation); err != nil {
+ return err
+ }
+ }
+
+ //add child
+ if _, hasChild := params["child"]; hasChild {
+ if err = node.SetChild(params["child"]); err != nil {
+ return err
+ }
+ }
+
+ //delete child
+ if _, deleteChild := params["deletechild"]; deleteChild {
+ if err = node.DeleteChild(params["deletechild"]); err != nil {
+ return err
+ }
+ }
+
return
}
@@ -501,6 +544,44 @@ func (node *Node) SetFile(file FormFile) (err error) {
return
}
+func (node *Node) SetParents(parents string, operation string) (err error) {
+ node.Parent.Operation = operation
+ parentList := strings.Split(parents, ",")
+ for _, parent := range parentList {
+ node.Parent.ParentNodes = append(node.Parent.ParentNodes, parent)
+ }
+ err = node.Save()
+ return
+}
+
+func (node *Node) SetChild(child string) (err error) {
+ segs := strings.Split(child, ",")
+ if len(segs) > 2 {
+ return errors.New("invalid child string")
+ }
+ childId := segs[0]
+ if _, hasKey := node.Children[childId]; hasKey {
+ return errors.New("child id already existed")
+ }
+ var op string
+ if len(segs) == 1 {
+ op = "unknown_operation"
+ } else if len(segs) == 2 {
+ op = segs[1]
+ }
+ node.Children[childId] = op
+ err = node.Save()
+ return
+}
+
+func (node *Node) DeleteChild(child string) (err error) {
+ if _, ok := node.Children[child]; ok {
+ delete(node.Children, child)
+ }
+ err = node.Save()
+ return
+}
+
func (node *Node) SetAttributes(attr FormFile) (err error) {
attributes, err := ioutil.ReadFile(attr.Path)
if err != nil {
View
1 store/store.go
@@ -74,6 +74,7 @@ func NewNode() (node *Node) {
node = new(Node)
node.Indexes = make(map[string]string)
node.File.Checksum = make(map[string]string)
+ node.Children = make(map[string]string)
node.setId()
return
}

0 comments on commit 606cf02

Please sign in to comment.
Something went wrong with that request. Please try again.