public class ODataDemoProperty { @EdmProperty private String propertyName; @EdmProperty(nullable = true) private ODataDemoPropertyType propertyType; @EdmProperty private ODataDemoPropertyValue defaultValue; @EdmProperty private List<String> requires = new ArrayList<>(); @EdmProperty private List<String> implies = new ArrayList<>();
public static Object getEdmPropertyValue(Object entity, String propertyName) throws IllegalAccessException { for (Field fld : entity.getClass().getDeclaredFields()) { EdmProperty ann = fld.getAnnotation(EdmProperty.class); if (ann != null && propertyName.equals(ann.name())) { fld.setAccessible(true); return fld.get(entity); } } throw new IllegalAccessException("No property " + propertyName + " in object of type " + entity.getClass().getName()); } }
private Property buildProperty(EdmProperty propertyAnno, Field field) { PropertyImpl.Builder builder = new PropertyImpl.Builder(); // Name String name = propertyAnno.name(); if (isNullOrEmpty(name)) { // Use field name if name is not specified in the EdmProperty annotation name = field.getName(); } builder.setName(name); // Type String typeName = propertyAnno.type(); if (!isNullOrEmpty(typeName)) { builder.setTypeName(typeName); } else { // Derive OData type from Java field type builder.setTypeFromJavaField(field, typeNameResolver); } return builder .setIsNullable(propertyAnno.nullable()) .setJavaField(field) .setDefaultValue(isNullOrEmpty(propertyAnno.defaultValue()) ? null : propertyAnno.defaultValue()) .setMaxLength(propertyAnno.maxLength()) .setPrecision(propertyAnno.precision()) .setScale(propertyAnno.scale()) .setSRID(propertyAnno.srid()) .setIsUnicode(propertyAnno.unicode()) .build(); }
private Property buildProperty(EdmProperty propertyAnno, Field field) { PropertyImpl.Builder builder = new PropertyImpl.Builder(); // Name String name = propertyAnno.name(); if (isNullOrEmpty(name)) { // Use field name if name is not specified in the EdmProperty annotation name = field.getName(); } builder.setName(name); // Type String typeName = propertyAnno.type(); if (!isNullOrEmpty(typeName)) { builder.setTypeName(typeName); } else { // Derive OData type from Java field type builder.setTypeFromJavaField(field, typeNameResolver); } return builder .setIsNullable(propertyAnno.nullable()) .setJavaField(field) .setDefaultValue(isNullOrEmpty(propertyAnno.defaultValue()) ? null : propertyAnno.defaultValue()) .setMaxLength(propertyAnno.maxLength()) .setPrecision(propertyAnno.precision()) .setScale(propertyAnno.scale()) .setSRID(propertyAnno.srid()) .setIsUnicode(propertyAnno.unicode()) .build(); }
public class ODataDemoPropertyValue { @EdmProperty private Boolean booleanValue; @EdmProperty private Integer integerValue; @EdmProperty private Double floatValue; @EdmProperty private Set<String> setValue = new HashSet<>(); @EdmProperty private String stringValue; @EdmProperty private ODataVersion versionValue; @EdmProperty private ODataDemoClassification pathValue; @EdmProperty private ODataDemoPropertyType type;
public static Object getEdmPropertyValue(Object entity, String propertyName) throws IllegalAccessException { for (Field fld : entity.getClass().getDeclaredFields()) { EdmProperty ann = fld.getAnnotation(EdmProperty.class); if (ann != null && propertyName.equals(ann.name())) { fld.setAccessible(true); return fld.get(entity); } } throw new IllegalAccessException("No property " + propertyName + " in object of type " + entity.getClass().getName()); } }
@EdmProperty(name = "ID", nullable = false) private long id; @EdmProperty(name = "Name", nullable = false, maxLength = EDM_MAX_LENGTH) private String name;
@EdmProperty(name = "ID", nullable = false) private long id; @EdmProperty(name = "Name", nullable = false, maxLength = EDM_MAX_LENGTH) private String name;
public class ODataDemoProperty { @EdmProperty private String propertyName; @EdmProperty(nullable = true) private ODataDemoPropertyType propertyType; @EdmProperty private ODataDemoPropertyValue defaultValue; @EdmProperty private List<String> requires = new ArrayList<>(); @EdmProperty private List<String> implies = new ArrayList<>();
public class ODataDemoPropertyValue { @EdmProperty private Boolean booleanValue; @EdmProperty private Integer integerValue; @EdmProperty private Double floatValue; @EdmProperty private Set<String> setValue = new HashSet<>(); @EdmProperty private String stringValue; @EdmProperty private ODataVersion versionValue; @EdmProperty private ODataDemoClassification pathValue; @EdmProperty private ODataDemoPropertyType type;
public class ODataDemoClassification { @EdmProperty private List<String> classifications = new ArrayList<>(); @EdmProperty private String key;
/** * The Complex Type Sample List model. */ @EdmComplex(namespace = "ODataDemo") public class ComplexTypeSampleList { @EdmProperty(name = "ListProperty", nullable = true) private List<String> listProperty; public List<String> getListProperty() { return listProperty; } public ComplexTypeSampleList setListProperty(List<String> property) { this.listProperty = property; return this; } }
/** * The Abstract Complex Type Sample. */ @EdmComplex(namespace = "ODataDemo") public abstract class AbstractComplexTypeSample { @EdmProperty(name = "InheritedProperty", nullable = true) private String inheritedProperty; public String getInheritedProperty() { return inheritedProperty; } public AbstractComplexTypeSample setInheritedProperty(String newInheritedProperty) { this.inheritedProperty = newInheritedProperty; return this; } }
public class ODataDemoClassification { @EdmProperty private List<String> classifications = new ArrayList<>(); @EdmProperty private String key;
/** * The Complex Type Sample model. */ @EdmComplex(namespace = "ODataDemo") public class ComplexTypeSample extends AbstractComplexTypeSample { @EdmProperty(name = "SimpleProperty", nullable = true) private String simpleProperty; public String getSimpleProperty() { return simpleProperty; } public ComplexTypeSample setSimpleProperty(String property) { this.simpleProperty = property; return this; } }
/** * The Abstract Complex Type Sample. */ @EdmComplex(namespace = "ODataDemo") public abstract class AbstractComplexTypeSample { @EdmProperty(name = "InheritedProperty", nullable = true) private String inheritedProperty; public String getInheritedProperty() { return inheritedProperty; } public AbstractComplexTypeSample setInheritedProperty(String newInheritedProperty) { this.inheritedProperty = newInheritedProperty; return this; } }
@EdmProperty(nullable = false) private int number = 0; @EdmProperty private String modifier; @EdmProperty(nullable = false) private int modifierNumber = 0; @EdmProperty(nullable = false) private int modifierPriority = 0;
@EdmProperty(name = "ID", nullable = false) private long id; @EdmProperty(name = "Name", nullable = false, maxLength = EDM_MAX_LENGTH) private String name; @EdmProperty(name = "PrimitivesCollection") private List<String> primitivesCollection = new ArrayList<>(); @EdmProperty(name = "EnumCollection") private List<EnumSample> enumCollection = new ArrayList<>(); @EdmProperty(name = "IdNamePairCollection") private List<IdNamePairComplex> idNamePairCollection = new ArrayList<>();
/** * The Complex Type Sample List model. */ @EdmComplex(namespace = "ODataDemo") public class ComplexTypeSampleList { @EdmProperty(name = "ListProperty", nullable = true) private List<String> listProperty; public List<String> getListProperty() { return listProperty; } public ComplexTypeSampleList setListProperty(List<String> property) { this.listProperty = property; return this; } }
/** * The Complex Type Sample model. */ @EdmComplex(namespace = "ODataDemo") public class ComplexTypeSample extends AbstractComplexTypeSample { @EdmProperty(name = "SimpleProperty", nullable = true) private String simpleProperty; public String getSimpleProperty() { return simpleProperty; } public ComplexTypeSample setSimpleProperty(String property) { this.simpleProperty = property; return this; } }