You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@olingo.apache.org by "Elliott, Anthony (LNG-RDU)" <an...@lexisnexis.com> on 2014/07/08 22:13:44 UTC

Strongly Typed models in Olingo 4

Hi all,

I'm using Olingo 4 (currently in development) to provide the framework for a Java client library for an OData 4 API.  What is the recommended way for me to create subclasses of ODataEntity and ODataEntitySet?

Specifically, I want to return each AlertProfile entity in the AlertProfiles entity set from the API.  I currently do that with the below code and end up casting to AlertProfile.  To avoid casting I could create my own methods like getAlertProfileIteratorRequest() and getAlertProfileEntitySetRequest(), but I'd rather do something like getIteratorRequest<AlertProfileEntitySet, AlertProfileEntity>().

Just checking to see what the recommended way is.

Thanks,
Anthony Elliott
-------------------------------------------

// lexis is an ODataClient
URI uri = lexis.newURIBuilder().appendEntitySetSegment("AlertProfiles").build();

ODataEntitySetIteratorRequest<ODataEntitySet, ODataEntity> request =
        lexis.getRetrieveRequestFactory().getEntitySetIteratorRequest(uri);

ODataEntitySetIterator<ODataEntitySet, ODataEntity> iterator = request.execute().getBody();

while (iterator.hasNext()) {
    AlertProfile alertProfile = (AlertProfile) iterator.next();
    // do stuff with alertProfile
}



Re: Strongly Typed models in Olingo 4

Posted by "Bolz, Michael" <mi...@sap.com>.
Hi Anthony,

no problem for the help. But unfortunately there is (IMHO) no way which is more 'generic' or reduce number of methdos/class inherits.

Kind regards,
Michael


On 10.07.2014, at 17:11, Elliott, Anthony (LNG-RDU) <an...@lexisnexis.com> wrote:

> Thanks for the help Michael!  I wasn’t sure if there was a more ‘generic’ way that I missed to reduce the number of methods, but I guess not…
>  
> Thanks again,
> Anthony
>  
>  
>  
> From: Bolz, Michael [mailto:michael.bolz@sap.com] 
> Sent: Wednesday, July 09, 2014 3:07 AM
> To: user@olingo.apache.org
> Subject: Re: Strongly Typed models in Olingo 4
>  
> Hi Anthony,
>  
> I have to admit that I'am not the expert for the client use case.
> So perhaps Francesco can add his opinion to my suggestion and/or improve it  ;o)
>  
> I think a good way is to create the AlertProfileEntitySet and AlertProfileEntity with "extends AbstractODataEntitySet implements ODataEntitySet" (for this short example I extended directly the *Impl which is not recommended).
> Then you have to create a "ODataEntitySetIteratorRequest<AlertProfileEntitySet, AlertProfileEntity>".
> Therefore it is the best to create a implementation of "AbstractRetrieveRequestFactory" (for which example code can be found in "RetrieveRequestFactoryImpl"). For the short example I directly copied the create method.
> Afterwards you can do the request, get the iterator and iterate over the next objects without casting.
>  
> Kind regards,
> Michael
>  
> Sample code snippet:
>  
> ```
>   private static class AlertProfileEntitySet extends ODataEntitySetImpl {
>     //extends AbstractODataEntitySet implements ODataEntitySet
>   }
>  
>   private static class AlertProfileEntity extends ODataEntityImpl {
>     public AlertProfileEntity(FullQualifiedName typeName) {
>       super(typeName);
>     }
>     //extends AbstractODataEntity implements ODataEntity, ODataSingleton
>   }
>  
>   private void sample(final ODataFormat format) {
>     final URIBuilder uriBuilder = client.newURIBuilder(getServiceRoot());
>  
>     ODataEntitySetIteratorRequest<AlertProfileEntitySet, AlertProfileEntity> req = getEntitySetIteratorRequest(uriBuilder.build());
>     req.setFormat(format);
>  
>     final ODataRetrieveResponse<ODataEntitySetIterator<AlertProfileEntitySet, AlertProfileEntity>> res = req.execute();
>     final ODataEntitySetIterator<AlertProfileEntitySet, AlertProfileEntity> feedIterator = res.getBody();
>  
>     while (feedIterator.hasNext()) {
>       AlertProfileEntity next = feedIterator.next();
>       // do stuff
>     }
>   }
>  
>   public ODataEntitySetIteratorRequest<AlertProfileEntitySet, AlertProfileEntity> getEntitySetIteratorRequest(final URI uri) {
>     return new ODataEntitySetIteratorRequestImpl<AlertProfileEntitySet, AlertProfileEntity>(client, uri);
>   }
> ```
>  
> From: <Elliott>, "Anthony (LNG-RDU)" <an...@lexisnexis.com>
> Reply-To: "user@olingo.apache.org" <us...@olingo.apache.org>
> Date: Dienstag, 8. Juli 2014 22:13
> To: "user@olingo.apache.org" <us...@olingo.apache.org>
> Subject: Strongly Typed models in Olingo 4
>  
> Hi all,
>  
> I’m using Olingo 4 (currently in development) to provide the framework for a Java client library for an OData 4 API.  What is the recommended way for me to create subclasses of ODataEntity and ODataEntitySet?
>  
> Specifically, I want to return each AlertProfile entity in the AlertProfiles entity set from the API.  I currently do that with the below code and end up casting to AlertProfile.  To avoid casting I could create my own methods like getAlertProfileIteratorRequest() and getAlertProfileEntitySetRequest(), but I’d rather do something like getIteratorRequest<AlertProfileEntitySet, AlertProfileEntity>().
>  
> Just checking to see what the recommended way is.
>  
> Thanks,
> Anthony Elliott
> -------------------------------------------
>  
> // lexis is an ODataClient
> URI uri = lexis.newURIBuilder().appendEntitySetSegment("AlertProfiles").build();
>  
> ODataEntitySetIteratorRequest<ODataEntitySet, ODataEntity> request =
>         lexis.getRetrieveRequestFactory().getEntitySetIteratorRequest(uri);
>  
> ODataEntitySetIterator<ODataEntitySet, ODataEntity> iterator = request.execute().getBody();
>  
> while (iterator.hasNext()) {
>     AlertProfile alertProfile = (AlertProfile) iterator.next();
>     // do stuff with alertProfile
> }


RE: Strongly Typed models in Olingo 4

Posted by "Elliott, Anthony (LNG-RDU)" <an...@lexisnexis.com>.
Thanks for the help Michael!  I wasn't sure if there was a more 'generic' way that I missed to reduce the number of methods, but I guess not...

Thanks again,
Anthony



From: Bolz, Michael [mailto:michael.bolz@sap.com]
Sent: Wednesday, July 09, 2014 3:07 AM
To: user@olingo.apache.org
Subject: Re: Strongly Typed models in Olingo 4

Hi Anthony,

I have to admit that I'am not the expert for the client use case.
So perhaps Francesco can add his opinion to my suggestion and/or improve it  ;o)

I think a good way is to create the AlertProfileEntitySet and AlertProfileEntity with "extends AbstractODataEntitySet implements ODataEntitySet" (for this short example I extended directly the *Impl which is not recommended).
Then you have to create a "ODataEntitySetIteratorRequest<AlertProfileEntitySet, AlertProfileEntity>".
Therefore it is the best to create a implementation of "AbstractRetrieveRequestFactory" (for which example code can be found in "RetrieveRequestFactoryImpl"). For the short example I directly copied the create method.
Afterwards you can do the request, get the iterator and iterate over the next objects without casting.

Kind regards,
Michael

Sample code snippet:

```
  private static class AlertProfileEntitySet extends ODataEntitySetImpl {
    //extends AbstractODataEntitySet implements ODataEntitySet
  }

  private static class AlertProfileEntity extends ODataEntityImpl {
    public AlertProfileEntity(FullQualifiedName typeName) {
      super(typeName);
    }
    //extends AbstractODataEntity implements ODataEntity, ODataSingleton
  }

  private void sample(final ODataFormat format) {
    final URIBuilder uriBuilder = client.newURIBuilder(getServiceRoot());

    ODataEntitySetIteratorRequest<AlertProfileEntitySet, AlertProfileEntity> req = getEntitySetIteratorRequest(uriBuilder.build());
    req.setFormat(format);

    final ODataRetrieveResponse<ODataEntitySetIterator<AlertProfileEntitySet, AlertProfileEntity>> res = req.execute();
    final ODataEntitySetIterator<AlertProfileEntitySet, AlertProfileEntity> feedIterator = res.getBody();

    while (feedIterator.hasNext()) {
      AlertProfileEntity next = feedIterator.next();
      // do stuff
    }
  }

  public ODataEntitySetIteratorRequest<AlertProfileEntitySet, AlertProfileEntity> getEntitySetIteratorRequest(final URI uri) {
    return new ODataEntitySetIteratorRequestImpl<AlertProfileEntitySet, AlertProfileEntity>(client, uri);
  }
```

From: <Elliott>, "Anthony (LNG-RDU)" <an...@lexisnexis.com>>
Reply-To: "user@olingo.apache.org<ma...@olingo.apache.org>" <us...@olingo.apache.org>>
Date: Dienstag, 8. Juli 2014 22:13
To: "user@olingo.apache.org<ma...@olingo.apache.org>" <us...@olingo.apache.org>>
Subject: Strongly Typed models in Olingo 4

Hi all,

I'm using Olingo 4 (currently in development) to provide the framework for a Java client library for an OData 4 API.  What is the recommended way for me to create subclasses of ODataEntity and ODataEntitySet?

Specifically, I want to return each AlertProfile entity in the AlertProfiles entity set from the API.  I currently do that with the below code and end up casting to AlertProfile.  To avoid casting I could create my own methods like getAlertProfileIteratorRequest() and getAlertProfileEntitySetRequest(), but I'd rather do something like getIteratorRequest<AlertProfileEntitySet, AlertProfileEntity>().

Just checking to see what the recommended way is.

Thanks,
Anthony Elliott
-------------------------------------------

// lexis is an ODataClient
URI uri = lexis.newURIBuilder().appendEntitySetSegment("AlertProfiles").build();

ODataEntitySetIteratorRequest<ODataEntitySet, ODataEntity> request =
        lexis.getRetrieveRequestFactory().getEntitySetIteratorRequest(uri);

ODataEntitySetIterator<ODataEntitySet, ODataEntity> iterator = request.execute().getBody();

while (iterator.hasNext()) {
    AlertProfile alertProfile = (AlertProfile) iterator.next();
    // do stuff with alertProfile
}



Re: Strongly Typed models in Olingo 4

Posted by "Bolz, Michael" <mi...@sap.com>.
Hi Anthony,

I have to admit that I'am not the expert for the client use case.
So perhaps Francesco can add his opinion to my suggestion and/or improve it
;o)

I think a good way is to create the AlertProfileEntitySet and
AlertProfileEntity with "extends AbstractODataEntitySet implements
ODataEntitySet" (for this short example I extended directly the *Impl which
is not recommended).
Then you have to create a
"ODataEntitySetIteratorRequest<AlertProfileEntitySet, AlertProfileEntity>".
Therefore it is the best to create a implementation of
"AbstractRetrieveRequestFactory" (for which example code can be found in
"RetrieveRequestFactoryImpl"). For the short example I directly copied the
create method.
Afterwards you can do the request, get the iterator and iterate over the
next objects without casting.

Kind regards,
Michael

Sample code snippet:

```
  private static class AlertProfileEntitySet extends ODataEntitySetImpl {
    //extends AbstractODataEntitySet implements ODataEntitySet
  }

  private static class AlertProfileEntity extends ODataEntityImpl {
    public AlertProfileEntity(FullQualifiedName typeName) {
      super(typeName);
    }
    //extends AbstractODataEntity implements ODataEntity, ODataSingleton
  }

  private void sample(final ODataFormat format) {
    final URIBuilder uriBuilder = client.newURIBuilder(getServiceRoot());

    ODataEntitySetIteratorRequest<AlertProfileEntitySet, AlertProfileEntity>
req = getEntitySetIteratorRequest(uriBuilder.build());
    req.setFormat(format);

    final 
ODataRetrieveResponse<ODataEntitySetIterator<AlertProfileEntitySet,
AlertProfileEntity>> res = req.execute();
    final ODataEntitySetIterator<AlertProfileEntitySet, AlertProfileEntity>
feedIterator = res.getBody();

    while (feedIterator.hasNext()) {
      AlertProfileEntity next = feedIterator.next();
      // do stuff
    }
  }

  public ODataEntitySetIteratorRequest<AlertProfileEntitySet,
AlertProfileEntity> getEntitySetIteratorRequest(final URI uri) {
    return new ODataEntitySetIteratorRequestImpl<AlertProfileEntitySet,
AlertProfileEntity>(client, uri);
  }
```

From:  <Elliott>, "Anthony   (LNG-RDU)" <an...@lexisnexis.com>
Reply-To:  "user@olingo.apache.org" <us...@olingo.apache.org>
Date:  Dienstag, 8. Juli 2014 22:13
To:  "user@olingo.apache.org" <us...@olingo.apache.org>
Subject:  Strongly Typed models in Olingo 4

Hi all,
 
I¹m using Olingo 4 (currently in development) to provide the framework for a
Java client library for an OData 4 API.  What is the recommended way for me
to create subclasses of ODataEntity and ODataEntitySet?
 
Specifically, I want to return each AlertProfile entity in the AlertProfiles
entity set from the API.  I currently do that with the below code and end up
casting to AlertProfile.  To avoid casting I could create my own methods
like getAlertProfileIteratorRequest() and getAlertProfileEntitySetRequest(),
but I¹d rather do something like getIteratorRequest<AlertProfileEntitySet,
AlertProfileEntity>().
 
Just checking to see what the recommended way is.
 
Thanks,
Anthony Elliott
-------------------------------------------
 
// lexis is an ODataClient
URI uri = 
lexis.newURIBuilder().appendEntitySetSegment("AlertProfiles").build();
 
ODataEntitySetIteratorRequest<ODataEntitySet, ODataEntity> request =
        lexis.getRetrieveRequestFactory().getEntitySetIteratorRequest(uri);
 
ODataEntitySetIterator<ODataEntitySet, ODataEntity> iterator =
request.execute().getBody();
 
while (iterator.hasNext()) {
    AlertProfile alertProfile = (AlertProfile) iterator.next();
    // do stuff with alertProfile
}