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

V1: prototype product API 2 CSV with json buffer #38

Open
wants to merge 8 commits into
base: obelink-xml-v3
Choose a base branch
from

Conversation

Thijzer
Copy link
Member

@Thijzer Thijzer commented May 9, 2023

This PR is meant to improve the handling API payload data in a better way.
It already introduced the following improvements:

  • JSON buffer files: quickly save your API date to a buffer, handy when testing or running multiple transformations on the same data, it also separates the slow API fetching so you could test your transformation a buffer data.
  • Akeneo Header formation : this code makes all the required headers from an attributes list
  • powerfull converters : more power is giving to the converter, when adding a converter the data is converted in example from API to editable DATA && from editable DATA back to API. Another benifit is you could connect data using 2 distinct converters, for example from API to editable data && from editable DATA to CSV.
  • the reader and writer can now accept a converter, reader with use the convert option, writer the revert option.
  • the encoder has been improved
  • we added a group formatter with separator to explode grouped fields

We are focusing on the following possible workflows ::
-> Fetch some API data, do some actions, respond with API data
-> Fetch some API data, do some actions, respond with API data, over a downloadable CSV
-> Fetch a CSV file, do some actions, respond with API data

All Actions have now Flat version tests so we can't break any of the current logic when we go and implement the new logic.

TODO

  • we need to adjust our actions to supports a new format of data
  • we need to discover new types of actions that are more focused on array data.
  • we need some kind of validation, as a directive in the first place, validation could run a every xTH item.
  • converter function convert / revert are bad, we have to improve so that we can determine the direction better

@tbrankaer tbrankaer self-requested a review August 16, 2023 12:42
'currencies' => [],
'has_locale' => false,
'has_scope' => false,
], $context);
}

public function add($code, string $type, array $context = []): void
public function addValue($code, string $type, array $context = []): void

Choose a reason for hiding this comment

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

Force code for string input.

{
if ($this->pipeline === null) {

Choose a reason for hiding this comment

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

Use is_null function instead?

@@ -292,6 +305,11 @@ public function createWriter(array $configuration): ItemWriterInterface
$factory = $this->factory->getFactory('writer');
$writer = $factory->createFromConfiguration($configuration, $this->getWorkFileManager());

if (isset($configuration['converter'])) {
$converter = $this->createConverter($configuration['converter']);
$this->config->getPipeline()->line(new RevertPipe($converter));

Choose a reason for hiding this comment

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

$converter variable needed? $this->config->getPipeline()->line(new RevertPipe($this->createConverter($configuration['converter'])));

@@ -348,6 +366,11 @@ public function createReader(array $configuration)
$factory = $this->factory->getFactory('reader');
$reader = $factory->createFromConfiguration($cursor, $configuration, $this->getConfig());

if (isset($configuration['converter'])) {
$converter = $this->createConverter($configuration['converter']);

Choose a reason for hiding this comment

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

Same. Variable needed?

];
private $decoder;

public function convert(array $item): array

Choose a reason for hiding this comment

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

Code duplication AkeneoProductApiConverter? Can we use one function for this?

case $class instanceof StringFormat:
$item[$property] = $class->reverseFormat($item[$property]);
break;
case $class instanceof ArrayFormat:
$item = $class->reverseFormat($item);
$item = $class->reverseFormat($item);

Choose a reason for hiding this comment

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

undo

if (isset($item[$property])) {
foreach ($matches as $match) {
$this->processMatch($item, $property, $match);
}
} else {

Choose a reason for hiding this comment

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

Avoid else, use continue instead

$this->getOption('separator')
);
}

Choose a reason for hiding this comment

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

Remove whitespace

{
return $this->implodeKeys($value, $this->getOption('separator'));
}

Choose a reason for hiding this comment

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

Remove whitespace

$newPath = $path . $key;
if (is_array($value) && $value !== []) {
$this->implodeKeys($value, $separator, $result, $newPath . $separator);
} else {

Choose a reason for hiding this comment

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

Use continue instead

{
foreach ($array as $key => $value) {
$newPath = $path . $key;
if (is_array($value) && $value !== []) {

Choose a reason for hiding this comment

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

!empty?

$newPath = $path . $key;
if (is_array($value) && $value !== []) {
$this->implodeKeys($value, $separator, $result, $newPath . $separator);
} else {

Choose a reason for hiding this comment

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

Use continue

});
} elseif (is_string($rowValue) && in_array($rowValue, ['UNIQUE', 'IS_NOT_NUMERIC', 'NOT_EMPTY', 'NOT_NULL'])) {

Choose a reason for hiding this comment

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

Use switch with default here?

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@Thijzer Thijzer changed the base branch from master to obelink-xml-v3 December 13, 2024 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants