[OLINGO-659] Fix URIResource toString() ,methods

This commit is contained in:
Christian Amend 2015-08-21 16:03:06 +02:00
parent c0e032d485
commit 08ffd20199
33 changed files with 322 additions and 42 deletions

View File

@ -48,6 +48,10 @@ public abstract class OData {
private static final String IMPLEMENTATION = "org.apache.olingo.server.core.ODataImpl";
/**
* Use this method to create a new OData instance. Each thread/request should keep its own instance.
* @return a new OData instance
*/
public static OData newInstance() {
try {
final Class<?> clazz = Class.forName(OData.IMPLEMENTATION);
@ -74,7 +78,8 @@ public abstract class OData {
public abstract ODataSerializer createSerializer(ContentType contentType) throws SerializerException;
/**
* Creates a new serializer object for rendering content in a fixed format, e.g., for binary output.
* Creates a new serializer object for rendering content in a fixed format, e.g., for binary output or multipart/mixed
* outpu.
* Serializers are used in Processor implementations.
*/
public abstract FixedFormatSerializer createFixedFormatSerializer();

View File

@ -6,9 +6,9 @@
* 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
@ -97,14 +97,27 @@ public class ODataApplicationException extends ODataException {
this.oDataErrorCode = oDataErrorCode;
}
/**
* Will return the status code which will be used as a status code for the HTTP response. If not set the default is a
* 500 Internal Server Error.
* @return status code for this exception
*/
public int getStatusCode() {
return statusCode;
}
/**
* Returns the Locale which was used for the error message. The default is null.
* @return locale used for the error message
*/
public Locale getLocale() {
return locale;
}
/**
* This method will return the error code specified by the application. The default is null.
* @return the applications error code.
*/
public String getODataErrorCode() {
return oDataErrorCode;
}

View File

@ -231,7 +231,7 @@ public class ODataRequest {
/**
* Sets the HTTP protocol used
* @param 2protocol
* @param protocol
* @see #getProtocol()
*/
public void setProtocol(String protocol) {

View File

@ -26,7 +26,7 @@ import org.apache.olingo.commons.api.ex.ODataError;
import org.apache.olingo.commons.api.ex.ODataErrorDetail;
/**
* Server error.
* Class to hold all server relevant error information.
*/
public class ODataServerError extends ODataError {

View File

@ -20,6 +20,9 @@ package org.apache.olingo.server.api.etag;
import org.apache.olingo.server.api.ODataLibraryException;
/**
* This exception is thrown for invalid precondition error cases.
*/
public class PreconditionException extends ODataLibraryException {
private static final long serialVersionUID = -8112658467394158700L;

View File

@ -18,6 +18,9 @@
*/
package org.apache.olingo.server.api.etag;
/**
* Register implementations for this interface in oder to support etags for the metadata document and service document.
*/
public interface ServiceMetadataETagSupport {
/**

View File

@ -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.
******************************************************************************/
/**
* Olingo Server API
* <p>
* OData Library is a protocol implementation of the OData V4.0 standard. For details of this standard
* see <a href="http://odata.org">odata.org</a>.
* <p>
* This API is intended to help implement an OData service. An OData service consists of a metadata provider
* implementation and an OData processor implementation.
* <p>
* An OData service can be exposed by a web application using the standard java servlet API. See the Olingo tutorials
* section on how to implement a V4 service for further information:
* <a href="http://olingo.apache.org/doc/odata4/index.html">http://olingo.apache.org/doc/odata4/index.html
* <p>
* The main entry point is the org.apache.olingo.server.api.OData class. Use the newInstance() method to create a new
* object and start providing your service from there.
*
*/
package org.apache.olingo.server.api;

View File

@ -0,0 +1,34 @@
/*******************************************************************************
* 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.
******************************************************************************/
/**
* Olingo Processors
* <p>
* Processors are used to handle OData requests and send back the OData reponse. Before a specific processor is called
* the Olingo library will parse the URI and validate it. Afterwards the Processor which matches the return type is
* called. E.g.: If a primitive property is requested by the URI we will call the PrimitveProcessor.read method.
* <p>
* Processors can be registered at the {@link org.apache.olingo.server.api.ODataHttpHandler} object. Per default we will
* have the {@link org.apache.olingo.server.api.processor.DefaultProcessor} registered to perform basic functionality
* like delivering the metadata and service document as well as rendering an OData error.
* <br>In case an application would like to perform custom tasks for these cases a new
* {@link org.apache.olingo.server.api.processor.ServiceDocumentProcessor} can be registered in order to overwrite the
* default behaviour.
*/
package org.apache.olingo.server.api.processor;

View File

@ -19,6 +19,9 @@
package org.apache.olingo.server.api.serializer;
/**
* Thrown for invalid batch payloads.
*/
public class BatchSerializerException extends SerializerException {
private static final long serialVersionUID = 2634433974342796905L;

View File

@ -20,6 +20,9 @@ package org.apache.olingo.server.api.serializer;
import org.apache.olingo.commons.api.data.ContextURL;
/**
* Use this options calls to pass additional information to the reference serializer.
*/
public final class ReferenceSerializerOptions {
private ContextURL contextURL;

View File

@ -31,21 +31,57 @@ public interface UriInfo extends
UriInfoService, UriInfoAll, UriInfoBatch, UriInfoCrossjoin,
UriInfoEntityId, UriInfoMetadata, UriInfoResource {
/**
* See {@link UriInfoKind} for more details which kinds are allowed.
* @return the kind of this URI info object.
*/
UriInfoKind getKind();
/**
* Convenience casting method.
* @return this as a {@link UriInfoService} object
*/
UriInfoService asUriInfoService();
/**
* Convenience casting method.
* @return this as a {@link UriInfoAll} object
*/
UriInfoAll asUriInfoAll();
/**
* Convenience casting method.
* @return this as a {@link UriInfoBatch} object
*/
UriInfoBatch asUriInfoBatch();
/**
* Convenience casting method.
* @return this as a {@link UriInfoCrossjoin} object
*/
UriInfoCrossjoin asUriInfoCrossjoin();
/**
* Convenience casting method.
* @return this as a {@link UriInfoEntityId} object
*/
UriInfoEntityId asUriInfoEntityId();
/**
* Convenience casting method.
* @return this as a {@link UriInfoMetadata} object
*/
UriInfoMetadata asUriInfoMetadata();
/**
* Convenience casting method.
* @return this as a {@link UriInfoResource} object
*/
UriInfoResource asUriInfoResource();
/**
* A collection of all system query options which were in the URI.
* @return a collection of all system query options used.
*/
Collection<SystemQueryOption> getSystemQueryOptions();
}

View File

@ -6,9 +6,9 @@
* 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
@ -29,6 +29,13 @@ public interface UriResource {
*/
UriResourceKind getKind();
/**
* In case of an EntitySet this method will return the EntitySet name. In Case of $ref this method will return '$ref"
* as a String.
* @return the value of this URI Resource Segment
*/
String getSegmentValue();
@Override
String toString();

View File

@ -35,6 +35,11 @@ public interface UriResourcePartTyped extends UriResource {
*/
boolean isCollection();
/**
* @return String representation of the type
*/
public String getSegmentValue(final boolean includeFilters);
/**
* @return String representation of the type
*/

View File

@ -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.
******************************************************************************/
/**
* Olingo URI
* <p>
* The URI package is used to condense all information about the OData path used to query the data.
* <br> In order to support filter and orderby statements the
* {@link org.apache.olingo.server.api.uri.queryoption.expression.ExpressionVisitor} has to be implemented by an
* application.
*/
package org.apache.olingo.server.api.uri;

View File

@ -74,14 +74,24 @@ public class UriResourceActionImpl extends UriResourceImpl implements UriResourc
}
return null;
}
@Override
public String toString(final boolean includeFilters) {
public String getSegmentValue(final boolean includeFilters){
return actionImport == null ? (action == null ? "" : action.getName()) : actionImport.getName();
}
@Override
public String getSegmentValue(){
return getSegmentValue(false);
}
@Override
public String toString(final boolean includeFilters) {
return getSegmentValue(includeFilters);
}
@Override
public String toString() {
return toString(false);
return getSegmentValue();
}
}

View File

@ -63,8 +63,13 @@ public class UriResourceComplexPropertyImpl extends UriResourceTypedImpl impleme
}
@Override
public String toString() {
public String getSegmentValue(){
return property.getName();
}
@Override
public String toString() {
return getSegmentValue();
}
}

View File

@ -26,10 +26,15 @@ public class UriResourceCountImpl extends UriResourceImpl implements UriResource
public UriResourceCountImpl() {
super(UriResourceKind.count);
}
@Override
public String toString() {
public String getSegmentValue(){
return "$count";
}
@Override
public String toString() {
return getSegmentValue();
}
}

View File

@ -55,9 +55,15 @@ public class UriResourceEntitySetImpl extends UriResourceWithKeysImpl implements
public boolean isCollection() {
return keyPredicates == null;
}
@Override
public String getSegmentValue(){
return edmEntitySet.getName();
}
@Override
public String toString() {
return edmEntitySet.getName();
return getSegmentValue();
}
}

View File

@ -95,7 +95,7 @@ public class UriResourceFunctionImpl extends UriResourceWithKeysImpl implements
}
@Override
public String toString() {
public String getSegmentValue(){
if (functionImport != null) {
return functionImport.getName();
} else if (function != null) {
@ -103,6 +103,11 @@ public class UriResourceFunctionImpl extends UriResourceWithKeysImpl implements
}
return "";
}
@Override
public String toString() {
return getSegmentValue();
}
public boolean isParameterListFilled() {
return isParameterListFilled;

View File

@ -56,10 +56,15 @@ public class UriResourceItImpl extends UriResourceWithKeysImpl implements UriRes
this.isCollection = isCollection;
return this;
}
@Override
public String toString() {
public String getSegmentValue(){
return "$it";
}
@Override
public String toString() {
return getSegmentValue();
}
}

View File

@ -68,10 +68,15 @@ public class UriResourceLambdaAllImpl extends UriResourceTypedImpl implements Ur
this.expression = expression;
return this;
}
@Override
public String toString() {
public String getSegmentValue(){
return "all";
}
@Override
public String toString() {
return getSegmentValue();
}
}

View File

@ -68,9 +68,14 @@ public class UriResourceLambdaAnyImpl extends UriResourceTypedImpl implements Ur
this.expression = expression;
return this;
}
@Override
public String getSegmentValue(){
return "any";
}
@Override
public String toString() {
return "any";
return getSegmentValue();
}
}

View File

@ -64,7 +64,12 @@ public class UriResourceLambdaVarImpl extends UriResourceTypedImpl implements Ur
}
@Override
public String toString() {
public String getSegmentValue(){
return variableText;
}
@Override
public String toString() {
return getSegmentValue();
}
}

View File

@ -54,10 +54,15 @@ public class UriResourceNavigationPropertyImpl extends UriResourceWithKeysImpl i
}
return navigationProperty.isCollection();
}
@Override
public String toString() {
public String getSegmentValue(){
return navigationProperty.getName();
}
@Override
public String toString() {
return getSegmentValue();
}
}

View File

@ -50,10 +50,15 @@ public class UriResourcePrimitivePropertyImpl extends UriResourceTypedImpl imple
public boolean isCollection() {
return property.isCollection();
}
@Override
public String getSegmentValue(){
return property.getName();
}
@Override
public String toString() {
return property.getName();
return getSegmentValue();
}
}

View File

@ -27,10 +27,14 @@ public class UriResourceRefImpl extends UriResourceImpl implements UriResourceRe
super(UriResourceKind.ref);
}
@Override
public String toString() {
public String getSegmentValue(){
return "$ref";
}
@Override
public String toString() {
return getSegmentValue();
}
}

View File

@ -53,10 +53,15 @@ public class UriResourceRootImpl extends UriResourceWithKeysImpl implements UriR
this.isCollection = isCollection;
return this;
}
@Override
public String toString() {
public String getSegmentValue(){
return "$root";
}
@Override
public String toString() {
return getSegmentValue();
}
}

View File

@ -62,10 +62,15 @@ public class UriResourceSingletonImpl extends UriResourceTypedImpl implements Ur
public boolean isCollection() {
return false;
}
@Override
public String toString() {
public String getSegmentValue(){
return singleton.getName();
}
@Override
public String toString() {
return getSegmentValue();
}
}

View File

@ -59,8 +59,13 @@ public class UriResourceStartingTypeFilterImpl extends UriResourceWithKeysImpl {
}
@Override
public String toString() {
public String getSegmentValue(){
return type.getNamespace() + "." + type.getName();
}
@Override
public String toString() {
return getSegmentValue();
}
}

View File

@ -40,15 +40,19 @@ public abstract class UriResourceTypedImpl extends UriResourceImpl implements Ur
return this;
}
@Override
public String toString(final boolean includeFilters) {
public String getSegmentValue(final boolean includeFilters) {
if (includeFilters) {
if (typeFilter != null) {
return toString() + "/" + typeFilter.getFullQualifiedName().toString();
return getSegmentValue() + "/" + typeFilter.getFullQualifiedName().toString();
} else {
return toString();
return getSegmentValue();
}
}
return toString();
return getSegmentValue();
}
@Override
public String toString(final boolean includeFilters) {
return getSegmentValue(includeFilters);
}
}

