public static UriInfoImpl constructDeepReadForRoot(EdmEntitySet edmEntitySet, String serviceName, List<KeyPredicate> keyPredicates) throws ODataException { UriInfoImpl uriInfoForRead = new UriInfoImpl(); uriInfoForRead.setStartEntitySet(edmEntitySet); uriInfoForRead.setTargetEntitySet(edmEntitySet); Map<String,List<String>> compositionTree = CSNUtil.getCompositionTree(serviceName, edmEntitySet.getName()); List<ArrayList<NavigationPropertySegment>> expandOption = new ArrayList<>(); constructTreeExpand(edmEntitySet, serviceName, compositionTree, new ArrayList<>(), expandOption); uriInfoForRead.setKeyPredicates(keyPredicates); uriInfoForRead.setTargetType(edmEntitySet.getEntityType()); uriInfoForRead.setExpand(expandOption); return uriInfoForRead; }
private static void checkNotGetSystemQueryOptions(final ODataHttpMethod method, final UriInfoImpl uriInfo) throws ODataException { switch (uriInfo.getUriType()) { case URI1: case URI6B: if (uriInfo.getFormat() != null || uriInfo.getFilter() != null || uriInfo.getInlineCount() != null || uriInfo.getOrderBy() != null || uriInfo.getSkipToken() != null || uriInfo.getSkip() != null || uriInfo.getTop() != null || !uriInfo.getExpand().isEmpty() || !uriInfo.getSelect().isEmpty()) { throw new ODataMethodNotAllowedException(ODataMethodNotAllowedException.DISPATCH); if (uriInfo.getFormat() != null || !uriInfo.getExpand().isEmpty() || !uriInfo.getSelect().isEmpty()) { throw new ODataMethodNotAllowedException(ODataMethodNotAllowedException.DISPATCH); if (uriInfo.getFilter() != null) { throw new ODataMethodNotAllowedException(ODataMethodNotAllowedException.DISPATCH); if (uriInfo.getFormat() != null) { throw new ODataMethodNotAllowedException(ODataMethodNotAllowedException.DISPATCH); case URI5: if (method == ODataHttpMethod.PUT || method == ODataHttpMethod.PATCH || method == ODataHttpMethod.MERGE) { if (!uriInfo.isValue() && uriInfo.getFormat() != null) { throw new ODataMethodNotAllowedException(ODataMethodNotAllowedException.DISPATCH); if (uriInfo.getFormat() != null || uriInfo.getFilter() != null) { throw new ODataMethodNotAllowedException(ODataMethodNotAllowedException.DISPATCH); if (uriInfo.getFormat() != null || uriInfo.getFilter() != null || uriInfo.getInlineCount() != null || uriInfo.getOrderBy() != null || uriInfo.getSkipToken() != null || uriInfo.getSkip() != null || uriInfo.getTop() != null) {
private static void checkNumberOfNavigationSegments(final UriInfoImpl uriInfo) throws ODataException { switch (uriInfo.getUriType()) { case URI1: case URI6B: case URI7A: case URI7B: if (uriInfo.getNavigationSegments().size() > 1) { throw new ODataBadRequestException(ODataBadRequestException.NOTSUPPORTED); } break; case URI3: case URI4: case URI5: case URI17: if (!uriInfo.getNavigationSegments().isEmpty()) { throw new ODataBadRequestException(ODataBadRequestException.NOTSUPPORTED); } break; default: break; } }
private UriInfoImpl getDeleteUriInfo(UriInfoImpl uriInfoForRead, String navigationName, Map<String, Object> navigatedData, boolean isDraft) throws EdmException { UriInfoImpl uriInfoForDelete = new UriInfoImpl(); EdmEntitySet entitySet = this.getTargetEntitySetFromNavigation(uriInfoForRead, navigationName); if(entitySet != null) { List<KeyPredicate> keyPredicates = this.getKeys(entitySet, navigatedData, isDraft); uriInfoForDelete.setStartEntitySet(entitySet); uriInfoForDelete.setTargetEntitySet(entitySet); uriInfoForDelete.setKeyPredicates(keyPredicates); } return uriInfoForDelete; }
public static UriInfoImpl constructDeepReadForDraftRoot(EdmEntitySet edmEntitySet, String serviceName) throws ODataException { UriInfoImpl uriInfoForRead = new UriInfoImpl(); uriInfoForRead.setStartEntitySet(edmEntitySet); uriInfoForRead.setTargetEntitySet(edmEntitySet); Map<String,List<String>> draftTree = CSNUtil.getDraftTree(serviceName); List<ArrayList<NavigationPropertySegment>> expandOption = new ArrayList<>(); constructDraftTreeExpand(edmEntitySet, serviceName, draftTree, new ArrayList<>(), expandOption); uriInfoForRead.setExpand(expandOption); return uriInfoForRead; }
private void handleEntitySet(final EdmEntitySet entitySet, final String keyPredicate) throws UriSyntaxException, UriNotMatchingException, EdmException { final EdmEntityType entityType = entitySet.getEntityType(); uriResult.setTargetType(entityType); uriResult.setTargetEntitySet(entitySet); if (keyPredicate == null) { if (pathSegments.isEmpty()) { uriResult.setUriType(UriType.URI1); } else { currentPathSegment = pathSegments.remove(0); checkCount(); if (uriResult.isCount()) { uriResult.setUriType(UriType.URI15); } else { throw new UriSyntaxException(UriSyntaxException.ENTITYSETINSTEADOFENTITY.addContent(entitySet.getName())); } } } else { uriResult.setKeyPredicates(parseKey(keyPredicate, entityType)); if (pathSegments.isEmpty()) { uriResult.setUriType(UriType.URI2); } else { handleNavigationPathOptions(); } } }
private void handlePropertyPath(final EdmProperty property) throws UriSyntaxException, UriNotMatchingException, EdmException { uriResult.addProperty(property); final EdmType type = property.getType(); if (uriResult.getPropertyPath().size() == 1) { uriResult.setUriType(UriType.URI5); } else { uriResult.setUriType(UriType.URI4); uriResult.setUriType(UriType.URI3); } else { throw new UriSyntaxException(UriSyntaxException.INVALIDPROPERTYTYPE.addContent(type.getKind())); uriResult.setTargetType(type); } else { if ("$value".equals(currentPathSegment)) { ensureLastSegment(); uriResult.setValue(true); if (uriResult.getPropertyPath().size() == 1) { uriResult.setUriType(UriType.URI5); } else { uriResult.setUriType(UriType.URI4); uriResult.setTargetType(type); break;
private void addNavigationSegment(final String keyPredicateName, final EdmNavigationProperty navigationProperty) throws UriSyntaxException, EdmException { final EdmEntitySet targetEntitySet = uriResult.getTargetEntitySet().getRelatedEntitySet(navigationProperty); final EdmEntityType targetEntityType = targetEntitySet.getEntityType(); uriResult.setTargetEntitySet(targetEntitySet); uriResult.setTargetType(targetEntityType); NavigationSegmentImpl navigationSegment = new NavigationSegmentImpl(); navigationSegment.setEntitySet(targetEntitySet); navigationSegment.setNavigationProperty(navigationProperty); if (keyPredicateName != null) { navigationSegment.setKeyPredicates(parseKey(keyPredicateName, targetEntityType)); } uriResult.addNavigationSegment(navigationSegment); }
UriInfoImpl clone = ((UriInfoImpl) createView).getClone(); clone.setTargetEntitySet(createView.getStartEntitySet()); clone.getNavigationSegments().clear(); clone.setTargetType(clone.getTargetEntitySet().getEntityType()); Object relatedEntity = readEntity(new JPAQueryBuilder(oDataJPAContext).build((PutMergePatchUriInfo) clone), (UriInfo) clone); ((UriInfoImpl) createView).setKeyPredicates(predicates); ((UriInfoImpl) createView).setRawEntity(false);
private void handleNavigationPathOptions() throws UriSyntaxException, UriNotMatchingException, EdmException { currentPathSegment = pathSegments.remove(0); checkCount(); if (uriResult.isCount()) { uriResult.setUriType(UriType.URI16); // Count of multiple entities is handled elsewhere } else if ("$value".equals(currentPathSegment)) { if (uriResult.getTargetEntitySet().getEntityType().hasStream()) { ensureLastSegment(); uriResult.setUriType(UriType.URI17); uriResult.setValue(true); } else { throw new UriSyntaxException(UriSyntaxException.NOMEDIARESOURCE); } } else if ("$links".equals(currentPathSegment)) { uriResult.setLinks(true); if (pathSegments.isEmpty()) { throw new UriSyntaxException(UriSyntaxException.MUSTNOTBELASTSEGMENT.addContent(currentPathSegment)); } currentPathSegment = pathSegments.remove(0); handleNavigationProperties(); } else { handleNavigationProperties(); } }
uriResult.setTargetType(type); switch (type.getKind()) { case SIMPLE: uriResult.setUriType(isCollection ? UriType.URI13 : UriType.URI14); break; case COMPLEX: uriResult.setUriType(isCollection ? UriType.URI11 : UriType.URI12); break; case ENTITY: uriResult.setUriType(UriType.URI10); break; default: if (uriResult.getUriType() == UriType.URI14) { currentPathSegment = pathSegments.remove(0); if ("$value".equals(currentPathSegment)) { uriResult.setValue(true); } else { throw new UriSyntaxException(UriSyntaxException.INVALIDSEGMENT.addContent(currentPathSegment));
validateNotNull(odataRequest, uriInfo, supportedContentTypes); if (uriInfo.isCount()) { return ContentType.TEXT_PLAIN_CS_UTF_8; } else if (uriInfo.isValue()) { if (uriInfo.getUriType() == UriType.URI5 || uriInfo.getUriType() == UriType.URI4) { return ContentType.TEXT_PLAIN_CS_UTF_8; if (uriInfo.getFormat() == null) { return doContentNegotiationForAcceptHeader(odataRequest.getAcceptHeaders(), ContentType .create(supportedContentTypes));
final EdmTyped property = uriResult.getTargetEntitySet().getEntityType().getProperty(navigationPropertyName); if (property == null) { throw new UriNotMatchingException(UriNotMatchingException.PROPERTYNOTFOUND.addContent(navigationPropertyName)); if (uriResult.isLinks()) { throw new UriSyntaxException(UriSyntaxException.NONAVIGATIONPROPERTY.addContent(property)); if (uriResult.isLinks()) { uriResult.setUriType(UriType.URI7B); } else { uriResult.setUriType(UriType.URI6B); } else if (uriResult.isLinks()) { uriResult.setUriType(UriType.URI7A); } else { uriResult.setUriType(UriType.URI6A); } else if (many || uriResult.isLinks()) { currentPathSegment = pathSegments.remove(0); checkCount(); if (!uriResult.isCount()) { throw new UriSyntaxException(UriSyntaxException.INVALIDSEGMENT.addContent(currentPathSegment)); if (uriResult.isLinks()) { uriResult.setUriType(UriType.URI50B); } else { uriResult.setUriType(UriType.URI15); uriResult.setUriType(UriType.URI50A);
protected static Class<? extends ODataProcessor> mapUriTypeToProcessorFeature(final UriInfoImpl uriInfo) { Class<? extends ODataProcessor> feature; switch (uriInfo.getUriType()) { case URI0: feature = ServiceDocumentProcessor.class; case URI4: case URI5: feature = uriInfo.isValue() ? EntitySimplePropertyValueProcessor.class : EntitySimplePropertyProcessor.class; break; case URI7A: break; case URI14: feature = uriInfo.isValue() ? FunctionImportValueProcessor.class : FunctionImportProcessor.class; break; case URI17: break; default: throw new ODataRuntimeException("Unknown or not implemented URI type: " + uriInfo.getUriType());
private static UriInfoDraftHelperV2 transFormerForCreate(Map<String, Object> ent, EdmEntitySet entSet, DraftFlow flow) { UriInfoDraftHelperV2 uriT=new UriInfoDraftHelperV2(); //Create the UriInfoForCreate UriInfoImpl uriInfoForCreate = new UriInfoImpl(); uriInfoForCreate.setStartEntitySet(entSet); uriInfoForCreate.setTargetEntitySet(entSet); //Create the Deserializer //Remove any links and navigation links . We only want to create payload for a single level if(flow.equals(DraftFlow.DRAFT_ACTIVATE_FROMNEW)||flow.equals(DraftFlow.DRAFT_ACTIVATE_FROMEXISTING)) { washDraftEntity(ent); } //Clean up navigation properties as Olingo V2 insert doesn't allow them. ODataEntryImpl data = new ODataEntryImpl(washNavigationEntity(ent), null, null, null, false); uriT.setUriInfo(uriInfoForCreate); uriT.setContent(data); uriT.setUriFunction(UriFunction.CREATE); return uriT; }
private static void validateUriMethod(final ODataHttpMethod method, final UriInfoImpl uriInfo) throws ODataException { switch (uriInfo.getUriType()) { case URI0: case URI8: && method != ODataHttpMethod.PATCH && method != ODataHttpMethod.MERGE) { throw new ODataMethodNotAllowedException(ODataMethodNotAllowedException.DISPATCH); } else if (method == ODataHttpMethod.DELETE && !uriInfo.isValue()) { throw new ODataMethodNotAllowedException(ODataMethodNotAllowedException.DISPATCH); throw new ODataMethodNotAllowedException(ODataMethodNotAllowedException.DISPATCH); } else { if (uriInfo.getFormat() != null) { throw new ODataRuntimeException("Unknown or not implemented URI type: " + uriInfo.getUriType());
EdmEntitySet fromEntitySet = uriResult.getTargetEntitySet(); uriResult.setExpand(expand);
private void handleSystemQueryOptionOrderBy(final String orderBy) throws UriSyntaxException { final EdmType targetType = uriResult.getTargetType(); if (targetType instanceof EdmEntityType) { try { uriResult.setOrderBy(parseOrderByString((EdmEntityType) targetType, orderBy)); } catch (ExpressionParserException e) { throw new UriSyntaxException(UriSyntaxException.INVALIDORDERBYEXPRESSION.addContent(orderBy), e); } catch (ODataMessageException e) { throw new UriSyntaxException(UriSyntaxException.INVALIDORDERBYEXPRESSION.addContent(orderBy), e); } } }
private void handleSystemQueryOptionFilter(final String filter) throws UriSyntaxException { final EdmType targetType = uriResult.getTargetType(); if (targetType instanceof EdmEntityType) { try { uriResult.setFilter(new FilterParserImpl((EdmEntityType) targetType).parseFilterString(filter, true)); } catch (ExpressionParserException e) { throw new UriSyntaxException(UriSyntaxException.INVALIDFILTEREXPRESSION.addContent(filter), e); } catch (ODataMessageException e) { throw new UriSyntaxException(UriSyntaxException.INVALIDFILTEREXPRESSION.addContent(filter), e); } } }
/** * A modifying request that targets an entity with enabled concurrency control * must contain at least one concurrency-control HTTP request header field. */ private static void checkConditions(final ODataHttpMethod method, final UriInfoImpl uriInfo, final String ifMatch, final String ifNoneMatch, final String ifModifiedSince, final String ifUnmodifiedSince) throws ODataException { if ((method == ODataHttpMethod.PUT || method == ODataHttpMethod.PATCH || method == ODataHttpMethod.MERGE || method == ODataHttpMethod.DELETE) && ifMatch == null && ifNoneMatch == null && ifModifiedSince == null && ifUnmodifiedSince == null && Arrays.asList(UriType.URI2, UriType.URI6A, UriType.URI3, UriType.URI4, UriType.URI5, UriType.URI17) .contains(uriInfo.getUriType()) && hasConcurrencyControl(uriInfo.getTargetEntitySet().getEntityType())) { throw new ODataPreconditionRequiredException(ODataPreconditionRequiredException.COMMON); } }