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

Adapter refactoring Level 04 #164

Merged
merged 95 commits into from
Jan 24, 2020
Merged

Conversation

alelom
Copy link
Member

@alelom alelom commented Nov 14, 2019

Alignment instructions

https://github.com/BHoM/BHoM_Adapter/wiki/BHoM_Adapter-refactoring-Level-04-alignment-instructions

NOTE: DEPENDS ON

BHoM/BHoM_Engine#1371

NOTE: BRANCHES DEPENDANT ON THIS (needed for testing)

BHoM/BHoM_UI#167

Issues addressed by this PR

Changes on Config and Settings: Closes #45 Closes #108

Changes on Delete action: Closes #138 Closes #156

Retrocompatibility: Closes #158

MapSpecialProperties: Closes #168

Project and folders rearrangements/tidy up: Closes #170, Closes #169, Closes #171

Test files

Test files for specific Toolkits to be found in their related alignment PR.

At the moment, you can only find GSA: BHoM/GSA_Toolkit#130

Changelog

  • CRUD base actions are called ICreate, IDelete, etc in order to follow Engine convention of interface methods "to be implemented"
  • New field m_AdapterSettings. This is where default settings to be used for the Adapter can be set once per build.
  • Replaced the config Dictionary<string,object> input for all Adapter Actions with a new class ActionConfig. It contains configs common to all Toolkits. It can be inherited in specific Toolkits to create other adapter-specific Configs.
  • Delete has been renamed to Remove.
  • UpdateProperty has been renamed to UpdateTag. It only handles tag which is the only correct use. Other cases must fall in Push scenarios.
  • MapSpecialProperties has been splitted in 2 separate methods: CopyBHoMObjectProperties that copies only IBHoMObject basic properties over; ICopyTypeSpecificProperties that's meant to copy type specific properties. Specific implementation of that must be done in specific Toolkits.
  • Introduction of PushType (and PullType) enum. Allow to select the type of Push being done (FullCRUD, DeleteThenCreate, CreateOnly, etc).
  • Added a Push Type and code implementation: DeleteThenCreate
  • Folder and files reorganisation:
    • Created new Adapter_oM project
    • Created new Adapter_Engine project
    • All methods and class definition that could be moved up to those project have been moved. Exceptions are only those methods that have to be left in the BHoMAdapter partial class in order to allow overrides in specific Toolkits.
    • General widespread tidy up of the code.
  • Introduced the concept of Adapter Modules. See this comment for a description.

…Only`, `DependenciesCreateOnly`, `DependenciesUpdateOnly`
There is not a single use case where they are used with non-IBHoMObjects anyway. This clarifies that they are meant to be implemented as part as the full CRUD
…ss name. #163

No need to store its value as a hard-coded value somewhere, like "Robot_id".

The initialisation had to be done inside a new BHoMAdapter constructor, because the identifier `this` is not available in the auto-property initialisers.
… 2) Added ActionConfig global property and logic to reset it at the start of each AdapterAction (except Move).
@alelom alelom self-assigned this Nov 14, 2019
@alelom alelom added the status:WIP PR in progress and still in draft, not ready for formal review label Nov 14, 2019
…now in BHoM_UI (except for the Move, which must have it here)
- UpdateTags is not a CRUD method because there is no CRUD action involved; it's only used to update (if existing) a collection of tags to be stored in a private field of the specific adapter. Moved in new folder "SupportMethods".
- MapSpecialProperties might end up in "SupportMethods" too
- Refactored the Push to allow for AdapterSettings to be overridden with more ActionConfig, especially for the PushType
- Added a PushType for `DeleteAllThenCreate` that should clean the exported model and then create stuff in it.
- Added method in FullCRUD that does the previous. Uses the DiffingEngine "HashComparing", but only to avoid Deleting and then Creating the same stuff.
- MapSpecialProperties must be abstracted more. Renamed as `PortProperties`. Added generic method that does the same thing, but for any object and given a propertyName.
- When the new PortProperties is called by the adapter, specific adapter implementation can say what properties should be ported. This work has to be finished.
The generic `PortProperties` might be useless. Being a feature addition I'll keep it.
JosefTaylor
JosefTaylor previously approved these changes Jan 22, 2020
// Performs a Pull and then a Push. Useful to move data between two different software without passing it through the UI.
public virtual bool Move(BHoMAdapter to, IRequest request, Dictionary<string, object> pullConfig = null, Dictionary<string, object> pushConfig = null)
[Description("Performs a Pull and then a Push. Useful to move data between two different software without passing it through the UI.")]
public virtual bool Move(IBHoMAdapter to, IRequest request,
Copy link
Member

Choose a reason for hiding this comment

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

I feel that this is actually a copy rather than a move at this point.

@epignatelli epignatelli self-requested a review January 23, 2020 11:30
Copy link
Member

@epignatelli epignatelli left a comment

Choose a reason for hiding this comment

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

That's a big refactoring! I felt it made the HTTPAdapter simpler when amending the code do comply with this.

Some observations I made with @alelom while reviewing this.
The come with a green tick because I believe the best time to do these is in the next wave.

  1. When performing an action, like a Push or a Pull, I feel that the information to include are sparser than they can be. I.e. PullType can be a property of the ActionConfig. This takes us to specifty the ActionConfig into PullConfig, PushConfig, ExecuteConfig, MoveConfig, and RemoveConfig. They all inherit from ActionConfig. All of this allows to keep the information more compressed and I feel that's more intuitive.
  2. In the light of 1., the ActionConfig can be removed from the Create, as it is never used.
  3. I never know if to override the Pull or the Read or any other one, when I need to perform a task. I prefer to be channeled to override only one or the other, otherwise the implementer is completely lost in there. My suggestion is to use the pattern Grasshopper uses for the component. To disable the override of a Pull or a Push, and add two functions BeforeAction and AfterAction, the same way Grasshopper implements BeforeSolveInstance and AfterSolveIntance. This way if you need to wrap your objects around BHoMObjects or anything else, you can override these two.

Copy link
Contributor

@FraserGreenroyd FraserGreenroyd left a comment

Choose a reason for hiding this comment

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

Based on the tests I have run on my toolkits as part of the refactoring process, this is good to me. I have not reviewed the code but can see from comments that others have.

@alelom
Copy link
Member Author

alelom commented Jan 24, 2020

My suggestion is to use the pattern Grasshopper uses for the component. To disable the override of a Pull or a Push, and add two functions BeforeAction and AfterAction, the same way Grasshopper implements BeforeSolveInstance and AfterSolveIntance. This way if you need to wrap your objects around BHoMObjects or anything else, you can override these two.

This is really a good suggestion! It would simplify things. However, we must also consider that overriding the "core" action might be needed in some cases, as brought up by @adecler.
But if we include a "BeforeSolve" and "AfterSolve", we could at least make this "unadvisable", limiting overrides to only the strictly neededed cases. Like saying, if you override the action, then you need to make sure you understand what is needed for it to work properly: like implementing some checks that should come with it.

@FraserGreenroyd
Copy link
Contributor

/azp run BHoM_Adapter.CheckInstaller

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@al-fisher al-fisher changed the title Adapter refactoring Level04 Adapter refactoring Level 04 Jan 24, 2020
@al-fisher al-fisher added the type:compliance Non-conforming to code guidelines label Jan 24, 2020
Copy link
Member

@al-fisher al-fisher left a comment

Choose a reason for hiding this comment

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

Happy to approve this. Tested on a number of different Adapter_Toolkits.
And in addition approval based on the very valuable restructuring of the Adapter itself, and the successful passing reviews on the many dependant PRs.

@FraserGreenroyd FraserGreenroyd removed the status:do-not-merge For instance, test PR, for discussion, or dependant PRs not ready for merge label Jan 24, 2020
@alelom alelom merged commit 610e130 into master Jan 24, 2020
@alelom alelom deleted the BHoM_Adapter-refactoringLvl04-01 branch January 24, 2020 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment