Java Code Examples for org.apache.olingo.server.api.uri.UriResource#getKind()
The following examples show how to use
org.apache.olingo.server.api.uri.UriResource#getKind() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UriValidator.java From olingo-odata4 with Apache License 2.0 | 6 votes |
private void validatePropertyOperations(final UriInfo uriInfo, final HttpMethod method) throws UriValidationException { final List<UriResource> parts = uriInfo.getUriResourceParts(); final UriResource last = !parts.isEmpty() ? parts.get(parts.size() - 1) : null; final UriResource previous = parts.size() > 1 ? parts.get(parts.size() - 2) : null; if (last != null && (last.getKind() == UriResourceKind.primitiveProperty || last.getKind() == UriResourceKind.complexProperty || (last.getKind() == UriResourceKind.value && previous != null && previous.getKind() == UriResourceKind.primitiveProperty))) { final EdmProperty property = ((UriResourceProperty) (last.getKind() == UriResourceKind.value ? previous : last)).getProperty(); if (method == HttpMethod.PATCH && property.isCollection()) { throw new UriValidationException("Attempt to patch collection property.", UriValidationException.MessageKeys.UNSUPPORTED_HTTP_METHOD, method.toString()); } if (method == HttpMethod.DELETE && !property.isNullable()) { throw new UriValidationException("Attempt to delete non-nullable property.", UriValidationException.MessageKeys.UNSUPPORTED_HTTP_METHOD, method.toString()); } } }
Example 2
Source File: TechnicalPrimitiveComplexProcessor.java From olingo-odata4 with Apache License 2.0 | 5 votes |
private void validatePath(final UriInfoResource uriInfo) throws ODataApplicationException { final List<UriResource> resourcePaths = uriInfo.getUriResourceParts(); for (final UriResource segment : resourcePaths.subList(1, resourcePaths.size())) { final UriResourceKind kind = segment.getKind(); if (kind != UriResourceKind.navigationProperty && kind != UriResourceKind.primitiveProperty && kind != UriResourceKind.complexProperty && kind != UriResourceKind.count && kind != UriResourceKind.value && kind != UriResourceKind.function) { throw new ODataApplicationException("Invalid resource type.", HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ROOT); } } }
Example 3
Source File: ODataDispatcher.java From olingo-odata4 with Apache License 2.0 | 4 votes |
private void handleResourceDispatching(final ODataRequest request, final ODataResponse response) throws ODataApplicationException, ODataLibraryException { final int lastPathSegmentIndex = uriInfo.getUriResourceParts().size() - 1; final UriResource lastPathSegment = uriInfo.getUriResourceParts().get(lastPathSegmentIndex); switch (lastPathSegment.getKind()) { case action: checkMethod(request.getMethod(), HttpMethod.POST); handleActionDispatching(request, response, (UriResourceAction) lastPathSegment); break; case function: checkMethod(request.getMethod(), HttpMethod.GET); handleFunctionDispatching(request, response, (UriResourceFunction) lastPathSegment); break; case entitySet: case navigationProperty: handleEntityDispatching(request, response, ((UriResourcePartTyped) lastPathSegment).isCollection(), isEntityOrNavigationMedia(lastPathSegment)); break; case singleton: handleSingleEntityDispatching(request, response, isSingletonMedia(lastPathSegment), true); break; case count: checkMethod(request.getMethod(), HttpMethod.GET); handleCountDispatching(request, response, lastPathSegmentIndex); break; case primitiveProperty: handlePrimitiveDispatching(request, response, ((UriResourceProperty) lastPathSegment).isCollection()); break; case complexProperty: handleComplexDispatching(request, response, ((UriResourceProperty) lastPathSegment).isCollection()); break; case value: handleValueDispatching(request, response, lastPathSegmentIndex); break; case ref: handleReferenceDispatching(request, response, lastPathSegmentIndex); break; default: throw new ODataHandlerException(NOT_IMPLEMENTED_MESSAGE, ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED); } }
Example 4
Source File: PreconditionsValidator.java From olingo-odata4 with Apache License 2.0 | 4 votes |
private EdmBindingTarget extractInformation(final UriInfo uriInfo) throws PreconditionException { EdmBindingTarget lastFoundEntitySetOrSingleton = null; int counter = 0; for (UriResource uriResourcePart : uriInfo.getUriResourceParts()) { switch (uriResourcePart.getKind()) { case function: lastFoundEntitySetOrSingleton = getEntitySetFromFunctionImport((UriResourceFunction) uriResourcePart); break; case singleton: lastFoundEntitySetOrSingleton = ((UriResourceSingleton) uriResourcePart).getSingleton(); break; case entitySet: lastFoundEntitySetOrSingleton = getEntitySet((UriResourceEntitySet) uriResourcePart); break; case navigationProperty: lastFoundEntitySetOrSingleton = getEntitySetFromNavigation(lastFoundEntitySetOrSingleton, (UriResourceNavigation) uriResourcePart); break; case primitiveProperty: case complexProperty: break; case value: case action: // This should not be possible since the URI Parser validates this but to be sure we throw an exception. if (counter != uriInfo.getUriResourceParts().size() - 1) { throw new PreconditionException("$value or Action must be the last segment in the URI.", PreconditionException.MessageKeys.INVALID_URI); } break; default: lastFoundEntitySetOrSingleton = null; break; } if (lastFoundEntitySetOrSingleton == null) { // Once we loose track of the entity set there is no way to retrieve it. break; } counter++; } return lastFoundEntitySetOrSingleton; }
Example 5
Source File: UriValidator.java From olingo-odata4 with Apache License 2.0 | 4 votes |
/** * Determines the URI type for a resource path. * The URI parser has already made sure that there are enough segments for a given type of the last segment, * but don't try to extract always the second-to-last segment, it could cause an {@link IndexOutOfBoundsException}. */ private UriType getUriTypeForResource(final List<UriResource> segments) throws UriValidationException { final UriResource lastPathSegment = segments.get(segments.size() - 1); UriType uriType; switch (lastPathSegment.getKind()) { case count: uriType = getUriTypeForCount(segments.get(segments.size() - 2)); break; case action: uriType = getUriTypeForAction(lastPathSegment); break; case complexProperty: uriType = getUriTypeForComplexProperty(lastPathSegment); break; case entitySet: case navigationProperty: uriType = getUriTypeForEntitySet(lastPathSegment); break; case function: uriType = getUriTypeForFunction(lastPathSegment); break; case primitiveProperty: uriType = getUriTypeForPrimitiveProperty(lastPathSegment); break; case ref: uriType = getUriTypeForRef(segments.get(segments.size() - 2)); break; case singleton: uriType = UriType.entity; break; case value: uriType = getUriTypeForValue(segments.get(segments.size() - 2)); break; default: throw new UriValidationException("Unsupported uriResource kind: " + lastPathSegment.getKind(), UriValidationException.MessageKeys.UNSUPPORTED_URI_RESOURCE_KIND, lastPathSegment.getKind().toString()); } return uriType; }