Skip to content

Commit e5a1ec6

Browse files
committed
json2puml 2.0.18.70
- Updated / fixed logic how to calculate characteristics
1 parent 12ba856 commit e5a1ec6

14 files changed

+1912
-1488
lines changed

source/json2puml.dproj

Lines changed: 202 additions & 301 deletions
Large diffs are not rendered by default.

source/json2puml.res

0 Bytes
Binary file not shown.

source/json2pumlapps.dsk

Lines changed: 126 additions & 143 deletions
Large diffs are not rendered by default.

source/json2pumlbasedefinition.pas

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ tJson2PumlBaseObject = class(tPersistent)
7171
function GetIdent: string; virtual; abstract;
7272
function GetIsFilled: boolean; virtual;
7373
function GetIsValid: boolean; virtual;
74-
function JsonAttributeValue (iPropertyName, iValue: string): string;
74+
function JsonAttributeValue(iPropertyName, iValue: string; iValueQuotes: Boolean = true): string;
7575
function JsonAttributeValueList (iPropertyName: string; iValueList: TStringList): string;
7676
function JsonPropertyName (iPropertyName: string): string;
7777
function MergeValue (iValue, iNewValue: string): string;
@@ -372,12 +372,12 @@ function tJson2PumlBaseObject.GetIsValid: boolean;
372372
Result := IsFilled;
373373
end;
374374

375-
function tJson2PumlBaseObject.JsonAttributeValue (iPropertyName, iValue: string): string;
375+
function tJson2PumlBaseObject.JsonAttributeValue(iPropertyName, iValue: string; iValueQuotes: Boolean = true): string;
376376
begin
377377
Result := '';
378378
if iPropertyName.IsEmpty or iValue.IsEmpty then
379379
exit;
380-
Result := Format ('%s, ', [JsonPropertyNameValue(iPropertyName, iValue)]);
380+
Result := Format ('%s, ', [JsonPropertyNameValue(iPropertyName, iValue, iValueQuotes)]);
381381
end;
382382

383383
function tJson2PumlBaseObject.JsonAttributeValueList (iPropertyName: string; iValueList: TStringList): string;

source/json2pumlconst.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ interface
7676

7777
cNewLinePuml = '\n';
7878

79-
cCurrentVersion = '2.0.17.69';
79+
cCurrentVersion = '2.0.18.70';
8080

8181
JSON2PUML_EVENTTYPENAMES: TEventTypeNames = ['', 'INFO ', 'SUCCESS ', 'WARNING ', 'ERROR ', 'CRITICAL',
8282
'EXCEPT ', 'DEBUG ', 'TRACE ', 'DONE ', 'CUSTOM1 ', 'CUSTOM2 '];

source/json2pumlconverter.pas

