Java Code Examples for org.apache.olingo.commons.api.data.Entity#setId()

The following examples show how to use org.apache.olingo.commons.api.data.Entity#setId() . 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: Storage.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private List<Entity> cloneEntityCollection(final List<Entity> entities) {
  final List<Entity> clonedEntities = new ArrayList<Entity>();
  
  for(final Entity entity : entities) {
    final Entity clonedEntity = new Entity();
    
    clonedEntity.setId(entity.getId());
    for(final Property property : entity.getProperties()) {
      clonedEntity.addProperty(new Property(property.getType(), 
                                            property.getName(), 
                                            property.getValueType(), 
                                            property.getValue()));
    }
     
    clonedEntities.add(clonedEntity);
  }
  
  return clonedEntities;
}
 
Example 2
Source File: EdmAssistedJsonSerializerTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void expandMetadataMin() throws Exception {
  final Entity relatedEntity1 = new Entity().addProperty(new Property(null, "Related1", ValueType.PRIMITIVE, 1.5));
  final Entity relatedEntity2 = new Entity().addProperty(new Property(null, "Related1", ValueType.PRIMITIVE, 2.75));
  EntityCollection target = new EntityCollection();
  target.getEntities().add(relatedEntity1);
  target.getEntities().add(relatedEntity2);
  Link link = new Link();
  link.setTitle("NavigationProperty");
  link.setInlineEntitySet(target);
  Entity entity = new Entity();
  entity.setId(null);
  entity.addProperty(new Property(null, "Property1", ValueType.PRIMITIVE, (short) 1));
  entity.getNavigationLinks().add(link);
  EntityCollection entityCollection = new EntityCollection();
  entityCollection.getEntities().add(entity);
  Assert.assertEquals("{\"@odata.context\":\"$metadata#EntitySet(Property1,NavigationProperty(Related1))\","
      + "\"value\":[{"
      + "\"Property1\":1,"
      + "\"NavigationProperty\":["
      + "{\"Related1\":1.5},"
      + "{\"Related1\":2.75}]}]}",
      serialize(serializerMin, metadata, null, entityCollection, "Property1,NavigationProperty(Related1)"));
}
 
Example 3
Source File: EdmAssistedJsonSerializerTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void expandMetadataNone() throws Exception {
  final Entity relatedEntity1 = new Entity().addProperty(new Property(null, "Related1", ValueType.PRIMITIVE, 1.5));
  final Entity relatedEntity2 = new Entity().addProperty(new Property(null, "Related1", ValueType.PRIMITIVE, 2.75));
  EntityCollection target = new EntityCollection();
  target.getEntities().add(relatedEntity1);
  target.getEntities().add(relatedEntity2);
  Link link = new Link();
  link.setTitle("NavigationProperty");
  link.setInlineEntitySet(target);
  Entity entity = new Entity();
  entity.setId(null);
  entity.addProperty(new Property(null, "Property1", ValueType.PRIMITIVE, (short) 1));
  entity.getNavigationLinks().add(link);
  EntityCollection entityCollection = new EntityCollection();
  entityCollection.getEntities().add(entity);
  Assert.assertEquals("{"
      + "\"value\":[{"
      + "\"Property1\":1,"
      + "\"NavigationProperty\":["
      + "{\"Related1\":1.5},"
      + "{\"Related1\":2.75}]}]}",
      serialize(serializerNone, metadata, null, entityCollection, "Property1,NavigationProperty(Related1)"));
}
 
Example 4
Source File: EdmAssistedJsonSerializerTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void expand() throws Exception {
  final Entity relatedEntity1 = new Entity().addProperty(new Property(null, "Related1", ValueType.PRIMITIVE, 1.5));
  final Entity relatedEntity2 = new Entity().addProperty(new Property(null, "Related1", ValueType.PRIMITIVE, 2.75));
  EntityCollection target = new EntityCollection();
  target.getEntities().add(relatedEntity1);
  target.getEntities().add(relatedEntity2);
  Link link = new Link();
  link.setTitle("NavigationProperty");
  link.setInlineEntitySet(target);
  Entity entity = new Entity();
  entity.setId(null);
  entity.addProperty(new Property(null, "Property1", ValueType.PRIMITIVE, (short) 1));
  entity.getNavigationLinks().add(link);
  EntityCollection entityCollection = new EntityCollection();
  entityCollection.getEntities().add(entity);
  Assert.assertEquals("{\"@odata.context\":\"$metadata#EntitySet(Property1,NavigationProperty(Related1))\","
      + "\"value\":[{\"@odata.id\":null,"
      + "\"[email protected]\":\"#Int16\",\"Property1\":1,"
      + "\"NavigationProperty\":["
      + "{\"@odata.id\":null,\"[email protected]\":\"#Double\",\"Related1\":1.5},"
      + "{\"@odata.id\":null,\"[email protected]\":\"#Double\",\"Related1\":2.75}]}]}",
      serialize(serializer, metadata, null, entityCollection, "Property1,NavigationProperty(Related1)"));
}
 
Example 5
Source File: EdmAssistedJsonSerializerTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void entityCollectionWithComplexProperty() throws Exception {
  Entity entity = new Entity();
  entity.setId(null);
  entity.addProperty(new Property(null, "Property1", ValueType.PRIMITIVE, 1L));
  ComplexValue complexValue = new ComplexValue();
  complexValue.getValue().add(new Property(null, "Inner1", ValueType.PRIMITIVE,
      BigDecimal.TEN.scaleByPowerOfTen(-5)));
  Calendar time = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
  time.clear();
  time.set(Calendar.HOUR_OF_DAY, 13);
  time.set(Calendar.SECOND, 59);
  time.set(Calendar.MILLISECOND, 999);
  complexValue.getValue().add(new Property("Edm.TimeOfDay", "Inner2", ValueType.PRIMITIVE, time));
  entity.addProperty(new Property("Namespace.ComplexType", "Property2", ValueType.COMPLEX, complexValue));
  EntityCollection entityCollection = new EntityCollection();
  entityCollection.getEntities().add(entity);
  Assert.assertEquals("{\"@odata.context\":\"$metadata#EntitySet(Property1,Property2)\","
      + "\"value\":[{\"@odata.id\":null,"
      + "\"[email protected]\":\"#Int64\",\"Property1\":1,"
      + "\"Property2\":{\"@odata.type\":\"#Namespace.ComplexType\","
      + "\"[email protected]\":\"#Decimal\",\"Inner1\":0.00010,"
      + "\"[email protected]\":\"#TimeOfDay\",\"Inner2\":\"13:00:59.999\"}}]}",
      serialize(serializer, metadata, null, entityCollection, null));
}
 
Example 6
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private Entity createEntity(EdmEntitySet edmEntitySet, EdmEntityType edmEntityType, Entity entity, 
    List<Entity> entityList, final String rawServiceUri) throws ODataApplicationException {
  
  // 1.) Create the entity
  final Entity newEntity = new Entity();
  newEntity.setType(entity.getType());
  
  // Create the new key of the entity
  int newId = 1;
  while (entityIdExists(newId, entityList)) {
    newId++;
  }
  
  // Add all provided properties
  newEntity.getProperties().addAll(entity.getProperties());
  
  // Add the key property
  newEntity.getProperties().add(new Property(null, "ID", ValueType.PRIMITIVE, newId));
  newEntity.setId(createId(newEntity, "ID"));
  
  // --> Implement Deep Insert handling here <--
  
  entityList.add(newEntity);

  return newEntity;
}
 
Example 7
Source File: DataProvider.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private EntityCollection createManufacturers() {
  EntityCollection entitySet = new EntityCollection();

  Entity el = new Entity()
      .addProperty(createPrimitive("Id", 1))
      .addProperty(createPrimitive("Name", "Star Powered Racing"))
      .addProperty(createAddress("Star Street 137", "Stuttgart", "70173", "Germany"));
  el.setId(createId(CarsEdmProvider.ES_MANUFACTURER_NAME, 1));
  entitySet.getEntities().add(el);

  el = new Entity()
      .addProperty(createPrimitive("Id", 2))
      .addProperty(createPrimitive("Name", "Horse Powered Racing"))
      .addProperty(createAddress("Horse Street 1", "Maranello", "41053", "Italy"));
  el.setId(createId(CarsEdmProvider.ES_MANUFACTURER_NAME, 2));
  entitySet.getEntities().add(el);

  for (Entity entity:entitySet.getEntities()) {
    entity.setType(CarsEdmProvider.ET_MANUFACTURER.getFullQualifiedNameAsString());
  }
  return entitySet;
}
 
