org.apache.olingo.server.api.uri.UriInfoResource Java Examples

The following examples show how to use org.apache.olingo.server.api.uri.UriInfoResource. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CarsProcessor.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private EdmEntitySet getEdmEntitySet(final UriInfoResource uriInfo) throws ODataApplicationException {
  final List<UriResource> resourcePaths = uriInfo.getUriResourceParts();
  /*
   * To get the entity set we have to interpret all URI segments
   */
  if (!(resourcePaths.get(0) instanceof UriResourceEntitySet)) {
    throw new ODataApplicationException("Invalid resource type for first segment.",
        HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ENGLISH);
  }

  /*
   * Here we should interpret the whole URI but in this example we do not support navigation so we throw an exception
   */

  final UriResourceEntitySet uriResource = (UriResourceEntitySet) resourcePaths.get(0);
  return uriResource.getEntitySet();
}
 
Example #2
Source File: OrderByHandler.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
public static void applyOrderByOption(final OrderByOption orderByOption, final EntityCollection entitySet,
    final UriInfoResource uriInfo, final Edm edm) throws ODataApplicationException {

  if (orderByOption == null) {
    return;
  }

  try {
    applyOrderByOptionInternal(orderByOption, entitySet, uriInfo, edm);
  } catch (SystemQueryOptionsRuntimeException e) {
    if (e.getCause() instanceof ODataApplicationException) {
      // Throw the nested exception, to send the correct HTTP status code in the HTTP response
      throw (ODataApplicationException) e.getCause();
    } else {
      throw new ODataApplicationException("Exception in orderBy evaluation",
          HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.ROOT);
    }
  }
}
 
Example #3
Source File: ExpandSelectMock.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private static UriInfoResource mockResourceOnComplexTypesWithNav(final EdmEntitySet edmEntitySet,
    final String name, final String navProperty) {
  EdmStructuredType type = edmEntitySet.getEntityType();
  List<UriResource> elements = new ArrayList<UriResource>();
  final EdmElement edmElement = type.getProperty(name);
  final EdmProperty property = (EdmProperty) edmElement;
  UriResourceComplexProperty element = Mockito.mock(UriResourceComplexProperty.class);
  Mockito.when(element.getProperty()).thenReturn(property);
  elements.add(element);
  
  mockNavPropertyOnEdmType(navProperty, elements, property);
  
  UriInfoResource resource = Mockito.mock(UriInfoResource.class);
  Mockito.when(resource.getUriResourceParts()).thenReturn(elements);
  return resource;
}
 
Example #4
Source File: ExpandSystemQueryOptionHandler.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private void applyOptionsToEntityCollection(final EntityCollection entitySet,
    final EdmBindingTarget edmBindingTarget,
    final FilterOption filterOption, final OrderByOption orderByOption, final CountOption countOption,
    final SkipOption skipOption, final TopOption topOption, final ExpandOption expandOption,
    final UriInfoResource uriInfo, final Edm edm)
    throws ODataApplicationException {

  FilterHandler.applyFilterSystemQuery(filterOption, entitySet, uriInfo, edm);
  OrderByHandler.applyOrderByOption(orderByOption, entitySet, uriInfo, edm);
  CountHandler.applyCountSystemQueryOption(countOption, entitySet);
  SkipHandler.applySkipSystemQueryHandler(skipOption, entitySet);
  TopHandler.applyTopSystemQueryOption(topOption, entitySet);

  // Apply nested expand system query options to remaining entities
  if (expandOption != null) {
    for (final Entity entity : entitySet.getEntities()) {
      applyExpandOptionToEntity(entity, edmBindingTarget, expandOption, uriInfo, edm);
    }
  }
}
 
