[OLINGO-482][OLINGO-507] Merge branch 'OLINGO-507_MinorRefactoring'

This commit is contained in:
Michael Bolz 2015-01-14 07:42:41 +01:00
commit 3fd3843662
29 changed files with 1170 additions and 424 deletions

View File

@ -34,11 +34,14 @@ import java.util.List;
import org.apache.olingo.client.api.CommonODataClient;
import org.apache.olingo.client.api.communication.ODataClientErrorException;
import org.apache.olingo.client.api.communication.ODataServerErrorException;
import org.apache.olingo.client.api.communication.request.cud.ODataEntityCreateRequest;
import org.apache.olingo.client.api.communication.request.retrieve.EdmMetadataRequest;
import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetRequest;
import org.apache.olingo.client.api.communication.request.retrieve.ODataServiceDocumentRequest;
import org.apache.olingo.client.api.communication.request.retrieve.XMLMetadataRequest;
import org.apache.olingo.client.api.communication.response.ODataEntityCreateResponse;
import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
import org.apache.olingo.client.api.edm.xml.XMLMetadata;
import org.apache.olingo.client.api.edm.xml.v4.Reference;
@ -52,9 +55,11 @@ import org.apache.olingo.commons.api.domain.v4.ODataEntitySet;
import org.apache.olingo.commons.api.domain.v4.ODataProperty;
import org.apache.olingo.commons.api.domain.v4.ODataValue;
import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.format.ContentType;
import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.commons.api.http.HttpStatusCode;
import org.apache.olingo.commons.core.domain.v4.ODataEntityImpl;
import org.apache.olingo.fit.AbstractBaseTestITCase;
import org.apache.olingo.fit.tecsvc.TecSvcConst;
import org.junit.Test;
@ -188,6 +193,42 @@ public class BasicITCase extends AbstractBaseTestITCase {
assertEquals(30112, iterator.next().asPrimitive().toValue());
}
/**
* Actual an create request for an entity will lead to an "501 - Not Implemented" response
* and hence to an ODataServerErrorException
*/
@Test(expected = ODataServerErrorException.class)
public void createEntity() throws IOException {
final ODataEntityRequest<ODataEntity> request = getClient().getRetrieveRequestFactory()
.getEntityRequest(getClient().newURIBuilder(SERVICE_URI)
.appendEntitySetSegment("ESCollAllPrim").appendKeySegment(1).build());
assertNotNull(request);
final ODataRetrieveResponse<ODataEntity> response = request.execute();
assertEquals(HttpStatusCode.OK.getStatusCode(), response.getStatusCode());
assertThat(response.getContentType(), containsString(ContentType.APPLICATION_JSON.toContentTypeString()));
final ODataEntity entity = response.getBody();
assertNotNull(entity);
final ODataEntityCreateRequest<ODataEntity> createRequest = getClient().getCUDRequestFactory()
.getEntityCreateRequest(getClient().newURIBuilder(SERVICE_URI)
.appendEntitySetSegment("ESCollAllPrim").build(), entity);
assertNotNull(createRequest);
ODataEntityCreateResponse<ODataEntity> createResponse = createRequest.execute();
final ODataEntity createdEntity = createResponse.getBody();
assertNotNull(createdEntity);
final ODataProperty property = createdEntity.getProperty("CollPropertyInt16");
assertNotNull(property);
assertNotNull(property.getCollectionValue());
assertEquals(3, property.getCollectionValue().size());
Iterator<ODataValue> iterator = property.getCollectionValue().iterator();
assertEquals(1000, iterator.next().asPrimitive().toValue());
assertEquals(2000, iterator.next().asPrimitive().toValue());
assertEquals(30112, iterator.next().asPrimitive().toValue());
}
@Override
protected CommonODataClient<?> getClient() {
ODataClient odata = ODataClientFactory.getV4();

View File

@ -0,0 +1,48 @@
/*
* 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.server.api.processor;
import org.apache.olingo.commons.api.format.ContentType;
import org.apache.olingo.server.api.ODataApplicationException;
import org.apache.olingo.server.api.ODataRequest;
import org.apache.olingo.server.api.ODataResponse;
import org.apache.olingo.server.api.deserializer.DeserializerException;
import org.apache.olingo.server.api.serializer.SerializerException;
import org.apache.olingo.server.api.uri.UriInfo;
/**
* Processor interface for handling an action import request which has a
* return type of ComplexCollection.
*/
public interface ActionComplexCollectionProcessor extends ComplexCollectionProcessor {
/**
* Process an action which has as return type a complex-type collection.
* @param request OData request object containing raw HTTP information
* @param response OData response object for collecting response data
* @param uriInfo information of a parsed OData URI
* @param requestFormat content type of body sent with request
* @param responseFormat requested content type after content negotiation
* @throws org.apache.olingo.server.api.ODataApplicationException if the service implementation encounters a failure
* @throws org.apache.olingo.server.api.deserializer.DeserializerException if deserialization failed
* @throws org.apache.olingo.server.api.serializer.SerializerException if serialization failed
*/
void processActionComplexCollection(ODataRequest request, ODataResponse response, UriInfo uriInfo,
ContentType requestFormat, ContentType responseFormat)
throws ODataApplicationException, DeserializerException, SerializerException;
}

View File

@ -0,0 +1,48 @@
/*
* 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.server.api.processor;
import org.apache.olingo.commons.api.format.ContentType;
import org.apache.olingo.server.api.ODataApplicationException;
import org.apache.olingo.server.api.ODataRequest;
import org.apache.olingo.server.api.ODataResponse;
import org.apache.olingo.server.api.deserializer.DeserializerException;
import org.apache.olingo.server.api.serializer.SerializerException;
import org.apache.olingo.server.api.uri.UriInfo;
/**
* Processor interface for handling an action import request which has a
* return type of Complex.
*/
public interface ActionComplexProcessor extends ComplexProcessor {
/**
* Process an action which has as return type a complex-type.
* @param request OData request object containing raw HTTP information
* @param response OData response object for collecting response data
* @param uriInfo information of a parsed OData URI
* @param requestFormat content type of body sent with request
* @param responseFormat requested content type after content negotiation
* @throws org.apache.olingo.server.api.ODataApplicationException if the service implementation encounters a failure
* @throws org.apache.olingo.server.api.deserializer.DeserializerException if deserialization failed
* @throws org.apache.olingo.server.api.serializer.SerializerException if serialization failed
*/
void processActionComplex(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType requestFormat,
ContentType responseFormat)
throws ODataApplicationException, DeserializerException, SerializerException;
}

View File

@ -0,0 +1,48 @@
/*
* 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.server.api.processor;
import org.apache.olingo.commons.api.format.ContentType;
import org.apache.olingo.server.api.ODataApplicationException;
import org.apache.olingo.server.api.ODataRequest;
import org.apache.olingo.server.api.ODataResponse;
import org.apache.olingo.server.api.deserializer.DeserializerException;
import org.apache.olingo.server.api.serializer.SerializerException;
import org.apache.olingo.server.api.uri.UriInfo;
/**
* Processor interface for handling an action import request which has a
* return type of Entity Collection.
*/
public interface ActionEntityCollectionProcessor extends EntityCollectionProcessor {
/**
* Process an action which has as return type a collection of entities.
* @param request OData request object containing raw HTTP information
* @param response OData response object for collecting response data
* @param uriInfo information of a parsed OData URI
* @param requestFormat content type of body sent with request
* @param responseFormat requested content type after content negotiation
* @throws org.apache.olingo.server.api.ODataApplicationException if the service implementation encounters a failure
* @throws org.apache.olingo.server.api.deserializer.DeserializerException if deserialization failed
* @throws org.apache.olingo.server.api.serializer.SerializerException if serialization failed
*/
void processActionEntityCollection(ODataRequest request, ODataResponse response,
UriInfo uriInfo, ContentType requestFormat, ContentType responseFormat)
throws ODataApplicationException, DeserializerException, SerializerException;
}

View File

@ -0,0 +1,48 @@
/*
* 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.server.api.processor;
import org.apache.olingo.commons.api.format.ContentType;
import org.apache.olingo.server.api.ODataApplicationException;
import org.apache.olingo.server.api.ODataRequest;
import org.apache.olingo.server.api.ODataResponse;
import org.apache.olingo.server.api.deserializer.DeserializerException;
import org.apache.olingo.server.api.serializer.SerializerException;
import org.apache.olingo.server.api.uri.UriInfo;
/**
* Processor interface for handling an action import request which has a
* return type of Entity.
*/
public interface ActionEntityProcessor extends EntityProcessor {
/**
* Process an action which has as return type an entity.
* @param request OData request object containing raw HTTP information
* @param response OData response object for collecting response data
* @param uriInfo information of a parsed OData URI
* @param requestFormat content type of body sent with request
* @param responseFormat requested content type after content negotiation
* @throws org.apache.olingo.server.api.ODataApplicationException if the service implementation encounters a failure
* @throws org.apache.olingo.server.api.deserializer.DeserializerException if deserialization failed
* @throws org.apache.olingo.server.api.serializer.SerializerException if serialization failed
*/
void processActionEntity(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType requestFormat,
ContentType responseFormat)
throws ODataApplicationException, DeserializerException, SerializerException;
}

View File

@ -0,0 +1,48 @@
/*
* 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.server.api.processor;
import org.apache.olingo.commons.api.format.ContentType;
import org.apache.olingo.server.api.ODataApplicationException;
import org.apache.olingo.server.api.ODataRequest;
import org.apache.olingo.server.api.ODataResponse;
import org.apache.olingo.server.api.deserializer.DeserializerException;
import org.apache.olingo.server.api.serializer.SerializerException;
import org.apache.olingo.server.api.uri.UriInfo;
/**
* Processor interface for handling an action import request which has a
* return type of Primitive Collection.
*/
public interface ActionPrimitiveCollectionProcessor extends PrimitiveCollectionProcessor {
/**
* Process an action which has as return type a primitive-type collection.
* @param request OData request object containing raw HTTP information
* @param response OData response object for collecting response data
* @param uriInfo information of a parsed OData URI
* @param requestFormat content type of body sent with request
* @param responseFormat requested content type after content negotiation
* @throws org.apache.olingo.server.api.ODataApplicationException if the service implementation encounters a failure
* @throws org.apache.olingo.server.api.deserializer.DeserializerException if deserialization failed
* @throws org.apache.olingo.server.api.serializer.SerializerException if serialization failed
*/
void processActionPrimitiveCollection(ODataRequest request, ODataResponse response, UriInfo uriInfo,
ContentType requestFormat, ContentType responseFormat)
throws ODataApplicationException, DeserializerException, SerializerException;
}

View File

@ -0,0 +1,48 @@
/*
* 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.server.api.processor;
import org.apache.olingo.commons.api.format.ContentType;
import org.apache.olingo.server.api.ODataApplicationException;
import org.apache.olingo.server.api.ODataRequest;
import org.apache.olingo.server.api.ODataResponse;
import org.apache.olingo.server.api.deserializer.DeserializerException;
import org.apache.olingo.server.api.serializer.SerializerException;
import org.apache.olingo.server.api.uri.UriInfo;
/**
* Processor interface for handling an action import request which has a
* return type of Primitive.
*/
public interface ActionPrimitiveProcessor extends PrimitiveProcessor {
/**
* Process an action which has as return type a primitive-type.
* @param request OData request object containing raw HTTP information
* @param response OData response object for collecting response data
* @param uriInfo information of a parsed OData URI
* @param requestFormat content type of body sent with request
* @param responseFormat requested content type after content negotiation
* @throws org.apache.olingo.server.api.ODataApplicationException if the service implementation encounters a failure
* @throws org.apache.olingo.server.api.deserializer.DeserializerException if deserialization failed
* @throws org.apache.olingo.server.api.serializer.SerializerException if serialization failed
*/
void processActionPrimitive(ODataRequest request, ODataResponse response, UriInfo uriInfo,
ContentType requestFormat, ContentType responseFormat)
throws ODataApplicationException, DeserializerException, SerializerException;
}

View File

@ -43,6 +43,7 @@ public interface ComplexProcessor extends Processor {
*/
void readComplex(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType responseFormat)
throws ODataApplicationException, SerializerException;
/**
* Update complex-type instance with send data in the persistence and
* puts content, status, and Location into the response.

View File

@ -22,6 +22,7 @@ import org.apache.olingo.commons.api.format.ContentType;
import org.apache.olingo.server.api.ODataApplicationException;
import org.apache.olingo.server.api.ODataRequest;
import org.apache.olingo.server.api.ODataResponse;
import org.apache.olingo.server.api.deserializer.DeserializerException;
import org.apache.olingo.server.api.serializer.SerializerException;
import org.apache.olingo.server.api.uri.UriInfo;
@ -41,4 +42,5 @@ public interface EntityCollectionProcessor extends Processor {
*/
void readEntityCollection(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType responseFormat)
throws ODataApplicationException, SerializerException;
}

View File

@ -81,4 +81,5 @@ public interface EntityProcessor extends Processor {
* @throws ODataApplicationException if the service implementation encounters a failure
*/
void deleteEntity(ODataRequest request, ODataResponse response, UriInfo uriInfo) throws ODataApplicationException;
}

View File

@ -72,4 +72,5 @@ public interface PrimitiveProcessor extends Processor {
*/
void deletePrimitive(ODataRequest request, ODataResponse response, UriInfo uriInfo)
throws ODataApplicationException;
}

View File

@ -151,4 +151,17 @@ public class ContentNegotiator {
throw new ContentNegotiatorException("unsupported content type: " + contentType,
ContentNegotiatorException.MessageKeys.UNSUPPORTED_CONTENT_TYPE, contentType.toContentTypeString());
}
public static boolean isSupported(final ContentType contentType,
final CustomContentTypeSupport customContentTypeSupport,
final RepresentationType representationType) throws ContentNegotiatorException {
for (final ContentType supportedContentType :
getSupportedContentTypes(customContentTypeSupport, representationType)) {
if (AcceptType.fromContentType(supportedContentType).get(0).matches(contentType)) {
return true;
}
}
return false;
}
}

