Class: RubyAem::Package

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_aem/package.rb

Overview

Package class contains API calls related to managing an AEM package.

Instance Method Summary collapse

Constructor Details

#initialize(client, group_name, package_name, package_version) ⇒ Object

Initialise a package. Package name and version will then be used to construct the package file in the filesystem. E.g. package name ‘somepackage’ with version ‘1.2.3’ will translate to somepackage-1.2.3.zip in the filesystem.



30
31
32
33
34
35
36
37
# File 'lib/ruby_aem/package.rb', line 30

def initialize(client, group_name, package_name, package_version)
  @client = client
  @info = {
    group_name: group_name,
    package_name: package_name,
    package_version: package_version
  }
end

Instance Method Details

#activate_filter(ignore_deactivated, modified_only) ⇒ Object

Activate all paths within a package filter.



117
118
119
120
121
122
123
124
125
126
# File 'lib/ruby_aem/package.rb', line 117

def activate_filter(ignore_deactivated, modified_only)
  result = get_filter()

  results = [result]
  result.data.each { |filter_path|
    path = RubyAem::Path.new(@client, filter_path)
    results.push(path.activate(ignore_deactivated, modified_only))
  }
  results
end

#buildObject

Build the package.



65
66
67
# File 'lib/ruby_aem/package.rb', line 65

def build()
  @client.call(self.class, __callee__.to_s, @info)
end

#createObject

Create the package.



42
43
44
# File 'lib/ruby_aem/package.rb', line 42

def create()
  @client.call(self.class, __callee__.to_s, @info)
end

#deleteObject

Delete the package.



58
59
60
# File 'lib/ruby_aem/package.rb', line 58

def delete()
  @client.call(self.class, __callee__.to_s, @info)
end

#download(file_path) ⇒ Object

Download the package to a specified directory.



88
89
90
91
# File 'lib/ruby_aem/package.rb', line 88

def download(file_path)
  @info[:file_path] = file_path
  @client.call(self.class, __callee__.to_s, @info)
end

#get_filterObject

Get the package filter value. Filter value is stored in result’s data.



108
109
110
# File 'lib/ruby_aem/package.rb', line 108

def get_filter()
  @client.call(self.class, __callee__.to_s, @info)
end

#installObject

Install the package.



72
73
74
# File 'lib/ruby_aem/package.rb', line 72

def install()
  @client.call(self.class, __callee__.to_s, @info)
end

#is_installedObject

Check if this package is installed. Success result indicates that the package is installed. Otherwise a failure result indicates that package is not installed.



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/ruby_aem/package.rb', line 166

def is_installed()
  result = is_uploaded()

  if result.is_success?
    package = result.data
    last_unpacked_by = package.xpath('lastUnpackedBy')

    if not ['<lastUnpackedBy/>', '<lastUnpackedBy>null</lastUnpackedBy>'].include? last_unpacked_by.to_s
      status = 'success'
      message = "Package #{@info[:group_name]}/#{@info[:package_name]}-#{@info[:package_version]} is installed"
    else
      status = 'failure'
      message = "Package #{@info[:group_name]}/#{@info[:package_name]}-#{@info[:package_version]} is not installed"
    end
    result = RubyAem::Result.new(status, message)
  end

  result
end

#is_uploadedObject

Check if this package is uploaded. Success result indicates that the package is uploaded. Otherwise a failure result indicates that package is not uploaded.



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/ruby_aem/package.rb', line 140

def is_uploaded()
  result = list_all()

  if result.is_success?
    packages = result.data
    package = packages.xpath("//packages/package[group=\"#{@info[:group_name]}\" and name=\"#{@info[:package_name]}\" and version=\"#{@info[:package_version]}\"]")

    if package.to_s != ''
      status = 'success'
      message = "Package #{@info[:group_name]}/#{@info[:package_name]}-#{@info[:package_version]} is uploaded"
    else
      status = 'failure'
      message = "Package #{@info[:group_name]}/#{@info[:package_name]}-#{@info[:package_version]} is not uploaded"
    end
    result = RubyAem::Result.new(status, message)
    result.data = package
  end

  result
end

#list_allObject

List all packages available in AEM instance.



131
132
133
# File 'lib/ruby_aem/package.rb', line 131

def list_all()
  @client.call(self.class, __callee__.to_s, @info)
end

#replicateObject

Replicate the package. Package will then be added to replication agents.



80
81
82
# File 'lib/ruby_aem/package.rb', line 80

def replicate()
  @client.call(self.class, __callee__.to_s, @info)
end

#update(filter) ⇒ Object

Update the package with specific filter.



50
51
52
53
# File 'lib/ruby_aem/package.rb', line 50

def update(filter)
  @info[:filter] = filter
  @client.call(self.class, __callee__.to_s, @info)
end

#upload(file_path, force) ⇒ Object

Upload the package.



98
99
100
101
102
# File 'lib/ruby_aem/package.rb', line 98

def upload(file_path, force)
  @info[:file_path] = file_path
  @info[:force] = force
  @client.call(self.class, __callee__.to_s, @info)
end