Uploaded image for project: 'Olingo'
  1. Olingo
  2. OLINGO-741

UriParser unable to determine correct UriResource type when NavigationProperty has same name as an EntitySet

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: (Java) V4 4.0.0-beta-03
    • Fix Version/s: (Java) V4 4.0.0
    • Component/s: odata4-server
    • Labels:
      None

      Description

      UriParser unable to determine correct UriResource type when NavigationProperty has same name as an EntitySet.

      Example can be found in Tutorial Part 6 (p6_queryoptions-es) in Git Commit: [OLINGO-713] Added tutorial project for system query options - expand/select.

      Just start sample and navigate to http://localhost:8080/DemoService.svc/Categories(1)/?$expand=Products.

        Activity

        Hide
        mirbo Michael Bolz added a comment -

        Issue could be related to method Object visitExpandPath(final ExpandPathContext ctx).

        Change method as follows could fix this:

          @Override
          public Object visitExpandPath(final ExpandPathContext ctx) {
            ExpandItemImpl expandItem = new ExpandItemImpl();
        
            // UriResourceItImpl pathInfoIT = new UriResourceItImpl();
            UriResource lastPart = context.contextUriInfo.getLastResourcePart();
        
            // save context
            ExpandItemImpl contextExpandItemPathBU = context.contextExpandItemPath;
            UriInfoImpl uriInfoResourceBU = context.contextUriInfo;
        
            // set tmp context
            context.contextExpandItemPath = expandItem;
            context.contextUriInfo = new UriInfoImpl().setKind(UriInfoKind.resource);
            // contextUriInfo.addPathInfo(pathInfoIT);
            context.contextUriInfo.addResourcePart((UriResourceImpl) lastPart);
        
            super.visitExpandPath(ctx);
        
            if(context.contextUriInfo.getUriResourceParts().get(0) == lastPart) {
              context.contextUriInfo.removeResourcePart(0);
            }
        
            EdmType startType = removeUriResourceStartingTypeFilterImpl(context.contextUriInfo);
            expandItem.setResourcePath(context.contextUriInfo);
            if (startType != null) {
              expandItem.setTypeFilter(startType);
            }
        
            // reset context
            context.contextUriInfo = uriInfoResourceBU;
            context.contextExpandItemPath = contextExpandItemPathBU;
        
            return expandItem;
          }
        
        Show
        mirbo Michael Bolz added a comment - Issue could be related to method Object visitExpandPath(final ExpandPathContext ctx) . Change method as follows could fix this: @Override public Object visitExpandPath( final ExpandPathContext ctx) { ExpandItemImpl expandItem = new ExpandItemImpl(); // UriResourceItImpl pathInfoIT = new UriResourceItImpl(); UriResource lastPart = context.contextUriInfo.getLastResourcePart(); // save context ExpandItemImpl contextExpandItemPathBU = context.contextExpandItemPath; UriInfoImpl uriInfoResourceBU = context.contextUriInfo; // set tmp context context.contextExpandItemPath = expandItem; context.contextUriInfo = new UriInfoImpl().setKind(UriInfoKind.resource); // contextUriInfo.addPathInfo(pathInfoIT); context.contextUriInfo.addResourcePart((UriResourceImpl) lastPart); super .visitExpandPath(ctx); if (context.contextUriInfo.getUriResourceParts().get(0) == lastPart) { context.contextUriInfo.removeResourcePart(0); } EdmType startType = removeUriResourceStartingTypeFilterImpl(context.contextUriInfo); expandItem.setResourcePath(context.contextUriInfo); if (startType != null ) { expandItem.setTypeFilter(startType); } // reset context context.contextUriInfo = uriInfoResourceBU; context.contextExpandItemPath = contextExpandItemPathBU; return expandItem; }
        Hide
        mirbo Michael Bolz added a comment -

        Above fix did work but break other use cases.

        Final fix is to do a pre-validation in org.apache.olingo.server.core.uri.parser.UriParseTreeVisitor.readResourcePathSegment(...).

        See related commit: [OLINGO-741] Add pre-validation for properties in UriParseTreeVisitor.

        Show
        mirbo Michael Bolz added a comment - Above fix did work but break other use cases. Final fix is to do a pre-validation in org.apache.olingo.server.core.uri.parser.UriParseTreeVisitor.readResourcePathSegment(...) . See related commit: [OLINGO-741] Add pre-validation for properties in UriParseTreeVisitor .
        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit 1695437 from Michael Bolz in branch 'site/trunk'
        [ https://svn.apache.org/r1695437 ]

        Added note for issue OLINGO-741

        Show
        jira-bot ASF subversion and git services added a comment - Commit 1695437 from Michael Bolz in branch 'site/trunk' [ https://svn.apache.org/r1695437 ] Added note for issue OLINGO-741

          People

          • Assignee:
            mirbo Michael Bolz
            Reporter:
            mirbo Michael Bolz
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development