Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cq_jcr copy action #45

Open
mariozet opened this issue Mar 23, 2017 · 0 comments
Open

cq_jcr copy action #45

mariozet opened this issue Mar 23, 2017 · 0 comments

Comments

@mariozet
Copy link

mariozet commented Mar 23, 2017

It would be nice to have copy action in cq_jcr resource in order to make simple changes which not need groovy scripts.

In my example I had to copy node with its children to new location and overwrite destination nodes with new one.
However, copy action should be possible only for one particular node.

Use full sling API reference:
http://sling.apache.org/documentation/bundles/manipulating-content-the-slingpostservlet-servlets-post.html#copying-content

Additionally I've wrote small module in my cookbook which can be useful:

module JcrHelper
  include Cq::HttpHelper

  def copy_node(instance, path, user, pass, src, dst, force)
    payload = {
        ':operation' => 'copy',
        ':applyTo' => "#{src}",
        ':dest' => "#{dst}",
        ':replace' => "#{force}"
      }

    http_resp = http_multipart_post(
      instance,
      path,
      user,
      pass,
      payload
    )

    validate_resp(http_resp, path)
  end

  def validate_resp(http_resp, path)
    Chef::Application.fatal!(
      "Something went wrong during operation on #{path}\n"\
      "HTTP response code: #{http_resp.code}\n"\
      "HTTP response body: #{http_resp.body}\n"\
      'Please check error.log file to get more info.'
    ) unless http_resp.code.start_with?('20')
  end

end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants