[OLINGO-675] inheritance of action processors removed

Signed-off-by: Christian Amend <chrisam@apache.org>
This commit is contained in:
Klaus Straubinger 2015-05-28 16:44:24 +02:00 committed by Christian Amend
parent 7ad5b0fb54
commit 91c2f6a451
10 changed files with 355 additions and 289 deletions

View File

@ -29,7 +29,7 @@ import org.apache.olingo.server.api.uri.UriInfo;
/** /**
* Processor interface for handling an action request with a return type of ComplexCollection. * Processor interface for handling an action request with a return type of ComplexCollection.
*/ */
public interface ActionComplexCollectionProcessor extends ComplexCollectionProcessor { public interface ActionComplexCollectionProcessor extends Processor {
/** /**
* Process an action which has as return type a complex-type collection. * Process an action which has as return type a complex-type collection.
* @param request OData request object containing raw HTTP information * @param request OData request object containing raw HTTP information

View File

@ -29,7 +29,7 @@ import org.apache.olingo.server.api.uri.UriInfo;
/** /**
* Processor interface for handling an action request with a return type of Complex. * Processor interface for handling an action request with a return type of Complex.
*/ */
public interface ActionComplexProcessor extends ComplexProcessor { public interface ActionComplexProcessor extends Processor {
/** /**
* Process an action which has as return type a complex type. * Process an action which has as return type a complex type.
* @param request OData request object containing raw HTTP information * @param request OData request object containing raw HTTP information

View File

@ -29,7 +29,7 @@ import org.apache.olingo.server.api.uri.UriInfo;
/** /**
* Processor interface for handling an action request with a return type of Entity Collection. * Processor interface for handling an action request with a return type of Entity Collection.
*/ */
public interface ActionEntityCollectionProcessor extends EntityCollectionProcessor { public interface ActionEntityCollectionProcessor extends Processor {
/** /**
* Process an action which has as return type a collection of entities. * Process an action which has as return type a collection of entities.
* @param request OData request object containing raw HTTP information * @param request OData request object containing raw HTTP information

View File

@ -29,7 +29,7 @@ import org.apache.olingo.server.api.uri.UriInfo;
/** /**
* Processor interface for handling an action request with a return type of Entity. * Processor interface for handling an action request with a return type of Entity.
*/ */
public interface ActionEntityProcessor extends EntityProcessor { public interface ActionEntityProcessor extends Processor {
/** /**
* Process an action which has as return type an entity. * Process an action which has as return type an entity.
* @param request OData request object containing raw HTTP information * @param request OData request object containing raw HTTP information

View File

@ -29,7 +29,7 @@ import org.apache.olingo.server.api.uri.UriInfo;
/** /**
* Processor interface for handling an action request with a return type of Primitive Collection. * Processor interface for handling an action request with a return type of Primitive Collection.
*/ */
public interface ActionPrimitiveCollectionProcessor extends PrimitiveCollectionProcessor { public interface ActionPrimitiveCollectionProcessor extends Processor {
/** /**
* Process an action which has as return type a primitive-type collection. * Process an action which has as return type a primitive-type collection.
* @param request OData request object containing raw HTTP information * @param request OData request object containing raw HTTP information

View File

@ -29,7 +29,7 @@ import org.apache.olingo.server.api.uri.UriInfo;
/** /**
* Processor interface for handling an action request with a return type of Primitive. * Processor interface for handling an action request with a return type of Primitive.
*/ */
public interface ActionPrimitiveProcessor extends PrimitiveProcessor { public interface ActionPrimitiveProcessor extends Processor {
/** /**
* Process an action which has as return type a primitive-type. * Process an action which has as return type a primitive-type.
* @param request OData request object containing raw HTTP information * @param request OData request object containing raw HTTP information

View File

@ -35,6 +35,7 @@ import org.apache.olingo.server.api.ServiceMetadata;
import org.apache.olingo.server.api.edmx.EdmxReference; import org.apache.olingo.server.api.edmx.EdmxReference;
import org.apache.olingo.server.api.edmx.EdmxReferenceInclude; import org.apache.olingo.server.api.edmx.EdmxReferenceInclude;
import org.apache.olingo.server.tecsvc.data.DataProvider; import org.apache.olingo.server.tecsvc.data.DataProvider;
import org.apache.olingo.server.tecsvc.processor.TechnicalActionProcessor;
import org.apache.olingo.server.tecsvc.processor.TechnicalBatchProcessor; import org.apache.olingo.server.tecsvc.processor.TechnicalBatchProcessor;
import org.apache.olingo.server.tecsvc.processor.TechnicalEntityProcessor; import org.apache.olingo.server.tecsvc.processor.TechnicalEntityProcessor;
import org.apache.olingo.server.tecsvc.processor.TechnicalPrimitiveComplexProcessor; import org.apache.olingo.server.tecsvc.processor.TechnicalPrimitiveComplexProcessor;
@ -68,10 +69,11 @@ public class TechnicalServlet extends HttpServlet {
ODataHttpHandler handler = odata.createHandler(serviceMetadata); ODataHttpHandler handler = odata.createHandler(serviceMetadata);
handler.register(new TechnicalEntityProcessor(dataProvider, serviceMetadata)); handler.register(new TechnicalEntityProcessor(dataProvider, serviceMetadata));
handler.register(new TechnicalPrimitiveComplexProcessor(dataProvider, serviceMetadata)); handler.register(new TechnicalPrimitiveComplexProcessor(dataProvider, serviceMetadata));
handler.register(new TechnicalActionProcessor(dataProvider, serviceMetadata));
handler.register(new TechnicalBatchProcessor(dataProvider)); handler.register(new TechnicalBatchProcessor(dataProvider));
handler.register(new ETagSupport()); handler.register(new ETagSupport());
handler.process(request, response); handler.process(request, response);
} catch (RuntimeException e) { } catch (final RuntimeException e) {
LOG.error("Server Error", e); LOG.error("Server Error", e);
throw new ServletException(e); throw new ServletException(e);
} }

View File

@ -0,0 +1,315 @@
/*
* 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.tecsvc.processor;
import java.util.Locale;
import org.apache.olingo.commons.api.data.ContextURL;
import org.apache.olingo.commons.api.data.ContextURL.Builder;
import org.apache.olingo.commons.api.data.ContextURL.Suffix;
import org.apache.olingo.commons.api.data.EntityCollection;
import org.apache.olingo.commons.api.data.Property;
import org.apache.olingo.commons.api.edm.EdmAction;
import org.apache.olingo.commons.api.edm.EdmComplexType;
import org.apache.olingo.commons.api.edm.EdmEntitySet;
import org.apache.olingo.commons.api.edm.EdmEntityType;
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
import org.apache.olingo.commons.api.format.ContentType;
import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.commons.api.http.HttpHeader;
import org.apache.olingo.commons.api.http.HttpStatusCode;
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.ServiceMetadata;
import org.apache.olingo.server.api.deserializer.DeserializerException;
import org.apache.olingo.server.api.deserializer.DeserializerResult;
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.ActionVoidProcessor;
import org.apache.olingo.server.api.serializer.ComplexSerializerOptions;
import org.apache.olingo.server.api.serializer.EntityCollectionSerializerOptions;
import org.apache.olingo.server.api.serializer.EntitySerializerOptions;
import org.apache.olingo.server.api.serializer.PrimitiveSerializerOptions;
import org.apache.olingo.server.api.serializer.SerializerException;
import org.apache.olingo.server.api.serializer.SerializerResult;
import org.apache.olingo.server.api.uri.UriInfo;
import org.apache.olingo.server.api.uri.UriResourceAction;
import org.apache.olingo.server.tecsvc.data.DataProvider;
import org.apache.olingo.server.tecsvc.data.EntityActionResult;
/**
* Technical Processor for entity-related functionality.
*/
public class TechnicalActionProcessor extends TechnicalProcessor
implements ActionEntityCollectionProcessor, ActionEntityProcessor,
ActionPrimitiveCollectionProcessor, ActionPrimitiveProcessor,
ActionComplexCollectionProcessor, ActionComplexProcessor,
ActionVoidProcessor {
public TechnicalActionProcessor(final DataProvider dataProvider, final ServiceMetadata serviceMetadata) {
super(dataProvider, serviceMetadata);
}
@Override
public void processActionEntityCollection(final ODataRequest request, final ODataResponse response,
final UriInfo uriInfo, final ContentType requestFormat, final ContentType responseFormat)
throws ODataApplicationException, DeserializerException, SerializerException {
blockBoundActions(uriInfo);
final EdmAction action = ((UriResourceAction) uriInfo.asUriInfoResource().getUriResourceParts().get(0))
.getAction();
DeserializerResult deserializerResult =
odata.createDeserializer(ODataFormat.fromContentType(requestFormat))
.actionParameters(request.getBody(), action);
EntityCollection collection =
dataProvider.processActionEntityCollection(action.getName(), deserializerResult.getActionParameters());
// Collections must never be null.
// Not nullable return types must not contain a null value.
if (collection == null
|| collection.getEntities().contains(null) && !action.getReturnType().isNullable()) {
throw new ODataApplicationException("The action could not be executed.",
HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.ROOT);
}
final EdmEntitySet edmEntitySet = getEdmEntitySet(uriInfo.asUriInfoResource());
final EdmEntityType type = (EdmEntityType) action.getReturnType().getType();
final ODataFormat format = ODataFormat.fromContentType(responseFormat);
EntityCollectionSerializerOptions options = EntityCollectionSerializerOptions.with()
.contextURL(format == ODataFormat.JSON_NO_METADATA ? null : getContextUrl(edmEntitySet, type, false))
.build();
response.setContent(odata.createSerializer(format)
.entityCollection(serviceMetadata, type, collection, options).getContent());
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString());
}
@Override
public void processActionEntity(final ODataRequest request, final ODataResponse response, final UriInfo uriInfo,
final ContentType requestFormat, final ContentType responseFormat)
throws ODataApplicationException, DeserializerException, SerializerException {
blockBoundActions(uriInfo);
final EdmAction action = ((UriResourceAction) uriInfo.asUriInfoResource().getUriResourceParts().get(0))
.getAction();
final EdmEntitySet edmEntitySet = getEdmEntitySet(uriInfo.asUriInfoResource());
final EdmEntityType type = (EdmEntityType) action.getReturnType().getType();
final DeserializerResult deserializerResult =
odata.createDeserializer(ODataFormat.fromContentType(requestFormat))
.actionParameters(request.getBody(), action);
final EntityActionResult entityResult =
dataProvider.processActionEntity(action.getName(), deserializerResult.getActionParameters());
if (entityResult == null || entityResult.getEntity() == null) {
if (action.getReturnType().isNullable()) {
response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
} else {
// Not nullable return type so we have to give back a 500
throw new ODataApplicationException("The action could not be executed.",
HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.ROOT);
}
} else {
final ODataFormat format = ODataFormat.fromContentType(responseFormat);
response.setContent(odata.createSerializer(format).entity(
serviceMetadata,
type,
entityResult.getEntity(),
EntitySerializerOptions.with()
.contextURL(format == ODataFormat.JSON_NO_METADATA ? null : getContextUrl(edmEntitySet, type, true))
.build())
.getContent());
response.setStatusCode((entityResult.isCreated() ? HttpStatusCode.CREATED : HttpStatusCode.OK)
.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString());
if (entityResult.getEntity().getETag() != null) {
response.setHeader(HttpHeader.ETAG, entityResult.getEntity().getETag());
}
}
}
@Override
public void processActionPrimitiveCollection(final ODataRequest request, ODataResponse response,
final UriInfo uriInfo, final ContentType requestFormat, final ContentType responseFormat)
throws ODataApplicationException, DeserializerException, SerializerException {
blockBoundActions(uriInfo);
final EdmAction action = ((UriResourceAction) uriInfo.asUriInfoResource().getUriResourceParts().get(0))
.getAction();
DeserializerResult deserializerResult =
odata.createDeserializer(ODataFormat.fromContentType(requestFormat))
.actionParameters(request.getBody(), action);
Property property =
dataProvider.processActionPrimitiveCollection(action.getName(), deserializerResult.getActionParameters());
if (property == null || property.isNull()) {
// Collection Propertys must never be null
throw new ODataApplicationException("The action could not be executed.",
HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.ROOT);
} else if (property.asCollection().contains(null) && !action.getReturnType().isNullable()) {
// Not nullable return type but array contains a null value
throw new ODataApplicationException("The action could not be executed.",
HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.ROOT);
}
EdmPrimitiveType type = (EdmPrimitiveType) action.getReturnType().getType();
ContextURL contextURL = ContextURL.with().type(type).asCollection().build();
PrimitiveSerializerOptions options = PrimitiveSerializerOptions.with().contextURL(contextURL).build();
SerializerResult result =
odata.createSerializer(ODataFormat.fromContentType(responseFormat))
.primitiveCollection(type, property, options);
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
response.setContent(result.getContent());
response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString());
}
@Override
public void processActionPrimitive(final ODataRequest request, ODataResponse response,
final UriInfo uriInfo, final ContentType requestFormat, final ContentType responseFormat)
throws ODataApplicationException, DeserializerException, SerializerException {
blockBoundActions(uriInfo);
final EdmAction action = ((UriResourceAction) uriInfo.asUriInfoResource().getUriResourceParts().get(0))
.getAction();
DeserializerResult deserializerResult =
odata.createDeserializer(ODataFormat.fromContentType(requestFormat))
.actionParameters(request.getBody(), action);
Property property = dataProvider.processActionPrimitive(action.getName(), deserializerResult.getActionParameters());
EdmPrimitiveType type = (EdmPrimitiveType) action.getReturnType().getType();
if (property == null || property.isNull()) {
if (action.getReturnType().isNullable()) {
response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
} else {
// Not nullable return type so we have to give back an Internal Server Error
throw new ODataApplicationException("The action could not be executed.",
HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.ROOT);
}
} else {
ContextURL contextURL = ContextURL.with().type(type).build();
PrimitiveSerializerOptions options = PrimitiveSerializerOptions.with().contextURL(contextURL).build();
SerializerResult result = odata.createSerializer(ODataFormat.fromContentType(responseFormat)).primitive(type,
property, options);
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
response.setContent(result.getContent());
response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString());
}
}
@Override
public void processActionComplexCollection(final ODataRequest request, ODataResponse response,
final UriInfo uriInfo, final ContentType requestFormat, final ContentType responseFormat)
throws ODataApplicationException, DeserializerException, SerializerException {
blockBoundActions(uriInfo);
final EdmAction action = ((UriResourceAction) uriInfo.asUriInfoResource().getUriResourceParts().get(0))
.getAction();
DeserializerResult deserializerResult =
odata.createDeserializer(ODataFormat.fromContentType(requestFormat))
.actionParameters(request.getBody(), action);
Property property =
dataProvider.processActionComplexCollection(action.getName(), deserializerResult.getActionParameters());
if (property == null || property.isNull()) {
// Collection Propertys must never be null
throw new ODataApplicationException("The action could not be executed.",
HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.ROOT);
} else if (property.asCollection().contains(null) && !action.getReturnType().isNullable()) {
// Not nullable return type but array contains a null value
throw new ODataApplicationException("The action could not be executed.",
HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.ROOT);
}
EdmComplexType type = (EdmComplexType) action.getReturnType().getType();
ContextURL contextURL = ContextURL.with().type(type).asCollection().build();
ComplexSerializerOptions options = ComplexSerializerOptions.with().contextURL(contextURL).build();
SerializerResult result =
odata.createSerializer(ODataFormat.fromContentType(responseFormat)).complexCollection(serviceMetadata, type,
property, options);
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
response.setContent(result.getContent());
response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString());
}
@Override
public void processActionComplex(final ODataRequest request, ODataResponse response, final UriInfo uriInfo,
final ContentType requestFormat, final ContentType responseFormat)
throws ODataApplicationException, DeserializerException, SerializerException {
blockBoundActions(uriInfo);
final EdmAction action = ((UriResourceAction) uriInfo.asUriInfoResource().getUriResourceParts().get(0))
.getAction();
DeserializerResult deserializerResult =
odata.createDeserializer(ODataFormat.fromContentType(requestFormat))
.actionParameters(request.getBody(), action);
Property property = dataProvider.processActionComplex(action.getName(), deserializerResult.getActionParameters());
EdmComplexType type = (EdmComplexType) action.getReturnType().getType();
if (property == null || property.isNull()) {
if (action.getReturnType().isNullable()) {
response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
} else {
// Not nullable return type so we have to give back an Internal Server Error
throw new ODataApplicationException("The action could not be executed.",
HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.ROOT);
}
} else {
ContextURL contextURL = ContextURL.with().type(type).build();
ComplexSerializerOptions options = ComplexSerializerOptions.with().contextURL(contextURL).build();
SerializerResult result =
odata.createSerializer(ODataFormat.fromContentType(responseFormat)).complex(serviceMetadata, type, property,
options);
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
response.setContent(result.getContent());
response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString());
}
}
@Override
public void processActionVoid(final ODataRequest request, final ODataResponse response, final UriInfo uriInfo,
final ContentType requestFormat) throws ODataApplicationException, DeserializerException {
final UriResourceAction resource =
((UriResourceAction) uriInfo.getUriResourceParts().get(uriInfo.getUriResourceParts().size() - 1));
final EdmAction action = resource.getAction();
if (action.getParameterNames().size() - (action.isBound() ? 1 : 0) > 0) {
checkRequestFormat(requestFormat);
odata.createDeserializer(ODataFormat.fromContentType(requestFormat))
.actionParameters(request.getBody(), action);
}
response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
}
private ContextURL getContextUrl(final EdmEntitySet entitySet, final EdmEntityType entityType,
final boolean isSingleEntity) throws SerializerException {
Builder builder = ContextURL.with();
builder = entitySet == null ?
isSingleEntity ? builder.type(entityType) : builder.asCollection().type(entityType) :
builder.entitySet(entitySet);
builder = builder.suffix(isSingleEntity && entitySet != null ? Suffix.ENTITY : null);
return builder.build();
}
}

View File

@ -26,7 +26,6 @@ import org.apache.olingo.commons.api.data.ContextURL.Builder;
import org.apache.olingo.commons.api.data.ContextURL.Suffix; import org.apache.olingo.commons.api.data.ContextURL.Suffix;
import org.apache.olingo.commons.api.data.Entity; import org.apache.olingo.commons.api.data.Entity;
import org.apache.olingo.commons.api.data.EntityCollection; import org.apache.olingo.commons.api.data.EntityCollection;
import org.apache.olingo.commons.api.edm.EdmAction;
import org.apache.olingo.commons.api.edm.EdmEntitySet; import org.apache.olingo.commons.api.edm.EdmEntitySet;
import org.apache.olingo.commons.api.edm.EdmEntityType; import org.apache.olingo.commons.api.edm.EdmEntityType;
import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.format.ContentType;
@ -42,9 +41,6 @@ import org.apache.olingo.server.api.ServiceMetadata;
import org.apache.olingo.server.api.deserializer.DeserializerException; import org.apache.olingo.server.api.deserializer.DeserializerException;
import org.apache.olingo.server.api.deserializer.DeserializerResult; import org.apache.olingo.server.api.deserializer.DeserializerResult;
import org.apache.olingo.server.api.deserializer.ODataDeserializer; import org.apache.olingo.server.api.deserializer.ODataDeserializer;
import org.apache.olingo.server.api.processor.ActionEntityCollectionProcessor;
import org.apache.olingo.server.api.processor.ActionEntityProcessor;
import org.apache.olingo.server.api.processor.ActionVoidProcessor;
import org.apache.olingo.server.api.processor.CountEntityCollectionProcessor; import org.apache.olingo.server.api.processor.CountEntityCollectionProcessor;
import org.apache.olingo.server.api.processor.EntityCollectionProcessor; import org.apache.olingo.server.api.processor.EntityCollectionProcessor;
import org.apache.olingo.server.api.processor.EntityProcessor; import org.apache.olingo.server.api.processor.EntityProcessor;
@ -53,12 +49,10 @@ import org.apache.olingo.server.api.processor.ReferenceCollectionProcessor;
import org.apache.olingo.server.api.processor.ReferenceProcessor; import org.apache.olingo.server.api.processor.ReferenceProcessor;
import org.apache.olingo.server.api.serializer.EntityCollectionSerializerOptions; import org.apache.olingo.server.api.serializer.EntityCollectionSerializerOptions;
import org.apache.olingo.server.api.serializer.EntitySerializerOptions; import org.apache.olingo.server.api.serializer.EntitySerializerOptions;
import org.apache.olingo.server.api.serializer.ODataSerializer;
import org.apache.olingo.server.api.serializer.SerializerException; import org.apache.olingo.server.api.serializer.SerializerException;
import org.apache.olingo.server.api.serializer.SerializerResult; import org.apache.olingo.server.api.serializer.SerializerResult;
import org.apache.olingo.server.api.uri.UriInfo; import org.apache.olingo.server.api.uri.UriInfo;
import org.apache.olingo.server.api.uri.UriResource; 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.UriResourceEntitySet;
import org.apache.olingo.server.api.uri.UriResourceFunction; import org.apache.olingo.server.api.uri.UriResourceFunction;
import org.apache.olingo.server.api.uri.UriResourceValue; import org.apache.olingo.server.api.uri.UriResourceValue;
@ -66,7 +60,6 @@ import org.apache.olingo.server.api.uri.queryoption.CountOption;
import org.apache.olingo.server.api.uri.queryoption.ExpandOption; import org.apache.olingo.server.api.uri.queryoption.ExpandOption;
import org.apache.olingo.server.api.uri.queryoption.SelectOption; import org.apache.olingo.server.api.uri.queryoption.SelectOption;
import org.apache.olingo.server.tecsvc.data.DataProvider; import org.apache.olingo.server.tecsvc.data.DataProvider;
import org.apache.olingo.server.tecsvc.data.EntityActionResult;
import org.apache.olingo.server.tecsvc.data.RequestValidator; import org.apache.olingo.server.tecsvc.data.RequestValidator;
import org.apache.olingo.server.tecsvc.processor.queryoptions.ExpandSystemQueryOptionHandler; import org.apache.olingo.server.tecsvc.processor.queryoptions.ExpandSystemQueryOptionHandler;
import org.apache.olingo.server.tecsvc.processor.queryoptions.options.CountHandler; import org.apache.olingo.server.tecsvc.processor.queryoptions.options.CountHandler;
@ -80,9 +73,8 @@ import org.apache.olingo.server.tecsvc.processor.queryoptions.options.TopHandler
* Technical Processor for entity-related functionality. * Technical Processor for entity-related functionality.
*/ */
public class TechnicalEntityProcessor extends TechnicalProcessor public class TechnicalEntityProcessor extends TechnicalProcessor
implements EntityCollectionProcessor, ActionEntityCollectionProcessor, CountEntityCollectionProcessor, implements EntityCollectionProcessor, CountEntityCollectionProcessor, EntityProcessor, MediaEntityProcessor,
EntityProcessor, ActionEntityProcessor, MediaEntityProcessor, ReferenceCollectionProcessor, ReferenceProcessor {
ActionVoidProcessor, ReferenceCollectionProcessor, ReferenceProcessor {
public TechnicalEntityProcessor(final DataProvider dataProvider, final ServiceMetadata serviceMetadata) { public TechnicalEntityProcessor(final DataProvider dataProvider, final ServiceMetadata serviceMetadata) {
super(dataProvider, serviceMetadata); super(dataProvider, serviceMetadata);
@ -93,42 +85,7 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
final ContentType requestedContentType) throws ODataApplicationException, SerializerException { final ContentType requestedContentType) throws ODataApplicationException, SerializerException {
validateOptions(uriInfo.asUriInfoResource()); validateOptions(uriInfo.asUriInfoResource());
processEntityCollection(request, response, uriInfo, requestedContentType, false); readEntityCollection(request, response, uriInfo, requestedContentType, false);
}
@Override
public void processActionEntityCollection(final ODataRequest request, final ODataResponse response,
final UriInfo uriInfo, final ContentType requestFormat, final ContentType responseFormat)
throws ODataApplicationException, DeserializerException, SerializerException {
blockBoundActions(uriInfo);
final EdmAction action = ((UriResourceAction) uriInfo.asUriInfoResource().getUriResourceParts().get(0))
.getAction();
DeserializerResult deserializerResult =
odata.createDeserializer(ODataFormat.fromContentType(requestFormat))
.actionParameters(request.getBody(), action);
EntityCollection collection =
dataProvider.processActionEntityCollection(action.getName(), deserializerResult.getActionParameters());
// Collections must never be null.
// Not nullable return types must not contain a null value.
if (collection == null
|| collection.getEntities().contains(null) && !action.getReturnType().isNullable()) {
throw new ODataApplicationException("The action could not be executed.",
HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.ROOT);
}
final EdmEntitySet edmEntitySet = getEdmEntitySet(uriInfo.asUriInfoResource());
final EdmEntityType type = (EdmEntityType) action.getReturnType().getType();
final ODataFormat format = ODataFormat.fromContentType(responseFormat);
EntityCollectionSerializerOptions options = EntityCollectionSerializerOptions.with()
.contextURL(format == ODataFormat.JSON_NO_METADATA ? null :
getContextUrl(edmEntitySet, type, false, null, null))
.build();
response.setContent(odata.createSerializer(format)
.entityCollection(serviceMetadata, type, collection, options).getContent());
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString());
} }
@Override @Override
@ -230,8 +187,8 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
throws ODataApplicationException, DeserializerException, SerializerException { throws ODataApplicationException, DeserializerException, SerializerException {
final EdmEntitySet edmEntitySet = getEdmEntitySet(uriInfo); final EdmEntitySet edmEntitySet = getEdmEntitySet(uriInfo);
final EdmEntityType edmEntityType = edmEntitySet.getEntityType(); final EdmEntityType edmEntityType = edmEntitySet.getEntityType();
Entity entity;
Entity entity;
try { try {
entity = readEntity(uriInfo); entity = readEntity(uriInfo);
} catch (ODataApplicationException e) { } catch (ODataApplicationException e) {
@ -311,69 +268,6 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode()); response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
} }
@Override
public void processActionEntity(final ODataRequest request, final ODataResponse response, final UriInfo uriInfo,
final ContentType requestFormat, final ContentType responseFormat)
throws ODataApplicationException, DeserializerException, SerializerException {
blockBoundActions(uriInfo);
final EdmAction action = ((UriResourceAction) uriInfo.asUriInfoResource().getUriResourceParts().get(0))
.getAction();
final EdmEntitySet edmEntitySet = getEdmEntitySet(uriInfo.asUriInfoResource());
final EdmEntityType type = (EdmEntityType) action.getReturnType().getType();
final DeserializerResult deserializerResult =
odata.createDeserializer(ODataFormat.fromContentType(requestFormat))
.actionParameters(request.getBody(), action);
final EntityActionResult entityResult =
dataProvider.processActionEntity(action.getName(), deserializerResult.getActionParameters());
if (entityResult == null || entityResult.getEntity() == null) {
if (action.getReturnType().isNullable()) {
response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
} else {
// Not nullable return type so we have to give back a 500
throw new ODataApplicationException("The action could not be executed.",
HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.ROOT);
}
} else {
final ODataFormat format = ODataFormat.fromContentType(responseFormat);
response.setContent(serializeEntity(entityResult.getEntity(), edmEntitySet, type, format, null, null)
.getContent());
response.setStatusCode((entityResult.isCreated() ? HttpStatusCode.CREATED : HttpStatusCode.OK)
.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString());
if (entityResult.getEntity().getETag() != null) {
response.setHeader(HttpHeader.ETAG, entityResult.getEntity().getETag());
}
}
}
@Override
public void processActionVoid(final ODataRequest request, final ODataResponse response, final UriInfo uriInfo,
final ContentType requestFormat) throws ODataApplicationException, DeserializerException {
final UriResourceAction resource =
((UriResourceAction) uriInfo.getUriResourceParts().get(uriInfo.getUriResourceParts().size() - 1));
final EdmAction action = resource.getAction();
if (action.getParameterNames().size() - (action.isBound() ? 1 : 0) > 0) {
checkRequestFormat(requestFormat);
odata.createDeserializer(ODataFormat.fromContentType(requestFormat))
.actionParameters(request.getBody(), action);
}
response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
}
private ContextURL getContextUrl(final EdmEntitySet entitySet, final EdmEntityType entityType,
final boolean isSingleEntity, final ExpandOption expand, final SelectOption select) throws SerializerException {
Builder builder = ContextURL.with();
builder = entitySet == null ?
isSingleEntity ? builder.type(entityType) : builder.asCollection().type(entityType) :
builder.entitySet(entitySet);
builder = builder
.selectList(odata.createUriHelper().buildContextURLSelectList(entityType, expand, select))
.suffix(isSingleEntity && entitySet != null ? Suffix.ENTITY : null);
return builder.build();
}
@Override @Override
public void readReference(final ODataRequest request, ODataResponse response, final UriInfo uriInfo, public void readReference(final ODataRequest request, ODataResponse response, final UriInfo uriInfo,
final ContentType requestedContentType) throws ODataApplicationException, SerializerException { final ContentType requestedContentType) throws ODataApplicationException, SerializerException {
@ -401,8 +295,7 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
@Override @Override
public void readReferenceCollection(final ODataRequest request, final ODataResponse response, final UriInfo uriInfo, public void readReferenceCollection(final ODataRequest request, final ODataResponse response, final UriInfo uriInfo,
final ContentType requestedContentType) throws ODataApplicationException, SerializerException { final ContentType requestedContentType) throws ODataApplicationException, SerializerException {
readEntityCollection(request, response, uriInfo, requestedContentType, true);
processEntityCollection(request, response, uriInfo, requestedContentType, true);
} }
private void readEntity(final ODataRequest request, final ODataResponse response, final UriInfo uriInfo, private void readEntity(final ODataRequest request, final ODataResponse response, final UriInfo uriInfo,
@ -440,10 +333,9 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
response.setHeader(HttpHeader.CONTENT_TYPE, requestedContentType.toContentTypeString()); response.setHeader(HttpHeader.CONTENT_TYPE, requestedContentType.toContentTypeString());
} }
private void processEntityCollection(final ODataRequest request, final ODataResponse response, private void readEntityCollection(final ODataRequest request, final ODataResponse response,
final UriInfo uriInfo, final ContentType requestedContentType, final boolean isReference) final UriInfo uriInfo, final ContentType requestedContentType, final boolean isReference)
throws ODataApplicationException, SerializerException { throws ODataApplicationException, SerializerException {
final EdmEntitySet edmEntitySet = getEdmEntitySet(uriInfo.asUriInfoResource()); final EdmEntitySet edmEntitySet = getEdmEntitySet(uriInfo.asUriInfoResource());
final EdmEntityType edmEntityType = edmEntitySet == null ? final EdmEntityType edmEntityType = edmEntitySet == null ?
(EdmEntityType) ((UriResourceFunction) uriInfo.getUriResourceParts() (EdmEntityType) ((UriResourceFunction) uriInfo.getUriResourceParts()
@ -503,7 +395,6 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
final EdmEntitySet edmEntitySet, final EdmEntityType edmEntityType, final ODataFormat format, final EdmEntitySet edmEntitySet, final EdmEntityType edmEntityType, final ODataFormat format,
final ExpandOption expand, final SelectOption select, final CountOption countOption) final ExpandOption expand, final SelectOption select, final CountOption countOption)
throws SerializerException { throws SerializerException {
return odata.createSerializer(format).entityCollection( return odata.createSerializer(format).entityCollection(
serviceMetadata, serviceMetadata,
edmEntityType, edmEntityType,
@ -518,20 +409,16 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
private SerializerResult serializeReferenceCollection(final EntityCollection entityCollection, private SerializerResult serializeReferenceCollection(final EntityCollection entityCollection,
final EdmEntitySet edmEntitySet, final ODataFormat format) throws SerializerException { final EdmEntitySet edmEntitySet, final ODataFormat format) throws SerializerException {
return odata.createSerializer(format)
final ContextURL contextUrl = ContextURL.with().asCollection().suffix(Suffix.REFERENCE).build(); .referenceCollection(serviceMetadata, edmEntitySet, entityCollection,
final ODataSerializer serializer = odata.createSerializer(format); ContextURL.with().asCollection().suffix(Suffix.REFERENCE).build());
return serializer.referenceCollection(serviceMetadata, edmEntitySet, entityCollection, contextUrl);
} }
private SerializerResult serializeReference(final Entity entity, final EdmEntitySet edmEntitySet, private SerializerResult serializeReference(final Entity entity, final EdmEntitySet edmEntitySet,
final ODataFormat format ) throws SerializerException { final ODataFormat format ) throws SerializerException {
return odata.createSerializer(format)
final ContextURL contextUrl = ContextURL.with().suffix(Suffix.REFERENCE).build(); .reference(serviceMetadata, edmEntitySet, entity,
final ODataSerializer serializer = odata.createSerializer(format); ContextURL.with().suffix(Suffix.REFERENCE).build());
return serializer.reference(serviceMetadata, edmEntitySet, entity, contextUrl);
} }
private SerializerResult serializeEntity(final Entity entity, private SerializerResult serializeEntity(final Entity entity,
@ -547,4 +434,16 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
.expand(expand).select(select) .expand(expand).select(select)
.build()); .build());
} }
private ContextURL getContextUrl(final EdmEntitySet entitySet, final EdmEntityType entityType,
final boolean isSingleEntity, final ExpandOption expand, final SelectOption select) throws SerializerException {
Builder builder = ContextURL.with();
builder = entitySet == null ?
isSingleEntity ? builder.type(entityType) : builder.asCollection().type(entityType) :
builder.entitySet(entitySet);
builder = builder
.selectList(odata.createUriHelper().buildContextURLSelectList(entityType, expand, select))
.suffix(isSingleEntity && entitySet != null ? Suffix.ENTITY : null);
return builder.build();
}
} }

View File

@ -27,7 +27,6 @@ import org.apache.olingo.commons.api.data.ContextURL;
import org.apache.olingo.commons.api.data.ContextURL.Builder; import org.apache.olingo.commons.api.data.ContextURL.Builder;
import org.apache.olingo.commons.api.data.Entity; import org.apache.olingo.commons.api.data.Entity;
import org.apache.olingo.commons.api.data.Property; import org.apache.olingo.commons.api.data.Property;
import org.apache.olingo.commons.api.edm.EdmAction;
import org.apache.olingo.commons.api.edm.EdmComplexType; import org.apache.olingo.commons.api.edm.EdmComplexType;
import org.apache.olingo.commons.api.edm.EdmEntitySet; import org.apache.olingo.commons.api.edm.EdmEntitySet;
import org.apache.olingo.commons.api.edm.EdmPrimitiveType; import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
@ -47,11 +46,6 @@ import org.apache.olingo.server.api.ODataRequest;
import org.apache.olingo.server.api.ODataResponse; import org.apache.olingo.server.api.ODataResponse;
import org.apache.olingo.server.api.ServiceMetadata; import org.apache.olingo.server.api.ServiceMetadata;
import org.apache.olingo.server.api.deserializer.DeserializerException; import org.apache.olingo.server.api.deserializer.DeserializerException;
import org.apache.olingo.server.api.deserializer.DeserializerResult;
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.ComplexCollectionProcessor;
import org.apache.olingo.server.api.processor.ComplexProcessor; import org.apache.olingo.server.api.processor.ComplexProcessor;
import org.apache.olingo.server.api.processor.PrimitiveCollectionProcessor; import org.apache.olingo.server.api.processor.PrimitiveCollectionProcessor;
@ -69,7 +63,6 @@ import org.apache.olingo.server.api.uri.UriHelper;
import org.apache.olingo.server.api.uri.UriInfo; import org.apache.olingo.server.api.uri.UriInfo;
import org.apache.olingo.server.api.uri.UriInfoResource; import org.apache.olingo.server.api.uri.UriInfoResource;
import org.apache.olingo.server.api.uri.UriResource; import org.apache.olingo.server.api.uri.UriResource;
import org.apache.olingo.server.api.uri.UriResourceAction;
import org.apache.olingo.server.api.uri.UriResourceFunction; import org.apache.olingo.server.api.uri.UriResourceFunction;
import org.apache.olingo.server.api.uri.UriResourceKind; import org.apache.olingo.server.api.uri.UriResourceKind;
import org.apache.olingo.server.api.uri.UriResourceProperty; import org.apache.olingo.server.api.uri.UriResourceProperty;
@ -81,10 +74,8 @@ import org.apache.olingo.server.tecsvc.data.DataProvider;
* Technical Processor which provides functionality related to primitive and complex types and collections thereof. * Technical Processor which provides functionality related to primitive and complex types and collections thereof.
*/ */
public class TechnicalPrimitiveComplexProcessor extends TechnicalProcessor public class TechnicalPrimitiveComplexProcessor extends TechnicalProcessor
implements PrimitiveProcessor, PrimitiveValueProcessor, ActionPrimitiveProcessor, implements PrimitiveProcessor, PrimitiveValueProcessor, PrimitiveCollectionProcessor,
PrimitiveCollectionProcessor, ActionPrimitiveCollectionProcessor, ComplexProcessor, ComplexCollectionProcessor {
ComplexProcessor, ActionComplexProcessor,
ComplexCollectionProcessor, ActionComplexCollectionProcessor {
public TechnicalPrimitiveComplexProcessor(final DataProvider dataProvider, public TechnicalPrimitiveComplexProcessor(final DataProvider dataProvider,
final ServiceMetadata serviceMetadata) { final ServiceMetadata serviceMetadata) {
@ -110,40 +101,6 @@ public class TechnicalPrimitiveComplexProcessor extends TechnicalProcessor
deleteProperty(request, response, uriInfo); deleteProperty(request, response, uriInfo);
} }
@Override
public void processActionPrimitive(final ODataRequest request, ODataResponse response,
final UriInfo uriInfo, final ContentType requestFormat, final ContentType responseFormat)
throws ODataApplicationException, DeserializerException, SerializerException {
blockBoundActions(uriInfo);
final EdmAction action = ((UriResourceAction) uriInfo.asUriInfoResource().getUriResourceParts().get(0))
.getAction();
DeserializerResult deserializerResult =
odata.createDeserializer(ODataFormat.fromContentType(requestFormat))
.actionParameters(request.getBody(), action);
Property property = dataProvider.processActionPrimitive(action.getName(), deserializerResult.getActionParameters());
EdmPrimitiveType type = (EdmPrimitiveType) action.getReturnType().getType();
if (property == null || property.isNull()) {
if (action.getReturnType().isNullable()) {
response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
} else {
// Not nullable return type so we have to give back an Internal Server Error
throw new ODataApplicationException("The action could not be executed.",
HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.ROOT);
}
} else {
ContextURL contextURL = ContextURL.with().type(type).build();
PrimitiveSerializerOptions options = PrimitiveSerializerOptions.with().contextURL(contextURL).build();
SerializerResult result = odata.createSerializer(ODataFormat.fromContentType(responseFormat)).primitive(type,
property, options);
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
response.setContent(result.getContent());
response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString());
}
}
@Override @Override
public void readPrimitiveCollection(final ODataRequest request, ODataResponse response, final UriInfo uriInfo, public void readPrimitiveCollection(final ODataRequest request, ODataResponse response, final UriInfo uriInfo,
final ContentType contentType) throws ODataApplicationException, SerializerException { final ContentType contentType) throws ODataApplicationException, SerializerException {
@ -163,42 +120,6 @@ public class TechnicalPrimitiveComplexProcessor extends TechnicalProcessor
deleteProperty(request, response, uriInfo); deleteProperty(request, response, uriInfo);
} }
@Override
public void processActionPrimitiveCollection(final ODataRequest request, ODataResponse response,
final UriInfo uriInfo, final ContentType requestFormat, final ContentType responseFormat)
throws ODataApplicationException, DeserializerException, SerializerException {
blockBoundActions(uriInfo);
final EdmAction action = ((UriResourceAction) uriInfo.asUriInfoResource().getUriResourceParts().get(0))
.getAction();
DeserializerResult deserializerResult =
odata.createDeserializer(ODataFormat.fromContentType(requestFormat))
.actionParameters(request.getBody(), action);
Property property =
dataProvider.processActionPrimitiveCollection(action.getName(), deserializerResult.getActionParameters());
if (property == null || property.isNull()) {
// Collection Propertys must never be null
throw new ODataApplicationException("The action could not be executed.",
HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.ROOT);
} else if (property.asCollection().contains(null) && !action.getReturnType().isNullable()) {
// Not nullable return type but array contains a null value
throw new ODataApplicationException("The action could not be executed.",
HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.ROOT);
}
EdmPrimitiveType type = (EdmPrimitiveType) action.getReturnType().getType();
ContextURL contextURL = ContextURL.with().type(type).asCollection().build();
PrimitiveSerializerOptions options = PrimitiveSerializerOptions.with().contextURL(contextURL).build();
SerializerResult result =
odata.createSerializer(ODataFormat.fromContentType(responseFormat))
.primitiveCollection(type, property, options);
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
response.setContent(result.getContent());
response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString());
}
@Override @Override
public void readComplex(final ODataRequest request, ODataResponse response, final UriInfo uriInfo, public void readComplex(final ODataRequest request, ODataResponse response, final UriInfo uriInfo,
final ContentType contentType) throws ODataApplicationException, SerializerException { final ContentType contentType) throws ODataApplicationException, SerializerException {
@ -218,41 +139,6 @@ public class TechnicalPrimitiveComplexProcessor extends TechnicalProcessor
deleteProperty(request, response, uriInfo); deleteProperty(request, response, uriInfo);
} }
@Override
public void processActionComplex(final ODataRequest request, ODataResponse response, final UriInfo uriInfo,
final ContentType requestFormat, final ContentType responseFormat)
throws ODataApplicationException, DeserializerException, SerializerException {
blockBoundActions(uriInfo);
final EdmAction action = ((UriResourceAction) uriInfo.asUriInfoResource().getUriResourceParts().get(0))
.getAction();
DeserializerResult deserializerResult =
odata.createDeserializer(ODataFormat.fromContentType(requestFormat))
.actionParameters(request.getBody(), action);
Property property = dataProvider.processActionComplex(action.getName(), deserializerResult.getActionParameters());
EdmComplexType type = (EdmComplexType) action.getReturnType().getType();
if (property == null || property.isNull()) {
if (action.getReturnType().isNullable()) {
response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
} else {
// Not nullable return type so we have to give back an Internal Server Error
throw new ODataApplicationException("The action could not be executed.",
HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.ROOT);
}
} else {
ContextURL contextURL = ContextURL.with().type(type).build();
ComplexSerializerOptions options = ComplexSerializerOptions.with().contextURL(contextURL).build();
SerializerResult result =
odata.createSerializer(ODataFormat.fromContentType(responseFormat)).complex(serviceMetadata, type, property,
options);
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
response.setContent(result.getContent());
response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString());
}
}
@Override @Override
public void readComplexCollection(final ODataRequest request, ODataResponse response, final UriInfo uriInfo, public void readComplexCollection(final ODataRequest request, ODataResponse response, final UriInfo uriInfo,
final ContentType contentType) throws ODataApplicationException, SerializerException { final ContentType contentType) throws ODataApplicationException, SerializerException {
@ -272,42 +158,6 @@ public class TechnicalPrimitiveComplexProcessor extends TechnicalProcessor
deleteProperty(request, response, uriInfo); deleteProperty(request, response, uriInfo);
} }
@Override
public void processActionComplexCollection(final ODataRequest request, ODataResponse response,
final UriInfo uriInfo, final ContentType requestFormat, final ContentType responseFormat)
throws ODataApplicationException, DeserializerException, SerializerException {
blockBoundActions(uriInfo);
final EdmAction action = ((UriResourceAction) uriInfo.asUriInfoResource().getUriResourceParts().get(0))
.getAction();
DeserializerResult deserializerResult =
odata.createDeserializer(ODataFormat.fromContentType(requestFormat))
.actionParameters(request.getBody(), action);
Property property =
dataProvider.processActionComplexCollection(action.getName(), deserializerResult.getActionParameters());
if (property == null || property.isNull()) {
// Collection Propertys must never be null
throw new ODataApplicationException("The action could not be executed.",
HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.ROOT);
} else if (property.asCollection().contains(null) && !action.getReturnType().isNullable()) {
// Not nullable return type but array contains a null value
throw new ODataApplicationException("The action could not be executed.",
HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.ROOT);
}
EdmComplexType type = (EdmComplexType) action.getReturnType().getType();
ContextURL contextURL = ContextURL.with().type(type).asCollection().build();
ComplexSerializerOptions options = ComplexSerializerOptions.with().contextURL(contextURL).build();
SerializerResult result =
odata.createSerializer(ODataFormat.fromContentType(responseFormat)).complexCollection(serviceMetadata, type,
property, options);
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
response.setContent(result.getContent());
response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString());
}
private void readProperty(final ODataRequest request, ODataResponse response, final UriInfo uriInfo, private void readProperty(final ODataRequest request, ODataResponse response, final UriInfo uriInfo,
final ContentType contentType, final RepresentationType representationType) final ContentType contentType, final RepresentationType representationType)
throws ODataApplicationException, SerializerException { throws ODataApplicationException, SerializerException {