Java Code Examples for org.apache.olingo.commons.api.edm.EdmEntitySet#getEntityType()

The following examples show how to use org.apache.olingo.commons.api.edm.EdmEntitySet#getEntityType() . 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: 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 2
Source File: DemoEntityProcessor.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
public void updateEntity(ODataRequest request, ODataResponse response, UriInfo uriInfo,
                          ContentType requestFormat, ContentType responseFormat)
						throws ODataApplicationException, DeserializerException, SerializerException {
	
	// 1. Retrieve the entity set which belongs to the requested entity 
	List<UriResource> resourcePaths = uriInfo.getUriResourceParts();
	// Note: only in our example we can assume that the first segment is the EntitySet
	UriResourceEntitySet uriResourceEntitySet = (UriResourceEntitySet) resourcePaths.get(0); 
	EdmEntitySet edmEntitySet = uriResourceEntitySet.getEntitySet();
	EdmEntityType edmEntityType = edmEntitySet.getEntityType();

	// 2. update the data in backend
	// 2.1. retrieve the payload from the PUT request for the entity to be updated 
	InputStream requestInputStream = request.getBody();
	ODataDeserializer deserializer = this.odata.createDeserializer(requestFormat);
	DeserializerResult result = deserializer.entity(requestInputStream, edmEntityType);
	Entity requestEntity = result.getEntity();
	// 2.2 do the modification in backend
	List<UriParameter> keyPredicates = uriResourceEntitySet.getKeyPredicates();
	// Note that this updateEntity()-method is invoked for both PUT or PATCH operations
	HttpMethod httpMethod = request.getMethod();
	storage.updateEntityData(edmEntitySet, keyPredicates, requestEntity, httpMethod);
	
	//3. configure the response object
	response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
}
 
Example 3
Source File: DemoEntityProcessor.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
public void updateEntity(ODataRequest request, ODataResponse response, UriInfo uriInfo,
                          ContentType requestFormat, ContentType responseFormat)
						throws ODataApplicationException, DeserializerException, SerializerException {
	
	// 1. Retrieve the entity set which belongs to the requested entity 
	List<UriResource> resourcePaths = uriInfo.getUriResourceParts();
	// Note: only in our example we can assume that the first segment is the EntitySet
	UriResourceEntitySet uriResourceEntitySet = (UriResourceEntitySet) resourcePaths.get(0); 
	EdmEntitySet edmEntitySet = uriResourceEntitySet.getEntitySet();
	EdmEntityType edmEntityType = edmEntitySet.getEntityType();

	// 2. update the data in backend
	// 2.1. retrieve the payload from the PUT request for the entity to be updated 
	InputStream requestInputStream = request.getBody();
	ODataDeserializer deserializer = odata.createDeserializer(requestFormat);
	DeserializerResult result = deserializer.entity(requestInputStream, edmEntityType);
	Entity requestEntity = result.getEntity();
	// 2.2 do the modification in backend
	List<UriParameter> keyPredicates = uriResourceEntitySet.getKeyPredicates();
	// Note that this updateEntity()-method is invoked for both PUT or PATCH operations
	HttpMethod httpMethod = request.getMethod();
	storage.updateEntityData(edmEntitySet, keyPredicates, requestEntity, httpMethod);
	
	//3. configure the response object
	response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
}
 
Example 4
Source File: JsonDeltaSerializerWithNavigationsTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void expandSelectInDelta() throws Exception {
  final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESDelta");
  final EdmEntityType entityType = edmEntitySet.getEntityType();
  final UriHelper helper = odata.createUriHelper();
  final SelectOption select = ExpandSelectMock.mockSelectOption(Collections.singletonList(
      ExpandSelectMock.mockSelectItem(entityContainer.getEntitySet("ESAllPrim"), "PropertyString")));
  ExpandItem expandItem = ExpandSelectMock.mockExpandItem(edmEntitySet, "NavPropertyETAllPrimOne");
  Mockito.when(expandItem.getSelectOption()).thenReturn(select);
  final ExpandOption expand = ExpandSelectMock.mockExpandOption(Collections.singletonList(expandItem));
  final Entity entity = data.readAll(edmEntitySet).getEntities().get(3);
     
     Delta delta = new Delta();
     List<Entity> addedEntity = new ArrayList<Entity>();
     addedEntity.add(entity);
     delta.getEntities().addAll(addedEntity);
     InputStream stream = ser.entityCollection(metadata, edmEntitySet.getEntityType(), delta ,
         EntityCollectionSerializerOptions.with()
         .contextURL(ContextURL.with().entitySet(edmEntitySet)
             .selectList(helper.buildContextURLSelectList(entityType, expand, select)).build()).expand(expand)
         .build()).getContent();
        String jsonString = IOUtils.toString(stream);
  Assert.assertEquals("{"
      + "\"@context\":\"$metadata#ESDelta(PropertyInt16,PropertyString,NavPropertyETAllPrimOne("
      + "PropertyInt16,PropertyString))/$delta\","
      + "\"value\":[{\"@id\":\"ESDelta(100)\",\"PropertyInt16\":100,\"PropertyString\":\"Number:100\","
      + "\"NavPropertyETAllPrimOne@delta\":{\"@id\":\"ESAllPrim(32767)\","
      + "\"PropertyString\":\"First Resource - positive values\"}}]}",
      jsonString);
}
 
Example 5
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
public Entity createEntityData(EdmEntitySet edmEntitySet, Entity entityToCreate) {

    EdmEntityType edmEntityType = edmEntitySet.getEntityType();

    // actually, this is only required if we have more than one Entity Type
    if (edmEntityType.getName().equals(DemoEdmProvider.ET_PRODUCT_NAME)) {
      return createProduct(edmEntityType, entityToCreate);
    }

    return null;
  }
 
Example 6
Source File: EdmEntitySetImplTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void entitySetIncludeInServiceDocumentFalseAndInvalidType() throws Exception {
  CsdlEdmProvider provider = mock(CsdlEdmProvider.class);
  EdmProviderImpl edm = new EdmProviderImpl(provider);

  final FullQualifiedName containerName = new FullQualifiedName("ns", "container");
  final CsdlEntityContainerInfo containerInfo = new CsdlEntityContainerInfo().setContainerName(containerName);
  when(provider.getEntityContainerInfo(containerName)).thenReturn(containerInfo);
  final EdmEntityContainer entityContainer = new EdmEntityContainerImpl(edm, provider, containerInfo);

  final String entitySetName = "entitySet";
  final CsdlEntitySet entitySetProvider = new CsdlEntitySet()
      .setName(entitySetName)
      .setType("invalid.invalid")
      .setIncludeInServiceDocument(false);
  when(provider.getEntitySet(containerName, entitySetName)).thenReturn(entitySetProvider);

  final EdmEntitySet entitySet = new EdmEntitySetImpl(edm, entityContainer, entitySetProvider);
  assertFalse(entitySet.isIncludeInServiceDocument());

  try {
    entitySet.getEntityType();
    fail("Expected an EdmException");
  } catch (EdmException e) {
    assertEquals("CanĀ“t find entity type: invalid.invalid for entity set or singleton: " + entitySetName, e
        .getMessage());
  }
}
 
