Skip to content

feature/odata cast derivedconstraint #303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Oct 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
634f56b
- adds missing final keyword for skiptoken method
baywet Sep 25, 2020
5f0cf14
- updates unit test files for missing final keyword
baywet Sep 25, 2020
0e48ed0
- fixes a bug where passing a non property would make the template fail
baywet Sep 28, 2020
6d3e786
- fixes a bug where references collections would return the wrong type
baywet Sep 28, 2020
281cfe0
- fixes a bug where passing a non property would generate invalid met…
baywet Sep 28, 2020
ac7e17b
- fixes missing line break
baywet Sep 29, 2020
2324d28
- fixes javadoc to document the right return type
baywet Sep 29, 2020
52aebf7
- adds test case for derived type constraint
baywet Sep 29, 2020
328ce7b
- fixes annotation name in test file
baywet Sep 29, 2020
5e806d9
- upgrades odata lib to match vipr
baywet Sep 29, 2020
3ff2dd8
- fixes a null reference exception on implicit nav props detection
baywet Sep 29, 2020
e7b12dd
- adds support for odata cast in java templates
baywet Sep 29, 2020
dc07e41
- updates unit test files for java odata cast
baywet Sep 29, 2020
69d93c0
- updates reference to vipr for odata cast
baywet Sep 29, 2020
2d13cc1
- udpates reference to vipr
baywet Sep 29, 2020
894764d
- prevents odata cast virtual properties from generating properties i…
baywet Sep 29, 2020
0a5e1fb
- udpates java test file generated model to avoid virtual cast proper…
baywet Sep 29, 2020
e8221ae
- fixes a bug were duplicated annotations would introduce duplicated …
baywet Sep 30, 2020
abd0c85
- collapses slash and type for odata cast
baywet Sep 30, 2020
9510e74
- updates unit test files
baywet Sep 30, 2020
3355ec6
- updates reference to vipr
baywet Oct 2, 2020
c6e22a2
- enables virtual properties injection based on language
baywet Oct 2, 2020
353064e
- adds missing generator conditional cast properties
baywet Oct 2, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import <#=mainNamespace#>.<#=c.GetPackagePrefix()#>.<#=c.TypeName()#>;
super(requestUrl, client, requestOptions, <#=c.TypeCollectionResponse()#>.class, <#=c.ITypeCollectionPage()#>.class);
}

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