Example #5
Source File: ExpandSelectMock.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private static UriInfoResource mockResourceOnDerivedEntityAndComplexTypes(
    final String name, final EdmType derivedEntityType, final EdmType derivedComplexType, 
    final String pathSegment) {
  EdmStructuredType type = (EdmStructuredType) derivedEntityType;
  List<UriResource> elements = new ArrayList<UriResource>();
  mockComplexPropertyWithTypeFilter(name, derivedComplexType, type, elements);
  
  final EdmElement edmElement1 = ((EdmStructuredType) derivedComplexType).getProperty(pathSegment);
  UriResourceNavigation element1 = Mockito.mock(UriResourceNavigation.class);
  Mockito.when(element1.getProperty()).thenReturn((EdmNavigationProperty) edmElement1);
  elements.add(element1);
  
  UriInfoResource resource = Mockito.mock(UriInfoResource.class);
  Mockito.when(resource.getUriResourceParts()).thenReturn(elements);
  return resource;
}
 
Example #6
Source File: ExpandSelectMock.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private static UriInfoResource mockResourceMultiLevelOnDerivedComplexTypes(final EdmEntitySet edmEntitySet, 
    final String pathSegmentBeforeCast,
    final String name, final EdmType derivedType, final String pathSegmentAfterCast) {
  EdmStructuredType type = edmEntitySet.getEntityType();
  List<UriResource> elements = new ArrayList<UriResource>();
  final EdmElement edmElement = type.getProperty(name);
  final EdmProperty property = (EdmProperty) edmElement;
  UriResourceComplexProperty element = Mockito.mock(UriResourceComplexProperty.class);
  Mockito.when(element.getProperty()).thenReturn(property);
  elements.add(element);
  
  if (pathSegmentBeforeCast != null) {
    mockComplexPropertyWithTypeFilter(pathSegmentBeforeCast, (EdmComplexType) derivedType, 
        (EdmStructuredType) edmElement.getType(), elements);
  }
  
  mockPropertyOnDerivedType(derivedType, pathSegmentAfterCast, elements);
  
  UriInfoResource resource = Mockito.mock(UriInfoResource.class);
  Mockito.when(resource.getUriResourceParts()).thenReturn(elements);
  return resource;
}
 
Example #7
Source File: DataProvider.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private Map<String, Parameter> getFunctionParameters(final EdmFunction function,
    final List<UriParameter> parameters, final UriInfoResource uriInfo) throws DataProviderException {
  Map<String, Parameter> values = new HashMap<String, Parameter>();
  for (final UriParameter parameter : parameters) {
    if (parameter.getExpression() != null && !(parameter.getExpression() instanceof Literal)) {
      throw new DataProviderException("Expression in function-parameter value is not supported yet!",
          HttpStatusCode.NOT_IMPLEMENTED);
    }
    final EdmParameter edmParameter = function.getParameter(parameter.getName());
    final String text = parameter.getAlias() == null ?
        parameter.getText() :
        uriInfo.getValueForAlias(parameter.getAlias());
    if (text != null) {
      try {
        values.put(parameter.getName(),
            odata.createFixedFormatDeserializer().parameter(text, edmParameter));
      } catch (final DeserializerException e) {
        throw new DataProviderException("Invalid function parameter.", HttpStatusCode.BAD_REQUEST, e);
      }
    }
  }
  return values;
}
 
Example #8
Source File: ContextURLHelperTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void buildExpandWithSelectHavingDerivedEntityType() throws Exception {
  final EdmEntitySet entitySet = entityContainer.getEntitySet("ESKeyNavCont");
  final EdmEntityType derivedEntityType = edm.getEntityType(
      new FullQualifiedName("olingo.odata.test1.ETBaseTwoKeyNav"));
  final EdmProperty edmProperty = derivedEntityType.getStructuralProperty("PropertyDate");
  ExpandItem expandItem = ExpandSelectMock.mockExpandItem(entitySet, "NavPropertyETTwoKeyNavContOne");
  SelectItem selectItem = Mockito.mock(SelectItem.class);
  Mockito.when(selectItem.getStartTypeFilter()).thenReturn(derivedEntityType);
  final UriInfoResource resource = ExpandSelectMock.mockComplexTypeResource(edmProperty);
  Mockito.when(selectItem.getResourcePath()).thenReturn(resource);
  final SelectOption selectOption = ExpandSelectMock.mockSelectOption(Arrays.asList(selectItem));
  Mockito.when(expandItem.getSelectOption()).thenReturn(selectOption);
  final ExpandOption expand = ExpandSelectMock.mockExpandOption(Arrays.asList(expandItem));
  final ContextURL contextURL = ContextURL.with().entitySet(entitySet)
      .selectList(ContextURLHelper.buildSelectList(entitySet.getEntityType(), expand, null)).build();
  assertEquals("$metadata#ESKeyNavCont(NavPropertyETTwoKeyNavContOne("
      + "PropertyInt16,PropertyString,olingo.odata.test1.ETBaseTwoKeyNav/PropertyDate))", 
      ContextURLBuilder.create(contextURL).toASCIIString());
}
 