Example 8
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private Entity createEntity(EdmEntityType edmEntityType, Entity entity, List<Entity> entityList) {
  
  // the ID of the newly created entity is generated automatically
  int newId = 1;
  while (entityIdExists(newId, entityList)) {
    newId++;
  }

  Property idProperty = entity.getProperty("ID");
  if (idProperty != null) {
    idProperty.setValue(ValueType.PRIMITIVE, Integer.valueOf(newId));
  } else {
    // as of OData v4 spec, the key property can be omitted from the POST request body
    entity.getProperties().add(new Property(null, "ID", ValueType.PRIMITIVE, newId));
  }
  entity.setId(createId(entity, "ID"));
  entityList.add(entity);

  return entity;
}
 
Example 9
Source File: DataProvider.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
public Entity create(final EdmEntitySet edmEntitySet) throws DataProviderException {
  final EdmEntityType edmEntityType = edmEntitySet.getEntityType();
  EntityCollection entitySet = readAll(edmEntitySet);
  final List<Entity> entities = entitySet.getEntities();
  final Map<String, Object> newKey = findFreeComposedKey(entities, edmEntityType);
  Entity newEntity = new Entity();
  newEntity.setType(edmEntityType.getFullQualifiedName().getFullQualifiedNameAsString());
  for (final String keyName : edmEntityType.getKeyPredicateNames()) {
    newEntity.addProperty(DataCreator.createPrimitive(keyName, newKey.get(keyName)));
  }

  createProperties(edmEntityType, newEntity.getProperties());
  try {
    newEntity.setId(URI.create(odata.createUriHelper().buildCanonicalURL(edmEntitySet, newEntity)));
  } catch (final SerializerException e) {
    throw new DataProviderException("Unable to set entity ID!", HttpStatusCode.INTERNAL_SERVER_ERROR, e);
  }
  entities.add(newEntity);

  return newEntity;
}
 
Example 10
Source File: Storage.java    From syndesis with Apache License 2.0 6 votes vote down vote up
private static Entity createEntity(int id, String name, String description, String[] serials, ComplexValue spec) {
    Entity e = new Entity()
        .addProperty(new Property(
                              EdmPrimitiveTypeKind.Int32.getFullQualifiedName().toString(),
                              PRODUCT_ID, ValueType.PRIMITIVE, id))
        .addProperty(new Property(
                              EdmPrimitiveTypeKind.String.getFullQualifiedName().toString(),
                              PRODUCT_NAME, ValueType.PRIMITIVE, name))
        .addProperty(new Property(
                              EdmPrimitiveTypeKind.String.getFullQualifiedName().toString(),
                              PRODUCT_DESCRIPTION, ValueType.PRIMITIVE, description))
        .addProperty(new Property(
                              EdmPrimitiveTypeKind.String.getFullQualifiedName().toString(),
                              PRODUCT_SERIALS, ValueType.COLLECTION_PRIMITIVE, Arrays.asList(serials)))
        .addProperty(new Property(
                              ET_SPEC_FQN.toString(),
                              PRODUCT_SPEC, ValueType.COMPLEX, spec));

    e.setId(createId(ES_PRODUCTS_NAME, id));
    return e;
}
 
Example 11
Source File: JsonDeltaSerializer.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
/**
 * Get the ascii representation of the entity id
 * or thrown an {@link SerializerException} if id is <code>null</code>.
 *
 * @param entity the entity
 * @return ascii representation of the entity id
 */
private String getEntityId(Entity entity, EdmEntityType entityType, String name) throws SerializerException {
  try {
    if (entity != null) {
      if (entity.getId() == null) {
        if (entityType == null || entityType.getKeyPredicateNames() == null
            || name == null) {
          throw new SerializerException("Entity id is null.", SerializerException.MessageKeys.MISSING_ID);
        } else {
          final UriHelper uriHelper = new UriHelperImpl();
          entity.setId(URI.create(name + '(' + uriHelper.buildKeyPredicate(entityType, entity) + ')'));
          return entity.getId().toASCIIString();
        }
      } else {
        return entity.getId().toASCIIString();
      }
    } 
    return null;
  } catch (Exception e) {
    throw new SerializerException("Entity id is null.", SerializerException.MessageKeys.MISSING_ID);
  }
}
 
Example 12
Source File: AtomDeserializer.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private Entity entityRef(final StartElement start) throws XMLStreamException {
  final Entity entity = new Entity();

  final Attribute entityRefId = start.getAttributeByName(Constants.QNAME_ATOM_ATTR_ID);
  if (entityRefId != null) {
    entity.setId(URI.create(entityRefId.getValue()));
  }

  return entity;
}
 
Example 13
Source File: DataProvider.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
public Entity createContNav(final EdmEntitySet edmEntitySet, final EdmEntityType edmEntityType, 
    final Entity newEntity, List<UriParameter> keys, String navPropertyName) throws DataProviderException {
  List<Entity> rootEntity = data.get(edmEntitySet.getName()).getEntities();
  EntityCollection entitySet = data.get(edmEntityType.getName());
  entitySet.getEntities().add(newEntity);
  
  
  
  for (Entity entity : rootEntity) {
    if (isRootEntity(entity, keys)){
      String id = entity.getId().toASCIIString() + "/" + navPropertyName + 
          appendKeys(newEntity.getProperties(), edmEntityType.getKeyPredicateNames());
      newEntity.setId(URI.create(id));
      
      Link link = entity.getNavigationLink(navPropertyName);
      if (link == null) {
        link = new Link();
        link.setRel(Constants.NS_NAVIGATION_LINK_REL + navPropertyName);
        link.setType(Constants.ENTITY_NAVIGATION_LINK_TYPE);
        link.setTitle(navPropertyName);
        link.setHref(entity.getId().toASCIIString() + 
            (navPropertyName != null && navPropertyName.length() > 0 ? "/" + navPropertyName: ""));
        entity.getNavigationLinks().add(link);
      }
      if (link.getInlineEntitySet() != null) {
        link.getInlineEntitySet().getEntities().add(newEntity);
      } else {
        EntityCollection collection = new EntityCollection();
        collection.getEntities().add(newEntity);
        link.setInlineEntitySet(collection);
      }
    }
  }
  
  return newEntity;
}
 
Example 14
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private void initSampleData(){

		// add some sample product entities
		final Entity e1 = new Entity()
				.addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 1))
				.addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "Notebook Basic 15"))
				.addProperty(new Property(null, "Description", ValueType.PRIMITIVE,
						"Notebook Basic, 1.7GHz - 15 XGA - 1024MB DDR2 SDRAM - 40GB"));
		e1.setId(createId("Products", 1));
		productList.add(e1);

		final Entity e2 = new Entity()
				.addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 2))
				.addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "1UMTS PDA"))
				.addProperty(new Property(null, "Description", ValueType.PRIMITIVE,
						"Ultrafast 3G UMTS/HSDPA Pocket PC, supports GSM network"));
		e2.setId(createId("Products", 2));
		productList.add(e2);

		final Entity e3 = new Entity()
				.addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 3))
				.addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "Ergo Screen"))
				.addProperty(new Property(null, "Description", ValueType.PRIMITIVE,
						"19 Optimum Resolution 1024 x 768 @ 85Hz, resolution 1280 x 960"));
		e3.setId(createId("Products", 3));
		productList.add(e3);
	}
 
Example 15
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private void initSampleData(){

		// add some sample product entities
		final Entity e1 = new Entity()
				.addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 1))
				.addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "Notebook Basic 15"))
				.addProperty(new Property(null, "Description", ValueType.PRIMITIVE,
						"Notebook Basic, 1.7GHz - 15 XGA - 1024MB DDR2 SDRAM - 40GB"));
		e1.setId(createId("Products", 1));
		productList.add(e1);

		final Entity e2 = new Entity()
				.addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 2))
				.addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "1UMTS PDA"))
				.addProperty(new Property(null, "Description", ValueType.PRIMITIVE,
						"Ultrafast 3G UMTS/HSDPA Pocket PC, supports GSM network"));
		e2.setId(createId("Products", 2));
		productList.add(e2);

		final Entity e3 = new Entity()
				.addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 3))
				.addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "Ergo Screen"))
				.addProperty(new Property(null, "Description", ValueType.PRIMITIVE,
						"19 Optimum Resolution 1024 x 768 @ 85Hz, resolution 1280 x 960"));
		e3.setId(createId("Products", 3));
		productList.add(e3);
	}
 
