[ 
https://issues.apache.org/jira/browse/OLINGO-992?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16290286#comment-16290286
 ] 

Ramya commented on OLINGO-992:
------------------------------

On the client side there are 2 ways to handle this problem
1. Term definition is part of the external file
Sample code
//Create a list of Input Streams that include the term definition files. Here 
VOC_Core is one such term definition file
List<InputStream> streams = new ArrayList<InputStream>();
streams.add(getClass().getResourceAsStream("VOC_Core.xml"));
//use the readmetadata() API that takes edmx file and the external vocabulary 
file as parameters. Both the parameters are input streams.
final Edm edm = 
client.getReader().readMetadata(getClass().getResourceAsStream("edmxWithCoreAnnotation.xml"),
 streams);
 
final EdmEntityType person = edm.getEntityType(new 
FullQualifiedName("Microsoft.Exchange.Services.OData.Model", "Person"));
EdmProperty concurrency = (EdmProperty) person.getProperty("Concurrency");
List<EdmAnnotation> annotations = concurrency.getAnnotations();
EdmTerm term = annotations.get(0).getTerm();

2. Term definition is specified in edmx reference uri within the metadata file
Sample Code
InputStream input = 
Thread.currentThread().getContextClassLoader().getResourceAsStream("edmxWithCoreAnnotation.xml");
// use the toMetadata API is used to fetch the edmx reference uri from the 
metadata file
final XMLMetadata metadata = 
getClient().getDeserializer(ContentType.APPLICATION_XML).toMetadata(input);
String vocabUrl = metadata.getReferences().get(0).getUri().toString();
vocabUrl = vocabUrl.substring(vocabUrl.indexOf("../") + 3);
vocabUrl = SERVICE_ROOT_URL + vocabUrl;
URI uri = new URI(vocabUrl);
input.close();
// Fire a request with the edmx reference uri to fetch the term definitions 
part of the external file
ODataRawRequest request = 
getClient().getRetrieveRequestFactory().getRawRequest(uri);
ODataRawResponse response = request.execute();
// Create a list of Input Streams that include all external term definitions as 
done in step 1
List<InputStream> streams = new ArrayList<InputStream>();
streams.add(response.getRawResponse());
// use the readMetadata api takes both the metadata file and external file as 
parameters. Both the parameters are input streams.
Edm edm = getClient().getReader().readMetadata(metadata, streams);

Please try these approaches and reopen the bug if you have face any issues.

Regards,
Ramya

> Load OData "CORE" Terms implicitly
> ----------------------------------
>
>                 Key: OLINGO-992
>                 URL: https://issues.apache.org/jira/browse/OLINGO-992
>             Project: Olingo
>          Issue Type: Improvement
>          Components: odata4-commons
>    Affects Versions: (Java) V4 4.2.0
>            Reporter: Punith DG
>              Labels: newbie, usability
>
> As many OData provides doesn't iclude OData Core definitions of "Term, thus 
> the EdmAnnotation.getTerm() retunrs NULLs. One could argue that these are 
> "core" vocabularies they need to be always available with whatever $metadata 
> document, which I agree as they are put forward by the OData Specification. 
> However, right now, Olingo client side library does not automatically add 
> these vocabularies into the Edm object, which does not have any of these 
> "core" terms. Hence users can't read the terms of Entity/Property annotations.
> It would help solve pro to request to add them implicitly on client side. 
> BTW, I see the server side MetadataParser does add these implicitly by 
> default.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to