org.apache.olingo.commons.api.data.ValueType Java Examples
The following examples show how to use
org.apache.olingo.commons.api.data.ValueType.
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: ODataJsonSerializerTest.java From olingo-odata4 with Apache License 2.0 | 7 votes |
@Test public void primitivePropertyNull() throws Exception { final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim"); final EdmProperty edmProperty = (EdmProperty) edmEntitySet.getEntityType().getProperty("PropertyString"); final Property property = new Property("Edm.String", edmProperty.getName(), ValueType.PRIMITIVE, null); final String resultString = IOUtils .toString(serializer.primitive(metadata, (EdmPrimitiveType) edmProperty.getType(), property, PrimitiveSerializerOptions.with() .contextURL(ContextURL.with() .entitySet(edmEntitySet).keyPath("4242").navOrPropertyPath(edmProperty.getName()) .build()) .build()).getContent()); Assert.assertEquals( "{\"@odata.context\":\"../$metadata#ESAllPrim(4242)/PropertyString\"," +"\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\",\"value\":null}", resultString); }
Example #2
Source File: EdmAssistedJsonSerializerTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void entityCollectionWithComplexPropertyMetadataMin() 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\":[{" + "\"Property1\":1," + "\"Property2\":{" + "\"Inner1\":0.00010," + "\"Inner2\":\"13:00:59.999\"}}]}", serialize(serializerMin, metadata, null, entityCollection, null)); }
Example #3
Source File: Storage.java From syndesis with Apache License 2.0 | 6 votes |
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 #4
Source File: Services.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@GET @Path("/StoredPIs(1000)") public Response getStoredPI(@Context final UriInfo uriInfo) { final Entity entity = new Entity(); entity.setType("Microsoft.Test.OData.Services.ODataWCFService.StoredPI"); final Property id = new Property(); id.setType("Edm.Int32"); id.setName("StoredPIID"); id.setValue(ValueType.PRIMITIVE, 1000); entity.getProperties().add(id); final Link edit = new Link(); edit.setHref(uriInfo.getRequestUri().toASCIIString()); edit.setRel("edit"); edit.setTitle("StoredPI"); entity.setEditLink(edit); final ByteArrayOutputStream content = new ByteArrayOutputStream(); final OutputStreamWriter writer = new OutputStreamWriter(content, Constants.ENCODING); try { jsonSerializer.write(writer, new ResWrap<Entity>((URI) null, null, entity)); return xml.createResponse(new ByteArrayInputStream(content.toByteArray()), null, Accept.JSON_FULLMETA); } catch (Exception e) { LOG.error("While creating StoredPI", e); return xml.createFaultResponse(Accept.JSON_FULLMETA.toString(), e); } }
Example #5
Source File: Storage.java From olingo-odata4 with Apache License 2.0 | 6 votes |
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 #6
Source File: ActionData.java From olingo-odata4 with Apache License 2.0 | 6 votes |
protected static Property complexCollectionAction(final String name, final Map<String, Parameter> parameters) throws DataProviderException { if ("UARTCollCTTwoPrimParam".equals(name)) { List<ComplexValue> complexCollection = new ArrayList<ComplexValue>(); final Parameter paramInt16 = parameters.get("ParameterInt16"); final Short number = paramInt16 == null || paramInt16.isNull() ? 0 : (Short) paramInt16.asPrimitive(); if (number >= 1) { complexCollection.add(createCTTwoPrimComplexProperty("PropertyComp", (short) 16, "Test123").asComplex()); } if (number >= 2) { complexCollection.add(createCTTwoPrimComplexProperty("PropertyComp", (short) 17, "Test456").asComplex()); } if (number >= 3) { complexCollection.add(createCTTwoPrimComplexProperty("PropertyComp", (short) 18, "Test678").asComplex()); } return new Property("PropertyCollComp", name, ValueType.COLLECTION_COMPLEX, complexCollection); } throw new DataProviderException("Action " + name + " is not yet implemented.", HttpStatusCode.NOT_IMPLEMENTED); }
Example #7
Source File: ODataXmlSerializerTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void primitivePropertyNull() throws Exception { final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim"); final EdmProperty edmProperty = (EdmProperty) edmEntitySet.getEntityType().getProperty("PropertyString"); final Property property = new Property("Edm.String", edmProperty.getName(), ValueType.PRIMITIVE, null); String response = IOUtils.toString(serializer.primitive(metadata, (EdmPrimitiveType) edmProperty.getType(), property, PrimitiveSerializerOptions.with() .contextURL(ContextURL.with() .entitySet(edmEntitySet).keyPath("4242").navOrPropertyPath(edmProperty.getName()) .build()) .build()).getContent()); String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<m:value xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\" " + "m:context=\"../$metadata#ESAllPrim(4242)/PropertyString\" " + "m:metadata-etag=\"metadataETag\" " + "m:null=\"true\"></m:value>"; Assert.assertEquals(expected, response); }
Example #8
Source File: ODataXmlSerializerTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void testXML10ReplacementChar() throws Exception { final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim"); final EdmProperty edmProperty = (EdmProperty) edmEntitySet.getEntityType().getProperty("PropertyString"); final Property property = data.readAll(edmEntitySet).getEntities().get(0).getProperty(edmProperty.getName()); property.setValue(ValueType.PRIMITIVE, "ab\u0000cd\u0001"); final String resultString = IOUtils.toString(serializer .primitive(metadata, (EdmPrimitiveType) edmProperty.getType(), property, PrimitiveSerializerOptions.with() .contextURL(ContextURL.with() .entitySet(edmEntitySet).keyPath("32767").navOrPropertyPath(edmProperty.getName()) .build()) .xml10InvalidCharReplacement("XX") .unicode(Boolean.TRUE) .build()).getContent()); String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<m:value xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\" " + "m:context=\"../$metadata#ESAllPrim(32767)/PropertyString\" " + "m:metadata-etag=\"metadataETag\">" + "abXXcdXX</m:value>"; Assert.assertEquals(expected, resultString); }
Example #9
Source File: EntityTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void testNullValuesForPrimitiveTypes() throws Exception { final InputStream input = getClass().getResourceAsStream("ESTwoKeyNav.json"); final ClientEntity entity = client.getBinder().getODataEntity( client.getDeserializer(ContentType.APPLICATION_JSON).toEntity(input)); assertNotNull(entity); Entity entity1 = client.getBinder().getEntity(entity); assertNotNull(entity1); Property property = entity1.getProperty("PropertyComp").asComplex().getValue(). get(1).asComplex().getValue().get(2); assertEquals(property.getType(), "Edm.Boolean"); assertNull(property.getValue()); assertTrue(property.isPrimitive()); assertEquals(property.getValueType(), ValueType.PRIMITIVE); }
Example #10
Source File: EdmAssistedJsonSerializerTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@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 #11
Source File: ODataJsonSerializerv01Test.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void geoPoint() throws Exception { final EdmEntityType entityType = mockEntityType(EdmPrimitiveTypeKind.GeometryPoint); Entity entity = new Entity() .addProperty(new Property(null, entityType.getPropertyNames().get(0), ValueType.GEOSPATIAL, createPoint(1.5, 4.25))); Assert.assertEquals("{\"" + entityType.getPropertyNames().get(0) + "\":{" + "\"type\":\"Point\",\"coordinates\":[1.5,4.25]}}", IOUtils.toString(serializerNoMetadata.entity(metadata, entityType, entity, null).getContent())); Point point = new Point(Dimension.GEOMETRY, null); point.setZ(42); entity = new Entity().addProperty(new Property(null, entityType.getPropertyNames().get(0), ValueType.GEOSPATIAL, point)); Assert.assertEquals("{\"" + entityType.getPropertyNames().get(0) + "\":{" + "\"type\":\"Point\",\"coordinates\":[0.0,0.0,42.0]}}", IOUtils.toString(serializerNoMetadata.entity(metadata, entityType, entity, null).getContent())); }
Example #12
Source File: ODataJsonSerializerTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void geoPoint() throws Exception { final EdmEntityType entityType = mockEntityType(EdmPrimitiveTypeKind.GeometryPoint); Entity entity = new Entity() .addProperty(new Property(null, entityType.getPropertyNames().get(0), ValueType.GEOSPATIAL, createPoint(1.5, 4.25))); Assert.assertEquals("{\"" + entityType.getPropertyNames().get(0) + "\":{" + "\"type\":\"Point\",\"coordinates\":[1.5,4.25]}}", IOUtils.toString(serializerNoMetadata.entity(metadata, entityType, entity, null).getContent())); Point point = new Point(Dimension.GEOMETRY, null); point.setZ(42); entity = new Entity().addProperty(new Property(null, entityType.getPropertyNames().get(0), ValueType.GEOSPATIAL, point)); Assert.assertEquals("{\"" + entityType.getPropertyNames().get(0) + "\":{" + "\"type\":\"Point\",\"coordinates\":[0.0,0.0,42.0]}}", IOUtils.toString(serializerNoMetadata.entity(metadata, entityType, entity, null).getContent())); }
Example #13
Source File: Storage.java From olingo-odata4 with Apache License 2.0 | 6 votes |
private Entity createProduct(EdmEntityType edmEntityType, Entity entity) { // the ID of the newly created product entity is generated automatically int newId = 1; while (productIdExists(newId)) { 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("Products", newId)); this.productList.add(entity); return entity; }
Example #14
Source File: EdmAssistedJsonSerializerTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test(expected = SerializerException.class) public void wrongValueForPropertyFacetInComplexProperty() throws Exception { ComplexValue innerComplexValue = new ComplexValue(); innerComplexValue.getValue().add(new Property(null, "PropertyDecimal", ValueType.PRIMITIVE, BigDecimal.ONE.scaleByPowerOfTen(-6))); ComplexValue complexValue = new ComplexValue(); complexValue.getValue().add(new Property(null, "PropertyComp", ValueType.COMPLEX, innerComplexValue)); EntityCollection entityCollection = new EntityCollection(); entityCollection.getEntities().add( new Entity().addProperty( new Property(null, "CollPropertyComp", ValueType.COLLECTION_COMPLEX, Collections.singletonList(complexValue)))); serializer.entityCollection(metadata, entityContainer.getEntitySet("ESKeyNav").getEntityType(), entityCollection, null); }
Example #15
Source File: ODataJsonSerializerTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void nullComplexValueButInDataMapAndNullCollectionsNotInDataMap() throws Exception { final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMixEnumDefCollComp"); Entity entity = new Entity(); entity.setId(URI.create("id")); entity.addProperty(new Property(null, "PropertyEnumString", ValueType.ENUM, 6)); entity.addProperty(new Property(null, "PropertyDefString", ValueType.PRIMITIVE, "Test")); entity.addProperty(new Property(null, "PropertyCompMixedEnumDef", ValueType.COMPLEX, null)); final String resultString = IOUtils.toString(serializer.entity(metadata, edmEntitySet.getEntityType(), entity, EntitySerializerOptions.with() .contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build()) .build()).getContent()); Assert.assertEquals("{\"@odata.context\":\"$metadata#ESMixEnumDefCollComp/$entity\"," + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"PropertyEnumString\":\"String2,String3\"," + "\"CollPropertyEnumString\":[]," + "\"PropertyDefString\":\"Test\"," + "\"CollPropertyDefString\":[]," + "\"PropertyCompMixedEnumDef\":null," + "\"CollPropertyCompMixedEnumDef\":[]}", resultString); }
Example #16
Source File: EdmAssistedJsonSerializerTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void entityCollectionWithComplexCollection() throws Exception { final EdmEntitySet entitySet = entityContainer.getEntitySet("ESMixPrimCollComp"); ComplexValue complexValue1 = new ComplexValue(); complexValue1.getValue().add(new Property(null, "PropertyInt16", ValueType.PRIMITIVE, 1)); complexValue1.getValue().add(new Property(null, "PropertyString", ValueType.PRIMITIVE, "one")); ComplexValue complexValue2 = new ComplexValue(); complexValue2.getValue().add(new Property(null, "PropertyInt16", ValueType.PRIMITIVE, 2)); complexValue2.getValue().add(new Property(null, "PropertyString", ValueType.PRIMITIVE, "two")); ComplexValue complexValue3 = new ComplexValue(); complexValue3.getValue().add(new Property(null, "PropertyInt16", ValueType.PRIMITIVE, 3)); complexValue3.getValue().add(new Property(null, "PropertyString", ValueType.PRIMITIVE, "three")); EntityCollection entityCollection = new EntityCollection(); entityCollection.getEntities().add(new Entity() .addProperty(new Property(null, "CollPropertyComp", ValueType.COLLECTION_COMPLEX, Arrays.asList(complexValue1, complexValue2, complexValue3)))); Assert.assertEquals("{\"@odata.context\":\"$metadata#ESMixPrimCollComp(CollPropertyComp)\"," + "\"value\":[{\"@odata.id\":null," + "\"CollPropertyComp\":[" + "{\"PropertyInt16\":1,\"PropertyString\":\"one\"}," + "{\"PropertyInt16\":2,\"PropertyString\":\"two\"}," + "{\"PropertyInt16\":3,\"PropertyString\":\"three\"}]}]}", serialize(serializer, metadata, entitySet, entityCollection, "CollPropertyComp")); }
Example #17
Source File: Storage.java From olingo-odata4 with Apache License 2.0 | 6 votes |
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 #18
Source File: ODataJsonSerializerTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void entityWrongData() throws Exception { final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim"); Entity entity = data.readAll(edmEntitySet).getEntities().get(0); entity.getProperties().get(0).setValue(ValueType.PRIMITIVE, false); try { serializer.entity(metadata, edmEntitySet.getEntityType(), entity, EntitySerializerOptions.with() .contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build()) .build()); Assert.fail("Expected exception not thrown!"); } catch (final SerializerException e) { Assert.assertEquals(SerializerException.MessageKeys.WRONG_PROPERTY_VALUE, e.getMessageKey()); final String message = e.getLocalizedMessage(); Assert.assertThat(message, CoreMatchers.containsString("PropertyInt16")); Assert.assertThat(message, CoreMatchers.containsString("false")); } }
Example #19
Source File: ActionDataProviderTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void actionUARTCollStringTwoParam() throws Exception { Map<String, Parameter> parameters = new HashMap<String, Parameter>(); Parameter paramInt16 = new Parameter(); paramInt16.setName("ParameterInt16"); paramInt16.setValue(ValueType.PRIMITIVE, new Short((short) 3)); parameters.put("ParameterInt16", paramInt16); Parameter paramDuration = new Parameter(); paramDuration.setName("ParameterDuration"); paramDuration.setValue(ValueType.PRIMITIVE, new BigDecimal(2)); parameters.put("ParameterDuration", paramDuration); Property result = ActionData.primitiveCollectionAction("UARTCollStringTwoParam", parameters, oData); assertNotNull(result); assertEquals(3, result.asCollection().size()); }
Example #20
Source File: ActionDataProviderTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void actionUARTCTTwoPrimParam() throws Exception { Parameter paramInt16 = new Parameter(); paramInt16.setName("ParameterInt16"); paramInt16.setValue(ValueType.PRIMITIVE, new Short((short) 3)); final Map<String, Parameter> parameters = Collections.singletonMap("ParameterInt16", paramInt16); Property result = ActionData.complexAction("UARTCTTwoPrimParam", parameters); assertNotNull(result); ComplexValue value = result.asComplex(); assertEquals((short) 3, value.getValue().get(0).asPrimitive()); result = ActionData.complexAction("UARTCTTwoPrimParam", Collections.<String, Parameter> emptyMap()); assertNotNull(result); value = result.asComplex(); assertEquals((short) 32767, value.getValue().get(0).asPrimitive()); }
Example #21
Source File: EdmAssistedJsonSerializerTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@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 #22
Source File: ODataJsonSerializerv01Test.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void primitivePropertyNull() throws Exception { final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim"); final EdmProperty edmProperty = (EdmProperty) edmEntitySet.getEntityType().getProperty("PropertyString"); final Property property = new Property("Edm.String", edmProperty.getName(), ValueType.PRIMITIVE, null); final String resultString = IOUtils .toString(serializer.primitive(metadata, (EdmPrimitiveType) edmProperty.getType(), property, PrimitiveSerializerOptions.with() .contextURL(ContextURL.with() .entitySet(edmEntitySet).keyPath("4242").navOrPropertyPath(edmProperty.getName()) .build()) .build()).getContent()); Assert.assertEquals( "{\"@context\":\"../$metadata#ESAllPrim(4242)/PropertyString\"," +"\"@metadataEtag\":\"W/\\\"metadataETag\\\"\",\"value\":null}", resultString); }
Example #23
Source File: EdmAssistedJsonSerializerTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@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 #24
Source File: Storage.java From olingo-odata4 with Apache License 2.0 | 6 votes |
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 #25
Source File: ODataJsonSerializerv01Test.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void geoMultiLineString() throws Exception { final EdmEntityType entityType = mockEntityType(EdmPrimitiveTypeKind.GeometryMultiLineString); final Entity entity = new Entity() .addProperty(new Property(null, entityType.getPropertyNames().get(0), ValueType.GEOSPATIAL, new MultiLineString(Dimension.GEOMETRY, null, Arrays.asList( new LineString(Dimension.GEOMETRY, null, Arrays.asList( createPoint(1, 1), createPoint(2, 2), createPoint(3, 3), createPoint(4, 4), createPoint(5, 5))), new LineString(Dimension.GEOMETRY, null, Arrays.asList( createPoint(99.5, 101.5), createPoint(150, 151.25))))))); Assert.assertEquals("{\"" + entityType.getPropertyNames().get(0) + "\":{" + "\"type\":\"MultiLineString\",\"coordinates\":[" + "[[1.0,1.0],[2.0,2.0],[3.0,3.0],[4.0,4.0],[5.0,5.0]]," + "[[99.5,101.5],[150.0,151.25]]]}}", IOUtils.toString(serializerNoMetadata.entity(metadata, entityType, entity, null).getContent())); }
Example #26
Source File: EdmAssistedJsonSerializerTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void entityCollectionWithComplexCollectionMin() throws Exception { final EdmEntitySet entitySet = entityContainer.getEntitySet("ESMixPrimCollComp"); ComplexValue complexValue1 = new ComplexValue(); complexValue1.getValue().add(new Property(null, "PropertyInt16", ValueType.PRIMITIVE, 1)); complexValue1.getValue().add(new Property(null, "PropertyString", ValueType.PRIMITIVE, "one")); ComplexValue complexValue2 = new ComplexValue(); complexValue2.getValue().add(new Property(null, "PropertyInt16", ValueType.PRIMITIVE, 2)); complexValue2.getValue().add(new Property(null, "PropertyString", ValueType.PRIMITIVE, "two")); ComplexValue complexValue3 = new ComplexValue(); complexValue3.getValue().add(new Property(null, "PropertyInt16", ValueType.PRIMITIVE, 3)); complexValue3.getValue().add(new Property(null, "PropertyString", ValueType.PRIMITIVE, "three")); EntityCollection entityCollection = new EntityCollection(); entityCollection.getEntities().add(new Entity() .addProperty(new Property(null, "CollPropertyComp", ValueType.COLLECTION_COMPLEX, Arrays.asList(complexValue1, complexValue2, complexValue3)))); Assert.assertEquals("{\"@odata.context\":\"$metadata#ESMixPrimCollComp(CollPropertyComp)\"," + "\"value\":[{" + "\"CollPropertyComp\":[" + "{\"PropertyInt16\":1,\"PropertyString\":\"one\"}," + "{\"PropertyInt16\":2,\"PropertyString\":\"two\"}," + "{\"PropertyInt16\":3,\"PropertyString\":\"three\"}]}]}", serialize(serializerMin, metadata, entitySet, entityCollection, "CollPropertyComp")); }
Example #27
Source File: Storage.java From olingo-odata4 with Apache License 2.0 | 6 votes |
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 #28
Source File: Storage.java From olingo-odata4 with Apache License 2.0 | 5 votes |
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 #29
Source File: EdmAssistedJsonSerializerTest.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Test public void entityCollectionSimpleMetadataMin() throws Exception { Entity entity = new Entity(); entity.setId(null); entity.addProperty(new Property(null, "Property1", ValueType.PRIMITIVE, 1.25F)); EntityCollection entityCollection = new EntityCollection(); entityCollection.getEntities().add(entity); Assert.assertEquals("{\"@odata.context\":\"$metadata#EntitySet(Property1)\"," + "\"value\":[{\"Property1\":1.25}]}", serialize(serializerMin, metadata, null, entityCollection, null)); }
Example #30
Source File: EdmAssistedJsonSerializerTest.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Test public void entityCollectionMetadataNone() 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.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(serializerNone, metadata, null, entityCollection, null)); }