Example 16
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private void initSampleData(){

		// add some sample product entities
		final Entity e1 = new Entity()
				.addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 1))
				.addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "Notebook Basic 15"))
				.addProperty(new Property(null, "Description", ValueType.PRIMITIVE,
						"Notebook Basic, 1.7GHz - 15 XGA - 1024MB DDR2 SDRAM - 40GB"));
		e1.setId(createId("Products", 1));
		productList.add(e1);

		final Entity e2 = new Entity()
				.addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 2))
				.addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "1UMTS PDA"))
				.addProperty(new Property(null, "Description", ValueType.PRIMITIVE,
						"Ultrafast 3G UMTS/HSDPA Pocket PC, supports GSM network"));
		e2.setId(createId("Products", 2));
		productList.add(e2);

		final Entity e3 = new Entity()
				.addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 3))
				.addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "Ergo Screen"))
				.addProperty(new Property(null, "Description", ValueType.PRIMITIVE,
						"19 Optimum Resolution 1024 x 768 @ 85Hz, resolution 1280 x 960"));
		e3.setId(createId("Products", 3));
		productList.add(e3);
	}
 
Example 17
Source File: EdmAssistedJsonSerializerTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void entityCollectionMetadataMin() throws Exception {
  Entity entity = new Entity();
  entity.setId(null);
  entity.addProperty(new Property(null, "Property0", ValueType.PRIMITIVE, null))
      .addProperty(new Property(null, "Property1", ValueType.PRIMITIVE, 1));
  Calendar date = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
  date.clear();
  date.set(2000, 1, 29);
  entity.addProperty(new Property("Edm.Date", "Property2", ValueType.PRIMITIVE, date))
      .addProperty(new Property("Edm.DateTimeOffset", "Property3", ValueType.PRIMITIVE, date))
      .addProperty(new Property(null, "Property4", ValueType.COLLECTION_PRIMITIVE,
          Arrays.asList(true, false, null)));
  EntityCollection entityCollection = new EntityCollection();
  entityCollection.getEntities().add(entity);
  entityCollection.setCount(2);
  entityCollection.setNext(URI.create("nextLink"));
  Assert.assertEquals(
      "{\"@odata.context\":\"$metadata#EntitySet(Property0,Property1,Property2,Property3,Property4)\","
          + "\"@odata.count\":2,"
          + "\"value\":[{"
          + "\"Property0\":null,"
          + "\"Property1\":1,"
          + "\"Property2\":\"2000-02-29\","
          + "\"Property3\":\"2000-02-29T00:00:00Z\","
          + "\"Property4\":[true,false,null]}],"
          + "\"@odata.nextLink\":\"nextLink\"}",
      serialize(serializerMin, metadata, null, entityCollection, null));
}
 
Example 18
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private void initSampleData(){

    // add some sample product entities
    final Entity e1 = new Entity()
        .addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 1))
        .addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "Notebook Basic 15"))
        .addProperty(new Property(null, "Description", ValueType.PRIMITIVE,
            "Notebook Basic, 1.7GHz - 15 XGA - 1024MB DDR2 SDRAM - 40GB"));
    e1.setId(createId("Products", 1));
    productList.add(e1);

    final Entity e2 = new Entity()
        .addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 2))
        .addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "1UMTS PDA"))
        .addProperty(new Property(null, "Description", ValueType.PRIMITIVE,
            "Ultrafast 3G UMTS/HSDPA Pocket PC, supports GSM network"));
    e2.setId(createId("Products", 2));
    productList.add(e2);

    final Entity e3 = new Entity()
        .addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 3))
        .addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "Ergo Screen"))
        .addProperty(new Property(null, "Description", ValueType.PRIMITIVE,
            "19 Optimum Resolution 1024 x 768 @ 85Hz, resolution 1280 x 960"));
    e3.setId(createId("Products", 3));
    productList.add(e3);
  }
 
