Hello all, sorry if this is too rudimentary of a question but I have setup an 
oData service with the help of the great tutorials posted on the olingo site.   
 The tutorials cover the Resource path but I'd like to now perform a system or 
custom query.   Below I've included my basic $metadata document which has 2 
simple entities: Account/Producer (EntitySets: Accounts/Producers).    As it 
stands I can perform an operation like /Accounts(1) which is taken care of in 
my implementation of readEntity() in my ODataSingleProcesser shown below.    
Now I'd like to get say an account by 'AccountName'.   So would it be system 
$filter like: /Accounts?$filter=AccountName eq 'Account1'  or would it be a 
custom query like: /Accounts?AccountName='Account1'



And, where would I implement it?   Within readEntity?  If so, could you give me 
some guidance on the implementation?    I saw the sample of the visitor pattern 
to transform an odata query into a jdbc query but my odata service is 
connecting to another disparate service: this.accountService so I just need to 
basically parse the query and then perform the corresponding service call based 
on the query name/value pair.    Should I leverage what was shown in the 
visitor example?  If so, how does that 'plugin' to my OdataSingleProcessor 
implementation?



public class WPODataSingleProcessor extends ODataSingleProcessor {

.....

public ODataResponse readEntity(GetEntityUriInfo uriInfo, String contentType) 
throws ODataException {

                              logger.info("custom query options: " + 
uriInfo.getCustomQueryOptions());

                              if (uriInfo.getNavigationSegments().size() == 0) {

                                             EdmEntitySet entitySet = 
uriInfo.getStartEntitySet();

                                             WPEntitySet startEntitySet = 
WPEntitySet.fromString(entitySet.getName());



                                             int id;

                                             switch(startEntitySet) {

                                             case ACCOUNTS:

                                                            id = 
getKeyValue(uriInfo.getKeyPredicates().get(0));

                                                            Map<String, Object> 
account = this.accountService.getAccount(id);



                                                            if (account != 
null) {

                                                                           URI 
serviceRoot = getContext().getPathInfo().getServiceRoot();

                                                                           
ODataEntityProviderPropertiesBuilder propertiesBuilder = 
EntityProviderWriteProperties.serviceRoot(serviceRoot);



                                                                           
return EntityProvider.writeEntry(contentType, entitySet, account, 
propertiesBuilder.build());

                                                            }



                                             case PRODUCERS:

                                                            id = 
getKeyValue(uriInfo.getKeyPredicates().get(0));

                                                            Map<String, Object> 
producer = this.producerService.getProducer(id);



                                                            if (producer != 
null) {

                                                                           URI 
serviceRoot = getContext().getPathInfo().getServiceRoot();

                                                                           
ODataEntityProviderPropertiesBuilder propertiesBuilder = 
EntityProviderWriteProperties.serviceRoot(serviceRoot);



                                                                           
return EntityProvider.writeEntry(contentType, entitySet, producer, 
propertiesBuilder.build());

                                                            }              

                                             }



                                             throw new 
ODataNotFoundException(ODataNotFoundException.ENTITY);



                              }



                              throw new ODataNotImplementedException();

               }



...



}





-------------------

My $metadata:

-------------------

<edmx:Edmx xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx"; 
Version="1.0">

<edmx:DataServices 
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"; 
m:DataServiceVersion="1.0">

<Schema xmlns="http://schemas.microsoft.com/ado/2008/09/edm"; 
Namespace="com.sap.workplace.uiservice.odata">

<EntityType Name="Account">

<Key>

<PropertyRef Name="Id"/>

</Key>

<Property Name="Id" Type="Edm.Int32" Nullable="false"/>

<Property Name="AccountId" Type="Edm.String" Nullable="false"/>

<Property Name="AccountType" Type="Edm.String" Nullable="false"/>

<Property Name="AccountName" Type="Edm.String" Nullable="false"/>

<Property Name="AccountNumber" Type="Edm.String" Nullable="false"/>

<Property Name="Address" Type="com.sap.workplace.uiservice.odata.Address"/>

</EntityType>

<EntityType Name="Producer">

<Key>

<PropertyRef Name="Id"/>

</Key>

<Property Name="Id" Type="Edm.Int32" Nullable="false"/>

<Property Name="ProducerName" Type="Edm.String" Nullable="false"/>

<Property Name="ProducerId" Type="Edm.String" Nullable="false"/>

<Property Name="FirstName" Type="Edm.String" Nullable="false" MaxLength="100"/>

<Property Name="LastName" Type="Edm.String" Nullable="false" MaxLength="100"/>

<Property Name="Address" Type="com.sap.workplace.uiservice.odata.Address"/>

</EntityType>

<ComplexType Name="Address">

<Property Name="Address1" Type="Edm.String" Nullable="true"/>

<Property Name="Address2" Type="Edm.String" Nullable="true"/>

<Property Name="City" Type="Edm.String" Nullable="true"/>

<Property Name="State" Type="Edm.String" Nullable="true"/>

<Property Name="Country" Type="Edm.String" Nullable="true"/>

<Property Name="Zip" Type="Edm.String" Nullable="true"/>

</ComplexType>

<EntityContainer Name="SAPWorkplaceEntityContainer" 
m:IsDefaultEntityContainer="true">

<EntitySet Name="Accounts" 
EntityType="com.sap.workplace.uiservice.odata.Account"/>

<EntitySet Name="Producers" 
EntityType="com.sap.workplace.uiservice.odata.Producer"/>

</EntityContainer>

</Schema>

</edmx:DataServices>

</edmx:Edmx>





Reply via email to