http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/109c33ba/lib/client-api/src/main/java/org/apache/olingo/client/api/uri/SearchFactory.java ---------------------------------------------------------------------- diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/uri/SearchFactory.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/uri/SearchFactory.java new file mode 100644 index 0000000..aefd1f4 --- /dev/null +++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/uri/SearchFactory.java @@ -0,0 +1,31 @@ +/* + * 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.uri; + +public interface SearchFactory { + + URISearch literal(String value); + + URISearch and(URISearch left, URISearch right); + + URISearch or(URISearch left, URISearch right); + + URISearch not(URISearch filter); + +}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/109c33ba/lib/client-api/src/main/java/org/apache/olingo/client/api/uri/URIBuilder.java ---------------------------------------------------------------------- diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/uri/URIBuilder.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/uri/URIBuilder.java new file mode 100644 index 0000000..efedbfe --- /dev/null +++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/uri/URIBuilder.java @@ -0,0 +1,143 @@ +/* + * 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.uri; + +import java.util.Map; + +import org.apache.commons.lang3.tuple.Pair; +import org.apache.olingo.commons.api.edm.EdmEnumType; + +public interface URIBuilder extends CommonURIBuilder<URIBuilder> { + + /** + * Appends enum key segment to the URI. + * + * @param enumType enum type + * @param memberName enum member name + * @return current URIBuilder instance + */ + URIBuilder appendKeySegment(EdmEnumType enumType, String memberName); + + /** + * Appends key segment to the URI, for multiple keys. + * + * @param enumValues enum segment values. + * @param segmentValues segment values. + * @return current URIBuilder instance + */ + URIBuilder appendKeySegment(Map<String, Pair<EdmEnumType, String>> enumValues, Map<String, Object> segmentValues); + + /** + * Appends Singleton segment to the URI. + * + * @param segmentValue segment value. + * @return current URIBuilder instance + */ + URIBuilder appendSingletonSegment(String segmentValue); + + /** + * Appends entity-id segment to the URI. + * + * @param segmentValue segment value + * @return current URIBuilder instance + */ + URIBuilder appendEntityIdSegment(String segmentValue); + + /** + * Appends ref segment to the URI. + * + * @return current URIBuilder instance + */ + URIBuilder appendRefSegment(); + + /** + * Appends cross join segment to the URI. + * + * @param segmentValues segment values. + * @return current URIBuilder instance + */ + URIBuilder appendCrossjoinSegment(String... segmentValues); + + /** + * Appends all segment to the URI. + * + * @return current URIBuilder instance + */ + URIBuilder appendAllSegment(); + + /** + * Adds id query option. + * + * @param idValue opaque token. + * @return current URIBuilder instance + * @see org.apache.olingo.client.api.uri.QueryOption#ID + */ + URIBuilder id(String idValue); + + /** + * Appends count query option. + * + * @param value true or false + * @return current URIBuilder instance + * @see org.apache.olingo.client.api.uri.QueryOption#COUNT + */ + URIBuilder count(boolean value); + + /** + * Appends search query option. + * + * @param search search expression + * @return current URIBuilder instance + * @see org.apache.olingo.client.api.uri.QueryOption#SEARCH + */ + URIBuilder search(URISearch search); + + /** + * Appends search query option. + * + * @param expression search expression + * @return current URIBuilder instance + * @see org.apache.olingo.client.api.uri.QueryOption#SEARCH + */ + URIBuilder search(String expression); + + /** + * The set of expanded entities can be refined through the application of expand options, expressed as a + * semicolon-separated list of system query options, enclosed in parentheses, see [OData-URL]. + * + * @param expandItem item to be expanded. + * @param options System query options. Allowed query options are: $filter, $select, $orderby, $skip, $top, $count, + * $search, $expand, and $levels. + * @return current URIBuilder instance. + * @see org.apache.olingo.client.api.uri.QueryOption#EXPAND + */ + URIBuilder expandWithOptions(String expandItem, Map<QueryOption, Object> options); + + /** + * Properties of related entities can be specified by including the $select query option within the $expand. + * <br /> + * <tt>http://host/service/Products?$expand=Category($select=Name)</tt> + * @param expandItem related entity name. + * @param selectItems properties to be selected. + * @return current URIBuilder instance. + * @see org.apache.olingo.client.api.uri.QueryOption#EXPAND + * @see org.apache.olingo.client.api.uri.QueryOption#SELECT + */ + URIBuilder expandWithSelect(String expandItem, String... selectItems); +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/109c33ba/lib/client-api/src/main/java/org/apache/olingo/client/api/uri/URISearch.java ---------------------------------------------------------------------- diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/uri/URISearch.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/uri/URISearch.java new file mode 100644 index 0000000..0d6af3e --- /dev/null +++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/uri/URISearch.java @@ -0,0 +1,32 @@ +/* + * 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.uri; + +/** + * Interface for <tt>$search</tt>; obtain instances via <tt>SearchFactory</tt>. + * + * @see SearchFactory + */ +public interface URISearch { + + /** + * @return String representation of this search. + */ + String build(); +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/109c33ba/lib/client-api/src/main/java/org/apache/olingo/client/api/uri/v4/FilterArgFactory.java ---------------------------------------------------------------------- diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/uri/v4/FilterArgFactory.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/uri/v4/FilterArgFactory.java deleted file mode 100644 index 456507c..0000000 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/uri/v4/FilterArgFactory.java +++ /dev/null @@ -1,59 +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.uri.v4; - -import org.apache.olingo.client.api.uri.CommonFilterArgFactory; -import org.apache.olingo.client.api.uri.FilterArg; -import org.apache.olingo.client.api.uri.URIFilter; - -public interface FilterArgFactory extends CommonFilterArgFactory { - - FilterArg contains(FilterArg first, FilterArg second); - - FilterArg fractionalseconds(FilterArg param); - - FilterArg date(FilterArg param); - - FilterArg time(FilterArg param); - - FilterArg totaloffsetminutes(FilterArg param); - - FilterArg now(); - - FilterArg mindatetime(); - - FilterArg maxdatetime(); - - FilterArg totalseconds(FilterArg param); - - FilterArg cast(FilterArg type); - - FilterArg cast(FilterArg expression, FilterArg type); - - FilterArg geoDistance(FilterArg first, FilterArg second); - - FilterArg geoIntersects(FilterArg first, FilterArg second); - - FilterArg geoLength(FilterArg first, FilterArg second); - - FilterArg any(FilterArg collection, URIFilter expression); - - FilterArg all(FilterArg collection, URIFilter expression); - -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/109c33ba/lib/client-api/src/main/java/org/apache/olingo/client/api/uri/v4/FilterFactory.java ---------------------------------------------------------------------- diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/uri/v4/FilterFactory.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/uri/v4/FilterFactory.java deleted file mode 100644 index c66b0c5..0000000 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/uri/v4/FilterFactory.java +++ /dev/null @@ -1,35 +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.uri.v4; - -import org.apache.olingo.client.api.uri.CommonFilterFactory; -import org.apache.olingo.client.api.uri.FilterArg; -import org.apache.olingo.client.api.uri.URIFilter; -import org.apache.olingo.commons.api.edm.EdmEnumType; - -public interface FilterFactory extends CommonFilterFactory { - - @Override - FilterArgFactory getArgFactory(); - - URIFilter has(String key, EdmEnumType enumType, String memberName); - - URIFilter has(FilterArg left, EdmEnumType enumType, String memberName); - -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/109c33ba/lib/client-api/src/main/java/org/apache/olingo/client/api/uri/v4/SearchFactory.java ---------------------------------------------------------------------- diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/uri/v4/SearchFactory.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/uri/v4/SearchFactory.java deleted file mode 100644 index 61689e1..0000000 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/uri/v4/SearchFactory.java +++ /dev/null @@ -1,31 +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.uri.v4; - -public interface SearchFactory { - - URISearch literal(String value); - - URISearch and(URISearch left, URISearch right); - - URISearch or(URISearch left, URISearch right); - - URISearch not(URISearch filter); - -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/109c33ba/lib/client-api/src/main/java/org/apache/olingo/client/api/uri/v4/URIBuilder.java ---------------------------------------------------------------------- diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/uri/v4/URIBuilder.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/uri/v4/URIBuilder.java deleted file mode 100644 index 0271f44..0000000 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/uri/v4/URIBuilder.java +++ /dev/null @@ -1,145 +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.uri.v4; - -import java.util.Map; - -import org.apache.commons.lang3.tuple.Pair; -import org.apache.olingo.client.api.uri.CommonURIBuilder; -import org.apache.olingo.client.api.uri.QueryOption; -import org.apache.olingo.commons.api.edm.EdmEnumType; - -public interface URIBuilder extends CommonURIBuilder<URIBuilder> { - - /** - * Appends enum key segment to the URI. - * - * @param enumType enum type - * @param memberName enum member name - * @return current URIBuilder instance - */ - URIBuilder appendKeySegment(EdmEnumType enumType, String memberName); - - /** - * Appends key segment to the URI, for multiple keys. - * - * @param enumValues enum segment values. - * @param segmentValues segment values. - * @return current URIBuilder instance - */ - URIBuilder appendKeySegment(Map<String, Pair<EdmEnumType, String>> enumValues, Map<String, Object> segmentValues); - - /** - * Appends Singleton segment to the URI. - * - * @param segmentValue segment value. - * @return current URIBuilder instance - */ - URIBuilder appendSingletonSegment(String segmentValue); - - /** - * Appends entity-id segment to the URI. - * - * @param segmentValue segment value - * @return current URIBuilder instance - */ - URIBuilder appendEntityIdSegment(String segmentValue); - - /** - * Appends ref segment to the URI. - * - * @return current URIBuilder instance - */ - URIBuilder appendRefSegment(); - - /** - * Appends cross join segment to the URI. - * - * @param segmentValues segment values. - * @return current URIBuilder instance - */ - URIBuilder appendCrossjoinSegment(String... segmentValues); - - /** - * Appends all segment to the URI. - * - * @return current URIBuilder instance - */ - URIBuilder appendAllSegment(); - - /** - * Adds id query option. - * - * @param idValue opaque token. - * @return current URIBuilder instance - * @see org.apache.olingo.client.api.uri.QueryOption#ID - */ - URIBuilder id(String idValue); - - /** - * Appends count query option. - * - * @param value true or false - * @return current URIBuilder instance - * @see org.apache.olingo.client.api.uri.QueryOption#COUNT - */ - URIBuilder count(boolean value); - - /** - * Appends search query option. - * - * @param search search expression - * @return current URIBuilder instance - * @see org.apache.olingo.client.api.uri.QueryOption#SEARCH - */ - URIBuilder search(URISearch search); - - /** - * Appends search query option. - * - * @param expression search expression - * @return current URIBuilder instance - * @see org.apache.olingo.client.api.uri.QueryOption#SEARCH - */ - URIBuilder search(String expression); - - /** - * The set of expanded entities can be refined through the application of expand options, expressed as a - * semicolon-separated list of system query options, enclosed in parentheses, see [OData-URL]. - * - * @param expandItem item to be expanded. - * @param options System query options. Allowed query options are: $filter, $select, $orderby, $skip, $top, $count, - * $search, $expand, and $levels. - * @return current URIBuilder instance. - * @see org.apache.olingo.client.api.uri.QueryOption#EXPAND - */ - URIBuilder expandWithOptions(String expandItem, Map<QueryOption, Object> options); - - /** - * Properties of related entities can be specified by including the $select query option within the $expand. - * <br /> - * <tt>http://host/service/Products?$expand=Category($select=Name)</tt> - * @param expandItem related entity name. - * @param selectItems properties to be selected. - * @return current URIBuilder instance. - * @see org.apache.olingo.client.api.uri.QueryOption#EXPAND - * @see org.apache.olingo.client.api.uri.QueryOption#SELECT - */ - URIBuilder expandWithSelect(String expandItem, String... selectItems); -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/109c33ba/lib/client-api/src/main/java/org/apache/olingo/client/api/uri/v4/URISearch.java ---------------------------------------------------------------------- diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/uri/v4/URISearch.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/uri/v4/URISearch.java deleted file mode 100644 index 2249498..0000000 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/uri/v4/URISearch.java +++ /dev/null @@ -1,32 +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.uri.v4; - -/** - * Interface for <tt>$search</tt>; obtain instances via <tt>SearchFactory</tt>. - * - * @see SearchFactory - */ -public interface URISearch { - - /** - * @return String representation of this search. - */ - String build(); -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/109c33ba/lib/client-api/src/main/java/org/apache/olingo/client/api/v4/EdmEnabledODataClient.java ---------------------------------------------------------------------- diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/v4/EdmEnabledODataClient.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/v4/EdmEnabledODataClient.java deleted file mode 100644 index 2e9e8c2..0000000 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/v4/EdmEnabledODataClient.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.api.v4; - -import org.apache.olingo.client.api.CommonEdmEnabledODataClient; -import org.apache.olingo.client.api.communication.request.cud.v4.UpdateType; -import org.apache.olingo.client.api.communication.request.invoke.EdmEnabledInvokeRequestFactory; -import org.apache.olingo.client.api.uri.v4.URIBuilder; - -public interface EdmEnabledODataClient extends CommonEdmEnabledODataClient<UpdateType>, ODataClient { - - @Override - URIBuilder newURIBuilder(); - - @Override - EdmEnabledInvokeRequestFactory getInvokeRequestFactory(); -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/109c33ba/lib/client-api/src/main/java/org/apache/olingo/client/api/v4/ODataClient.java ---------------------------------------------------------------------- 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 deleted file mode 100644 index eff5ad9..0000000 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/v4/ODataClient.java +++ /dev/null @@ -1,68 +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.v4; - -import org.apache.olingo.client.api.CommonODataClient; -import org.apache.olingo.client.api.communication.request.batch.v4.BatchRequestFactory; -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.v4.AsyncRequestFactory; -import org.apache.olingo.client.api.serialization.v4.ODataBinder; -import org.apache.olingo.client.api.serialization.v4.ODataDeserializer; -import org.apache.olingo.client.api.serialization.v4.ODataReader; -import org.apache.olingo.client.api.uri.v4.FilterFactory; -import org.apache.olingo.client.api.uri.v4.SearchFactory; -import org.apache.olingo.client.api.uri.v4.URIBuilder; -import org.apache.olingo.commons.api.domain.v4.ODataObjectFactory; -import org.apache.olingo.commons.api.format.ODataFormat; - -public interface ODataClient extends CommonODataClient<UpdateType> { - - @Override - ODataDeserializer getDeserializer(ODataFormat format); - - @Override - ODataReader getReader(); - - @Override - ODataBinder getBinder(); - - @Override - URIBuilder newURIBuilder(String serviceRoot); - - @Override - FilterFactory getFilterFactory(); - - SearchFactory getSearchFactory(); - - @Override - ODataObjectFactory getObjectFactory(); - - AsyncRequestFactory getAsyncRequestFactory(); - - @Override - RetrieveRequestFactory getRetrieveRequestFactory(); - - @Override - CUDRequestFactory getCUDRequestFactory(); - - @Override - BatchRequestFactory getBatchRequestFactory(); -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/109c33ba/lib/client-core/src/main/java/org/apache/olingo/client/core/AndSearch.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/AndSearch.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/AndSearch.java new file mode 100644 index 0000000..fc9f476 --- /dev/null +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/AndSearch.java @@ -0,0 +1,42 @@ +/* + * 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; + +import org.apache.olingo.client.api.uri.URISearch; + +public class AndSearch implements URISearch { + + private final URISearch left; + + private final URISearch right; + + AndSearch(final URISearch left, final URISearch right) { + this.left = left; + this.right = right; + } + + @Override + public String build() { + return new StringBuilder(). + append('(').append(left.build()). + append(" AND "). + append(right.build()).append(')'). + toString(); + } +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/109c33ba/lib/client-core/src/main/java/org/apache/olingo/client/core/EdmEnabledODataClientImpl.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/EdmEnabledODataClientImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/EdmEnabledODataClientImpl.java new file mode 100644 index 0000000..b254473 --- /dev/null +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/EdmEnabledODataClientImpl.java @@ -0,0 +1,86 @@ +/* + * 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; + +import org.apache.olingo.client.api.EdmEnabledODataClient; +import org.apache.olingo.client.api.communication.request.invoke.EdmEnabledInvokeRequestFactory; +import org.apache.olingo.client.api.communication.request.retrieve.EdmMetadataRequest; +import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse; +import org.apache.olingo.client.api.uri.URIBuilder; +import org.apache.olingo.client.core.communication.request.invoke.EdmEnabledInvokeRequestFactoryImpl; +import org.apache.olingo.client.core.uri.URIBuilderImpl; +import org.apache.olingo.commons.api.edm.Edm; + +public class EdmEnabledODataClientImpl extends ODataClientImpl implements EdmEnabledODataClient { + + private final String serviceRoot; + + private Edm edm; + + private String metadataETag; + + private EdmEnabledInvokeRequestFactory edmEnabledInvokeRequestFactory; + + public EdmEnabledODataClientImpl(final String serviceRoot, final Edm edm, final String metadataETag) { + super(); + + this.serviceRoot = serviceRoot; + this.edm = edm; + this.metadataETag = metadataETag; + } + + @Override + public String getServiceRoot() { + return serviceRoot; + } + + @Override + public Edm getEdm(final String metadataETag) { + synchronized (this) { + if (this.edm == null || (metadataETag != null && !metadataETag.equals(this.metadataETag))) { + final EdmMetadataRequest metadataReq = getRetrieveRequestFactory().getMetadataRequest(serviceRoot); + final ODataRetrieveResponse<Edm> metadataRes = metadataReq.execute(); + this.metadataETag = metadataRes.getETag(); + this.edm = metadataRes.getBody(); + } + } + return this.edm; + } + + @Override + public Edm getCachedEdm() { + if (this.edm == null) { + getEdm(null); + } + return this.edm; + } + + @Override + public URIBuilder newURIBuilder() { + return new URIBuilderImpl(getServiceVersion(), configuration, serviceRoot); + } + + @Override + public EdmEnabledInvokeRequestFactory getInvokeRequestFactory() { + if (edmEnabledInvokeRequestFactory == null) { + edmEnabledInvokeRequestFactory = new EdmEnabledInvokeRequestFactoryImpl(this); + } + return edmEnabledInvokeRequestFactory; + } +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/109c33ba/lib/client-core/src/main/java/org/apache/olingo/client/core/LiteralSearch.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/LiteralSearch.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/LiteralSearch.java new file mode 100644 index 0000000..3d64d6f --- /dev/null +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/LiteralSearch.java @@ -0,0 +1,35 @@ +/* + * 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; + +import org.apache.olingo.client.api.uri.URISearch; + +public class LiteralSearch implements URISearch { + + private final String value; + + LiteralSearch(final String value) { + this.value = value; + } + + @Override + public String build() { + return value; + } +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/109c33ba/lib/client-core/src/main/java/org/apache/olingo/client/core/NotSearch.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/NotSearch.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/NotSearch.java new file mode 100644 index 0000000..07f4b0c --- /dev/null +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/NotSearch.java @@ -0,0 +1,35 @@ +/* + * 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; + +import org.apache.olingo.client.api.uri.URISearch; + +public class NotSearch implements URISearch { + + private final URISearch filter; + + NotSearch(final URISearch left) { + this.filter = left; + } + + @Override + public String build() { + return new StringBuilder("NOT (").append(filter.build()).append(')').toString(); + } +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/109c33ba/lib/client-core/src/main/java/org/apache/olingo/client/core/ODataClientFactory.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/ODataClientFactory.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/ODataClientFactory.java index 804466a..e4cf2e7 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/ODataClientFactory.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/ODataClientFactory.java @@ -18,16 +18,15 @@ */ package org.apache.olingo.client.core; -import org.apache.olingo.client.api.v4.EdmEnabledODataClient; -import org.apache.olingo.client.api.v4.ODataClient; -import org.apache.olingo.client.core.v4.EdmEnabledODataClientImpl; +import org.apache.olingo.client.api.EdmEnabledODataClient; +import org.apache.olingo.client.api.ODataClient; import org.apache.olingo.commons.api.edm.Edm; import org.apache.olingo.commons.api.format.ODataFormat; public final class ODataClientFactory { public static ODataClient getV4() { - return new org.apache.olingo.client.core.v4.ODataClientImpl(); + return new org.apache.olingo.client.core.ODataClientImpl(); } public static EdmEnabledODataClient getEdmEnabledV4(final String serviceRoot) { http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/109c33ba/lib/client-core/src/main/java/org/apache/olingo/client/core/ODataClientImpl.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/ODataClientImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/ODataClientImpl.java new file mode 100644 index 0000000..7db4856 --- /dev/null +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/ODataClientImpl.java @@ -0,0 +1,156 @@ +/* + * 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; + +import org.apache.olingo.client.api.ODataClient; +import org.apache.olingo.client.api.communication.header.HeaderName; +import org.apache.olingo.client.api.communication.header.ODataHeaders; +import org.apache.olingo.client.api.communication.request.AsyncRequestFactory; +import org.apache.olingo.client.api.communication.request.batch.BatchRequestFactory; +import org.apache.olingo.client.api.communication.request.cud.CUDRequestFactory; +import org.apache.olingo.client.api.communication.request.cud.UpdateType; +import org.apache.olingo.client.api.communication.request.invoke.InvokeRequestFactory; +import org.apache.olingo.client.api.communication.request.retrieve.RetrieveRequestFactory; +import org.apache.olingo.client.api.serialization.ODataBinder; +import org.apache.olingo.client.api.serialization.ODataDeserializer; +import org.apache.olingo.client.api.serialization.ODataReader; +import org.apache.olingo.client.api.uri.FilterFactory; +import org.apache.olingo.client.api.uri.SearchFactory; +import org.apache.olingo.client.api.uri.URIBuilder; +import org.apache.olingo.client.core.communication.header.ODataHeadersImpl; +import org.apache.olingo.client.core.communication.request.AsyncRequestFactoryImpl; +import org.apache.olingo.client.core.communication.request.batch.BatchRequestFactoryImpl; +import org.apache.olingo.client.core.communication.request.cud.CUDRequestFactoryImpl; +import org.apache.olingo.client.core.communication.request.invoke.InvokeRequestFactoryImpl; +import org.apache.olingo.client.core.communication.request.retrieve.RetrieveRequestFactoryImpl; +import org.apache.olingo.client.core.serialization.ODataBinderImpl; +import org.apache.olingo.client.core.serialization.ODataDeserializerImpl; +import org.apache.olingo.client.core.serialization.ODataReaderImpl; +import org.apache.olingo.client.core.uri.FilterFactoryImpl; +import org.apache.olingo.client.core.uri.URIBuilderImpl; +import org.apache.olingo.commons.api.domain.v4.ODataObjectFactory; +import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; +import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.serialization.ODataSerializer; +import org.apache.olingo.commons.core.domain.v4.ODataObjectFactoryImpl; +import org.apache.olingo.commons.core.serialization.AtomSerializer; +import org.apache.olingo.commons.core.serialization.JsonSerializer; + +public class ODataClientImpl extends AbstractODataClient<UpdateType> implements ODataClient { + + private final FilterFactory filterFactory = new FilterFactoryImpl(getServiceVersion()); + + private final SearchFactory searchFactory = new SearchFactoryImpl(); + + private final ODataReader reader = new ODataReaderImpl(this); + + private final ODataBinder binder = new ODataBinderImpl(this); + + private final ODataObjectFactory objectFactory = new ODataObjectFactoryImpl(getServiceVersion()); + + private final AsyncRequestFactory asyncReqFact = new AsyncRequestFactoryImpl(this); + + private final RetrieveRequestFactory retrieveReqFact = new RetrieveRequestFactoryImpl(this); + + private final CUDRequestFactory cudReqFact = new CUDRequestFactoryImpl(this); + + private final InvokeRequestFactory invokeReqFact = new InvokeRequestFactoryImpl(this); + + private final BatchRequestFactory batchReqFact = new BatchRequestFactoryImpl(this); + + @Override + public ODataServiceVersion getServiceVersion() { + return ODataServiceVersion.V40; + } + + @Override + public ODataHeaders newVersionHeaders() { + final ODataHeadersImpl odataHeaders = new ODataHeadersImpl(); + odataHeaders.setHeader(HeaderName.odataMaxVersion, ODataServiceVersion.V40.toString()); + odataHeaders.setHeader(HeaderName.odataVersion, ODataServiceVersion.V40.toString()); + return odataHeaders; + } + + @Override + public URIBuilder newURIBuilder(final String serviceRoot) { + return new URIBuilderImpl(getServiceVersion(), getConfiguration(), serviceRoot); + } + + @Override + public FilterFactory getFilterFactory() { + return filterFactory; + } + + @Override + public SearchFactory getSearchFactory() { + return searchFactory; + } + + @Override + public ODataDeserializer getDeserializer(final ODataFormat format) { + return new ODataDeserializerImpl(getServiceVersion(), false, format); + } + + @Override + public ODataSerializer getSerializer(final ODataFormat format) { + return format == ODataFormat.ATOM || format == ODataFormat.XML ? + new AtomSerializer(getServiceVersion()) : + new JsonSerializer(getServiceVersion(), false, format); + } + + @Override + public ODataReader getReader() { + return reader; + } + + @Override + public ODataBinder getBinder() { + return binder; + } + + @Override + public ODataObjectFactory getObjectFactory() { + return objectFactory; + } + + @Override + public AsyncRequestFactory getAsyncRequestFactory() { + return asyncReqFact; + } + + @Override + public RetrieveRequestFactory getRetrieveRequestFactory() { + return retrieveReqFact; + } + + @Override + public CUDRequestFactory getCUDRequestFactory() { + return cudReqFact; + } + + @Override + public InvokeRequestFactory getInvokeRequestFactory() { + return invokeReqFact; + } + + @Override + public BatchRequestFactory getBatchRequestFactory() { + return batchReqFact; + } +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/109c33ba/lib/client-core/src/main/java/org/apache/olingo/client/core/OrSearch.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/OrSearch.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/OrSearch.java new file mode 100644 index 0000000..f876a37 --- /dev/null +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/OrSearch.java @@ -0,0 +1,42 @@ +/* + * 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; + +import org.apache.olingo.client.api.uri.URISearch; + +public class OrSearch implements URISearch { + + private final URISearch left; + + private final URISearch right; + + OrSearch(final URISearch left, final URISearch right) { + this.left = left; + this.right = right; + } + + @Override + public String build() { + return new StringBuilder(). + append('(').append(left.build()). + append(" OR "). + append(right.build()).append(')'). + toString(); + } +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/109c33ba/lib/client-core/src/main/java/org/apache/olingo/client/core/SearchFactoryImpl.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/SearchFactoryImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/SearchFactoryImpl.java new file mode 100644 index 0000000..1f0895d --- /dev/null +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/SearchFactoryImpl.java @@ -0,0 +1,46 @@ +/* + * 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; + +import org.apache.olingo.client.api.uri.SearchFactory; +import org.apache.olingo.client.api.uri.URISearch; + +public class SearchFactoryImpl implements SearchFactory { + + @Override + public URISearch literal(final String value) { + return new LiteralSearch(value); + } + + @Override + public URISearch and(final URISearch left, final URISearch right) { + return new AndSearch(left, right); + } + + @Override + public URISearch or(final URISearch left, final URISearch right) { + return new OrSearch(left, right); + } + + @Override + public URISearch not(final URISearch filter) { + return new NotSearch(filter); + } + +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/109c33ba/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AbstractODataRequest.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AbstractODataRequest.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AbstractODataRequest.java index 9f02870..a5b267c 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AbstractODataRequest.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AbstractODataRequest.java @@ -48,9 +48,9 @@ import org.apache.olingo.commons.api.http.HttpMethod; * Abstract representation of an OData request. Get instance by using factories. * * @see org.apache.olingo.client.api.communication.request.cud.v3.CUDRequestFactory - * @see org.apache.olingo.client.api.communication.request.cud.v4.CUDRequestFactory + * @see org.apache.olingo.client.api.communication.request.cud.CUDRequestFactory * @see org.apache.olingo.client.api.communication.request.batch.v3.BatchRequestFactory - * @see org.apache.olingo.client.api.communication.request.batch.v4.BatchRequestFactory + * @see org.apache.olingo.client.api.communication.request.batch.BatchRequestFactory * @see org.apache.olingo.client.api.communication.request.invoke.InvokeRequestFactory */ public abstract class AbstractODataRequest extends AbstractRequest implements ODataRequest { http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/109c33ba/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AsyncBatchRequestWrapperImpl.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AsyncBatchRequestWrapperImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AsyncBatchRequestWrapperImpl.java new file mode 100644 index 0000000..71174a4 --- /dev/null +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AsyncBatchRequestWrapperImpl.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.client.core.communication.request; + +import java.net.URI; +import java.util.Collection; + +import org.apache.commons.io.IOUtils; +import org.apache.olingo.client.api.ODataClient; +import org.apache.olingo.client.api.communication.header.HeaderName; +import org.apache.olingo.client.api.communication.header.ODataPreferences; +import org.apache.olingo.client.api.communication.request.AsyncBatchRequestWrapper; +import org.apache.olingo.client.api.communication.request.ODataBatchableRequest; +import org.apache.olingo.client.api.communication.request.batch.BatchManager; +import org.apache.olingo.client.api.communication.request.batch.ODataBatchRequest; +import org.apache.olingo.client.api.communication.request.batch.ODataChangeset; +import org.apache.olingo.client.api.communication.response.AsyncResponseWrapper; +import org.apache.olingo.client.api.communication.response.ODataBatchResponse; +import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; + +public class AsyncBatchRequestWrapperImpl extends AsyncRequestWrapperImpl<ODataBatchResponse> + implements AsyncBatchRequestWrapper { + + private BatchManager batchManager; + + protected AsyncBatchRequestWrapperImpl(final ODataClient odataClient, final ODataBatchRequest odataRequest) { + super(odataClient, odataRequest); + batchManager = odataRequest.payloadManager(); + } + + /** + * {@inheritDoc} + */ + @Override + public ODataChangeset addChangeset() { + return batchManager.addChangeset(); + } + + /** + * {@inheritDoc} + */ + @Override + public void addRetrieve(final ODataBatchableRequest request) { + batchManager.addRequest(request); + } + + /** + * {@inheritDoc} + */ + @Override + public void addOutsideUpdate(final ODataBatchableRequest request) { + batchManager.addRequest(request); + } + + @Override + public AsyncResponseWrapper<ODataBatchResponse> execute() { + return new AsyncResponseWrapperImpl(batchManager.getResponse()); + } + + public class AsyncResponseWrapperImpl + extends AsyncRequestWrapperImpl<ODataBatchResponse>.AsyncResponseWrapperImpl { + + /** + * Constructor. + * + * @param res OData batch response. + */ + public AsyncResponseWrapperImpl(final ODataBatchResponse res) { + super(); + + if (res.getStatusCode() == 202) { + retrieveMonitorDetails(res); + } else { + response = res; + } + } + + private void retrieveMonitorDetails(final ODataBatchResponse res) { + Collection<String> headers = res.getHeader(HeaderName.location.toString()); + if (headers == null || headers.isEmpty()) { + throw new AsyncRequestException("Invalid async request response. Monitor URL not found"); + } else { + this.location = URI.create(headers.iterator().next()); + } + + headers = res.getHeader(HeaderName.retryAfter.toString()); + if (headers != null && !headers.isEmpty()) { + this.retryAfter = Integer.parseInt(headers.iterator().next()); + } + + headers = res.getHeader(HeaderName.preferenceApplied.toString()); + if (headers != null && !headers.isEmpty()) { + for (String header : headers) { + if (header.equalsIgnoreCase(new ODataPreferences(ODataServiceVersion.V40).respondAsync())) { + preferenceApplied = true; + } + } + } + + IOUtils.closeQuietly(res.getRawResponse()); + } + } +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/109c33ba/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AsyncRequestException.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AsyncRequestException.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AsyncRequestException.java new file mode 100644 index 0000000..a039c94 --- /dev/null +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AsyncRequestException.java @@ -0,0 +1,28 @@ +/* + * 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; + +public class AsyncRequestException extends RuntimeException { + + private static final long serialVersionUID = -6080844898544654406L; + + public AsyncRequestException(final String message) { + super(message); + } +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/109c33ba/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AsyncRequestFactoryImpl.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AsyncRequestFactoryImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AsyncRequestFactoryImpl.java new file mode 100644 index 0000000..14e1e2a --- /dev/null +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AsyncRequestFactoryImpl.java @@ -0,0 +1,46 @@ +/* + * 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; + +import org.apache.olingo.client.api.ODataClient; +import org.apache.olingo.client.api.communication.request.AsyncBatchRequestWrapper; +import org.apache.olingo.client.api.communication.request.AsyncRequestFactory; +import org.apache.olingo.client.api.communication.request.AsyncRequestWrapper; +import org.apache.olingo.client.api.communication.request.ODataRequest; +import org.apache.olingo.client.api.communication.request.batch.ODataBatchRequest; +import org.apache.olingo.client.api.communication.response.ODataResponse; + +public class AsyncRequestFactoryImpl implements AsyncRequestFactory { + + private final ODataClient client; + + public AsyncRequestFactoryImpl(final ODataClient client) { + this.client = client; + } + + @Override + public <R extends ODataResponse> AsyncRequestWrapper<R> getAsyncRequestWrapper(final ODataRequest odataRequest) { + return new AsyncRequestWrapperImpl<R>(client, odataRequest); + } + + @Override + public AsyncBatchRequestWrapper getAsyncBatchRequestWrapper(final ODataBatchRequest odataRequest) { + return new AsyncBatchRequestWrapperImpl(client, odataRequest); + } +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/109c33ba/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AsyncRequestWrapperImpl.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AsyncRequestWrapperImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AsyncRequestWrapperImpl.java new file mode 100644 index 0000000..f02d9e4 --- /dev/null +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AsyncRequestWrapperImpl.java @@ -0,0 +1,314 @@ +/* + * 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; + +import java.io.IOException; +import java.net.URI; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.apache.commons.lang3.ArrayUtils; +import org.apache.http.Header; +import org.apache.http.HttpResponse; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpUriRequest; +import org.apache.http.impl.client.DecompressingHttpClient; +import org.apache.http.util.EntityUtils; +import org.apache.olingo.client.api.ODataClient; +import org.apache.olingo.client.api.communication.ODataClientErrorException; +import org.apache.olingo.client.api.communication.header.HeaderName; +import org.apache.olingo.client.api.communication.header.ODataPreferences; +import org.apache.olingo.client.api.communication.request.AsyncRequestWrapper; +import org.apache.olingo.client.api.communication.request.ODataRequest; +import org.apache.olingo.client.api.communication.request.cud.ODataDeleteRequest; +import org.apache.olingo.client.api.communication.response.AsyncResponseWrapper; +import org.apache.olingo.client.api.communication.response.ODataDeleteResponse; +import org.apache.olingo.client.api.communication.response.ODataResponse; +import org.apache.olingo.client.api.http.HttpClientException; +import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; +import org.apache.olingo.commons.api.http.HttpMethod; + +public class AsyncRequestWrapperImpl<R extends ODataResponse> extends AbstractRequest + implements AsyncRequestWrapper<R> { + + protected static final int MAX_RETRY = 5; + + protected final ODataClient odataClient; + + /** + * Request to be wrapped. + */ + protected final ODataRequest odataRequest; + + /** + * HTTP client. + */ + protected final HttpClient httpClient; + + /** + * HTTP request. + */ + protected final HttpUriRequest request; + + /** + * Target URI. + */ + protected final URI uri; + + protected AsyncRequestWrapperImpl(final ODataClient odataClient, final ODataRequest odataRequest) { + this.odataRequest = odataRequest; + this.odataRequest.setAccept(this.odataRequest.getAccept()); + this.odataRequest.setContentType(this.odataRequest.getContentType()); + + extendHeader(HeaderName.prefer.toString(), new ODataPreferences(ODataServiceVersion.V40).respondAsync()); + + this.odataClient = odataClient; + final HttpMethod method = odataRequest.getMethod(); + + // target uri + this.uri = odataRequest.getURI(); + + HttpClient _httpClient = odataClient.getConfiguration().getHttpClientFactory().create(method, this.uri); + if (odataClient.getConfiguration().isGzipCompression()) { + _httpClient = new DecompressingHttpClient(_httpClient); + } + this.httpClient = _httpClient; + + this.request = odataClient.getConfiguration().getHttpUriRequestFactory().create(method, this.uri); + } + + @Override + public final AsyncRequestWrapper<R> wait(final int waitInSeconds) { + extendHeader(HeaderName.prefer.toString(), new ODataPreferences(ODataServiceVersion.V40).wait(waitInSeconds)); + return this; + } + + @Override + public final AsyncRequestWrapper<R> callback(URI url) { + extendHeader(HeaderName.prefer.toString(), + new ODataPreferences(ODataServiceVersion.V40).callback(url.toASCIIString())); + return this; + } + + protected final void extendHeader(final String headerName, final String headerValue) { + final StringBuilder extended = new StringBuilder(); + if (this.odataRequest.getHeaderNames().contains(headerName)) { + extended.append(this.odataRequest.getHeader(headerName)).append(", "); + } + + this.odataRequest.addCustomHeader(headerName, extended.append(headerValue).toString()); + } + + @Override + public AsyncResponseWrapper<R> execute() { + return new AsyncResponseWrapperImpl(doExecute()); + } + + protected HttpResponse doExecute() { + // Add all available headers + for (String key : odataRequest.getHeaderNames()) { + final String value = odataRequest.getHeader(key); + this.request.addHeader(key, value); + LOG.debug("HTTP header being sent {}: {}", key, value); + } + + return executeHttpRequest(httpClient, this.request); + } + + public class AsyncResponseWrapperImpl implements AsyncResponseWrapper<R> { + + protected URI location = null; + + protected R response = null; + + protected int retryAfter = 5; + + protected boolean preferenceApplied = false; + + public AsyncResponseWrapperImpl() { + } + + /** + * Constructor. + * + * @param res HTTP response. + */ + @SuppressWarnings("unchecked") + public AsyncResponseWrapperImpl(final HttpResponse res) { + if (res.getStatusLine().getStatusCode() == 202) { + retrieveMonitorDetails(res); + } else { + response = (R) ((AbstractODataRequest) odataRequest).getResponseTemplate().initFromHttpResponse(res); + } + } + + @Override + public boolean isPreferenceApplied() { + return preferenceApplied; + } + + @Override + public boolean isDone() { + if (response == null) { + // check to the monitor URL + final HttpResponse res = checkMonitor(location); + + if (res.getStatusLine().getStatusCode() == 202) { + retrieveMonitorDetails(res); + } else { + response = instantiateResponse(res); + } + } + + return response != null; + } + + @Override + public R getODataResponse() { + HttpResponse res = null; + for (int i = 0; response == null && i < MAX_RETRY; i++) { + res = checkMonitor(location); + + if (res.getStatusLine().getStatusCode() == 202) { + + final Header[] headers = res.getHeaders(HeaderName.retryAfter.toString()); + if (ArrayUtils.isNotEmpty(headers)) { + this.retryAfter = Integer.parseInt(headers[0].getValue()); + } + + try { + // wait for retry-after + Thread.sleep(retryAfter * 1000); + } catch (InterruptedException ignore) { + // ignore + } + + } else { + location = null; + return instantiateResponse(res); + } + } + + if (response == null) { + throw new ODataClientErrorException(res == null ? null : res.getStatusLine()); + } + + return response; + } + + /** + * {@inheritDoc} + */ + @Override + public ODataDeleteResponse delete() { + final ODataDeleteRequest deleteRequest = odataClient.getCUDRequestFactory().getDeleteRequest(location); + return deleteRequest.execute(); + } + + /** + * {@inheritDoc} + */ + @Override + public AsyncResponseWrapper<ODataDeleteResponse> asyncDelete() { + return odataClient.getAsyncRequestFactory().<ODataDeleteResponse>getAsyncRequestWrapper( + odataClient.getCUDRequestFactory().getDeleteRequest(location)).execute(); + } + + /** + * {@inheritDoc} + */ + @Override + public AsyncResponseWrapper<R> forceNextMonitorCheck(final URI uri) { + this.location = uri; + this.response = null; + return this; + } + + @SuppressWarnings("unchecked") + private R instantiateResponse(final HttpResponse res) { + R odataResponse; + try { + odataResponse = (R) ((AbstractODataRequest) odataRequest).getResponseTemplate(). + initFromEnclosedPart(res.getEntity().getContent()); + + } catch (Exception e) { + LOG.error("Error instantiating odata response", e); + odataResponse = null; + } + + return odataResponse; + } + + private void retrieveMonitorDetails(final HttpResponse res) { + Header[] headers = res.getHeaders(HeaderName.location.toString()); + if (ArrayUtils.isNotEmpty(headers)) { + this.location = URI.create(headers[0].getValue()); + } else { + throw new AsyncRequestException( + "Invalid async request response. Monitor URL '" + headers[0].getValue() + "'"); + } + + headers = res.getHeaders(HeaderName.retryAfter.toString()); + if (ArrayUtils.isNotEmpty(headers)) { + this.retryAfter = Integer.parseInt(headers[0].getValue()); + } + + headers = res.getHeaders(HeaderName.preferenceApplied.toString()); + if (ArrayUtils.isNotEmpty(headers)) { + for (Header header : headers) { + if (header.getValue().equalsIgnoreCase(new ODataPreferences(ODataServiceVersion.V40).respondAsync())) { + preferenceApplied = true; + } + } + } + try { + EntityUtils.consume(res.getEntity()); + } catch (IOException ex) { + Logger.getLogger(AsyncRequestWrapperImpl.class.getName()).log(Level.SEVERE, null, ex); + } + } + } + + protected final HttpResponse checkMonitor(final URI location) { + if (location == null) { + throw new AsyncRequestException("Invalid async request response. Missing monitor URL"); + } + + final HttpUriRequest monitor = odataClient.getConfiguration().getHttpUriRequestFactory(). + create(HttpMethod.GET, location); + + return executeHttpRequest(httpClient, monitor); + } + + protected final HttpResponse executeHttpRequest(final HttpClient client, final HttpUriRequest req) { + final HttpResponse response; + try { + response = client.execute(req); + } catch (IOException e) { + throw new HttpClientException(e); + } catch (RuntimeException e) { + req.abort(); + throw new HttpClientException(e); + } + + checkResponse(odataClient, response, odataRequest.getAccept()); + + return response; + } +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/109c33ba/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/BatchRequestFactoryImpl.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/BatchRequestFactoryImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/BatchRequestFactoryImpl.java new file mode 100644 index 0000000..e29a01d --- /dev/null +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/BatchRequestFactoryImpl.java @@ -0,0 +1,37 @@ +/* + * 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.batch; + +import org.apache.olingo.client.api.ODataClient; +import org.apache.olingo.client.api.communication.request.batch.BatchRequestFactory; +import org.apache.olingo.client.api.communication.request.batch.ODataBatchRequest; + +public class BatchRequestFactoryImpl extends AbstractBatchRequestFactory + implements BatchRequestFactory { + + public BatchRequestFactoryImpl(final ODataClient client) { + super(client); + } + + @Override + public ODataBatchRequest getBatchRequest(final String serviceRoot) { + return new ODataBatchRequestImpl( + (ODataClient) client, client.newURIBuilder(serviceRoot).appendBatchSegment().build()); + } +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/109c33ba/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/ODataBatchRequestImpl.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/ODataBatchRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/ODataBatchRequestImpl.java new file mode 100644 index 0000000..220e495 --- /dev/null +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/ODataBatchRequestImpl.java @@ -0,0 +1,120 @@ +/* + * 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.batch; + +import java.io.IOException; +import java.net.URI; +import java.util.Iterator; +import java.util.concurrent.TimeUnit; + +import org.apache.http.HttpResponse; +import org.apache.http.client.HttpClient; +import org.apache.olingo.client.api.CommonODataClient; +import org.apache.olingo.client.api.ODataClient; +import org.apache.olingo.client.api.communication.header.HeaderName; +import org.apache.olingo.client.api.communication.header.ODataPreferences; +import org.apache.olingo.client.api.communication.request.ODataBatchableRequest; +import org.apache.olingo.client.api.communication.request.batch.BatchManager; +import org.apache.olingo.client.api.communication.request.batch.ODataBatchRequest; +import org.apache.olingo.client.api.communication.request.batch.ODataBatchResponseItem; +import org.apache.olingo.client.api.communication.response.ODataBatchResponse; +import org.apache.olingo.client.core.communication.response.AbstractODataResponse; +import org.apache.olingo.client.core.communication.response.batch.ODataBatchResponseManager; + +public class ODataBatchRequestImpl + extends AbstractODataBatchRequest<ODataBatchResponse, BatchManager> + implements ODataBatchRequest { + + public ODataBatchRequestImpl(final ODataClient odataClient, final URI uri) { + super(odataClient, uri); + setAccept(odataClient.getConfiguration().getDefaultBatchAcceptFormat().toContentTypeString()); + } + + @Override + protected BatchManager getPayloadManager() { + if (payloadManager == null) { + payloadManager = new BatchManagerImpl(this); + } + return (BatchManager) payloadManager; + } + + @Override + public ODataBatchRequest rawAppend(final byte[] toBeStreamed) throws IOException { + getPayloadManager().getBodyStreamWriter().write(toBeStreamed); + return this; + } + + @Override + public ODataBatchRequest rawAppend(final byte[] toBeStreamed, int off, int len) throws IOException { + getPayloadManager().getBodyStreamWriter().write(toBeStreamed, off, len); + return this; + } + + @Override + protected HttpResponse doExecute() { + if (odataClient.getConfiguration().isContinueOnError()) { + addCustomHeader(HeaderName.prefer, new ODataPreferences(odataClient.getServiceVersion()).continueOnError()); + } + + return super.doExecute(); + } + + /** + * Batch request payload management. + */ + public class BatchManagerImpl extends AbstractBatchManager implements BatchManager { + + public BatchManagerImpl(final ODataBatchRequest req) { + super(req, ODataBatchRequestImpl.this.futureWrapper, + ODataBatchRequestImpl.this.odataClient.getConfiguration().isContinueOnError()); + } + + @Override + protected ODataBatchResponse getResponseInstance(final long timeout, final TimeUnit unit) { + return new ODataBatchResponseImpl(odataClient, httpClient, getHttpResponse(timeout, unit)); + } + + @Override + protected void validateSingleRequest(final ODataBatchableRequest request) { + } + } + + protected class ODataBatchResponseImpl extends AbstractODataResponse implements ODataBatchResponse { + + protected ODataBatchResponseImpl( + final CommonODataClient<?> odataClient, final HttpClient httpClient, final HttpResponse res) { + + super(odataClient, httpClient, res); + } + + @Override + public Iterator<ODataBatchResponseItem> getBody() { + return new ODataBatchResponseManager(this, expectedResItems, odataClient.getConfiguration().isContinueOnError()); + } + + @Override + public void close() { + for (ODataBatchResponseItem resItem : expectedResItems) { + resItem.close(); + } + super.close(); + } + + } +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/109c33ba/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/ODataChangesetResponseItem.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/ODataChangesetResponseItem.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/ODataChangesetResponseItem.java index bdc859c..cbeb5a4 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/ODataChangesetResponseItem.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/ODataChangesetResponseItem.java @@ -24,8 +24,8 @@ import java.util.NoSuchElementException; import org.apache.olingo.client.api.ODataBatchConstants; import org.apache.olingo.client.api.communication.response.ODataResponse; +import org.apache.olingo.client.core.communication.response.AsyncResponseImpl; import org.apache.olingo.client.core.communication.response.batch.ODataBatchErrorResponse; -import org.apache.olingo.client.core.communication.response.v4.AsyncResponseImpl; /** * Changeset wrapper for the corresponding batch item. http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/109c33ba/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/ODataSingleResponseItem.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/ODataSingleResponseItem.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/ODataSingleResponseItem.java index 35e30d2..e7e6546 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/ODataSingleResponseItem.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/ODataSingleResponseItem.java @@ -23,8 +23,8 @@ import java.util.Map; import java.util.NoSuchElementException; import org.apache.olingo.client.api.communication.response.ODataResponse; +import org.apache.olingo.client.core.communication.response.AsyncResponseImpl; import org.apache.olingo.client.core.communication.response.batch.ODataBatchErrorResponse; -import org.apache.olingo.client.core.communication.response.v4.AsyncResponseImpl; /** * Retrieve response wrapper for the corresponding batch item. http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/109c33ba/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/v4/BatchRequestFactoryImpl.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/v4/BatchRequestFactoryImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/v4/BatchRequestFactoryImpl.java deleted file mode 100644 index 9d93ad4..0000000 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/v4/BatchRequestFactoryImpl.java +++ /dev/null @@ -1,38 +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.batch.v4; - -import org.apache.olingo.client.api.communication.request.batch.v4.BatchRequestFactory; -import org.apache.olingo.client.api.communication.request.batch.v4.ODataBatchRequest; -import org.apache.olingo.client.api.v4.ODataClient; -import org.apache.olingo.client.core.communication.request.batch.AbstractBatchRequestFactory; - -public class BatchRequestFactoryImpl extends AbstractBatchRequestFactory - implements BatchRequestFactory { - - public BatchRequestFactoryImpl(final ODataClient client) { - super(client); - } - - @Override - public ODataBatchRequest getBatchRequest(final String serviceRoot) { - return new ODataBatchRequestImpl( - (ODataClient) client, client.newURIBuilder(serviceRoot).appendBatchSegment().build()); - } -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/109c33ba/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/v4/ODataBatchRequestImpl.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/v4/ODataBatchRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/v4/ODataBatchRequestImpl.java deleted file mode 100644 index 55a3ee7..0000000 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/v4/ODataBatchRequestImpl.java +++ /dev/null @@ -1,122 +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.batch.v4; - -import java.io.IOException; -import java.net.URI; -import java.util.Iterator; -import java.util.concurrent.TimeUnit; - -import org.apache.http.HttpResponse; -import org.apache.http.client.HttpClient; -import org.apache.olingo.client.api.CommonODataClient; -import org.apache.olingo.client.api.communication.header.HeaderName; -import org.apache.olingo.client.api.communication.header.ODataPreferences; -import org.apache.olingo.client.api.communication.request.ODataBatchableRequest; -import org.apache.olingo.client.api.communication.request.batch.BatchManager; -import org.apache.olingo.client.api.communication.request.batch.ODataBatchResponseItem; -import org.apache.olingo.client.api.communication.request.batch.v4.ODataBatchRequest; -import org.apache.olingo.client.api.communication.response.ODataBatchResponse; -import org.apache.olingo.client.api.v4.ODataClient; -import org.apache.olingo.client.core.communication.request.batch.AbstractBatchManager; -import org.apache.olingo.client.core.communication.request.batch.AbstractODataBatchRequest; -import org.apache.olingo.client.core.communication.response.AbstractODataResponse; -import org.apache.olingo.client.core.communication.response.batch.ODataBatchResponseManager; - -public class ODataBatchRequestImpl - extends AbstractODataBatchRequest<ODataBatchResponse, BatchManager> - implements ODataBatchRequest { - - public ODataBatchRequestImpl(final ODataClient odataClient, final URI uri) { - super(odataClient, uri); - setAccept(odataClient.getConfiguration().getDefaultBatchAcceptFormat().toContentTypeString()); - } - - @Override - protected BatchManager getPayloadManager() { - if (payloadManager == null) { - payloadManager = new BatchManagerImpl(this); - } - return (BatchManager) payloadManager; - } - - @Override - public ODataBatchRequest rawAppend(final byte[] toBeStreamed) throws IOException { - getPayloadManager().getBodyStreamWriter().write(toBeStreamed); - return this; - } - - @Override - public ODataBatchRequest rawAppend(final byte[] toBeStreamed, int off, int len) throws IOException { - getPayloadManager().getBodyStreamWriter().write(toBeStreamed, off, len); - return this; - } - - @Override - protected HttpResponse doExecute() { - if (odataClient.getConfiguration().isContinueOnError()) { - addCustomHeader(HeaderName.prefer, new ODataPreferences(odataClient.getServiceVersion()).continueOnError()); - } - - return super.doExecute(); - } - - /** - * Batch request payload management. - */ - public class BatchManagerImpl extends AbstractBatchManager implements BatchManager { - - public BatchManagerImpl(final ODataBatchRequest req) { - super(req, ODataBatchRequestImpl.this.futureWrapper, - ODataBatchRequestImpl.this.odataClient.getConfiguration().isContinueOnError()); - } - - @Override - protected ODataBatchResponse getResponseInstance(final long timeout, final TimeUnit unit) { - return new ODataBatchResponseImpl(odataClient, httpClient, getHttpResponse(timeout, unit)); - } - - @Override - protected void validateSingleRequest(final ODataBatchableRequest request) { - } - } - - protected class ODataBatchResponseImpl extends AbstractODataResponse implements ODataBatchResponse { - - protected ODataBatchResponseImpl( - final CommonODataClient<?> odataClient, final HttpClient httpClient, final HttpResponse res) { - - super(odataClient, httpClient, res); - } - - @Override - public Iterator<ODataBatchResponseItem> getBody() { - return new ODataBatchResponseManager(this, expectedResItems, odataClient.getConfiguration().isContinueOnError()); - } - - @Override - public void close() { - for (ODataBatchResponseItem resItem : expectedResItems) { - resItem.close(); - } - super.close(); - } - - } -}
