in lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/XMLMetadataRequestImpl.java [49:134]
public ODataRetrieveResponse<XMLMetadata> execute() {
SingleXMLMetadatRequestImpl rootReq = new SingleXMLMetadatRequestImpl(odataClient, uri);
if (getPrefer() != null) {
rootReq.setPrefer(getPrefer());
}
if (getIfMatch() != null) {
rootReq.setIfMatch(getIfMatch());
}
if (getIfNoneMatch() != null) {
rootReq.setIfNoneMatch(getIfNoneMatch());
}
if (getHeader() != null) {
for (String key : getHeaderNames()) {
rootReq.addCustomHeader(key, odataHeaders.getHeader(key));
}
}
final ODataRetrieveResponse<XMLMetadata> rootRes = rootReq.execute();
if (rootRes.getStatusCode() != HttpStatusCode.OK.getStatusCode()) {
return rootRes;
}
final XMLMetadataResponseImpl response =
new XMLMetadataResponseImpl(odataClient, httpClient, rootReq.getHttpResponse(), rootRes.getBody());
// process external references
for (Reference reference : rootRes.getBody().getReferences()) {
final SingleXMLMetadatRequestImpl includeReq = new SingleXMLMetadatRequestImpl(
odataClient,
odataClient.newURIBuilder(uri.resolve(reference.getUri()).toASCIIString()).build());
// Copying the headers from first request to next request
for(String key : rootReq.getHeaderNames()){
includeReq.addCustomHeader(key ,rootReq.getHeader(key));
}
final XMLMetadata includeMetadata = includeReq.execute().getBody();
// edmx:Include
for (Include include : reference.getIncludes()) {
final CsdlSchema includedSchema = includeMetadata.getSchema(include.getNamespace());
if (includedSchema != null) {
response.getBody().getSchemas().add(includedSchema);
if (StringUtils.isNotBlank(include.getAlias())) {
includedSchema.setAlias(include.getAlias());
}
}
}
// edmx:IncludeAnnotations
for (IncludeAnnotations include : reference.getIncludeAnnotations()) {
for (CsdlSchema schema : includeMetadata.getSchemas()) {
// create empty schema that will be fed with edm:Annotations that match the criteria in IncludeAnnotations
final CsdlSchema forInclusion = new CsdlSchema();
forInclusion.setNamespace(schema.getNamespace());
forInclusion.setAlias(schema.getAlias());
// process all edm:Annotations in each schema of the included document
for (CsdlAnnotations annotationGroup : schema.getAnnotationGroups()) {
// take into account only when (TargetNamespace was either not provided or matches) and
// (Qualifier was either not provided or matches)
if ((StringUtils.isBlank(include.getTargetNamespace())
|| include.getTargetNamespace().equals(
StringUtils.substringBeforeLast(annotationGroup.getTarget(), ".")))
&& (StringUtils.isBlank(include.getQualifier())
|| include.getQualifier().equals(annotationGroup.getQualifier()))) {
final CsdlAnnotations toBeIncluded = new CsdlAnnotations();
toBeIncluded.setTarget(annotationGroup.getTarget());
toBeIncluded.setQualifier(annotationGroup.getQualifier());
// only import annotations with terms matching the given TermNamespace
for (CsdlAnnotation annotation : annotationGroup.getAnnotations()) {
if (include.getTermNamespace().equals(StringUtils.substringBeforeLast(annotation.getTerm(), "."))) {
toBeIncluded.getAnnotations().add(annotation);
}
}
forInclusion.getAnnotationGroups().add(toBeIncluded);
}
}
if (!forInclusion.getAnnotationGroups().isEmpty()) {
response.getBody().getSchemas().add(forInclusion);
}
}
}
}
return response;
}