Class: RubyAem::Resources::Package

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_aem/resources/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.

Parameters:

  • client

    RubyAem::Client

  • group_name

    the group name of the package, e.g. somepackagegroup

  • package_name

    the name of the package, e.g. somepackage

  • package_version

    the version of the package, e.g. 1.2.3



33
34
35
36
37
38
39
40
# File 'lib/ruby_aem/resources/package.rb', line 33

def initialize(client, group_name, package_name, package_version)
  @client = client
  @call_params = {
    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. Returns an array of results:

  • the first result is the result from retrieving filter paths

  • the rest of the results are the results from activating the filter paths, one result for each activation

Parameters:

  • ignore_deactivated

    if true, then deactivated items in the path will not be activated

  • modified_only

    if true, then only modified items in the path will be activated

Returns:

  • an array of RubyAem::Result



129
130
131
132
133
134
135
136
137
138
# File 'lib/ruby_aem/resources/package.rb', line 129

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

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

#buildObject

Build the package.

Returns:

  • RubyAem::Result



69
70
71
# File 'lib/ruby_aem/resources/package.rb', line 69

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

#createObject

Create the package.

Returns:

  • RubyAem::Result



45
46
47
# File 'lib/ruby_aem/resources/package.rb', line 45

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

#deleteObject

Delete the package.

Returns:

  • RubyAem::Result



62
63
64
# File 'lib/ruby_aem/resources/package.rb', line 62

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

#download(file_path) ⇒ Object

Download the package to a specified directory.

Parameters:

  • file_path

    the directory where the package will be downloaded to

Returns:

  • RubyAem::Result



92
93
94
95
# File 'lib/ruby_aem/resources/package.rb', line 92

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

#get_filterObject

Get the package filter value. Filter value is stored as result data as an array of paths.

Returns:

  • RubyAem::Result



117
118
119
# File 'lib/ruby_aem/resources/package.rb', line 117

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

#installObject

Install the package without waiting until the package status states it is installed.

Returns:

  • RubyAem::Result



76
77
78
# File 'lib/ruby_aem/resources/package.rb', line 76

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

#install_wait_until_readyObject

Install the package and wait until the package status states it is installed.

Returns:

  • RubyAem::Result



215
216
217
218
219
220
221
222
223
224
225
# File 'lib/ruby_aem/resources/package.rb', line 215

def install_wait_until_ready()
  result = install()
  with_retries(:max_tries => 30, :base_sleep_seconds => 2, :max_sleep_seconds => 2) { |retries_count|
    check_result = is_installed()
    puts 'Install check #%d: %s - %s' % [retries_count, check_result.data, check_result.message]
    if check_result.data == false
      raise StandardError.new(check_result.message)
    end
  }
  result
end

#is_installedObject

Check if this package is installed. True result data indicates that the package is installed, false otherwise.

Returns:

  • RubyAem::Result



172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/ruby_aem/resources/package.rb', line 172

def is_installed()
  packages = list_all().data
  package = packages.xpath("//packages/package[group=\"#{@call_params[:group_name]}\" and name=\"#{@call_params[:package_name]}\" and version=\"#{@call_params[:package_version]}\"]")
  last_unpacked_by = package.xpath('lastUnpackedBy')

  if not ['<lastUnpackedBy/>', '<lastUnpackedBy>null</lastUnpackedBy>'].include? last_unpacked_by.to_s
    message = "Package #{@call_params[:group_name]}/#{@call_params[:package_name]}-#{@call_params[:package_version]} is installed"
    is_installed = true
  else
    message = "Package #{@call_params[:group_name]}/#{@call_params[:package_name]}-#{@call_params[:package_version]} is not installed"
    is_installed = false
  end
  result = RubyAem::Result.new(message, nil)
  result.data = is_installed

  result
end

#is_uploadedObject

Check if this package is uploaded. True result data indicates that the package is uploaded, false otherwise.

Returns:

  • RubyAem::Result



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/ruby_aem/resources/package.rb', line 151

def is_uploaded()
  packages = list_all().data
  package = packages.xpath("//packages/package[group=\"#{@call_params[:group_name]}\" and name=\"#{@call_params[:package_name]}\" and version=\"#{@call_params[:package_version]}\"]")

  if package.to_s != ''
    message = "Package #{@call_params[:group_name]}/#{@call_params[:package_name]}-#{@call_params[:package_version]} is uploaded"
    is_uploaded = true
  else
    message = "Package #{@call_params[:group_name]}/#{@call_params[:package_name]}-#{@call_params[:package_version]} is not uploaded"
    is_uploaded = false
  end
  result = RubyAem::Result.new(message, nil)
  result.data = is_uploaded

  result
end

#list_allObject

List all packages available in AEM instance.

Returns:

  • RubyAem::Result



143
144
145
# File 'lib/ruby_aem/resources/package.rb', line 143

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

#replicateObject

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

Returns:

  • RubyAem::Result



84
85
86
# File 'lib/ruby_aem/resources/package.rb', line 84

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

#update(filter) ⇒ Object

Update the package with specific filter.

example: [href="">root”:“/apps/geometrixx”,“rules”:[],“root”:“/apps/geometrixx-common”,“rules”:</a>]

Parameters:

  • filter

    package filter JSON string

Returns:

  • RubyAem::Result



54
55
56
57
# File 'lib/ruby_aem/resources/package.rb', line 54

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

#upload(file_path, opts = { force: true }) ⇒ Object

Upload the package without waiting until the package status states it is uploaded.

  • force: if false then a package file will not be uploaded when the package already exists with the same group, name, and version, default is true (will overwrite existing package file)

Parameters:

  • file_path

    the directory where the package file to be uploaded is

  • force

    if true, then overwrite if the package already exists

  • opts (defaults to: { force: true })

    optional parameters:

Returns:

  • RubyAem::Result



104
105
106
107
108
109
110
111
# File 'lib/ruby_aem/resources/package.rb', line 104

def upload(file_path,
  opts = {
    force: true
  })
  @call_params[:file_path] = file_path
  @call_params = @call_params.merge(opts)
  @client.call(self.class, __callee__.to_s, @call_params)
end

#upload_wait_until_ready(file_path, opts = { force: true }) ⇒ Object

Upload the package and wait until the package status states it is uploaded.

  • force: if false then a package file will not be uploaded when the package already exists with the same group, name, and version, default is true (will overwrite existing package file)

Parameters:

  • file_path

    the directory where the package file to be uploaded is

  • force

    if true, then overwrite if the package already exists

  • opts (defaults to: { force: true })

    optional parameters:

Returns:

  • RubyAem::Result



197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/ruby_aem/resources/package.rb', line 197

def upload_wait_until_ready(file_path,
  opts = {
    force: true
  })
  result = upload(file_path, opts)
  with_retries(:max_tries => 30, :base_sleep_seconds => 2, :max_sleep_seconds => 2) { |retries_count|
    check_result = is_uploaded()
    puts 'Upload check #%d: %s - %s' % [retries_count, check_result.data, check_result.message]
    if check_result.data == false
      raise StandardError.new(check_result.message)
    end
  }
  result
end