String prop = c.AsOdcmProperty().GetServiceCollectionNavigationPropertyForPropertyType(((CustomT4Host)Host).CurrentModel).Name;
#>
public void post(final <#=c.TypeName()#> new<#=c.TypeName()#>, final ICallback<? super <#=c.TypeName()#>> callback) {
final String requestUrl = getBaseRequest().getRequestUrl().toString();
final ReferenceRequestBody body = new ReferenceRequestBody(getBaseRequest().getClient().getServiceRoot() + "/<#=prop#>/<#=implicitNavigationProperty#>" + new<#=c.TypeName()#>.id);
new <#=c.TypeWithReferencesRequestBuilder()#>(requestUrl, getBaseRequest().getClient(), /* Options */ null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,44 +45,44 @@ import <#=importNamespace#>.concurrency.IExecutors;
}

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

<# } #>
<# if (c.GetFeatures().CanFilter) { #>
public <#=c.ITypeCollectionRequest()#> filter(final String value) {
public <#=c.ITypeCollectionWithReferencesRequest()#> filter(final String value) {
addQueryOption(new com.microsoft.graph.options.QueryOption("$filter", value));
return (<#=c.TypeCollectionRequest()#>)this;
return this;
}

<# } #>
<# if (c.GetFeatures().CanSort) { #>
public <#=c.ITypeCollectionRequest()#> orderBy(final String value) {
public <#=c.ITypeCollectionWithReferencesRequest()#> orderBy(final String value) {
addQueryOption(new com.microsoft.graph.options.QueryOption("$orderby", value));
return (<#=c.TypeCollectionRequest()#>)this;
return this;
}

<# } #>
<# if (c.GetFeatures().CanSelect) { #>
public <#=c.ITypeCollectionRequest()#> select(final String value) {
public <#=c.ITypeCollectionWithReferencesRequest()#> select(final String value) {
addQueryOption(new com.microsoft.graph.options.QueryOption("$select", value));
return (<#=c.TypeCollectionRequest()#>)this;
return this;
}

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

<# } #>
public <#=c.ITypeCollectionWithReferencesPage()#> buildFromResponse(final <#=c.TypeCollectionResponse()#> response) {
final <#=c.ITypeCollectionRequestBuilder()#> builder;
final <#=c.ITypeCollectionWithReferencesRequestBuilder()#> builder;
if (response.nextLink != null) {
builder = new <#=c.TypeCollectionRequestBuilder()#>(response.nextLink, getBaseRequest().getClient(), /* options */ null);
builder = new <#=c.TypeCollectionWithReferencesRequestBuilder()#>(response.nextLink, getBaseRequest().getClient(), /* options */ null);
} else {
builder = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ if (c.AsOdcmClass() != null)
if (prop.IsCollection()) {
#>
public <#=prop.ITypeCollectionRequestBuilder()#> <#=sanitizedProperty#>() {
return new <#=prop.TypeCollectionRequestBuilder()#>(getRequestUrlWithAdditionalSegment("<#=prop.Name#>"), getClient(), null);
return new <#=prop.TypeCollectionRequestBuilder()#>(getRequestUrlWithAdditionalSegment("<#=prop.ParentPropertyType == null ? prop.Name : prop.ParentPropertyType.Name #>")<# if(prop.ParentPropertyType != null) { #> + "/<#=prop.Projection.Type.FullName#>"<# } #>, getClient(), null);
}

public <#=prop.ITypeRequestBuilder()#> <#=sanitizedProperty#>(final String id) {
return new <#=prop.TypeRequestBuilder()#>(getRequestUrlWithAdditionalSegment("<#=prop.Name#>") + "/" + id, getClient(), null);
return new <#=prop.TypeRequestBuilder()#>(getRequestUrlWithAdditionalSegment("<#=prop.ParentPropertyType == null ? prop.Name : prop.ParentPropertyType.Name #>") + "/" + id<# if(prop.ParentPropertyType != null) { #> + "/<#=prop.Projection.Type.FullName#>"<# } #>, getClient(), null);
}
<#
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ if (c.AsOdcmClass() != null)
if (prop.IsCollection()) {
#>
public <#=prop.ITypeCollectionRequestBuilder()#> <#=prop.Name#>() {
return new <#=prop.TypeCollectionRequestBuilder()#>(getRequestUrlWithAdditionalSegment("<#=prop.Name#>"), getClient(), null);
return new <#=prop.TypeCollectionRequestBuilder()#>(getRequestUrlWithAdditionalSegment("<#=prop.ParentPropertyType == null ? prop.Name : prop.ParentPropertyType.Name #>")<# if(prop.ParentPropertyType != null) { #> + "/<#=prop.Projection.Type.FullName#>"<# } #>, getClient(), null);
}

public <#=prop.ITypeRequestBuilder()#> <#=prop.Name#>(final String id) {
return new <#=prop.TypeRequestBuilder()#>(getRequestUrlWithAdditionalSegment("<#=prop.Name#>") + "/" + id, getClient(), null);
return new <#=prop.TypeRequestBuilder()#>(getRequestUrlWithAdditionalSegment("<#=prop.ParentPropertyType == null ? prop.Name : prop.ParentPropertyType.Name #>") + "/" + id<# if(prop.ParentPropertyType != null) { #> + "/<#=prop.Projection.Type.FullName#>"<# } #>, getClient(), null);
}
<#
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ if(m != null && m.IsComposable && m.ReturnType != null && m.ReturnType is OdcmCl
if (prop.IsCollection()) {
#>
public <#=prop.ITypeCollectionRequestBuilder()#> <#=sanitizedProperty#>() {
return new <#=prop.TypeCollectionRequestBuilder()#>(getRequestUrlWithAdditionalSegment("<#=prop.Name#>"), getClient(), null);
return new <#=prop.TypeCollectionRequestBuilder()#>(getRequestUrlWithAdditionalSegment("<#=prop.ParentPropertyType == null ? prop.Name : prop.ParentPropertyType.Name #>")<# if(prop.ParentPropertyType != null) { #> + "/<#=prop.Projection.Type.FullName#>"<# } #>, getClient(), null);
}

public <#=prop.ITypeRequestBuilder()#> <#=sanitizedProperty#>(final String id) {
return new <#=prop.TypeRequestBuilder()#>(getRequestUrlWithAdditionalSegment("<#=prop.Name#>") + "/" + id, getClient(), null);
return new <#=prop.TypeRequestBuilder()#>(getRequestUrlWithAdditionalSegment("<#=prop.ParentPropertyType == null ? prop.Name : prop.ParentPropertyType.Name #>") + "/" + id<# if(prop.ParentPropertyType != null) { #> + "/<#=prop.Projection.Type.FullName#>"<# } #>, getClient(), null);
}
<#
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ import <#=mainNamespace#>.<#=c.GetPackagePrefix()#>.<#=c.TypeName()#>;

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

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

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

