[OLINGO-1253]Client Module for Olingo v2
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata2/repo Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata2/commit/4261deb7 Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata2/tree/4261deb7 Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata2/diff/4261deb7 Branch: refs/heads/master Commit: 4261deb7fb7b309d444d9af0e5aad2e45dbfb8ea Parents: 91bd4b8 Author: Archana Rai <[email protected]> Authored: Mon Apr 9 11:58:24 2018 +0530 Committer: Archana Rai <[email protected]> Committed: Mon Apr 9 11:58:24 2018 +0530 ---------------------------------------------------------------------- .../olingo/odata2/api/edm/EdmException.java | 5 + .../odata2/api/ep/EntityProviderException.java | 8 + odata2-lib/odata-client-api/pom.xml | 71 + .../olingo/odata2/client/api/ODataClient.java | 119 + .../olingo/odata2/client/api/edm/ClientEdm.java | 41 + .../odata2/client/api/edm/EdmDataServices.java | 85 + .../odata2/client/api/edm/EdmDocumentation.java | 58 + .../olingo/odata2/client/api/edm/EdmSchema.java | 81 + .../olingo/odata2/client/api/edm/EdmUsing.java | 57 + .../api/ep/ContentTypeBasedDeserializer.java | 91 + .../api/ep/ContentTypeBasedSerializer.java | 63 + .../DeserializerMetadataProviderInterface.java | 30 + .../client/api/ep/DeserializerProperties.java | 170 + .../olingo/odata2/client/api/ep/Entity.java | 97 + .../odata2/client/api/ep/EntityCollection.java | 79 + .../EntityCollectionSerializerProperties.java | 119 + .../api/ep/EntitySerializerProperties.java | 159 + .../odata2/client/api/ep/EntityStream.java | 55 + .../ep/callback/OnDeserializeInlineContent.java | 47 + .../odata2/client/api/uri/EdmURIBuilder.java | 184 + .../odata2/client/api/uri/QueryOption.java | 70 + .../odata2/client/api/uri/SegmentType.java | 76 + .../odata2/client/api/uri/URIBuilder.java | 174 + odata2-lib/odata-client-core/pom.xml | 90 + .../odata2/client/core/ODataClientImpl.java | 181 + .../core/edm/EdmMetadataAssociationEnd.java | 38 + .../odata2/client/core/edm/EdmOnDelete.java | 52 + .../edm/Impl/EdmAnnotationAttributeImpl.java | 99 + .../core/edm/Impl/EdmAnnotationElementImpl.java | 93 + .../core/edm/Impl/EdmAnnotationsImpl.java | 82 + .../core/edm/Impl/EdmAssociationEndImpl.java | 106 + .../core/edm/Impl/EdmAssociationImpl.java | 149 + .../core/edm/Impl/EdmAssociationSetEndImpl.java | 92 + .../core/edm/Impl/EdmAssociationSetImpl.java | 137 + .../core/edm/Impl/EdmComplexPropertyImpl.java | 56 + .../core/edm/Impl/EdmComplexTypeImpl.java | 75 + .../Impl/EdmCustomizableFeedMappingsImpl.java | 140 + .../core/edm/Impl/EdmDocumentationImpl.java | 110 + .../client/core/edm/Impl/EdmElementImpl.java | 55 + .../core/edm/Impl/EdmEntityContainerImpl.java | 222 + .../client/core/edm/Impl/EdmEntitySetImpl.java | 136 + .../client/core/edm/Impl/EdmEntityTypeImpl.java | 133 + .../core/edm/Impl/EdmFunctionImportImpl.java | 179 + .../edm/Impl/EdmFunctionImportParameter.java | 140 + .../odata2/client/core/edm/Impl/EdmImpl.java | 207 + .../odata2/client/core/edm/Impl/EdmKeyImpl.java | 101 + .../client/core/edm/Impl/EdmMappingImpl.java | 99 + .../client/core/edm/Impl/EdmNamedImpl.java | 82 + .../edm/Impl/EdmNavigationPropertyImpl.java | 119 + .../client/core/edm/Impl/EdmOnDeleteImpl.java | 112 + .../client/core/edm/Impl/EdmParameterImpl.java | 71 + .../client/core/edm/Impl/EdmPropertyImpl.java | 91 + .../core/edm/Impl/EdmPropertyRefImpl.java | 47 + .../edm/Impl/EdmReferentialConstraintImpl.java | 72 + .../Impl/EdmReferentialConstraintRoleImpl.java | 98 + .../client/core/edm/Impl/EdmSchemaImpl.java | 205 + .../core/edm/Impl/EdmSimplePropertyImpl.java | 62 + .../core/edm/Impl/EdmStructuralTypeImpl.java | 154 + .../client/core/edm/Impl/EdmTypedImpl.java | 84 + .../client/core/edm/Impl/EdmUsingImpl.java | 129 + .../core/ep/AtomSerializerDeserializer.java | 211 + .../core/ep/JsonSerializerDeserializer.java | 169 + .../ep/deserializer/JsonEntityDeserializer.java | 218 + .../ep/deserializer/JsonEntryDeserializer.java | 451 + .../JsonErrorDocumentDeserializer.java | 278 + .../ep/deserializer/JsonFeedDeserializer.java | 255 + .../deserializer/JsonPropertyDeserializer.java | 326 + .../ep/deserializer/XmlEntityDeserializer.java | 190 + .../ep/deserializer/XmlEntryDeserializer.java | 596 + .../XmlErrorDocumentDeserializer.java | 184 + .../ep/deserializer/XmlFeedDeserializer.java | 226 + .../deserializer/XmlMetadataDeserializer.java | 1570 +++ .../deserializer/XmlPropertyDeserializer.java | 199 + .../serializer/AtomEntryEntitySerializer.java | 669 + .../core/ep/serializer/AtomFeedSerializer.java | 183 + .../serializer/JsonEntryEntitySerializer.java | 309 + .../ep/serializer/JsonFeedEntitySerializer.java | 125 + .../ep/serializer/JsonLinkEntitySerializer.java | 49 + .../JsonPropertyEntitySerializer.java | 151 + .../serializer/XmlPropertyEntitySerializer.java | 234 + .../client/core/uri/EdmURIBuilderImpl.java | 491 + .../olingo/odata2/client/core/uri/Segment.java | 32 + .../odata2/client/core/uri/URIBuilderImpl.java | 217 + .../odata2/client/core/uri/util/UriUtil.java | 186 + .../core/edm/impl/EdmAnnotationImplTest.java | 95 + .../core/edm/impl/EdmAssociationImplTest.java | 64 + .../core/edm/impl/EdmDocumentationImplTest.java | 53 + .../client/core/edm/impl/EdmEntityImplTest.java | 215 + .../core/edm/impl/EdmMappingImplTest.java | 43 + .../core/edm/impl/EdmOnDeleteImplTest.java | 48 + .../client/core/ep/AbstractProviderTest.java | 214 + .../core/ep/AbstractXmlProducerTestHelper.java | 66 + .../core/ep/DeserializerPropertiesTest.java | 65 + .../core/ep/JSON_XMLErrorConsumerTest.java | 70 + .../ep/ProducerConsumerIntegrationTest.java | 811 ++ .../core/ep/SerializerPropertiesTest.java | 87 + .../deserializer/AbstractDeserializerTest.java | 182 + .../AbstractXmlDeserializerTest.java | 63 + .../client/core/ep/deserializer/Callback.java | 21 + .../JsonEntryDeepInsertEntryTest.java | 168 + .../JsonEntryDeepInsertFeedTest.java | 154 + .../deserializer/JsonEntryDeserializerTest.java | 539 + .../JsonErrorDocumentDeserializerTest.java | 234 + .../deserializer/JsonFeedDeserializerTest.java | 689 + .../JsonPropertyDeserializerTest.java | 834 ++ ...LMetadataFunctionImportDeserializerTest.java | 583 + .../deserializer/XmlEntityDeserializerTest.java | 2461 ++++ .../ep/deserializer/XmlErrorDocumentTest.java | 281 + .../deserializer/XmlFeedDeserializerTest.java | 241 + .../XmlMetadataAssociationTest.java | 504 + .../XmlMetadataDeserializerTest.java | 1904 +++ .../ep/serializer/AtomEntrySerializerTest.java | 1814 +++ .../ep/serializer/AtomFeedSerializerTest.java | 1033 ++ .../JsonEntryEntitySerializerTest.java | 1027 ++ .../JsonFeedEntitySerializerTest.java | 919 ++ .../client/core/uri/EdmUriBuilderTest.java | 988 ++ .../core/uri/UriBuilderIntegrationTest.java | 51 + .../odata2/client/core/uri/UriBuilderTest.java | 586 + .../odata2/client/core/uri/UriInfoTest.java | 168 + .../odata2/client/core/uri/UriParserTest.java | 1132 ++ .../src/test/resources/EmployeeContentOnly.xml | 37 + .../EmployeeContentOnlyWithNavigationLink.xml | 38 + .../src/test/resources/JsonBuilding.json | 17 + .../resources/JsonBuildingWithInlineRooms.json | 37 + ...ldingWithInlineRoomsAndNextLinkAndCount.json | 39 + .../JsonBuildingWithInlineRoomsClientCase.json | 35 + .../test/resources/JsonBuildingWithoutD.json | 15 + .../src/test/resources/JsonEmployee.json | 48 + .../test/resources/JsonEmployeeContentOnly.json | 25 + ...onEmployeeContentOnlyWithAdditionalLink.json | 30 + .../JsonEmployeeInlineRoomBuilding.json | 75 + .../resources/JsonEmployeeWithInlineTeam.json | 58 + .../JsonInlineRoomWithInlineBuilding.json | 75 + .../resources/JsonInlineRoomWithInlineNull.json | 44 + .../JsonInvalidTeamDoubleNameProperty.json | 18 + .../src/test/resources/JsonRoom.json | 24 + .../src/test/resources/JsonRoomContentOnly.json | 8 + .../JsonRoomContentOnlyWithAdditionalLink.json | 13 + .../JsonRoom_EmptyInlineEmployeesToTeam.json | 22 + .../JsonRoom_InlineEmployeesToTeam.json | 79 + .../JsonRoomsToEmployeesWithInlineTeams.json | 118 + .../JsonRooms_InlineEmployeesTeams.json | 236 + ...sonRooms_InlineEmployees_InlineBuilding.json | 236 + .../src/test/resources/JsonTeam.json | 17 + .../src/test/resources/JsonTeams.json | 34 + .../src/test/resources/JsonTeamsWithCount.json | 35 + .../resources/JsonTeamsWithCountWithoutD.json | 34 + .../resources/JsonTeamsWithInlineEmployees.json | 151 + .../src/test/resources/JsonTeamsWithoutD.json | 33 + .../test/resources/JsonWithDeletedEntries.json | 30 + .../src/test/resources/LargeEmployeeFeed.xml | 12556 +++++++++++++++++ .../src/test/resources/ProductsFeed.xml | 474 + .../src/test/resources/RoomContentOnly.xml | 28 + .../RoomContentOnlyWithNavigationLink.xml | 29 + .../RoomsToEmployeesWithInlineTeams.xml | 104 + .../src/test/resources/batchWithPost.batch | 39 + .../src/test/resources/double_expanded_team.xml | 264 + .../src/test/resources/expandedBuilding.xml | 61 + .../src/test/resources/expanded_team.xml | 146 + .../src/test/resources/feed_employees.xml | 247 + .../src/test/resources/feed_employees_full.xml | 249 + .../resources/feed_with_deleted_entries.xml | 40 + .../src/test/resources/feed_with_delta_link.xml | 69 + .../test/resources/metadataForDeepInsert.xml | 53 + .../test/resources/metadataForRelatedEntity.xml | 240 + .../src/test/resources/metadataProducts.xml | 69 + .../test/resources/metadataWithNavigations.xml | 19 + .../provider/EdmServiceMetadataImplProv.java | 11 +- .../src/main/resources/i18n.properties | 6 + .../EdmServiceMetadataImplProvTest.java | 20 + .../olingo/odata2/testutil/mock/EdmMock.java | 35 +- odata2-lib/pom.xml | 2 + 172 files changed, 48382 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/4261deb7/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/edm/EdmException.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/edm/EdmException.java b/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/edm/EdmException.java index bc43ac8..5d2322e 100644 --- a/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/edm/EdmException.java +++ b/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/edm/EdmException.java @@ -41,6 +41,11 @@ public class EdmException extends ODataMessageException { public static final MessageReference MUSTBEPROPERTY = createMessageReference(EdmException.class, "MUSTBEPROPERTY"); public static final MessageReference NAMINGERROR = createMessageReference(EdmException.class, "NAMINGERROR"); + public static final MessageReference TYPEPROBLEM = createMessageReference(EdmException.class, "TYPEPROBLEM"); + public static final MessageReference ENTITYTYPEPROBLEM = + createMessageReference(EdmException.class, "ENTITYTYPEPROBLEM"); + public static final MessageReference ASSOCIATIONNOTFOUND = + createMessageReference(EdmException.class, "ASSOCIATIONNOTFOUND"); public EdmException(final MessageReference messageReference) { super(messageReference); http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/4261deb7/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/ep/EntityProviderException.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/ep/EntityProviderException.java b/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/ep/EntityProviderException.java index 4c157a9..cc65e67 100644 --- a/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/ep/EntityProviderException.java +++ b/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/ep/EntityProviderException.java @@ -102,6 +102,14 @@ public class EntityProviderException extends ODataMessageException { /** MISSING_RESULTS_ARRAY requires no content value */ public static final MessageReference MISSING_RESULTS_ARRAY = createMessageReference(EntityProviderException.class, "MISSING_RESULTS_ARRAY"); + public static final MessageReference NULL_VALUE = createMessageReference(EntityProviderException.class, + "NULL_VALUE"); + /** Navigation Property has incorrect type */ + public static final MessageReference INCORRECT_NAVIGATION_TYPE = createMessageReference( + EntityProviderException.class, "INCORRECT_NAVIGATION_TYPE"); + /** MANDATORY_WRITE_PROPERTY requires no content value */ + public static final MessageReference MANDATORY_WRITE_PROPERTY = createMessageReference(EntityProviderException.class, + "MANDATORY_WRITE_PROPERTY"); public static final MessageReference INVALID_DELETED_ENTRY_METADATA = createMessageReference( EntityProviderException.class, "INVALID_DELETED_ENTRY_METADATA"); http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/4261deb7/odata2-lib/odata-client-api/pom.xml ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-client-api/pom.xml b/odata2-lib/odata-client-api/pom.xml new file mode 100644 index 0000000..4291bec --- /dev/null +++ b/odata2-lib/odata-client-api/pom.xml @@ -0,0 +1,71 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.olingo</groupId> + <artifactId>olingo-odata2-lib</artifactId> + <version>2.0.11-SNAPSHOT</version> + <relativePath>..</relativePath> + </parent> + <artifactId>olingo-odata2-client-api</artifactId> + <packaging>jar</packaging> + <name>${project.artifactId}</name> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>${junit.version}</version> + </dependency> + + <dependency> + <groupId>org.apache.olingo</groupId> + <artifactId>olingo-odata2-api</artifactId> + <version>${project.version}</version> + </dependency> + + + </dependencies> + <build> + <plugins> + <plugin> + <artifactId>maven-jar-plugin</artifactId> + <configuration> + <archive> + <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile> + </archive> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <extensions>true</extensions> + <executions> + <execution> + <id>bundle-manifest</id> + <phase>process-classes</phase> + <goals> + <goal>manifest</goal> + </goals> + </execution> + </executions> + <configuration> + <instructions> + <Import-Package> + org.apache.olingo.odata2.client.core.ep;resolution:=optional, + * + </Import-Package> + <Export-Package> + org.apache.olingo.odata2.client.api;version=${project.version}, + org.apache.olingo.odata2.client.api.*;version=${project.version} + </Export-Package> + <Bundle-DocURL>${project.url}</Bundle-DocURL> + <Bundle-ActivationPolicy>lazy</Bundle-ActivationPolicy> + <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName> + </instructions> + </configuration> + </plugin> + </plugins> + </build> +</project> http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/4261deb7/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/ODataClient.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/ODataClient.java b/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/ODataClient.java new file mode 100644 index 0000000..f031004 --- /dev/null +++ b/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/ODataClient.java @@ -0,0 +1,119 @@ +package org.apache.olingo.odata2.client.api; + +import java.io.InputStream; +import java.util.List; +import java.util.Map; + +import org.apache.olingo.odata2.api.edm.Edm; +import org.apache.olingo.odata2.api.edm.EdmException; +import org.apache.olingo.odata2.api.ep.EntityProviderException; +import org.apache.olingo.odata2.api.exception.ODataRuntimeApplicationException; +import org.apache.olingo.odata2.api.uri.PathSegment; +import org.apache.olingo.odata2.api.uri.UriInfo; +import org.apache.olingo.odata2.api.uri.UriNotMatchingException; +import org.apache.olingo.odata2.api.uri.UriSyntaxException; +import org.apache.olingo.odata2.client.api.edm.EdmDataServices; +import org.apache.olingo.odata2.client.api.ep.ContentTypeBasedDeserializer; +import org.apache.olingo.odata2.client.api.ep.ContentTypeBasedSerializer; +import org.apache.olingo.odata2.client.api.uri.EdmURIBuilder; +import org.apache.olingo.odata2.client.api.uri.URIBuilder; + +/** + * This class provides an instance of odata Client + * + */ +public abstract class ODataClient { + + private static final String IMPLEMENTATION = "org.apache.olingo.odata2.client.core.ODataClientImpl"; + + /** + * Use this method to create a new OData instance. Each thread/request should keep its own instance. + * @return a new OData instance + */ + public static ODataClient newInstance() { + try { + final Class<?> clazz = Class.forName(ODataClient.IMPLEMENTATION); + + /* + * We explicitly do not use the singleton pattern to keep the server state free + * and avoid class loading issues also during hot deployment. + */ + final Object object = clazz.newInstance(); + + return (ODataClient) object; + + } catch (final Exception e) { + //TODO: Change the exception + throw new ODataRuntimeApplicationException(null, null, null, null, e); + } + } + + /** + * Creates a new serializer object for rendering content in the specified format. + * + * @param contentType any format supported by Olingo (XML, JSON ...) + * @return ContentTypeBasedSerializer + */ + public abstract ContentTypeBasedSerializer createSerializer(String contentType) throws EntityProviderException; + + /** + * Creates a new deserializer object for reading content in the specified format. + * + * @param contentType any content type supported by Olingo (XML, JSON ...) + * @return ContentTypeBasedDeserializer + */ + public abstract ContentTypeBasedDeserializer createDeserializer(String contentType) throws EntityProviderException; + + /** + * Reads the metadata file and validates it if validate parameter is set to true + * @param content inputStream + * @param validate + * @return EdmDataServices + * @throws EntityProviderException + */ + public abstract EdmDataServices readMetadata(InputStream content, boolean validate) + throws EntityProviderException, EdmException; //NOPMD - suppressed + + /** + * Parses the uri and returns UriInfo + * @param edm + * @param pathSegments + * @param queryParameters + * @return UriInfo + * @throws EntityProviderException + * @throws EdmException + */ + + public abstract UriInfo parseUri(final Edm edm, final List<PathSegment> pathSegments, + final Map<String, List<String>> queryParameters) + throws UriSyntaxException, UriNotMatchingException, EdmException; //NOPMD - suppressed + + /** + * Parses the uri and returns UriInfo + * @param edm + * @param uri + * @return UriInfo + * @throws UriSyntaxException + * @throws UriNotMatchingException + * @throws EdmException + */ + + public abstract UriInfo parseUri(final Edm edm, final String uri) + throws UriSyntaxException, UriNotMatchingException, EdmException; //NOPMD - suppressed + + + + /** + * Constructs the edm uri based on segments appended + * @param serviceRoot + * @return EdmURIBuilder + */ + public abstract EdmURIBuilder edmUriBuilder(String serviceRoot); + + /** + * Constructs the uri based on segments appended + * @param serviceRoot + * @return URIBuilder + */ + public abstract URIBuilder uriBuilder(String serviceRoot); +} http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/4261deb7/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/edm/ClientEdm.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/edm/ClientEdm.java b/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/edm/ClientEdm.java new file mode 100644 index 0000000..6113fd7 --- /dev/null +++ b/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/edm/ClientEdm.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * 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.odata2.client.api.edm; + +import java.util.List; + +import org.apache.olingo.odata2.api.edm.Edm; + +/** + * @org.apache.olingo.odata2.DoNotImplement + * Entity Data Model (EDM) + * <p>Interface representing a Entity Data Model as described in the Conceptual Schema Definition. + * + */ +public interface ClientEdm extends Edm{ + + /** + * This method <b>DOES NOT</b> support lazy loading. All schemas are loaded completely! + * + * @return all schemas defined for this EDM + */ + List<EdmSchema> getSchemas(); + + +} http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/4261deb7/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/edm/EdmDataServices.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/edm/EdmDataServices.java b/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/edm/EdmDataServices.java new file mode 100644 index 0000000..056eb1e --- /dev/null +++ b/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/edm/EdmDataServices.java @@ -0,0 +1,85 @@ +/******************************************************************************* + * 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.odata2.client.api.edm; + +/** + * Objects of this class represent the data service. They contain all schemas of the EDM as well as the + * dataServiceVersion + * + */ +public class EdmDataServices { + + private ClientEdm edm; + private String dataServiceVersion; + private String customEdmxVersion; + + + /** + * Sets the Edm for this {@link EdmDataServices} + * @param edm + * @return {@link EdmDataServices} for method chaining + */ + public EdmDataServices setClientEdm(final ClientEdm edm) { + this.edm = edm; + return this; + } + + + /** + * Sets the data service version for this {@link EdmDataServices} + * @param dataServiceVersion + * @return {@link EdmDataServices} for method chaining + */ + public EdmDataServices setDataServiceVersion(final String dataServiceVersion) { + this.dataServiceVersion = dataServiceVersion; + return this; + } + + + /** + * Sets a custom edmx version which is used in the metadata document + * @param customEdmxVersion + * @return {@link ComplexType} for method chaining + */ + public EdmDataServices setCustomEdmxVersion(String customEdmxVersion) { + this.customEdmxVersion = customEdmxVersion; + return this; + } + + /** + * @return <b>String</b> data service version + */ + public String getDataServiceVersion() { + return dataServiceVersion; + } + + /** + * @return <b>String</b> custom edmx version + */ + public String getCustomEdmxVersion() { + return customEdmxVersion; + } + + /** + * @return <b>Edm</b> edm + */ + public ClientEdm getEdm() { + return edm; + } +} http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/4261deb7/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/edm/EdmDocumentation.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/edm/EdmDocumentation.java b/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/edm/EdmDocumentation.java new file mode 100644 index 0000000..1df22d1 --- /dev/null +++ b/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/edm/EdmDocumentation.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * 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.odata2.client.api.edm; + +import java.util.List; + +import org.apache.olingo.odata2.api.edm.EdmAnnotationAttribute; +import org.apache.olingo.odata2.api.edm.EdmAnnotationElement; + +/** + * Objects of this class represent documentation + * + */ +public interface EdmDocumentation { + + /** + * Sets the summary for this {@link EdmDocumentation} + * @param summary + * @return {@link EdmDocumentation} for method chaining + */ + public EdmDocumentation setSummary(final String summary); + + /** + * Sets the long description for this {@link EdmDocumentation} + * @param longDescription + * @return {@link EdmDocumentation} for method chaining + */ + public EdmDocumentation setLongDescription(final String longDescription) ; + /** + * Sets the collection of {@link AnnotationAttribute} for this {@link EdmDocumentation} + * @param annotationAttributes + * @return {@link EdmDocumentation} for method chaining + */ + public EdmDocumentation setAnnotationAttributes(final List<EdmAnnotationAttribute> annotationAttributes) ; + + /** + * Sets the collection of {@link AnnotationElement} for this {@link EdmDocumentation} + * @param annotationElements + * @return {@link EdmDocumentation} for method chaining + */ + public EdmDocumentation setAnnotationElements(final List<EdmAnnotationElement> annotationElements); +} http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/4261deb7/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/edm/EdmSchema.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/edm/EdmSchema.java b/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/edm/EdmSchema.java new file mode 100644 index 0000000..5d3cd1e --- /dev/null +++ b/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/edm/EdmSchema.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * 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.odata2.client.api.edm; + +import java.util.List; +import org.apache.olingo.odata2.api.edm.provider.Using; +import org.apache.olingo.odata2.api.edm.EdmEntityType; +import org.apache.olingo.odata2.api.edm.EdmEntityContainer; +import org.apache.olingo.odata2.api.edm.EdmAssociation; +import org.apache.olingo.odata2.api.edm.EdmComplexType; +import org.apache.olingo.odata2.api.edm.EdmAnnotationAttribute; +import org.apache.olingo.odata2.api.edm.EdmAnnotationElement; + +/** + * Impl Objects of this class represent a client schema + * + */ +public interface EdmSchema { + + /** + * @return <b>String</b> namespace of this {@link EdmSchema} + */ + public String getNamespace() ; + + /** + * @return <b>String</b> alias of this {@link EdmSchema} + */ + public String getAlias() ; + + /** + * @return List<{@link Using}> of this {@link EdmSchema} + */ + public List<EdmUsing> getUsings() ; + + /** + * @return List<{@link EntityType}> of this {@link EdmSchema} + */ + public List<EdmEntityType> getEntityTypes() ; + + + /** + * @return List<{@link ComplexType}> of this {@link EdmSchema} + */ + public List<EdmComplexType> getComplexTypes() ; + + /** + * @return List<{@link Association}> of this {@link EdmSchema} + */ + public List<EdmAssociation> getAssociations() ; + + /** + * @return List<{@link EntityContainer}> of this {@link EdmSchema} + */ + public List<EdmEntityContainer> getEntityContainers(); + + /** + * @return List of {@link AnnotationAttribute} annotation attributes + */ + public List<EdmAnnotationAttribute> getAnnotationAttributes(); + + /** + * @return List of {@link AnnotationElement} annotation elements + */ + public List<EdmAnnotationElement> getAnnotationElements() ; +} http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/4261deb7/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/edm/EdmUsing.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/edm/EdmUsing.java b/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/edm/EdmUsing.java new file mode 100644 index 0000000..df42d5e --- /dev/null +++ b/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/edm/EdmUsing.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * 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.odata2.client.api.edm; + +import java.util.Collection; + +import org.apache.olingo.odata2.api.edm.EdmAnnotationAttribute; +import org.apache.olingo.odata2.api.edm.EdmAnnotationElement; +import org.apache.olingo.odata2.api.edm.provider.AnnotationAttribute; +import org.apache.olingo.odata2.api.edm.provider.AnnotationElement; + +/** + * Impl objects of this class create a client EdmUsing + */ +public interface EdmUsing { + + /** + * @return <b>String</b> namespace + */ + public String getNamespace() ; + + /** + * @return <b>String</b> alias + */ + public String getAlias() ; + + /** + * @return {@link EdmDocumentation} documentation + */ + public EdmDocumentation getDocumentation() ; + + /** + * @return collection of {@link AnnotationAttribute} annotation attributes + */ + public Collection<EdmAnnotationAttribute> getAnnotationAttributes() ; + + /** + * @return collection of {@link AnnotationElement} annotation elements + */ + public Collection<EdmAnnotationElement> getAnnotationElements() ; +} http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/4261deb7/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/ep/ContentTypeBasedDeserializer.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/ep/ContentTypeBasedDeserializer.java b/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/ep/ContentTypeBasedDeserializer.java new file mode 100644 index 0000000..4036cbf --- /dev/null +++ b/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/ep/ContentTypeBasedDeserializer.java @@ -0,0 +1,91 @@ +/******************************************************************************* + * 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.odata2.client.api.ep; + +import java.io.InputStream; +import java.util.List; + +import org.apache.olingo.odata2.api.batch.BatchException; +import org.apache.olingo.odata2.api.batch.BatchResponsePart; +import org.apache.olingo.odata2.api.edm.EdmEntitySet; +import org.apache.olingo.odata2.api.edm.EdmFunctionImport; +import org.apache.olingo.odata2.api.ep.EntityProviderException; +import org.apache.olingo.odata2.api.ep.entry.ODataEntry; +import org.apache.olingo.odata2.api.ep.feed.ODataFeed; +import org.apache.olingo.odata2.api.processor.ODataErrorContext; +import org.apache.olingo.odata2.api.processor.ODataResponse; + +/** + * Interface for all none basic (content type <b>dependent</b>) deserializer methods. + * + * + */ +public interface ContentTypeBasedDeserializer { + + /** + * Returns an ODataFeed + * @param entitySet + * @param content + * @return ODataFeed + * @throws EntityProviderException + */ + ODataFeed readFeed(EdmEntitySet entitySet, EntityStream content) + throws EntityProviderException; + + /** + * Returns an ODataEntry + * @param entitySet + * @param content + * @return ODataEntry + * @throws EntityProviderException + */ + ODataEntry readEntry(EdmEntitySet entitySet, EntityStream content) + throws EntityProviderException; + + /** + * Read (de-serialize) data from error document as {@link InputStream} and provide according + * {@link ODataErrorContext}. + * + * @param errorDocument error document which is read + * @param contentType format of content in the given input stream + * @return read error document + * @throws EntityProviderException if reading of data (de-serialization) fails + */ + ODataErrorContext readErrorDocument(InputStream errorDocument) throws EntityProviderException; + + /** + * Returns an ODataResponse + * @param batchResponseParts + * @return ODataResponse + * @throws BatchException + */ + ODataResponse writeBatchResponse(final List<BatchResponsePart> batchResponseParts) + throws BatchException; + + /** + * Returns an object + * @param functionImport + * @param content + * @return + * @throws EntityProviderException + */ + Object readFunctionImport(final EdmFunctionImport functionImport, + final EntityStream content) throws EntityProviderException; + +} http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/4261deb7/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/ep/ContentTypeBasedSerializer.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/ep/ContentTypeBasedSerializer.java b/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/ep/ContentTypeBasedSerializer.java new file mode 100644 index 0000000..1b4bbee --- /dev/null +++ b/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/ep/ContentTypeBasedSerializer.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * 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.odata2.client.api.ep; + +import java.io.InputStream; +import java.util.List; + +import org.apache.olingo.odata2.api.client.batch.BatchPart; +import org.apache.olingo.odata2.api.edm.EdmEntitySet; +import org.apache.olingo.odata2.api.ep.EntityProviderException; +import org.apache.olingo.odata2.api.processor.ODataResponse; + +/** + * Interface for all none basic (content type <b>dependent</b>) serializer methods. + * + * + */ +public interface ContentTypeBasedSerializer { + + /** + * Returns an OData Response for a given entry + * @param entitySet + * @param data + * @return ODataResponse + * @throws EntityProviderException + */ + ODataResponse writeEntry(EdmEntitySet entitySet, Entity data) + throws EntityProviderException; + + /** + * Returns an OData Response for a given feed + * @param entitySet + * @param data + * @return ODataResponse + * @throws EntityProviderException + */ + ODataResponse writeFeed(EdmEntitySet entitySet, EntityCollection data) + throws EntityProviderException; + + /** + * Reads Batch Request Parts and returns an input Stream + * @param batchParts + * @param boundary + * @return InputStream + */ + InputStream readBatchRequest(final List<BatchPart> batchParts, final String boundary); +} http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/4261deb7/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/ep/DeserializerMetadataProviderInterface.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/ep/DeserializerMetadataProviderInterface.java b/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/ep/DeserializerMetadataProviderInterface.java new file mode 100644 index 0000000..3ddf338 --- /dev/null +++ b/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/ep/DeserializerMetadataProviderInterface.java @@ -0,0 +1,30 @@ +package org.apache.olingo.odata2.client.api.ep; + +import java.io.InputStream; + +import org.apache.olingo.odata2.api.edm.Edm; +import org.apache.olingo.odata2.api.edm.EdmException; +import org.apache.olingo.odata2.api.ep.EntityProviderException; +import org.apache.olingo.odata2.client.api.edm.EdmDataServices; + +/** + * + * Interface for metadata deserializer methods. + * + */ +public interface DeserializerMetadataProviderInterface { + + + /** + * Read (de-serialize) data from metadata <code>inputStream</code> (as {@link InputStream}) and provide Edm as + * {@link Edm} + * + * @param inputStream the given input stream + * @param validate has to be true if metadata should be validated + * @return Edm as {@link Edm} + * @throws EntityProviderException, EdmException if reading of data (de-serialization) fails + */ + EdmDataServices readMetadata(InputStream content, boolean validate) + throws EntityProviderException, EdmException; //NOPMD - suppressed + +} http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/4261deb7/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/ep/DeserializerProperties.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/ep/DeserializerProperties.java b/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/ep/DeserializerProperties.java new file mode 100644 index 0000000..c1ef36f --- /dev/null +++ b/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/ep/DeserializerProperties.java @@ -0,0 +1,170 @@ +/******************************************************************************* + * 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.odata2.client.api.ep; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import org.apache.olingo.odata2.api.ep.EntityProvider; +import org.apache.olingo.odata2.api.ep.EntityProviderException; +import org.apache.olingo.odata2.api.ep.EntityProviderReadProperties; +import org.apache.olingo.odata2.client.api.ep.callback.OnDeserializeInlineContent; + +/** + * <p>The {@link EntityProviderReadProperties} contains all necessary settings + * to read an entity with the {@link EntityProvider}.</p> + * <p>The main settings are + * <ul> + * <li>the <code>type mappings</code></li> + * <li>and <code>validatingFacets</code></li> + * </ul> + * </p> + */ +public class DeserializerProperties{ + /** Callback which is necessary if entity contains inlined navigation properties. */ + private OnDeserializeInlineContent callback; + /** + * typeMappings contains mappings from <code>edm property name</code> to <code>java class</code> which should be used + * for a type mapping during reading of content. If according <code>edm property</code> can not be read + * into given <code>java class</code> an {@link EntityProviderException} is thrown. + * Supported mappings are documented in {@link org.apache.olingo.odata2.api.edm.EdmSimpleType}. + */ + private final Map<String, Object> typeMappings;//entity + + /** whether the constraints expressed in properties' facets are validated */ + private boolean validatingFacets = true;//entity + + private final Map<String, String> validatedPrefix2NamespaceUri;//Collection + + private DeserializerProperties() { + typeMappings = new HashMap<String, Object>(); + validatedPrefix2NamespaceUri = new HashMap<String, String>(); + } + + /** + * + * @return DeserializerPropertiesBuilder + */ + public static DeserializerPropertiesBuilder init() { + return new DeserializerPropertiesBuilder(); + } + + /** + * + * @param properties + * @return DeserializerPropertiesBuilder + */ + public static DeserializerPropertiesBuilder initFrom + (final DeserializerProperties properties) { + return new DeserializerPropertiesBuilder(properties); + } + /** + * + * @return TypeMappings + */ + public Map<String, Object> getTypeMappings() { + return Collections.unmodifiableMap(typeMappings); + } + + public Map<String, String> getValidatedPrefixNamespaceUris() { + return Collections.unmodifiableMap(validatedPrefix2NamespaceUri); + } + + + public boolean isValidatingFacets() { + return validatingFacets; + } + + public OnDeserializeInlineContent getCallback() { + return callback; + } + + /** + * Builder for {@link EntityProviderReadProperties}. + */ + public static class DeserializerPropertiesBuilder { + private final DeserializerProperties properties = new DeserializerProperties(); + + public DeserializerPropertiesBuilder() {} + /** + * + * @param propertiesFrom + */ + public DeserializerPropertiesBuilder(final DeserializerProperties propertiesFrom) { + addValidatedPrefixes(propertiesFrom.validatedPrefix2NamespaceUri); + addTypeMappings(propertiesFrom.typeMappings); + properties.validatingFacets = propertiesFrom.validatingFacets; + properties.callback = propertiesFrom.callback; + } + + /** + * + * @param prefix2NamespaceUri + * @return DeserializerPropertiesBuilder + */ + public DeserializerPropertiesBuilder addValidatedPrefixes + (final Map<String, String> prefix2NamespaceUri) { + if (prefix2NamespaceUri != null) { + properties.validatedPrefix2NamespaceUri.putAll(prefix2NamespaceUri); + } + return this; + } + + /** + * + * @param typeMappings + * @return DeserializerPropertiesBuilder + */ + public DeserializerPropertiesBuilder addTypeMappings(final Map<String, Object> typeMappings) { + if (typeMappings != null) { + properties.typeMappings.putAll(typeMappings); + } + return this; + } + + /** + * + * @param callback + * @return DeserializerPropertiesBuilder + */ + public DeserializerPropertiesBuilder callback(final OnDeserializeInlineContent callback) { + properties.callback = callback; + return this; + } + + /** + * + * @param validatingFacets + * @return DeserializerPropertiesBuilder + */ + public DeserializerPropertiesBuilder isValidatingFacets(final boolean validatingFacets) { + properties.validatingFacets = validatingFacets; + return this; + } + + /** + * + * @return DeserializerProperties + */ + public DeserializerProperties build() { + return properties; + } + } +} http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/4261deb7/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/ep/Entity.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/ep/Entity.java b/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/ep/Entity.java new file mode 100644 index 0000000..a78d871 --- /dev/null +++ b/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/ep/Entity.java @@ -0,0 +1,97 @@ +/* + * 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.odata2.client.api.ep; + +import java.util.HashMap; +import java.util.Map; + +/** + * Data representation for a single entity. + */ +public class Entity { + + private final Map<String, Object> properties = new HashMap<String, Object>(); + private final Map<String, Object> navigations = new HashMap<String, Object>(); + private EntitySerializerProperties writeProperties; + + public Map<String, Object> getNavigations() { + return navigations; + } + + /** + * Add Navigation + * @param link + * @param value + */ + public void addNavigation(final String link, final Object value) { + navigations.put(link, value); + } + + /** + * + * @param link + * @return Object + */ + public Object getNavigation(String link) { + return navigations.get(link); + } + + /** + * Return properties of an entity + * @return Properties + */ + public Map<String, Object> getProperties() { + return properties; + } + + /** + * Add a property to entity + * @param property + * @param value + */ + public void addProperty(final String property, final Object value) { + properties.put(property, value); + } + + /** + * Get Property of an entity + * @param property + * @return Object + */ + public Object getProperty(String property) { + return properties.get(property); + } + + /** + * Returns the Write properties + * @return EntitySerializerProperties + */ + public EntitySerializerProperties getWriteProperties() { + return writeProperties; + } + + /** + * Sets the write properties for an entity + * @param writeProperties + */ + public void setWriteProperties(EntitySerializerProperties writeProperties) { + this.writeProperties = writeProperties; + } + +} http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/4261deb7/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/ep/EntityCollection.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/ep/EntityCollection.java b/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/ep/EntityCollection.java new file mode 100644 index 0000000..6846310 --- /dev/null +++ b/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/ep/EntityCollection.java @@ -0,0 +1,79 @@ +/* + * 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.odata2.client.api.ep; + +import java.util.ArrayList; +import java.util.List; + +/** + * Data representation for a single entity. + */ +public class EntityCollection { + + private final List<Entity> entities = new ArrayList<Entity>(); + private EntityCollectionSerializerProperties collectionProperties; + private EntitySerializerProperties globalEntityProperties; + + /** + * @return the globalWriteProperties + */ + public EntitySerializerProperties getGlobalEntityProperties() { + return globalEntityProperties; + } + + /** + * @param globalWriteProperties the globalWriteProperties to set + */ + public void setGlobalEntityProperties(EntitySerializerProperties globalEntityProperties) { + this.globalEntityProperties = globalEntityProperties; + } + + /** + * + * @return List of Entities + */ + public List<Entity> getEntities() { + return entities; + } + + /** + * Add an Entity to collection of entities + * @param entity + */ + public void addEntity(Entity entity) { + entities.add(entity); + } + + /** + * Return collection write properties + * @return EntityCollectionSerializerProperties + */ + public EntityCollectionSerializerProperties getCollectionProperties() { + return collectionProperties; + } + + /** + * Set collection write properties + * @param collectionProperties + */ + public void setCollectionProperties(EntityCollectionSerializerProperties collectionProperties) { + this.collectionProperties = collectionProperties; + } + +} http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/4261deb7/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/ep/EntityCollectionSerializerProperties.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/ep/EntityCollectionSerializerProperties.java b/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/ep/EntityCollectionSerializerProperties.java new file mode 100644 index 0000000..cf112a6 --- /dev/null +++ b/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/ep/EntityCollectionSerializerProperties.java @@ -0,0 +1,119 @@ +/******************************************************************************* + * 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.odata2.client.api.ep; + +import java.net.URI; + +/** + * {@link EntityCollectionSerializerProperties} contains all additional properties which are necessary to <b>write + * (serialize)</b> an {@link org.apache.olingo.odata2.api.ep.entry.ODataEntry} into an specific format (e.g. + * <code>XML</code> or <code>JSON</code> or ...). + */ +public class EntityCollectionSerializerProperties { + + private URI serviceRoot; + private URI selfLink; + + private EntityCollectionSerializerProperties() {} + + /** + * Gets the self link from an application. May be null. + * @return the self link + */ + public final URI getSelfLink() { + return selfLink; + } + + /** + * Gets the service root. + * @return the service root + */ + public final URI getServiceRoot() { + return serviceRoot; + } + + /** + * + * @param serviceRoot + * @return EntityCollectionPropertiesBuilder + */ + public static EntityCollectionPropertiesBuilder serviceRoot(final URI serviceRoot) { + return new EntityCollectionPropertiesBuilder().serviceRoot(serviceRoot); + } + + /** + * This class builds the Entity collection properties + * + */ + public static class EntityCollectionPropertiesBuilder { + private final EntityCollectionSerializerProperties properties = + new EntityCollectionSerializerProperties(); + + /** + * @param serviceRoot + */ + public final EntityCollectionPropertiesBuilder serviceRoot(final URI serviceRoot) { + properties.serviceRoot = serviceRoot; + return this; + } + + + /** + * Build properties object. + * @return assembled properties object + */ + public final EntityCollectionSerializerProperties build() { + return properties; + } + + /** + * + * @param selfLink + * @return EntityCollectionPropertiesBuilder + */ + public EntityCollectionPropertiesBuilder selfLink(final URI selfLink) { + properties.selfLink = selfLink; + return this; + } + + /** + * + * @param properties + * @return EntityCollectionPropertiesBuilder + */ + public EntityCollectionPropertiesBuilder fromProperties + (final EntityCollectionSerializerProperties properties) { + this.properties.selfLink = properties.getSelfLink(); + return this; + } + + } + + /** + * + * @param properties + * @return EntityCollectionPropertiesBuilder + */ + public static EntityCollectionPropertiesBuilder fromProperties + (final EntityCollectionSerializerProperties properties) { + final EntityCollectionPropertiesBuilder builder = + EntityCollectionSerializerProperties.serviceRoot(properties.getServiceRoot()); + return builder.fromProperties(properties); + } +} http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/4261deb7/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/ep/EntitySerializerProperties.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/ep/EntitySerializerProperties.java b/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/ep/EntitySerializerProperties.java new file mode 100644 index 0000000..c285290 --- /dev/null +++ b/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/ep/EntitySerializerProperties.java @@ -0,0 +1,159 @@ +/******************************************************************************* + * 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.odata2.client.api.ep; + +import java.net.URI; + +/** + * {@link EntitySerializerProperties} contains all additional properties which are necessary to <b>write + * (serialize)</b> an {@link org.apache.olingo.odata2.api.ep.entry.ODataEntry} into an specific format (e.g. + * <code>XML</code> or <code>JSON</code> or ...). + */ +public class EntitySerializerProperties { + + private URI serviceRoot; + private boolean includeMetadata = false; + private boolean validatingFacets = true; + private boolean isKeyAutoGenerated = false; + + private EntitySerializerProperties() {} + + /** + * Set true or false to include metadata + * @return boolean + */ + public boolean isIncludeMetadata() { + return includeMetadata; + } + + /** + * Set true or false for auto key generation + * @return boolean + */ + public final boolean isKeyAutoGenerated() { + return isKeyAutoGenerated; + } + + /** + * Gets the service root. + * @return the service root + */ + public final URI getServiceRoot() { + return serviceRoot; + } + + /** + * + * @param serviceRoot + * @return EntitySerializerPropertiesBuilder + */ + public static EntitySerializerPropertiesBuilder serviceRoot(final URI serviceRoot) { + return new EntitySerializerPropertiesBuilder().serviceRoot(serviceRoot); + } + + /** + * + * @return boolean + */ + public boolean isValidatingFacets() { + return validatingFacets; + } + + /** + * This class builds the Entity Serializer Properties + * + */ + public static class EntitySerializerPropertiesBuilder { + private final EntitySerializerProperties properties = new EntitySerializerProperties(); + + /** + * + * @param includeMetadata + * @return EntitySerializerPropertiesBuilder + */ + public EntitySerializerPropertiesBuilder + includeMetadata(final boolean includeMetadata) { + properties.includeMetadata = includeMetadata; + return this; + } + + + + /** + * @param serviceRoot + */ + public final EntitySerializerPropertiesBuilder serviceRoot(final URI serviceRoot) { + properties.serviceRoot = serviceRoot; + return this; + } + + /** + * @param setting if payload has auto generated keys + */ + public final EntitySerializerPropertiesBuilder isKeyAutoGenerated + (boolean isKeyAutoGenerated) { + properties.isKeyAutoGenerated = isKeyAutoGenerated; + return this; + } + + /** + * Build properties object. + * @return assembled properties object + */ + public final EntitySerializerProperties build() { + return properties; + } + + /** + * + * @param validatingFacets + * @return EntitySerializerPropertiesBuilder + */ + public EntitySerializerPropertiesBuilder validatingFacets(final boolean validatingFacets) { + properties.validatingFacets = validatingFacets; + return this; + } + + /** + * + * @param properties + * @return EntitySerializerPropertiesBuilder + */ + public EntitySerializerPropertiesBuilder fromProperties + (final EntitySerializerProperties properties) { + this.properties.validatingFacets = properties.validatingFacets; + this.properties.includeMetadata = properties.includeMetadata; + this.properties.isKeyAutoGenerated = properties.isKeyAutoGenerated; + return this; + } + + } + + /** + * + * @param properties + * @return EntitySerializerPropertiesBuilder + */ + public static EntitySerializerPropertiesBuilder fromProperties + (final EntitySerializerProperties properties) { + final EntitySerializerPropertiesBuilder builder = + EntitySerializerProperties.serviceRoot(properties.getServiceRoot()); + return builder.fromProperties(properties); + } +} http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/4261deb7/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/ep/EntityStream.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/ep/EntityStream.java b/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/ep/EntityStream.java new file mode 100644 index 0000000..21cc6d9 --- /dev/null +++ b/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/ep/EntityStream.java @@ -0,0 +1,55 @@ +/* + * 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.odata2.client.api.ep; + +import java.io.InputStream; + +/** + * Data representation for a single entity. + */ +public class EntityStream { + + private InputStream content ; + private DeserializerProperties readProperties; + public InputStream getContent() { + return content; + } + /** + * Set the content + * @param content + */ + public void setContent(InputStream content) { + this.content = content; + } + /** + * Get Read properties + * @return DeserializerProperties + */ + public DeserializerProperties getReadProperties() { + return readProperties; + } + /** + * Set read properties + * @param readProperties + */ + public void setReadProperties(DeserializerProperties readProperties) { + this.readProperties = readProperties; + } + +} http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/4261deb7/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/ep/callback/OnDeserializeInlineContent.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/ep/callback/OnDeserializeInlineContent.java b/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/ep/callback/OnDeserializeInlineContent.java new file mode 100644 index 0000000..0696848 --- /dev/null +++ b/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/ep/callback/OnDeserializeInlineContent.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * 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.odata2.client.api.ep.callback; + +import org.apache.olingo.odata2.api.edm.EdmNavigationProperty; +import org.apache.olingo.odata2.api.exception.ODataApplicationException; +import org.apache.olingo.odata2.client.api.ep.DeserializerProperties; + +/** + * <p> + * Callback interface for the deep insert read calls (read of <code><m:inline></code> content). + * Typically the {@link #receiveReadProperties(EntityProviderReadProperties, EdmNavigationProperty)} method is called + * when an inline navigation property is found and will be read. + * </p> + * + */ +public interface OnDeserializeInlineContent { + + /** + * Receive (request) to be used {@link EntityProviderReadProperties} to read the found inline navigation property + * (<code>><m:inline>...</m:inline></code>). + * + * @param readProperties read properties which are used to read enclosing parent entity + * @param navigationProperty emd navigation property information of found inline navigation property + * @return read properties which are used to read (de-serialize) found inline navigation property + * @throws ODataApplicationException + */ + DeserializerProperties receiveReadProperties(DeserializerProperties readProperties, + EdmNavigationProperty navigationProperty) throws ODataApplicationException; + +} http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/4261deb7/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/uri/EdmURIBuilder.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/uri/EdmURIBuilder.java b/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/uri/EdmURIBuilder.java new file mode 100644 index 0000000..22278bd --- /dev/null +++ b/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/uri/EdmURIBuilder.java @@ -0,0 +1,184 @@ +package org.apache.olingo.odata2.client.api.uri; + +import java.net.URI; +import java.util.List; +import java.util.Map; + +import org.apache.olingo.odata2.api.edm.EdmEntitySet; +import org.apache.olingo.odata2.api.edm.EdmFunctionImport; +import org.apache.olingo.odata2.api.edm.EdmNavigationProperty; +import org.apache.olingo.odata2.api.edm.EdmParameter; +import org.apache.olingo.odata2.api.edm.EdmProperty; + +/** + * + * This is an Edm Uri Builder + * + */ +public interface EdmURIBuilder { + /** + * Appends EntitySet segment to the URI. + * + * @param entitySet Edm entity set. + * @return current EdmURIBuilder instance + */ + EdmURIBuilder appendEntitySetSegment(EdmEntitySet entitySet); + + /** + * Appends navigation segment to the URI. + * + * @param property navigation property. + * @return current EdmURIBuilder instance + */ + EdmURIBuilder appendNavigationSegment(EdmNavigationProperty property); + + /** + * Appends key segment to the URI. + * + * @param property edm property + * @param value key value + * @return current EdmURIBuilder instance + */ + EdmURIBuilder appendKeySegment(EdmProperty property, Object value); + + /** + * Appends key segment to the URI, for multiple keys. + * + * @param segmentValues segment values. + * @return current EdmURIBuilder instance + */ + EdmURIBuilder appendKeySegment(Map<EdmProperty, Object> segmentValues); + + /** + * Appends property segment to the URI. + * + * @param property edmProperty + * @param segmentValue segment value. + * @return current EdmURIBuilder instance + */ + EdmURIBuilder appendPropertySegment(EdmProperty property, String segmentValue); + + /** + * Adds expand query option. + * + * @param expandItems items to be expanded in-line + * @return current EdmURIBuilder instance + * @see QueryOption#EXPAND + */ + EdmURIBuilder expand(String... expandItems); + + /** + * Adds select query option. + * + * @param selectItems select items + * @return current EdmURIBuilder instance + * @see QueryOption#SELECT + */ + EdmURIBuilder select(String... selectItems); + + /** + * Adds orderby query option. + * + * @param property property string. + * @return current EdmURIBuilder instance + * @see QueryOption#ORDERBY + */ + EdmURIBuilder orderBy(String property); + + /** + * Appends count segment to the URI. + * @return current EdmURIBuilder instance + */ + EdmURIBuilder appendCountSegment(); + + /** + * Appends metadata segment to the URI. + * + * @return current EdmURIBuilder instance + */ + EdmURIBuilder appendMetadataSegment(); + + /** + * Adds format query option. + * + * @param format media type acceptable in a response. + * @return current EdmURIBuilder instance + * @see QueryOption#FORMAT + */ + EdmURIBuilder format(String format); + + /** + * Appends value segment to the URI. + * + * @return current EdmURIBuilder instance + */ + EdmURIBuilder appendValueSegment(); + + /** + * Adds the specified query option to the URI. + * <br /> + * Concatenates value if the specified query option already exists. + * + * @param option query option. + * @param value query option value. + * @return current EdmURIBuilder instance + */ + EdmURIBuilder addQueryOption(QueryOption option, String value); + + /** + * Adds filter query option. + * + * @param filter filter string. + * @return current EdmURIBuilder instance + * @see QueryOption#FILTER + */ + EdmURIBuilder filter(String filter); + + /** + * Adds top query option. + * + * @param top maximum number of entities to be returned. + * @return current EdmURIBuilder instance + * @see QueryOption#TOP + */ + EdmURIBuilder top(int top); + + /** + * Adds skip query option. + * + * @param skip number of entities to be skipped into the response. + * @return current EdmURIBuilder instance + * @see QueryOption#SKIP + */ + EdmURIBuilder skip(int skip); + + /** + * Adds custom query option + * @param paramName parameter name + * @param paramValue parameter value + * @return current EdmURIBuilder instance + */ + EdmURIBuilder addCustomQueryOption(String paramName, Object paramValue); + + /** + * Appends Function import to the uri + * @param functionImport + * @return current EdmURIBuilder instance + */ + EdmURIBuilder appendFunctionImportSegment(EdmFunctionImport functionImport); + + /** + * Appends function import parameters + * @param functionImportParams + * @return current EdmURIBuilder instance + */ + EdmURIBuilder appendFunctionImportParameters(Map<EdmParameter, Object> functionImportParams); + + /** + * Build OData URI. + * + * @return OData URI. + */ + URI build(); + +} http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/4261deb7/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/uri/QueryOption.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/uri/QueryOption.java b/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/uri/QueryOption.java new file mode 100644 index 0000000..36b4bf9 --- /dev/null +++ b/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/uri/QueryOption.java @@ -0,0 +1,70 @@ +package org.apache.olingo.odata2.client.api.uri; + +/** + * This is a list of query options + * + */ +public enum QueryOption { + + /** + * The $count system query option allows clients to request a count of the matching resources included with the + * resources in the response. The $count query option has a Boolean value of true or false. + */ + COUNT("$count"), + /** + * This option indicates entities associated with the EntityType instance or EntitySet, identified by the resource + * path section of the URI, and MUST be represented inline in the data service's response. + */ + EXPAND("$expand"), + /** + * This option specifies the media type acceptable in a response. If present, this value SHOULD take precedence over + * value(s) specified in an Accept request header. + */ + FORMAT("$format"), + /** + * This option is used to specify that a subset of the properties of the entities identified by the path of the + * request URI and $expand query option SHOULD be returned in the response from the data service. + */ + SELECT("$select"), + /** + * This option specifies the sort properties and sort direction (ascending or descending) that the data service MUST + * use to order the entities in the EntitySet, identified by the resource path section of the URI. + */ + ORDERBY("$orderby"), + /** + * This option specifies a positive integer N that is the maximum number of entities in the EntitySet, identified by + * the resource path section of the URI, that the data service MUST return. + */ + TOP("$top"), + /** + * This option specifies a positive integer N that represents the number of entities, counted from the first entity in + * the EntitySet and ordered as specified by the $orderby option, that the data service should skip when returning the + * entities in the EntitySet, which is identified by the resource path section of the URI. The data service SHOULD + * return all subsequent entities, starting from the one in position N+1. + */ + SKIP("$skip"), + /** + * The value of a $skiptoken query option is an opaque token which identifies an index into the collection + * of entities identified by the URI containing the $skiptoken parameter. + */ + SKIPTOKEN("$skiptoken"), + /** + * This option specifies a predicate used to filter the elements from the EntitySet identified by the resource path + * section of the URI. + */ + FILTER("$filter"); + + private final String value; + + private QueryOption() { + this.value = ""; + } + + private QueryOption(final String value) { + this.value = value; + } + + public String getValue() { + return value; + } +} http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/4261deb7/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/uri/SegmentType.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/uri/SegmentType.java b/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/uri/SegmentType.java new file mode 100644 index 0000000..1d50e08 --- /dev/null +++ b/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/uri/SegmentType.java @@ -0,0 +1,76 @@ +package org.apache.olingo.odata2.client.api.uri; + +/** + * URI Segment types. + */ +public enum SegmentType { + + /** + * Initial will be the builder state to begin with a service root url + */ + INITIAL, + /** + * When we append entity set state is changed to ENTITYSET + */ + ENTITYSET, + /** + * + */ + ENTITY, + /** + * When we append simple property state is changed to SIMPLEPROPERTY + */ + SIMPLEPROPERTY, + /** + * When there is a key in segment + */ + KEY, + /** + * When we append simple complex state is changed to COMPLEXPROPERTY + */ + COMPLEXPROPERTY, + /** + * When there is navigation to many then the state is NAVIGATION_TO_MANY + */ + NAVIGATION_TO_MANY, + /** + * When there is navigation to many with a key then the state is + * NAVIGATION_TO_MANY_WITH_KEY + */ + NAVIGATION_TO_MANY_WITH_KEY, + /** + * When there is navigation to one then the state is NAVIGATION_TO_ONE + */ + NAVIGATION_TO_ONE, + /** + * When there is count query option + */ + COUNT("$count"), + /** + * When there is a value query option + */ + VALUE("$value"), + /** + * When there is a metadata uri segment + */ + METADATA("$metadata"), + PROPERTY, + NAVIGATION, + FUNCTIONIMPORT, + FUNCTIONIMPORT_WITH_KEY, + FUNCTIONIMPORT_MANY; + + private final String value; + + private SegmentType() { + this.value = ""; + } + + private SegmentType(final String value) { + this.value = value; + } + + public String getValue() { + return value; + } +} http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/4261deb7/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/uri/URIBuilder.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/uri/URIBuilder.java b/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/uri/URIBuilder.java new file mode 100644 index 0000000..7ecd908 --- /dev/null +++ b/odata2-lib/odata-client-api/src/main/java/org/apache/olingo/odata2/client/api/uri/URIBuilder.java @@ -0,0 +1,174 @@ +package org.apache.olingo.odata2.client.api.uri; + +import java.net.URI; +import java.util.Map; + +/** + * This is a URIBuilder class + * + */ +public interface URIBuilder { + + /** + * Appends EntitySet segment to the URI. + * + * @param entitySet String entity set. + * @return current URIBuilder instance + */ + URIBuilder appendEntitySetSegment(String entitySet); + + /** + * Appends navigation segment to the URI. + * + * @param navigationProperty String navigation property. + * @return current URIBuilder instance + */ + URIBuilder appendNavigationSegment(String navigationProperty); + + /** + * Appends key segment to the URI. + * + * @param val segment value. + * @return current URIBuilder instance + */ + URIBuilder appendKeySegment(Object val); + + /** + * Appends key segment to the URI, for multiple keys. + * + * @param segmentValues segment values. + * @return current URIBuilder instance + */ + URIBuilder appendKeySegment(Map<String, Object> segmentValues); + + /** + * Appends property segment to the URI. + * + * @param segmentValue String segment value. + * @return current URIBuilder instance + */ + URIBuilder appendPropertySegment(String segmentValue); + + /** + * Adds expand query option. + * + * @param expandItems items to be expanded in-line + * @return current URIBuilder instance + * @see QueryOption#EXPAND + */ + URIBuilder expand(String... expandItems); + + /** + * Adds select query option. + * + * @param selectItems select items + * @return current URIBuilder instance + * @see QueryOption#SELECT + */ + URIBuilder select(String... selectItems); + + /** + * Adds orderby query option. + * + * @param order order string. + * @return current URIBuilder instance + * @see QueryOption#ORDERBY + */ + URIBuilder orderBy(String order); + + /** + * Appends count segment to the URI. + * @return current URIBuilder instance + */ + URIBuilder appendCountSegment(); + + /** + * Appends metadata segment to the URI. + * + * @return current URIBuilder instance + */ + URIBuilder appendMetadataSegment(); + + /** + * Adds format query option. + * + * @param format media type acceptable in a response. + * @return current URIBuilder instance + * @see QueryOption#FORMAT + */ + URIBuilder format(String format); + + /** + * Appends value segment to the URI. + * + * @return current URIBuilder instance + */ + URIBuilder appendValueSegment(); + + /** + * Adds the specified query option to the URI. + * <br /> + * Concatenates value if the specified query option already exists. + * + * @param option query option. + * @param value query option value. + * @return current URIBuilder instance + */ + URIBuilder addQueryOption(QueryOption option, String value); + + /** + * Adds filter query option. + * + * @param filter filter string. + * @return current URIBuilder instance + * @see QueryOption#FILTER + */ + URIBuilder filter(String filter); + + /** + * Adds top query option. + * + * @param top maximum number of entities to be returned. + * @return current URIBuilder instance + * @see QueryOption#TOP + */ + URIBuilder top(int top); + + /** + * Adds skip query option. + * + * @param skip number of entities to be skipped into the response. + * @return current URIBuilder instance + * @see QueryOption#SKIP + */ + URIBuilder skip(int skip); + + /** + * Adds custom query option + * @param paramName parameter name + * @param paramValue parameter value + * @return current URIBuilder instance + */ + URIBuilder addCustomQueryOption(String paramName, Object paramValue); + + /** + * Appends function import to the uri + * @param functionImport + * @return current URIBuilder instance + */ + URIBuilder appendFunctionImportSegment(String functionImport); + + /** + * Appends function import parameters to the uri + * @param functionImportParams + * @return current URIBuilder instance + */ + URIBuilder appendFunctionImportParameters(Map<String, Object> functionImportParams); + + /** + * Build OData URI. + * + * @return OData URI. + */ + URI build(); +}