Example 7
Source File: DemoEntityProcessor.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
public void readEntity(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType responseFormat)
     throws ODataApplicationException, SerializerException {
	
	// 1. retrieve the Entity Type 
	List<UriResource> resourcePaths = uriInfo.getUriResourceParts();
	// Note: only in our example we can assume that the first segment is the EntitySet
	UriResourceEntitySet uriResourceEntitySet = (UriResourceEntitySet) resourcePaths.get(0); 
	EdmEntitySet edmEntitySet = uriResourceEntitySet.getEntitySet();
	
	// 2. retrieve the data from backend
	List<UriParameter> keyPredicates = uriResourceEntitySet.getKeyPredicates();
	Entity entity = storage.readEntityData(edmEntitySet, keyPredicates);
	
	// 3. serialize
	EdmEntityType entityType = edmEntitySet.getEntityType();
	
	ContextURL contextUrl = ContextURL.with().entitySet(edmEntitySet).suffix(ContextURL.Suffix.ENTITY).build();
 	// expand and select currently not supported
	EntitySerializerOptions options = EntitySerializerOptions.with().contextURL(contextUrl).build();

	ODataSerializer serializer = this.odata.createSerializer(responseFormat);
	SerializerResult result = serializer.entity(serviceMetadata, entityType, entity, options);
	
	//4. configure the response object
	response.setContent(result.getContent());
	response.setStatusCode(HttpStatusCode.OK.getStatusCode());
	response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString());
}
 
Example 8
Source File: ODataJsonSerializerTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void selectComplexTwice() throws Exception {
  final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESFourKeyAlias");
  final EdmEntityType entityType = edmEntitySet.getEntityType();
  final EntityCollection entitySet = data.readAll(edmEntitySet);
  final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(
      ExpandSelectMock.mockSelectItem(edmEntitySet, "PropertyComp", "PropertyString"),
      ExpandSelectMock.mockSelectItem(edmEntitySet, "PropertyCompComp", "PropertyComp")));
  final String resultString = IOUtils.toString(serializer
      .entityCollection(metadata, entityType, entitySet,
          EntityCollectionSerializerOptions.with()
              .contextURL(ContextURL.with().entitySet(edmEntitySet)
                  .selectList(helper.buildContextURLSelectList(entityType, null, select))
                  .build())
              .select(select)
              .build()).getContent());
  
  String expected = "{"
          + "\"@odata.context\":\"$metadata#ESFourKeyAlias"
          +   "(PropertyInt16,PropertyComp/PropertyString,PropertyCompComp/PropertyComp)\","
          + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\","
          + "\"value\":[{"
              + "\"@odata.id\":\"ESFourKeyAlias(PropertyInt16=1,KeyAlias1=11,KeyAlias2='Num11',KeyAlias3='Num111')\","
              + "\"PropertyInt16\":1,\"PropertyComp\":{"
                  + "\"PropertyString\":\"Num11\""
              + "},"
              + "\"PropertyCompComp\":{"
                  + "\"PropertyComp\":{"
                      + "\"@odata.type\":\"#olingo.odata.test1.CTBase\","
                      + "\"PropertyInt16\":111,"
                      + "\"PropertyString\":\"Num111\","
                      + "\"AdditionalPropString\":\"Test123\""
          + "}}}]}";
  
  Assert.assertEquals(expected, resultString);
}
 
Example 9
Source File: ODataJsonSerializerTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void selectExtendedComplexType() throws Exception {
  final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESFourKeyAlias");
  final EdmEntityType entityType = edmEntitySet.getEntityType();
  final EntityCollection entitySet = data.readAll(edmEntitySet);
  InputStream result = serializer
      .entityCollection(metadata, entityType, entitySet,
          EntityCollectionSerializerOptions.with()
              .contextURL(ContextURL.with().entitySet(edmEntitySet).build())
              .build()).getContent();
  final String resultString = IOUtils.toString(result);

  final String expected = "{"
      + "\"@odata.context\":\"$metadata#ESFourKeyAlias\","
      + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\","
      + "\"value\":[{"
      + "\"PropertyInt16\":1,"
      + "\"PropertyComp\":{"
      + "\"PropertyInt16\":11,"
      + "\"PropertyString\":\"Num11\""
      + "},"
      + "\"PropertyCompComp\":{"
      + "\"PropertyComp\":{"
      + "\"@odata.type\":\"#olingo.odata.test1.CTBase\","
      + "\"PropertyInt16\":111,"
      + "\"PropertyString\":\"Num111\","
      + "\"AdditionalPropString\":\"Test123\""
      + "}}}]}";

  Assert.assertEquals(expected, resultString);
}
 
Example 10
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
public Entity createEntityData(EdmEntitySet edmEntitySet, Entity entityToCreate) {

    EdmEntityType edmEntityType = edmEntitySet.getEntityType();

    // actually, this is only required if we have more than one Entity Type
    if (edmEntityType.getName().equals(DemoEdmProvider.ET_PRODUCT_NAME)) {
      return createProduct(edmEntityType, entityToCreate);
    }

    return null;
  }
 
Example 11
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
public void deleteEntityData(EdmEntitySet edmEntitySet, List<UriParameter> keyParams)
    throws ODataApplicationException {

  EdmEntityType edmEntityType = edmEntitySet.getEntityType();

  // actually, this is only required if we have more than one Entity Type
  if (edmEntityType.getName().equals(DemoEdmProvider.ET_PRODUCT_NAME)) {
    deleteProduct(edmEntityType, keyParams);
  }
}
 
Example 12
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
public Entity readEntityData(EdmEntitySet edmEntitySet, List<UriParameter> keyParams)
    throws ODataApplicationException {

  EdmEntityType edmEntityType = edmEntitySet.getEntityType();

  // actually, this is only required if we have more than one Entity Type
  if (edmEntityType.getName().equals(DemoEdmProvider.ET_PRODUCT_NAME)) {
    return getProduct(edmEntityType, keyParams);
  }

  return null;
}
 
Example 13
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
public Entity readEntityData(EdmEntitySet edmEntitySet, List<UriParameter> keyParams) throws ODataApplicationException{

		EdmEntityType edmEntityType = edmEntitySet.getEntityType();

		// actually, this is only required if we have more than one Entity Type
		if(edmEntityType.getName().equals(DemoEdmProvider.ET_PRODUCT_NAME)){
			return getProduct(edmEntityType, keyParams);
		}

		return null;
	}
 
Example 14
Source File: DemoEntityCollectionProcessor.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
public void readEntityCollection(ODataRequest request, ODataResponse response, UriInfo uriInfo,
    ContentType responseFormat) throws ODataApplicationException, SerializerException {

  // 1st retrieve the requested EntitySet from the uriInfo (representation of the parsed URI)
  List<UriResource> resourcePaths = uriInfo.getUriResourceParts();
  // in our example, the first segment is the EntitySet
  UriResourceEntitySet uriResourceEntitySet = (UriResourceEntitySet) resourcePaths.get(0);
  EdmEntitySet edmEntitySet = uriResourceEntitySet.getEntitySet();

  // 2nd: fetch the data from backend for this requested EntitySetName
  // it has to be delivered as EntitySet object
  EntityCollection entitySet = storage.readEntitySetData(edmEntitySet);

  // 3rd: create a serializer based on the requested format (json)
  ODataSerializer serializer = odata.createSerializer(responseFormat);

  // and serialize the content: transform from the EntitySet object to InputStream
  EdmEntityType edmEntityType = edmEntitySet.getEntityType();
  ContextURL contextUrl = ContextURL.with().entitySet(edmEntitySet).build();

  final String id = request.getRawBaseUri() + "/" + edmEntitySet.getName();
  EntityCollectionSerializerOptions opts =
      EntityCollectionSerializerOptions.with().id(id).contextURL(contextUrl).build();
  SerializerResult serializedContent = serializer.entityCollection(serviceMetadata, edmEntityType, entitySet, opts);

  // Finally: configure the response object: set the body, headers and status code
  response.setContent(serializedContent.getContent());
  response.setStatusCode(HttpStatusCode.OK.getStatusCode());
  response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString());
}
 