Example #9
Source File: ODataJsonSerializerTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void complexCollectionWithSelectProperty() throws Exception {
  final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESKeyNav");
  final EdmProperty edmProperty = (EdmProperty) edmEntitySet.getEntityType().getProperty("CollPropertyComp");
  final Property property = data.readAll(edmEntitySet).getEntities().get(0).getProperty(edmProperty.getName());
  final EdmComplexType complexType = metadata.getEdm().getComplexType(
      new FullQualifiedName("olingo.odata.test1", "CTPrimComp"));
  final EdmProperty propertyWithinCT = (EdmProperty) complexType.getProperty("PropertyInt16"); 
  
  final UriInfoResource resource = ExpandSelectMock.mockComplexTypeResource(propertyWithinCT);
  final SelectItem selectItem = ExpandSelectMock.mockSelectItemForColComplexProperty(resource);
  final SelectOption selectOption = ExpandSelectMock.mockSelectOption(Arrays.asList(selectItem));
  
  final String resultString = IOUtils.toString(serializer
      .complexCollection(metadata, (EdmComplexType) edmProperty.getType(), property,
          ComplexSerializerOptions.with()
              .contextURL(ContextURL.with()
                  .entitySet(edmEntitySet).keyPath("1")
                  .navOrPropertyPath("CollPropertyComp")
                  .build()).select(selectOption)
              .build()).getContent());
  Assert.assertEquals("{\"@odata.context\":\"../$metadata#ESKeyNav(1)/CollPropertyComp\","
      + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\","
      + "\"value\":[{\"PropertyInt16\":1},{\"PropertyInt16\":2},{\"PropertyInt16\":3}]}",
      resultString);
}
 
Example #10
Source File: ODataJsonSerializerTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void complexCollectionPropertyWithSelectNoMetadata() throws Exception {
  final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESKeyNav");
  final EdmProperty edmProperty = (EdmProperty) edmEntitySet.getEntityType().getProperty("CollPropertyComp");
  final Property property = data.readAll(edmEntitySet).getEntities().get(0).getProperty(edmProperty.getName());
  
  final EdmComplexType complexType = metadata.getEdm().getComplexType(
      new FullQualifiedName("olingo.odata.test1", "CTPrimComp"));
  final EdmProperty propertyWithinCT = (EdmProperty) complexType.getProperty("PropertyInt16"); 
  
  final UriInfoResource resource = ExpandSelectMock.mockComplexTypeResource(propertyWithinCT);
  final SelectItem selectItem = ExpandSelectMock.mockSelectItemForColComplexProperty(resource);
  final SelectOption selectOption = ExpandSelectMock.mockSelectOption(Arrays.asList(selectItem));
  
  final String resultString = IOUtils.toString(serializerNoMetadata
      .complexCollection(metadata, (EdmComplexType) edmProperty.getType(), property, ComplexSerializerOptions.with()
          .contextURL(ContextURL.with()
              .entitySet(edmEntitySet).keyPath("1")
              .navOrPropertyPath("CollPropertyComp")
              .build()).select(selectOption).build()).getContent());
  Assert.assertEquals("{\"value\":[{\"PropertyInt16\":1},{\"PropertyInt16\":2},{\"PropertyInt16\":3}]}",
      resultString);
}
 
