How to create an enum entity type in Olingo OData V4 java API -


i have created enumeration:

public enum rolecategory {     low ("low risk", 0),     medium ("medium risk", 1),      public final string attrname;     public final int value;      rolecategory(string attrname, int value) {         this.attrname = attrname;         this.value = value;     }     public static rolecategory valueof(int val){         switch(val){         case 0: return low;          case 1: return medium;         default: throw new illegalargumentexception("blablabla");         }     }     public int toint() { return value; } } 

according starter tutorial i've created normal odataprovider class. i'm missing peace of code enum fqdn type property instantiation:

csdlproperty p = new csdlproperty().setname("myenum").settype( ?getenumtype("myenum")? ) 

ok, found simple solution myself. it's not best one:

1.) i've added new static fullqualifiedname:

public static final fullqualifiedname cet_rolecat = new fullqualifiedname(namespace, "rolecategory"); 

2.) i've created member getenumtype()

public csdlenumtype getenumtype(final fullqualifiedname enmutypename){     if (cet_rolecat.equals(enmutypename)) {         return new csdlenumtype()             .setname(cet_rolecat.getname())             .setmembers(arrays.aslist(                     new csdlenummember().setname("low").setvalue("0"),                     new csdlenummember().setname("medium").setvalue("1")             ))             .setunderlyingtype(edmprimitivetypekind.int32.getfullqualifiedname())         ;     }     return null; } 

3.) i've added fqdn 1.) entity property:

// ...     csdlproperty p = new csdlproperty().setname("rolecategory").settype(cet_rolecat)); //... 

4.) i've added enumtype schema:

public list<csdlschema> getschemas() throws odataexception {     csdlschema schema = new csdlschema();     // ...     list<csdlenumtype> enumtypes = new arraylist<csdlenumtype>();     enumtypes.add(getenumtype(cet_rolecat));     schema.setenumtypes(enumtypes);     // ...     list<csdlschema> schemas = new arraylist<csdlschema>();     schemas.add(schema);     return schemas; } 

fyi: 'namespace' public static final string member in edmodataprovider class.

unfortunately possible me add strings in name , value parts in 2.) @ csdlenummember. neither i'm sure what's setunderlyningtype() for.


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -