Java Code Examples for org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind#String
The following examples show how to use
org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind#String .
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: ClientPrimitiveValueImpl.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Override public BuilderImpl setType(final EdmPrimitiveTypeKind type) { if (type == EdmPrimitiveTypeKind.Stream) { throw new IllegalArgumentException(String.format( "Cannot build a primitive value for %s", EdmPrimitiveTypeKind.Stream.toString())); } if (type == EdmPrimitiveTypeKind.Geography || type == EdmPrimitiveTypeKind.Geometry) { throw new IllegalArgumentException( type + "is not an instantiable type. " + "An entity can declare a property to be of type Geometry. " + "An instance of an entity MUST NOT have a value of type Geometry. " + "Each value MUST be of some subtype."); } instance.typeKind = type == null ? EdmPrimitiveTypeKind.String : type; instance.type = EdmPrimitiveTypeFactory.getInstance(instance.typeKind); return this; }
Example 2
Source File: EdmTypeInfo.java From olingo-odata4 with Apache License 2.0 | 5 votes |
public static EdmPrimitiveTypeKind determineTypeKind(final Object value) { if (value == null) { return null; } else if (value instanceof Boolean) { return EdmPrimitiveTypeKind.Boolean; } else if (value instanceof String) { return EdmPrimitiveTypeKind.String; } else if (value instanceof UUID) { return EdmPrimitiveTypeKind.Guid; } else if (value instanceof Long || value instanceof BigInteger) { return EdmPrimitiveTypeKind.Int64; } else if (value instanceof Integer) { return EdmPrimitiveTypeKind.Int32; } else if (value instanceof Short) { return EdmPrimitiveTypeKind.Int16; } else if (value instanceof Byte) { return EdmPrimitiveTypeKind.SByte; } else if (value instanceof BigDecimal) { return EdmPrimitiveTypeKind.Decimal; } else if (value instanceof Double) { return EdmPrimitiveTypeKind.Double; } else if (value instanceof Float) { return EdmPrimitiveTypeKind.Single; } else if (value instanceof Calendar || value instanceof Date || value instanceof java.sql.Timestamp) { return EdmPrimitiveTypeKind.DateTimeOffset; } else if (value instanceof java.sql.Date) { return EdmPrimitiveTypeKind.Date; } else if (value instanceof java.sql.Time) { return EdmPrimitiveTypeKind.TimeOfDay; } else if (value instanceof byte[] || value instanceof Byte[]) { return EdmPrimitiveTypeKind.Binary; } return null; }
Example 3
Source File: CommonPrimitiveTypeTest.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Test public void validate() throws Exception { for (final EdmPrimitiveTypeKind kind : EdmPrimitiveTypeKind.values()) { final EdmPrimitiveType instance = EdmPrimitiveTypeFactory.getInstance(kind); assertTrue(instance.validate(null, null, null, null, null, null)); assertTrue(instance.validate(null, true, null, null, null, null)); assertFalse(instance.validate(null, false, null, null, null, null)); if (kind != EdmPrimitiveTypeKind.Stream) { assertFalse(instance.validate("ä", null, null, null, null, false)); } if (kind != EdmPrimitiveTypeKind.String && kind != EdmPrimitiveTypeKind.Binary && kind != EdmPrimitiveTypeKind.Stream) { assertFalse(instance.validate("", null, null, null, null, null)); } if (kind != EdmPrimitiveTypeKind.String && kind != EdmPrimitiveTypeKind.Stream) { assertFalse(instance.validate("ä", null, null, null, null, null)); } } assertTrue(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Binary). validate("abcd", null, 3, null, null, null)); assertFalse(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Binary). validate("abcd", null, 2, null, null, null)); assertTrue(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Decimal). validate("1", null, null, null, null, null)); assertFalse(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Decimal). validate("1.2", null, null, null, 0, null)); }
Example 4
Source File: EdmTypeDefinitionImplTest.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Test public void compatibility() { assertTrue(instance.isCompatible(instance)); for (final EdmPrimitiveTypeKind kind : EdmPrimitiveTypeKind.values()) { if (kind != EdmPrimitiveTypeKind.String) { assertFalse(instance.isCompatible(EdmPrimitiveTypeFactory.getInstance(kind))); } } }
Example 5
Source File: ODataJsonDeserializer.java From olingo-odata4 with Apache License 2.0 | 5 votes |
private boolean matchTextualCase(final JsonNode node, final EdmPrimitiveTypeKind primKind) { return node.isTextual() && (primKind == EdmPrimitiveTypeKind.String || primKind == EdmPrimitiveTypeKind.Binary || primKind == EdmPrimitiveTypeKind.Date || primKind == EdmPrimitiveTypeKind.DateTimeOffset || primKind == EdmPrimitiveTypeKind.Duration || primKind == EdmPrimitiveTypeKind.Guid || primKind == EdmPrimitiveTypeKind.TimeOfDay); }
Example 6
Source File: JsonDeserializer.java From olingo-odata4 with Apache License 2.0 | 5 votes |
private EdmPrimitiveTypeKind guessPrimitiveTypeKind(final JsonNode node) { return node.isShort() ? EdmPrimitiveTypeKind.Int16 : node.isInt() ? EdmPrimitiveTypeKind.Int32 : node.isLong() ? EdmPrimitiveTypeKind.Int64 : node.isBoolean() ? EdmPrimitiveTypeKind.Boolean : node.isFloat() ? EdmPrimitiveTypeKind.Single : node.isDouble() ? EdmPrimitiveTypeKind.Double : node.isBigDecimal() ? EdmPrimitiveTypeKind.Decimal : EdmPrimitiveTypeKind.String; }
Example 7
Source File: ODataUtils.java From micro-integrator with Apache License 2.0 | 4 votes |
/** * This method creates access uri for the entity. * * @param baseURL base URL * @param entity entity * @param enitySetName entity Set Name * @param type entity Type * @return Entity URI * @throws EdmPrimitiveTypeException */ public static String buildLocation(String baseURL, Entity entity, String enitySetName, EdmEntityType type) throws EdmPrimitiveTypeException { StringBuilder location = new StringBuilder(); location.append(baseURL).append("/").append(enitySetName); int i = 0; boolean usename = type.getKeyPredicateNames().size() > 1; location.append("("); String value; for (Iterator var7 = type.getKeyPredicateNames().iterator(); var7.hasNext(); location.append(value)) { String key = (String) var7.next(); if (i > 0) { location.append(","); } ++i; if (usename) { location.append(key).append("="); } String propertyType = entity.getProperty(key).getType(); Object propertyValue = entity.getProperty(key).getValue(); if (propertyType.startsWith("Edm.")) { propertyType = propertyType.substring(4); } EdmPrimitiveTypeKind kind = EdmPrimitiveTypeKind.valueOf(propertyType); EdmProperty property = type.getStructuralProperty(key); value = EdmPrimitiveTypeFactory.getInstance(kind) .valueToString(propertyValue, property.isNullable(), property.getMaxLength(), property.getPrecision(), property.getScale(), property.isUnicode()); if (kind == EdmPrimitiveTypeKind.String) { value = EdmString.getInstance().toUriLiteral(Encoder.encode(value)); } } location.append(")"); return location.toString(); }
Example 8
Source File: EdmConstantExpressionImpl.java From olingo-odata4 with Apache License 2.0 | 4 votes |
private void build() { if (csdlExp.getType() == CsdlConstantExpression.ConstantExpressionType.EnumMember) { if (csdlExp.getValue() == null) { throw new EdmException("Expression value must not be null"); } final List<String> localEnumValues = new ArrayList<>(); for (String split : csdlExp.getValue().split(" ")) { final String[] enumSplit = split.split("/"); if (enumSplit.length != 2) { throw new EdmException("Enum expression value must consist of enumTypeName/EnumMember."); } enumTypeName = enumSplit[0]; localEnumValues.add(enumSplit[1]); } enumMembers = Collections.unmodifiableList(localEnumValues); } else { EdmPrimitiveTypeKind kind; switch (csdlExp.getType()) { case Binary: kind = EdmPrimitiveTypeKind.Binary; break; case Bool: kind = EdmPrimitiveTypeKind.Boolean; break; case Date: kind = EdmPrimitiveTypeKind.Date; break; case DateTimeOffset: kind = EdmPrimitiveTypeKind.DateTimeOffset; break; case Decimal: kind = EdmPrimitiveTypeKind.Decimal; break; case Duration: kind = EdmPrimitiveTypeKind.Duration; break; case Float: kind = EdmPrimitiveTypeKind.Single; break; case Guid: kind = EdmPrimitiveTypeKind.Guid; break; case Int: kind = EdmPrimitiveTypeKind.Int32; break; case TimeOfDay: kind = EdmPrimitiveTypeKind.TimeOfDay; break; case String: default: kind = EdmPrimitiveTypeKind.String; } type = EdmPrimitiveTypeFactory.getInstance(kind); try { primitive = type.valueOfString(csdlExp.getValue(), null, null, null, null, null, type.getDefaultType()); } catch (EdmPrimitiveTypeException e) { throw new IllegalArgumentException(e); } } built = true; }
Example 9
Source File: MethodImpl.java From olingo-odata4 with Apache License 2.0 | 4 votes |
public EdmType getType() { EdmPrimitiveTypeKind kind = null; switch (method) { case CONTAINS: case STARTSWITH: case ENDSWITH: case SUBSTRINGOF: kind = EdmPrimitiveTypeKind.Boolean; break; case LENGTH: case INDEXOF: kind = EdmPrimitiveTypeKind.Int32; break; case SUBSTRING: case TOLOWER: case TOUPPER: case TRIM: case CONCAT: kind = EdmPrimitiveTypeKind.String; break; case YEAR: case MONTH: case DAY: case HOUR: case MINUTE: case SECOND: kind = EdmPrimitiveTypeKind.Int32; break; case FRACTIONALSECONDS: case TOTALSECONDS: kind = EdmPrimitiveTypeKind.Decimal; break; case DATE: kind = EdmPrimitiveTypeKind.Date; break; case TIME: kind = EdmPrimitiveTypeKind.TimeOfDay; break; case TOTALOFFSETMINUTES: kind = EdmPrimitiveTypeKind.Int32; break; case MINDATETIME: case MAXDATETIME: case NOW: kind = EdmPrimitiveTypeKind.DateTimeOffset; break; case ROUND: case FLOOR: case CEILING: // Needs to be refined if Decimal must be distinguished from Double. kind = EdmPrimitiveTypeKind.Double; break; case GEODISTANCE: case GEOLENGTH: kind = EdmPrimitiveTypeKind.Double; break; case GEOINTERSECTS: kind = EdmPrimitiveTypeKind.Boolean; break; case CAST: return ((TypeLiteral) parameters.get(parameters.size() - 1)).getType(); case ISOF: kind = EdmPrimitiveTypeKind.Boolean; break; } return new ODataImpl().createPrimitiveTypeInstance(kind); }
Example 10
Source File: EntityResponse.java From olingo-odata4 with Apache License 2.0 | 4 votes |
public static String buildLocation(String baseURL, Entity entity, String enitySetName, EdmEntityType type) throws EdmPrimitiveTypeException { StringBuilder location = new StringBuilder(); location.append(baseURL).append("/").append(enitySetName); int i = 0; boolean usename = type.getKeyPredicateNames().size() > 1; location.append("("); for (String key : type.getKeyPredicateNames()) { if (i > 0) { location.append(","); } i++; if (usename) { location.append(key).append("="); } EdmProperty property = (EdmProperty)type.getProperty(key); String propertyType = entity.getProperty(key).getType(); Object propertyValue = entity.getProperty(key).getValue(); if (propertyValue == null) { throw new EdmPrimitiveTypeException("The key value for property "+key+" is invalid; Key value cannot be null"); } if(propertyType.startsWith("Edm.")) { propertyType = propertyType.substring(4); } EdmPrimitiveTypeKind kind = EdmPrimitiveTypeKind.valueOf(propertyType); String value = EdmPrimitiveTypeFactory.getInstance(kind).valueToString( propertyValue, property.isNullable(), property.getMaxLength(), property.getPrecision(), property.getScale(), property.isUnicode()); if (kind == EdmPrimitiveTypeKind.String) { value = EdmString.getInstance().toUriLiteral(Encoder.encode(value)); } location.append(value); } location.append(")"); return location.toString(); }