violet_rails icon indicating copy to clipboard operation
violet_rails copied to clipboard

Unique string aggregator plugin

Open donrestarone opened this issue 3 years ago • 9 comments
trafficstars

given a JSON path that points to a string value, this plugin will scan the the associated API Resources of the API Namespace it is run against to output a unique list of API Resources to a target API Namespace

Namespace

NA since it runs on an existing Namespace

Properties

resolve_string_path: "api_namespace_slug.some_property.another_property" output_api_namespace: "api_namespace_slug" pristine: boolean

Algorithm

Validations

  1. resolve_string_path's api_namespace_slug should be the same API Namespace the External API Connection is running on.
  2. raise exception "API Namespace resource pollution detected, check resolve_string_path and output_api_namespace" if resolve_string_path's "api_namespace_slug" and output_api_namespace's "api_namespace_slug" are the same
  3. if pristine is set to true, collect all ID's of all existing API Resources in the target API Namespace and delete them after successful connection execution

Logic

  1. if pristine is set to true: calculate all the ID's of the API resources to delete in the target API Namespace, assign that to a variable and remove them after the algorithm runs

  2. Access the resolve_string_path in the current API Namespace, and loop over all the API Resources building a hash.

  3. Take the hash and loop over the keys creating an API Resource in the target namespace for each key. The created API Resources should have the following format:
    property_name (derived form "api_namespace_slug.some_property.another_property" inresolve_string_path )

{
`property_name`: "string value"  
}

in the example property_name is the resulting property of the JSON path evaluation in "api_namespace_slug.some_property.another_property"

Example

API Namespace: Movies

title: 'titanic',
tags: ['romance', 'shipbuilding']

given an API Namespace of movies, build a unique list of tags that each movie is tagged under.

donrestarone avatar Sep 05 '22 13:09 donrestarone

@Sushmit1997 have you had a chance to take a look at this?

donrestarone avatar Sep 09 '22 22:09 donrestarone

@donrestarone Yes, I'm looking at this. Will post estimates shortly.

Sushmit1997 avatar Sep 10 '22 14:09 Sushmit1997

@Sushmit1997 have you had a chance to take a look at this?

I've posted estimate for this task in my backlog.

Sushmit1997 avatar Sep 10 '22 15:09 Sushmit1997

@donrestarone

In logic number 1, what does assign that to a variable means? And I didn't get logic number 3

CC @Pralish @alis-khadka

Sushmit1997 avatar Sep 11 '22 15:09 Sushmit1997

@Sushmit1997

  1. This is to ensure that the unique index is rebuilt each time the plugin is run. You should capture the existing ID's (if any) into a variable and destroy them after the algorithm runs (this is the stale set)

Example:

API Namespace: Movies attributes: title, tags (array)

title: Titanic tags: ['romance', ships]

title: Hunt for Red October tags: ['cold war', 'ships']

title: Lost tags: ['fantasy']

  • the very first time the plugin runs over the above data set, there will be nothing to destroy (because there are no tags in the target namespace
  • the second time the plugin runs over the above data set, it should first calculate all the existing tags (eg: romance, ships, Cold War, fantasy)-- run the algorithm and delete the old ones before inserting the new ones (eg: romance, ships, Cold War, fantasy)

donrestarone avatar Sep 11 '22 16:09 donrestarone

@donrestarone What exactly do you mean by hash map?

Is it the array of something like

title: Hunt for Red October tags: ['cold war', 'ships']

and can you give an example of logic 3? It would be easier to understand with clear example.

Sushmit1997 avatar Sep 11 '22 16:09 Sushmit1997

@Sushmit1997 its a hash (see corrected). It maps as follows:

{
'cold war' => [API_RESOURCE_IDS],
'fantasy' => [API_RESOURCE_IDS],
}

The API_RESOURCE_IDS above are the API_RESOURCE_IDS of the movies Titanic, Lost etc

donrestarone avatar Sep 11 '22 16:09 donrestarone

@Ayon95 any updates on this?

donrestarone avatar Sep 23 '22 16:09 donrestarone

Is it necessary to build a hash? Our aim is to look at all the array values of one property of each API resource and then generate an array of unique values.

Ayon95 avatar Sep 26 '22 13:09 Ayon95