Example #11
Source File: Util.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
public static EdmEntitySet getEdmEntitySet(UriInfoResource uriInfo) throws ODataApplicationException {

    List<UriResource> resourcePaths = uriInfo.getUriResourceParts();
    // To get the entity set we have to interpret all URI segments
    if (!(resourcePaths.get(0) instanceof UriResourceEntitySet)) {
      // Here we should interpret the whole URI but in this example we do not support navigation so we throw an
      // exception
      throw new ODataApplicationException("Invalid resource type for first segment.", HttpStatusCode.NOT_IMPLEMENTED
          .getStatusCode(), Locale.ENGLISH);
    }

    UriResourceEntitySet uriResource = (UriResourceEntitySet) resourcePaths.get(0);

    return uriResource.getEntitySet();
  }
 
Example #12
Source File: TechnicalPrimitiveComplexProcessor.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private void validatePath(final UriInfoResource uriInfo) throws ODataApplicationException {
  final List<UriResource> resourcePaths = uriInfo.getUriResourceParts();
  for (final UriResource segment : resourcePaths.subList(1, resourcePaths.size())) {
    final UriResourceKind kind = segment.getKind();
    if (kind != UriResourceKind.navigationProperty
        && kind != UriResourceKind.primitiveProperty
        && kind != UriResourceKind.complexProperty
        && kind != UriResourceKind.count
        && kind != UriResourceKind.value
        && kind != UriResourceKind.function) {
      throw new ODataApplicationException("Invalid resource type.",
          HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ROOT);
    }
  }
}
 
Example #13
Source File: Util.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
public static EdmEntitySet getEdmEntitySet(UriInfoResource uriInfo) throws ODataApplicationException {

    List<UriResource> resourcePaths = uriInfo.getUriResourceParts();
    // To get the entity set we have to interpret all URI segments
    if (!(resourcePaths.get(0) instanceof UriResourceEntitySet)) {
      // Here we should interpret the whole URI but in this example we do not support navigation so we throw an
      // exception
      throw new ODataApplicationException("Invalid resource type for first segment.", HttpStatusCode.NOT_IMPLEMENTED
          .getStatusCode(), Locale.ENGLISH);
    }

    UriResourceEntitySet uriResource = (UriResourceEntitySet) resourcePaths.get(0);

    return uriResource.getEntitySet();
  }
 
Example #14
Source File: Util.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
public static EdmEntitySet getEdmEntitySet(UriInfoResource uriInfo) throws ODataApplicationException {

    List<UriResource> resourcePaths = uriInfo.getUriResourceParts();
    // To get the entity set we have to interpret all URI segments
    if (!(resourcePaths.get(0) instanceof UriResourceEntitySet)) {
      // Here we should interpret the whole URI but in this example we do not support navigation so we throw an
      // exception
      throw new ODataApplicationException("Invalid resource type for first segment.", HttpStatusCode.NOT_IMPLEMENTED
          .getStatusCode(), Locale.ENGLISH);
    }

    UriResourceEntitySet uriResource = (UriResourceEntitySet) resourcePaths.get(0);

    return uriResource.getEntitySet();
  }
 
Example #15
Source File: Util.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
public static EdmEntitySet getEdmEntitySet(UriInfoResource uriInfo) throws ODataApplicationException {

    List<UriResource> resourcePaths = uriInfo.getUriResourceParts();
    // To get the entity set we have to interpret all URI segments
    if (!(resourcePaths.get(0) instanceof UriResourceEntitySet)) {
      // Here we should interpret the whole URI but in this example we do not support navigation so we throw an
      // exception
      throw new ODataApplicationException("Invalid resource type for first segment.", HttpStatusCode.NOT_IMPLEMENTED
          .getStatusCode(), Locale.ENGLISH);
    }

    UriResourceEntitySet uriResource = (UriResourceEntitySet) resourcePaths.get(0);

    return uriResource.getEntitySet();
  }
 