Lines changed: 88 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,13 @@ tJson2PumlRecursionRecord = record
4949
ParentIsRelationship: Boolean;
5050
StopRecursion: Boolean;
5151
Level: Integer;
52+
ArrayIndex: Integer;
5253
ObjectLevel: Integer;
5354
CharacteristicParentPropertyName: string;
5455
CharacteristicObject: tPumlCharacteristicObject;
55-
procedure Init(iLeadingObject: string);
56+
CharacteristicValue: tPumlCharacteristicValue;
57+
CharacteristicRecord: tPumlCharacteristicRecord;
58+
procedure Init (iLeadingObject: string);
5659
function GetParentObjectType: string;
5760
function GetInCharacteristicMode: Boolean;
5861
function GetCurrentCharacteristicDefinition: tJson2PumlCharacteristicDefinition;
@@ -150,9 +153,11 @@ procedure TJson2PumlConverter.BuildObjectRelationships (iHierarchieParentObject,
150153
ArrowFormat: string;
151154
GroupFromCondition, GroupToCondition, ArrowCondition: string;
152155
begin
153-
GroupObjectTo:= Definition.IsGroupProperty (iPumlObject.ObjectType, iHierarchieParentObject.ObjectType, '', GroupFromCondition);
154-
//GroupObjectFrom := Definition.IsGroupProperty (iHierarchieParentObject.ObjectType, iPumlObject.ObjectType, '', GroupToCondition);
155-
GroupObjectFrom := Definition.IsGroupProperty (iPumlObject.ObjectType, iHierarchieParentObject.ObjectType, '', GroupFromCondition);
156+
GroupObjectTo := Definition.IsGroupProperty (iPumlObject.ObjectType, iHierarchieParentObject.ObjectType, '',
157+
GroupFromCondition);
158+
// GroupObjectFrom := Definition.IsGroupProperty (iHierarchieParentObject.ObjectType, iPumlObject.ObjectType, '', GroupToCondition);
159+
GroupObjectFrom := Definition.IsGroupProperty (iPumlObject.ObjectType, iHierarchieParentObject.ObjectType, '',
160+
GroupFromCondition);
156161
ArrowFormat := Definition.RelationshipTypeArrowFormats.GetFormat (iPumlObject.ObjectType, iRelationshipProperty,
157162
iRelationshipType, ArrowCondition);
158163
added := iHierarchieParentObject.addRelationship (iRelationshipProperty, iRelationshipType, iRelationshipTypeProperty,
@@ -213,17 +218,17 @@ procedure TJson2PumlConverter.ConvertArray (iJsonArray: TJSONArray; iInfo: tJson
213218
begin
214219
if not Assigned (iJsonArray) then
215220
Exit;
216-
for i := 0 to iJsonArray.Count - 1 do
217-
begin
218-
SaveRecursionRecord := IncRecursionRecord (iInfo, trpArray);
219-
try
220-
if iInfo.CurrentCharacteristicType = jctList then
221-
iInfo.CharacteristicParentPropertyName :=
222-
Format ('%s[%s]', [iInfo.CharacteristicParentPropertyName, (i + 1).ToString.PadLeft((i mod 10) + 1)]);
221+
SaveRecursionRecord := IncRecursionRecord (iInfo, trpArray);
222+
try
223+
for i := 0 to iJsonArray.Count - 1 do
224+
begin
225+
iInfo.ArrayIndex := i;
226+
if iInfo.InCharacteristicMode then
227+
iInfo.CharacteristicRecord := iInfo.CharacteristicValue.AddDetailRecord (i);
223228
ConvertValue (iJsonArray.Items[i], iInfo, trpArray);
224-
finally
225-
DecRecursionRecord (iInfo, SaveRecursionRecord, trpArray);
226229
end;
230+
finally
231+
DecRecursionRecord (iInfo, SaveRecursionRecord, trpArray);
227232
end;
228233
end;
229234

@@ -435,11 +440,22 @@ procedure TJson2PumlConverter.ConvertObject (iJsonObject: TJsonObject; iInfo: tJ
435440
RelationshipType := '';
436441
RelationshipTypeProperty := '';
437442
end;
438-
if IsCharacteristic and not IsObjectDetail then
439-
begin
440-
iInfo.CharacteristicParentPropertyName := '';
441-
iInfo.CharacteristicObject := iInfo.ParentObject.AddCharacteristic (iInfo.PropertyName, CharacteristicDefinition);
442-
end;
443+
if not IsObjectDetail then
444+
if IsCharacteristic then
445+
begin
446+
iInfo.CharacteristicParentPropertyName := '';
447+
iInfo.CharacteristicObject := iInfo.ParentObject.AddCharacteristic (iInfo.PropertyName,
448+
CharacteristicDefinition);
449+
iInfo.CharacteristicValue := iInfo.CharacteristicObject;
450+
iInfo.CharacteristicRecord := iInfo.CharacteristicValue.AddDetailRecord (iInfo.ArrayIndex);
451+
end
452+
else if iInfo.InCharacteristicMode then
453+
begin
454+
// iInfo.CharacteristicValue := iInfo.CharacteristicRecord.AddValue (iInfo.PropertyName, '');
455+
// iInfo.CharacteristicRecord := iInfo.CharacteristicValue.AddDetailRecord (iInfo.ArrayIndex);
456+
iInfo.CharacteristicParentPropertyName :=
457+
string.join ('.', [iInfo.CharacteristicParentPropertyName, iInfo.PropertyName]).TrimLeft (['.']);
458+
end;
443459
if Assigned (PumlObject) then
444460
begin
445461
if not ObjectIdent.IsEmpty then
@@ -461,15 +477,13 @@ procedure TJson2PumlConverter.ConvertObject (iJsonObject: TJsonObject; iInfo: tJ
461477
iInfo.ParentRelationshipType := RelationshipType;
462478
iInfo.ParentRelationShipTypeProperty := RelationshipTypeProperty;
463479
iInfo.ParentIsRelationship := IsRelationShip;
464-
if iInfo.InCharacteristicMode and not IsCharacteristic then
465-
iInfo.CharacteristicParentPropertyName :=
466-
string.join ('.', [iInfo.CharacteristicParentPropertyName, iInfo.PropertyName]).TrimLeft (['.']);
467480
iInfo.ParentPropertyName := iInfo.PropertyName;
468481
if Definition.ContinueAfterUnhandledObjects or (iInfo.CurrentCharacteristicType = jctrecord) then
469482
iInfo.StopRecursion := false
470483
else
471484
iInfo.StopRecursion := (not (Assigned(PumlObject) or IsObjectDetail or IsRelationShip) and
472485
Assigned(iInfo.HierarchieParentObject)) or (iInfo.CurrentCharacteristicType = jctList);
486+
iInfo.ArrayIndex := - 1;
473487
for i := 0 to iJsonObject.Count - 1 do
474488
begin
475489
cName := iJsonObject.Pairs[i].JsonString.Value;
@@ -483,8 +497,6 @@ procedure TJson2PumlConverter.ConvertObject (iJsonObject: TJsonObject; iInfo: tJ
483497
AddFileLog ('Stop property handling, property [%s.%s] is hidden %s',
484498
[iInfo.ParentPropertyName, cName, FoundCondition]);
485499
end;
486-
if iInfo.CurrentCharacteristicType = jctList then
487-
iInfo.CharacteristicObject.AddRecord;
488500
finally
489501
DecRecursionRecord (iInfo, SaveRecursionRecord, trpObject);
490502
end;
@@ -501,17 +513,62 @@ procedure TJson2PumlConverter.ConvertValue (iJsonValue: TJSONValue; iInfo: tJson
501513
IsRelationShip: Boolean;
502514
LogMessage: string;
503515
FoundCondition: string;
516+
ValuePropertyName: string;
517+
518+
function IsCharacteristicPropertyAllowed (iPropertyName, iParentPropertyName: string;
519+
var oFoundCondition: string): Boolean;
520+
begin
521+
Result := iInfo.CurrentCharacteristicDefinition.IsPropertyAllowed (iPropertyName, iParentPropertyName,
522+
oFoundCondition);
523+
if Result then
524+
AddFileLog ('characteristic property [%s] found %s', [iPropertyName, oFoundCondition])
525+
else
526+
AddFileLog ('property [%s] not allowed and skipped %s', [iPropertyName, oFoundCondition]);
527+
end;
528+
504529
begin
505530
if not Assigned (iJsonValue) then
506531
Exit;
532+
if iInfo.InCharacteristicMode then
533+
if iRecursionParent = trpArray then
534+
ValuePropertyName := Format ('[%d]', [iInfo.ArrayIndex])
535+
else
536+
ValuePropertyName := iInfo.PropertyName
537+
else
538+
ValuePropertyName := '';
507539
SaveRecursionRecord := IncRecursionRecord (iInfo, trpValue);
508540
try
509541
if iJsonValue is TJSONArray then
510-
ConvertArray (iJsonValue as TJSONArray, iInfo)
542+
begin
543+
if iInfo.InCharacteristicMode then
544+
begin
545+
if IsCharacteristicPropertyAllowed (ValuePropertyName, iInfo.CharacteristicParentPropertyName, FoundCondition)
546+
then
547+
begin
548+
iInfo.CharacteristicValue := iInfo.CharacteristicRecord.AddValue (ValuePropertyName, '');
549+
ConvertArray (iJsonValue as TJSONArray, iInfo);
550+
end;
551+
end
552+
else
553+
ConvertArray (iJsonValue as TJSONArray, iInfo);
554+
end
511555
else if iJsonValue is TJsonObject then
512556
begin
513557
if not iInfo.StopRecursion then
514-
ConvertObject (iJsonValue as TJsonObject, iInfo)
558+
begin
559+
if iInfo.InCharacteristicMode then
560+
begin
561+
if IsCharacteristicPropertyAllowed (ValuePropertyName, iInfo.CharacteristicParentPropertyName, FoundCondition)
562+
then
563+
begin
564+
iInfo.CharacteristicValue := iInfo.CharacteristicRecord.AddValue (ValuePropertyName, '');
565+
iInfo.CharacteristicRecord := iInfo.CharacteristicValue.AddDetailRecord ( - 1);
566+
ConvertObject (iJsonValue as TJsonObject, iInfo)
567+
end;
568+
end
569+
else
570+
ConvertObject (iJsonValue as TJsonObject, iInfo)
571+
end;
515572
end
516573
else if IsJsonSimple (iJsonValue) then
517574
begin
@@ -546,16 +603,11 @@ procedure TJson2PumlConverter.ConvertValue (iJsonValue: TJSONValue; iInfo: tJson
546603
begin
547604
if iInfo.InCharacteristicMode then
548605
begin
549-
if iInfo.CurrentCharacteristicDefinition.IsPropertyAllowed (iInfo.PropertyName,
550-
iInfo.CharacteristicParentPropertyName, FoundCondition) then
606+
if IsCharacteristicPropertyAllowed (ValuePropertyName, iInfo.CharacteristicParentPropertyName,
607+
FoundCondition) then
551608
begin
552-
iInfo.CharacteristicObject.AddRecordProperty (iInfo.PropertyName, Value,
553-
iInfo.CharacteristicParentPropertyName);
554-
AddFileLog ('characteristic property [%s] value [%s] found %s',
555-
[iInfo.PropertyName, Value, FoundCondition]);
609+
iInfo.CharacteristicValue := iInfo.CharacteristicRecord.AddValue (ValuePropertyName, Value);
556610
end
557-
else
558-
AddFileLog ('property [%s] not allowed and skipped %s', [iInfo.PropertyName, FoundCondition]);
559611
end
560612
else
561613
begin
@@ -831,7 +883,7 @@ function TJson2PumlConverter.Convert: Boolean;
831883
[InputHandlerRecord.InputFile.OutputFileName])
832884
else
833885
begin
834-
InfoRec.Init(LeadingObject);
886+
InfoRec.Init (LeadingObject);
835887
ConvertValue (jValue, InfoRec, trpStart);
836888
GeneratePuml;
837889
Result := true;
@@ -986,7 +1038,7 @@ function tJson2PumlRecursionParentHelper.OperationName: string;
9861038
Result := cJson2PumlRecursionParentFunction[self];
9871039
end;
9881040

989-
procedure tJson2PumlRecursionRecord.Init(iLeadingObject: string);
1041+
procedure tJson2PumlRecursionRecord.Init (iLeadingObject: string);
9901042
begin
9911043
ParentObject := nil;
9921044
HierarchieParentObject := nil;
@@ -1000,6 +1052,7 @@ procedure tJson2PumlRecursionRecord.Init(iLeadingObject: string);
10001052
StopRecursion := false;
10011053
Level := 0;
10021054
ObjectLevel := 0;
1055+
ArrayIndex := - 1;
10031056
CharacteristicParentPropertyName := '';
10041057
CharacteristicObject := nil;
10051058
end;

source/json2pumlconverterdefinition.pas

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ tJson2PumlSingleFormatDefinition = class(tJson2PumlBaseObject)
170170
procedure SetShowCharacteristicsStr (const Value: string);
171171
procedure SetShowFromRelationsStr (const Value: string);
172172
procedure SetShowIfEmptyStr (const Value: string);
173-
procedure SetShowNullValuesStr(const Value: string);
173+
procedure SetShowNullValuesStr (const Value: string);
174174
procedure SetShowToRelationsStr (const Value: string);
175175
procedure SetSkinParams (const Value: tStringList);
176176
protected
@@ -291,6 +291,7 @@ tJson2PumlCharacteristicDefinition = class(tJson2PumlBaseObject)
291291
iWriteEmpty: boolean = false); override;
292292
published
293293
function IsPropertyAllowed (iPropertyName, iParentPropertyName: string; var oFoundCondition: string): boolean;
294+
procedure SortUsedColumnsByPropertyList (iUsedColumns: tStringList);
294295
property CharacteristicType: tJson2PumlCharacteristicType read FCharacteristicType write FCharacteristicType
295296
default jctList;
296297
property IncludeIndex: boolean read GetIncludeIndex;
@@ -1028,7 +1029,8 @@ procedure tJson2PumlConverterDefinition.WriteToJson (oJsonOutPut: TStrings; iPro
10281029

10291030
WriteToJsonValue (oJsonOutPut, 'continueAfterUnhandledObjects', ContinueAfterUnhandledObjectsStr, Level + 1,
10301031
WriteEmpty, false);
1031-
WriteToJsonValue (oJsonOutPut, 'groupDetailObjectsTogether', GroupDetailObjectsTogetherStr, Level + 1, WriteEmpty, false);
1032+
WriteToJsonValue (oJsonOutPut, 'groupDetailObjectsTogether', GroupDetailObjectsTogetherStr, Level + 1,
1033+
WriteEmpty, false);
10321034
WriteToJsonValue (oJsonOutPut, 'hideDuplicateRelations', HideDuplicateRelationsStr, Level + 1, WriteEmpty, false);
10331035
WriteToJsonValue (oJsonOutPut, 'identifyObjectsByTypeAndIdent', IdentifyObjectsByTypeAndIdentStr, Level + 1,
10341036
WriteEmpty, false);
@@ -1452,8 +1454,9 @@ function tJson2PumlSingleFormatDefinition.GetIsFilled: boolean;
14521454
Result := not CaptionShowIdentStr.IsEmpty or not CaptionShowTitleStr.IsEmpty or not CaptionShowTypeStr.IsEmpty or
14531455
not CaptionSplitCharacter.IsEmpty or not CaptionSplitLengthStr.IsEmpty or not IconColor.IsEmpty or
14541456
not (ObjectFilter.Count > 0) or not ShowAttributesStr.IsEmpty or not ShowCharacteristicsStr.IsEmpty or
1455-
not ShowIfEmptyStr.IsEmpty or not ShowFromRelationsStr.IsEmpty or not ShowNullValuesStr.IsEmpty or not ShowToRelationsStr.IsEmpty or
1456-
not SortAttributesStr.IsEmpty or (SkinParams.Count > 0) or not ValueSplitLengthStr.IsEmpty;
1457+
not ShowIfEmptyStr.IsEmpty or not ShowFromRelationsStr.IsEmpty or not ShowNullValuesStr.IsEmpty or
1458+
not ShowToRelationsStr.IsEmpty or not SortAttributesStr.IsEmpty or (SkinParams.Count > 0) or
1459+
not ValueSplitLengthStr.IsEmpty;
14571460
end;
14581461

14591462
function tJson2PumlSingleFormatDefinition.GetShowNullValues: boolean;
@@ -1567,7 +1570,7 @@ procedure tJson2PumlSingleFormatDefinition.SetShowIfEmptyStr (const Value: strin
15671570
FShowIfEmptyStr := ValidateBooleanInput (Value);
15681571
end;
15691572

1570-
procedure tJson2PumlSingleFormatDefinition.SetShowNullValuesStr(const Value: string);
1573+
procedure tJson2PumlSingleFormatDefinition.SetShowNullValuesStr (const Value: string);
15711574
begin
15721575
FShowNullValuesStr := ValidateBooleanInput (Value);
15731576
end;
@@ -2090,6 +2093,24 @@ procedure tJson2PumlCharacteristicDefinition.SetIncludeIndexStr (const Value: st
20902093
FIncludeIndexStr := ValidateBooleanInput (Value);
20912094
end;
20922095

2096+
procedure tJson2PumlCharacteristicDefinition.SortUsedColumnsByPropertyList (iUsedColumns: tStringList);
2097+
var
2098+
i: Integer;
2099+
col: string;
2100+
j : Integer;
2101+
begin
2102+
i := 0;
2103+
for col in PropertyList do
2104+
begin
2105+
j := iUsedColumns.IndexOf(col);
2106+
if j >= 0 then
2107+
begin
2108+
iUsedColumns.Move(j, i);
2109+
inc (i);
2110+
end;
2111+
end;
2112+
end;
2113+
20932114
procedure tJson2PumlCharacteristicDefinition.WriteToJson (oJsonOutPut: TStrings; iPropertyName: string; iLevel: Integer;
20942115
iWriteEmpty: boolean = false);
20952116
var
@@ -2105,7 +2126,7 @@ procedure tJson2PumlCharacteristicDefinition.WriteToJson (oJsonOutPut: TStrings;
21052126
else
21062127
Value := JsonAttributeValue ('parentProperty', ParentProperty) + JsonAttributeValue ('type',
21072128
CharacteristicType.ToString) + JsonAttributeValueList ('propertyList', PropertyList) +
2108-
JsonAttributeValue ('includeIndex', IncludeIndexStr);
2129+
JsonAttributeValue ('includeIndex', IncludeIndexStr, false);
21092130
if IsRecord then
21102131
Value := Format ('{%s}', [Value.trimRight([',', ' '])])
21112132
else

0 commit comments

Comments
 (0)