Example 15
Source File: DemoEntityCollectionProcessor.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
public void readEntityCollection(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType responseFormat) throws ODataApplicationException, SerializerException {

		// 1st retrieve the requested EntitySet from the uriInfo (representation of the parsed URI)
		List<UriResource> resourcePaths = uriInfo.getUriResourceParts();
		UriResourceEntitySet uriResourceEntitySet = (UriResourceEntitySet) resourcePaths.get(0); // in our example, the first segment is the EntitySet
		EdmEntitySet edmEntitySet = uriResourceEntitySet.getEntitySet();

		// 2nd: fetch the data from backend for this requested EntitySetName and deliver as EntitySet
		EntityCollection entityCollection = storage.readEntitySetData(edmEntitySet);

		// 3rd: create a serializer based on the requested format (json)
		ODataSerializer serializer = odata.createSerializer(responseFormat);

		// and serialize the content: transform from the EntitySet object to InputStream
		EdmEntityType edmEntityType = edmEntitySet.getEntityType();
		ContextURL contextUrl = ContextURL.with().entitySet(edmEntitySet).build();

		final String id = request.getRawBaseUri() + "/" + edmEntitySet.getName();
		EntityCollectionSerializerOptions opts =
				EntityCollectionSerializerOptions.with().id(id).contextURL(contextUrl).build();
		SerializerResult serializerResult = serializer.entityCollection(serviceMetadata, edmEntityType, entityCollection, opts);
		InputStream serializedContent = serializerResult.getContent();

		// 4th: configure the response object: set the body, headers and status code
		response.setContent(serializedContent);
		response.setStatusCode(HttpStatusCode.OK.getStatusCode());
		response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString());
	}
 
Example 16
Source File: DemoEntityCollectionProcessor.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void readEntityCollection(ODataRequest request, ODataResponse response, 
        UriInfo uriInfo, ContentType responseFormat) throws ODataApplicationException, SerializerException {

    // 1st we have retrieve the requested EntitySet from the uriInfo object 
    // (representation of the parsed service URI)
    List<UriResource> resourcePaths = uriInfo.getUriResourceParts();
    // In our example, the first segment is the EntitySet
    UriResourceEntitySet uriResourceEntitySet = (UriResourceEntitySet) resourcePaths.get(0); 
    EdmEntitySet edmEntitySet = uriResourceEntitySet.getEntitySet();

    // 2nd: fetch the data from backend for this requested EntitySetName 
    // it has to be delivered as EntitySet object
    EntityCollection entitySet = getData(edmEntitySet);

    // 3rd: create a serializer based on the requested format (json)
    ODataSerializer serializer = odata.createSerializer(responseFormat);
    
    // 4th: Now serialize the content: transform from the EntitySet object to InputStream
    EdmEntityType edmEntityType = edmEntitySet.getEntityType();
    ContextURL contextUrl = ContextURL.with().entitySet(edmEntitySet).build();

    final String id = request.getRawBaseUri() + "/" + edmEntitySet.getName();
    EntityCollectionSerializerOptions opts =
            EntityCollectionSerializerOptions.with().id(id).contextURL(contextUrl).build();
    SerializerResult serializedContent = serializer.entityCollection(serviceMetadata, 
        edmEntityType, entitySet, opts);

    // Finally: configure the response object: set the body, headers and status code
    response.setContent(serializedContent.getContent());
    response.setStatusCode(HttpStatusCode.OK.getStatusCode());
    response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString());
}
 