View File

@ -30,6 +30,7 @@ public class ContentNegotiatorException extends ODataTranslatedException {
UNSUPPORTED_CONTENT_TYPES,
/** parameter: content type */
UNSUPPORTED_CONTENT_TYPE,
/** no parameter */
NO_CONTENT_TYPE_SUPPORTED,
/** parameter: format string */
UNSUPPORTED_FORMAT_OPTION;

View File

@ -21,9 +21,13 @@ package org.apache.olingo.server.core;
import java.util.LinkedList;
import java.util.List;
import org.apache.olingo.commons.api.edm.EdmAction;
import org.apache.olingo.commons.api.edm.EdmActionImport;
import org.apache.olingo.commons.api.edm.EdmEntityType;
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
import org.apache.olingo.commons.api.edm.EdmFunction;
import org.apache.olingo.commons.api.edm.EdmFunctionImport;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.apache.olingo.commons.api.edm.EdmReturnType;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
import org.apache.olingo.commons.api.format.ContentType;
import org.apache.olingo.commons.api.format.ODataFormat;
@ -38,6 +42,12 @@ import org.apache.olingo.server.api.ODataServerError;
import org.apache.olingo.server.api.ServiceMetadata;
import org.apache.olingo.server.api.batch.exception.BatchDeserializerException;
import org.apache.olingo.server.api.deserializer.DeserializerException;
import org.apache.olingo.server.api.processor.ActionComplexCollectionProcessor;
import org.apache.olingo.server.api.processor.ActionComplexProcessor;
import org.apache.olingo.server.api.processor.ActionEntityCollectionProcessor;
import org.apache.olingo.server.api.processor.ActionEntityProcessor;
import org.apache.olingo.server.api.processor.ActionPrimitiveCollectionProcessor;
import org.apache.olingo.server.api.processor.ActionPrimitiveProcessor;
import org.apache.olingo.server.api.processor.BatchProcessor;
import org.apache.olingo.server.api.processor.ComplexCollectionProcessor;
import org.apache.olingo.server.api.processor.ComplexProcessor;
@ -62,7 +72,9 @@ import org.apache.olingo.server.api.serializer.RepresentationType;
import org.apache.olingo.server.api.serializer.SerializerException;
import org.apache.olingo.server.api.uri.UriInfo;
import org.apache.olingo.server.api.uri.UriResource;
import org.apache.olingo.server.api.uri.UriResourceAction;
import org.apache.olingo.server.api.uri.UriResourceEntitySet;
import org.apache.olingo.server.api.uri.UriResourceFunction;
import org.apache.olingo.server.api.uri.UriResourceNavigation;
import org.apache.olingo.server.api.uri.UriResourcePartTyped;
import org.apache.olingo.server.api.uri.UriResourcePrimitiveProperty;
@ -136,64 +148,70 @@ public class ODataHandler {
}
private void processInternal(final ODataRequest request, final ODataResponse response)
throws ODataHandlerException, UriParserException, UriValidationException, ContentNegotiatorException,
ODataApplicationException, SerializerException, DeserializerException {
throws ODataHandlerException, UriParserException, UriValidationException, ContentNegotiatorException,
ODataApplicationException, SerializerException, DeserializerException {
validateODataVersion(request, response);
uriInfo = new Parser().parseUri(request.getRawODataPath(), request.getRawQueryPath(), null,
serviceMetadata.getEdm());
serviceMetadata.getEdm());
final HttpMethod method = request.getMethod();
new UriValidator().validate(uriInfo, method);
switch (uriInfo.getKind()) {
case metadata:
if (method == HttpMethod.GET) {
final ContentType requestedContentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
request, customContentTypeSupport, RepresentationType.METADATA);
selectProcessor(MetadataProcessor.class)
.readMetadata(request, response, uriInfo, requestedContentType);
} else {
throw new ODataHandlerException("HttpMethod " + method + " not allowed for metadata document",
ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, method.toString());
}
break;
case service:
if (method == HttpMethod.GET) {
if ("".equals(request.getRawODataPath())) {
selectProcessor(RedirectProcessor.class).redirect(request, response);
} else {
case metadata:
if (method == HttpMethod.GET) {
final ContentType requestedContentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
request, customContentTypeSupport, RepresentationType.SERVICE);
selectProcessor(ServiceDocumentProcessor.class)
.readServiceDocument(request, response, uriInfo, requestedContentType);
request, customContentTypeSupport, RepresentationType.METADATA);
selectProcessor(MetadataProcessor.class)
.readMetadata(request, response, uriInfo, requestedContentType);
} else {
throw new ODataHandlerException("HttpMethod " + method + " not allowed for metadata document",
ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, method.toString());
}
} else {
throw new ODataHandlerException("HttpMethod " + method + " not allowed for service document",
ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, method.toString());
}
break;
case resource:
handleResourceDispatching(request, response);
break;
case batch:
if (method == HttpMethod.POST) {
final BatchProcessor bp = selectProcessor(BatchProcessor.class);
final BatchHandler handler = new BatchHandler(this, bp);
handler.process(request, response, true);
} else {
throw new ODataHandlerException("HTTP method " + method + " is not allowed.",
ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, method.toString());
}
break;
default:
throw new ODataHandlerException("not implemented",
ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
break;
case service:
if (method == HttpMethod.GET) {
if ("".equals(request.getRawODataPath())) {
selectProcessor(RedirectProcessor.class).redirect(request, response);
} else {
final ContentType requestedContentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
request, customContentTypeSupport, RepresentationType.SERVICE);
selectProcessor(ServiceDocumentProcessor.class)
.readServiceDocument(request, response, uriInfo, requestedContentType);
}
} else {
throw new ODataHandlerException("HttpMethod " + method + " not allowed for service document",
ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, method.toString());
}
break;
case resource:
handleResourceDispatching(request, response);
break;
case batch:
if (method == HttpMethod.POST) {
final BatchProcessor bp = selectProcessor(BatchProcessor.class);
final BatchHandler handler = new BatchHandler(this, bp);
handler.process(request, response, true);
} else {
throw new ODataHandlerException("HTTP method " + method + " is not allowed.",
ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, method.toString());
}
break;
default:
throw new ODataHandlerException("not implemented",
ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
}
}
public void handleException(ODataRequest request, ODataResponse response, ODataServerError serverError) {
public void handleException(final ODataRequest request, final ODataResponse response,
final ODataServerError serverError) {
ErrorProcessor exceptionProcessor;
try {
exceptionProcessor = selectProcessor(ErrorProcessor.class);
@ -204,8 +222,8 @@ public class ODataHandler {
ContentType requestedContentType;
try {
requestedContentType = ContentNegotiator.doContentNegotiation(
uriInfo == null ? null : uriInfo.getFormatOption(), request, customContentTypeSupport,
RepresentationType.ERROR);
uriInfo == null ? null : uriInfo.getFormatOption(), request, customContentTypeSupport,
RepresentationType.ERROR);
} catch (final ContentNegotiatorException e) {
requestedContentType = ODataFormat.JSON.getContentType(ODataServiceVersion.V40);
}
@ -213,274 +231,451 @@ public class ODataHandler {
}
private void handleResourceDispatching(final ODataRequest request, final ODataResponse response)
throws ODataHandlerException, ContentNegotiatorException, ODataApplicationException,
SerializerException, DeserializerException {
final HttpMethod method = request.getMethod();
throws ODataHandlerException, ContentNegotiatorException, ODataApplicationException,
SerializerException, DeserializerException {
final int lastPathSegmentIndex = uriInfo.getUriResourceParts().size() - 1;
final UriResource lastPathSegment = uriInfo.getUriResourceParts().get(lastPathSegmentIndex);
switch (lastPathSegment.getKind()) {
case entitySet:
case navigationProperty:
if (((UriResourcePartTyped) lastPathSegment).isCollection()) {
if (method == HttpMethod.GET) {
final ContentType requestedContentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
request, customContentTypeSupport, RepresentationType.COLLECTION_ENTITY);
case action:
handleActionDispatching(request, response, (UriResourceAction) lastPathSegment);
break;
selectProcessor(EntityCollectionProcessor.class)
.readEntityCollection(request, response, uriInfo, requestedContentType);
} else if (method == HttpMethod.POST) {
if (isMedia(lastPathSegment)) {
final ContentType requestFormat = ContentType.parse(request.getHeader(HttpHeader.CONTENT_TYPE));
final ContentType responseFormat = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
request, customContentTypeSupport, RepresentationType.ENTITY);
selectProcessor(MediaEntityProcessor.class)
.createMediaEntity(request, response, uriInfo, requestFormat, responseFormat);
} else {
final ContentType requestFormat = ContentType.parse(request.getHeader(HttpHeader.CONTENT_TYPE));
ContentNegotiator.checkSupport(requestFormat, customContentTypeSupport, RepresentationType.ENTITY);
final ContentType responseFormat = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
request, customContentTypeSupport, RepresentationType.ENTITY);
selectProcessor(EntityProcessor.class)
.createEntity(request, response, uriInfo, requestFormat, responseFormat);
}
} else {
throw new ODataHandlerException("HTTP method " + method + " is not allowed.",
case function:
handleFunctionDispatching(request, response, (UriResourceFunction) lastPathSegment);
break;
case entitySet:
case navigationProperty:
handleEntityDispatching(request, response, (UriResourcePartTyped) lastPathSegment);
break;
case count:
handleCountDispatching(request, response, lastPathSegmentIndex);
break;
case primitiveProperty:
handlePrimitivePropertyDispatching(request, response, false,
((UriResourceProperty) lastPathSegment).isCollection());
break;
case complexProperty:
handleComplexPropertyDispatching(request, response, false,
((UriResourceProperty) lastPathSegment).isCollection());
break;
case value:
handleValueDispatching(request, response, lastPathSegmentIndex);
break;
case ref:
handleReferenceDispatching(request, response, lastPathSegmentIndex);
break;
default:
throw new ODataHandlerException("not implemented",
ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
}
}
private void handleFunctionDispatching(final ODataRequest request, final ODataResponse response,
final UriResourceFunction uriResourceFunction)
throws ODataHandlerException, SerializerException, ContentNegotiatorException,
ODataApplicationException, DeserializerException {
final HttpMethod method = request.getMethod();
if(method != HttpMethod.GET) {
throw new ODataHandlerException("HTTP method " + method + " is not allowed.",
ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, method.toString());
}
} else {
if (method == HttpMethod.GET) {
final ContentType requestedContentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
request, customContentTypeSupport, RepresentationType.ENTITY);
}
selectProcessor(EntityProcessor.class)
.readEntity(request, response, uriInfo, requestedContentType);
} else if (method == HttpMethod.PUT || method == HttpMethod.PATCH) {
final ContentType requestFormat = ContentType.parse(request.getHeader(HttpHeader.CONTENT_TYPE));
ContentNegotiator.checkSupport(requestFormat, customContentTypeSupport, RepresentationType.ENTITY);
final ContentType responseFormat = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
request, customContentTypeSupport, RepresentationType.ENTITY);
selectProcessor(EntityProcessor.class)
.updateEntity(request, response, uriInfo, requestFormat, responseFormat);
} else if (method == HttpMethod.DELETE) {
selectProcessor(isMedia(lastPathSegment) ? MediaEntityProcessor.class : EntityProcessor.class)
.deleteEntity(request, response, uriInfo);
} else {
throw new ODataHandlerException("HTTP method " + method + " is not allowed.",
EdmFunctionImport functionImport = uriResourceFunction.getFunctionImport();
// could be null for bound functions
if(functionImport == null) {
throw new ODataHandlerException("Bound functions are not implemented yet",
ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
}
List<EdmFunction> unboundFunctions = functionImport.getUnboundFunctions();
if(unboundFunctions == null || unboundFunctions.isEmpty()) {
throw new ODataHandlerException("No unbound function defined for function import",
ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
}
EdmReturnType returnType = unboundFunctions.get(0).getReturnType();
handleOperationDispatching(request, response, false, returnType);
}
private void handleActionDispatching(final ODataRequest request, final ODataResponse response,
final UriResourceAction uriResourceAction)
throws ODataHandlerException, SerializerException, ContentNegotiatorException,
ODataApplicationException, DeserializerException {
final HttpMethod method = request.getMethod();
if(request.getMethod() != HttpMethod.POST) {
throw new ODataHandlerException("HTTP method " + method + " is not allowed.",
ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, method.toString());
}
}
break;
}
case count:
if (method == HttpMethod.GET) {
final UriResource resource = uriInfo.getUriResourceParts().get(lastPathSegmentIndex - 1);
if (resource instanceof UriResourceEntitySet || resource instanceof UriResourceNavigation) {
selectProcessor(CountEntityCollectionProcessor.class)
.countEntityCollection(request, response, uriInfo);
} else if (resource instanceof UriResourcePrimitiveProperty) {
selectProcessor(CountPrimitiveCollectionProcessor.class)
.countPrimitiveCollection(request, response, uriInfo);
} else {
selectProcessor(CountComplexCollectionProcessor.class)
.countComplexCollection(request, response, uriInfo);
}
} else {
throw new ODataHandlerException("HTTP method " + method + " is not allowed for count.",
ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, method.toString());
}
break;
EdmActionImport actionImport = uriResourceAction.getActionImport();
// could be null for bound actions
if(actionImport == null) {
throw new ODataHandlerException("Bound actions are not implemented yet",
ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
}
case primitiveProperty:
final UriResourceProperty propertyResource = (UriResourceProperty) lastPathSegment;
final RepresentationType representationType = propertyResource.isCollection() ?
RepresentationType.COLLECTION_PRIMITIVE : RepresentationType.PRIMITIVE;
EdmAction unboundActions = actionImport.getUnboundAction();
if(unboundActions == null) {
throw new ODataHandlerException("No unbound function defined for function import",
ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
}
EdmReturnType returnType = unboundActions.getReturnType();
handleOperationDispatching(request, response, true, returnType);
}
private void handleOperationDispatching(final ODataRequest request, final ODataResponse response,
final boolean isAction, final EdmReturnType edmReturnTypeKind)
throws ODataHandlerException, SerializerException, ContentNegotiatorException,
ODataApplicationException, DeserializerException {
switch (edmReturnTypeKind.getType().getKind()) {
case ENTITY:
handleEntityDispatching(request, response, edmReturnTypeKind.isCollection(), false, isAction);
break;
case PRIMITIVE:
handlePrimitivePropertyDispatching(request, response, isAction, edmReturnTypeKind.isCollection());
break;
case COMPLEX:
handleComplexPropertyDispatching(request, response, isAction, edmReturnTypeKind.isCollection());
break;
default:
throw new ODataHandlerException("not implemented",
ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
}
}
private void handleReferenceDispatching(final ODataRequest request, final ODataResponse response,
final int lastPathSegmentIndex)
throws ContentNegotiatorException, ODataApplicationException, SerializerException, ODataHandlerException,
DeserializerException {
final HttpMethod method = request.getMethod();
if (((UriResourcePartTyped) uriInfo.getUriResourceParts().get(lastPathSegmentIndex - 1)).isCollection()) {
if (method == HttpMethod.GET) {
final ContentType requestedContentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
request, customContentTypeSupport, representationType);
if (representationType == RepresentationType.PRIMITIVE) {
selectProcessor(PrimitiveProcessor.class)
.readPrimitive(request, response, uriInfo, requestedContentType);
} else {
selectProcessor(PrimitiveCollectionProcessor.class)
.readPrimitiveCollection(request, response, uriInfo, requestedContentType);
}
} else if (method == HttpMethod.PUT || method == HttpMethod.PATCH) {
final ContentType requestFormat = ContentType.parse(request.getHeader(HttpHeader.CONTENT_TYPE));
ContentNegotiator.checkSupport(requestFormat, customContentTypeSupport, representationType);
final ContentType responseFormat = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
request, customContentTypeSupport, representationType);
if (representationType == RepresentationType.PRIMITIVE) {
selectProcessor(PrimitiveProcessor.class)
.updatePrimitive(request, response, uriInfo, requestFormat, responseFormat);
} else {
selectProcessor(PrimitiveCollectionProcessor.class)
.updatePrimitiveCollection(request, response, uriInfo, requestFormat, responseFormat);
}
} else if (method == HttpMethod.DELETE) {
if (representationType == RepresentationType.PRIMITIVE) {
selectProcessor(PrimitiveProcessor.class)
.deletePrimitive(request, response, uriInfo);
} else {
selectProcessor(PrimitiveCollectionProcessor.class)
.deletePrimitiveCollection(request, response, uriInfo);
}
request, customContentTypeSupport, RepresentationType.COLLECTION_REFERENCE);
selectProcessor(ReferenceCollectionProcessor.class)
.readReferenceCollection(request, response, uriInfo, responseFormat);
} else if (method == HttpMethod.POST) {
final ContentType requestFormat = ContentType.parse(request.getHeader(HttpHeader.CONTENT_TYPE));
checkContentTypeSupport(requestFormat, RepresentationType.REFERENCE);
selectProcessor(ReferenceProcessor.class)
.createReference(request, response, uriInfo, requestFormat);
} else {
throw new ODataHandlerException("HTTP method " + method + " is not allowed.",
ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, method.toString());
ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, method.toString());
}
break;
case complexProperty:
final UriResourceProperty complexPropertyResource = (UriResourceProperty) lastPathSegment;
final RepresentationType complexRepresentationType = complexPropertyResource.isCollection() ?
RepresentationType.COLLECTION_COMPLEX : RepresentationType.COMPLEX;
} else {
if (method == HttpMethod.GET) {
final ContentType requestedContentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
request, customContentTypeSupport, complexRepresentationType);
if (complexRepresentationType == RepresentationType.COMPLEX) {
selectProcessor(ComplexProcessor.class)
.readComplex(request, response, uriInfo, requestedContentType);
} else {
selectProcessor(ComplexCollectionProcessor.class)
.readComplexCollection(request, response, uriInfo, requestedContentType);
}
final ContentType responseFormat = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
request, customContentTypeSupport, RepresentationType.REFERENCE);
selectProcessor(ReferenceProcessor.class).readReference(request, response, uriInfo, responseFormat);
} else if (method == HttpMethod.PUT || method == HttpMethod.PATCH) {
final ContentType requestFormat = ContentType.parse(request.getHeader(HttpHeader.CONTENT_TYPE));
ContentNegotiator.checkSupport(requestFormat, customContentTypeSupport, complexRepresentationType);
final ContentType responseFormat = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
request, customContentTypeSupport, complexRepresentationType);
if (complexRepresentationType == RepresentationType.COMPLEX) {
selectProcessor(ComplexProcessor.class)
.updateComplex(request, response, uriInfo, requestFormat, responseFormat);
} else {
selectProcessor(ComplexCollectionProcessor.class)
.updateComplexCollection(request, response, uriInfo, requestFormat, responseFormat);
}
checkContentTypeSupport(requestFormat, RepresentationType.REFERENCE);
selectProcessor(ReferenceProcessor.class)
.updateReference(request, response, uriInfo, requestFormat);
} else if (method == HttpMethod.DELETE) {
if (complexRepresentationType == RepresentationType.COMPLEX) {
selectProcessor(ComplexProcessor.class)
.deleteComplex(request, response, uriInfo);
} else {
selectProcessor(ComplexCollectionProcessor.class)
.deleteComplexCollection(request, response, uriInfo);
}
selectProcessor(ReferenceProcessor.class)
.deleteReference(request, response, uriInfo);
} else {
throw new ODataHandlerException("HTTP method " + method + " is not allowed.",
ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, method.toString());
ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, method.toString());
}
break;
}
}
case value:
final UriResource resource = uriInfo.getUriResourceParts().get(lastPathSegmentIndex - 1);
if (resource instanceof UriResourceProperty) {
final RepresentationType valueRepresentationType =
(EdmPrimitiveType) ((UriResourceProperty) resource).getType() ==
EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Binary) ?
RepresentationType.BINARY : RepresentationType.VALUE;
if (method == HttpMethod.GET) {
final ContentType requestedContentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
request, customContentTypeSupport, valueRepresentationType);
private void handleValueDispatching(final ODataRequest request, final ODataResponse response,
final int lastPathSegmentIndex)
throws ContentNegotiatorException, ODataApplicationException, SerializerException, ODataHandlerException,
DeserializerException {
final HttpMethod method = request.getMethod();
final UriResource resource = uriInfo.getUriResourceParts().get(lastPathSegmentIndex - 1);
if (resource instanceof UriResourceProperty) {
final RepresentationType valueRepresentationType =
((UriResourceProperty) resource).getType() ==
EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Binary) ?
RepresentationType.BINARY : RepresentationType.VALUE;
if (method == HttpMethod.GET) {
final ContentType requestedContentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
request, customContentTypeSupport, valueRepresentationType);
selectProcessor(PrimitiveValueProcessor.class)
.readPrimitiveValue(request, response, uriInfo, requestedContentType);
} else if (method == HttpMethod.PUT) {
final ContentType requestFormat = ContentType.parse(request.getHeader(HttpHeader.CONTENT_TYPE));
ContentNegotiator.checkSupport(requestFormat, customContentTypeSupport, valueRepresentationType);
final ContentType responseFormat = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
request, customContentTypeSupport, valueRepresentationType);
selectProcessor(PrimitiveValueProcessor.class)
.updatePrimitive(request, response, uriInfo, requestFormat, responseFormat);
} else if (method == HttpMethod.DELETE) {
selectProcessor(PrimitiveValueProcessor.class)
.deletePrimitive(request, response, uriInfo);
} else {
throw new ODataHandlerException("HTTP method " + method + " is not allowed.",
ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, method.toString());
}
selectProcessor(PrimitiveValueProcessor.class)
.readPrimitiveValue(request, response, uriInfo, requestedContentType);
} else if (method == HttpMethod.PUT) {
final ContentType requestFormat = ContentType.parse(request.getHeader(HttpHeader.CONTENT_TYPE));
checkContentTypeSupport(requestFormat, valueRepresentationType);
final ContentType responseFormat = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
request, customContentTypeSupport, valueRepresentationType);
selectProcessor(PrimitiveValueProcessor.class)
.updatePrimitive(request, response, uriInfo, requestFormat, responseFormat);
} else if (method == HttpMethod.DELETE) {
selectProcessor(PrimitiveValueProcessor.class).deletePrimitive(request, response, uriInfo);
} else {
if (method == HttpMethod.GET) {
final ContentType requestedContentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
request, customContentTypeSupport, RepresentationType.MEDIA);
selectProcessor(MediaEntityProcessor.class)
.readMediaEntity(request, response, uriInfo, requestedContentType);
} else if (method == HttpMethod.PUT) {
throw new ODataHandlerException("HTTP method " + method + " is not allowed.",
ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, method.toString());
}
} else {
if (method == HttpMethod.GET) {
final ContentType requestedContentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
request, customContentTypeSupport, RepresentationType.MEDIA);
selectProcessor(MediaEntityProcessor.class)
.readMediaEntity(request, response, uriInfo, requestedContentType);
} else if (method == HttpMethod.PUT) {
final ContentType requestFormat = ContentType.parse(request.getHeader(HttpHeader.CONTENT_TYPE));
final ContentType responseFormat = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
request, customContentTypeSupport, RepresentationType.ENTITY);
selectProcessor(MediaEntityProcessor.class)
.updateMediaEntity(request, response, uriInfo, requestFormat, responseFormat);
} else if (method == HttpMethod.DELETE) {
selectProcessor(MediaEntityProcessor.class).deleteEntity(request, response, uriInfo);
} else {
throw new ODataHandlerException("HTTP method " + method + " is not allowed.",
ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, method.toString());
}
}
}
private void handleComplexPropertyDispatching(final ODataRequest request, final ODataResponse response,
final boolean isAction, final boolean isCollection)
throws ContentNegotiatorException, ODataApplicationException, SerializerException, ODataHandlerException,
DeserializerException {
final HttpMethod method = request.getMethod();
final RepresentationType complexRepresentationType = isCollection ?
RepresentationType.COLLECTION_COMPLEX : RepresentationType.COMPLEX;
if (method == HttpMethod.GET) {
final ContentType requestedContentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
request, customContentTypeSupport, complexRepresentationType);
if (complexRepresentationType == RepresentationType.COMPLEX) {
selectProcessor(ComplexProcessor.class)
.readComplex(request, response, uriInfo, requestedContentType);
} else {
selectProcessor(ComplexCollectionProcessor.class)
.readComplexCollection(request, response, uriInfo, requestedContentType);
}
} else if (method == HttpMethod.PUT || method == HttpMethod.PATCH) {
final ContentType requestFormat = ContentType.parse(request.getHeader(HttpHeader.CONTENT_TYPE));
checkContentTypeSupport(requestFormat, complexRepresentationType);
final ContentType responseFormat = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
request, customContentTypeSupport, complexRepresentationType);
if (complexRepresentationType == RepresentationType.COMPLEX) {
selectProcessor(ComplexProcessor.class)
.updateComplex(request, response, uriInfo, requestFormat, responseFormat);
} else {
selectProcessor(ComplexCollectionProcessor.class)
.updateComplexCollection(request, response, uriInfo, requestFormat, responseFormat);
}
} else if (method == HttpMethod.POST && isAction) {
final ContentType requestFormat = ContentType.parse(request.getHeader(HttpHeader.CONTENT_TYPE));
checkContentTypeSupport(requestFormat, complexRepresentationType);
final ContentType responseFormat = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
request, customContentTypeSupport, complexRepresentationType);
if (complexRepresentationType == RepresentationType.COMPLEX) {
selectProcessor(ActionComplexProcessor.class)
.processActionComplex(request, response, uriInfo, requestFormat, responseFormat);
} else {
selectProcessor(ActionComplexCollectionProcessor.class)
.processActionComplexCollection(request, response, uriInfo, requestFormat, responseFormat);
}
} else if (method == HttpMethod.DELETE) {
if (complexRepresentationType == RepresentationType.COMPLEX) {
selectProcessor(ComplexProcessor.class).deleteComplex(request, response, uriInfo);
} else {
selectProcessor(ComplexCollectionProcessor.class).deleteComplexCollection(request, response, uriInfo);
}
} else {
throw new ODataHandlerException("HTTP method " + method + " is not allowed.",
ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, method.toString());
}
}
private void handlePrimitivePropertyDispatching(final ODataRequest request, final ODataResponse response,
boolean isAction, final boolean isCollection)
throws ContentNegotiatorException, ODataApplicationException, SerializerException, ODataHandlerException,
DeserializerException {
final HttpMethod method = request.getMethod();
final RepresentationType representationType = isCollection ?
RepresentationType.COLLECTION_PRIMITIVE : RepresentationType.PRIMITIVE;
if (method == HttpMethod.GET) {
final ContentType requestedContentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
request, customContentTypeSupport, representationType);
if (representationType == RepresentationType.PRIMITIVE) {
selectProcessor(PrimitiveProcessor.class).readPrimitive(request, response, uriInfo, requestedContentType);
} else {
selectProcessor(PrimitiveCollectionProcessor.class)
.readPrimitiveCollection(request, response, uriInfo, requestedContentType);
}
} else if (method == HttpMethod.PUT || method == HttpMethod.PATCH) {
final ContentType requestFormat = ContentType.parse(request.getHeader(HttpHeader.CONTENT_TYPE));
checkContentTypeSupport(requestFormat, representationType);
final ContentType responseFormat = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
request, customContentTypeSupport, representationType);
if (representationType == RepresentationType.PRIMITIVE) {
selectProcessor(PrimitiveProcessor.class)
.updatePrimitive(request, response, uriInfo, requestFormat, responseFormat);
} else {
selectProcessor(PrimitiveCollectionProcessor.class)
.updatePrimitiveCollection(request, response, uriInfo, requestFormat, responseFormat);
}
} else if (method == HttpMethod.DELETE) {
if (representationType == RepresentationType.PRIMITIVE) {
selectProcessor(PrimitiveProcessor.class).deletePrimitive(request, response, uriInfo);
} else {
selectProcessor(PrimitiveCollectionProcessor.class).deletePrimitiveCollection(request, response, uriInfo);
}
} else if (method == HttpMethod.POST && isAction) {
final ContentType requestFormat = ContentType.parse(request.getHeader(HttpHeader.CONTENT_TYPE));
checkContentTypeSupport(requestFormat, representationType);
final ContentType responseFormat = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
request, customContentTypeSupport, representationType);
if (representationType == RepresentationType.PRIMITIVE) {
selectProcessor(ActionPrimitiveProcessor.class)
.processActionPrimitive(request, response, uriInfo, requestFormat, responseFormat);
} else {
selectProcessor(ActionPrimitiveCollectionProcessor.class)
.processActionPrimitiveCollection(request, response, uriInfo, requestFormat, responseFormat);
}
} else {
throw new ODataHandlerException("HTTP method " + method + " is not allowed.",
ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, method.toString());
}
}
private void handleCountDispatching(final ODataRequest request, final ODataResponse response,
final int lastPathSegmentIndex)
throws ODataApplicationException, SerializerException, ODataHandlerException {
final HttpMethod method = request.getMethod();
if (method == HttpMethod.GET) {
final UriResource resource = uriInfo.getUriResourceParts().get(lastPathSegmentIndex - 1);
if (resource instanceof UriResourceEntitySet || resource instanceof UriResourceNavigation) {
selectProcessor(CountEntityCollectionProcessor.class)
.countEntityCollection(request, response, uriInfo);
} else if (resource instanceof UriResourcePrimitiveProperty) {
selectProcessor(CountPrimitiveCollectionProcessor.class)
.countPrimitiveCollection(request, response, uriInfo);
} else {
selectProcessor(CountComplexCollectionProcessor.class)
.countComplexCollection(request, response, uriInfo);
}
} else {
throw new ODataHandlerException("HTTP method " + method + " is not allowed for count.",
ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, method.toString());
}
}
private void handleEntityDispatching(final ODataRequest request, final ODataResponse response,
final UriResourcePartTyped uriResourcePart)
throws ContentNegotiatorException, ODataApplicationException, SerializerException, ODataHandlerException,
DeserializerException {
handleEntityDispatching(request, response, uriResourcePart.isCollection(), isMedia(uriResourcePart), false);
}
private void handleEntityDispatching(final ODataRequest request, final ODataResponse response,
final boolean isCollection, final boolean isMedia, boolean isAction)
throws ContentNegotiatorException, ODataApplicationException, SerializerException, ODataHandlerException,
DeserializerException {
final HttpMethod method = request.getMethod();
if (isCollection) {
if (method == HttpMethod.GET) {
final ContentType requestedContentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
request, customContentTypeSupport, RepresentationType.COLLECTION_ENTITY);
selectProcessor(EntityCollectionProcessor.class)
.readEntityCollection(request, response, uriInfo, requestedContentType);
} else if (method == HttpMethod.POST) {
final ContentType requestFormat = ContentType.parse(request.getHeader(HttpHeader.CONTENT_TYPE));
if (isMedia) {
final ContentType responseFormat = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
request, customContentTypeSupport, RepresentationType.ENTITY);
selectProcessor(MediaEntityProcessor.class)
.updateMediaEntity(request, response, uriInfo, requestFormat, responseFormat);
} else if (method == HttpMethod.DELETE) {
selectProcessor(MediaEntityProcessor.class)
.deleteEntity(request, response, uriInfo);
} else {
throw new ODataHandlerException("HTTP method " + method + " is not allowed.",
ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, method.toString());
}
}
break;
case ref:
if (((UriResourcePartTyped) uriInfo.getUriResourceParts().get(lastPathSegmentIndex - 1)).isCollection()) {
if (method == HttpMethod.GET) {
.createMediaEntity(request, response, uriInfo, requestFormat, responseFormat);
} else if(isAction) {
checkContentTypeSupport(requestFormat, RepresentationType.ENTITY);
final ContentType responseFormat = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
request, customContentTypeSupport, RepresentationType.COLLECTION_REFERENCE);
selectProcessor(ReferenceCollectionProcessor.class)
.readReferenceCollection(request, response, uriInfo, responseFormat);
} else if (method == HttpMethod.POST) {
final ContentType requestFormat = ContentType.parse(request.getHeader(HttpHeader.CONTENT_TYPE));
ContentNegotiator.checkSupport(requestFormat, customContentTypeSupport, RepresentationType.REFERENCE);
selectProcessor(ReferenceProcessor.class)
.createReference(request, response, uriInfo, requestFormat);
request, customContentTypeSupport, RepresentationType.ENTITY);
selectProcessor(ActionEntityCollectionProcessor.class)
.processActionEntityCollection(request, response, uriInfo, requestFormat, responseFormat);
} else {
throw new ODataHandlerException("HTTP method " + method + " is not allowed.",
ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, method.toString());
checkContentTypeSupport(requestFormat, RepresentationType.ENTITY);
final ContentType responseFormat = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
request, customContentTypeSupport, RepresentationType.ENTITY);
selectProcessor(EntityProcessor.class)
.createEntity(request, response, uriInfo, requestFormat, responseFormat);
}
} else {
if (method == HttpMethod.GET) {
final ContentType responseFormat = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
request, customContentTypeSupport, RepresentationType.REFERENCE);
selectProcessor(ReferenceProcessor.class)
.readReference(request, response, uriInfo, responseFormat);
} else if (method == HttpMethod.PUT || method == HttpMethod.PATCH) {
final ContentType requestFormat = ContentType.parse(request.getHeader(HttpHeader.CONTENT_TYPE));
ContentNegotiator.checkSupport(requestFormat, customContentTypeSupport, RepresentationType.REFERENCE);
selectProcessor(ReferenceProcessor.class)
.updateReference(request, response, uriInfo, requestFormat);
} else if (method == HttpMethod.DELETE) {
selectProcessor(ReferenceProcessor.class)
.deleteReference(request, response, uriInfo);
} else {
throw new ODataHandlerException("HTTP method " + method + " is not allowed.",
ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, method.toString());
}
throw new ODataHandlerException("HTTP method " + method + " is not allowed.",
ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, method.toString());
}
break;
} else {
if (method == HttpMethod.GET) {
final ContentType requestedContentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
request, customContentTypeSupport, RepresentationType.ENTITY);
default:
throw new ODataHandlerException("not implemented",
ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
selectProcessor(EntityProcessor.class).readEntity(request, response, uriInfo, requestedContentType);
} else if (method == HttpMethod.PUT || method == HttpMethod.PATCH) {
final ContentType requestFormat = ContentType.parse(request.getHeader(HttpHeader.CONTENT_TYPE));
checkContentTypeSupport(requestFormat, RepresentationType.ENTITY);
final ContentType responseFormat = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
request, customContentTypeSupport, RepresentationType.ENTITY);
selectProcessor(EntityProcessor.class).updateEntity(request, response, uriInfo, requestFormat, responseFormat);
} else if (method == HttpMethod.POST && isAction) {
final ContentType requestFormat = ContentType.parse(request.getHeader(HttpHeader.CONTENT_TYPE));
checkContentTypeSupport(requestFormat, RepresentationType.ENTITY);
final ContentType responseFormat = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
request, customContentTypeSupport, RepresentationType.ENTITY);
selectProcessor(ActionEntityProcessor.class).processActionEntity(
request, response, uriInfo, requestFormat, responseFormat);
} else if (method == HttpMethod.DELETE) {
selectProcessor(isMedia ? MediaEntityProcessor.class : EntityProcessor.class)
.deleteEntity(request, response, uriInfo);
} else {
throw new ODataHandlerException("HTTP method " + method + " is not allowed.",
ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, method.toString());
}
}
}
private void checkContentTypeSupport(ContentType requestFormat, RepresentationType representationType)
throws ODataHandlerException, ContentNegotiatorException {
if (!ContentNegotiator.isSupported(requestFormat, customContentTypeSupport, representationType)) {
final String contentTypeString = requestFormat.toContentTypeString();
throw new ODataHandlerException("ContentType " + contentTypeString + " is not supported.",
ODataHandlerException.MessageKeys.UNSUPPORTED_CONTENT_TYPE, contentTypeString);
}
}
private void validateODataVersion(final ODataRequest request, final ODataResponse response)
throws ODataHandlerException {
throws ODataHandlerException {
final String maxVersion = request.getHeader(HttpHeader.ODATA_MAX_VERSION);
response.setHeader(HttpHeader.ODATA_VERSION, ODataServiceVersion.V40.toString());
if (maxVersion != null) {
if (ODataServiceVersion.isBiggerThan(ODataServiceVersion.V40.toString(), maxVersion)) {
throw new ODataHandlerException("ODataVersion not supported: " + maxVersion,
ODataHandlerException.MessageKeys.ODATA_VERSION_NOT_SUPPORTED, maxVersion);
ODataHandlerException.MessageKeys.ODATA_VERSION_NOT_SUPPORTED, maxVersion);
}
}
}
private boolean isMedia(final UriResource pathSegment) {
return pathSegment instanceof UriResourceEntitySet
&& ((UriResourceEntitySet) pathSegment).getEntityType().hasStream()
|| pathSegment instanceof UriResourceNavigation
&& ((EdmEntityType) ((UriResourceNavigation) pathSegment).getType()).hasStream();
&& ((UriResourceEntitySet) pathSegment).getEntityType().hasStream()
|| pathSegment instanceof UriResourceNavigation
&& ((EdmEntityType) ((UriResourceNavigation) pathSegment).getType()).hasStream();
}
private <T extends Processor> T selectProcessor(final Class<T> cls) throws ODataHandlerException {
@ -491,7 +686,7 @@ public class ODataHandler {
}
}
throw new ODataHandlerException("Processor: " + cls.getSimpleName() + " not registered.",
ODataHandlerException.MessageKeys.PROCESSOR_NOT_IMPLEMENTED, cls.getSimpleName());
ODataHandlerException.MessageKeys.PROCESSOR_NOT_IMPLEMENTED, cls.getSimpleName());
}
public void register(final Processor processor) {

View File

@ -29,7 +29,8 @@ public class ODataHandlerException extends ODataTranslatedException {
/** parameter: HTTP method */ INVALID_HTTP_METHOD,
/** parameter: HTTP method */ HTTP_METHOD_NOT_ALLOWED,
/** parameter: processor interface */ PROCESSOR_NOT_IMPLEMENTED,
FUNCTIONALITY_NOT_IMPLEMENTED,
/** no parameter */ FUNCTIONALITY_NOT_IMPLEMENTED,
/** parameter: content type */ UNSUPPORTED_CONTENT_TYPE,
/** parameter: version */ ODATA_VERSION_NOT_SUPPORTED;
@Override

View File

@ -24,6 +24,7 @@ ODataHandlerException.HTTP_METHOD_NOT_ALLOWED=HTTP method '%1$s' not allowed for
ODataHandlerException.PROCESSOR_NOT_IMPLEMENTED=No processor for interface '%1$s' registered.
ODataHandlerException.FUNCTIONALITY_NOT_IMPLEMENTED=The requested functionality has not been implemented (yet).
ODataHandlerException.ODATA_VERSION_NOT_SUPPORTED=OData version '%1$s' is not supported.
ODataHandlerException.UNSUPPORTED_CONTENT_TYPE=The content type '%1$s' is not supported for this request.
UriParserSyntaxException.MUST_BE_LAST_SEGMENT=The segment '%1$s' must be the last segment.
UriParserSyntaxException.UNKNOWN_SYSTEM_QUERY_OPTION=The system query option '%1$s' is not defined.

View File

@ -35,6 +35,8 @@ import org.apache.olingo.server.api.ODataApplicationException;
import org.apache.olingo.server.api.ODataRequest;
import org.apache.olingo.server.api.ODataResponse;
import org.apache.olingo.server.api.deserializer.DeserializerException;
import org.apache.olingo.server.api.processor.ActionEntityCollectionProcessor;
import org.apache.olingo.server.api.processor.ActionEntityProcessor;
import org.apache.olingo.server.api.processor.CountEntityCollectionProcessor;
import org.apache.olingo.server.api.processor.EntityCollectionProcessor;
import org.apache.olingo.server.api.processor.EntityProcessor;
@ -55,7 +57,8 @@ import org.apache.olingo.server.tecsvc.data.DataProvider;
* Technical Processor for entity-related functionality.
*/
public class TechnicalEntityProcessor extends TechnicalProcessor
implements EntityCollectionProcessor, CountEntityCollectionProcessor, EntityProcessor, MediaEntityProcessor {
implements EntityCollectionProcessor, ActionEntityCollectionProcessor, CountEntityCollectionProcessor,
EntityProcessor, ActionEntityProcessor, MediaEntityProcessor {
public TechnicalEntityProcessor(final DataProvider dataProvider) {
super(dataProvider);
@ -89,6 +92,15 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
}
}
@Override
public void processActionEntityCollection(final ODataRequest request, final ODataResponse response,
final UriInfo uriInfo,
final ContentType requestFormat, final ContentType responseFormat)
throws ODataApplicationException, DeserializerException, SerializerException {
throw new ODataApplicationException("Process entity collection is not supported yet.",
HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ROOT);
}
@Override
public void countEntityCollection(final ODataRequest request, ODataResponse response, final UriInfo uriInfo)
throws ODataApplicationException, SerializerException {
@ -247,6 +259,15 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
}
}
@Override
public void processActionEntity(final ODataRequest request, final ODataResponse response,
final UriInfo uriInfo, final ContentType requestFormat,
final ContentType responseFormat)
throws ODataApplicationException, DeserializerException, SerializerException {
throw new ODataApplicationException("Process entity is not supported yet.",
HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ROOT);
}
private void blockNavigation(final UriInfo uriInfo) throws ODataApplicationException {
final List<UriResource> parts = uriInfo.asUriInfoResource().getUriResourceParts();
if (parts.size() > 2

View File

@ -41,6 +41,10 @@ import org.apache.olingo.server.api.ODataApplicationException;
import org.apache.olingo.server.api.ODataRequest;
import org.apache.olingo.server.api.ODataResponse;
import org.apache.olingo.server.api.deserializer.DeserializerException;
import org.apache.olingo.server.api.processor.ActionComplexCollectionProcessor;
import org.apache.olingo.server.api.processor.ActionComplexProcessor;
import org.apache.olingo.server.api.processor.ActionPrimitiveCollectionProcessor;
import org.apache.olingo.server.api.processor.ActionPrimitiveProcessor;
import org.apache.olingo.server.api.processor.ComplexCollectionProcessor;
import org.apache.olingo.server.api.processor.ComplexProcessor;
import org.apache.olingo.server.api.processor.PrimitiveCollectionProcessor;
@ -68,8 +72,10 @@ import org.apache.olingo.server.tecsvc.data.DataProvider;
* Technical Processor which provides functionality related to primitive and complex types and collections thereof.
*/
public class TechnicalPrimitiveComplexProcessor extends TechnicalProcessor
implements PrimitiveProcessor, PrimitiveValueProcessor, PrimitiveCollectionProcessor,
ComplexProcessor, ComplexCollectionProcessor {
implements PrimitiveProcessor, PrimitiveValueProcessor, ActionPrimitiveProcessor,
PrimitiveCollectionProcessor, ActionPrimitiveCollectionProcessor,
ComplexProcessor, ActionComplexProcessor,
ComplexCollectionProcessor, ActionComplexCollectionProcessor {
public TechnicalPrimitiveComplexProcessor(final DataProvider dataProvider) {
super(dataProvider);
@ -95,6 +101,15 @@ public class TechnicalPrimitiveComplexProcessor extends TechnicalProcessor
deleteProperty(response, uriInfo);
}
@Override
public void processActionPrimitive(final ODataRequest request, final ODataResponse response,
final UriInfo uriInfo,
final ContentType requestFormat, final ContentType responseFormat)
throws ODataApplicationException, DeserializerException, SerializerException {
throw new ODataApplicationException("Not supported yet.",
HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ROOT);
}
@Override
public void readPrimitiveCollection(final ODataRequest request, ODataResponse response, final UriInfo uriInfo,
final ContentType contentType) throws ODataApplicationException, SerializerException {
@ -115,6 +130,16 @@ public class TechnicalPrimitiveComplexProcessor extends TechnicalProcessor
deleteProperty(response, uriInfo);
}
@Override
public void processActionPrimitiveCollection(final ODataRequest request, final ODataResponse response,
final UriInfo uriInfo,
final ContentType requestFormat, final ContentType responseFormat)
throws ODataApplicationException, DeserializerException,
SerializerException {
throw new ODataApplicationException("Not supported yet.",
HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ROOT);
}
@Override
public void readComplex(final ODataRequest request, ODataResponse response, final UriInfo uriInfo,
final ContentType contentType) throws ODataApplicationException, SerializerException {
@ -129,6 +154,14 @@ public class TechnicalPrimitiveComplexProcessor extends TechnicalProcessor
HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ROOT);
}
@Override
public void processActionComplex(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType
requestFormat, ContentType responseFormat) throws ODataApplicationException, DeserializerException,
SerializerException {
throw new ODataApplicationException("Not supported yet.",
HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ROOT);
}
@Override
public void deleteComplex(final ODataRequest request, final ODataResponse response, final UriInfo uriInfo)
throws ODataApplicationException {
@ -149,6 +182,15 @@ public class TechnicalPrimitiveComplexProcessor extends TechnicalProcessor
HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ROOT);
}
@Override
public void processActionComplexCollection(ODataRequest request, ODataResponse response,
UriInfo uriInfo, ContentType requestFormat,
ContentType responseFormat)
throws ODataApplicationException, DeserializerException, SerializerException {
throw new ODataApplicationException("Not supported yet.",
HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ROOT);
}
@Override
public void deleteComplexCollection(final ODataRequest request, ODataResponse response, final UriInfo uriInfo)
throws ODataApplicationException {
@ -190,28 +232,28 @@ public class TechnicalPrimitiveComplexProcessor extends TechnicalProcessor
helper.buildContextURLSelectList((EdmStructuredType) edmProperty.getType(), expand, select))
.build();
switch (representationType) {
case PRIMITIVE:
response.setContent(serializer.primitive((EdmPrimitiveType) edmProperty.getType(), property,
PrimitiveSerializerOptions.with().contextURL(contextURL).facetsFrom(edmProperty).build()));
break;
case COMPLEX:
response.setContent(serializer.complex((EdmComplexType) edmProperty.getType(), property,
ComplexSerializerOptions.with().contextURL(contextURL)
.expand(expand).select(select)
.build()));
break;
case COLLECTION_PRIMITIVE:
response.setContent(serializer.primitiveCollection((EdmPrimitiveType) edmProperty.getType(), property,
PrimitiveSerializerOptions.with().contextURL(contextURL).facetsFrom(edmProperty).build()));
break;
case COLLECTION_COMPLEX:
response.setContent(serializer.complexCollection((EdmComplexType) edmProperty.getType(), property,
ComplexSerializerOptions.with().contextURL(contextURL)
.expand(expand).select(select)
.build()));
break;
default:
break;
case PRIMITIVE:
response.setContent(serializer.primitive((EdmPrimitiveType) edmProperty.getType(), property,
PrimitiveSerializerOptions.with().contextURL(contextURL).facetsFrom(edmProperty).build()));
break;
case COMPLEX:
response.setContent(serializer.complex((EdmComplexType) edmProperty.getType(), property,
ComplexSerializerOptions.with().contextURL(contextURL)
.expand(expand).select(select)
.build()));
break;
case COLLECTION_PRIMITIVE:
response.setContent(serializer.primitiveCollection((EdmPrimitiveType) edmProperty.getType(), property,
PrimitiveSerializerOptions.with().contextURL(contextURL).facetsFrom(edmProperty).build()));
break;
case COLLECTION_COMPLEX:
response.setContent(serializer.complexCollection((EdmComplexType) edmProperty.getType(), property,
ComplexSerializerOptions.with().contextURL(contextURL)
.expand(expand).select(select)
.build()));
break;
default:
break;
}
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, contentType.toContentTypeString());
@ -239,7 +281,7 @@ public class TechnicalPrimitiveComplexProcessor extends TechnicalProcessor
}
private Property getPropertyData(final UriResourceEntitySet resourceEntitySet, final List<String> path)
throws ODataApplicationException {
throws ODataApplicationException {
final Entity entity = dataProvider.read(resourceEntitySet.getEntitySet(), resourceEntitySet.getKeyPredicates());
if (entity == null) {
throw new ODataApplicationException("Nothing found.", HttpStatusCode.NOT_FOUND.getStatusCode(), Locale.ROOT);

View File

@ -21,6 +21,7 @@ package org.apache.olingo.server.tecsvc.provider;
import org.apache.olingo.commons.api.ODataException;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.server.api.edm.provider.Action;
import org.apache.olingo.server.api.edm.provider.ComplexType;
import org.apache.olingo.server.api.edm.provider.Parameter;
import org.apache.olingo.server.api.edm.provider.ReturnType;
@ -46,78 +47,91 @@ public class ActionProvider {
new FullQualifiedName(SchemaProvider.NAMESPACE, "BAETTwoKeyNavRTETTwoKeyNav");
// Unbound Actions
public static final FullQualifiedName nameUARTCompCollParam = new FullQualifiedName(SchemaProvider.NAMESPACE,
"UARTCompCollParam");
public static final FullQualifiedName nameUARTCompParam = new FullQualifiedName(SchemaProvider.NAMESPACE,
"UARTCompParam");
public static final FullQualifiedName nameUARTESParam =
new FullQualifiedName(SchemaProvider.NAMESPACE, "UARTESParam");
public static final FullQualifiedName nameUARTString = new FullQualifiedName(SchemaProvider.NAMESPACE,
"UARTString");
public static final FullQualifiedName nameUARTCollStringTwoParam = new FullQualifiedName(SchemaProvider.NAMESPACE,
"UARTCollStringTwoParam");
public static final FullQualifiedName nameUARTCollCTTwoPrimParam = new FullQualifiedName(SchemaProvider.NAMESPACE,
"UARTCollCTTwoPrimParam");
public static final FullQualifiedName nameUARTCTTwoPrimParam = new FullQualifiedName(SchemaProvider.NAMESPACE,
"UARTCTTwoPrimParam");
public static final FullQualifiedName nameUARTETTwoKeyTwoPrimParam =
new FullQualifiedName(SchemaProvider.NAMESPACE, "UARTETTwoKeyTwoPrimParam");
public static final FullQualifiedName nameUARTCollETKeyNavParam =
new FullQualifiedName(SchemaProvider.NAMESPACE, "UARTCollETKeyNavParam");
public static final FullQualifiedName nameUARTETAllPrimParam =
new FullQualifiedName(SchemaProvider.NAMESPACE, "UARTETAllPrimParam");
public static final FullQualifiedName nameUARTCollETAllPrimParam =
new FullQualifiedName(SchemaProvider.NAMESPACE, "UARTCollETAllPrimParam");
public static final FullQualifiedName nameUARTETParam =
new FullQualifiedName(SchemaProvider.NAMESPACE, "UARTETParam");
public static final FullQualifiedName nameUARTPrimParam = new FullQualifiedName(SchemaProvider.NAMESPACE,
"UARTPrimParam");
public static final FullQualifiedName nameUARTPrimCollParam = new FullQualifiedName(SchemaProvider.NAMESPACE,
"UARTPrimCollParam");
public List<Action> getActions(final FullQualifiedName actionName) throws ODataException {
if (actionName.equals(nameUARTPrimParam)) {
if (actionName.equals(nameUARTString)) {
return Arrays.asList(
new Action().setName("UARTPrimParam")
.setParameters(Arrays.asList(
new Parameter().setName("ParameterInt16").setType(PropertyProvider.nameInt16)))
new Action().setName(nameUARTString.getName())
.setReturnType(new ReturnType().setType(PropertyProvider.nameString))
);
} else if (actionName.equals(nameUARTCollStringTwoParam)) {
return Arrays.asList(
new Action().setName(nameUARTCollStringTwoParam.getName())
.setParameters(Arrays.asList(
new Parameter().setName("ParameterInt16").setType(PropertyProvider.nameInt16)))
.setReturnType(new ReturnType().setType(PropertyProvider.nameString).setCollection(true))
);
.setReturnType(new ReturnType().setType(PropertyProvider.nameString))
} else if (actionName.equals(nameUARTCTTwoPrimParam)) {
return Arrays.asList(
new Action().setName(nameUARTCTTwoPrimParam.getName())
.setParameters(Arrays.asList(
new Parameter().setName("ParameterInt16").setType(PropertyProvider.nameInt16)))
.setReturnType(
new ReturnType().setType(ComplexTypeProvider.nameCTTwoPrim))
);
} else if (actionName.equals(nameUARTCollCTTwoPrimParam)) {
return Arrays.asList(
new Action().setName(nameUARTCollCTTwoPrimParam.getName())
.setParameters(Arrays.asList(
new Parameter().setName("ParameterInt16").setType(PropertyProvider.nameInt16)))
.setReturnType(
new ReturnType().setType(ComplexTypeProvider.nameCTTwoPrim).setCollection(true))
);
} else if (actionName.equals(nameUARTETTwoKeyTwoPrimParam)) {
return Arrays.asList(
new Action().setName(nameUARTETTwoKeyTwoPrimParam.getName())
.setParameters(Arrays.asList(
new Parameter().setName("ParameterInt16").setType(PropertyProvider.nameInt16)))
.setReturnType(
new ReturnType().setType(EntityTypeProvider.nameETTwoKeyTwoPrim))
);
} else if (actionName.equals(nameUARTCollETKeyNavParam)) {
return Arrays.asList(
new Action().setName(nameUARTCollETKeyNavParam.getName())
.setParameters(Arrays.asList(
new Parameter().setName("ParameterInt16").setType(PropertyProvider.nameInt16)))
.setReturnType(
new ReturnType().setType(EntityTypeProvider.nameETKeyNav).setCollection(true))
);
} else if (actionName.equals(nameUARTPrimCollParam)) {
} else if (actionName.equals(nameUARTETAllPrimParam)) {
return Arrays.asList(
new Action().setName("UARTPrimCollParam")
.setParameters(Arrays.asList(
new Parameter().setName("ParameterInt16").setType(PropertyProvider.nameInt16)))
.setReturnType(
new ReturnType().setType(PropertyProvider.nameString).setCollection(true))
new Action().setName(nameUARTETAllPrimParam.getName())
.setParameters(Arrays.asList(
new Parameter().setName("ParameterDate").setType(PropertyProvider.nameDate)))
.setReturnType(
new ReturnType().setType(EntityTypeProvider.nameETAllPrim))
);
} else if (actionName.equals(nameUARTCompParam)) {
} else if (actionName.equals(nameUARTCollETAllPrimParam)) {
return Arrays.asList(
new Action().setName("UARTCompParam")
.setParameters(Arrays.asList(
new Parameter().setName("ParameterInt16").setType(PropertyProvider.nameInt16)))
.setReturnType(
new ReturnType().setType(ComplexTypeProvider.nameCTTwoPrim))
);
} else if (actionName.equals(nameUARTCompCollParam)) {
return Arrays.asList(
new Action().setName("UARTCompCollParam")
.setParameters(Arrays.asList(
new Parameter().setName("ParameterInt16").setType(PropertyProvider.nameInt16)))
.setReturnType(
new ReturnType().setType(ComplexTypeProvider.nameCTTwoPrim).setCollection(true))
);
} else if (actionName.equals(nameUARTETParam)) {
return Arrays.asList(
new Action().setName("UARTETParam")
.setParameters(Arrays.asList(
new Parameter().setName("ParameterInt16").setType(PropertyProvider.nameInt16)))
.setReturnType(
new ReturnType().setType(EntityTypeProvider.nameETTwoKeyTwoPrim))
);
} else if (actionName.equals(nameUARTESParam)) {
return Arrays.asList(
new Action().setName("UARTESParam")
.setParameters(Arrays.asList(
new Parameter().setName("ParameterInt16").setType(PropertyProvider.nameInt16)))
.setReturnType(
new ReturnType().setType(EntityTypeProvider.nameETKeyNav).setCollection(true))
);
new Action().setName(nameUARTCollETAllPrimParam.getName())
.setParameters(Arrays.asList(
new Parameter().setName("ParameterTimeOfDay").setType(PropertyProvider.nameInt16)))
.setReturnType(
new ReturnType().setType(EntityTypeProvider.nameETAllPrim).setCollection(true))
);
} else if (actionName.equals(nameBAETTwoKeyNavRTETTwoKeyNav)) {
return Arrays.asList(

View File

@ -36,6 +36,14 @@ import java.util.List;
public class ContainerProvider {
public static final FullQualifiedName nameContainer = new FullQualifiedName(SchemaProvider.NAMESPACE, "Container");
public static final String AIRT_STRING = "AIRTString";
public static final String AIRT_COLL_STRING_TWO_PARAM = "AIRTCollStringTwoParam";
public static final String AIRTCT_TWO_PRIM_PARAM = "AIRTCTTwoPrimParam";
public static final String AIRT_COLL_CT_TWO_PRIM_PARAM = "AIRTCollCTTwoPrimParam";
public static final String AIRTET_TWO_KEY_TWO_PRIM_PARAM = "AIRTETTwoKeyTwoPrimParam";
public static final String AIRT_COLL_ET_KEY_NAV_PARAM = "AIRTCollETKeyNavParam";
public static final String AIRTES_ALL_PRIM_PARAM = "AIRTESAllPrimParam";
public static final String AIRT_COLL_ES_ALL_PRIM_PARAM = "AIRTCollESAllPrimParam";
EntityContainerInfo entityContainerInfoTest1 =
new EntityContainerInfo().setContainerName(nameContainer);
@ -98,12 +106,14 @@ public class ContainerProvider {
// ActionImports
List<ActionImport> actionImports = new ArrayList<ActionImport>();
container.setActionImports(actionImports);
actionImports.add(prov.getActionImport(ContainerProvider.nameContainer, "AIRTPrimParam"));
actionImports.add(prov.getActionImport(ContainerProvider.nameContainer, "AIRTPrimCollParam"));
actionImports.add(prov.getActionImport(ContainerProvider.nameContainer, "AIRTCompParam"));
actionImports.add(prov.getActionImport(ContainerProvider.nameContainer, "AIRTCompCollParam"));
actionImports.add(prov.getActionImport(ContainerProvider.nameContainer, "AIRTETParam"));
actionImports.add(prov.getActionImport(ContainerProvider.nameContainer, "AIRTETCollAllPrimParam"));
actionImports.add(prov.getActionImport(ContainerProvider.nameContainer, AIRT_STRING));
actionImports.add(prov.getActionImport(ContainerProvider.nameContainer, AIRT_COLL_STRING_TWO_PARAM));
actionImports.add(prov.getActionImport(ContainerProvider.nameContainer, AIRTCT_TWO_PRIM_PARAM));
actionImports.add(prov.getActionImport(ContainerProvider.nameContainer, AIRT_COLL_CT_TWO_PRIM_PARAM));
actionImports.add(prov.getActionImport(ContainerProvider.nameContainer, AIRTET_TWO_KEY_TWO_PRIM_PARAM));
actionImports.add(prov.getActionImport(ContainerProvider.nameContainer, AIRT_COLL_ET_KEY_NAV_PARAM));
actionImports.add(prov.getActionImport(ContainerProvider.nameContainer, AIRTES_ALL_PRIM_PARAM));
actionImports.add(prov.getActionImport(ContainerProvider.nameContainer, AIRT_COLL_ES_ALL_PRIM_PARAM));
// FunctionImports
List<FunctionImport> functionImports = new ArrayList<FunctionImport>();
@ -258,38 +268,48 @@ public class ContainerProvider {
return null;
}
public ActionImport getActionImport(final FullQualifiedName entityContainer, final String name) throws ODataException
{
public ActionImport getActionImport(final FullQualifiedName entityContainer, final String name)
throws ODataException {
if (entityContainer.equals(nameContainer)) {
if (name.equals("AIRTPrimParam")) {
if (name.equals(AIRT_STRING)) {
return new ActionImport()
.setName("AIRTPrimParam")
.setAction(ActionProvider.nameUARTPrimParam);
.setName(AIRT_STRING)
.setAction(ActionProvider.nameUARTString);
} else if (name.equals("AIRTPrimCollParam")) {
} else if (name.equals(AIRT_COLL_STRING_TWO_PARAM)) {
return new ActionImport()
.setName("AIRTPrimCollParam")
.setAction(ActionProvider.nameUARTPrimCollParam);
.setName(AIRT_COLL_STRING_TWO_PARAM)
.setAction(ActionProvider.nameUARTCollStringTwoParam);
} else if (name.equals("AIRTCompParam")) {
} else if (name.equals(AIRTCT_TWO_PRIM_PARAM)) {
return new ActionImport()
.setName("AIRTCompParam")
.setAction(ActionProvider.nameUARTCompParam);
.setName(AIRTCT_TWO_PRIM_PARAM)
.setAction(ActionProvider.nameUARTCTTwoPrimParam);
} else if (name.equals("AIRTCompCollParam")) {
} else if (name.equals(AIRT_COLL_CT_TWO_PRIM_PARAM)) {
return new ActionImport()
.setName("AIRTCompCollParam")
.setAction(ActionProvider.nameUARTCompCollParam);
.setName(AIRT_COLL_CT_TWO_PRIM_PARAM)
.setAction(ActionProvider.nameUARTCollCTTwoPrimParam);
} else if (name.equals("AIRTETParam")) {
} else if (name.equals(AIRTET_TWO_KEY_TWO_PRIM_PARAM)) {
return new ActionImport()
.setName("AIRTETParam")
.setAction(ActionProvider.nameUARTETParam);
.setName(AIRTET_TWO_KEY_TWO_PRIM_PARAM)
.setAction(ActionProvider.nameUARTETTwoKeyTwoPrimParam);
} else if (name.equals("AIRTETCollAllPrimParam")) {
} else if (name.equals(AIRT_COLL_ET_KEY_NAV_PARAM)) {
return new ActionImport()
.setName("AIRTETCollAllPrimParam")
.setAction(ActionProvider.nameUARTESParam);
.setName(AIRT_COLL_ET_KEY_NAV_PARAM)
.setAction(ActionProvider.nameUARTCollETKeyNavParam);
} else if (name.equals(AIRTES_ALL_PRIM_PARAM)) {
return new ActionImport()
.setName(AIRTES_ALL_PRIM_PARAM)
.setAction(ActionProvider.nameUARTETAllPrimParam);
} else if (name.equals(AIRT_COLL_ES_ALL_PRIM_PARAM)) {
return new ActionImport()
.setName(AIRT_COLL_ES_ALL_PRIM_PARAM)
.setAction(ActionProvider.nameUARTCollETAllPrimParam);
}
}

View File

@ -107,12 +107,14 @@ public class SchemaProvider {
actions.addAll(prov.getActions(ActionProvider.nameBAESTwoKeyNavRTESTwoKeyNav));
actions.addAll(prov.getActions(ActionProvider.nameBAETBaseTwoKeyNavRTETBaseTwoKeyNav));
actions.addAll(prov.getActions(ActionProvider.nameBAETTwoBaseTwoKeyNavRTETBaseTwoKeyNav));
actions.addAll(prov.getActions(ActionProvider.nameUARTPrimParam));
actions.addAll(prov.getActions(ActionProvider.nameUARTPrimCollParam));
actions.addAll(prov.getActions(ActionProvider.nameUARTCompParam));
actions.addAll(prov.getActions(ActionProvider.nameUARTCompCollParam));
actions.addAll(prov.getActions(ActionProvider.nameUARTETParam));
actions.addAll(prov.getActions(ActionProvider.nameUARTESParam));
actions.addAll(prov.getActions(ActionProvider.nameUARTString));
actions.addAll(prov.getActions(ActionProvider.nameUARTCollStringTwoParam));
actions.addAll(prov.getActions(ActionProvider.nameUARTCTTwoPrimParam));
actions.addAll(prov.getActions(ActionProvider.nameUARTCollCTTwoPrimParam));
actions.addAll(prov.getActions(ActionProvider.nameUARTETTwoKeyTwoPrimParam));
actions.addAll(prov.getActions(ActionProvider.nameUARTCollETKeyNavParam));
actions.addAll(prov.getActions(ActionProvider.nameUARTETAllPrimParam));
actions.addAll(prov.getActions(ActionProvider.nameUARTCollETAllPrimParam));
// Functions
List<Function> functions = new ArrayList<Function>();

View File

@ -49,6 +49,12 @@ import org.apache.olingo.server.api.ServiceMetadata;
import org.apache.olingo.server.api.edm.provider.EdmProvider;
import org.apache.olingo.server.api.edm.provider.EntitySet;
import org.apache.olingo.server.api.edmx.EdmxReference;
import org.apache.olingo.server.api.processor.ActionComplexCollectionProcessor;
import org.apache.olingo.server.api.processor.ActionComplexProcessor;
import org.apache.olingo.server.api.processor.ActionEntityCollectionProcessor;
import org.apache.olingo.server.api.processor.ActionEntityProcessor;
import org.apache.olingo.server.api.processor.ActionPrimitiveCollectionProcessor;
import org.apache.olingo.server.api.processor.ActionPrimitiveProcessor;
import org.apache.olingo.server.api.processor.BatchProcessor;
import org.apache.olingo.server.api.processor.ComplexCollectionProcessor;
import org.apache.olingo.server.api.processor.ComplexProcessor;
@ -67,6 +73,7 @@ import org.apache.olingo.server.api.processor.ReferenceCollectionProcessor;
import org.apache.olingo.server.api.processor.ReferenceProcessor;
import org.apache.olingo.server.api.processor.ServiceDocumentProcessor;
import org.apache.olingo.server.api.uri.UriInfo;
import org.apache.olingo.server.tecsvc.provider.ContainerProvider;
import org.apache.olingo.server.tecsvc.provider.EdmTechProvider;
import org.junit.Test;
@ -278,6 +285,97 @@ public class ODataHandlerTest {
any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class));
}
@Test
public void dispatchFunction() throws Exception {
EntityProcessor entityProcessor = mock(EntityProcessor.class);
dispatch(HttpMethod.GET, "FICRTETKeyNav()", entityProcessor);
verify(entityProcessor).readEntity(
any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class), any(ContentType.class));
EntityCollectionProcessor entityCollectionProcessor = mock(EntityCollectionProcessor.class);
dispatch(HttpMethod.GET, "FICRTESTwoKeyNavParam(ParameterInt16=123)", entityCollectionProcessor);
verify(entityCollectionProcessor).readEntityCollection(
any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class), any(ContentType.class));
PrimitiveProcessor primitiveProcessor = mock(PrimitiveProcessor.class);
dispatch(HttpMethod.GET, "FICRTString()", primitiveProcessor);
verify(primitiveProcessor).readPrimitive(
any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class), any(ContentType.class));
PrimitiveCollectionProcessor primitiveCollectionProcessor = mock(PrimitiveCollectionProcessor.class);
dispatch(HttpMethod.GET, "FICRTCollString()", primitiveCollectionProcessor);
verify(primitiveCollectionProcessor).readPrimitiveCollection(
any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class), any(ContentType.class));
ComplexProcessor complexProcessor = mock(ComplexProcessor.class);
dispatch(HttpMethod.GET, "FICRTCTTwoPrim()", complexProcessor);
verify(complexProcessor).readComplex(
any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class), any(ContentType.class));
ComplexCollectionProcessor complexCollectionProcessor = mock(ComplexCollectionProcessor.class);
dispatch(HttpMethod.GET, "FICRTCollCTTwoPrim()", complexCollectionProcessor);
verify(complexCollectionProcessor).readComplexCollection(
any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class), any(ContentType.class));
dispatchMethodNotAllowed(HttpMethod.POST, "FICRTCollString()", mock(Processor.class));
dispatchMethodNotAllowed(HttpMethod.PUT, "FICRTCollString()", mock(Processor.class));
dispatchMethodNotAllowed(HttpMethod.DELETE, "FICRTCollString()", mock(Processor.class));
}
@Test
public void dispatchAction() throws Exception {
ActionPrimitiveProcessor primitiveProcessor = mock(ActionPrimitiveProcessor.class);
dispatch(HttpMethod.POST, ContainerProvider.AIRT_STRING, primitiveProcessor);
verify(primitiveProcessor).processActionPrimitive(
any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class),
any(ContentType.class), any(ContentType.class));
ActionPrimitiveCollectionProcessor primitiveCollectionProcessor = mock(ActionPrimitiveCollectionProcessor.class);
dispatch(HttpMethod.POST, ContainerProvider.AIRT_COLL_STRING_TWO_PARAM, primitiveCollectionProcessor);
verify(primitiveCollectionProcessor).processActionPrimitiveCollection(
any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class),
any(ContentType.class), any(ContentType.class));
ActionComplexProcessor complexProcessor = mock(ActionComplexProcessor.class);
dispatch(HttpMethod.POST, ContainerProvider.AIRTCT_TWO_PRIM_PARAM, complexProcessor);
verify(complexProcessor).processActionComplex(
any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class),
any(ContentType.class), any(ContentType.class));
ActionComplexCollectionProcessor complexCollectionProcessor = mock(ActionComplexCollectionProcessor.class);
dispatch(HttpMethod.POST, ContainerProvider.AIRT_COLL_CT_TWO_PRIM_PARAM, complexCollectionProcessor);
verify(complexCollectionProcessor).processActionComplexCollection(
any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class),
any(ContentType.class), any(ContentType.class));
ActionEntityProcessor entityProcessor = mock(ActionEntityProcessor.class);
dispatch(HttpMethod.POST, ContainerProvider.AIRTET_TWO_KEY_TWO_PRIM_PARAM, entityProcessor);
verify(entityProcessor).processActionEntity(
any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class),
any(ContentType.class), any(ContentType.class));
ActionEntityCollectionProcessor entityCollectionProcessor = mock(ActionEntityCollectionProcessor.class);
dispatch(HttpMethod.POST, ContainerProvider.AIRT_COLL_ET_KEY_NAV_PARAM, entityCollectionProcessor);
verify(entityCollectionProcessor).processActionEntityCollection(
any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class),
any(ContentType.class), any(ContentType.class));
ActionEntityProcessor entityProcessorEs = mock(ActionEntityProcessor.class);
dispatch(HttpMethod.POST, ContainerProvider.AIRTES_ALL_PRIM_PARAM, entityProcessorEs);
verify(entityProcessorEs).processActionEntity(
any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class),
any(ContentType.class), any(ContentType.class));
ActionEntityCollectionProcessor entityCollectionProcessorEs = mock(ActionEntityCollectionProcessor.class);
dispatch(HttpMethod.POST, ContainerProvider.AIRT_COLL_ES_ALL_PRIM_PARAM, entityCollectionProcessorEs);
verify(entityCollectionProcessorEs).processActionEntityCollection(
any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class),
any(ContentType.class), any(ContentType.class));
dispatchMethodNotAllowed(HttpMethod.GET, "AIRTString", mock(Processor.class));
}
@Test
public void dispatchEntity() throws Exception {
final String uri = "ESAllPrim(0)";

View File

@ -89,9 +89,9 @@ public class MetadataDocumentTest {
// TODO: TypeDefinition
// assertThat(metadata, containsString("<TypeDefinition Name=\"typeDef\" Type=\"Edm.Int16\"/>"));
assertThat(metadata, containsString("<Action Name=\"UARTPrimParam\" IsBound=\"false\">"
assertThat(metadata, containsString("<Action Name=\"UARTCTTwoPrimParam\" IsBound=\"false\">"
+ "<Parameter Name=\"ParameterInt16\" Type=\"Edm.Int16\"/>"
+ "<ReturnType Type=\"Edm.String\"/></Action>"));
+ "<ReturnType Type=\"Namespace1_Alias.CTTwoPrim\"/></Action>"));
assertThat(metadata,
containsString("<Action Name=\"BAESAllPrimRTETAllPrim\" IsBound=\"true\">"
@ -120,7 +120,7 @@ public class MetadataDocumentTest {
+ "</Singleton>"));
assertThat(metadata,
containsString("<ActionImport Name=\"AIRTPrimParam\" Action=\"Namespace1_Alias.UARTPrimParam\"/>"));
containsString("<ActionImport Name=\"AIRTCTTwoPrimParam\" Action=\"Namespace1_Alias.UARTCTTwoPrimParam\"/>"));
assertThat(metadata,
containsString("<FunctionImport Name=\"FINInvisible2RTInt16\" Function=\"Namespace1_Alias.UFNRTInt16\" "

View File

@ -76,19 +76,19 @@ public class UriResourceImplTest {
assertEquals("", impl.toString());
// action
EdmAction action = edm.getUnboundAction(ActionProvider.nameUARTETParam);
EdmAction action = edm.getUnboundAction(ActionProvider.nameUARTETTwoKeyTwoPrimParam);
impl.setAction(action);
assertEquals(action, impl.getAction());
assertEquals(ActionProvider.nameUARTETParam.getName(), impl.toString());
assertEquals(ActionProvider.nameUARTETTwoKeyTwoPrimParam.getName(), impl.toString());
// action import
impl = new UriResourceActionImpl();
EdmActionImport actionImport = edm.getEntityContainer(null).getActionImport("AIRTPrimParam");
EdmActionImport actionImport = edm.getEntityContainer(null).getActionImport("AIRTCTTwoPrimParam");
impl.setActionImport(actionImport);
assertEquals(actionImport, impl.getActionImport());
assertEquals(actionImport.getUnboundAction(), impl.getAction());
assertEquals(false, impl.isCollection());
assertEquals("AIRTPrimParam", impl.toString());
assertEquals("AIRTCTTwoPrimParam", impl.toString());
assertEquals(actionImport.getUnboundAction().getReturnType().getType(), impl.getType());
}

View File

@ -35,10 +35,13 @@ import org.apache.olingo.server.core.uri.testutil.EdmTechTestProvider;
import org.apache.olingo.server.core.uri.testutil.FilterValidator;
import org.apache.olingo.server.core.uri.testutil.ResourceValidator;
import org.apache.olingo.server.core.uri.testutil.TestUriValidator;
import org.apache.olingo.server.tecsvc.provider.ActionProvider;
import org.apache.olingo.server.tecsvc.provider.ComplexTypeProvider;
import org.apache.olingo.server.tecsvc.provider.ContainerProvider;
import org.apache.olingo.server.tecsvc.provider.EntityTypeProvider;
import org.apache.olingo.server.tecsvc.provider.EnumTypeProvider;
import org.apache.olingo.server.tecsvc.provider.PropertyProvider;
import org.apache.olingo.server.tecsvc.provider.SchemaProvider;
import org.junit.Ignore;
import org.junit.Test;
@ -2724,15 +2727,15 @@ public class TestFullResourcePath {
.isType(PropertyProvider.nameString)
.isParameter(0, "ParameterInt16", "1");
testUri.run("AIRTETParam")
testUri.run(ContainerProvider.AIRT_STRING)
.isKind(UriInfoKind.resource)
.goPath().first()
.isActionImport("AIRTETParam");
.isActionImport(ContainerProvider.AIRT_STRING);
testUri.run("AIRTPrimParam")
testUri.run(ContainerProvider.AIRT_COLL_ES_ALL_PRIM_PARAM)
.isKind(UriInfoKind.resource)
.goPath().first()
.isActionImport("AIRTPrimParam");
.isActionImport(ContainerProvider.AIRT_COLL_ES_ALL_PRIM_PARAM);
testUri.run("ESKeyNav/$count")
.isKind(UriInfoKind.resource)

View File

@ -36,7 +36,9 @@ import org.apache.olingo.server.core.uri.testutil.FilterValidator;
import org.apache.olingo.server.core.uri.testutil.ResourceValidator;
import org.apache.olingo.server.core.uri.testutil.TestUriValidator;
import org.apache.olingo.server.core.uri.validator.UriValidationException;
import org.apache.olingo.server.tecsvc.provider.ActionProvider;
import org.apache.olingo.server.tecsvc.provider.ComplexTypeProvider;
import org.apache.olingo.server.tecsvc.provider.ContainerProvider;
import org.apache.olingo.server.tecsvc.provider.EntityTypeProvider;
import org.apache.olingo.server.tecsvc.provider.PropertyProvider;
import org.junit.Test;
@ -160,37 +162,37 @@ public class TestUriParserImpl {
@Test
public void runActionImport_VarReturnType() {
testRes.run("AIRTPrimParam").isKind(UriInfoKind.resource)
testRes.run(ContainerProvider.AIRT_STRING).isKind(UriInfoKind.resource)
.first()
.isActionImport("AIRTPrimParam")
.isAction("UARTPrimParam")
.isActionImport(ContainerProvider.AIRT_STRING)
.isAction(ActionProvider.nameUARTString.getName())
.isType(PropertyProvider.nameString, false);
testRes.run("AIRTPrimCollParam").isKind(UriInfoKind.resource)
.first()
.isActionImport("AIRTPrimCollParam")
.isAction("UARTPrimCollParam")
.isType(PropertyProvider.nameString, true);
testRes.run(ContainerProvider.AIRT_COLL_STRING_TWO_PARAM).isKind(UriInfoKind.resource)
.first()
.isActionImport(ContainerProvider.AIRT_COLL_STRING_TWO_PARAM)
.isAction(ActionProvider.nameUARTCollStringTwoParam.getName())
.isType(PropertyProvider.nameString, true);
testRes.run("AIRTCompParam").isKind(UriInfoKind.resource)
testRes.run(ContainerProvider.AIRTCT_TWO_PRIM_PARAM).isKind(UriInfoKind.resource)
.first()
.isActionImport("AIRTCompParam")
.isAction("UARTCompParam")
.isActionImport(ContainerProvider.AIRTCT_TWO_PRIM_PARAM)
.isAction(ActionProvider.nameUARTCTTwoPrimParam.getName())
.isType(ComplexTypeProvider.nameCTTwoPrim, false);
testRes.run("AIRTCompCollParam").isKind(UriInfoKind.resource)
testRes.run(ContainerProvider.AIRT_COLL_CT_TWO_PRIM_PARAM).isKind(UriInfoKind.resource)
.first()
.isActionImport("AIRTCompCollParam")
.isAction("UARTCompCollParam")
.isActionImport(ContainerProvider.AIRT_COLL_CT_TWO_PRIM_PARAM)
.isAction(ActionProvider.nameUARTCollCTTwoPrimParam.getName())
.isType(ComplexTypeProvider.nameCTTwoPrim, true);
testRes.run("AIRTETParam").isKind(UriInfoKind.resource)
testRes.run(ContainerProvider.AIRTET_TWO_KEY_TWO_PRIM_PARAM).isKind(UriInfoKind.resource)
.first()
.isActionImport("AIRTETParam")
.isAction("UARTETParam")
.isActionImport(ContainerProvider.AIRTET_TWO_KEY_TWO_PRIM_PARAM)
.isAction(ActionProvider.nameUARTETTwoKeyTwoPrimParam.getName())
.isType(EntityTypeProvider.nameETTwoKeyTwoPrim, false);
testUri.runEx("AIRTPrimParam/invalidElement")
testUri.runEx(ContainerProvider.AIRT_STRING + "/invalidElement")
.isExSemantic(UriParserSemanticException.MessageKeys.RESOURCE_PART_MUST_BE_PRECEDED_BY_STRUCTURAL_TYPE);
}

View File

@ -135,7 +135,7 @@ public class ExpressionTest {
EdmEntityType entityType = edm.getEntityType(EntityTypeProvider.nameETKeyNav);
// UriResourceImplTyped
EdmAction action = edm.getUnboundAction(ActionProvider.nameUARTPrimParam);
EdmAction action = edm.getUnboundAction(ActionProvider.nameUARTString);
UriInfoResource uriInfo = new UriInfoImpl().setKind(UriInfoKind.resource).addResourcePart(
new UriResourceActionImpl().setAction(action)).asUriInfoResource();
expression.setResourcePath(uriInfo);
@ -143,20 +143,20 @@ public class ExpressionTest {
// check accept and path
assertEquals(uriInfo, expression.getResourcePath());
assertEquals("<UARTPrimParam>", expression.accept(new FilterTreeToText()));
assertEquals("<UARTString>", expression.accept(new FilterTreeToText()));
// UriResourceImplTyped check collection = false case
assertEquals(false, expression.isCollection());
// UriResourceImplTyped check collection = true case
action = edm.getUnboundAction(ActionProvider.nameUARTPrimCollParam);
action = edm.getUnboundAction(ActionProvider.nameUARTCollStringTwoParam);
expression.setResourcePath(new UriInfoImpl().setKind(UriInfoKind.resource).addResourcePart(
new UriResourceActionImpl().setAction(action))
.asUriInfoResource());
assertEquals(true, expression.isCollection());
// UriResourceImplTyped with filter
action = edm.getUnboundAction(ActionProvider.nameUARTPrimParam);
action = edm.getUnboundAction(ActionProvider.nameUARTString);
expression.setResourcePath(new UriInfoImpl().setKind(UriInfoKind.resource).addResourcePart(
new UriResourceActionImpl().setAction(action).setTypeFilter(entityType))
.asUriInfoResource());

View File

@ -27,6 +27,7 @@ import org.apache.olingo.server.core.uri.parser.UriParserException;
import org.apache.olingo.server.core.uri.parser.UriParserSemanticException;
import org.apache.olingo.server.core.uri.parser.UriParserSyntaxException;
import org.apache.olingo.server.core.uri.testutil.TestUriValidator;
import org.apache.olingo.server.tecsvc.provider.ContainerProvider;
import org.apache.olingo.server.tecsvc.provider.EdmTechProvider;
import org.junit.Test;
@ -152,9 +153,9 @@ public class UriValidatorTest {
{ "ESTwoKeyNav/olingo.odata.test1.BAESTwoKeyNavRTESTwoKeyNav" },
{ "ESAllPrim/olingo.odata.test1.BAESAllPrimRTETAllPrim" },
{ "AIRTPrimCollParam" },
{ "AIRTETParam" },
{ "AIRTPrimParam" }
{ ContainerProvider.AIRT_COLL_STRING_TWO_PARAM },
{ ContainerProvider.AIRTET_TWO_KEY_TWO_PRIM_PARAM },
{ ContainerProvider.AIRT_STRING }
};
private String[][] urisWithNonValidSystemQueryOptions = {

View File

@ -55,9 +55,7 @@ import org.apache.olingo.server.api.serializer.EntityCollectionSerializerOptions
import org.apache.olingo.server.api.serializer.EntitySerializerOptions;
import org.apache.olingo.server.api.serializer.ODataSerializer;
import org.apache.olingo.server.api.serializer.PrimitiveSerializerOptions;
import org.apache.olingo.server.api.serializer.RepresentationType;
import org.apache.olingo.server.api.serializer.SerializerException;
import org.apache.olingo.server.api.uri.UriHelper;
import org.apache.olingo.server.api.uri.UriInfo;
import org.apache.olingo.server.api.uri.UriInfoResource;
import org.apache.olingo.server.api.uri.UriResource;