Skip to content

Fix #2056: opertation returns path for the return entity set or singl… - #2060

Closed
xuzhg wants to merge 2 commits into
OData:masterfrom
xuzhg:issue2056
Closed

xuzhg wants to merge 2 commits into
OData:masterfrom
xuzhg:issue2056

Conversation

@xuzhg

@xuzhg xuzhg commented Feb 19, 2020

Copy link
Copy Markdown
Contributor

…eton

Issues

This pull request fixes issue ##2056.

Description

  • If Operation returns "entity set". we should set the "Path" on "WriterSetting" for that "entity set".

Checklist (Uncheck if it is not completed)

  • Test cases added
  • Build and test with one-click build and test script passed

Additional work necessary

If documentation update is needed, please add "Docs Needed" label to the issue and provide details about the required document change in the issue.

@habbes

habbes commented Feb 20, 2020 •

Copy link
Copy Markdown
Contributor

@xuzhg could you add test cases for this feature? And maybe add a bit more details to the description explaining why it fixes the issue? #Resolved

@mikepizzo mikepizzo added this to the 7.4 Beta milestone Feb 26, 2020
@xuzhg xuzhg added the Ready for review Use this label if a pull request is ready to be reviewed label Feb 27, 2020
return path.Path;
}

private static Microsoft.OData.UriParser.ODataPath GeneratePath(IEdmEntitySetBase entitySetBase)

@Sreejithpin Sreejithpin Feb 27, 2020 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor: Can move it to a Factory implementation. #WontFix

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is only used in this class once. So, it's better to keep it private in this helper class.


In reply to: 384850926 [](ancestors = 384850926)


var tasks = new ProjectTask[]
{
new ProjectTask { Id = "1", ProjectId = "11",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe indent the elements of the array.

{
new ProjectTaskAssignment { Id = "22", ProjectTaskId = "2" }
}
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

shouldn't this use the projectTasks passed in the payload?

@mikepizzo

mikepizzo commented Feb 27, 2020 •

Copy link
Copy Markdown
Contributor

+1 -- please add a test case.

Should also support contained entity sets, although we could open a separate work item for that.


In reply to: 589150185 [](ancestors = 589150185)

return new Microsoft.OData.UriParser.ODataPath(new SingletonSegment((IEdmSingleton)entitySetBase));

case EdmNavigationSourceKind.ContainedEntitySet:
// TODO: for containment, do we have the scenario to return a containment in an operation?

@mikepizzo mikepizzo Feb 27, 2020 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes; this should be supported. This may seem like an edge case, but for services like Microsoft Graph that organize different sources of data through a singleton navigation property it is actually the common scenario. #Closed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I add codes to process this case. Please take a look


In reply to: 385351278 [](ancestors = 385351278)

@xuzhg

xuzhg commented Feb 28, 2020

Copy link
Copy Markdown
Contributor Author

Added E2E test cases. Please take a look.


In reply to: 592155477 [](ancestors = 592155477,589150185)

@xuzhg

xuzhg commented Mar 2, 2020 •

Copy link
Copy Markdown
Contributor Author


case EdmNavigationSourceKind.ContainedEntitySet:
IEdmContainedEntitySet containedEntitySet = (IEdmContainedEntitySet)navigationSource;
var path = GeneratePath(containedEntitySet.ParentNavigationSource);

@mikepizzo mikepizzo Mar 2, 2020 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

var [](start = 20, length = 3)

var [](start = 20, length = 3)

better not to use var #Closed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes. I know. I originally thought it's easy to use "var" not "Microsoft.OData.UriParser.ODataPath". But I changed.


In reply to: 386706993 [](ancestors = 386706993)

}
}

segments.Add(new NavigationPropertySegment(containedEntitySet.NavigationProperty, containedEntitySet.ParentNavigationSource));

@mikepizzo mikepizzo Mar 2, 2020 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is this the right behavior for path == null? if path==null, shouldn't you just return null?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Emm... probably. in ODL, IEdmContainedEntitySet interface is public, but there's only one implementation "EdmContainedEntitySet" is internal. That means user can't create a "EdmContainedEntitySet" instance. If you can get an instance of "IEdmContainedEntitySet", the ParentNavigationSource should be valid. So, i'd like to remove the conditional verification.


In reply to: 386708095 [](ancestors = 386708095)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This method looks similar to the ComputePath() method in EdmContainedEntitySet, which is unfortunately internal. However, that method deals with nav props defined on derived types. Do we need to do anything to handle that case here?