<# } #>
<# if (c.GetFeatures().CanSelect) { #>
<#=c.ITypeCollectionReferenceRequest()#> select(final String value);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,6 @@ import <#=importNamespace#>.http.IHttpRequest;
*
* @return the updated request
*/
<#=c.ITypeCollectionRequest()#> skipToken(String skipToken);
<#=c.ITypeCollectionRequest()#> skipToken(final String skipToken);
}
<#=PostProcess(c.ITypeCollectionRequest())#>
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ import <#=importNamespace#>.http.IHttpRequest;
* Creates the request
*
* @param requestOptions the options for this request
* @return the IUserRequest instance
* @return the <#=c.ITypeCollectionWithReferencesRequest()#> instance
*/
<#=c.ITypeCollectionWithReferencesRequest()#> buildRequest(final com.microsoft.graph.options.Option... requestOptions);

/**
* Creates the request
*
* @param requestOptions the options for this request
* @return the IUserRequest instance
* @return the <#=c.ITypeCollectionWithReferencesRequest()#> instance
*/
<#=c.ITypeCollectionWithReferencesRequest()#> buildRequest(final java.util.List<? extends <#=importNamespace#>.options.Option> requestOptions);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@ public static string CreatePackageDefForEntity(this CustomT4Host host)
var importFormat = @"import {0}.{1}.{2};";
Dictionary<string, int> uniqueStore = new Dictionary<string, int>();

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