Example #16
Source File: TechnicalPrimitiveComplexProcessor.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private void deleteProperty(final ODataRequest request, ODataResponse response, final UriInfo uriInfo,
    final boolean isValue) throws ODataLibraryException, ODataApplicationException {
  final UriInfoResource resource = uriInfo.asUriInfoResource();
  validatePath(resource);
  getEdmEntitySet(uriInfo); // including checks

  Entity entity = readEntity(uriInfo);
  odata.createETagHelper().checkChangePreconditions(entity.getETag(),
      request.getHeaders(HttpHeader.IF_MATCH),
      request.getHeaders(HttpHeader.IF_NONE_MATCH));

  final List<UriResource> resourceParts = resource.getUriResourceParts();
  final int trailing = isValue ? 1 : 0;
  final List<String> path = getPropertyPath(resourceParts, trailing);

  Property property = getPropertyData(entity, path);

  final EdmProperty edmProperty = ((UriResourceProperty) resourceParts.get(resourceParts.size() - trailing - 1))
      .getProperty();

  if (edmProperty.isNullable()) {
    property.setValue(property.getValueType(), edmProperty.isCollection() ? Collections.emptyList() : null);
    dataProvider.updateETag(entity);
    response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
    if (entity.getETag() != null) {
      response.setHeader(HttpHeader.ETAG, entity.getETag());
    }
  } else {
    throw new ODataApplicationException("Not nullable.", HttpStatusCode.BAD_REQUEST.getStatusCode(), Locale.ROOT);
  }
}
 
Example #17
Source File: ODataJsonSerializerTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void complexCollectionPropertyWithSelectWithMetadataFull() throws Exception {
  final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESKeyNav");
  final EdmProperty edmProperty = (EdmProperty) edmEntitySet.getEntityType().getProperty("CollPropertyComp");
  
  final EdmComplexType complexType = metadata.getEdm().getComplexType(
      new FullQualifiedName("olingo.odata.test1", "CTPrimComp"));
  final EdmProperty propertyWithinCT = (EdmProperty) complexType.getProperty("PropertyInt16"); 
  
  final UriInfoResource resource = ExpandSelectMock.mockComplexTypeResource(propertyWithinCT);
  final SelectItem selectItem = ExpandSelectMock.mockSelectItemForColComplexProperty(resource);
  final SelectOption selectOption = ExpandSelectMock.mockSelectOption(Arrays.asList(selectItem));
  
  final Property property = data.readAll(edmEntitySet).getEntities().get(0).getProperty(edmProperty.getName());
  final String resultString = IOUtils.toString(serializerFullMetadata
          .complexCollection(metadata, (EdmComplexType) edmProperty.getType(),
              property, ComplexSerializerOptions.with()
                  .contextURL(ContextURL.with().entitySet(edmEntitySet)
                      .keyPath("1")
                      .navOrPropertyPath("CollPropertyComp").build())
                  .select(selectOption)
                  .build())
          .getContent());
  assertTrue(resultString.contains("\"value\":[{\"@odata.type\":\"#olingo.odata.test1.CTPrimComp\","
      + "\"[email protected]\":\"#Int16\",\"PropertyInt16\":1},"
      + "{\"@odata.type\":\"#olingo.odata.test1.CTPrimComp\","
      + "\"[email protected]\":\"#Int16\",\"PropertyInt16\":2},"
      + "{\"@odata.type\":\"#olingo.odata.test1.CTPrimComp\","
      + "\"[email protected]\":\"#Int16\",\"PropertyInt16\":3}]"));
}
 
Example #18
Source File: ExpandSelectMock.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private static UriInfoResource mockResourceOnDerivedComplexTypes(final EdmEntitySet edmEntitySet,
    final String name, final EdmType derivedType, final String pathSegmentAfterCast) {
  EdmStructuredType type = edmEntitySet.getEntityType();
  List<UriResource> elements = new ArrayList<UriResource>();
  mockComplexPropertyWithTypeFilter(name, derivedType, type, elements);
  
  mockPropertyOnDerivedType(derivedType, pathSegmentAfterCast, elements);
  
  UriInfoResource resource = Mockito.mock(UriInfoResource.class);
  Mockito.when(resource.getUriResourceParts()).thenReturn(elements);
  return resource;
}
 
Example #19
Source File: TechnicalPrimitiveComplexProcessor.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private Property getData(Entity entity, List<String> path, List<UriResource> resourceParts, UriInfoResource resource) 
    throws DataProviderException {
  if(resourceParts.size()>1 && resourceParts.get(1) instanceof UriResourceFunction){
    return dataProvider.readFunctionPrimitiveComplex(((UriResourceFunction) resourceParts.get(1)).getFunction(),
        ((UriResourceFunction) resourceParts.get(1)).getParameters(), resource);
  }
  return getPropertyData(entity, path);
}
 