Example 19
Source File: JsonDeltaSerializerWithNavigationsTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void testIdAnnotationWithNavigationManyInDelta() throws Exception {
  final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESDelta");
  Delta delta = new Delta();
  final Entity entity = data.readAll(edmEntitySet).getEntities().get(1);
  final Entity entity2 = data.readAll(edmEntitySet).getEntities().get(2);
  final ExpandOption expand = ExpandSelectMock.mockExpandOption(Collections.singletonList(
      ExpandSelectMock.mockExpandItem(edmEntitySet, "NavPropertyETBaseContTwoContMany")));
  List<Entity> addedEntity = new ArrayList<Entity>();
  Entity changedEntity = new Entity();
  changedEntity.setId(entity2.getId());
  changedEntity.addProperty(entity2.getProperty("PropertyString"));
  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).build()).expand(expand)
      .build()).getContent();
     String jsonString = IOUtils.toString(stream);
     final String expectedResult = "{\"@context\":\"$metadata#ESDelta/$delta\","
         + "\"value\":[{\"@id\":\"ESDelta(-32768)\",\"PropertyInt16\":-32768,"
         + "\"PropertyString\":\"Number:-32768\","
         + "\"NavPropertyETBaseContTwoContMany@delta\":"
         + "[{\"@id\":\"ESDelta(-32768)/NavPropertyETBaseContTwoContMany"
         + "(PropertyInt16=222,PropertyString='TEST%20B')\","
         + "\"PropertyInt16\":222,\"PropertyString\":\"TEST B\"},"
         + "{\"@id\":\"ESDelta(-32768)/NavPropertyETBaseContTwoContMany"
         + "(PropertyInt16=333,PropertyString='TEST%20C')\",\"PropertyInt16\":333,"
         + "\"PropertyString\":\"TEST C\"}]},{\"@id\":\"ESDelta(0)\","
         + "\"PropertyString\":\"Number:0\",\"NavPropertyETBaseContTwoContMany\":[]}]}";
     Assert.assertNotNull(jsonString);
     Assert.assertEquals(expectedResult, jsonString);
   }
 
Example 20
Source File: JsonDeltaSerializerWithNavigationsTest.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
@Test
public void navigationInDeltaEntityInFullRepresentation() throws Exception {
  final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESDelta");
  Delta delta = new Delta();
  final Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
  final Entity entity2 = data.readAll(edmEntitySet).getEntities().get(1);
  final ExpandOption expand = ExpandSelectMock.mockExpandOption(Collections.singletonList(
      ExpandSelectMock.mockExpandItem(edmEntitySet, "NavPropertyETAllPrimMany")));
  List<Entity> addedEntity = new ArrayList<Entity>();
  Entity changedEntity = new Entity();
  changedEntity.setId(entity2.getId());
  changedEntity.addProperty(entity2.getProperty("PropertyString"));
  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).build()).expand(expand)
      .isFullRepresentation(true).build()).getContent();
     String jsonString = IOUtils.toString(stream);
     final String expectedResult = "{"
       + "\"@context\":\"$metadata#ESDelta/$delta\",\"value\":"
       + "[{\"@id\":\"ESDelta(32767)\",\"PropertyInt16\":32767,\"PropertyString\":\"Number:32767\","
       + "\"NavPropertyETAllPrimMany\":["
       + "{\"@id\":\"ESAllPrim(-32768)\",\"PropertyInt16\":-32768,"
       + "\"PropertyString\":\"Second Resource - negative values\","
       + "\"PropertyBoolean\":false,\"PropertyByte\":0,\"PropertySByte\":-128,\"PropertyInt32\":-2147483648,"
       + "\"PropertyInt64\":-9223372036854775808,\"PropertySingle\":-1.79E8,\"PropertyDouble\":-179000.0,"
       + "\"PropertyDecimal\":-34,\"PropertyBinary\":\"ASNFZ4mrze8=\",\"PropertyDate\":\"2015-11-05\","
       + "\"PropertyDateTimeOffset\":\"2005-12-03T07:17:08Z\",\"PropertyDuration\":\"PT9S\","
       + "\"PropertyGuid\":\"76543201-23ab-cdef-0123-456789dddfff\",\"PropertyTimeOfDay\":\"23:49:14\"},"
       + "{\"@id\":\"ESAllPrim(0)\",\"PropertyInt16\":0,\"PropertyString\":\"\","
       + "\"PropertyBoolean\":false,\"PropertyByte\":0,\"PropertySByte\":0,\"PropertyInt32\":0,"
       + "\"PropertyInt64\":0,\"PropertySingle\":0.0,\"PropertyDouble\":0.0,"
       + "\"PropertyDecimal\":0,"
       + "\"PropertyBinary\":\"\",\"PropertyDate\":\"1970-01-01\","
       + "\"PropertyDateTimeOffset\":\"2005-12-03T00:00:00Z\","
       + "\"PropertyDuration\":\"PT0S\",\"PropertyGuid\":"
       + "\"76543201-23ab-cdef-0123-456789cccddd\","
       + "\"PropertyTimeOfDay\":\"00:01:01\"}]},{\"@id\":\"ESDelta(-32768)\","
       + "\"PropertyString\":\"Number:-32768\",\"NavPropertyETAllPrimMany\":[]}]}";
     Assert.assertNotNull(jsonString);
     Assert.assertEquals(expectedResult, jsonString);
   }