Also a bit concerned that EdmContainedEntitySet allows passing in a navigationPath, which is used in ComputePath. What are the situations in which that would be something other than the navigationProperty? Would this be used for nav props on complex types? Do we need to handle that case here?


In reply to: 386750791 [](ancestors = 386750791,386708095)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

EdmContainedEntitySet constructor makes the input check. That can make sure "ParentNavigationSource" never be null if the "EntityContainedEntitySet" is live.

public EdmContainedEntitySet(IEdmNavigationSource parentNavigationSource, IEdmNavigationProperty navigationProperty, IEdmPathExpression navigationPath)
: base(navigationProperty.Name, navigationProperty.ToEntityType())
{
EdmUtil.CheckArgumentNull(parentNavigationSource, "parentNavigationSource");
...

        this.parentNavigationSource = parentNavigationSource;
        this.navigationProperty = navigationProperty;
        this.navigationPath = navigationPath;
    }

In reply to: 391139997 [](ancestors = 391139997,386750791,386708095)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Besides, for the ComputePath() method in EdmContainedEntitySet, we can call " containedEntitySet.Path" to get the Path. However, "Path" is IEdmPathExpression, it's a string segment.
We want the ODataPath, it's a path segments. So, we have to use "OData Uri parse" to parse the "IEdmPathExpression". That's not feasible here.
I'd like to create a new issue to track on this feature request. And I do think that's a feature in the ODL .

@mikep


In reply to: 394725483 [](ancestors = 394725483,391139997,386750791,386708095)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@[email protected] -- did you create an issue to track this? Please specifically call out what is not currently supported (i.e., how does this code handle navigation properties on complex types or navigation properties defined on derived types? does it work with navigation properties on entities returned from contained navigation properties?)


In reply to: 394726333 [](ancestors = 394726333,394725483,391139997,386750791,386708095)


private static Microsoft.OData.UriParser.ODataPath GeneratePath(IEdmNavigationSource navigationSource)
{
switch (navigationSource.NavigationSourceKind())

@mikepizzo mikepizzo Apr 1, 2020 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe add assert that navigationSource != null #Closed

return null;
}

if (IsOperationPath(path))

@mikepizzo mikepizzo Apr 1, 2020 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What is the value in doing this check? It's going to walk the path looking for an operationSegment or operationImportSegment, and if it returns true, we're going to go to the last segment and check to see if it's an operationSegment or operationImportSegment. Can we remove the IsOperationPath(path) check and just rely on the existing checks on line 363 and 369? The only difference I can see in doing the check first is that the current logic will return a null if there is an operation (i.e., a composible function) in the path but not as the last segment -- is that desired behavior? #Resolved

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'd like to keep the behavior unchanged. if we consider the compossible function, the logic here is not enough to cover it.


In reply to: 401841900 [](ancestors = 401841900)

public async Task BoundFunctionWithContainmentReturnTypeWorksWithCorrectContextUri()
{
// Arrange
var requestUri = string.Format("{0}/odata/Projects/Default.GetAssigments", BaseAddress);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

how about adding a segment after the bound function call, i.e.:
-Projects/Default.GetAssignments/111
-Projects/Default.GetAssignments/Default.ProjectTaskAssignment

public async Task BoundFunctionWithNonContainmentReturnTypeWorksWithCorrectContextUri()
{
// Arrange
var requestUri = string.Format("{0}/odata/Projects/Default.GetProjectTask", BaseAddress);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

       var requestUri = string.Format("{0}/odata/Projects/Default.GetProjectTask" [](start = 0, length = 86)

how about adding a segment after the bound function call, i.e.:
-Projects/Default.GetProjectTask/1
-Projects/Default.GetDefaultProjectTask/Default.ProjectTask

@mikepizzo mikepizzo left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🕐

A couple small comments -- please take a look and let me know your thoughts, then we can approve. Would like to get this in soon.

@mikepizzo mikepizzo removed the Ready for review Use this label if a pull request is ready to be reviewed label Apr 1, 2020
@mikepizzo mikepizzo modified the milestones: 7.4 Beta, 7.5 May 6, 2020
@mikepizzo

Copy link
Copy Markdown
Contributor

Still have a couple of small comments, but nothing to block merging.

@mikepizzo mikepizzo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

:shipit:

xuzhg added a commit that referenced this pull request Sep 16, 2020
@xuzhg

xuzhg commented Sep 16, 2020

Copy link
Copy Markdown
Contributor Author

Merged at c79634a

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.

5 participants