Example #20
Source File: ExpandSelectMock.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
public static SelectItem mockSelectItemHavingAction(final EdmEntitySet edmEntitySet, 
    final EdmAction action) {
  final UriInfoResource resource = mockResourceOnAction(
      edmEntitySet, action);
  SelectItem selectItem = Mockito.mock(SelectItem.class);
  Mockito.when(selectItem.getResourcePath()).thenReturn(resource);
  return selectItem;
}
 
Example #21
Source File: ExpandSelectMock.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
public static SelectItem mockSelectItemHavingFunction(final EdmEntitySet edmEntitySet, 
    final EdmFunction function) {
  final UriInfoResource resource = mockResourceOnFunction(
      edmEntitySet, function);
  SelectItem selectItem = Mockito.mock(SelectItem.class);
  Mockito.when(selectItem.getResourcePath()).thenReturn(resource);
  return selectItem;
}
 
Example #22
Source File: ExpandSelectMock.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private static UriInfoResource mockResourceOnAction(
    EdmEntitySet edmEntitySet, EdmAction action) {
  List<UriResource> elements = new ArrayList<UriResource>();
  UriResourceAction element = Mockito.mock(UriResourceAction.class);
  Mockito.when(element.getAction()).thenReturn(action);
  elements.add(element);
  
  UriInfoResource resource = Mockito.mock(UriInfoResource.class);
  Mockito.when(resource.getUriResourceParts()).thenReturn(elements);
  return resource;
}
 
Example #23
Source File: ExpandSelectMock.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private static UriInfoResource mockResourceOnFunction(EdmEntitySet edmEntitySet, EdmFunction function) {
  UriResourceFunction element = Mockito.mock(UriResourceFunction.class);
  Mockito.when(element.getFunction()).thenReturn(function);
  List<UriResource> elements = new ArrayList<UriResource>();
  elements.add(element);
  
  UriInfoResource resource = Mockito.mock(UriInfoResource.class);
  Mockito.when(resource.getUriResourceParts()).thenReturn(elements);
  return resource;
}
 
Example #24
Source File: Util.java    From syndesis with Apache License 2.0 5 votes vote down vote up
public static EdmEntitySet getEdmEntitySet(UriInfoResource uriInfo) throws ODataApplicationException {
    List<UriResource> resourcePaths = uriInfo.getUriResourceParts();
    // To get the entity set we have to interpret all URI segments
    if (!(resourcePaths.get(0) instanceof UriResourceEntitySet)) {
        // Here we should interpret the whole URI but in this example we do not support navigation so we throw an
        // exception
        throw new ODataApplicationException("Invalid resource type for first segment.",
                                            HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ENGLISH);
    }

    UriResourceEntitySet uriResource = (UriResourceEntitySet)resourcePaths.get(0);

    return uriResource.getEntitySet();
}
 
Example #25
Source File: ExpandSelectMock.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
public static SelectItem mockSelectItemOnDerivedComplexTypes(final EdmEntitySet edmEntitySet, final String name, 
    final EdmType type, final String pathSegmentAfterCast) {
  final UriInfoResource resource = mockResourceOnDerivedComplexTypes(edmEntitySet,  
      name, type, pathSegmentAfterCast);
  SelectItem selectItem = Mockito.mock(SelectItem.class);
  Mockito.when(selectItem.getResourcePath()).thenReturn(resource);
  return selectItem;
}
 
Example #26
Source File: ExpandSelectMock.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
public static SelectItem mockSelectItemOnDerivedEntityAndComplexTypes(
    final String name, final EdmType entityType, final EdmType complexType, final String pathSegment) {
  final UriInfoResource resource = mockResourceOnDerivedEntityAndComplexTypes(
      name, entityType, complexType, pathSegment);
  SelectItem selectItem = Mockito.mock(SelectItem.class);
  Mockito.when(selectItem.getResourcePath()).thenReturn(resource);
  return selectItem;
}
 
