org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException Java Examples
The following examples show how to use
org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException.
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: ODataAdapter.java From micro-integrator with Apache License 2.0 | 6 votes |
/** * This method returns the object which is the value of the property. * * @param edmProperty EdmProperty * @param value String value * @return Object * @throws ODataApplicationException */ private Object readPrimitiveValue(EdmProperty edmProperty, String value) throws ODataApplicationException { if (value == null) { return null; } try { if (value.startsWith("'") && value.endsWith("'")) { value = value.substring(1, value.length() - 1); } EdmPrimitiveType edmPrimitiveType = (EdmPrimitiveType) edmProperty.getType(); Class<?> javaClass = getJavaClassForPrimitiveType(edmProperty, edmPrimitiveType); return edmPrimitiveType.valueOfString(value, edmProperty.isNullable(), edmProperty.getMaxLength(), edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode(), javaClass); } catch (EdmPrimitiveTypeException e) { throw new ODataApplicationException("Invalid value: " + value + " for property: " + edmProperty.getName(), HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.getDefault()); } }
Example #2
Source File: AtomSerializer.java From olingo-odata4 with Apache License 2.0 | 6 votes |
private void writeLink(final XMLStreamWriter writer, final Link link, final ExtraContent content) throws XMLStreamException, EdmPrimitiveTypeException { writer.writeStartElement(Constants.ATOM_ELEM_LINK); if (link.getRel() != null) { writer.writeAttribute(Constants.ATTR_REL, link.getRel()); } if (link.getTitle() != null) { writer.writeAttribute(Constants.ATTR_TITLE, link.getTitle()); } if (link.getHref() != null) { writer.writeAttribute(Constants.ATTR_HREF, link.getHref()); } if (link.getType() != null) { writer.writeAttribute(Constants.ATTR_TYPE, link.getType()); } content.write(writer, link); for (Annotation annotation : link.getAnnotations()) { annotation(writer, annotation, null); } writer.writeEndElement(); }
Example #3
Source File: SingletonTestITCase.java From olingo-odata4 with Apache License 2.0 | 6 votes |
private void update(final ContentType contentType) throws EdmPrimitiveTypeException { final ClientSingleton changes = getClient().getObjectFactory().newSingleton( new FullQualifiedName("Microsoft.Test.OData.Services.ODataWCFService.Company")); changes.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("Revenue", getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt64(132520L))); final URI uri = client.newURIBuilder(testStaticServiceRootURL).appendSingletonSegment("Company").build(); final ODataEntityUpdateRequest<ClientSingleton> req = getClient().getCUDRequestFactory(). getSingletonUpdateRequest(uri, UpdateType.PATCH, changes); req.setFormat(contentType); final ODataEntityUpdateResponse<ClientSingleton> res = req.execute(); assertEquals(204, res.getStatusCode()); final ClientSingleton updated = getClient().getRetrieveRequestFactory().getSingletonRequest(uri).execute().getBody(); assertNotNull(updated); assertEquals(132520, updated.getProperty("Revenue").getPrimitiveValue().toCastValue(Integer.class), 0); }
Example #4
Source File: ODataJsonDeserializer.java From olingo-odata4 with Apache License 2.0 | 6 votes |
private Object readPrimitiveValue(final String name, final EdmPrimitiveType type, final boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale, final boolean isUnicode, final EdmMapping mapping, final JsonNode jsonNode) throws DeserializerException { if (isValidNull(name, isNullable, jsonNode)) { return null; } final boolean isGeoType = type.getName().startsWith("Geo"); if (!isGeoType) { checkForValueNode(name, jsonNode); } checkJsonTypeBasedOnPrimitiveType(name, type, jsonNode); try { if (isGeoType) { return readPrimitiveGeoValue(name, type, (ObjectNode) jsonNode); } return type.valueOfString(jsonNode.asText(), isNullable, maxLength, precision, scale, isUnicode, getJavaClassForPrimitiveType(mapping, type)); } catch (final EdmPrimitiveTypeException e) { throw new DeserializerException( "Invalid value: " + jsonNode.asText() + " for property: " + name, e, DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY, name); } }
Example #5
Source File: ActionData.java From olingo-odata4 with Apache License 2.0 | 6 votes |
protected static Property primitiveCollectionBoundAction(final String name, final Map<String, Parameter> parameters, final Map<String, EntityCollection> data, EdmEntitySet edmEntitySet, List<UriParameter> keyList, final OData oData) throws DataProviderException { List<Object> collectionValues = new ArrayList<Object>(); if ("BAETTwoPrimRTCollString".equals(name)) { EdmPrimitiveType strType = oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.String); try { String strValue1 = strType.valueToString("ABC", false, 100, null, null, false); collectionValues.add(strValue1); String strValue2 = strType.valueToString("XYZ", false, 100, null, null, false); collectionValues.add(strValue2); } catch (EdmPrimitiveTypeException e) { throw new DataProviderException("EdmPrimitiveTypeException", HttpStatusCode.BAD_REQUEST, e); } return new Property(null, name, ValueType.COLLECTION_PRIMITIVE, collectionValues); } throw new DataProviderException("Action " + name + " is not yet implemented.", HttpStatusCode.NOT_IMPLEMENTED); }
Example #6
Source File: EdmBinary.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Override protected <T> T internalValueOfString(final String value, final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale, final Boolean isUnicode, final Class<T> returnType) throws EdmPrimitiveTypeException { if (value == null || !isBase64(value.getBytes(UTF_8))) { throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content."); } if (!validateMaxLength(value, maxLength)) { throw new EdmPrimitiveTypeException("The literal '" + value + "' does not match the facets' constraints."); } final byte[] result = Base64.decodeBase64(value.getBytes(UTF_8)); if (returnType.isAssignableFrom(byte[].class)) { return returnType.cast(result); } else if (returnType.isAssignableFrom(Byte[].class)) { final Byte[] byteArray = new Byte[result.length]; for (int i = 0; i < result.length; i++) { byteArray[i] = result[i]; } return returnType.cast(byteArray); } else { throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported."); } }
Example #7
Source File: EdmBinary.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Override protected <T> String internalValueToString(final T value, final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { byte[] byteArrayValue; if (value instanceof byte[]) { byteArrayValue = (byte[]) value; } else if (value instanceof Byte[]) { final int length = ((Byte[]) value).length; byteArrayValue = new byte[length]; for (int i = 0; i < length; i++) { byteArrayValue[i] = ((Byte[]) value)[i].byteValue(); } } else { throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported."); } if (maxLength != null && byteArrayValue.length > maxLength) { throw new EdmPrimitiveTypeException("The value '" + value + "' does not match the facets' constraints."); } return new String(Base64.encodeBase64(byteArrayValue, false), UTF_8); }
Example #8
Source File: PrimitiveValueTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void Date() throws EdmPrimitiveTypeException { final Calendar expected = Calendar.getInstance(); expected.clear(); expected.set(2013, 0, 10); final ClientValue value = client.getObjectFactory().newPrimitiveValueBuilder() .setType(EdmPrimitiveTypeKind.Date).setValue(expected).build(); assertEquals(EdmPrimitiveTypeKind.Date, value.asPrimitive().getTypeKind()); final Calendar actual = value.asPrimitive().toCastValue(Calendar.class); assertEquals(expected.get(Calendar.YEAR), actual.get(Calendar.YEAR)); assertEquals(expected.get(Calendar.MONTH), actual.get(Calendar.MONTH)); assertEquals(expected.get(Calendar.DATE), actual.get(Calendar.DATE)); assertEquals("2013-01-10", value.asPrimitive().toString()); }
Example #9
Source File: AbstractGeospatialType.java From olingo-odata4 with Apache License 2.0 | 6 votes |
protected String toString(final MultiLineString multiLineString, final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { if (dimension != multiLineString.getDimension()) { throw new EdmPrimitiveTypeException("The value '" + multiLineString + "' is not valid."); } final StringBuilder result = toStringBuilder(multiLineString.getSrid()). append(reference.getSimpleName()). append('('); for (final Iterator<LineString> itor = multiLineString.iterator(); itor.hasNext();) { result.append('('); appendPoints(itor.next(), isNullable, maxLength, precision, scale, isUnicode, result). append(')'); if (itor.hasNext()) { result.append(','); } } return result.append(")'").toString(); }
Example #10
Source File: EdmDateTimeOffset.java From olingo-odata4 with Apache License 2.0 | 6 votes |
private static <T> ZonedDateTime createZonedDateTime(final T value) throws EdmPrimitiveTypeException { if (value instanceof ZonedDateTime) { return (ZonedDateTime) value; } if (value instanceof Instant) { return ((Instant) value).atZone(ZULU); } if (value instanceof GregorianCalendar) { GregorianCalendar calendar = (GregorianCalendar) value; ZonedDateTime zdt = calendar.toZonedDateTime(); ZoneId normalizedZoneId = calendar.getTimeZone().toZoneId().normalized(); return zdt.withZoneSameInstant(normalizedZoneId); } return convertToInstant(value).atZone(ZULU); }
Example #11
Source File: AbstractGeospatialType.java From olingo-odata4 with Apache License 2.0 | 6 votes |
private Matcher getMatcher(final Pattern pattern, final String value) throws EdmPrimitiveTypeException { final Matcher matcher = pattern.matcher(value); if (!matcher.matches()) { throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content."); } Geospatial.Dimension _dimension = null; Geospatial.Type _type = null; try { _dimension = Geospatial.Dimension.valueOf(matcher.group(1).toUpperCase()); _type = Geospatial.Type.valueOf(matcher.group(3).toUpperCase()); } catch (IllegalArgumentException e) { throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.", e); } if (_dimension != this.dimension || (!pattern.equals(COLLECTION_PATTERN) && _type != this.type)) { throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content."); } return matcher; }
Example #12
Source File: AtomSerializer.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Override public <T> void write(final Writer writer, final T obj) throws ODataSerializerException { try { if (obj instanceof EntityCollection) { entitySet(writer, (EntityCollection) obj); } else if (obj instanceof Entity) { entity(writer, (Entity) obj); } else if (obj instanceof Property) { property(writer, (Property) obj); } else if (obj instanceof Link) { link(writer, (Link) obj); } } catch (final XMLStreamException | EdmPrimitiveTypeException e) { throw new ODataSerializerException(e); } }
Example #13
Source File: EdmGeoTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void multiPoint() throws EdmPrimitiveTypeException { final String input = "geography'SRID=0;MultiPoint((142.1 64.1),(1.0 2.0))'"; expectContentErrorInValueOfString(EdmGeometryMultiPoint.getInstance(), input); MultiPoint multipoint = EdmGeographyMultiPoint.getInstance(). valueOfString(input, null, null, null, null, null, MultiPoint.class); assertNotNull(multipoint); assertEquals("0", multipoint.getSrid().toString()); assertEquals(142.1, multipoint.iterator().next().getX(), 0); assertEquals(64.1, multipoint.iterator().next().getY(), 0); assertEquals(input, EdmGeographyMultiPoint.getInstance().valueToString(multipoint, null, null, null, null, null)); multipoint = EdmGeographyMultiPoint.getInstance(). valueOfString("geography'SRID=0;MultiPoint()'", null, null, null, null, null, MultiPoint.class); assertFalse(multipoint.iterator().hasNext()); }
Example #14
Source File: AbstractGeospatialType.java From olingo-odata4 with Apache License 2.0 | 6 votes |
protected String toString(final MultiPoint multiPoint, final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { if (dimension != multiPoint.getDimension()) { throw new EdmPrimitiveTypeException("The value '" + multiPoint + "' is not valid."); } final StringBuilder result = toStringBuilder(multiPoint.getSrid()). append(reference.getSimpleName()). append('('); for (final Iterator<Point> itor = multiPoint.iterator(); itor.hasNext();) { result.append('('). append(point(itor.next(), isNullable, maxLength, precision, scale, isUnicode)). append(')'); if (itor.hasNext()) { result.append(','); } } return result.append(")'").toString(); }
Example #15
Source File: EdmEnumTypeImpl.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Override public String valueToString(final Object value, final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { if (value == null) { if (isNullable != null && !isNullable) { throw new EdmPrimitiveTypeException("The value NULL is not allowed."); } return null; } if (value instanceof Byte || value instanceof Short || value instanceof Integer || value instanceof Long) { return constructEnumValue(((Number) value).longValue()); } else { throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported."); } }
Example #16
Source File: ODataJsonDeserializer.java From olingo-odata4 with Apache License 2.0 | 6 votes |
private List<Point> readGeoPointValues(final String name, final Geospatial.Dimension dimension, final int minimalSize, final boolean closed, JsonNode node) throws DeserializerException, EdmPrimitiveTypeException { if (node.isArray()) { List<Point> points = new ArrayList<>(); for (final JsonNode element : node) { points.add(readGeoPointValue(name, dimension, element, null)); } if (points.size() >= minimalSize && (!closed || points.get(points.size() - 1).equals(points.get(0)))) { return points; } } throw new DeserializerException("Invalid point values '" + node + "' in property: " + name, DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY, name); }
Example #17
Source File: EdmGeographyMultiPoint.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Override protected <T> String internalValueToString(final T value, final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { if (value instanceof MultiPoint) { return toString((MultiPoint) value, isNullable, maxLength, precision, scale, isUnicode); } throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported."); }
Example #18
Source File: EdmGeometryMultiPolygon.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Override protected <T> String internalValueToString(final T value, final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { if (value instanceof MultiPolygon) { return toString((MultiPolygon) value, isNullable, maxLength, precision, scale, isUnicode); } throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported."); }
Example #19
Source File: ODataJsonDeserializer.java From olingo-odata4 with Apache License 2.0 | 5 votes |
private Point readGeoPointValue(final String name, final Geospatial.Dimension dimension, JsonNode node, SRID srid) throws DeserializerException, EdmPrimitiveTypeException { if (node.isArray() && (node.size() ==2 || node.size() == 3) && node.get(0).isNumber() && node.get(1).isNumber() && (node.get(2) == null || node.get(2).isNumber())) { Point point = new Point(dimension, srid); point.setX(getDoubleValue(node.get(0).asText())); point.setY(getDoubleValue(node.get(1).asText())); if (node.get(2) != null) { point.setZ(getDoubleValue(node.get(2).asText())); } return point; } throw new DeserializerException("Invalid point value '" + node + "' in property: " + name, DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY, name); }
Example #20
Source File: EdmDate.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Override protected <T> String internalValueToString(final T value, final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { // appropriate types if (value instanceof LocalDate) { return value.toString(); } else if (value instanceof java.sql.Date) { return value.toString(); } // inappropriate types, which need to be supported for backward compatibility if (value instanceof GregorianCalendar) { GregorianCalendar calendar = (GregorianCalendar) value; return calendar.toZonedDateTime().toLocalDate().toString(); } long millis; if (value instanceof Long) { millis = (Long) value; } else if (value instanceof java.util.Date) { millis = ((java.util.Date) value).getTime(); } else { throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported."); } ZonedDateTime zdt = Instant.ofEpochMilli(millis).atZone(ZoneId.systemDefault()); return zdt.toLocalDate().toString(); }
Example #21
Source File: EdmGeometryMultiPoint.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Override protected <T> T internalValueOfString(final String value, final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale, final Boolean isUnicode, final Class<T> returnType) throws EdmPrimitiveTypeException { final MultiPoint point = stringToMultiPoint(value, isNullable, maxLength, precision, scale, isUnicode); if (returnType.isAssignableFrom(MultiPoint.class)) { return returnType.cast(point); } else { throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported."); } }
Example #22
Source File: ODataXmlDeserializer.java From olingo-odata4 with Apache License 2.0 | 5 votes |
private void properties(final XMLEventReader reader, final StartElement start, final Entity entity, final EdmEntityType edmEntityType) throws XMLStreamException, EdmPrimitiveTypeException, DeserializerException { boolean foundEndProperties = false; while (reader.hasNext() && !foundEndProperties) { final XMLEvent event = reader.nextEvent(); if (event.isStartElement()) { String propertyName = event.asStartElement().getName().getLocalPart(); EdmProperty edmProperty = (EdmProperty) edmEntityType.getProperty(propertyName); if (edmProperty == null) { throw new DeserializerException("Invalid Property in payload with name: " + propertyName, DeserializerException.MessageKeys.UNKNOWN_CONTENT, propertyName); } entity.getProperties().add(property(reader, event.asStartElement(), edmProperty.getType(), edmProperty.isNullable(), edmProperty.getMaxLength(), edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode(), edmProperty.isCollection())); } if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) { foundEndProperties = true; } } }
Example #23
Source File: ClientODataDeserializerImpl.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Override public ResWrap<Delta> toDelta(final InputStream input) throws ODataDeserializerException { try { return contentType.isCompatible(ContentType.APPLICATION_ATOM_SVC) || contentType.isCompatible(ContentType.APPLICATION_ATOM_XML) ? new AtomDeserializer().delta(input) : new JsonDeltaDeserializer(false).toDelta(input); } catch (final XMLStreamException | EdmPrimitiveTypeException e) { throw new ODataDeserializerException(e); } }
Example #24
Source File: EdmGeographyMultiLineString.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Override protected <T> String internalValueToString(final T value, final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { if (value instanceof MultiLineString) { return toString((MultiLineString) value, isNullable, maxLength, precision, scale, isUnicode); } throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported."); }
Example #25
Source File: ClientPrimitiveValueImpl.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Override public String toString() { if (value == null) { return ""; } else if (typeKind.isGeospatial()) { return value.toString(); } else { try { // TODO: set facets return type.valueToString(value, null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null); } catch (EdmPrimitiveTypeException e) { throw new IllegalArgumentException(e); } } }
Example #26
Source File: PrimitiveTypeBaseTest.java From olingo-odata4 with Apache License 2.0 | 5 votes |
protected void expectErrorInFromUriLiteral(final EdmPrimitiveType instance, final String value) { try { instance.fromUriLiteral(value); fail("Expected exception not thrown"); } catch (final EdmPrimitiveTypeException e) { assertNotNull(e.getLocalizedMessage()); assertThat(e.getLocalizedMessage(), containsString("' has illegal content.")); } }
Example #27
Source File: EdmGeographyMultiPolygon.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Override protected <T> T internalValueOfString(final String value, final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale, final Boolean isUnicode, final Class<T> returnType) throws EdmPrimitiveTypeException { final MultiPolygon multiPolygon = stringToMultiPolygon(value, isNullable, maxLength, precision, scale, isUnicode); if (returnType.isAssignableFrom(MultiPolygon.class)) { return returnType.cast(multiPolygon); } else { throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported."); } }
Example #28
Source File: AbstractGeospatialType.java From olingo-odata4 with Apache License 2.0 | 5 votes |
protected String toString(final LineString lineString, final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { if (dimension != lineString.getDimension()) { throw new EdmPrimitiveTypeException("The value '" + lineString + "' is not valid."); } StringBuilder builder = toStringBuilder(lineString.getSrid()). append(reference.getSimpleName()). append('('); return appendPoints(lineString, isNullable, maxLength, precision, scale, isUnicode, builder). append(")'").toString(); }
Example #29
Source File: ParserHelper.java From olingo-odata4 with Apache License 2.0 | 5 votes |
protected static void validateFunctionParameterFacets(final EdmFunction function, final List<UriParameter> parameters, Edm edm, Map<String, AliasQueryOption> aliases) throws UriParserException, UriValidationException { for (UriParameter parameter : parameters) { EdmParameter edmParameter = function.getParameter(parameter.getName()); final EdmType type = edmParameter.getType(); final EdmTypeKind kind = type.getKind(); if ((kind == EdmTypeKind.PRIMITIVE || kind == EdmTypeKind.DEFINITION || kind == EdmTypeKind.ENUM) && !edmParameter.isCollection()) { final EdmPrimitiveType primitiveType = (EdmPrimitiveType) type; String text = null; try { text = parameter.getAlias() == null ? parameter.getText() : aliases.containsKey(parameter.getAlias()) ? parseAliasValue(parameter.getAlias(), edmParameter.getType(), edmParameter.isNullable(), edmParameter.isCollection(), edm, type, aliases).getText() : null; if (edmParameter.getMapping() == null) { primitiveType.valueOfString(primitiveType.fromUriLiteral(text), edmParameter.isNullable(), edmParameter.getMaxLength(), edmParameter.getPrecision(), edmParameter.getScale(), true, primitiveType.getDefaultType()); } else { primitiveType.valueOfString(primitiveType.fromUriLiteral(text), edmParameter.isNullable(), edmParameter.getMaxLength(), edmParameter.getPrecision(), edmParameter.getScale(), true, edmParameter.getMapping().getMappedJavaClass()); } } catch (final EdmPrimitiveTypeException e) { throw new UriValidationException( "Invalid value '" + text + "' for parameter " + parameter.getName(), e, UriValidationException.MessageKeys.INVALID_VALUE_FOR_PROPERTY, parameter.getName()); } } } }
Example #30
Source File: BasicITCase.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Test public void upsert() throws EdmPrimitiveTypeException { final ClientEntity entity = getFactory().newEntity(new FullQualifiedName(SERVICE_NAMESPACE, "ETTwoPrim")); entity.getProperties().add(getFactory().newPrimitiveProperty(PROPERTY_STRING, getFactory().newPrimitiveValueBuilder().buildString("Test"))); final URI uri = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_TWO_PRIM).appendKeySegment(33) .build(); final ODataEntityUpdateResponse<ClientEntity> updateResponse = getEdmEnabledClient().getCUDRequestFactory().getEntityUpdateRequest(uri, UpdateType.PATCH, entity).execute(); assertEquals(HttpStatusCode.CREATED.getStatusCode(), updateResponse.getStatusCode()); assertEquals("Test", updateResponse.getBody().getProperty(PROPERTY_STRING).getPrimitiveValue().toValue()); final String cookie = updateResponse.getHeader(HttpHeader.SET_COOKIE).iterator().next(); final Short key = updateResponse.getBody().getProperty(PROPERTY_INT16) .getPrimitiveValue() .toCastValue(Short.class); final ODataEntityRequest<ClientEntity> entityRequest = getEdmEnabledClient().getRetrieveRequestFactory() .getEntityRequest(getEdmEnabledClient().newURIBuilder() .appendEntitySetSegment(ES_TWO_PRIM) .appendKeySegment(key) .build()); entityRequest.addCustomHeader(HttpHeader.COOKIE, cookie); final ODataRetrieveResponse<ClientEntity> responseEntityRequest = entityRequest.execute(); assertEquals(HttpStatusCode.OK.getStatusCode(), responseEntityRequest.getStatusCode()); assertEquals("Test", responseEntityRequest.getBody().getProperty(PROPERTY_STRING).getPrimitiveValue().toValue()); }