org.apache.olingo.commons.api.data.Property Java Examples
The following examples show how to use
org.apache.olingo.commons.api.data.Property.
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: ODataJsonSerializer.java From olingo-odata4 with Apache License 2.0 | 6 votes |
private void writePrimitive(final EdmPrimitiveType type, final Property property, final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale, final Boolean isUnicode, final JsonGenerator json) throws EdmPrimitiveTypeException, IOException, SerializerException { if (property.isPrimitive()) { writePrimitiveValue(property.getName(), type, property.asPrimitive(), isNullable, maxLength, precision, scale, isUnicode, json); } else if (property.isGeospatial()) { writeGeoValue(property.getName(), type, property.asGeospatial(), isNullable, json, null); } else if (property.isEnum()) { writePrimitiveValue(property.getName(), type, property.asEnum(), isNullable, maxLength, precision, scale, isUnicode, json); } else { throw new SerializerException("Inconsistent property type!", SerializerException.MessageKeys.INCONSISTENT_PROPERTY_TYPE, property.getName()); } }
Example #3
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 #4
Source File: ODataJsonSerializerv01Test.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void primitiveCollectionPropertyWithMetadataFull() throws Exception { final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESCollAllPrim"); final EdmProperty edmProperty = (EdmProperty) edmEntitySet.getEntityType().getProperty("CollPropertyString"); final Property property = data.readAll(edmEntitySet).getEntities().get(0).getProperty(edmProperty.getName()); final String resultString = IOUtils.toString(serializerFullMetadata .primitiveCollection(metadata, (EdmPrimitiveType) edmProperty.getType(), property, PrimitiveSerializerOptions.with() .contextURL(ContextURL.with() .entitySet(edmEntitySet).keyPath("1").navOrPropertyPath(edmProperty.getName()) .build()) .build()).getContent()); Assert.assertEquals("{\"@context\":\"../$metadata#ESCollAllPrim(1)/CollPropertyString\"," + "\"@metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"@type\":\"#Collection(String)\",\"value\":[\"[email protected]\"," + "\"[email protected]\",\"[email protected]\"]}", resultString); }
Example #5
Source File: ODataJsonSerializerTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@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 #6
Source File: ODataJsonSerializerv01Test.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void primitiveProperty() 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()); 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()) .build()).getContent()); Assert.assertEquals("{" + "\"@context\":\"../$metadata#ESAllPrim(32767)/PropertyString\"," + "\"@metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"value\":\"First Resource - positive values\"}", resultString); }
Example #7
Source File: DataCreator.java From olingo-odata4 with Apache License 2.0 | 6 votes |
private Property createCollPropertyComp() { return createComplexDerievedCollection("CollPropertyComp", ComplexTypeProvider.nameCTTwoPrim.getFullQualifiedNameAsString(), Arrays.asList(new ComplexValue[] { createComplexValue(ComplexTypeProvider.nameCTTwoPrim.getFullQualifiedNameAsString(), "CollPropertyComp", Arrays.asList(new Property[] { createPrimitive("PropertyInt16", (short) 123), createPrimitive("PropertyString", "TEST 1") } )), createComplexValue(ComplexTypeProvider.nameCTTwoPrim.getFullQualifiedNameAsString(), "CollPropertyComp", Arrays.asList(new Property[] { createPrimitive("PropertyInt16", (short) 456), createPrimitive("PropertyString", "TEST 2") } )), createComplexValue(ComplexTypeProvider.nameCTBase.getFullQualifiedNameAsString(), "CollPropertyComp", Arrays.asList(new Property[] { createPrimitive("PropertyInt16", (short) 789), createPrimitive("PropertyString", "TEST 3"), createPrimitive("AdditionalPropString", "ADD TEST") } ))})); }
Example #8
Source File: ODataJsonSerializerTest.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 #9
Source File: AtomSerializer.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Override public <T> void write(final Writer writer, final T obj) throws ODataSerializerException { try { if (obj instanceof EntityCollection) { entitySet(writer, (EntityCollection) obj); } else if (obj instanceof Entity) { entity(writer, (Entity) obj); } else if (obj instanceof Property) { property(writer, (Property) obj); } else if (obj instanceof Link) { link(writer, (Link) obj); } } catch (final XMLStreamException | EdmPrimitiveTypeException e) { throw new ODataSerializerException(e); } }
Example #10
Source File: ODataJsonSerializerv01Test.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void primitiveCollectionPropertyIEEE754CompatibleInt64() throws Exception { final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESCollAllPrim"); final EdmProperty edmProperty = (EdmProperty) edmEntitySet.getEntityType().getProperty("CollPropertyInt64"); final Property property = data.readAll(edmEntitySet).getEntities().get(0).getProperty(edmProperty.getName()); final String resultString = IOUtils.toString(serializerIEEECompatible .primitiveCollection(metadata, (EdmPrimitiveType) edmProperty.getType(), property, PrimitiveSerializerOptions.with() .contextURL(ContextURL.with() .entitySet(edmEntitySet).keyPath("1").navOrPropertyPath(edmProperty.getName()).build()) .build()).getContent()); Assert.assertEquals("{" + "\"@context\":\"../$metadata#ESCollAllPrim(1)/CollPropertyInt64\"," + "\"@metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"value\":[\"929292929292\",\"333333333333\",\"444444444444\"]}", resultString); }
Example #11
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 #12
Source File: ODataJsonSerializerv01Test.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void complexPropertyWithMetadataFull() throws Exception { final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMixPrimCollComp"); final EdmProperty edmProperty = (EdmProperty) edmEntitySet.getEntityType().getProperty("PropertyComp"); final Property property = data.readAll(edmEntitySet).getEntities().get(0).getProperty("PropertyComp"); final String resultString = IOUtils.toString(serializerFullMetadata .complex(metadata, (EdmComplexType) edmProperty.getType(), property, ComplexSerializerOptions.with() .contextURL(ContextURL.with() .entitySet(edmEntitySet).keyPath("32767").navOrPropertyPath(edmProperty.getName()) .build()).build()).getContent()); Assert.assertEquals("{\"@context\":\"../$metadata#ESMixPrimCollComp(32767)/PropertyComp\"," + "\"@metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"@type\":\"#olingo.odata.test1.CTTwoPrim\"," + "\"PropertyInt16@type\":\"#Int16\",\"PropertyInt16\":111," + "\"PropertyString\":\"TEST A\",\"NavPropertyETTwoKeyNavOne@navigationLink\":" + "\"ESTwoKeyNav(PropertyInt16=1,PropertyString='1')\"}",resultString); }
Example #13
Source File: EdmAssistedJsonSerializerTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void metadataMin() throws Exception { final ServiceMetadata metadata = oData.createServiceMetadata(null, Collections.<EdmxReference> emptyList(), new MetadataETagSupport("W/\"42\"")); Entity entity = new Entity(); entity.setType("Namespace.EntityType"); entity.setId(URI.create("ID")); entity.setETag("W/\"1000\""); Link link = new Link(); link.setHref("editLink"); entity.setEditLink(link); entity.setMediaContentSource(URI.create("media")); entity.addProperty(new Property(null, "Property1", ValueType.PRIMITIVE, UUID.fromString("12345678-ABCD-1234-CDEF-123456789012"))); EntityCollection entityCollection = new EntityCollection(); entityCollection.getEntities().add(entity); Assert.assertEquals("{\"@odata.context\":\"$metadata#EntitySet(Property1)\"," + "\"@odata.metadataEtag\":\"W/\\\"42\\\"\",\"value\":[{" + "\"@odata.etag\":\"W/\\\"1000\\\"\"," + "\"Property1\":\"12345678-abcd-1234-cdef-123456789012\"," + "\"@odata.editLink\":\"editLink\"," + "\"@odata.mediaReadLink\":\"editLink/$value\"}]}", serialize(serializerMin, metadata, null, entityCollection, null)); }
Example #14
Source File: ODataJsonSerializerv01Test.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void complexProperty() throws Exception { final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMixPrimCollComp"); final EdmProperty edmProperty = (EdmProperty) edmEntitySet.getEntityType().getProperty("PropertyComp"); final Property property = data.readAll(edmEntitySet).getEntities().get(0).getProperty("PropertyComp"); final String resultString = IOUtils.toString(serializer .complex(metadata, (EdmComplexType) edmProperty.getType(), property, ComplexSerializerOptions.with() .contextURL(ContextURL.with() .entitySet(edmEntitySet).keyPath("32767").navOrPropertyPath(edmProperty.getName()) .build()) .build()).getContent()); Assert.assertEquals("{" + "\"@context\":\"../$metadata#ESMixPrimCollComp(32767)/PropertyComp\"," + "\"@metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"PropertyInt16\":111,\"PropertyString\":\"TEST A\"}", resultString); }
Example #15
Source File: AtomSerializer.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Override @SuppressWarnings("unchecked") public <T> void write(final Writer writer, final ResWrap<T> container) throws ODataSerializerException { final T obj = container == null ? null : container.getPayload(); try { if (obj instanceof EntityCollection) { this.entitySet(writer, (ResWrap<EntityCollection>) container); } else if (obj instanceof Entity) { entity(writer, (ResWrap<Entity>) container); } else if (obj instanceof Property) { property(writer, (Property) obj); } else if (obj instanceof Link) { link(writer, (Link) obj); } else if (obj instanceof URI) { reference(writer, (ResWrap<URI>) container); } } catch (final XMLStreamException | EdmPrimitiveTypeException e) { throw new ODataSerializerException(e); } }
Example #16
Source File: ODataJsonSerializerTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void complexPropertyWithMetadataFull() throws Exception { final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMixPrimCollComp"); final EdmProperty edmProperty = (EdmProperty) edmEntitySet.getEntityType().getProperty("PropertyComp"); final Property property = data.readAll(edmEntitySet).getEntities().get(0).getProperty("PropertyComp"); final String resultString = IOUtils.toString(serializerFullMetadata .complex(metadata, (EdmComplexType) edmProperty.getType(), property, ComplexSerializerOptions.with() .contextURL(ContextURL.with() .entitySet(edmEntitySet).keyPath("32767").navOrPropertyPath(edmProperty.getName()) .build()).build()).getContent()); Assert.assertEquals("{\"@odata.context\":\"../$metadata#ESMixPrimCollComp(32767)/PropertyComp\"," + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"@odata.type\":\"#olingo.odata.test1.CTTwoPrim\"," + "\"[email protected]\":\"#Int16\",\"PropertyInt16\":111," + "\"PropertyString\":\"TEST A\",\"[email protected]\":" + "\"ESTwoKeyNav(PropertyInt16=1,PropertyString='1')\"}",resultString); }
Example #17
Source File: ProcessorServiceHandler.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Override public void updateProperty(DataRequest request, Property property, boolean rawValue, boolean merge, String entityETag, PropertyResponse response) throws ODataLibraryException, ODataApplicationException { if (property.isPrimitive()) { if (property.isCollection()) { selectProcessor(PrimitiveCollectionProcessor.class).updatePrimitiveCollection( request.getODataRequest(), response.getODataResponse(), request.getUriInfo(), request.getRequestContentType(), request.getResponseContentType()); } else { selectProcessor(PrimitiveProcessor.class).updatePrimitive( request.getODataRequest(), response.getODataResponse(), request.getUriInfo(), request.getRequestContentType(), request.getResponseContentType()); } } else { if (property.isCollection()) { selectProcessor(ComplexCollectionProcessor.class).updateComplexCollection( request.getODataRequest(), response.getODataResponse(), request.getUriInfo(), request.getRequestContentType(), request.getResponseContentType()); } else { selectProcessor(ComplexProcessor.class).updateComplex( request.getODataRequest(), response.getODataResponse(), request.getUriInfo(), request.getRequestContentType(), request.getResponseContentType()); } } }
Example #18
Source File: ActionData.java From olingo-odata4 with Apache License 2.0 | 6 votes |
protected static Property primitiveCollectionBoundAction(final String name, final Map<String, Parameter> parameters, final Map<String, EntityCollection> data, EdmEntitySet edmEntitySet, List<UriParameter> keyList, final OData oData) throws DataProviderException { List<Object> collectionValues = new ArrayList<Object>(); if ("BAETTwoPrimRTCollString".equals(name)) { EdmPrimitiveType strType = oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.String); try { String strValue1 = strType.valueToString("ABC", false, 100, null, null, false); collectionValues.add(strValue1); String strValue2 = strType.valueToString("XYZ", false, 100, null, null, false); collectionValues.add(strValue2); } catch (EdmPrimitiveTypeException e) { throw new DataProviderException("EdmPrimitiveTypeException", HttpStatusCode.BAD_REQUEST, e); } return new Property(null, name, ValueType.COLLECTION_PRIMITIVE, collectionValues); } throw new DataProviderException("Action " + name + " is not yet implemented.", HttpStatusCode.NOT_IMPLEMENTED); }
Example #19
Source File: ODataJsonSerializerv01Test.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("{\"@context\":\"$metadata#ESMixEnumDefCollComp/$entity\"," + "\"@metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"PropertyEnumString\":\"String2,String3\"," + "\"CollPropertyEnumString\":[]," + "\"PropertyDefString\":\"Test\"," + "\"CollPropertyDefString\":[]," + "\"PropertyCompMixedEnumDef\":null," + "\"CollPropertyCompMixedEnumDef\":[]}", resultString); }
Example #20
Source File: ODataXmlSerializer.java From olingo-odata4 with Apache License 2.0 | 6 votes |
protected void writeProperty(final ServiceMetadata metadata, final EdmProperty edmProperty, final Property property, final Set<List<String>> selectedPaths, final String xml10InvalidCharReplacement, final XMLStreamWriter writer, Set<List<String>> expandedPaths, Linked linked, ExpandOption expand) throws XMLStreamException, SerializerException { writer.writeStartElement(DATA, edmProperty.getName(), NS_DATA); if (property == null || property.isNull()) { if (edmProperty.isNullable()) { writer.writeAttribute(METADATA, NS_METADATA, Constants.ATTR_NULL, "true"); } else { throw new SerializerException("Non-nullable property not present!", SerializerException.MessageKeys.MISSING_PROPERTY, edmProperty.getName()); } } else { writePropertyValue(metadata, edmProperty, property, selectedPaths, xml10InvalidCharReplacement, writer, expandedPaths, linked, expand); } writer.writeEndElement(); }
Example #21
Source File: EdmAssistedJsonSerializerTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void entityCollectionWithComplexCollectionNone() 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("{" + "\"value\":[{" + "\"CollPropertyComp\":[" + "{\"PropertyInt16\":1,\"PropertyString\":\"one\"}," + "{\"PropertyInt16\":2,\"PropertyString\":\"two\"}," + "{\"PropertyInt16\":3,\"PropertyString\":\"three\"}]}]}", serialize(serializerNone, metadata, entitySet, entityCollection, "CollPropertyComp")); }
Example #22
Source File: EdmAssistedJsonSerializerTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void entityCollectionWithComplexPropertyMetadataNone() 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("{" + "\"value\":[{" + "\"Property1\":1," + "\"Property2\":{" + "\"Inner1\":0.00010," + "\"Inner2\":\"13:00:59.999\"}}]}", serialize(serializerNone, metadata, null, entityCollection, null)); }
Example #23
Source File: ODataJsonDeserializerEntityTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void derivedEntityETTwoPrim() throws Exception { String entityString = "{\"@odata.type\":\"#olingo.odata.test1.ETBase\","+ "\"PropertyInt16\":32767," + "\"PropertyString\":\"First Resource - positive values\"," + "\"AdditionalPropertyString_5\":\"Additional\"}"; final Entity entity = deserialize(entityString, "ETTwoPrim"); assertNotNull(entity); assertEquals("olingo.odata.test1.ETBase", entity.getType()); List<Property> properties = entity.getProperties(); assertNotNull(properties); assertEquals(3, properties.size()); assertEquals(new Short((short) 32767), entity.getProperty("PropertyInt16").getValue()); assertEquals("First Resource - positive values", entity.getProperty("PropertyString").getValue()); assertNotNull(entity.getProperty("AdditionalPropertyString_5").getValue()); }
Example #24
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 #25
Source File: ODataBinderImpl.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Override public ClientProperty getODataProperty(final ResWrap<Property> resource) { final Property payload = resource.getPayload(); final EdmTypeInfo typeInfo = buildTypeInfo(ContextURLParser.parse(resource.getContextURL()), resource.getMetadataETag(), payload.getName(), payload.getType()); final ClientProperty property = new ClientPropertyImpl(payload.getName(), getODataValue(typeInfo == null ? null : typeInfo.getFullQualifiedName(), payload, resource.getContextURL(), resource.getMetadataETag())); odataAnnotations(payload, property); for (Operation op : resource.getPayload().getOperations()) { ClientOperation operation = new ClientOperation(); operation.setTarget(op.getTarget()); operation.setTitle(op.getTitle()); operation.setMetadataAnchor(op.getMetadataAnchor()); property.getOperations().add(operation); } return property; }
Example #26
Source File: ODataJsonDeserializerEntityTest.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Test public void extendedComplexProperty() throws Exception { final String payload = "{" + "\"@odata.context\":\"$metadata#ESCompComp/$entity\"," + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"@odata.etag\":\"W/\\\"32767\\\"\"," + "\"PropertyInt16\":32767," + "\"PropertyComp\":{" + "\"@odata.type\":\"#olingo.odata.test1.CTTwoPrim\"," + "\"PropertyInt16\":11," + "\"PropertyString\":\"Num11\"" + "}," + "\"PropertyCompComp\":{" + "\"@odata.type\":\"#olingo.odata.test1.CTCompComp\"," + "\"PropertyComp\":{" + "\"@odata.type\":\"#olingo.odata.test1.CTBase\"," + "\"PropertyInt16\":32767," + "\"PropertyString\":\"Num111\"," + "\"AdditionalPropString\":\"Test123\"" + "}}}"; final Entity result = deserialize(payload, "ETFourKeyAlias"); Assert.assertNotNull(result); Property propertyCompComp = result.getProperty("PropertyCompComp"); Assert.assertEquals("PropertyCompComp", propertyCompComp.getName()); Assert.assertEquals("olingo.odata.test1.CTCompComp", propertyCompComp.getType()); Assert.assertTrue(propertyCompComp.isComplex()); ComplexValue complexValuePropComp = propertyCompComp.asComplex(); Property propertyComp = getCVProperty(complexValuePropComp, "PropertyComp"); Assert.assertEquals("PropertyComp", propertyComp.getName()); Assert.assertEquals("olingo.odata.test1.CTBase", propertyComp.getType()); Assert.assertTrue(propertyComp.isComplex()); final ComplexValue cvAdditionalString = propertyComp.asComplex(); Assert.assertEquals("Test123",getCVProperty(cvAdditionalString, "AdditionalPropString").asPrimitive()); }
Example #27
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 #28
Source File: Storage.java From olingo-odata4 with Apache License 2.0 | 5 votes |
private URI createId(Entity entity, String idPropertyName, String navigationName) { try { StringBuilder sb = new StringBuilder(getEntitySetName(entity)).append("("); final Property property = entity.getProperty(idPropertyName); sb.append(property.asPrimitive()).append(")"); if(navigationName != null) { sb.append("/").append(navigationName); } return new URI(sb.toString()); } catch (URISyntaxException e) { throw new ODataRuntimeException("Unable to create (Atom) id for entity: " + entity, e); } }
Example #29
Source File: DataCreator.java From olingo-odata4 with Apache License 2.0 | 5 votes |
protected static Property createComplexCollection(final String name, String type, final List<Property>... propertiesList) { List<ComplexValue> complexCollection = new ArrayList<ComplexValue>(); for (final List<Property> properties : propertiesList) { ComplexValue complexValue = new ComplexValue(); complexValue.getValue().addAll(properties); if (null != name) { complexValue.setId(URI.create(name)); } complexCollection.add(complexValue); } Property property = new Property(type, name, ValueType.COLLECTION_COMPLEX, complexCollection); createOperations(name, type, property); return property; }
Example #30
Source File: DataProvider.java From olingo-odata4 with Apache License 2.0 | 5 votes |
public byte[] readStreamProperty(Property property) { Link link; if(property!=null && property.getValue()!=null){ link = (Link)property.getValue(); if(link.getInlineEntity()!=null){ return (byte[]) link.getInlineEntity().getProperty(property.getName()).getValue(); } } return null; }