org.apache.olingo.odata2.api.edm.EdmSimpleType Java Examples
The following examples show how to use
org.apache.olingo.odata2.api.edm.EdmSimpleType.
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: AtomEntryEntitySerializer.java From olingo-odata2 with Apache License 2.0 | 6 votes |
private String getTargetPathValue(final EntityInfoAggregator eia, final String targetPath, final Map<String, Object> data) throws EntityProviderException { EntityPropertyInfo info = null; try { info = eia.getTargetPathInfo(targetPath); if (info != null) { EdmSimpleType type = (EdmSimpleType) info.getType(); Object value = data.get(info.getName()); return type.valueToString(value, EdmLiteralKind.DEFAULT, info.getFacets()); } return null; } catch (final EdmSimpleTypeException e) { throw new EntityProviderProducerException( EdmSimpleTypeException.getMessageReference(e.getMessageReference()). updateContent(e.getMessageReference().getContent(), info.getName()), e); } }
Example #2
Source File: EdmSimpleTypeTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void valueToStringInt32() throws Exception { final EdmSimpleType instance = EdmSimpleTypeKind.Int32.getEdmSimpleTypeInstance(); assertEquals("0", instance.valueToString(0, EdmLiteralKind.DEFAULT, null)); assertEquals("0", instance.valueToString(0, EdmLiteralKind.JSON, null)); assertEquals("0", instance.valueToString(0, EdmLiteralKind.URI, null)); assertEquals("8", instance.valueToString((byte) 8, EdmLiteralKind.DEFAULT, null)); assertEquals("16", instance.valueToString((short) 16, EdmLiteralKind.DEFAULT, null)); assertEquals("32", instance.valueToString(Integer.valueOf(32), EdmLiteralKind.DEFAULT, null)); assertEquals("255", instance.valueToString(255L, EdmLiteralKind.DEFAULT, null)); expectErrorInValueToString(instance, 12345678901L, EdmLiteralKind.DEFAULT, null, EdmSimpleTypeException.VALUE_ILLEGAL_CONTENT); expectErrorInValueToString(instance, -2147483649L, EdmLiteralKind.DEFAULT, null, EdmSimpleTypeException.VALUE_ILLEGAL_CONTENT); expectErrorInValueToString(instance, 1.0, EdmLiteralKind.DEFAULT, null, EdmSimpleTypeException.VALUE_TYPE_NOT_SUPPORTED); expectErrorInValueToString(instance, 1, null, null, EdmSimpleTypeException.LITERAL_KIND_MISSING); }
Example #3
Source File: EdmSimpleTypeTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void checkValueOfNull() throws Exception { for (EdmSimpleTypeKind kind : EdmSimpleTypeKind.values()) { if (kind == EdmSimpleTypeKind.Null) { continue; } final EdmSimpleType instance = kind.getEdmSimpleTypeInstance(); assertNull(instance.valueOfString(null, EdmLiteralKind.DEFAULT, null, instance.getDefaultType())); assertNull(instance.valueOfString(null, EdmLiteralKind.DEFAULT, getNullableFacets(true), instance .getDefaultType())); assertNull(instance.valueOfString(null, EdmLiteralKind.DEFAULT, getNullableFacets(null), instance .getDefaultType())); expectErrorInValueOfString(instance, null, EdmLiteralKind.DEFAULT, getNullableFacets(false), EdmSimpleTypeException.LITERAL_NULL_NOT_ALLOWED); expectErrorInValueOfString(instance, "", null, null, EdmSimpleTypeException.LITERAL_KIND_MISSING); } }
Example #4
Source File: EdmSimpleTypeTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void valueOfStringInt32() throws Exception { final EdmSimpleType instance = EdmSimpleTypeKind.Int32.getEdmSimpleTypeInstance(); assertEquals(Byte.valueOf((byte) 1), instance.valueOfString("1", EdmLiteralKind.DEFAULT, null, Byte.class)); assertEquals(Short.valueOf((short) 2), instance.valueOfString("2", EdmLiteralKind.JSON, null, Short.class)); assertEquals(Integer.valueOf(-10000000), instance.valueOfString("-10000000", EdmLiteralKind.URI, null, Integer.class)); assertEquals(Long.valueOf(10000000), instance.valueOfString("10000000", EdmLiteralKind.URI, null, Long.class)); expectErrorInValueOfString(instance, "-2147483649", EdmLiteralKind.DEFAULT, null, EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT); expectErrorInValueOfString(instance, "1.0", EdmLiteralKind.DEFAULT, null, EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT); expectTypeErrorInValueOfString(instance, "1", EdmLiteralKind.DEFAULT); expectUnconvertibleErrorInValueOfString(instance, "-129", Byte.class); expectUnconvertibleErrorInValueOfString(instance, "128", Byte.class); expectUnconvertibleErrorInValueOfString(instance, "-32769", Short.class); expectUnconvertibleErrorInValueOfString(instance, "32768", Short.class); }
Example #5
Source File: EdmSimpleTypeTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void valueToStringString() throws Exception { final EdmSimpleType instance = EdmSimpleTypeKind.String.getEdmSimpleTypeInstance(); assertEquals("text", instance.valueToString("text", EdmLiteralKind.DEFAULT, null)); assertEquals("a\nb", instance.valueToString("a\nb", EdmLiteralKind.JSON, null)); assertEquals("'true'", instance.valueToString(true, EdmLiteralKind.URI, null)); assertEquals("'a''b'", instance.valueToString("a'b", EdmLiteralKind.URI, null)); assertEquals("text", instance.valueToString("text", EdmLiteralKind.DEFAULT, getUnicodeFacets(true))); assertEquals("text", instance.valueToString("text", EdmLiteralKind.DEFAULT, getUnicodeFacets(null))); assertEquals("text", instance.valueToString("text", EdmLiteralKind.DEFAULT, getMaxLengthFacets(4))); assertEquals("text", instance.valueToString("text", EdmLiteralKind.DEFAULT, getMaxLengthFacets(Integer.MAX_VALUE))); assertEquals("text", instance.valueToString("text", EdmLiteralKind.DEFAULT, getMaxLengthFacets(null))); expectErrorInValueToString(instance, "schräg", EdmLiteralKind.DEFAULT, getUnicodeFacets(false), EdmSimpleTypeException.VALUE_FACETS_NOT_MATCHED); expectErrorInValueToString(instance, "text", EdmLiteralKind.DEFAULT, getMaxLengthFacets(3), EdmSimpleTypeException.VALUE_FACETS_NOT_MATCHED); expectErrorInValueToString(instance, "text", null, null, EdmSimpleTypeException.LITERAL_KIND_MISSING); }
Example #6
Source File: ListsProcessor.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Override public ODataResponse executeFunctionImportValue(final GetFunctionImportUriInfo uriInfo, final String contentType) throws ODataException { final EdmFunctionImport functionImport = uriInfo.getFunctionImport(); final EdmSimpleType type = (EdmSimpleType) functionImport.getReturnType().getType(); final Object data = dataSource.readData( functionImport, mapFunctionParameters(uriInfo.getFunctionImportParameters()), null); if (data == null) { throw new ODataNotFoundException(ODataHttpException.COMMON); } ODataResponse response; if (type == EdmSimpleTypeKind.Binary.getEdmSimpleTypeInstance()) { response = EntityProvider.writeBinary(((BinaryData) data).getMimeType(), ((BinaryData) data).getData()); } else { final String value = type.valueToString(data, EdmLiteralKind.DEFAULT, null); response = EntityProvider.writeText(value == null ? "" : value); } return ODataResponse.fromResponse(response).build(); }
Example #7
Source File: JPQLJoinSelectSingleStatementBuilderTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
private List<KeyPredicate> createKeyPredicates() throws EdmException { KeyPredicate keyPredicate = EasyMock.createMock(KeyPredicate.class); EasyMock.expect(keyPredicate.getLiteral()).andStubReturn("1"); EdmProperty edmProperty = EasyMock.createMock(EdmProperty.class); EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class); EasyMock.expect(edmMapping.getInternalName()).andStubReturn("soid"); EasyMock.expect(edmProperty.getMapping()).andStubReturn(edmMapping); EdmSimpleType edmType = EasyMock.createMock(EdmSimpleType.class); EasyMock.expect(edmProperty.getType()).andStubReturn(edmType); EasyMock.expect(keyPredicate.getProperty()).andStubReturn(edmProperty); EasyMock.replay(edmType, edmMapping, edmProperty, keyPredicate); List<KeyPredicate> keyPredicates = new ArrayList<KeyPredicate>(); keyPredicates.add(keyPredicate); return keyPredicates; }
Example #8
Source File: ListsProcessor.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Override public ODataResponse executeFunctionImportValue(final GetFunctionImportUriInfo uriInfo, final String contentType) throws ODataException { final EdmFunctionImport functionImport = uriInfo.getFunctionImport(); final EdmSimpleType type = (EdmSimpleType) functionImport.getReturnType().getType(); final Object data = dataSource.readData( functionImport, mapFunctionParameters(uriInfo.getFunctionImportParameters()), null); if (data == null) { throw new ODataNotFoundException(ODataHttpException.COMMON); } ODataResponse response; if (type == EdmSimpleTypeKind.Binary.getEdmSimpleTypeInstance()) { response = EntityProvider.writeBinary(((BinaryData) data).getMimeType(), ((BinaryData) data).getData()); } else { final String value = type.valueToString(data, EdmLiteralKind.DEFAULT, null); response = EntityProvider.writeText(value == null ? "" : value); } return ODataResponse.fromResponse(response).build(); }
Example #9
Source File: JPQLSelectSingleStatementBuilderTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
/** * Test method for {@link org.apache.olingo.odata2.processor.jpa.jpql.JPQLSelectSingleStatementBuilder#build)}. * @throws EdmException * @throws ODataJPARuntimeException */ @Test public void testBuildQueryWithSpecialChars() throws EdmException, ODataJPARuntimeException { EdmSimpleType edmType = EdmSimpleTypeKind.String.getEdmSimpleTypeInstance(); JPQLSelectSingleContext JPQLSelectSingleContextImpl = createSelectContext(edmType); JPQLSelectSingleStatementBuilder = new JPQLSelectSingleStatementBuilder(JPQLSelectSingleContextImpl); String query = JPQLSelectSingleStatementBuilder.build().toString(); query = query.substring(0, query.indexOf("?")); Map<String, Map<Integer,Object>> parameterizedQuery = JPQLSelectSingleContextImpl. getParameterizedQueryMap(); for (Entry<String, Map<Integer, Object>> parameter : parameterizedQuery.entrySet()) { for (Entry<Integer, Object> param : parameter.getValue().entrySet()) { query += param.getValue(); } } assertEquals("SELECT E1 FROM SalesOrderHeader E1 WHERE E1.Field1 LIKE MiMe-Id1", query); }
Example #10
Source File: EdmSimpleTypeTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void validate() throws Exception { for (EdmSimpleTypeKind kind : EdmSimpleTypeKind.values()) { if (kind == EdmSimpleTypeKind.Null) { continue; } final EdmSimpleType instance = kind.getEdmSimpleTypeInstance(); assertTrue(instance.validate(null, null, null)); assertTrue(instance.validate(null, null, getNullableFacets(null))); assertTrue(instance.validate(null, null, getNullableFacets(true))); assertFalse(instance.validate(null, null, getNullableFacets(false))); assertFalse(instance.validate("", null, null)); assertFalse(instance.validate("ä", EdmLiteralKind.DEFAULT, getUnicodeFacets(false))); assertFalse(instance.validate("ä", EdmLiteralKind.URI, null)); } assertTrue(EdmSimpleTypeKind.Binary.getEdmSimpleTypeInstance().validate("abcd", EdmLiteralKind.DEFAULT, getMaxLengthFacets(3))); assertFalse(EdmSimpleTypeKind.Binary.getEdmSimpleTypeInstance().validate("abcd", EdmLiteralKind.DEFAULT, getMaxLengthFacets(2))); assertTrue(EdmSimpleTypeKind.Decimal.getEdmSimpleTypeInstance().validate("1.2", EdmLiteralKind.DEFAULT, getPrecisionScaleFacets(null, null))); assertFalse(EdmSimpleTypeKind.Decimal.getEdmSimpleTypeInstance().validate("1.2", EdmLiteralKind.DEFAULT, getPrecisionScaleFacets(null, 0))); }
Example #11
Source File: EdmSimpleTypeTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void valueOfStringByte() throws Exception { final EdmSimpleType instance = EdmSimpleTypeKind.Byte.getEdmSimpleTypeInstance(); assertEquals(Short.valueOf((short) 1), instance.valueOfString("1", EdmLiteralKind.DEFAULT, null, Short.class)); assertEquals(Integer.valueOf(2), instance.valueOfString("2", EdmLiteralKind.JSON, null, Integer.class)); assertEquals(Byte.valueOf((byte) 127), instance.valueOfString("127", EdmLiteralKind.URI, null, Byte.class)); assertEquals(Short.valueOf((short) 255), instance.valueOfString("255", EdmLiteralKind.URI, null, Short.class)); assertEquals(Long.valueOf(0), instance.valueOfString("0", EdmLiteralKind.DEFAULT, null, Long.class)); expectErrorInValueOfString(instance, "0x42", EdmLiteralKind.DEFAULT, null, EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT); expectErrorInValueOfString(instance, "abc", EdmLiteralKind.DEFAULT, null, EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT); expectErrorInValueOfString(instance, "256", EdmLiteralKind.DEFAULT, null, EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT); expectErrorInValueOfString(instance, "-1", EdmLiteralKind.JSON, null, EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT); expectErrorInValueOfString(instance, "1.0", EdmLiteralKind.URI, null, EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT); expectTypeErrorInValueOfString(instance, "1", EdmLiteralKind.DEFAULT); expectUnconvertibleErrorInValueOfString(instance, "128", Byte.class); }
Example #12
Source File: EdmSimpleTypeTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void valueOfStringGuid() throws Exception { final EdmSimpleType instance = EdmSimpleTypeKind.Guid.getEdmSimpleTypeInstance(); final UUID uuid = UUID.fromString("aabbccdd-aabb-ccdd-eeff-aabbccddeeff"); assertEquals(uuid, instance.valueOfString("aabbccdd-aabb-ccdd-eeff-aabbccddeeff", EdmLiteralKind.DEFAULT, null, UUID.class)); assertEquals(uuid, instance.valueOfString("AABBCCDD-AABB-CCDD-EEFF-AABBCCDDEEFF", EdmLiteralKind.JSON, null, UUID.class)); assertEquals(uuid, instance.valueOfString("guid'AABBCCDD-aabb-ccdd-eeff-AABBCCDDEEFF'", EdmLiteralKind.URI, null, UUID.class)); //OLINGO-883 prefix is case insensitive assertEquals(uuid, instance.valueOfString("GuId'AABBCCDD-aabb-ccdd-eeff-AABBCCDDEEFF'", EdmLiteralKind.URI, null, UUID.class)); expectErrorInValueOfString(instance, "AABBCCDDAABBCCDDEEFFAABBCCDDEEFF", EdmLiteralKind.DEFAULT, null, EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT); expectErrorInValueOfString(instance, "uid'AABBCCDD-aabb-ccdd-eeff-AABBCCDDEEFF'", EdmLiteralKind.URI, null, EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT); expectTypeErrorInValueOfString(instance, uuid.toString(), EdmLiteralKind.DEFAULT); }
Example #13
Source File: UriParserImpl.java From olingo-odata2 with Apache License 2.0 | 6 votes |
private void handleOtherQueryParameters() throws UriSyntaxException, EdmException { final EdmFunctionImport functionImport = uriResult.getFunctionImport(); if (functionImport != null) { for (final String parameterName : functionImport.getParameterNames()) { final EdmParameter parameter = functionImport.getParameter(parameterName); final String value = otherQueryParameters.remove(parameterName); if (value == null) { if (parameter.getFacets() == null || parameter.getFacets().isNullable() == null || parameter.getFacets().isNullable()) { continue; } else { throw new UriSyntaxException(UriSyntaxException.MISSINGPARAMETER); } } EdmLiteral uriLiteral = parseLiteral(value, (EdmSimpleType) parameter.getType(), parameter.getFacets()); uriResult.addFunctionImportParameter(parameterName, uriLiteral); } } uriResult.setCustomQueryOptions(otherQueryParameters); }
Example #14
Source File: AtomEntryEntityProducer.java From olingo-odata2 with Apache License 2.0 | 6 votes |
private String getTargetPathValue(final EntityInfoAggregator eia, final String targetPath, final Map<String, Object> data) throws EntityProviderException { EntityPropertyInfo info = null; try { info = eia.getTargetPathInfo(targetPath); if (info != null) { EdmSimpleType type = (EdmSimpleType) info.getType(); Object value = data.get(info.getName()); return type.valueToString(value, EdmLiteralKind.DEFAULT, info.getFacets()); } return null; } catch (final EdmSimpleTypeException e) { throw new EntityProviderProducerException( EdmSimpleTypeException.getMessageReference(e.getMessageReference()). updateContent(e.getMessageReference().getContent(), info.getName()), e); } }
Example #15
Source File: EdmTypedImpl.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Override public EdmType getType() throws EdmException { if (edmType == null) { final String namespace = typeName.getNamespace(); if (EdmSimpleType.EDM_NAMESPACE.equals(typeName.getNamespace())) { edmType = EdmSimpleTypeFacadeImpl.getEdmSimpleType(EdmSimpleTypeKind.valueOf(typeName.getName())); } else { edmType = edm.getComplexType(namespace, typeName.getName()); } if (edmType == null) { edmType = edm.getEntityType(namespace, typeName.getName()); } if (edmType == null) { throw new EdmException(EdmException.TYPEPROBLEM); } } return edmType; }
Example #16
Source File: EdmSimpleTypeTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void valueOfStringBoolean() throws Exception { final EdmSimpleType instance = EdmSimpleTypeKind.Boolean.getEdmSimpleTypeInstance(); assertEquals(true, instance.valueOfString("true", EdmLiteralKind.DEFAULT, null, Boolean.class)); assertEquals(false, instance.valueOfString("false", EdmLiteralKind.JSON, null, Boolean.class)); assertEquals(true, instance.valueOfString("1", EdmLiteralKind.URI, null, Boolean.class)); assertEquals(false, instance.valueOfString("0", EdmLiteralKind.URI, null, Boolean.class)); expectErrorInValueOfString(instance, "True", EdmLiteralKind.DEFAULT, null, EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT); expectErrorInValueOfString(instance, "-1", EdmLiteralKind.JSON, null, EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT); expectErrorInValueOfString(instance, "FALSE", EdmLiteralKind.URI, null, EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT); expectTypeErrorInValueOfString(instance, "1", EdmLiteralKind.DEFAULT); }
Example #17
Source File: AtomEntryEntitySerializer.java From olingo-odata2 with Apache License 2.0 | 5 votes |
private static String createEntryKey(final EntityInfoAggregator entityInfo, final Map<String, Object> data, boolean isKeyAutoGenerated) throws EntityProviderException { final List<EntityPropertyInfo> keyPropertyInfos = entityInfo.getKeyPropertyInfos(); StringBuilder keys = new StringBuilder(); for (final EntityPropertyInfo keyPropertyInfo : keyPropertyInfos) { if (keys.length() > 0) { keys.append(','); } final String name = keyPropertyInfo.getName(); if (keyPropertyInfos.size() > 1) { keys.append(Encoder.encode(name)).append('='); } final EdmSimpleType type = (EdmSimpleType) keyPropertyInfo.getType(); try { String keyValue = null; if (isKeyAutoGenerated && data.get(name) == null) { // Every time default values for the key is generated // if it is not there and auto generation has to be done by the server Object value = fetchDefaultValue(type.getDefaultType()); keyValue = Encoder.encode(type.valueToString(value, EdmLiteralKind.URI, keyPropertyInfo.getFacets())); } else { keyValue = Encoder.encode(type.valueToString(data.get(name), EdmLiteralKind.URI, keyPropertyInfo.getFacets())); } keys.append(keyValue); } catch (final EdmSimpleTypeException e) { throw new EntityProviderProducerException( EdmSimpleTypeException.getMessageReference(e.getMessageReference()). updateContent(e.getMessageReference().getContent(), name), e); } } return keys.toString(); }
Example #18
Source File: EdmSimpleTypeTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
private void expectErrorInValueToString(final EdmSimpleType instance, final Object value, final EdmLiteralKind literalKind, final EdmFacets facets, final MessageReference messageReference) { try { instance.valueToString(value, literalKind, facets); fail("Expected exception not thrown"); } catch (EdmSimpleTypeException e) { assertNotNull(e.getMessageReference()); assertEquals(messageReference.getKey(), e.getMessageReference().getKey()); } }
Example #19
Source File: EdmSimpleTypeTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Test public void valueToStringBinary() throws Exception { final byte[] binary = new byte[] { (byte) 0xAA, (byte) 0xBB, (byte) 0xCC, (byte) 0xDD, (byte) 0xEE, (byte) 0xFF }; final EdmSimpleType instance = EdmSimpleTypeKind.Binary.getEdmSimpleTypeInstance(); assertEquals("qrvM3e7/", instance.valueToString(binary, EdmLiteralKind.DEFAULT, null)); assertEquals("qrvM3e7/", instance.valueToString(binary, EdmLiteralKind.JSON, null)); assertEquals("binary'AABBCCDDEEFF'", instance.valueToString(binary, EdmLiteralKind.URI, null)); assertEquals("qrvM3e7/", instance.valueToString(binary, EdmLiteralKind.DEFAULT, getMaxLengthFacets(6))); assertEquals("qrvM3e7/", instance.valueToString(binary, EdmLiteralKind.JSON, getMaxLengthFacets(6))); assertEquals("binary'AABBCCDDEEFF'", instance.valueToString(binary, EdmLiteralKind.URI, getMaxLengthFacets(6))); assertEquals("qrvM3e7/", instance.valueToString(binary, EdmLiteralKind.DEFAULT, getMaxLengthFacets(Integer.MAX_VALUE))); assertEquals("binary'AABBCCDDEEFF'", instance.valueToString(binary, EdmLiteralKind.URI, getMaxLengthFacets(Integer.MAX_VALUE))); assertEquals("qrvM3e7/", instance.valueToString(binary, EdmLiteralKind.DEFAULT, getMaxLengthFacets(null))); assertEquals("qg==", instance.valueToString(new Byte[] { new Byte((byte) 170) }, EdmLiteralKind.DEFAULT, null)); expectErrorInValueToString(instance, binary, EdmLiteralKind.DEFAULT, getMaxLengthFacets(3), EdmSimpleTypeException.VALUE_FACETS_NOT_MATCHED); expectErrorInValueToString(instance, binary, EdmLiteralKind.JSON, getMaxLengthFacets(3), EdmSimpleTypeException.VALUE_FACETS_NOT_MATCHED); expectErrorInValueToString(instance, binary, EdmLiteralKind.URI, getMaxLengthFacets(3), EdmSimpleTypeException.VALUE_FACETS_NOT_MATCHED); expectErrorInValueToString(instance, 0, EdmLiteralKind.DEFAULT, null, EdmSimpleTypeException.VALUE_TYPE_NOT_SUPPORTED); expectErrorInValueToString(instance, binary, null, null, EdmSimpleTypeException.LITERAL_KIND_MISSING); }
Example #20
Source File: EdmSimpleTypeTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Test public void valueOfStringString() throws Exception { final EdmSimpleType instance = EdmSimpleTypeKind.String.getEdmSimpleTypeInstance(); assertEquals("text", instance.valueOfString("text", EdmLiteralKind.DEFAULT, null, String.class)); assertEquals("a\nb", instance.valueOfString("a\nb", EdmLiteralKind.JSON, null, String.class)); assertEquals("true", instance.valueOfString("'true'", EdmLiteralKind.URI, null, String.class)); assertEquals("a'b", instance.valueOfString("'a''b'", EdmLiteralKind.URI, null, String.class)); assertEquals("text", instance.valueOfString("text", EdmLiteralKind.DEFAULT, getUnicodeFacets(true), String.class)); assertEquals("text", instance.valueOfString("text", EdmLiteralKind.DEFAULT, getUnicodeFacets(null), String.class)); assertEquals("text", instance.valueOfString("text", EdmLiteralKind.DEFAULT, getMaxLengthFacets(4), String.class)); assertEquals("text", instance.valueOfString("text", EdmLiteralKind.DEFAULT, getMaxLengthFacets(Integer.MAX_VALUE), String.class)); assertEquals("text", instance.valueOfString("text", EdmLiteralKind.DEFAULT, getMaxLengthFacets(null), String.class)); expectErrorInValueOfString(instance, "schräg", EdmLiteralKind.DEFAULT, getUnicodeFacets(false), EdmSimpleTypeException.LITERAL_FACETS_NOT_MATCHED); expectErrorInValueOfString(instance, "text", EdmLiteralKind.DEFAULT, getMaxLengthFacets(3), EdmSimpleTypeException.LITERAL_FACETS_NOT_MATCHED); expectErrorInValueOfString(instance, "'", EdmLiteralKind.URI, null, EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT); expectErrorInValueOfString(instance, "'text", EdmLiteralKind.URI, null, EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT); expectErrorInValueOfString(instance, "text'", EdmLiteralKind.URI, null, EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT); expectTypeErrorInValueOfString(instance, "text", EdmLiteralKind.DEFAULT); }
Example #21
Source File: ListsProcessor.java From olingo-odata2 with Apache License 2.0 | 5 votes |
private <T> String getSkipToken(final EdmEntitySet entitySet, final T data) throws ODataException { String skipToken = ""; for (final EdmProperty property : entitySet.getEntityType().getKeyProperties()) { final EdmSimpleType type = (EdmSimpleType) property.getType(); skipToken = skipToken.concat(type.valueToString(valueAccess.getPropertyValue(data, property), EdmLiteralKind.DEFAULT, property.getFacets())); } return skipToken; }
Example #22
Source File: XmlPropertyEntitySerializer.java From olingo-odata2 with Apache License 2.0 | 5 votes |
/** * Appends a simple-property value to the XML stream. * @param writer the XML stream writer * @param prop property informations * @param value the value of the property * @throws XMLStreamException * @throws EdmException * @throws EntityProviderProducerException */ private void appendProperty(final XMLStreamWriter writer, final EntityPropertyInfo prop, final Object value) throws XMLStreamException, EdmException, EntityProviderProducerException { Object contentValue = value; String mimeType = null; if (prop.getMimeType() != null) { mimeType = prop.getMimeType(); } else if (prop.getMapping() != null && prop.getMapping().getMediaResourceMimeTypeKey() != null) { mimeType = (String) extractChildValue(value, prop.getMapping().getMediaResourceMimeTypeKey()); contentValue = extractChildValue(value, prop.getName()); } if (mimeType != null) { writer.writeAttribute(Edm.NAMESPACE_M_2007_08, FormatXml.M_MIME_TYPE, mimeType); } final EdmSimpleType type = (EdmSimpleType) prop.getType(); final EdmFacets facets = validateFacets ? prop.getFacets() : null; String valueAsString = null; try { valueAsString = type.valueToString(contentValue, EdmLiteralKind.DEFAULT, facets); } catch (EdmSimpleTypeException e) { throw new EntityProviderProducerException(EdmSimpleTypeException.getMessageReference( e.getMessageReference()).updateContent( e.getMessageReference().getContent(), prop.getName()), e); } if (valueAsString == null) { writer.writeAttribute(Edm.NAMESPACE_M_2007_08, FormatXml.ATOM_NULL, FormatXml.ATOM_VALUE_TRUE); } else { writer.writeCharacters(valueAsString); } }
Example #23
Source File: EdmSimpleTypeTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Test public void valueOfStringInt64() throws Exception { final EdmSimpleType instance = EdmSimpleTypeKind.Int64.getEdmSimpleTypeInstance(); assertEquals(Short.valueOf((short) 1), instance.valueOfString("1", EdmLiteralKind.DEFAULT, null, Short.class)); assertEquals(Integer.valueOf(2), instance.valueOfString("2", EdmLiteralKind.JSON, null, Integer.class)); assertEquals(Long.valueOf(-1234567890123456789L), instance.valueOfString("-1234567890123456789L", EdmLiteralKind.URI, null, Long.class)); assertEquals(BigInteger.ONE, instance.valueOfString("1", EdmLiteralKind.DEFAULT, null, BigInteger.class)); assertEquals(Long.valueOf(0), instance.valueOfString("0l", EdmLiteralKind.URI, null, Long.class)); assertEquals(Byte.valueOf((byte) 0), instance.valueOfString("0L", EdmLiteralKind.URI, null, Byte.class)); expectErrorInValueOfString(instance, "-12345678901234567890", EdmLiteralKind.DEFAULT, null, EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT); expectErrorInValueOfString(instance, "1.0", EdmLiteralKind.DEFAULT, null, EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT); expectErrorInValueOfString(instance, "1.0L", EdmLiteralKind.URI, null, EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT); expectErrorInValueOfString(instance, "0M", EdmLiteralKind.URI, null, EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT); expectErrorInValueOfString(instance, "0x42", EdmLiteralKind.DEFAULT, null, EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT); expectTypeErrorInValueOfString(instance, "1", EdmLiteralKind.DEFAULT); expectUnconvertibleErrorInValueOfString(instance, "-129", Byte.class); expectUnconvertibleErrorInValueOfString(instance, "128", Byte.class); expectUnconvertibleErrorInValueOfString(instance, "-32769", Short.class); expectUnconvertibleErrorInValueOfString(instance, "32768", Short.class); expectUnconvertibleErrorInValueOfString(instance, "-2147483649", Integer.class); expectUnconvertibleErrorInValueOfString(instance, "2147483648", Integer.class); }
Example #24
Source File: EdmSimpleTypeTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
private void expectErrorInValueOfString(final EdmSimpleType instance, final String value, final EdmLiteralKind literalKind, final EdmFacets facets, final MessageReference messageReference) { try { instance.valueOfString(value, literalKind, facets, instance.getDefaultType()); fail("Expected exception not thrown"); } catch (EdmSimpleTypeException e) { assertNotNull(e.getMessageReference()); assertEquals(messageReference.getKey(), e.getMessageReference().getKey()); } }
Example #25
Source File: Processor.java From DataHubSystem with GNU Affero General Public License v3.0 | 5 votes |
@Override public ODataResponse executeFunctionImportValue(GetFunctionImportUriInfo uri_info, String content_type) throws ODataException { EdmFunctionImport function_import = uri_info.getFunctionImport(); Map<String, EdmLiteral> params = uri_info.getFunctionImportParameters(); // FIXME: returned type might not be a simple type ... EdmSimpleType type = (EdmSimpleType) function_import.getReturnType().getType(); AbstractOperation op = Model.getServiceOperation(function_import.getName()); fr.gael.dhus.database.object.User current_user = ApplicationContextProvider.getBean(SecurityService.class).getCurrentUser(); if (!op.canExecute(current_user)) { throw new NotAllowedException(); } Object res = op.execute(params); /* To handle binary results (NYI): if (type == EdmSimpleTypeKind.Binary.getEdmSimpleTypeInstance()) { response = EntityProvider.writeBinary( ((BinaryData) data).getMimeType(), // BinaryData is an meta-object holding the data ((BinaryData) data).getData() // and its mime type ); }//*/ final String value = type.valueToString(res, EdmLiteralKind.DEFAULT, null); return EntityProvider.writeText(value == null ? "" : value); }
Example #26
Source File: EdmSimpleTypeTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
private void expectTypeErrorInValueOfString(final EdmSimpleType instance, final String value, final EdmLiteralKind literalKind) { try { instance.valueOfString(value, literalKind, null, Class.class); fail("Expected exception not thrown"); } catch (EdmSimpleTypeException e) { assertNotNull(e.getMessageReference()); assertEquals(EdmSimpleTypeException.VALUE_TYPE_NOT_SUPPORTED.getKey(), e.getMessageReference().getKey()); } }
Example #27
Source File: EdmURIBuilderImpl.java From olingo-odata2 with Apache License 2.0 | 5 votes |
/** * @param property * @param value * @return * @throws EdmException * @throws EdmSimpleTypeException */ private String getKey(EdmProperty property, Object value, boolean isSegment) throws EdmException { String key = ""; EdmSimpleType edmType = (EdmSimpleType) property.getType(); if (value instanceof String) { value = Encoder.encode(value.toString()); //NOSONAR } if (!isSegment) { key = "(" + edmType.valueToString(value, EdmLiteralKind.URI, property.getFacets()) + ")"; } else { key = edmType.valueToString(value, EdmLiteralKind.URI, property.getFacets()); } return key; }
Example #28
Source File: EdmDecimal.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Override public boolean isCompatible(final EdmSimpleType simpleType) { return simpleType instanceof Bit || simpleType instanceof Uint7 || simpleType instanceof EdmByte || simpleType instanceof EdmSByte || simpleType instanceof EdmInt16 || simpleType instanceof EdmInt32 || simpleType instanceof EdmInt64 || simpleType instanceof EdmSingle || simpleType instanceof EdmDouble || simpleType instanceof EdmDecimal; }
Example #29
Source File: EdmInt16.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Override public boolean isCompatible(final EdmSimpleType simpleType) { return simpleType instanceof Bit || simpleType instanceof Uint7 || simpleType instanceof EdmByte || simpleType instanceof EdmSByte || simpleType instanceof EdmInt16; }
Example #30
Source File: XmlPropertyDeserializer.java From olingo-odata2 with Apache License 2.0 | 5 votes |
private Object convert(final EntityPropertyInfo property, final String value, final Class<?> typeMapping, final DeserializerProperties readProperties) throws EdmSimpleTypeException { final EdmSimpleType type = (EdmSimpleType) property.getType(); return type.valueOfString(value, EdmLiteralKind.DEFAULT, readProperties == null || readProperties.isValidatingFacets() ? property.getFacets() : null, typeMapping == null ? type.getDefaultType() : typeMapping); }