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

TransformationMapping: API for adding mapping item #546

Merged

Conversation

mzazrivec
Copy link
Contributor

@mzazrivec mzazrivec commented Jan 23, 2019

This change implements new action (add_mapping_item) for transformation mapping: it adds new transformation mapping item to previously created transformation mapping.

Requested in https://trello.com/c/P5W747wT/217-spike-add-patch-method-to-api-transformationmappings-id (originally requested as a PATCH method, but using POST and new action is more straightforward).

Usage:

  1. Create transformation mapping with empty list of transformation mapping items
$ cat create-mapping.json
{
    "name": "infra-mapping",
    "description": "infra-mapping",
    "state": "draft",
    "transformation_mapping_items": []
}
$ curl -X POST -d @create-mapping.json http://appliance-url/api/transformation_mappings
...
  1. Add new transformation mapping item using the newly created action
$ cat add-mapping-item.json
{
    "action": "add_mapping_item",
    "resource": {
        "source": "/api/clusters/1",
        "destination": "/api/clusters/2"
    }
}
$ curl -X POST -d @add-mapping-item.json http://appliance-url/api/transformation_mappings/1

@himdel @michaelkro

https://bugzilla.redhat.com/show_bug.cgi?id=1689896

@djberg96
Copy link
Contributor

👍

@djberg96
Copy link
Contributor

@abellotti Can we merge?

@djberg96
Copy link
Contributor

@miq-bot add_reviewer @abellotti

@miq-bot miq-bot requested a review from abellotti February 18, 2019 13:30
rescue StandardError => err
raise BadRequestError, "Failed to update Transformation Mapping - #{err}"
end

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A little syntactic sugar you can use here is the Object#tap method. So you can write that like this:

resource_search(id, type, collection_class(type)).tap do |mapping|
  mapping.transformation_mapping_items.append(create_mapping_items([data]))
  mapping.save!
end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All right, fixed.

add_mapping_item action: to add new transformation mapping items
(clusters, lans, storages) to the transformation_mapping_items
array.
@mzazrivec mzazrivec force-pushed the transformation_mapping_add_mapping_item branch from 33d3972 to 999d5ec Compare March 6, 2019 09:25
@miq-bot
Copy link
Member

miq-bot commented Mar 6, 2019

Checked commits mzazrivec/manageiq-api@aab74eb~...999d5ec with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
2 files checked, 0 offenses detected
Everything looks fine. 🏆

@miq-bot
Copy link
Member

miq-bot commented Mar 6, 2019

@mzazrivec Cannot apply the following label because they are not recognized: transformation enhancement

@mzazrivec
Copy link
Contributor Author

@miq-bot add_label transformation, enhancement

@djberg96
Copy link
Contributor

djberg96 commented Mar 7, 2019

@bdunne @abellotti Look ok?

@abellotti abellotti self-assigned this Mar 12, 2019
@abellotti abellotti added this to the Sprint 107 Ending Mar 18, 2019 milestone Mar 12, 2019
@abellotti
Copy link
Member

Thanks @mzazrivec for the API Enhancement. LGTM!!! 👍

@abellotti abellotti merged commit 200ca55 into ManageIQ:master Mar 12, 2019
@mzazrivec mzazrivec deleted the transformation_mapping_add_mapping_item branch March 12, 2019 15:12
@ghost
Copy link

ghost commented Mar 18, 2019

@ghost
Copy link

ghost commented Mar 18, 2019

@miq-bot add_label hammer/yes

simaishi pushed a commit that referenced this pull request Mar 29, 2019
…ping_item

TransformationMapping: API for adding mapping item
(cherry picked from commit 200ca55)

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1693718
@simaishi
Copy link
Contributor

Hammer backport details:

$ git log -1
commit 374b2be4874fc6bfdc92ecc9b111c9b4a4087064
Author: Alberto Bellotti <abellotti@users.noreply.github.com>
Date:   Tue Mar 12 10:59:34 2019 -0400

    Merge pull request #546 from mzazrivec/transformation_mapping_add_mapping_item
    
    TransformationMapping: API for adding mapping item
    (cherry picked from commit 200ca55bb0736973dfaae9ad637da7d597d515f1)
    
    Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1693718

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

Successfully merging this pull request may close these issues.

5 participants