| /* |
| * 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.List; |
| import java.util.Locale; |
| |
| import org.apache.olingo.commons.api.edm.EdmEntitySet; |
| import org.apache.olingo.commons.api.http.HttpStatusCode; |
| import org.apache.olingo.server.api.OData; |
| import org.apache.olingo.server.api.ODataApplicationException; |
| import org.apache.olingo.server.api.ServiceMetadata; |
| import org.apache.olingo.server.api.processor.Processor; |
| import org.apache.olingo.server.api.uri.UriInfoResource; |
| import org.apache.olingo.server.api.uri.UriResource; |
| import org.apache.olingo.server.api.uri.UriResourceEntitySet; |
| import org.apache.olingo.server.tecsvc.data.DataProvider; |
| |
| /** |
| * Technical Processor base. |
| */ |
| public abstract class TechnicalProcessor implements Processor { |
| |
| protected OData odata; |
| protected DataProvider dataProvider; |
| |
| protected TechnicalProcessor(final DataProvider dataProvider) { |
| this.dataProvider = dataProvider; |
| } |
| |
| @Override |
| public void init(final OData odata, final ServiceMetadata serviceMetadata) { |
| this.odata = odata; |
| } |
| |
| protected EdmEntitySet getEdmEntitySet(final UriInfoResource uriInfo) throws ODataApplicationException { |
| final List<UriResource> resourcePaths = uriInfo.getUriResourceParts(); |
| // first must be entity set |
| if (!(resourcePaths.get(0) instanceof UriResourceEntitySet)) { |
| throw new ODataApplicationException("Invalid resource type.", |
| HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ROOT); |
| } |
| |
| final UriResourceEntitySet uriResource = (UriResourceEntitySet) resourcePaths.get(0); |
| if (uriResource.getTypeFilterOnCollection() != null || uriResource.getTypeFilterOnEntry() != null) { |
| throw new ODataApplicationException("Type filters are not supported.", |
| HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ROOT); |
| } |
| return uriResource.getEntitySet(); |
| } |
| |
| protected void validateOptions(final UriInfoResource uriInfo) throws ODataApplicationException { |
| if (uriInfo.getCountOption() != null |
| || !uriInfo.getCustomQueryOptions().isEmpty() |
| || uriInfo.getFilterOption() != null |
| || uriInfo.getIdOption() != null |
| || uriInfo.getOrderByOption() != null |
| || uriInfo.getSearchOption() != null |
| || uriInfo.getSkipOption() != null |
| || uriInfo.getSkipTokenOption() != null |
| || uriInfo.getTopOption() != null) { |
| throw new ODataApplicationException("Not all of the specified options are supported.", |
| HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ROOT); |
| } |
| } |
| } |