Example 17
Source File: JsonDeltaSerializerTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void selectInDelta() throws Exception {
  final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESDelta");
  final EdmEntityType entityType = edmEntitySet.getEntityType();
  final UriHelper helper = odata.createUriHelper();
  final SelectOption select = ExpandSelectMock.mockSelectOption(Collections.singletonList(
      ExpandSelectMock.mockSelectItem(entityContainer.getEntitySet("ESAllPrim"), "PropertyString")));
  
  final Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
  final Entity entity2 = data.readAll(edmEntitySet).getEntities().get(1);
     
     Delta delta = new Delta();
     List<Entity> addedEntity = new ArrayList<Entity>();
     Entity changedEntity = new Entity();
     changedEntity.setId(entity2.getId());
     changedEntity.addProperty(entity2.getProperty("PropertyString"));
     changedEntity.addProperty(entity2.getProperty("PropertyInt16"));
     addedEntity.add(entity);
     addedEntity.add(changedEntity);
     delta.getEntities().addAll(addedEntity);
     InputStream stream = ser.entityCollection(metadata, edmEntitySet.getEntityType(), delta ,
         EntityCollectionSerializerOptions.with()
         .contextURL(ContextURL.with().entitySet(edmEntitySet)
             .selectList(helper.buildContextURLSelectList(entityType, null, select))
             .suffix(Suffix.ENTITY).build())
         .select(select).build()).getContent();
        String jsonString = IOUtils.toString(stream);
  Assert.assertEquals("{"
      +"\"@odata.context\":\"$metadata#ESDelta(PropertyInt16,PropertyString)/$entity/$delta\","
      + "\"value\":[{\"@odata.id\":\"ESDelta(32767)\",\"PropertyString\":\"Number:32767\"},"
      + "{\"@odata.id\":\"ESDelta(-32768)\",\"PropertyString\":\"Number:-32768\"}]}",
      jsonString);
}
 
Example 18
Source File: ODataJsonSerializerTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void expandSelect() throws Exception {
  final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESTwoPrim");
  final EdmEntityType entityType = edmEntitySet.getEntityType();
  final Entity entity = data.readAll(edmEntitySet).getEntities().get(3);
  final SelectOption select = ExpandSelectMock.mockSelectOption(Collections.singletonList(
      ExpandSelectMock.mockSelectItem(entityContainer.getEntitySet("ESAllPrim"), "PropertyDate")));
  ExpandItem expandItem = ExpandSelectMock.mockExpandItem(edmEntitySet, "NavPropertyETAllPrimOne");
  Mockito.when(expandItem.getSelectOption()).thenReturn(select);
  final ExpandOption expand = ExpandSelectMock.mockExpandOption(Collections.singletonList(expandItem));
  final String resultString = IOUtils.toString(serializer
      .entity(metadata, entityType, entity,
          EntitySerializerOptions.with()
              .contextURL(ContextURL.with().entitySet(edmEntitySet)
                  .selectList(helper.buildContextURLSelectList(entityType, expand, select))
                  .suffix(Suffix.ENTITY).build())
              .expand(expand)
              .build()).getContent());
  Assert.assertEquals("{"
      + "\"@odata.context\":\"$metadata#ESTwoPrim(PropertyInt16,"
+ "NavPropertyETAllPrimOne(PropertyInt16,PropertyDate))/$entity\","
      + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\","
      + "\"PropertyInt16\":32767,\"PropertyString\":\"Test String4\","
      + "\"NavPropertyETAllPrimOne\":{\"@odata.id\":\"ESAllPrim(32767)\","
+ "\"PropertyInt16\":32767,\"PropertyDate\":\"2012-12-03\"}}",
      resultString);
}
 
Example 19
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
public Entity readEntityData(EdmEntitySet edmEntitySet, List<UriParameter> keyParams) throws ODataApplicationException{

		EdmEntityType edmEntityType = edmEntitySet.getEntityType();

		// actually, this is only required if we have more than one Entity Type
		if(edmEntityType.getName().equals(DemoEdmProvider.ET_PRODUCT_NAME)){
			return getProduct(edmEntityType, keyParams);
		}

		return null;
	}
 