View File

@ -29,8 +29,13 @@ public class UriResourceValueImpl extends UriResourceImpl implements UriResource
}
@Override
public String toString() {
public String getSegmentValue(){
return "$value";
}
@Override
public String toString() {
return getSegmentValue();
}
}

View File

@ -71,8 +71,7 @@ public abstract class UriResourceWithKeysImpl extends UriResourceImpl implements
}
@Override
public String toString(final boolean includeFilters) {
public String getSegmentValue(final boolean includeFilters) {
if (includeFilters) {
StringBuilder tmp = new StringBuilder();
if (collectionTypeFilter != null) {
@ -88,11 +87,16 @@ public abstract class UriResourceWithKeysImpl extends UriResourceImpl implements
}
if (tmp.length() != 0) {
return toString() + "/" + tmp.toString();
return getSegmentValue() + "/" + tmp.toString();
}
}
return toString();
return getSegmentValue();
}
@Override
public String toString(final boolean includeFilters) {
return getSegmentValue(includeFilters);
}
private String getFQN(final EdmType type) {

View File

@ -267,6 +267,11 @@ public class UriResourceImplTest {
@Override
public String toString() {
return getSegmentValue();
}
@Override
public String getSegmentValue() {
return "mock";
}
}
@ -342,10 +347,15 @@ public class UriResourceImplTest {
this.type = type;
return this;
}
@Override
public String getSegmentValue() {
return "mock";
}
@Override
public String toString() {
return "mock";
return getSegmentValue();
}
}