Example #27
Source File: ExpandSelectMock.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
public static SelectItem mockSelectItemMultiLevelOnDerivedComplexTypes(
    final EdmEntitySet edmEntitySet, final String name, 
    final String pathSegmentBeforeCast, final EdmType type, final String pathSegmentAfterCast) {
  final UriInfoResource resource = mockResourceMultiLevelOnDerivedComplexTypes(
      edmEntitySet, pathSegmentBeforeCast, name, type, pathSegmentAfterCast);
  SelectItem selectItem = Mockito.mock(SelectItem.class);
  Mockito.when(selectItem.getResourcePath()).thenReturn(resource);
  return selectItem;
}
 
Example #28
Source File: ExpandSelectMock.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
public static SelectItem mockSelectItemOnComplexTypesWithNav (
    final EdmEntitySet edmEntitySet, final String name, final String navProperty) {
  final UriInfoResource resource = mockResourceOnComplexTypesWithNav(
      edmEntitySet, name, navProperty);
  SelectItem selectItem = Mockito.mock(SelectItem.class);
  Mockito.when(selectItem.getResourcePath()).thenReturn(resource);
  return selectItem;
}
 
Example #29
Source File: ODataXmlSerializerTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void complexCollectionWithSelectProperty() throws Exception {
  final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESKeyNav");
  final EdmProperty edmProperty = (EdmProperty) edmEntitySet.getEntityType().getProperty("CollPropertyComp");
  final Property property = data.readAll(edmEntitySet).getEntities().get(0).getProperty(edmProperty.getName());
  final EdmComplexType complexType = metadata.getEdm().getComplexType(
      new FullQualifiedName("olingo.odata.test1", "CTPrimComp"));
  final EdmProperty propertyWithinCT = (EdmProperty) complexType.getProperty("PropertyInt16"); 
  
  final UriInfoResource resource = ExpandSelectMock.mockComplexTypeResource(propertyWithinCT);
  final SelectItem selectItem = ExpandSelectMock.mockSelectItemForColComplexProperty(resource);
  final SelectOption selectOption = ExpandSelectMock.mockSelectOption(Arrays.asList(selectItem));
  
  final String resultString = IOUtils.toString(serializer
      .complexCollection(metadata, (EdmComplexType) edmProperty.getType(), property,
          ComplexSerializerOptions.with()
              .contextURL(ContextURL.with()
                  .entitySet(edmEntitySet).keyPath("1")
                  .navOrPropertyPath("CollPropertyComp")
                  .build()).select(selectOption)
              .build()).getContent());
  final String expectedResult = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
      + "<m:value xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\" "
      + "xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" xmlns:a=\"http://www.w3.org/2005/Atom\" "
      + "m:type=\"#Collection(olingo.odata.test1.CTPrimComp)\" "
      + "m:context=\"../$metadata#ESKeyNav(1)/CollPropertyComp\" "
      + "m:metadata-etag=\"metadataETag\">"
      + "<m:element><d:PropertyInt16 m:type=\"Int16\">1</d:PropertyInt16>"
      + "</m:element><m:element><d:PropertyInt16 m:type=\"Int16\">2</d:PropertyInt16>"
      + "</m:element><m:element><d:PropertyInt16 m:type=\"Int16\">3</d:PropertyInt16>"
      + "</m:element></m:value>";
  Assert.assertEquals(expectedResult, resultString);
}
 
Example #30
Source File: ExpandSelectMock.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
/**
 * @param propertyWithinCT
 * @return
 */
public static UriInfoResource mockComplexTypeResource(final EdmProperty propertyWithinCT) {
  final UriInfoResource resource = Mockito.mock(UriInfoResource.class);
  final List<UriResource> elements = new ArrayList<UriResource>();
  final UriResourceProperty element = Mockito.mock(UriResourceProperty.class);
  Mockito.when(element.getProperty()).thenReturn(propertyWithinCT);
  elements.add(element);
  Mockito.when(resource.getUriResourceParts()).thenReturn(elements);
  return resource;
}