Example 20
Source File: ODataXmlSerializerTest.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
@Test
public void selectComplexExtended() throws Exception {
  final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESFourKeyAlias");
  final EdmEntityType entityType = edmEntitySet.getEntityType();
  final EntityCollection entitySet = data.readAll(edmEntitySet);
  long currentTimeMillis = System.currentTimeMillis();
  InputStream result = serializer
      .entityCollection(metadata, entityType, entitySet,
          EntityCollectionSerializerOptions.with()
              .contextURL(ContextURL.with().entitySet(edmEntitySet).build())
              .id("http://host/svc/ESFourKeyAlias")
              .build()).getContent();
  final String resultString = IOUtils.toString(result);
  String expected = "<?xml version='1.0' encoding='UTF-8'?>\n" +
      "<a:feed xmlns:a=\"http://www.w3.org/2005/Atom\"\n" +
          "xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
          "xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" \n" +
          "m:context=\"$metadata#ESFourKeyAlias\"\n" +
          "m:metadata-etag=\"metadataETag\">\n" +
          "<a:id>http://host/svc/ESFourKeyAlias</a:id>\n" +
          "<a:entry>\n" +
              "<a:id>ESFourKeyAlias(PropertyInt16=1,KeyAlias1=11,KeyAlias2='Num11',KeyAlias3='Num111')</a:id>\n" +
              "<a:title />\n" +
              "<a:summary />\n" +
              "<a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + "</a:updated>" +
              "<a:author>\n" +
                  "<a:name/>\n" +
              "</a:author>\n" +
              "<a:link rel=\"edit\" " +
              "href=\"ESFourKeyAlias(PropertyInt16=1,KeyAlias1=11,KeyAlias2='Num11',KeyAlias3='Num111')\"/>\n" +
              "<a:category scheme=\"http://docs.oasis-open.org/odata/ns/scheme\" " +
                "term=\"#olingo.odata.test1.ETFourKeyAlias\"/>\n" +
             "<a:content type=\"application/xml\">\n" +
                  "<m:properties>\n" +
                  "<d:PropertyInt16 m:type=\"Int16\">1</d:PropertyInt16>\n" +
                  "<d:PropertyComp m:type=\"#olingo.odata.test1.CTTwoPrim\">\n" +
                      "<d:PropertyInt16 m:type=\"Int16\">11</d:PropertyInt16>\n" +
                      "<d:PropertyString>Num11</d:PropertyString>\n" +
                      "<a:link rel=\"http://docs.oasis-open.org/odata/ns/related/NavPropertyETTwoKeyNavOne\" "
                      + "type=\"application/atom+xml;type=feed\" title=\"NavPropertyETTwoKeyNavOne\" "
                      + "href=\"PropertyComp/NavPropertyETTwoKeyNavOne\"/>\n" +
                      "<a:link rel=\"http://docs.oasis-open.org/odata/ns/related/NavPropertyETMediaOne\" "
                      + "type=\"application/atom+xml;type=feed\" title=\"NavPropertyETMediaOne\" "
                      + "href=\"PropertyComp/NavPropertyETMediaOne\"/>\n" +
                  "</d:PropertyComp>\n" +
                  "<d:PropertyCompComp m:type=\"#olingo.odata.test1.CTCompComp\">\n" +
                      "<d:PropertyComp m:type=\"#olingo.odata.test1.CTBase\">\n" +
                          "<d:PropertyInt16 m:type=\"Int16\">111</d:PropertyInt16>\n" +
                          "<d:PropertyString>Num111</d:PropertyString>\n" +
                          "<d:AdditionalPropString>Test123</d:AdditionalPropString>\n" +
                          "<a:link rel=\"http://docs.oasis-open.org/odata/ns/related/NavPropertyETTwoKeyNavOne\" "
                          + "type=\"application/atom+xml;type=feed\" title=\"NavPropertyETTwoKeyNavOne\" "
                          + "href=\"PropertyComp/NavPropertyETTwoKeyNavOne\"/>\n" +
                          "<a:link rel=\"http://docs.oasis-open.org/odata/ns/related/NavPropertyETMediaOne\" "
                          + "type=\"application/atom+xml;type=feed\" title=\"NavPropertyETMediaOne\" "
                          + "href=\"PropertyComp/NavPropertyETMediaOne\"/>\n" +
                      "</d:PropertyComp>\n" +
                  "</d:PropertyCompComp>\n" +
                  "</m:properties>\n" +
              "</a:content>\n" +
          "</a:entry>\n" +
      "</a:feed>";
  checkXMLEqual(expected, resultString);
}