violet_rails
violet_rails copied to clipboard
Unique string aggregator plugin
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
resolve_string_path'sapi_namespace_slugshould be the same API Namespace the External API Connection is running on.- raise exception "API Namespace resource pollution detected, check resolve_string_path and output_api_namespace" if
resolve_string_path's "api_namespace_slug" andoutput_api_namespace's "api_namespace_slug" are the same - if
pristineis set totrue, collect all ID's of all existing API Resources in the target API Namespace and delete them after successful connection execution
Logic
-
if
pristineis set totrue: 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 -
Access the
resolve_string_pathin the current API Namespace, and loop over all the API Resources building a hash. -
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.
@Sushmit1997 have you had a chance to take a look at this?
@donrestarone Yes, I'm looking at this. Will post estimates shortly.
@Sushmit1997 have you had a chance to take a look at this?
I've posted estimate for this task in my backlog.
@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
- 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 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 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
@Ayon95 any updates on this?
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.