Skip to content

Commit 31fe6ac

Browse files
authored
Merge pull request #303 from microsoftgraph/feature/odata-cast-derivedconstraint
feature/odata cast derivedconstraint
2 parents 4fcd88e + 353064e commit 31fe6ac

File tree

95 files changed

+4451
-53
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+4451
-53
lines changed

Templates/Java/requests_extensions/BaseEntityCollectionReferenceRequest.java.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import <#=mainNamespace#>.<#=c.GetPackagePrefix()#>.<#=c.TypeName()#>;
2727
super(requestUrl, client, requestOptions, <#=c.TypeCollectionResponse()#>.class, <#=c.ITypeCollectionPage()#>.class);
2828
}
2929

30-
public void post(final <#=c.TypeName()#> new<#=c.TypeName()#>, final ICallback<? super <#=c.TypeName()#>> callback) {
3130
<#
3231
var navigationProperty = c.AsOdcmProperty().GetServiceCollectionNavigationPropertyForPropertyType(((CustomT4Host)Host).CurrentModel);
3332
if (navigationProperty != null) {
@@ -39,6 +38,7 @@ import <#=mainNamespace#>.<#=c.GetPackagePrefix()#>.<#=c.TypeName()#>;
3938

4039
String prop = c.AsOdcmProperty().GetServiceCollectionNavigationPropertyForPropertyType(((CustomT4Host)Host).CurrentModel).Name;
4140
#>
41+
public void post(final <#=c.TypeName()#> new<#=c.TypeName()#>, final ICallback<? super <#=c.TypeName()#>> callback) {
4242
final String requestUrl = getBaseRequest().getRequestUrl().toString();
4343
final ReferenceRequestBody body = new ReferenceRequestBody(getBaseRequest().getClient().getServiceRoot() + "/<#=prop#>/<#=implicitNavigationProperty#>" + new<#=c.TypeName()#>.id);
4444
new <#=c.TypeWithReferencesRequestBuilder()#>(requestUrl, getBaseRequest().getClient(), /* Options */ null)

Templates/Java/requests_extensions/BaseEntityCollectionWithReferencesRequest.java.tt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,44 +45,44 @@ import <#=importNamespace#>.concurrency.IExecutors;
4545
}
4646

4747
<# if (c.GetFeatures().CanExpand) { #>
48-
public <#=c.ITypeCollectionRequest()#> expand(final String value) {
48+
public <#=c.ITypeCollectionWithReferencesRequest()#> expand(final String value) {
4949
addQueryOption(new com.microsoft.graph.options.QueryOption("$expand", value));
50-
return (<#=c.TypeCollectionRequest()#>)this;
50+
return this;
5151
}
5252

5353
<# } #>
5454
<# if (c.GetFeatures().CanFilter) { #>
55-
public <#=c.ITypeCollectionRequest()#> filter(final String value) {
55+
public <#=c.ITypeCollectionWithReferencesRequest()#> filter(final String value) {
5656
addQueryOption(new com.microsoft.graph.options.QueryOption("$filter", value));
57-
return (<#=c.TypeCollectionRequest()#>)this;
57+
return this;
5858
}
5959

6060
<# } #>
6161
<# if (c.GetFeatures().CanSort) { #>
62-
public <#=c.ITypeCollectionRequest()#> orderBy(final String value) {
62+
public <#=c.ITypeCollectionWithReferencesRequest()#> orderBy(final String value) {
6363
addQueryOption(new com.microsoft.graph.options.QueryOption("$orderby", value));
64-
return (<#=c.TypeCollectionRequest()#>)this;
64+
return this;
6565
}
6666

6767
<# } #>
6868
<# if (c.GetFeatures().CanSelect) { #>
69-
public <#=c.ITypeCollectionRequest()#> select(final String value) {
69+
public <#=c.ITypeCollectionWithReferencesRequest()#> select(final String value) {
7070
addQueryOption(new com.microsoft.graph.options.QueryOption("$select", value));
71-
return (<#=c.TypeCollectionRequest()#>)this;
71+
return this;
7272
}
7373

7474
<# } #>
7575
<# if (c.GetFeatures().CanUseTop) { #>
76-
public <#=c.ITypeCollectionRequest()#> top(final int value) {
76+
public <#=c.ITypeCollectionWithReferencesRequest()#> top(final int value) {
7777
addQueryOption(new com.microsoft.graph.options.QueryOption("$top", value + ""));
78-
return (<#=c.TypeCollectionRequest()#>)this;
78+
return this;
7979
}
8080

8181
<# } #>
8282
public <#=c.ITypeCollectionWithReferencesPage()#> buildFromResponse(final <#=c.TypeCollectionResponse()#> response) {
83-
final <#=c.ITypeCollectionRequestBuilder()#> builder;
83+
final <#=c.ITypeCollectionWithReferencesRequestBuilder()#> builder;
8484
if (response.nextLink != null) {
85-
builder = new <#=c.TypeCollectionRequestBuilder()#>(response.nextLink, getBaseRequest().getClient(), /* options */ null);
85+
builder = new <#=c.TypeCollectionWithReferencesRequestBuilder()#>(response.nextLink, getBaseRequest().getClient(), /* options */ null);
8686
} else {
8787
builder = null;
8888
}

Templates/Java/requests_extensions/BaseEntityRequestBuilder.java.tt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ if (c.AsOdcmClass() != null)
6868
if (prop.IsCollection()) {
6969
#>
7070
public <#=prop.ITypeCollectionRequestBuilder()#> <#=sanitizedProperty#>() {
71-
return new <#=prop.TypeCollectionRequestBuilder()#>(getRequestUrlWithAdditionalSegment("<#=prop.Name#>"), getClient(), null);
71+
return new <#=prop.TypeCollectionRequestBuilder()#>(getRequestUrlWithAdditionalSegment("<#=prop.ParentPropertyType == null ? prop.Name : prop.ParentPropertyType.Name #>")<# if(prop.ParentPropertyType != null) { #> + "/<#=prop.Projection.Type.FullName#>"<# } #>, getClient(), null);
7272
}
7373

7474
public <#=prop.ITypeRequestBuilder()#> <#=sanitizedProperty#>(final String id) {
75-
return new <#=prop.TypeRequestBuilder()#>(getRequestUrlWithAdditionalSegment("<#=prop.Name#>") + "/" + id, getClient(), null);
75+
return new <#=prop.TypeRequestBuilder()#>(getRequestUrlWithAdditionalSegment("<#=prop.ParentPropertyType == null ? prop.Name : prop.ParentPropertyType.Name #>") + "/" + id<# if(prop.ParentPropertyType != null) { #> + "/<#=prop.Projection.Type.FullName#>"<# } #>, getClient(), null);
7676
}
7777
<#
7878
} else {

Templates/Java/requests_extensions/BaseEntityStreamRequestBuilder.java.tt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ if (c.AsOdcmClass() != null)
5050
if (prop.IsCollection()) {
5151
#>
5252
public <#=prop.ITypeCollectionRequestBuilder()#> <#=prop.Name#>() {
53-
return new <#=prop.TypeCollectionRequestBuilder()#>(getRequestUrlWithAdditionalSegment("<#=prop.Name#>"), getClient(), null);
53+
return new <#=prop.TypeCollectionRequestBuilder()#>(getRequestUrlWithAdditionalSegment("<#=prop.ParentPropertyType == null ? prop.Name : prop.ParentPropertyType.Name #>")<# if(prop.ParentPropertyType != null) { #> + "/<#=prop.Projection.Type.FullName#>"<# } #>, getClient(), null);
5454
}
5555

5656
public <#=prop.ITypeRequestBuilder()#> <#=prop.Name#>(final String id) {
57-
return new <#=prop.TypeRequestBuilder()#>(getRequestUrlWithAdditionalSegment("<#=prop.Name#>") + "/" + id, getClient(), null);
57+
return new <#=prop.TypeRequestBuilder()#>(getRequestUrlWithAdditionalSegment("<#=prop.ParentPropertyType == null ? prop.Name : prop.ParentPropertyType.Name #>") + "/" + id<# if(prop.ParentPropertyType != null) { #> + "/<#=prop.Projection.Type.FullName#>"<# } #>, getClient(), null);
5858
}
5959
<#
6060
} else {

Templates/Java/requests_extensions/BaseMethodRequestBuilder.java.tt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ if(m != null && m.IsComposable && m.ReturnType != null && m.ReturnType is OdcmCl
8383
if (prop.IsCollection()) {
8484
#>
8585
public <#=prop.ITypeCollectionRequestBuilder()#> <#=sanitizedProperty#>() {
86-
return new <#=prop.TypeCollectionRequestBuilder()#>(getRequestUrlWithAdditionalSegment("<#=prop.Name#>"), getClient(), null);
86+
return new <#=prop.TypeCollectionRequestBuilder()#>(getRequestUrlWithAdditionalSegment("<#=prop.ParentPropertyType == null ? prop.Name : prop.ParentPropertyType.Name #>")<# if(prop.ParentPropertyType != null) { #> + "/<#=prop.Projection.Type.FullName#>"<# } #>, getClient(), null);
8787
}
8888

8989
public <#=prop.ITypeRequestBuilder()#> <#=sanitizedProperty#>(final String id) {
90-
return new <#=prop.TypeRequestBuilder()#>(getRequestUrlWithAdditionalSegment("<#=prop.Name#>") + "/" + id, getClient(), null);
90+
return new <#=prop.TypeRequestBuilder()#>(getRequestUrlWithAdditionalSegment("<#=prop.ParentPropertyType == null ? prop.Name : prop.ParentPropertyType.Name #>") + "/" + id<# if(prop.ParentPropertyType != null) { #> + "/<#=prop.Projection.Type.FullName#>"<# } #>, getClient(), null);
9191
}
9292
<#
9393
} else {

Templates/Java/requests_extensions/IBaseEntityCollectionReferenceRequest.java.tt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,15 @@ import <#=mainNamespace#>.<#=c.GetPackagePrefix()#>.<#=c.TypeName()#>;
1313

1414
<#=TypeHelperJava.CreateInterfaceDef(c.ITypeCollectionReferenceRequest())#>
1515

16+
<#
17+
var navigationProperty = c.AsOdcmProperty().GetServiceCollectionNavigationPropertyForPropertyType(((CustomT4Host)Host).CurrentModel);
18+
if (navigationProperty != null) {
19+
#>
1620
void post(final <#=c.TypeName()#> new<#=c.TypeName()#>, final ICallback<? super <#=c.TypeName()#>> callback);
1721

1822
<#=c.TypeName()#> post(final <#=c.TypeName()#> new<#=c.TypeName()#>) throws ClientException;
1923

24+
<# } #>
2025
<# if (c.GetFeatures().CanSelect) { #>
2126
<#=c.ITypeCollectionReferenceRequest()#> select(final String value);
2227

Templates/Java/requests_extensions/IBaseEntityCollectionRequest.java.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,6 @@ import <#=importNamespace#>.http.IHttpRequest;
8787
*
8888
* @return the updated request
8989
*/
90-
<#=c.ITypeCollectionRequest()#> skipToken(String skipToken);
90+
<#=c.ITypeCollectionRequest()#> skipToken(final String skipToken);
9191
}
9292
<#=PostProcess(c.ITypeCollectionRequest())#>

Templates/Java/requests_extensions/IBaseEntityCollectionWithReferencesRequestBuilder.java.tt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ import <#=importNamespace#>.http.IHttpRequest;
1818
* Creates the request
1919
*
2020
* @param requestOptions the options for this request
21-
* @return the IUserRequest instance
21+
* @return the <#=c.ITypeCollectionWithReferencesRequest()#> instance
2222
*/
2323
<#=c.ITypeCollectionWithReferencesRequest()#> buildRequest(final com.microsoft.graph.options.Option... requestOptions);
2424

2525
/**
2626
* Creates the request
2727
*
2828
* @param requestOptions the options for this request
29-
* @return the IUserRequest instance
29+
* @return the <#=c.ITypeCollectionWithReferencesRequest()#> instance
3030
*/
3131
<#=c.ITypeCollectionWithReferencesRequest()#> buildRequest(final java.util.List<? extends <#=importNamespace#>.options.Option> requestOptions);
3232

src/GraphODataTemplateWriter/CodeHelpers/Java/TypeHelperJava.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,7 @@ public static string CreatePackageDefForEntity(this CustomT4Host host)
10511051
var importFormat = @"import {0}.{1}.{2};";
10521052
Dictionary<string, int> uniqueStore = new Dictionary<string, int>();
10531053

1054-
foreach (var property in properties.Where(p => !p.Projection.Type.Name.Equals("Stream")))
1054+
foreach (var property in properties.Where(p => !p.Projection.Type.Name.Equals("Stream") && p.ParentPropertyType == null))
10551055
{
10561056
var propertyType = property.GetTypeString();
10571057
if (property.Type is OdcmPrimitiveType)
@@ -1123,7 +1123,7 @@ public static string CreatePackageDefForEntity(this CustomT4Host host)
11231123

11241124
if (properties != null)
11251125
{
1126-
foreach (var property in properties.Where(p => p.IsCollection() && p.IsNavigation()))
1126+
foreach (var property in properties.Where(p => p.IsCollection() && p.IsNavigation() && p.ParentPropertyType == null))
11271127
{
11281128
if (property.Type is OdcmPrimitiveType)
11291129
continue;
@@ -1200,13 +1200,13 @@ public static string CreatePackageDef(this CustomT4Host host)
12001200
?.ToList()
12011201
?.ForEach(x => methodImports.Add(x));
12021202
c?.NavigationProperties()
1203-
?.Where(x => x.IsCollection)?
1203+
?.Where(x => x.IsCollection && x.ParentPropertyType == null)?
12041204
.Select(x => x.Projection.Type)
12051205
?.Distinct()
12061206
?.ToList()
12071207
?.ForEach(x => ImportRequestBuilderTypes(host, x, methodImports, importFormat, interfaceTemplatePrefix, true));
12081208
c?.NavigationProperties()
1209-
?.Where(x => !x.IsCollection)
1209+
?.Where(x => !x.IsCollection && x.ParentPropertyType == null)
12101210
?.Select(x => x.Projection.Type)
12111211
?.Distinct()
12121212
?.ToList()
@@ -1336,7 +1336,7 @@ public static string UpdatePropertiesWithinSetRawObject(IEnumerable<OdcmProperty
13361336
var sb = new StringBuilder();
13371337
if (!isComplexType && properties != null)
13381338
{
1339-
foreach (var property in properties.Where(p => p.IsCollection() && p.IsNavigation()))
1339+
foreach (var property in properties.Where(p => p.IsCollection() && p.IsNavigation() && p.ParentPropertyType == null))
13401340
{
13411341
sb.AppendFormat(
13421342
@"
@@ -1429,7 +1429,7 @@ public static string CreatePropertyDef(IEnumerable<OdcmProperty> properties, boo
14291429
14301430
";
14311431

1432-
foreach (var property in properties.Where(p => !p.Projection.Type.Name.Equals("Stream")))
1432+
foreach (var property in properties.Where(p => !p.Projection.Type.Name.Equals("Stream") && p.ParentPropertyType == null))
14331433
{
14341434
var propertyName = property.Name.ToUpperFirstChar();
14351435
var propertyType = "";

src/GraphODataTemplateWriter/Extensions/OdcmModelExtensions.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -257,18 +257,18 @@ public static OdcmProperty GetServiceCollectionNavigationPropertyForPropertyType
257257
@namespace
258258
.Classes
259259
.Where(odcmClass => odcmClass.Kind == OdcmClassKind.Service)
260-
.First()
261-
.Properties
262-
.Where(property => property.GetType() == typeof(OdcmSingleton)) //Get the list of singletons defined by the service
263-
.Where(singleton => singleton
260+
.FirstOrDefault()
261+
?.Properties
262+
?.Where(property => property.GetType() == typeof(OdcmSingleton)) //Get the list of singletons defined by the service
263+
?.Where(singleton => singleton
264264
.Type
265265
.AsOdcmClass()
266266
.Properties
267267
//Find navigation properties on the singleton that are self-contained (implicit EntitySets) that match the type
268268
//we are searching for
269269
.Where(prop => prop.ContainsTarget == true && prop.Type.Name == odcmProperty.Type.Name)
270270
.FirstOrDefault() != null
271-
)
271+
) ?? new OdcmProperty[] { }
272272
).FirstOrDefault();
273273

274274
if (implicitProperty != null)

0 commit comments

Comments
 (0)