protected boolean isGetRequest(ODataRequest request) { return request.getMethod() == Method.GET; }
protected boolean isGetRequest(ODataRequest request) { return request.getMethod() == Method.GET; }
/** * Check if the parser is being used in the context of a 'write operation'. * * @return {@code true} if it is used in the context of a 'write operation', {@code false} otherwise. */ protected boolean isWriteOperation() { return !GET.equals(request.getMethod()); }
/** * Check if the parser is being used in the context of a 'write operation'. * * @return {@code true} if it is used in the context of a 'write operation', {@code false} otherwise. */ protected boolean isWriteOperation() { return !GET.equals(request.getMethod()); }
private void doWireLogging(ODataRequest request) throws UnsupportedEncodingException { if (LOG.isTraceEnabled()) { LOG.trace("RAW REQUEST LOGGING"); LOG.trace("{} request for URL: {}", request.getMethod().name(), request.getUri()); for (Map.Entry<String, String> headerEntry : request.getHeaders().entrySet()) { LOG.trace("Header: {} value: {}", headerEntry.getKey(), headerEntry.getValue()); } LOG.trace("BODY: {}", request.getBodyText(UTF_8.name())); } } }
private void doWireLogging(ODataRequest request) throws UnsupportedEncodingException { if (LOG.isTraceEnabled()) { LOG.trace("RAW REQUEST LOGGING"); LOG.trace("{} request for URL: {}", request.getMethod().name(), request.getUri()); for (Map.Entry<String, String> headerEntry : request.getHeaders().entrySet()) { LOG.trace("Header: {} value: {}", headerEntry.getKey(), headerEntry.getValue()); } LOG.trace("BODY: {}", request.getBodyText(UTF_8.name())); } } }
private void ensureNonNullableCollectionArePresent(StructuredType entityType) throws ODataException { if (getRequest().getMethod() != ODataRequest.Method.POST) { return; } List<String> missingCollectionPropertyName = new ArrayList<>(); entityType.getStructuralProperties().stream() .filter(property -> (property.isCollection()) && !(property instanceof NavigationProperty) && (!property.isNullable())) .forEach(property -> { LOG.debug("Validating non-nullable collection property : {}", property.getName()); if (!foundCollectionProperties.contains(property.getName())) { missingCollectionPropertyName.add(property.getName()); } }); if (missingCollectionPropertyName.size() != 0) { StringJoiner joiner = new StringJoiner(","); missingCollectionPropertyName.forEach(joiner::add); LOG.debug("Non-nullable collections of {} are not found in the request" + missingCollectionPropertyName); throw new ODataUnmarshallingException("The request does not specify the non-nullable collections: '" + joiner.toString() + "."); } }
private void ensureNonNullableNavigationPropertiesArePresent(Set<String> navigationPropertyNames, StructuredType entityType) throws ODataException { if (getRequest().getMethod() != ODataRequest.Method.POST) { return; } List<String> missingNavigationPropertyNames = new ArrayList<>(); entityType.getStructuralProperties().stream() .filter(property -> (property instanceof NavigationProperty) && (!property.isNullable())) .forEach(property -> { LOG.debug("Validating non-nullable property : {}", property.getName()); if (!navigationPropertyNames.contains(property.getName())) { missingNavigationPropertyNames.add(property.getName()); } }); if (missingNavigationPropertyNames.size() != 0) { LOG.debug("Non-nullable navigation properties of {} are not found in the request" + missingNavigationPropertyNames); // NOTE: We are just logging if a navigation property is not present. // In future, we will impose this restriction like ODataJsonParser after // we support 8.2 of docs.oasis-open.org/odata/odata-atom-format/v4.0/cs02/odata-atom-format-v4.0-cs02.html } }
private void ensureNonNullableCollectionArePresent(StructuredType entityType) throws ODataException { if (getRequest().getMethod() != ODataRequest.Method.POST) { return; } List<String> missingCollectionPropertyName = new ArrayList<>(); entityType.getStructuralProperties().stream() .filter(property -> (property.isCollection()) && !(property instanceof NavigationProperty) && (!property.isNullable())) .forEach(property -> { LOG.debug("Validating non-nullable collection property : {}", property.getName()); if (!foundCollectionProperties.contains(property.getName())) { missingCollectionPropertyName.add(property.getName()); } }); if (missingCollectionPropertyName.size() != 0) { StringJoiner joiner = new StringJoiner(","); missingCollectionPropertyName.forEach(joiner::add); LOG.debug("Non-nullable collections of {} are not found in the request" + missingCollectionPropertyName); throw new ODataUnmarshallingException("The request does not specify the non-nullable collections: '" + joiner.toString() + "."); } }
/** * This method checks request method is PUT or POST or PATCH. * * @param request is ODataRequest * @return true if requested method is PUT or POST or PATCH otherwise false */ protected boolean isRightMethodForUnmarshall(ODataRequest request) { ODataRequest.Method method = request.getMethod(); return isPostMethod(method) || isPatchMethod(method) || isPutMethod(method); }
/** * This method checks request method is PUT or POST or PATCH. * * @param request is ODataRequest * @return true if requested method is PUT or POST or PATCH otherwise false */ protected boolean isRightMethodForUnmarshall(ODataRequest request) { ODataRequest.Method method = request.getMethod(); return isPostMethod(method) || isPatchMethod(method) || isPutMethod(method); }
private int getNumberOfChangeSetsInResult(List<ProcessorResult> result) { int changeSets = 0; for (ProcessorResult processorResult : result) { if (!processorResult.getRequestContext().getRequest().getMethod().equals(ODataRequest.Method.GET)) { changeSets++; } } return changeSets; }
private int getNumberOfChangeSetsInResult(List<ProcessorResult> result) { int changeSets = 0; for (ProcessorResult processorResult : result) { if (!processorResult.getRequestContext().getRequest().getMethod().equals(ODataRequest.Method.GET)) { changeSets++; } } return changeSets; }
@Override public int score(ODataRequestContext requestContext) { // Method must be DELETE and the URI must be an entity reference URI if (isDeleteMethod(requestContext.getRequest().getMethod()) && ODataUriUtil.isRefPathUri(requestContext.getUri())) { LOG.debug("Match for DeleteLinkUnmarshaller: {}", requestContext.getRequest()); return DELETE_LINK_SCORE; } return DEFAULT_SCORE; }
@Override public int score(ODataRequestContext requestContext) { // Method must be DELETE and the URI must be an entity reference URI if (isDeleteMethod(requestContext.getRequest().getMethod()) && ODataUriUtil.isRefPathUri(requestContext.getUri())) { LOG.debug("Match for DeleteLinkUnmarshaller: {}", requestContext.getRequest()); return DELETE_LINK_SCORE; } return DEFAULT_SCORE; }
@Override protected String getToEntityId(ODataRequestContext requestContext) throws ODataUnmarshallingException { // The body is expected to contain a single entity reference // See OData Atom XML specification chapter 13 String bodyText; try { bodyText = requestContext.getRequest().getBodyText(StandardCharsets.UTF_8.name()); } catch (UnsupportedEncodingException e) { throw new ODataSystemException("UTF-8 is not supported", e); } Document document = parseXML(bodyText); Element rootElement = document.getDocumentElement(); if (!rootElement.getNodeName().equals(REF)) { throw new ODataUnmarshallingException("A " + requestContext.getRequest().getMethod() + " request to an entity reference URI must contain a single entity reference in the body," + " but something else was found instead: " + rootElement.getNodeName()); } String idAttr = rootElement.getAttribute(ID); if (isNullOrEmpty(idAttr)) { throw new ODataUnmarshallingException("The <metadata:ref> element in the body has no 'id' attribute," + " or the attribute is empty. The element must have an 'id' attribute that refers" + " to the entity to link to."); } return idAttr; }
@Override public int score(ODataRequestContext requestContext) { // NOTE: Only POST and PUT are allowed for creating and updating links // See OData specification part 1, paragraph 11.4.6 ODataRequest.Method method = requestContext.getRequest().getMethod(); if ((isPostMethod(method) || isPutMethod(method)) && ODataUriUtil.isRefPathUri(requestContext.getUri())) { MediaType contentType = requestContext.getRequest().getContentType(); int score = super.score(contentType, supportedMediaTypes()); LOG.debug("Match for {}: {} with score: {}", this.getClass().getSimpleName(), requestContext.getRequest(), score); return score; } return DEFAULT_SCORE; }
@Override public int score(ODataRequestContext requestContext) { // NOTE: Only POST and PUT are allowed for creating and updating links // See OData specification part 1, paragraph 11.4.6 ODataRequest.Method method = requestContext.getRequest().getMethod(); if ((isPostMethod(method) || isPutMethod(method)) && ODataUriUtil.isRefPathUri(requestContext.getUri())) { MediaType contentType = requestContext.getRequest().getContentType(); int score = super.score(contentType, supportedMediaTypes()); LOG.debug("Match for {}: {} with score: {}", this.getClass().getSimpleName(), requestContext.getRequest(), score); return score; } return DEFAULT_SCORE; }
@Override protected Object processEntity(String bodyText) throws ODataException { initializeProcessor(new JsonProcessor(bodyText)); JsonPropertyExpander expander = new JsonPropertyExpander(getEntityDataModel()); String entityName = getEntityName(); Object entity = expander.loadEntity(entityName); StructuredType entityType = JsonParserUtils.getStructuredType(entityName, getEntityDataModel()); if (getRequest().getMethod() == ODataRequest.Method.POST) { JsonNullableValidator validator = new JsonNullableValidator(fields, links); validator.ensureCollection(entityType); validator.ensureNavigationProperties(entityType); } expander.setEntityProperties(entity, entityType, fields, null); setEntityNavigationProperties(entity, JsonParserUtils.getStructuredType(entityName, getEntityDataModel())); return entity; }
@Override protected Object processEntity(String bodyText) throws ODataException { initializeProcessor(new JsonProcessor(bodyText)); JsonPropertyExpander expander = new JsonPropertyExpander(getEntityDataModel()); String entityName = getEntityName(); Object entity = expander.loadEntity(entityName); StructuredType entityType = JsonParserUtils.getStructuredType(entityName, getEntityDataModel()); if (getRequest().getMethod() == ODataRequest.Method.POST) { JsonNullableValidator validator = new JsonNullableValidator(fields, links); validator.ensureCollection(entityType); validator.ensureNavigationProperties(entityType); } expander.setEntityProperties(entity, entityType, fields, null); setEntityNavigationProperties(entity, JsonParserUtils.getStructuredType(entityName, getEntityDataModel())); return entity; }