return OProperties.string(name, value); else if (value == null) return OProperties.null_(name, type); else if (EdmSimpleType.STRING.equals(type)) if (tokenType == JsonTokenType.STRING) return OProperties.string(name, value); else throw new JsonParseException("Illegal JSON string-value format"); else if (EdmSimpleType.GUID.equals(type)) return OProperties.guid(name, Guid.fromString(value)); else if (EdmSimpleType.BOOLEAN.equals(type)) if (tokenType == JsonTokenType.FALSE || tokenType == JsonTokenType.TRUE) return OProperties.boolean_(name, Boolean.valueOf(value)); else throw new JsonParseException("Illegal JSON boolean-value format"); else if (EdmSimpleType.BYTE.equals(type)) return OProperties.byte_(name, UnsignedByte.parseUnsignedByte(value)); else if (EdmSimpleType.SBYTE.equals(type)) return OProperties.sbyte_(name, Byte.parseByte(value)); else if (EdmSimpleType.INT16.equals(type)) return OProperties.int16(name, Short.parseShort(value)); else if (EdmSimpleType.INT32.equals(type)) return OProperties.int32(name, Integer.parseInt(value)); else if (EdmSimpleType.INT64.equals(type)) return OProperties.int64(name, Long.parseLong(value)); else if (EdmSimpleType.SINGLE.equals(type)) return OProperties.single(name, Float.parseFloat(value)); else if (EdmSimpleType.DOUBLE.equals(type)) return OProperties.double_(name, Double.parseDouble(value));
/** * Creates a new OData property, inferring the edm-type from the value provided, which cannot be null. * * @param <T> the property value's java-type * @param name the property name * @param value the property value * @return a new OData property instance */ public static <T> OProperty<T> simple(String name, T value) { if (value == null) throw new IllegalArgumentException("Cannot infer EdmType if value is null"); EdmSimpleType<T> type = EdmSimpleType.forJavaType(value.getClass()); if (type == null) throw new IllegalArgumentException("Cannot infer EdmType for java type: " + value.getClass().getName()); return simple(name, type, value); }
Object ov = override == null ? a.getValue() : override; if (a instanceof EdmAnnotationAttribute) { props.add(OProperties.string(propName, ov.toString())); } else if (ov instanceof OComplexObject) { OComplexObject co = (OComplexObject) ov; props.add(OProperties.complex(propName, (EdmComplexType) co.getType(), co.getProperties())); } else if (ov instanceof OCollection) { OCollection<?> co = (OCollection<?>) ov; props.add(OProperties.collection(propName, new EdmCollectionType(CollectionKind.Collection, co.getType()), co));
private OEntity getProperty(EdmStructuralType queryType, EdmStructuralType et, EdmProperty p, Context c) { List<OProperty<?>> props = new ArrayList<OProperty<?>>(); if (c.pathHelper.isSelected(Edm.Property.Namespace)) { props.add(OProperties.string(Edm.Property.Namespace, et.getNamespace())); props.add(OProperties.string(Edm.Property.EntityTypeName, et.getName())); props.add(OProperties.string(Edm.Property.Name, p.getName())); props.add(OProperties.string(Edm.Property.Type, p.getType().getFullyQualifiedTypeName())); props.add(OProperties.boolean_(Edm.Property.Nullable, p.isNullable())); props.add(OProperties.string(Edm.Property.DefaultValue, p.getDefaultValue())); props.add(OProperties.int32(Edm.Property.MaxLength, p.getMaxLength())); props.add(OProperties.boolean_(Edm.Property.FixedLength, p.getFixedLength())); props.add(OProperties.int32(Edm.Property.Precision, p.getPrecision())); props.add(OProperties.int32(Edm.Property.Scale, p.getScale())); props.add(OProperties.boolean_(Edm.Property.Unicode, p.getUnicode())); props.add(OProperties.string(Edm.Property.CollectionKind, p.getCollectionKind().toString()));
/** * Typeがnullの場合にmessageが返却されること. */ @Test public final void Typeがnullの場合にmessageが返却されること() { OProperty<?> expected = OProperties.string(SentMessage.P_TYPE.getName(), "message"); OProperty<?> result = this.setDefaultValue(SentMessage.P_TYPE.build(), SentMessage.P_TYPE.getName(), OProperties.string(SentMessage.P_TYPE.getName(), "")); assertEquals(expected.getValue(), result.getValue()); }
/** * ToがNullの場合にNullOPropertyが返却されること. */ @Test public final void ToがNullの場合にNullOPropertyが返却されること() { OProperty<?> expected = OProperties.null_(SentMessage.P_TO.getName(), EdmSimpleType.STRING); OProperty<?> result = this.setDefaultValue(SentMessage.P_TO.build(), SentMessage.P_TO.getName(), OProperties.string(SentMessage.P_TO.getName(), AbstractCase.STRING_LENGTH_129)); assertEquals(expected.getValue(), result.getValue()); }
.properties(OProperties.int32("ID", 10)) .properties(OProperties.string("Name", "Josta")) .properties(OProperties.string("Description", "With guaraná")) .properties(OProperties.datetime("ReleaseDate", new LocalDateTime())) .properties(OProperties.int32("Rating", 1)) .properties(OProperties.decimal("Price", 1.23)) .execute(); .properties(OProperties.int32("Rating", 5)) .execute(); .properties(OProperties.int32("Rating", 500)) .execute();
private OEntity getStructuralType(Context c, EdmStructuralType st) { List<OProperty<?>> props = new ArrayList<OProperty<?>>(); if (c.pathHelper.isSelected(Edm.StructuralType.Name)) { props.add(OProperties.string(Edm.StructuralType.Name, st.getName())); props.add(OProperties.string(Edm.StructuralType.Namespace, st.getNamespace())); props.add(OProperties.boolean_(Edm.StructuralType.Abstract, st.getIsAbstract())); props.add(OProperties.string(Edm.StructuralType.BaseType, st.getBaseType().getFullyQualifiedTypeName())); for (String key : ((EdmEntityType) st).getKeys()) { List<OProperty<?>> refProps = new ArrayList<OProperty<?>>(); refProps.add(OProperties.string(Edm.PropertyRef.Name, key)); builder.add(OComplexObjects.create(propRefType, refProps)); EdmProperty keysProp = entityKeyType.findProperty(Edm.EntityKey.Keys); EdmType collectionItemType = entityKeyType.findProperty(Edm.EntityKey.Keys).getType(); keyProps.add(OProperties.collection(Edm.EntityKey.Keys, new EdmCollectionType(keysProp.getCollectionKind(), collectionItemType), builder.build())); props.add(OProperties.complex(Edm.EntityType.Key, entityKeyType, key.getProperties()));
/** * Priorityが2の場合にDcCoreExceptionが発生しないこと. */ @Test public final void Priorityが2の場合にDcCoreExceptionが発生しないこと() { this.validateProperty(ReceivedMessage.P_PRIORITY.build(), ReceivedMessage.P_PRIORITY.getName(), OProperties.int32(ReceivedMessage.P_PRIORITY.getName(), 2)); }
/** * Priorityがnullの場合に3が発生すること. */ @Test public final void Priorityがnullの場合に3が発生すること() { OProperty<?> expected = OProperties.int32(SentMessage.P_PRIORITY.getName(), 3); OProperty<?> result = this.setDefaultValue(SentMessage.P_PRIORITY.build(), SentMessage.P_PRIORITY.getName(), OProperties.string(SentMessage.P_PRIORITY.getName(), "")); assertEquals(expected.getValue(), result.getValue()); }
properties.add(OProperties.simple(property.getName(), (EdmSimpleType<? extends Object>) property.getType(), value)); } else { properties.add(OProperties.complex(property.getName(), (EdmComplexType) property.getType(), null)); } else { Class<?> propType = propertyModel.getPropertyType(property.getName()); properties.add(OProperties.complex(property.getName(), (EdmComplexType) property.getType(), cprops)); properties.add(OProperties.collection(property.getName(),
entry.properties.add(OProperties.complex(name, (EdmComplexType) ep.getType(), null)); } else { throw new UnsupportedOperationException("complex property unknown parse state"); val.entities)); } else if (val.collection != null) { entry.properties.add(OProperties.collection(name, val.collectionType, val.collection)); } else if (val.complexObject != null) { entry.properties.add(OProperties.complex(name, (EdmComplexType) val.complexObject.getType(), val.complexObject.getProperties()));
private OProperty<?> readProperty(Column column, Object value) { if (value instanceof Array) { EdmType componentType = ODataTypeManager.odataType(column.getRuntimeType()); if (componentType instanceof EdmCollectionType) { componentType = ((EdmCollectionType)componentType).getItemType(); } OCollection.Builder<OObject> b = OCollections.newBuilder(componentType); List<Expression> values = ((Array)value).getExpressions(); for (int i = 0; i < values.size(); i++) { Literal literal = (Literal)values.get(i); b.add(OSimpleObjects.create((EdmSimpleType<?>)componentType, literal.getValue())); } return OProperties.collection(column.getName(), new EdmCollectionType(CollectionKind.Collection, componentType), b.build()); } else { Literal literal = (Literal)value; return OProperties.simple(column.getName(), literal.getValue()); } }
private static OProperty<?> readCollection(String name, EdmCollectionType collectionType, XMLEventReader2 reader, StartElement2 collectionElement, EdmDataServices metadata, EdmStructuralType structuralType) { EdmType componentType = collectionType.getItemType(); OCollection.Builder<OObject> b = OCollections.newBuilder(componentType); while (reader.hasNext()) { XMLEvent2 event = reader.nextEvent(); if (event.isEndElement() && event.asEndElement().getName().equals(collectionElement.getName())) { break; } if (event.isStartElement() && event.asStartElement().getName().getNamespaceUri().equals(NS_DATASERVICES)) { OProperty<?> op = null; Attribute2 nullAttribute = event.asStartElement().getAttributeByName(M_NULL); boolean isNull = nullAttribute != null && "true".equals(nullAttribute.getValue()); if (!componentType.isSimple()) { EdmStructuralType est = (EdmStructuralType) componentType; op = OProperties.complex(name, (EdmComplexType) componentType, isNull ? null : Enumerable.create(parseProperties(reader, event.asStartElement(), metadata, est)).toList()); } else { op = OProperties.parseSimple(name, (EdmSimpleType<?>) componentType, isNull ? null : reader.getElementText()); } b.add(OSimpleObjects.create((EdmSimpleType<?>)componentType, op.getValue())); } } return OProperties.collection(name, collectionType, b.build()); }
/** * ToもToRelationも存在しない場合にDcCoreExceptionが発生すること. */ @Test(expected = DcCoreException.class) public final void ToもToRelationも存在しない場合にDcCoreExceptionが発生すること() { String to = (String) OProperties.null_(SentMessage.P_TO.getName(), EdmSimpleType.STRING).getValue(); String toRelation = (String) OProperties.null_(SentMessage.P_TO_RELATION.getName(), EdmSimpleType.STRING).getValue(); MessageODataResource.validateToAndToRelation(to, toRelation); }
/** * Creates a new Guid-valued OData property with {@link EdmSimpleType#GUID} * * @param name the property name * @param value the property value * @return a new OData property instance */ public static OProperty<Guid> guid(String name, String value) { return guid(name, Guid.fromString(value)); }
/** * Double型の値の有効範囲チェックのテスト. * @param f テストパターン * @throws Exception Exception */ @Theory public void Double型の値の有効範囲チェック(Fixture f) throws Exception { ODataEntityResource resource = new ODataEntityResource(); Method method = AbstractODataResource.class.getDeclaredMethod("validateDynamicProperty", new Class[] {OProperty.class}); method.setAccessible(true); OProperty<Double> property = OProperties.double_("testKey", f.inputValue); boolean valildResult = true; try { method.invoke(resource, property); } catch (InvocationTargetException ex) { if (ex.getCause() instanceof DcCoreException) { DcCoreException e = (DcCoreException) ex.getCause(); if (DcCoreException.OData.REQUEST_FIELD_FORMAT_ERROR.getCode().equals(e.getCode())) { valildResult = false; } else { fail(f.testComment + ": 期待したエラーコードではない. 例外コード:[" + e.getCode() + "]"); } } } assertEquals(f.testComment, f.expectedReturnValue, valildResult); } }
/** * Bodyがnullの場合に空文字が返却されること. */ @Test public final void Bodyがnullの場合に空文字が返却されること() { OProperty<?> expected = OProperties.string(SentMessage.P_BODY.getName(), ""); OProperty<?> result = this.setDefaultValue(SentMessage.P_BODY.build(), SentMessage.P_BODY.getName(), OProperties.string(SentMessage.P_BODY.getName(), "")); assertEquals(expected.getValue(), result.getValue()); }
/** * ToRelationがnullの場合にNullOPropertyが返却されること. */ @Test public final void ToRelationがnullの場合にNullOPropertyが返却されること() { OProperty<?> expected = OProperties.null_(SentMessage.P_TO_RELATION.getName(), EdmSimpleType.STRING); OProperty<?> result = this.setDefaultValue(SentMessage.P_TO_RELATION.build(), SentMessage.P_TO_RELATION.getName(), OProperties.string(SentMessage.P_TO_RELATION.getName(), "")); assertEquals(expected.getValue(), result.getValue()); }
private OEntity getStructuralType(Context c, EdmStructuralType st) { List<OProperty<?>> props = new ArrayList<OProperty<?>>(); if (c.pathHelper.isSelected(Edm.StructuralType.Name)) { props.add(OProperties.string(Edm.StructuralType.Name, st.getName())); props.add(OProperties.string(Edm.StructuralType.Namespace, st.getNamespace())); props.add(OProperties.boolean_(Edm.StructuralType.Abstract, st.getIsAbstract())); props.add(OProperties.string(Edm.StructuralType.BaseType, st.getBaseType().getFullyQualifiedTypeName())); for (String key : ((EdmEntityType) st).getKeys()) { List<OProperty<?>> refProps = new ArrayList<OProperty<?>>(); refProps.add(OProperties.string(Edm.PropertyRef.Name, key)); builder.add(OComplexObjects.create(propRefType, refProps)); EdmProperty keysProp = entityKeyType.findProperty(Edm.EntityKey.Keys); EdmType collectionItemType = entityKeyType.findProperty(Edm.EntityKey.Keys).getType(); keyProps.add(OProperties.collection(Edm.EntityKey.Keys, new EdmCollectionType(keysProp.getCollectionKind(), collectionItemType), builder.build())); props.add(OProperties.complex(Edm.EntityType.Key, entityKeyType, key.getProperties()));