[MGNLREST-157] Endpoint doesn't get updated after decorating intially Created: 01/Dec/17  Updated: 18/Dec/17  Resolved: 18/Dec/17

Status: Closed
Project: Magnolia REST Framework
Component/s: None
Affects Version/s: 2.0.1
Fix Version/s: 2.0.1

Type: Bug Priority: Neutral
Reporter: Hieu Nguyen Duc Assignee: Dai Ha
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: 0d
Time Spent: 2d 3.5h
Original Estimate: 5.5h

Attachments: Zip Archive add-features-1.zip     Zip Archive rest-test.zip    
Issue Links:
Relates
relates to MGNLREST-138 Cannot decorate the delivery endpoint Closed
relates to MGNLREST-158 TourFinder endpoint overlaps newly re... Closed
Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled
Date of First Response:
Sprint: Saigon 125, Saigon 126
Story Points: 1

 Description   

Since I'm not sure whether this issue comes from "rest" or "main", feel free to move it to correct place.

Steps to reproduce:

+ Add "rest-test" to your light module folder
-> Endpoint works
+ Add "add-features-1" to your light module folder
-> Definitions app shows the correct endpoint but the endpoint doesn't get updated
+ Change "depth" in decoration file
-> The endpoint works with updated value



 Comments   
Comment by Mikaël Geljić [ 04/Dec/17 ]

Goal is first to validate where solution for MGNLREST-138 fails.

Comment by Dai Ha [ 06/Dec/17 ]

Rest is using customized logic to addDecorator as below:

@Override
    public void addDecorator(DefinitionDecorator<EndpointDefinition> decorator) {
        Optional<DefinitionProvider<EndpointDefinition>> targetProvider = getAllProviders().stream()
                .filter(decorator::appliesTo)
                .findFirst();
        super.addDecorator(decorator);
        targetProvider.ifPresent(provider -> systemEventBus.fireEvent(new EndpointDefinitionRegistryEvent(REREGISTERED, provider)));
    }

Definition is decorated in getAllProviders() call, with a valid provider. In case of new decoration file is added in light module, decoration process is trigger without an existing decorator to handle decoration -> the definition is the original one.
Then super.addDecorator(decorator) is called --> next time we change decoration file, there is a decorator to handle decoration --> the definition is merged.

Suggesstion: super.addDecorator(decorator) should be called before getAllProviders(). Sample code:

@Override
    public void addDecorator(DefinitionDecorator<EndpointDefinition> decorator) {
        super.addDecorator(decorator);
        Optional<DefinitionProvider<EndpointDefinition>> targetProvider = getAllProviders().stream()
                .filter(decorator::appliesTo)
                .findFirst();
        if(!targetProvider.isPresent()) {
            super.removeDecorator(decorator);
        }
        targetProvider.ifPresent(provider -> systemEventBus.fireEvent(new EndpointDefinitionRegistryEvent(REREGISTERED, provider)));
    }
Generated at Mon Feb 12 06:57:11 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.