Skip to content

Commit

Permalink
#152 Renamed generic OpenApi to OpenApiISH30 to allow room for OpenAp…
Browse files Browse the repository at this point in the history
…iAM10, restored all funky conversions from Enumerations,IShFields,IShFolder and IShFolders... it compiles... next Refresh spec json, rename Protocols and get folder to work
  • Loading branch information
ddemeyer committed Dec 29, 2022
1 parent 49fb33b commit 6617ba2
Show file tree
Hide file tree
Showing 14 changed files with 318 additions and 109 deletions.
2 changes: 1 addition & 1 deletion Source/ISHRemote/ISHRemote.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ VisualStudioVersion = 17.0.32802.463
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Trisoft.ISHRemote", "Trisoft.ISHRemote\Trisoft.ISHRemote.csproj", "{A86D41D8-600D-4FF2-BFF6-19C3D26CBB69}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Trisoft.ISHRemote.OpenApi", "Trisoft.ISHRemote.OpenApi\Trisoft.ISHRemote.OpenApi.csproj", "{E7C61499-DDD9-4DBC-B26D-0FE753D8BAAF}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Trisoft.ISHRemote.OpenApiISH30", "Trisoft.ISHRemote.OpenApiISH30\Trisoft.ISHRemote.OpenApiISH30.csproj", "{E7C61499-DDD9-4DBC-B26D-0FE753D8BAAF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
</PropertyGroup>

<ItemGroup>
<None Remove="OpenApi30.json" />
<None Remove="OpenApiISH30.json" />
</ItemGroup>

<ItemGroup>
<OpenApiReference Include="OpenApi30.json">
<OpenApiReference Include="OpenApiISH30.json">
<CodeGenerator>NSwagCSharp</CodeGenerator>
<Namespace>Trisoft.ISHRemote.OpenApi</Namespace>
<ClassName>OpenApi30{controller}Service</ClassName>
<Namespace>Trisoft.ISHRemote.OpenApiISH30</Namespace>
<ClassName>OpenApiISH30{controller}Service</ClassName>
</OpenApiReference>
</ItemGroup>

Expand Down
96 changes: 48 additions & 48 deletions Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/Folder/AddIshFolder.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ private void RetrieveRecursive(IshFolder ishFolder, int currentDepth, int maxDep
case Enumerations.Protocol.OpenApiBasicAuthentication:
// TODO [Must] Add OpenApi implementation
case Enumerations.Protocol.AsmxAuthenticationContext:
xmlIshFolders = IshSession.Folder25.RetrieveMetadataByIshFolderRefs(retrievedFolders.Ids,_requestedMetadata.ToXml());
string xmlIshFolders = IshSession.Folder25.RetrieveMetadataByIshFolderRefs(retrievedFolders.Ids,_requestedMetadata.ToXml());
retrievedFolders = new IshFolders(xmlIshFolders);
break;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,37 @@
/*
* Copyright (c) 2014 All Rights Reserved by the SDL Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using System;
using System.Collections.Generic;
using System.Linq;
using Trisoft.ISHRemote.Objects;
using Trisoft.ISHRemote.Objects.Public;
using Trisoft.ISHRemote.OpenApi;
using Trisoft.ISHRemote.OpenApiISH30;

namespace Trisoft.ISHRemote.ExtensionMethods
{
internal static class IshFieldsExtensionMethods
{
internal static ICollection<SetFieldValue> ToSetFieldValues(this IshFields ishFields, IshSession ishSession )
internal static ICollection<SetFieldValue> ToOpenApiISH30SetFieldValues(this IshFields ishFields, IshSession ishSession)
{
ICollection<SetFieldValue> fieldValues = new List<SetFieldValue>();

foreach(Objects.Public.IshField ishField in ishFields.Fields())
{
SetFieldValue setFieldValue = IshFieldToSetFieldValue(ishField, ishSession, ishFields);
SetFieldValue setFieldValue = IshFieldToOpenApiISH30SetFieldValue(ishField, ishSession, ishFields);
if (setFieldValue != null)
{
fieldValues.Add(setFieldValue);
Expand All @@ -25,57 +41,57 @@ internal static ICollection<SetFieldValue> ToSetFieldValues(this IshFields ishFi
return fieldValues;
}

internal static OpenApi.Level ToOpenApiLevel(this Enumerations.Level level)
internal static OpenApiISH30.Level ToOpenApiISH30Level(this Enumerations.Level level)
{
switch(level)
{
case Enumerations.Level.Annotation:
return OpenApi.Level.Annotation;
return OpenApiISH30.Level.Annotation;

case Enumerations.Level.Data:
return OpenApi.Level.Data;
return OpenApiISH30.Level.Data;

case Enumerations.Level.Detail:
return OpenApi.Level.Detail;
return OpenApiISH30.Level.Detail;

case Enumerations.Level.History:
// TODO
return OpenApi.Level.None;
return OpenApiISH30.Level.None;

case Enumerations.Level.Lng:
return OpenApi.Level.Language;
return OpenApiISH30.Level.Language;

case Enumerations.Level.Logical:
return OpenApi.Level.Logical;
return OpenApiISH30.Level.Logical;

case Enumerations.Level.None:
return OpenApi.Level.None;
return OpenApiISH30.Level.None;

case Enumerations.Level.Progress:
return OpenApi.Level.None;
return OpenApiISH30.Level.None;

case Enumerations.Level.Reply:
return OpenApi.Level.Reply;
return OpenApiISH30.Level.Reply;

case Enumerations.Level.Task:
// TODO
return OpenApi.Level.None;
return OpenApiISH30.Level.None;

case Enumerations.Level.Version:
return OpenApi.Level.Version;
return OpenApiISH30.Level.Version;
}

return OpenApi.Level.None;
return OpenApiISH30.Level.None;
}

private static SetFieldValue IshFieldToSetFieldValue(Objects.Public.IshField ishField, IshSession ishSession, IshFields ishFields)
private static SetFieldValue IshFieldToOpenApiISH30SetFieldValue(Objects.Public.IshField ishField, IshSession ishSession, IshFields ishFields)
{
SetFieldValue setFieldValue = null;
IshTypeFieldDefinition ishTypeFieldDefinition = ishSession.IshTypeFieldDefinition.FirstOrDefault(f => f.Name == ishField.Name && f.Level == ishField.Level);

if (ishTypeFieldDefinition != null)
{
OpenApi.IshField openApiIshField = new OpenApi.IshField() { Level = ishField.Level.ToOpenApiLevel(), Name = ishField.Name, Type = nameof(OpenApi.IshField ) };
OpenApiISH30.IshField openApiIshField = new OpenApiISH30.IshField() { Level = ishField.Level.ToOpenApiISH30Level(), Name = ishField.Name, Type = nameof(OpenApiISH30.IshField ) };

string fieldValue = ishFields.GetFieldValue(ishField.Name, ishField.Level, ishField.ValueType);
// TODO why is the separator on IshSession a string?
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright (c) 2014 All Rights Reserved by the SDL Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static Trisoft.ISHRemote.Objects.Enumerations;

namespace Trisoft.ISHRemote.ExtensionMethods
{
internal static class OpenApiISH30EnumerationsExtensions
{
/// <summary>
/// OpenApi (dd 20211228) implements FieldGroup as derived from ISHRemote RequestedMetadataGroup, should be 1-1 conversion to server-side decide which fields to retrieve
/// </summary>
internal static OpenApiISH30.FieldGroup ToOpenApiISH30FieldGroup(this RequestedMetadataGroup requestedMetadataGroup)
{
switch (requestedMetadataGroup)
{
case RequestedMetadataGroup.All:
return OpenApiISH30.FieldGroup.All;
case RequestedMetadataGroup.Basic:
return OpenApiISH30.FieldGroup.Basic;
case RequestedMetadataGroup.Descriptive:
default:
return OpenApiISH30.FieldGroup.Descriptive;
}

}

/// <summary>
/// OpenApi (dd 20211228) implements Field Level, needs mapping to ISHRemote levels
/// </summary>
internal static Level ToISHFieldLevel(this OpenApiISH30.Level oLevel)
{
switch (oLevel)
{
case OpenApiISH30.Level.None:
return Level.None;
case OpenApiISH30.Level.Logical:
return Level.Logical;
case OpenApiISH30.Level.Version:
return Level.Version;
case OpenApiISH30.Level.Language:
return Level.Lng;
case OpenApiISH30.Level.Data:
return Level.Data;
case OpenApiISH30.Level.Annotation:
return Level.Annotation;
case OpenApiISH30.Level.Reply:
return Level.Reply;
case OpenApiISH30.Level.Progress:
return Level.Progress;
case OpenApiISH30.Level.Detail:
return Level.Detail;
case OpenApiISH30.Level.Object:
case OpenApiISH30.Level.Compute:
default:
throw new ArgumentException($"Enumerations.ToFieldLevel OpenApiISH30.Level[{oLevel}] was unexpected.");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,30 +1,46 @@
using System;
/*
* Copyright (c) 2014 All Rights Reserved by the SDL Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using System;
using System.Collections.Generic;
using System.Text;
using Trisoft.ISHRemote.Objects;
using Trisoft.ISHRemote.Objects.Public;

namespace Trisoft.ISHRemote.ExtensionMethods
{
internal static class OpenApiFieldValueExtensions
internal static class OpenApiISH30FieldValueExtensions
{
internal static IshFields ToIshFields(this ICollection<OpenApi.FieldValue> fieldValues, IshSession ishSession)
internal static IshFields ToIshFields(this ICollection<OpenApiISH30.FieldValue> fieldValues, IshSession ishSession)
{
var ishFields = new IshFields();
foreach (var fieldValue in fieldValues)
{
switch (fieldValue.Type)
{
case OpenApi.FieldValueType.CardFieldValue:
case OpenApiISH30.FieldValueType.CardFieldValue:
{
var typedFieldValue = fieldValue as OpenApi.CardFieldValue; // Can I be optimistic or is null-check required after every cast?
ishFields.AddField(new IshMetadataField(typedFieldValue.IshField.Name, Enumerations.ToFieldLevel(typedFieldValue.IshField.Level), Enumerations.ValueType.Value, typedFieldValue.Value.Title));
ishFields.AddField(new IshMetadataField(typedFieldValue.IshField.Name, Enumerations.ToFieldLevel(typedFieldValue.IshField.Level), Enumerations.ValueType.Id, typedFieldValue.Value.Id));
var typedFieldValue = fieldValue as OpenApiISH30.CardFieldValue; // Can I be optimistic or is null-check required after every cast?
ishFields.AddField(new IshMetadataField(typedFieldValue.IshField.Name, typedFieldValue.IshField.Level.ToISHFieldLevel(), Enumerations.ValueType.Value, typedFieldValue.Value.Title));
ishFields.AddField(new IshMetadataField(typedFieldValue.IshField.Name, typedFieldValue.IshField.Level.ToISHFieldLevel(), Enumerations.ValueType.Id, typedFieldValue.Value.Id));
break;
}
case OpenApi.FieldValueType.MultiCardFieldValue:
case OpenApiISH30.FieldValueType.MultiCardFieldValue:
{
var typedFieldValue = fieldValue as OpenApi.MultiCardFieldValue;
var typedFieldValue = fieldValue as OpenApiISH30.MultiCardFieldValue;
StringBuilder values = new StringBuilder();
StringBuilder ids = new StringBuilder();
// TODO [Question] BaseObject offers Title (ahum Value) and Id (probably card_id) but where do I get Element name?
Expand All @@ -35,37 +51,37 @@ internal static IshFields ToIshFields(this ICollection<OpenApi.FieldValue> field
}
ishFields.AddField(new IshMetadataField(
typedFieldValue.IshField.Name,
Enumerations.ToFieldLevel(typedFieldValue.IshField.Level),
typedFieldValue.IshField.Level.ToISHFieldLevel(),
Enumerations.ValueType.Value,
string.Join(ishSession.Separator, values))
);
ishFields.AddField(new IshMetadataField(
typedFieldValue.IshField.Name,
Enumerations.ToFieldLevel(typedFieldValue.IshField.Level),
typedFieldValue.IshField.Level.ToISHFieldLevel(),
Enumerations.ValueType.Id,
string.Join(ishSession.Separator, ids))
);
break;
}
case OpenApi.FieldValueType.DateTimeFieldValue:
case OpenApiISH30.FieldValueType.DateTimeFieldValue:
{
// IShSession should offer date time format string as property
break;
}
case OpenApi.FieldValueType.MultiDateTimeFieldValue:
case OpenApiISH30.FieldValueType.MultiDateTimeFieldValue:
{
break;
}
case OpenApi.FieldValueType.LovFieldValue:
case OpenApiISH30.FieldValueType.LovFieldValue:
{
var typedFieldValue = fieldValue as OpenApi.LovFieldValue;
ishFields.AddField(new IshMetadataField(typedFieldValue.IshField.Name, Enumerations.ToFieldLevel(typedFieldValue.IshField.Level), Enumerations.ValueType.Value, typedFieldValue.Value.Title));
ishFields.AddField(new IshMetadataField(typedFieldValue.IshField.Name, Enumerations.ToFieldLevel(typedFieldValue.IshField.Level), Enumerations.ValueType.Id, typedFieldValue.Value.Id));
var typedFieldValue = fieldValue as OpenApiISH30.LovFieldValue;
ishFields.AddField(new IshMetadataField(typedFieldValue.IshField.Name, typedFieldValue.IshField.Level.ToISHFieldLevel(), Enumerations.ValueType.Value, typedFieldValue.Value.Title));
ishFields.AddField(new IshMetadataField(typedFieldValue.IshField.Name, typedFieldValue.IshField.Level.ToISHFieldLevel(), Enumerations.ValueType.Id, typedFieldValue.Value.Id));
break;
}
case OpenApi.FieldValueType.MultiLovFieldValue:
case OpenApiISH30.FieldValueType.MultiLovFieldValue:
{
var typedFieldValue = fieldValue as OpenApi.MultiLovFieldValue;
var typedFieldValue = fieldValue as OpenApiISH30.MultiLovFieldValue;
StringBuilder values = new StringBuilder();
StringBuilder ids = new StringBuilder();
// TODO [Question] BaseObject offers Title (ahum Value) and Id (probably card_id) but where do I get Element name?
Expand All @@ -76,34 +92,34 @@ internal static IshFields ToIshFields(this ICollection<OpenApi.FieldValue> field
}
ishFields.AddField(new IshMetadataField(
typedFieldValue.IshField.Name,
Enumerations.ToFieldLevel(typedFieldValue.IshField.Level),
typedFieldValue.IshField.Level.ToISHFieldLevel(),
Enumerations.ValueType.Value,
string.Join(ishSession.Separator, values))
);
ishFields.AddField(new IshMetadataField(
typedFieldValue.IshField.Name,
Enumerations.ToFieldLevel(typedFieldValue.IshField.Level),
typedFieldValue.IshField.Level.ToISHFieldLevel(),
Enumerations.ValueType.Id,
string.Join(ishSession.Separator, ids))
);
break;
}
case OpenApi.FieldValueType.NumberFieldValue:
case OpenApiISH30.FieldValueType.NumberFieldValue:
break;
case OpenApi.FieldValueType.MultiNumberFieldValue:
case OpenApiISH30.FieldValueType.MultiNumberFieldValue:
break;
case OpenApi.FieldValueType.StringFieldValue:
case OpenApiISH30.FieldValueType.StringFieldValue:
break;
case OpenApi.FieldValueType.MultiStringFieldValue:
case OpenApiISH30.FieldValueType.MultiStringFieldValue:
break;
case OpenApi.FieldValueType.TagFieldValue:
case OpenApiISH30.FieldValueType.TagFieldValue:
break;
case OpenApi.FieldValueType.MultiTagFieldValue:
case OpenApiISH30.FieldValueType.MultiTagFieldValue:
break;
case OpenApi.FieldValueType.VersionFieldValue:
case OpenApiISH30.FieldValueType.VersionFieldValue:
break;
default:
throw new NotImplementedException($"OpenApiFieldValueExtensions.ToIshFields cannot handle fieldValue.Type[{ fieldValue.Type }]");
throw new NotImplementedException($"OpenApiISH30FieldValueExtensions.ToIshFields cannot handle fieldValue.Type[{ fieldValue.Type }]");
}
}
return ishFields;
Expand Down
Loading

0 comments on commit 6617ba2

Please sign in to comment.