diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityTypeInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityTypeInvocationHandler.java index 389f791d3..d738b5b77 100644 --- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityTypeInvocationHandler.java +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityTypeInvocationHandler.java @@ -342,9 +342,9 @@ public class EntityTypeInvocationHandler((URI) null, null, entry); } else { diff --git a/fit/src/main/java/org/apache/olingo/fit/V4Demo.java b/fit/src/main/java/org/apache/olingo/fit/V4Demo.java new file mode 100644 index 000000000..c00d14a50 --- /dev/null +++ b/fit/src/main/java/org/apache/olingo/fit/V4Demo.java @@ -0,0 +1,157 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.olingo.fit; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import javax.ws.rs.Consumes; +import javax.ws.rs.DefaultValue; +import javax.ws.rs.GET; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriInfo; +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; +import org.apache.olingo.fit.metadata.Metadata; +import org.apache.olingo.fit.utils.Accept; +import org.apache.olingo.fit.utils.ConstantKey; +import org.apache.olingo.fit.utils.Constants; +import org.apache.olingo.fit.utils.FSManager; +import org.springframework.stereotype.Service; + +@Service +@Path("/V40/Demo.svc") +public class V4Demo { + + private final Metadata demoMetadata; + + private final V4Services services; + + public V4Demo() throws Exception { + this.demoMetadata = new Metadata(FSManager.instance(ODataServiceVersion.V40). + readFile("demo" + StringUtils.capitalize(Constants.get(ODataServiceVersion.V40, ConstantKey.METADATA)), + Accept.XML), ODataServiceVersion.V40); + this.services = new V4Services() { + @Override + protected Metadata getMetadataObj() { + return demoMetadata; + } + }; + } + + private Response replaceServiceName(final Response response) { + try { + final String content = IOUtils.toString((InputStream) response.getEntity(), Constants.ENCODING). + replaceAll("Static\\.svc", "Demo.svc"); + + final Response.ResponseBuilder builder = Response.status(response.getStatus()); + for (String headerName : response.getHeaders().keySet()) { + for (Object headerValue : response.getHeaders().get(headerName)) { + builder.header(headerName, headerValue); + } + } + + final InputStream toBeStreamedBack = IOUtils.toInputStream(content, Constants.ENCODING); + final ByteArrayOutputStream baos = new ByteArrayOutputStream(); + IOUtils.copy(toBeStreamedBack, baos); + IOUtils.closeQuietly(toBeStreamedBack); + + builder.header("Content-Length", baos.size()); + builder.entity(new ByteArrayInputStream(baos.toByteArray())); + + return builder.build(); + } catch (Exception e) { + return response; + } + } + + @GET + @Path("/$metadata") + @Produces(MediaType.APPLICATION_XML) + public Response getMetadata() { + return services.getMetadata( + "demo" + StringUtils.capitalize(Constants.get(ODataServiceVersion.V40, ConstantKey.METADATA))); + } + + @GET + @Path("/{entitySetName}({entityId})") + public Response getEntity( + @Context UriInfo uriInfo, + @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept, + @PathParam("entitySetName") String entitySetName, + @PathParam("entityId") String entityId, + @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format, + @QueryParam("$expand") @DefaultValue(StringUtils.EMPTY) String expand, + @QueryParam("$select") @DefaultValue(StringUtils.EMPTY) String select) { + + return replaceServiceName(services.getEntityInternal(uriInfo.getRequestUri().toASCIIString(), + accept, entitySetName, entityId, format, expand, select, false)); + } + + @GET + @Path("/{entitySetName}({entityId})/$value") + public Response getMediaEntity( + @Context UriInfo uriInfo, + @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept, + @PathParam("entitySetName") String entitySetName, + @PathParam("entityId") String entityId) { + + return services.getMediaEntity(uriInfo, accept, entitySetName, entityId); + } + + @POST + @Path("/{entitySetName}") + @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON}) + @Consumes({MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM}) + public Response postNewEntity( + @Context UriInfo uriInfo, + @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept, + @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType, + @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) String prefer, + @PathParam("entitySetName") String entitySetName, + final String entity) { + + return replaceServiceName(services.postNewEntity(uriInfo, accept, contentType, prefer, entitySetName, entity)); + } + + @PUT + @Produces({MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON}) + @Consumes({MediaType.WILDCARD, MediaType.APPLICATION_OCTET_STREAM}) + @Path("/{entitySetName}({entityId})/$value") + public Response replaceMediaEntity( + @Context UriInfo uriInfo, + @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) String prefer, + @PathParam("entitySetName") String entitySetName, + @PathParam("entityId") String entityId, + @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format, + String value) { + + return services.replaceMediaEntity(uriInfo, prefer, entitySetName, entityId, format, value); + } +} diff --git a/fit/src/main/resources/V40/Advertisements/f89dee73-af9f-4cd4-b330-db93c25ff3c7/$value.bin b/fit/src/main/resources/V40/Advertisements/f89dee73-af9f-4cd4-b330-db93c25ff3c7/$value.bin new file mode 100644 index 000000000..e69de29bb diff --git a/fit/src/main/resources/V40/Advertisements/f89dee73-af9f-4cd4-b330-db93c25ff3c7/entity.full.json b/fit/src/main/resources/V40/Advertisements/f89dee73-af9f-4cd4-b330-db93c25ff3c7/entity.full.json new file mode 100644 index 000000000..47307813b --- /dev/null +++ b/fit/src/main/resources/V40/Advertisements/f89dee73-af9f-4cd4-b330-db93c25ff3c7/entity.full.json @@ -0,0 +1,16 @@ +{ + "@odata.context": "http://localhost:${cargo.servlet.port}/stub/StaticService/V40/Demo.svc/$metadata#Advertisements/$entity", + "@odata.type": "#ODataDemo.Advertisement", + "@odata.id": "http://localhost:${cargo.servlet.port}/stub/StaticService/V40/Demo.svc/Advertisements(f89dee73-af9f-4cd4-b330-db93c25ff3c7)", + "@odata.editLink": "Advertisements(f89dee73-af9f-4cd4-b330-db93c25ff3c7)", + "@odata.mediaEditLink": "Advertisements(f89dee73-af9f-4cd4-b330-db93c25ff3c7)/$value", + "@odata.mediaContentType": "*/*", + "@odata.mediaEtag": "\"8zOOKKvgOtptr4gt8IrnapX3jds=\"", + "ID@odata.type": "#Guid", + "ID": "f89dee73-af9f-4cd4-b330-db93c25ff3c7", + "Name": "Old School Lemonade Store, Retro Style", + "AirDate@odata.type": "#DateTimeOffset", + "AirDate": "2012-11-07T00:00:00Z", + "FeaturedProduct@odata.associationLink": "Advertisements(f89dee73-af9f-4cd4-b330-db93c25ff3c7)/FeaturedProduct/$ref", + "FeaturedProduct@odata.navigationLink": "Advertisements(f89dee73-af9f-4cd4-b330-db93c25ff3c7)/FeaturedProduct" +} diff --git a/fit/src/main/resources/V40/Advertisements/f89dee73-af9f-4cd4-b330-db93c25ff3c7/entity.xml b/fit/src/main/resources/V40/Advertisements/f89dee73-af9f-4cd4-b330-db93c25ff3c7/entity.xml new file mode 100644 index 000000000..72a8cc62b --- /dev/null +++ b/fit/src/main/resources/V40/Advertisements/f89dee73-af9f-4cd4-b330-db93c25ff3c7/entity.xml @@ -0,0 +1,40 @@ + + + + http://localhost:${cargo.servlet.port}/stub/StaticService/V40/Demo.svc/Advertisements(f89dee73-af9f-4cd4-b330-db93c25ff3c7) + + + + + + <updated>2014-05-07T13:42:01Z</updated> + <author> + <name/> + </author> + <link rel="edit-media" title="Advertisement" href="Advertisements(f89dee73-af9f-4cd4-b330-db93c25ff3c7)/$value" m:etag=""8zOOKKvgOtptr4gt8IrnapX3jds=""/> + <content type="*/*" src="Advertisements(f89dee73-af9f-4cd4-b330-db93c25ff3c7)/$value"/> + <m:properties> + <d:ID m:type="Guid">f89dee73-af9f-4cd4-b330-db93c25ff3c7</d:ID> + <d:Name>Old School Lemonade Store, Retro Style</d:Name> + <d:AirDate m:type="DateTimeOffset">2012-11-07T00:00:00Z</d:AirDate> + </m:properties> +</entry> diff --git a/fit/src/main/resources/V40/Advertisements/feed.full.json b/fit/src/main/resources/V40/Advertisements/feed.full.json new file mode 100644 index 000000000..3d0a90e60 --- /dev/null +++ b/fit/src/main/resources/V40/Advertisements/feed.full.json @@ -0,0 +1,31 @@ +{ + "@odata.context": "http://localhost:${cargo.servlet.port}/stub/StaticService/V40/Demo.svc/$metadata#Advertisements", + "value": [{ + "@odata.type": "#ODataDemo.Advertisement", + "@odata.id": "http://localhost:${cargo.servlet.port}/stub/StaticService/V40/Demo.svc/Advertisements(f89dee73-af9f-4cd4-b330-db93c25ff3c7)", + "@odata.editLink": "Advertisements(f89dee73-af9f-4cd4-b330-db93c25ff3c7)", + "@odata.mediaEditLink": "Advertisements(f89dee73-af9f-4cd4-b330-db93c25ff3c7)/$value", + "@odata.mediaContentType": "*/*", + "@odata.mediaEtag": "\"8zOOKKvgOtptr4gt8IrnapX3jds=\"", + "ID@odata.type": "#Guid", + "ID": "f89dee73-af9f-4cd4-b330-db93c25ff3c7", + "Name": "Old School Lemonade Store, Retro Style", + "AirDate@odata.type": "#DateTimeOffset", + "AirDate": "2012-11-07T00:00:00Z", + "FeaturedProduct@odata.associationLink": "Advertisements(f89dee73-af9f-4cd4-b330-db93c25ff3c7)/FeaturedProduct/$ref", + "FeaturedProduct@odata.navigationLink": "Advertisements(f89dee73-af9f-4cd4-b330-db93c25ff3c7)/FeaturedProduct" + }, { + "@odata.type": "#ODataDemo.Advertisement", + "@odata.id": "http://localhost:${cargo.servlet.port}/stub/StaticService/V40/Demo.svc/Advertisements(db2d2186-1c29-4d1e-88ef-a127f521b9c6)", + "@odata.editLink": "Advertisements(db2d2186-1c29-4d1e-88ef-a127f521b9c6)", + "@odata.mediaEditLink": "Advertisements(db2d2186-1c29-4d1e-88ef-a127f521b9c6)/$value", + "@odata.mediaContentType": "*/*", + "ID@odata.type": "#Guid", + "ID": "db2d2186-1c29-4d1e-88ef-a127f521b9c6", + "Name": "Early morning start, need coffee", + "AirDate@odata.type": "#DateTimeOffset", + "AirDate": "2000-02-29T00:00:00Z", + "FeaturedProduct@odata.associationLink": "Advertisements(db2d2186-1c29-4d1e-88ef-a127f521b9c6)/FeaturedProduct/$ref", + "FeaturedProduct@odata.navigationLink": "Advertisements(db2d2186-1c29-4d1e-88ef-a127f521b9c6)/FeaturedProduct" + }] +} diff --git a/fit/src/main/resources/V40/Advertisements/feed.xml b/fit/src/main/resources/V40/Advertisements/feed.xml new file mode 100644 index 000000000..874ffe9cb --- /dev/null +++ b/fit/src/main/resources/V40/Advertisements/feed.xml @@ -0,0 +1,65 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + +--> +<feed xml:base="http://localhost:${cargo.servlet.port}/stub/StaticService/V40/Demo.svc/" xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://docs.oasis-open.org/odata/ns/data" xmlns:m="http://docs.oasis-open.org/odata/ns/metadata" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml" m:context="http://localhost:${cargo.servlet.port}/stub/StaticService/V40/Demo.svc/$metadata#Advertisements"> + <id>http://localhost:${cargo.servlet.port}/stub/StaticService/V40/Demo.svc/Advertisements</id> + <title type="text">Advertisements + 2014-05-07T13:39:27Z + + + http://localhost:${cargo.servlet.port}/stub/StaticService/V40/Demo.svc/Advertisements(f89dee73-af9f-4cd4-b330-db93c25ff3c7) + + + + + + <updated>2014-05-07T13:39:27Z</updated> + <author> + <name/> + </author> + <link rel="edit-media" title="Advertisement" href="Advertisements(f89dee73-af9f-4cd4-b330-db93c25ff3c7)/$value" m:etag=""8zOOKKvgOtptr4gt8IrnapX3jds=""/> + <content type="*/*" src="Advertisements(f89dee73-af9f-4cd4-b330-db93c25ff3c7)/$value"/> + <m:properties> + <d:ID m:type="Guid">f89dee73-af9f-4cd4-b330-db93c25ff3c7</d:ID> + <d:Name>Old School Lemonade Store, Retro Style</d:Name> + <d:AirDate m:type="DateTimeOffset">2012-11-07T00:00:00Z</d:AirDate> + </m:properties> + </entry> + <entry> + <id>http://localhost:${cargo.servlet.port}/stub/StaticService/V40/Demo.svc/Advertisements(db2d2186-1c29-4d1e-88ef-a127f521b9c6)</id> + <category term="#ODataDemo.Advertisement" scheme="http://docs.oasis-open.org/odata/ns/scheme"/> + <link rel="edit" title="Advertisement" href="Advertisements(db2d2186-1c29-4d1e-88ef-a127f521b9c6)"/> + <link rel="http://docs.oasis-open.org/odata/ns/relatedlinks/FeaturedProduct" type="application/xml" title="FeaturedProduct" href="Advertisements(db2d2186-1c29-4d1e-88ef-a127f521b9c6)/FeaturedProduct/$ref"/> + <link rel="http://docs.oasis-open.org/odata/ns/related/FeaturedProduct" type="application/atom+xml;type=entry" title="FeaturedProduct" href="Advertisements(db2d2186-1c29-4d1e-88ef-a127f521b9c6)/FeaturedProduct"/> + <title/> + <updated>2014-05-07T13:39:27Z</updated> + <author> + <name/> + </author> + <link rel="edit-media" title="Advertisement" href="Advertisements(db2d2186-1c29-4d1e-88ef-a127f521b9c6)/$value"/> + <content type="*/*" src="Advertisements(db2d2186-1c29-4d1e-88ef-a127f521b9c6)/$value"/> + <m:properties> + <d:ID m:type="Guid">db2d2186-1c29-4d1e-88ef-a127f521b9c6</d:ID> + <d:Name>Early morning start, need coffee</d:Name> + <d:AirDate m:type="DateTimeOffset">2000-02-29T00:00:00Z</d:AirDate> + </m:properties> + </entry> +</feed> diff --git a/fit/src/main/resources/V40/demoMetadata.xml b/fit/src/main/resources/V40/demoMetadata.xml new file mode 100644 index 000000000..22ecfe108 --- /dev/null +++ b/fit/src/main/resources/V40/demoMetadata.xml @@ -0,0 +1,172 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + +--> +<edmx:Edmx Version="4.0" xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx"> + <edmx:DataServices> + <Schema Namespace="ODataDemo" xmlns="http://docs.oasis-open.org/odata/ns/edm"> + <EntityType Name="Product"> + <Key> + <PropertyRef Name="ID" /> + </Key> + <Property Name="ID" Type="Edm.Int32" Nullable="false" /> + <Property Name="Name" Type="Edm.String" /> + <Property Name="Description" Type="Edm.String" /> + <Property Name="ReleaseDate" Type="Edm.DateTimeOffset" Nullable="false" /> + <Property Name="DiscontinuedDate" Type="Edm.DateTimeOffset" /> + <Property Name="Rating" Type="Edm.Int16" Nullable="false" /> + <Property Name="Price" Type="Edm.Double" Nullable="false" /> + <NavigationProperty Name="Categories" Type="Collection(ODataDemo.Category)" Partner="Products" /> + <NavigationProperty Name="Supplier" Type="ODataDemo.Supplier" Partner="Products" /> + <NavigationProperty Name="ProductDetail" Type="ODataDemo.ProductDetail" Partner="Product" /> + </EntityType> + <EntityType Name="FeaturedProduct" BaseType="ODataDemo.Product"> + <NavigationProperty Name="Advertisement" Type="ODataDemo.Advertisement" Partner="FeaturedProduct" /> + </EntityType> + <EntityType Name="ProductDetail"> + <Key> + <PropertyRef Name="ProductID" /> + </Key> + <Property Name="ProductID" Type="Edm.Int32" Nullable="false" /> + <Property Name="Details" Type="Edm.String" /> + <NavigationProperty Name="Product" Type="ODataDemo.Product" Partner="ProductDetail" /> + </EntityType> + <EntityType Name="Category" OpenType="true"> + <Key> + <PropertyRef Name="ID" /> + </Key> + <Property Name="ID" Type="Edm.Int32" Nullable="false" /> + <Property Name="Name" Type="Edm.String" /> + <NavigationProperty Name="Products" Type="Collection(ODataDemo.Product)" Partner="Categories" /> + </EntityType> + <EntityType Name="Supplier"> + <Key> + <PropertyRef Name="ID" /> + </Key> + <Property Name="ID" Type="Edm.Int32" Nullable="false" /> + <Property Name="Name" Type="Edm.String" /> + <Property Name="Address" Type="ODataDemo.Address" /> + <Property Name="Location" Type="Edm.GeographyPoint" SRID="Variable" /> + <Property Name="Concurrency" Type="Edm.Int32" ConcurrencyMode="Fixed" Nullable="false" /> + <NavigationProperty Name="Products" Type="Collection(ODataDemo.Product)" Partner="Supplier" /> + </EntityType> + <ComplexType Name="Address"> + <Property Name="Street" Type="Edm.String" /> + <Property Name="City" Type="Edm.String" /> + <Property Name="State" Type="Edm.String" /> + <Property Name="ZipCode" Type="Edm.String" /> + <Property Name="Country" Type="Edm.String" /> + </ComplexType> + <EntityType Name="Person"> + <Key> + <PropertyRef Name="ID" /> + </Key> + <Property Name="ID" Type="Edm.Int32" Nullable="false" /> + <Property Name="Name" Type="Edm.String" /> + <NavigationProperty Name="PersonDetail" Type="ODataDemo.PersonDetail" Partner="Person" /> + </EntityType> + <EntityType Name="Customer" BaseType="ODataDemo.Person"> + <Property Name="TotalExpense" Type="Edm.Decimal" Nullable="false" /> + </EntityType> + <EntityType Name="Employee" BaseType="ODataDemo.Person"> + <Property Name="EmployeeID" Type="Edm.Int64" Nullable="false" /> + <Property Name="HireDate" Type="Edm.DateTimeOffset" Nullable="false" /> + <Property Name="Salary" Type="Edm.Single" Nullable="false" /> + </EntityType> + <EntityType Name="PersonDetail"> + <Key> + <PropertyRef Name="PersonID" /> + </Key> + <Property Name="PersonID" Type="Edm.Int32" Nullable="false" /> + <Property Name="Age" Type="Edm.Byte" Nullable="false" /> + <Property Name="Gender" Type="Edm.Boolean" Nullable="false" /> + <Property Name="Phone" Type="Edm.String" /> + <Property Name="Address" Type="ODataDemo.Address" /> + <Property Name="Photo" Type="Edm.Stream" Nullable="false" /> + <NavigationProperty Name="Person" Type="ODataDemo.Person" Partner="PersonDetail" /> + </EntityType> + <EntityType Name="Advertisement" HasStream="true"> + <Key> + <PropertyRef Name="ID" /> + </Key> + <Property Name="ID" Type="Edm.Guid" Nullable="false" /> + <Property Name="Name" Type="Edm.String" /> + <Property Name="AirDate" Type="Edm.DateTimeOffset" Nullable="false" /> + <NavigationProperty Name="FeaturedProduct" Type="ODataDemo.FeaturedProduct" Partner="Advertisement" /> + </EntityType> + <Action Name="Discount" IsBound="true"> + <Parameter Name="product" Type="ODataDemo.Product" /> + <Parameter Name="discountPercentage" Type="Edm.Int32" Nullable="false" /> + <ReturnType Type="Edm.Double" Nullable="false" /> + </Action> + <Action Name="IncreaseSalaries"> + <Parameter Name="percentage" Type="Edm.Int32" Nullable="false" /> + </Action> + <EntityContainer Name="DemoService"> + <EntitySet Name="Products" EntityType="ODataDemo.Product"> + <NavigationPropertyBinding Path="ODataDemo.FeaturedProduct/Advertisement" Target="Advertisements" /> + <NavigationPropertyBinding Path="Categories" Target="Categories" /> + <NavigationPropertyBinding Path="Supplier" Target="Suppliers" /> + <NavigationPropertyBinding Path="ProductDetail" Target="ProductDetails" /> + </EntitySet> + <EntitySet Name="ProductDetails" EntityType="ODataDemo.ProductDetail"> + <NavigationPropertyBinding Path="Product" Target="Products" /> + </EntitySet> + <EntitySet Name="Categories" EntityType="ODataDemo.Category"> + <NavigationPropertyBinding Path="Products" Target="Products" /> + </EntitySet> + <EntitySet Name="Suppliers" EntityType="ODataDemo.Supplier"> + <NavigationPropertyBinding Path="Products" Target="Products" /> + </EntitySet> + <EntitySet Name="Persons" EntityType="ODataDemo.Person"> + <NavigationPropertyBinding Path="PersonDetail" Target="PersonDetails" /> + </EntitySet> + <EntitySet Name="PersonDetails" EntityType="ODataDemo.PersonDetail"> + <NavigationPropertyBinding Path="Person" Target="Persons" /> + </EntitySet> + <EntitySet Name="Advertisements" EntityType="ODataDemo.Advertisement"> + <NavigationPropertyBinding Path="FeaturedProduct" Target="Products" /> + </EntitySet> + <ActionImport Name="IncreaseSalaries" Action="ODataDemo.IncreaseSalaries" /> + </EntityContainer> + <Annotations Target="ODataDemo.DemoService"> + <Annotation Term="Org.OData.Display.V1.Description" String="This is a sample OData service with vocabularies" /> + </Annotations> + <Annotations Target="ODataDemo.Product"> + <Annotation Term="Org.OData.Display.V1.Description" String="All Products available in the online store" /> + </Annotations> + <Annotations Target="ODataDemo.Product/Name"> + <Annotation Term="Org.OData.Display.V1.DisplayName" String="Product Name" /> + </Annotations> + <Annotations Target="ODataDemo.DemoService/Suppliers"> + <Annotation Term="Org.OData.Publication.V1.PublisherName" String="Microsoft Corp." /> + <Annotation Term="Org.OData.Publication.V1.PublisherId" String="MSFT" /> + <Annotation Term="Org.OData.Publication.V1.Keywords" String="Inventory, Supplier, Advertisers, Sales, Finance" /> + <Annotation Term="Org.OData.Publication.V1.AttributionUrl" String="http://www.odata.org/" /> + <Annotation Term="Org.OData.Publication.V1.AttributionDescription" String="All rights reserved" /> + <Annotation Term="Org.OData.Publication.V1.DocumentationUrl " String="http://www.odata.org/" /> + <Annotation Term="Org.OData.Publication.V1.TermsOfUseUrl" String="All rights reserved" /> + <Annotation Term="Org.OData.Publication.V1.PrivacyPolicyUrl" String="http://www.odata.org/" /> + <Annotation Term="Org.OData.Publication.V1.LastModified" String="4/2/2013" /> + <Annotation Term="Org.OData.Publication.V1.ImageUrl " String="http://www.odata.org/" /> + </Annotations> + </Schema> + </edmx:DataServices> +</edmx:Edmx> \ No newline at end of file diff --git a/fit/src/main/webapp/WEB-INF/applicationContext.xml b/fit/src/main/webapp/WEB-INF/applicationContext.xml index c37b8d01e..f22858329 100644 --- a/fit/src/main/webapp/WEB-INF/applicationContext.xml +++ b/fit/src/main/webapp/WEB-INF/applicationContext.xml @@ -49,6 +49,7 @@ <bean class="org.apache.olingo.fit.V4NorthWindExt"/> <bean class="org.apache.olingo.fit.V4OpenType"/> <bean class="org.apache.olingo.fit.V4Vocabularies"/> + <bean class="org.apache.olingo.fit.V4Demo"/> </jaxrs:serviceBeans> <jaxrs:providers> <bean class="com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider"/> diff --git a/fit/src/test/java/org/apache/olingo/fit/v3/AbstractTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v3/AbstractTestITCase.java index ab81e7cd3..6ecc4f31b 100644 --- a/fit/src/test/java/org/apache/olingo/fit/v3/AbstractTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/v3/AbstractTestITCase.java @@ -375,7 +375,7 @@ public abstract class AbstractTestITCase extends AbstractBaseTestITCase { // check defined links checkLinks(original.getAssociationLinks(), actual.getAssociationLinks()); - checkLinks(original.getEditMediaLinks(), actual.getEditMediaLinks()); + checkLinks(original.getMediaEditLinks(), actual.getMediaEditLinks()); checkLinks(original.getNavigationLinks(), actual.getNavigationLinks()); // check defined properties equality diff --git a/fit/src/test/java/org/apache/olingo/fit/v3/AsyncTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v3/AsyncTestITCase.java index 68d852455..aa6f5e2ef 100644 --- a/fit/src/test/java/org/apache/olingo/fit/v3/AsyncTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/v3/AsyncTestITCase.java @@ -70,7 +70,7 @@ public class AsyncTestITCase extends AbstractTestITCase { final ODataEntity entity = entityRes.getBody(); entity.getAssociationLinks().clear(); entity.getNavigationLinks().clear(); - entity.getEditMediaLinks().clear(); + entity.getMediaEditLinks().clear(); entity.getProperties().remove(entity.getProperty("Description")); getClient().getBinder().add(entity, diff --git a/fit/src/test/java/org/apache/olingo/fit/v3/MediaEntityTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v3/MediaEntityTestITCase.java index e0bf0f284..49073786c 100644 --- a/fit/src/test/java/org/apache/olingo/fit/v3/MediaEntityTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/v3/MediaEntityTestITCase.java @@ -18,6 +18,9 @@ */ package org.apache.olingo.fit.v3; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + import java.io.ByteArrayInputStream; import java.io.InputStream; import org.apache.commons.io.IOUtils; @@ -38,11 +41,6 @@ import org.apache.olingo.commons.api.domain.v3.ODataEntity; import org.apache.olingo.commons.api.domain.v3.ODataProperty; import org.apache.olingo.commons.api.format.ODataMediaFormat; import org.apache.olingo.commons.api.format.ODataPubFormat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNotNull; - import org.junit.Test; public class MediaEntityTestITCase extends AbstractTestITCase { @@ -84,6 +82,28 @@ public class MediaEntityTestITCase extends AbstractTestITCase { retrieveReq.execute(); } + private void updateMediaEntity(final ODataPubFormat format, final int id) throws Exception { + final URIBuilder builder = client.getURIBuilder(testStaticServiceRootURL). + appendEntitySetSegment("Car").appendKeySegment(id).appendValueSegment(); + + final String TO_BE_UPDATED = "new buffered stream sample"; + final InputStream input = IOUtils.toInputStream(TO_BE_UPDATED); + + final ODataMediaEntityUpdateRequest<ODataEntity> updateReq = + client.getStreamedRequestFactory().getMediaEntityUpdateRequest(builder.build(), input); + updateReq.setFormat(format); + + final MediaEntityUpdateStreamManager<ODataEntity> streamManager = updateReq.execute(); + final ODataMediaEntityUpdateResponse<ODataEntity> updateRes = streamManager.getResponse(); + assertEquals(204, updateRes.getStatusCode()); + + final ODataMediaRequest retrieveReq = client.getRetrieveRequestFactory().getMediaRequest(builder.build()); + + final ODataRetrieveResponse<InputStream> retrieveRes = retrieveReq.execute(); + assertEquals(200, retrieveRes.getStatusCode()); + assertEquals(TO_BE_UPDATED, IOUtils.toString(retrieveRes.getBody())); + } + @Test public void updateMediaEntityAsAtom() throws Exception { updateMediaEntity(ODataPubFormat.ATOM, 14); @@ -94,6 +114,38 @@ public class MediaEntityTestITCase extends AbstractTestITCase { updateMediaEntity(ODataPubFormat.JSON, 15); } + private void createMediaEntity(final ODataPubFormat format, final InputStream input) throws Exception { + final URIBuilder builder = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Car"); + + final ODataMediaEntityCreateRequest<ODataEntity> createReq = + client.getStreamedRequestFactory().getMediaEntityCreateRequest(builder.build(), input); + createReq.setFormat(format); + + final MediaEntityCreateStreamManager<ODataEntity> streamManager = createReq.execute(); + final ODataMediaEntityCreateResponse<ODataEntity> createRes = streamManager.getResponse(); + assertEquals(201, createRes.getStatusCode()); + + final ODataEntity created = createRes.getBody(); + assertNotNull(created); + assertEquals(2, created.getProperties().size()); + + Integer id = null; + for (ODataProperty prop : created.getProperties()) { + if ("VIN".equals(prop.getName())) { + id = prop.getPrimitiveValue().toCastValue(Integer.class); + } + } + assertNotNull(id); + + builder.appendKeySegment(id).appendValueSegment(); + + final ODataMediaRequest retrieveReq = client.getRetrieveRequestFactory().getMediaRequest(builder.build()); + + final ODataRetrieveResponse<InputStream> retrieveRes = retrieveReq.execute(); + assertEquals(200, retrieveRes.getStatusCode()); + assertNotNull(retrieveRes.getBody()); + } + @Test public void createMediaEntityAsAtom() throws Exception { createMediaEntity(ODataPubFormat.ATOM, IOUtils.toInputStream("buffered stream sample")); @@ -131,59 +183,4 @@ public class MediaEntityTestITCase extends AbstractTestITCase { assertEquals(200, retrieveRes.getStatusCode()); assertEquals(TO_BE_UPDATED, IOUtils.toString(retrieveRes.getBody())); } - - private void updateMediaEntity(final ODataPubFormat format, final int id) throws Exception { - URIBuilder builder = client.getURIBuilder(testStaticServiceRootURL). - appendEntitySetSegment("Car").appendKeySegment(id).appendValueSegment(); - - final String TO_BE_UPDATED = "new buffered stream sample"; - final InputStream input = IOUtils.toInputStream(TO_BE_UPDATED); - - final ODataMediaEntityUpdateRequest<ODataEntity> updateReq = - client.getStreamedRequestFactory().getMediaEntityUpdateRequest(builder.build(), input); - updateReq.setFormat(format); - - final MediaEntityUpdateStreamManager<ODataEntity> streamManager = updateReq.execute(); - final ODataMediaEntityUpdateResponse<ODataEntity> updateRes = streamManager.getResponse(); - assertEquals(204, updateRes.getStatusCode()); - - final ODataMediaRequest retrieveReq = client.getRetrieveRequestFactory().getMediaRequest(builder.build()); - - final ODataRetrieveResponse<InputStream> retrieveRes = retrieveReq.execute(); - assertEquals(200, retrieveRes.getStatusCode()); - assertEquals(TO_BE_UPDATED, IOUtils.toString(retrieveRes.getBody())); - } - - private void createMediaEntity(final ODataPubFormat format, final InputStream input) throws Exception { - final URIBuilder builder = client.getURIBuilder(testStaticServiceRootURL). - appendEntitySetSegment("Car"); - - final ODataMediaEntityCreateRequest<ODataEntity> createReq = - client.getStreamedRequestFactory().getMediaEntityCreateRequest(builder.build(), input); - createReq.setFormat(format); - - final MediaEntityCreateStreamManager<ODataEntity> streamManager = createReq.execute(); - final ODataMediaEntityCreateResponse<ODataEntity> createRes = streamManager.getResponse(); - assertEquals(201, createRes.getStatusCode()); - - final ODataEntity created = createRes.getBody(); - assertNotNull(created); - assertEquals(2, created.getProperties().size()); - - Integer id = null; - for (ODataProperty prop : created.getProperties()) { - if ("VIN".equals(prop.getName())) { - id = prop.getPrimitiveValue().toCastValue(Integer.class); - } - } - assertNotNull(id); - - builder.appendKeySegment(id).appendValueSegment(); - - final ODataMediaRequest retrieveReq = client.getRetrieveRequestFactory().getMediaRequest(builder.build()); - - final ODataRetrieveResponse<InputStream> retrieveRes = retrieveReq.execute(); - assertEquals(200, retrieveRes.getStatusCode()); - assertNotNull(retrieveRes.getBody()); - } } diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/AbstractTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/AbstractTestITCase.java index 49161265b..7fe083707 100644 --- a/fit/src/test/java/org/apache/olingo/fit/v4/AbstractTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/v4/AbstractTestITCase.java @@ -49,6 +49,8 @@ public abstract class AbstractTestITCase extends AbstractBaseTestITCase { protected static String testStaticServiceRootURL; + protected static String testDemoServiceRootURL; + protected static String testVocabulariesServiceRootURL; protected static String testNorthwindRootURL; @@ -64,6 +66,7 @@ public abstract class AbstractTestITCase extends AbstractBaseTestITCase { @BeforeClass public static void setUpODataServiceRoot() throws IOException { testStaticServiceRootURL = "http://localhost:9080/stub/StaticService/V40/Static.svc"; + testDemoServiceRootURL = "http://localhost:9080/stub/StaticService/V40/Demo.svc"; testVocabulariesServiceRootURL = "http://localhost:9080/stub/StaticService/V40/Vocabularies.svc"; testNorthwindRootURL = "http://localhost:9080/stub/StaticService/V40/NorthWind.svc"; testKeyAsSegmentServiceRootURL = "http://localhost:9080/stub/StaticService/V40/KeyAsSegment.svc"; diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/MediaEntityTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/MediaEntityTestITCase.java new file mode 100644 index 000000000..459b24604 --- /dev/null +++ b/fit/src/test/java/org/apache/olingo/fit/v4/MediaEntityTestITCase.java @@ -0,0 +1,122 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.olingo.fit.v4; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.UUID; +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.RandomStringUtils; +import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest; +import org.apache.olingo.client.api.communication.request.retrieve.ODataMediaRequest; +import org.apache.olingo.client.api.communication.request.streamed.MediaEntityUpdateStreamManager; +import org.apache.olingo.client.api.communication.request.streamed.ODataMediaEntityUpdateRequest; +import org.apache.olingo.client.api.communication.response.ODataMediaEntityUpdateResponse; +import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse; +import org.apache.olingo.client.api.uri.v4.URIBuilder; +import org.apache.olingo.client.api.v4.ODataClient; +import org.apache.olingo.client.core.ODataClientFactory; +import org.apache.olingo.commons.api.domain.v4.ODataEntity; +import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; +import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; +import org.apache.olingo.commons.api.format.ODataPubFormat; +import org.junit.Test; + +public class MediaEntityTestITCase extends AbstractTestITCase { + + private void read(final ODataClient client, final ODataPubFormat format) throws IOException { + final URIBuilder builder = client.getURIBuilder(testDemoServiceRootURL). + appendEntitySetSegment("Advertisements"). + appendKeySegment(UUID.fromString("f89dee73-af9f-4cd4-b330-db93c25ff3c7")); + final ODataEntityRequest<ODataEntity> entityReq = + client.getRetrieveRequestFactory().getEntityRequest(builder.build()); + + final ODataEntity entity = entityReq.execute().getBody(); + assertNotNull(entity); + assertTrue(entity.isMediaEntity()); + assertEquals(EdmPrimitiveTypeKind.DateTimeOffset.getFullQualifiedName().toString(), + entity.getProperty("AirDate").getValue().getTypeName()); + + final ODataMediaRequest streamReq = client.getRetrieveRequestFactory(). + getMediaRequest(entity.getMediaContentSource()); + final ODataRetrieveResponse<InputStream> streamRes = streamReq.execute(); + assertEquals(200, streamRes.getStatusCode()); + + final byte[] actual = new byte[Integer.parseInt(streamRes.getHeader("Content-Length").iterator().next())]; + IOUtils.read(streamRes.getBody(), actual, 0, actual.length); + } + + @Test + public void readAsAtom() throws IOException { + read(client, ODataPubFormat.ATOM); + } + + @Test + public void readAsJSON() throws IOException { + read(ODataClientFactory.getEdmEnabledV4(testDemoServiceRootURL), ODataPubFormat.JSON); + } + + @Test + public void readAsJSONFull() throws IOException { + read(client, ODataPubFormat.JSON_FULL_METADATA); + } + + private void update(final ODataClient client, final ODataPubFormat format) + throws IOException, EdmPrimitiveTypeException { + + final URI uri = client.getURIBuilder(testDemoServiceRootURL). + appendEntitySetSegment("Advertisements"). + appendKeySegment(UUID.fromString("f89dee73-af9f-4cd4-b330-db93c25ff3c7")).appendValueSegment().build(); + + final String random = RandomStringUtils.random(124); + + // 1. update providing media content + final ODataMediaEntityUpdateRequest<ODataEntity> updateReq = client.getStreamedRequestFactory(). + getMediaEntityUpdateRequest(uri, IOUtils.toInputStream(random)); + updateReq.setFormat(format); + + final MediaEntityUpdateStreamManager<ODataEntity> streamManager = updateReq.execute(); + final ODataMediaEntityUpdateResponse<ODataEntity> createRes = streamManager.getResponse(); + assertEquals(204, createRes.getStatusCode()); + + // 2. check that media content was effectively uploaded + final ODataMediaRequest streamReq = client.getRetrieveRequestFactory().getMediaRequest(uri); + final ODataRetrieveResponse<InputStream> streamRes = streamReq.execute(); + assertEquals(200, streamRes.getStatusCode()); + + final byte[] actual = new byte[Integer.parseInt(streamRes.getHeader("Content-Length").iterator().next())]; + IOUtils.read(streamRes.getBody(), actual, 0, actual.length); + assertEquals(random, new String(actual)); + } + + @Test + public void updateAsAtom() throws IOException, EdmPrimitiveTypeException { + update(client, ODataPubFormat.ATOM); + } + + @Test + public void updateAsJSON() throws IOException, EdmPrimitiveTypeException { + update(client, ODataPubFormat.JSON); + } +} diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/PropertyTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/PropertyTestITCase.java index de7ea5090..2c8046bf7 100644 --- a/fit/src/test/java/org/apache/olingo/fit/v4/PropertyTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/v4/PropertyTestITCase.java @@ -18,12 +18,12 @@ */ package org.apache.olingo.fit.v4; -import java.io.IOException; -import org.apache.olingo.client.api.communication.request.cud.ODataPropertyUpdateRequest; -import org.apache.olingo.client.api.communication.request.cud.v4.UpdateType; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import java.io.IOException; +import org.apache.olingo.client.api.communication.request.cud.ODataPropertyUpdateRequest; +import org.apache.olingo.client.api.communication.request.cud.v4.UpdateType; import org.apache.olingo.client.api.communication.request.retrieve.ODataPropertyRequest; import org.apache.olingo.client.api.communication.response.ODataPropertyUpdateResponse; import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse; @@ -112,16 +112,6 @@ public class PropertyTestITCase extends AbstractTestITCase { complex(edmClient, ODataFormat.JSON); } - @Test - public void complexFromFullJSON() { - complex(client, ODataFormat.JSON_FULL_METADATA); - } - - @Test - public void patchComplexPropertyAsJSON() throws IOException { - updateComplexProperty(ODataFormat.JSON_FULL_METADATA, UpdateType.PATCH); - } - private void updateComplexProperty(final ODataFormat format, final UpdateType type) throws IOException { final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL). appendEntitySetSegment("Customers").appendKeySegment(1).appendPropertySegment("HomeAddress"); @@ -135,7 +125,7 @@ public class PropertyTestITCase extends AbstractTestITCase { ODataProperty homeAddress = client.getObjectFactory().newComplexProperty("HomeAddress", - client.getObjectFactory().newComplexValue(retrieveRes.getBody().getComplexValue().getTypeName())); + client.getObjectFactory().newComplexValue(retrieveRes.getBody().getComplexValue().getTypeName())); homeAddress.getComplexValue().add(client.getObjectFactory(). newPrimitiveProperty("City", client.getObjectFactory().newPrimitiveValueBuilder().buildString("Pescara"))); @@ -161,4 +151,15 @@ public class PropertyTestITCase extends AbstractTestITCase { homeAddress = retrieveRes.getBody(); assertEquals("Pescara", homeAddress.getComplexValue().get("City").getPrimitiveValue().toString()); } + + @Test + public void complexFromFullJSON() { + complex(client, ODataFormat.JSON_FULL_METADATA); + } + + @Test + public void patchComplexPropertyAsJSON() throws IOException { + updateComplexProperty(ODataFormat.JSON_FULL_METADATA, UpdateType.PATCH); + } + } diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/CommonODataClient.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/CommonODataClient.java index 759636d31..1d9cdd399 100644 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/CommonODataClient.java +++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/CommonODataClient.java @@ -25,7 +25,7 @@ import org.apache.olingo.client.api.communication.request.cud.CommonCUDRequestFa import org.apache.olingo.client.api.communication.request.cud.CommonUpdateType; import org.apache.olingo.client.api.communication.request.invoke.InvokeRequestFactory; import org.apache.olingo.client.api.communication.request.retrieve.CommonRetrieveRequestFactory; -import org.apache.olingo.client.api.communication.request.streamed.CommonStreamedRequestFactory; +import org.apache.olingo.client.api.communication.request.streamed.StreamedRequestFactory; import org.apache.olingo.client.api.op.ClientODataDeserializer; import org.apache.olingo.commons.api.domain.CommonODataObjectFactory; import org.apache.olingo.client.api.op.CommonODataBinder; @@ -71,7 +71,7 @@ public interface CommonODataClient<UT extends CommonUpdateType> { CommonCUDRequestFactory<UT> getCUDRequestFactory(); - CommonStreamedRequestFactory getStreamedRequestFactory(); + StreamedRequestFactory getStreamedRequestFactory(); InvokeRequestFactory getInvokeRequestFactory(); diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/streamed/CommonStreamedRequestFactory.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/streamed/StreamedRequestFactory.java similarity index 97% rename from lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/streamed/CommonStreamedRequestFactory.java rename to lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/streamed/StreamedRequestFactory.java index ec91b9bcd..b70642f77 100644 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/streamed/CommonStreamedRequestFactory.java +++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/streamed/StreamedRequestFactory.java @@ -26,7 +26,7 @@ import org.apache.olingo.commons.api.domain.CommonODataEntity; /** * OData request factory class. */ -public interface CommonStreamedRequestFactory extends Serializable { +public interface StreamedRequestFactory extends Serializable { /** * Gets a media entity create request object instance. diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/streamed/v3/StreamedRequestFactory.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/streamed/v3/StreamedRequestFactory.java deleted file mode 100644 index db3ff842c..000000000 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/streamed/v3/StreamedRequestFactory.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.olingo.client.api.communication.request.streamed.v3; - -import org.apache.olingo.client.api.communication.request.streamed.CommonStreamedRequestFactory; - -public interface StreamedRequestFactory extends CommonStreamedRequestFactory { -} diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/streamed/v4/StreamedRequestFactory.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/streamed/v4/StreamedRequestFactory.java deleted file mode 100644 index 7319e334e..000000000 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/streamed/v4/StreamedRequestFactory.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.olingo.client.api.communication.request.streamed.v4; - -import org.apache.olingo.client.api.communication.request.streamed.CommonStreamedRequestFactory; - -public interface StreamedRequestFactory extends CommonStreamedRequestFactory { -} diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/v3/ODataClient.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/v3/ODataClient.java index 576d64803..bca42cce0 100644 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/v3/ODataClient.java +++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/v3/ODataClient.java @@ -23,7 +23,6 @@ import org.apache.olingo.client.api.communication.request.batch.v3.BatchRequestF import org.apache.olingo.client.api.communication.request.cud.v3.CUDRequestFactory; import org.apache.olingo.client.api.communication.request.cud.v3.UpdateType; import org.apache.olingo.client.api.communication.request.retrieve.v3.RetrieveRequestFactory; -import org.apache.olingo.client.api.communication.request.streamed.v3.StreamedRequestFactory; import org.apache.olingo.client.api.op.v3.ODataBinder; import org.apache.olingo.client.api.op.v3.ODataDeserializer; import org.apache.olingo.client.api.op.v3.ODataReader; @@ -60,9 +59,6 @@ public interface ODataClient extends CommonODataClient<UpdateType> { @Override CUDRequestFactory getCUDRequestFactory(); - @Override - StreamedRequestFactory getStreamedRequestFactory(); - @Override BatchRequestFactory getBatchRequestFactory(); } diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/v4/ODataClient.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/v4/ODataClient.java index 171f51f2c..411e1fc44 100644 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/v4/ODataClient.java +++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/v4/ODataClient.java @@ -23,7 +23,6 @@ import org.apache.olingo.client.api.communication.request.batch.v4.BatchRequestF import org.apache.olingo.client.api.communication.request.cud.v4.CUDRequestFactory; import org.apache.olingo.client.api.communication.request.cud.v4.UpdateType; import org.apache.olingo.client.api.communication.request.retrieve.v4.RetrieveRequestFactory; -import org.apache.olingo.client.api.communication.request.streamed.v4.StreamedRequestFactory; import org.apache.olingo.client.api.communication.request.v4.AsyncRequestFactory; import org.apache.olingo.client.api.op.v4.ODataBinder; import org.apache.olingo.client.api.op.v4.ODataDeserializer; @@ -63,9 +62,6 @@ public interface ODataClient extends CommonODataClient<UpdateType> { @Override CUDRequestFactory getCUDRequestFactory(); - @Override - StreamedRequestFactory getStreamedRequestFactory(); - @Override BatchRequestFactory getBatchRequestFactory(); } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataMediaRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataMediaRequestImpl.java index 8159281c8..527ab2f67 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataMediaRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataMediaRequestImpl.java @@ -42,7 +42,7 @@ public class ODataMediaRequestImpl extends AbstractODataRetrieveRequest<InputStr * @param odataClient client instance getting this request * @param query query to be executed. */ - ODataMediaRequestImpl(final CommonODataClient odataClient, final URI query) { + ODataMediaRequestImpl(final CommonODataClient<?> odataClient, final URI query) { super(odataClient, ODataMediaFormat.class, query); setAccept(ODataMediaFormat.APPLICATION_OCTET_STREAM.toString()); @@ -75,6 +75,7 @@ public class ODataMediaRequestImpl extends AbstractODataRetrieveRequest<InputStr * Just to create response templates to be initialized from batch. */ private ODataMediaResponseImpl() { + super(); } /** diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/AbstractStreamedRequestFactory.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/StreamedRequestFactoryImpl.java similarity index 93% rename from lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/AbstractStreamedRequestFactory.java rename to lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/StreamedRequestFactoryImpl.java index cf15fcb7f..a7f1b56b8 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/AbstractStreamedRequestFactory.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/StreamedRequestFactoryImpl.java @@ -24,17 +24,17 @@ import org.apache.olingo.client.api.CommonODataClient; import org.apache.olingo.client.api.communication.request.streamed.ODataMediaEntityCreateRequest; import org.apache.olingo.client.api.communication.request.streamed.ODataMediaEntityUpdateRequest; import org.apache.olingo.client.api.communication.request.streamed.ODataStreamUpdateRequest; -import org.apache.olingo.client.api.communication.request.streamed.CommonStreamedRequestFactory; +import org.apache.olingo.client.api.communication.request.streamed.StreamedRequestFactory; import org.apache.olingo.client.api.http.HttpMethod; import org.apache.olingo.commons.api.domain.CommonODataEntity; -public abstract class AbstractStreamedRequestFactory implements CommonStreamedRequestFactory { +public class StreamedRequestFactoryImpl implements StreamedRequestFactory { private static final long serialVersionUID = -2438839640443961168L; protected final CommonODataClient<?> client; - protected AbstractStreamedRequestFactory(final CommonODataClient<?> client) { + public StreamedRequestFactoryImpl(final CommonODataClient<?> client) { this.client = client; } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/v3/StreamedRequestFactoryImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/v3/StreamedRequestFactoryImpl.java deleted file mode 100644 index 77446ce3a..000000000 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/v3/StreamedRequestFactoryImpl.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.olingo.client.core.communication.request.streamed.v3; - -import org.apache.olingo.client.api.v3.ODataClient; -import org.apache.olingo.client.api.communication.request.streamed.v3.StreamedRequestFactory; -import org.apache.olingo.client.core.communication.request.streamed.AbstractStreamedRequestFactory; - -public class StreamedRequestFactoryImpl extends AbstractStreamedRequestFactory - implements StreamedRequestFactory { - - private static final long serialVersionUID = 2255688283995758441L; - - public StreamedRequestFactoryImpl(final ODataClient client) { - super(client); - } -} diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/v4/StreamedRequestFactoryImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/v4/StreamedRequestFactoryImpl.java deleted file mode 100644 index 608c0efe2..000000000 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/v4/StreamedRequestFactoryImpl.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.olingo.client.core.communication.request.streamed.v4; - -import org.apache.olingo.client.api.v4.ODataClient; -import org.apache.olingo.client.api.communication.request.streamed.v4.StreamedRequestFactory; -import org.apache.olingo.client.core.communication.request.streamed.AbstractStreamedRequestFactory; - -public class StreamedRequestFactoryImpl extends AbstractStreamedRequestFactory - implements StreamedRequestFactory { - - private static final long serialVersionUID = 960862845654673053L; - - public StreamedRequestFactoryImpl(final ODataClient client) { - super(client); - } -} diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/AbstractODataBinder.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/AbstractODataBinder.java index 397ae95cb..4566eb6d9 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/AbstractODataBinder.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/AbstractODataBinder.java @@ -179,7 +179,7 @@ public abstract class AbstractODataBinder implements CommonODataBinder { // ------------------------------------------------------------- // Append edit-media links // ------------------------------------------------------------- - for (ODataLink link : odataEntity.getEditMediaLinks()) { + for (ODataLink link : odataEntity.getMediaEditLinks()) { LOG.debug("Append edit-media link\n{}", link); entity.getMediaEditLinks().add(getLink(link, ResourceFactory.formatForEntityClass(reference) == ODataPubFormat.ATOM)); @@ -417,9 +417,8 @@ public abstract class AbstractODataBinder implements CommonODataBinder { odataNavigationLinks(edmType, resource.getPayload(), entity, resource.getMetadataETag(), base); for (Link link : resource.getPayload().getMediaEditLinks()) { - entity.addLink(new ODataLink.Builder().setVersion(client.getServiceVersion()). - setURI(URIUtils.getURI(base, link.getHref())). - setType(ODataLinkType.MEDIA_EDIT).setTitle(link.getTitle()).build()); + entity.addLink(client.getObjectFactory(). + newMediaEditLink(link.getTitle(), URIUtils.getURI(base, link.getHref()))); } for (ODataOperation operation : resource.getPayload().getOperations()) { @@ -429,7 +428,7 @@ public abstract class AbstractODataBinder implements CommonODataBinder { if (resource.getPayload().isMediaEntity()) { entity.setMediaEntity(true); - entity.setMediaContentSource(resource.getPayload().getMediaContentSource()); + entity.setMediaContentSource(URIUtils.getURI(base, resource.getPayload().getMediaContentSource())); entity.setMediaContentType(resource.getPayload().getMediaContentType()); entity.setMediaETag(resource.getPayload().getMediaETag()); } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/v3/ODataClientImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/v3/ODataClientImpl.java index 8c6273d36..e968f9bb4 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/v3/ODataClientImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/v3/ODataClientImpl.java @@ -27,7 +27,7 @@ import org.apache.olingo.client.api.communication.request.cud.v3.CUDRequestFacto import org.apache.olingo.client.api.communication.request.cud.v3.UpdateType; import org.apache.olingo.client.api.communication.request.invoke.InvokeRequestFactory; import org.apache.olingo.client.api.communication.request.retrieve.v3.RetrieveRequestFactory; -import org.apache.olingo.client.api.communication.request.streamed.v3.StreamedRequestFactory; +import org.apache.olingo.client.api.communication.request.streamed.StreamedRequestFactory; import org.apache.olingo.commons.api.op.ODataSerializer; import org.apache.olingo.client.api.op.v3.ODataDeserializer; import org.apache.olingo.client.api.op.v3.ODataBinder; @@ -40,7 +40,7 @@ import org.apache.olingo.client.core.communication.request.batch.v3.BatchRequest import org.apache.olingo.client.core.communication.request.cud.v3.CUDRequestFactoryImpl; import org.apache.olingo.client.core.communication.request.invoke.v3.InvokeRequestFactoryImpl; import org.apache.olingo.client.core.communication.request.retrieve.v3.RetrieveRequestFactoryImpl; -import org.apache.olingo.client.core.communication.request.streamed.v3.StreamedRequestFactoryImpl; +import org.apache.olingo.client.core.communication.request.streamed.StreamedRequestFactoryImpl; import org.apache.olingo.client.core.op.impl.v3.ODataBinderImpl; import org.apache.olingo.client.core.op.impl.v3.ODataDeserializerImpl; import org.apache.olingo.client.core.op.impl.v3.ODataReaderImpl; diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/v4/ODataClientImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/v4/ODataClientImpl.java index 3a43644ef..58a46f5a5 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/v4/ODataClientImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/v4/ODataClientImpl.java @@ -27,7 +27,7 @@ import org.apache.olingo.client.api.communication.request.cud.v4.CUDRequestFacto import org.apache.olingo.client.api.communication.request.cud.v4.UpdateType; import org.apache.olingo.client.api.communication.request.invoke.InvokeRequestFactory; import org.apache.olingo.client.api.communication.request.retrieve.v4.RetrieveRequestFactory; -import org.apache.olingo.client.api.communication.request.streamed.v4.StreamedRequestFactory; +import org.apache.olingo.client.api.communication.request.streamed.StreamedRequestFactory; import org.apache.olingo.client.api.communication.request.v4.AsyncRequestFactory; import org.apache.olingo.commons.api.op.ODataSerializer; import org.apache.olingo.client.api.op.v4.ODataBinder; @@ -41,7 +41,7 @@ import org.apache.olingo.client.core.communication.request.batch.v4.BatchRequest import org.apache.olingo.client.core.communication.request.cud.v4.CUDRequestFactoryImpl; import org.apache.olingo.client.core.communication.request.invoke.v4.InvokeRequestFactoryImpl; import org.apache.olingo.client.core.communication.request.retrieve.v4.RetrieveRequestFactoryImpl; -import org.apache.olingo.client.core.communication.request.streamed.v4.StreamedRequestFactoryImpl; +import org.apache.olingo.client.core.communication.request.streamed.StreamedRequestFactoryImpl; import org.apache.olingo.client.core.communication.request.v4.AsyncRequestFactoryImpl; import org.apache.olingo.client.core.op.impl.v4.ODataBinderImpl; import org.apache.olingo.client.core.op.impl.v4.ODataDeserializerImpl; diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/EntityTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/EntityTest.java index 20f7536d8..b73dc0db9 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/EntityTest.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/EntityTest.java @@ -55,7 +55,7 @@ public class EntityTest extends AbstractTest { assertEquals("Microsoft.Test.OData.Services.AstoriaDefaultService.Customer", entity.getTypeName().toString()); assertTrue(entity.getEditLink().toASCIIString().endsWith("/Customer(-10)")); assertEquals(5, entity.getNavigationLinks().size()); - assertEquals(2, entity.getEditMediaLinks().size()); + assertEquals(2, entity.getMediaEditLinks().size()); boolean check = false; diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/EntityTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/EntityTest.java index 537dfcd51..8c61a50f4 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/EntityTest.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/EntityTest.java @@ -217,7 +217,7 @@ public class EntityTest extends AbstractTest { assertFalse(entity.isMediaEntity()); - final ODataLink editMedia = entity.getEditMediaLink("Photo"); + final ODataLink editMedia = entity.getMediaEditLink("Photo"); assertNotNull(editMedia); final ODataEntity written = getClient().getBinder().getODataEntity( diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Entity.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Entity.java index 67561f9bd..ab590a16e 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Entity.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Entity.java @@ -135,14 +135,14 @@ public interface Entity extends Linked, Annotatable { * * @return media content resource. */ - String getMediaContentSource(); + URI getMediaContentSource(); /** * Set media content source. * * @param mediaContentSource media content source. */ - void setMediaContentSource(String mediaContentSource); + void setMediaContentSource(URI mediaContentSource); /** * Set media content type. diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/CommonODataEntity.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/CommonODataEntity.java index bfae953a7..1487b130b 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/CommonODataEntity.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/CommonODataEntity.java @@ -101,14 +101,14 @@ public interface CommonODataEntity extends ODataLinked, ODataInvokeResult { * @param name candidate link name * @return media-edit link with given name, if available, otherwise <tt>null</tt> */ - ODataLink getEditMediaLink(String name); + ODataLink getMediaEditLink(final String name); /** - * Returns all entity media edit links. + * Returns entity media edit links. * * @return OData entity links. */ - List<ODataLink> getEditMediaLinks(); + List<ODataLink> getMediaEditLinks(); /** * TRUE if read-only entity. @@ -150,14 +150,14 @@ public interface CommonODataEntity extends ODataLinked, ODataInvokeResult { * * @return media content source. */ - String getMediaContentSource(); + URI getMediaContentSource(); /** * Sets media content source. * * @param mediaContentSource media content source. */ - void setMediaContentSource(String mediaContentSource); + void setMediaContentSource(URI mediaContentSource); /** * ETag of the binary stream represented by this media entity or named stream property. diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractEntity.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractEntity.java index 21ada97d4..7bc3fd59c 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractEntity.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractEntity.java @@ -18,9 +18,9 @@ */ package org.apache.olingo.commons.core.data; +import java.net.URI; import java.util.ArrayList; import java.util.List; -import org.apache.commons.lang3.StringUtils; import org.apache.olingo.commons.api.data.Entity; import org.apache.olingo.commons.api.data.Link; import org.apache.olingo.commons.api.data.Property; @@ -51,7 +51,7 @@ public abstract class AbstractEntity extends AbstractODataObject implements Enti private final List<Property> properties = new ArrayList<Property>(); - private String mediaContentSource; + private URI mediaContentSource; private String mediaContentType; @@ -167,12 +167,12 @@ public abstract class AbstractEntity extends AbstractODataObject implements Enti } @Override - public String getMediaContentSource() { + public URI getMediaContentSource() { return this.mediaContentSource; } @Override - public void setMediaContentSource(final String mediaContentSource) { + public void setMediaContentSource(final URI mediaContentSource) { this.mediaContentSource = mediaContentSource; } @@ -188,6 +188,6 @@ public abstract class AbstractEntity extends AbstractODataObject implements Enti @Override public boolean isMediaEntity() { - return StringUtils.isNotBlank(this.mediaContentSource); + return this.mediaContentSource != null; } } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomDeserializer.java index 27379da86..dad1bfa63 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomDeserializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomDeserializer.java @@ -677,7 +677,7 @@ public class AtomDeserializer extends AbstractAtomDealer { entity.setMediaContentType(type.getValue()); final Attribute src = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATOM_ATTR_SRC)); if (src != null) { - entity.setMediaContentSource(src.getValue()); + entity.setMediaContentSource(URI.create(src.getValue())); } } } else if (propertiesQName.equals(event.asStartElement().getName())) { diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomSerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomSerializer.java index 0f9750af7..cfa83fb8d 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomSerializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomSerializer.java @@ -309,8 +309,8 @@ public class AtomSerializer extends AbstractAtomDealer { if (StringUtils.isNotBlank(entity.getMediaContentType())) { writer.writeAttribute(Constants.ATTR_TYPE, entity.getMediaContentType()); } - if (StringUtils.isNotBlank(entity.getMediaContentSource())) { - writer.writeAttribute(Constants.ATOM_ATTR_SRC, entity.getMediaContentSource()); + if (entity.getMediaContentSource() != null) { + writer.writeAttribute(Constants.ATOM_ATTR_SRC, entity.getMediaContentSource().toASCIIString()); } writer.writeEndElement(); diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntityDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntityDeserializer.java index 567fadbcd..46413757e 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntityDeserializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntityDeserializer.java @@ -121,11 +121,11 @@ public class JSONEntityDeserializer extends AbstractJsonDeserializer<JSONEntityI } if (tree.hasNonNull(jsonMediaReadLink)) { - entity.setMediaContentSource(tree.get(jsonMediaReadLink).textValue()); + entity.setMediaContentSource(URI.create(tree.get(jsonMediaReadLink).textValue())); tree.remove(jsonMediaReadLink); } if (tree.hasNonNull(jsonMediaEditLink)) { - entity.setMediaContentSource(tree.get(jsonMediaEditLink).textValue()); + entity.setMediaContentSource(URI.create(tree.get(jsonMediaEditLink).textValue())); tree.remove(jsonMediaEditLink); } if (tree.hasNonNull(jsonMediaContentType)) { diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntitySerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntitySerializer.java index cb0280d70..cee5b54e6 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntitySerializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntitySerializer.java @@ -26,10 +26,10 @@ import java.net.URI; import org.apache.commons.lang3.StringUtils; import org.apache.olingo.commons.api.Constants; import org.apache.olingo.commons.api.data.Annotation; -import org.apache.olingo.commons.api.data.ResWrap; import org.apache.olingo.commons.api.data.Entity; import org.apache.olingo.commons.api.data.Link; import org.apache.olingo.commons.api.data.Property; +import org.apache.olingo.commons.api.data.ResWrap; import org.apache.olingo.commons.api.domain.ODataOperation; import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; import org.apache.olingo.commons.core.edm.EdmTypeInfo; @@ -87,12 +87,20 @@ public class JSONEntitySerializer extends AbstractJsonSerializer<JSONEntityImpl> valuable(jgen, property, property.getName()); } - if (serverMode && entity.getEditLink() != null && StringUtils.isNotBlank(entity.getEditLink().getHref())) { - final URI link = URI.create(entity.getEditLink().getHref()); - final String editLink = link.isAbsolute() ? link.toASCIIString() - : URI.create(entity.getBaseURI() + "/" + link.toASCIIString()).normalize().toASCIIString(); + if (serverMode) { + if (entity.getEditLink() != null && StringUtils.isNotBlank(entity.getEditLink().getHref())) { + final URI link = URI.create(entity.getEditLink().getHref()); + final String editLink = link.isAbsolute() ? link.toASCIIString() + : URI.create(entity.getBaseURI() + "/" + link.toASCIIString()).normalize().toASCIIString(); - jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_EDIT_LINK), editLink); + jgen.writeStringField( + version.getJSONMap().get(ODataServiceVersion.JSON_EDIT_LINK), editLink); + + if (entity.isMediaEntity()) { + jgen.writeStringField( + version.getJSONMap().get(ODataServiceVersion.JSON_MEDIAREAD_LINK), editLink + "/$value"); + } + } } links(entity, jgen); diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/AbstractODataEntity.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/AbstractODataEntity.java index 3152b3de8..bbc66f75a 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/AbstractODataEntity.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/AbstractODataEntity.java @@ -56,7 +56,7 @@ public abstract class AbstractODataEntity extends AbstractODataPayload implement /** * In case of media entity, media content source. */ - private String mediaContentSource; + private URI mediaContentSource; /** * Media ETag. @@ -81,7 +81,7 @@ public abstract class AbstractODataEntity extends AbstractODataPayload implement /** * Media edit links. */ - private final List<ODataLink> editMediaLinks = new ArrayList<ODataLink>(); + private final List<ODataLink> mediaEditLinks = new ArrayList<ODataLink>(); /** * Operations (legacy, functions, actions). @@ -89,7 +89,7 @@ public abstract class AbstractODataEntity extends AbstractODataPayload implement private final List<ODataOperation> operations = new ArrayList<ODataOperation>(); public AbstractODataEntity(final FullQualifiedName typeName) { - super(typeName == null? null: typeName.toString()); + super(typeName == null ? null : typeName.toString()); this.typeName = typeName; } @@ -160,7 +160,7 @@ public abstract class AbstractODataEntity extends AbstractODataPayload implement break; case MEDIA_EDIT: - result = editMediaLinks.contains(link) ? false : editMediaLinks.add(link); + result = mediaEditLinks.contains(link) ? false : mediaEditLinks.add(link); break; default: @@ -171,7 +171,7 @@ public abstract class AbstractODataEntity extends AbstractODataPayload implement @Override public boolean removeLink(final ODataLink link) { - return associationLinks.remove(link) || navigationLinks.remove(link) || editMediaLinks.remove(link); + return associationLinks.remove(link) || navigationLinks.remove(link); } private ODataLink getLink(final List<ODataLink> links, final String name) { @@ -206,13 +206,13 @@ public abstract class AbstractODataEntity extends AbstractODataPayload implement } @Override - public ODataLink getEditMediaLink(final String name) { - return getLink(editMediaLinks, name); + public ODataLink getMediaEditLink(final String name) { + return getLink(mediaEditLinks, name); } @Override - public List<ODataLink> getEditMediaLinks() { - return editMediaLinks; + public List<ODataLink> getMediaEditLinks() { + return mediaEditLinks; } @Override @@ -256,12 +256,12 @@ public abstract class AbstractODataEntity extends AbstractODataPayload implement } @Override - public String getMediaContentSource() { + public URI getMediaContentSource() { return mediaContentSource; } @Override - public void setMediaContentSource(final String mediaContentSource) { + public void setMediaContentSource(final URI mediaContentSource) { this.mediaContentSource = mediaContentSource; }