if (properties != null)
{
foreach (var property in properties.Where(p => p.IsCollection() && p.IsNavigation()))
foreach (var property in properties.Where(p => p.IsCollection() && p.IsNavigation() && p.ParentPropertyType == null))
{
if (property.Type is OdcmPrimitiveType)
continue;
Expand Down Expand Up @@ -1200,13 +1200,13 @@ public static string CreatePackageDef(this CustomT4Host host)
?.ToList()
?.ForEach(x => methodImports.Add(x));
c?.NavigationProperties()
?.Where(x => x.IsCollection)?
?.Where(x => x.IsCollection && x.ParentPropertyType == null)?
.Select(x => x.Projection.Type)
?.Distinct()
?.ToList()
?.ForEach(x => ImportRequestBuilderTypes(host, x, methodImports, importFormat, interfaceTemplatePrefix, true));
c?.NavigationProperties()
?.Where(x => !x.IsCollection)
?.Where(x => !x.IsCollection && x.ParentPropertyType == null)
?.Select(x => x.Projection.Type)
?.Distinct()
?.ToList()
Expand Down Expand Up @@ -1336,7 +1336,7 @@ public static string UpdatePropertiesWithinSetRawObject(IEnumerable<OdcmProperty
var sb = new StringBuilder();
if (!isComplexType && properties != null)
{
foreach (var property in properties.Where(p => p.IsCollection() && p.IsNavigation()))
foreach (var property in properties.Where(p => p.IsCollection() && p.IsNavigation() && p.ParentPropertyType == null))
{
sb.AppendFormat(
@"
Expand Down Expand Up @@ -1429,7 +1429,7 @@ public static string CreatePropertyDef(IEnumerable<OdcmProperty> properties, boo

";

foreach (var property in properties.Where(p => !p.Projection.Type.Name.Equals("Stream")))
foreach (var property in properties.Where(p => !p.Projection.Type.Name.Equals("Stream") && p.ParentPropertyType == null))
{
var propertyName = property.Name.ToUpperFirstChar();
var propertyType = "";
Expand Down
10 changes: 5 additions & 5 deletions src/GraphODataTemplateWriter/Extensions/OdcmModelExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,18 +257,18 @@ public static OdcmProperty GetServiceCollectionNavigationPropertyForPropertyType
@namespace
.Classes
.Where(odcmClass => odcmClass.Kind == OdcmClassKind.Service)
.First()
.Properties
.Where(property => property.GetType() == typeof(OdcmSingleton)) //Get the list of singletons defined by the service
.Where(singleton => singleton
.FirstOrDefault()
?.Properties
?.Where(property => property.GetType() == typeof(OdcmSingleton)) //Get the list of singletons defined by the service
?.Where(singleton => singleton
.Type
.AsOdcmClass()
.Properties
//Find navigation properties on the singleton that are self-contained (implicit EntitySets) that match the type
//we are searching for
.Where(prop => prop.ContainsTarget == true && prop.Type.Name == odcmProperty.Type.Name)
.FirstOrDefault() != null
)
) ?? new OdcmProperty[] { }
).FirstOrDefault();

if (implicitProperty != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<HintPath>..\..\packages\Mono.TextTemplating.1.0.0\lib\Mono.TextTemplating.dll</HintPath>
</Reference>
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\..\packages\NLog.4.5.7\lib\net45\NLog.dll</HintPath>
<HintPath>..\..\packages\NLog.4.7.5\lib\net45\NLog.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
Expand Down
2 changes: 1 addition & 1 deletion src/GraphODataTemplateWriter/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<packages>
<package id="Inflector" version="1.0.0.0" targetFramework="net45" />
<package id="Mono.TextTemplating" version="1.0.0" targetFramework="net45" />
<package id="NLog" version="4.5.7" targetFramework="net472" />
<package id="NLog" version="4.7.5" targetFramework="net472" />
<package id="NLog.Config" version="4.4.11" targetFramework="net45" />
<package id="NLog.Schema" version="4.4.11" targetFramework="net45" />
</packages>
5 changes: 4 additions & 1 deletion src/Typewriter/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,10 @@ static private IEnumerable<TextFile> MetadataToClientSource(string edmxString, s
if (String.IsNullOrEmpty(edmxString))
throw new ArgumentNullException("edmxString", "The EDMX file string contains no content.");

var reader = new OdcmReader();
var reader = new OdcmReader
{
AddCastPropertiesForNavigationProperties = targetLanguage.Equals("java", StringComparison.InvariantCultureIgnoreCase)
};
var writer = new TemplateWriter(targetLanguage, properties, endpointVersion);
writer.SetConfigurationProvider(new ConfigurationProvider());

Expand Down
2 changes: 1 addition & 1 deletion src/Typewriter/Typewriter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
<Version>4.0.1</Version>
</PackageReference>
<PackageReference Include="NLog">
<Version>4.5.7</Version>
<Version>4.7.5</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
19 changes: 19 additions & 0 deletions test/Typewriter.Test/Metadata/MetadataMultipleNamespaces.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,25 @@
<NavigationProperty Name="testInvalidNav" Type="graph.entityType2" />
<NavigationProperty Name="testExplicitNav" Type="graph.entityType3" />
</EntityType>
<EntityType Name="directoryObject" BaseType="graph.entity" OpenType="true">
<Property Name="deletedDateTime" Type="Edm.DateTimeOffset" />
</EntityType>
<EntityType Name="user" BaseType="graph.directoryObject" OpenType="true">
<Property Name="accountEnabled" Type="Edm.Boolean">
<Annotation Term="Org.OData.Core.V1.Description" String="true if the account is enabled; otherwise, false. This property is required when a user is created. Supports $filter." />
</Property>
</EntityType>
<EntityType Name="group" BaseType="graph.directoryObject" OpenType="true">
<NavigationProperty Name="members" Type="Collection(graph.directoryObject)">
<Annotation Term="Org.OData.Core.V1.Description" String="Users and groups that are members of this Adminsitrative Unit. HTTP Methods: GET (list members), POST (add members), DELETE (remove members)." />
<Annotation Term="Org.OData.Validation.V1.DerivedTypeConstraint">
<Collection>
<String>microsoft.graph.user</String>
<String>microsoft.graph.group</String>
</Collection>
</Annotation>
</NavigationProperty>
</EntityType>
<!--Colliding with endpoint in callRecords namespace-->
<EntityType Name="endpoint" BaseType="graph.entity">
<Property Name="property1" Type="Edm.Int64" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// ------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
// ------------------------------------------------------------------------------

package com.microsoft.graph.models.extensions;
import com.microsoft.graph.serializer.ISerializer;
import com.microsoft.graph.serializer.IJsonBackedObject;
import com.microsoft.graph.serializer.AdditionalDataManager;
import java.util.EnumSet;
import com.microsoft.graph.models.extensions.Entity;


import com.google.gson.JsonObject;
import com.google.gson.annotations.SerializedName;
import com.google.gson.annotations.Expose;

// **NOTE** This file was generated by a tool and any changes will be overwritten.

/**
* The class for the Directory Object.
*/
public class DirectoryObject extends Entity implements IJsonBackedObject {


/**
* The Deleted Date Time.
*
*/
@SerializedName("deletedDateTime")
@Expose
public java.util.Calendar deletedDateTime;


/**
* The raw representation of this class
*/
private JsonObject rawObject;

/**
* The serializer
*/
private ISerializer serializer;

/**
* Gets the raw representation of this class
*
* @return the raw representation of this class
*/
public JsonObject getRawObject() {
return rawObject;
}

/**
* Gets serializer
*
* @return the serializer
*/
protected ISerializer getSerializer() {
return serializer;
}

/**
* Sets the raw JSON object
*
* @param serializer the serializer
* @param json the JSON object to set this object to
*/
public void setRawObject(final ISerializer serializer, final JsonObject json) {
this.serializer = serializer;
rawObject = json;

}
}
Loading