Class: SakaiInfo::Content

Inherits:
SakaiObject show all
Includes:
ModProps
Defined in:
lib/sakai-info/content.rb

Direct Known Subclasses

ContentCollection, ContentResource

Instance Attribute Summary collapse

Attributes inherited from SakaiObject

#id

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ModProps

included

Methods inherited from SakaiObject

#dbrow_only_serialization, #dbrow_serialization, descendants, #object_type_serialization, #serialize, #shell_serialization, #to_csv, #to_json, #to_yaml

Instance Attribute Details

#parent_idObject (readonly)

Returns the value of attribute parent_id.



14
15
16
# File 'lib/sakai-info/content.rb', line 14

def parent_id
  @parent_id
end

Class Method Details

.all_serializationsObject



144
145
146
147
148
149
150
151
152
# File 'lib/sakai-info/content.rb', line 144

def self.all_serializations
  [
   :default,
   :children,
   :realm,
   :properties,
   :mod
  ]
end

.find(id) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/sakai-info/content.rb', line 22

def self.find(id)
  begin
    ContentResource.find(id)
  rescue ObjectNotFoundException
    begin
      ContentCollection.find(id)
    rescue ObjectNotFoundException
      if not id.match(/\/$/)
        ContentCollection.find(id + "/")
      else
        raise ObjectNotFoundException.new(Content, id)
      end
    end
  end
end

Instance Method Details

#binary_entityObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/sakai-info/content.rb', line 50

def binary_entity
  if @binary_entity.nil?
    @binary_entity = ContentBinaryEntity.new(@dbrow[:binary_entity])

    @dbrow[:_binary_entity_created_by] = @binary_entity["CHEF:creator"]
    @dbrow[:_binary_entity_modified_by] = @binary_entity["CHEF:modifiedby"]
    @dbrow[:_binary_entity_created_at] =
      Util.format_entity_date(@binary_entity["DAV:creationdate"])
    @dbrow[:_binary_entity_modified_at] =
      Util.format_entity_date(@binary_entity["DAV:getlastmodified"])
  end

  @binary_entity
end

#child_summary_serializationObject



108
109
110
111
112
113
# File 'lib/sakai-info/content.rb', line 108

def child_summary_serialization
  {
    "id" => self.id.gsub(/^#{self.parent_id}/,""),
    "size" => self.size_on_disk,
  }
end

#default_serializationObject



65
66
67
68
69
70
71
# File 'lib/sakai-info/content.rb', line 65

def default_serialization
  {
    "id" => self.id,
    "parent" => self.parent_id,
    "size_on_disk" => self.size_on_disk
  }
end

#effective_realmObject



94
95
96
# File 'lib/sakai-info/content.rb', line 94

def effective_realm
  self.realm || (parent.nil? ? nil : parent.effective_realm)
end

#mod_details_serializationObject



139
140
141
142
# File 'lib/sakai-info/content.rb', line 139

def mod_details_serialization
  self.binary_entity
  self.original_mod_details_serialization
end

#mod_serializationObject



134
135
136
137
# File 'lib/sakai-info/content.rb', line 134

def mod_serialization
  self.binary_entity
  self.original_mod_serialization
end

#original_mod_details_serializationObject



132
# File 'lib/sakai-info/content.rb', line 132

alias :original_mod_details_serialization :mod_details_serialization

#original_mod_serializationObject

ensure @binary_entity has been parsed before returning mod info



131
# File 'lib/sakai-info/content.rb', line 131

alias :original_mod_serialization :mod_serialization

#parentObject



38
39
40
41
42
43
44
# File 'lib/sakai-info/content.rb', line 38

def parent
  if @parent_id.nil?
    nil
  else
    @parent ||= ContentCollection.find(@parent_id)
  end
end

#properties_serializationObject



115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/sakai-info/content.rb', line 115

def properties_serialization
  result = self.binary_entity.to_hash
  if result["groups"] == []
    result.delete("groups")
  end
  result.keys.each do |key|
    if result[key].nil? or result[key] == ""
      result.delete(key)
    end
  end
  {
    "properties" => result
  }
end

#realmObject



81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/sakai-info/content.rb', line 81

def realm
  if @realm_is_nil
    nil
  else
    begin
      @realm ||= AuthzRealm.find_by_name("/content#{@id}")
    rescue ObjectNotFoundException
      @realm_is_nil = true
      nil
    end
  end
end

#realm_serializationObject



98
99
100
101
102
103
104
105
106
# File 'lib/sakai-info/content.rb', line 98

def realm_serialization
  if self.effective_realm.nil?
    {}
  else
    {
      "effective_realm" => self.effective_realm.name,
    }
  end
end

#size_on_diskObject



46
47
48
# File 'lib/sakai-info/content.rb', line 46

def size_on_disk
  0
end

#summary_serializationObject



73
74
75
76
77
78
79
# File 'lib/sakai-info/content.rb', line 73

def summary_serialization
  {
    "id" => self.id,
    "parent" => self.parent_id,
    "size_on_disk" => self.size_on_disk
  }
end