-
Notifications
You must be signed in to change notification settings - Fork 0
/
LinkAnchoredTextDB.go
909 lines (692 loc) · 36.3 KB
/
LinkAnchoredTextDB.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
// generated by stacks/gong/go/models/orm_file_per_struct_back_repo.go
package orm
import (
"database/sql"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
"sort"
"time"
"gorm.io/gorm"
"github.com/tealeg/xlsx/v3"
"github.com/fullstack-lang/gongsvg/go/models"
)
// dummy variable to have the import declaration wihthout compile failure (even if no code needing this import is generated)
var dummy_LinkAnchoredText_sql sql.NullBool
var dummy_LinkAnchoredText_time time.Duration
var dummy_LinkAnchoredText_sort sort.Float64Slice
// LinkAnchoredTextAPI is the input in POST API
//
// for POST, API, one needs the fields of the model as well as the fields
// from associations ("Has One" and "Has Many") that are generated to
// fullfill the ORM requirements for associations
//
// swagger:model linkanchoredtextAPI
type LinkAnchoredTextAPI struct {
gorm.Model
models.LinkAnchoredText_WOP
// encoding of pointers
// for API, it cannot be embedded
LinkAnchoredTextPointersEncoding LinkAnchoredTextPointersEncoding
}
// LinkAnchoredTextPointersEncoding encodes pointers to Struct and
// reverse pointers of slice of poitners to Struct
type LinkAnchoredTextPointersEncoding struct {
// insertion for pointer fields encoding declaration
// field Animates is a slice of pointers to another Struct (optional or 0..1)
Animates IntSlice `gorm:"type:TEXT"`
}
// LinkAnchoredTextDB describes a linkanchoredtext in the database
//
// It incorporates the GORM ID, basic fields from the model (because they can be serialized),
// the encoded version of pointers
//
// swagger:model linkanchoredtextDB
type LinkAnchoredTextDB struct {
gorm.Model
// insertion for basic fields declaration
// Declation for basic field linkanchoredtextDB.Name
Name_Data sql.NullString
// Declation for basic field linkanchoredtextDB.Content
Content_Data sql.NullString
// Declation for basic field linkanchoredtextDB.AutomaticLayout
// provide the sql storage for the boolan
AutomaticLayout_Data sql.NullBool
// Declation for basic field linkanchoredtextDB.LinkAnchorType
LinkAnchorType_Data sql.NullString
// Declation for basic field linkanchoredtextDB.X_Offset
X_Offset_Data sql.NullFloat64
// Declation for basic field linkanchoredtextDB.Y_Offset
Y_Offset_Data sql.NullFloat64
// Declation for basic field linkanchoredtextDB.FontWeight
FontWeight_Data sql.NullString
// Declation for basic field linkanchoredtextDB.FontSize
FontSize_Data sql.NullString
// Declation for basic field linkanchoredtextDB.LetterSpacing
LetterSpacing_Data sql.NullString
// Declation for basic field linkanchoredtextDB.Color
Color_Data sql.NullString
// Declation for basic field linkanchoredtextDB.FillOpacity
FillOpacity_Data sql.NullFloat64
// Declation for basic field linkanchoredtextDB.Stroke
Stroke_Data sql.NullString
// Declation for basic field linkanchoredtextDB.StrokeOpacity
StrokeOpacity_Data sql.NullFloat64
// Declation for basic field linkanchoredtextDB.StrokeWidth
StrokeWidth_Data sql.NullFloat64
// Declation for basic field linkanchoredtextDB.StrokeDashArray
StrokeDashArray_Data sql.NullString
// Declation for basic field linkanchoredtextDB.StrokeDashArrayWhenSelected
StrokeDashArrayWhenSelected_Data sql.NullString
// Declation for basic field linkanchoredtextDB.Transform
Transform_Data sql.NullString
// encoding of pointers
// for GORM serialization, it is necessary to embed to Pointer Encoding declaration
LinkAnchoredTextPointersEncoding
}
// LinkAnchoredTextDBs arrays linkanchoredtextDBs
// swagger:response linkanchoredtextDBsResponse
type LinkAnchoredTextDBs []LinkAnchoredTextDB
// LinkAnchoredTextDBResponse provides response
// swagger:response linkanchoredtextDBResponse
type LinkAnchoredTextDBResponse struct {
LinkAnchoredTextDB
}
// LinkAnchoredTextWOP is a LinkAnchoredText without pointers (WOP is an acronym for "Without Pointers")
// it holds the same basic fields but pointers are encoded into uint
type LinkAnchoredTextWOP struct {
ID int `xlsx:"0"`
// insertion for WOP basic fields
Name string `xlsx:"1"`
Content string `xlsx:"2"`
AutomaticLayout bool `xlsx:"3"`
LinkAnchorType models.LinkAnchorType `xlsx:"4"`
X_Offset float64 `xlsx:"5"`
Y_Offset float64 `xlsx:"6"`
FontWeight string `xlsx:"7"`
FontSize string `xlsx:"8"`
LetterSpacing string `xlsx:"9"`
Color string `xlsx:"10"`
FillOpacity float64 `xlsx:"11"`
Stroke string `xlsx:"12"`
StrokeOpacity float64 `xlsx:"13"`
StrokeWidth float64 `xlsx:"14"`
StrokeDashArray string `xlsx:"15"`
StrokeDashArrayWhenSelected string `xlsx:"16"`
Transform string `xlsx:"17"`
// insertion for WOP pointer fields
}
var LinkAnchoredText_Fields = []string{
// insertion for WOP basic fields
"ID",
"Name",
"Content",
"AutomaticLayout",
"LinkAnchorType",
"X_Offset",
"Y_Offset",
"FontWeight",
"FontSize",
"LetterSpacing",
"Color",
"FillOpacity",
"Stroke",
"StrokeOpacity",
"StrokeWidth",
"StrokeDashArray",
"StrokeDashArrayWhenSelected",
"Transform",
}
type BackRepoLinkAnchoredTextStruct struct {
// stores LinkAnchoredTextDB according to their gorm ID
Map_LinkAnchoredTextDBID_LinkAnchoredTextDB map[uint]*LinkAnchoredTextDB
// stores LinkAnchoredTextDB ID according to LinkAnchoredText address
Map_LinkAnchoredTextPtr_LinkAnchoredTextDBID map[*models.LinkAnchoredText]uint
// stores LinkAnchoredText according to their gorm ID
Map_LinkAnchoredTextDBID_LinkAnchoredTextPtr map[uint]*models.LinkAnchoredText
db *gorm.DB
stage *models.StageStruct
}
func (backRepoLinkAnchoredText *BackRepoLinkAnchoredTextStruct) GetStage() (stage *models.StageStruct) {
stage = backRepoLinkAnchoredText.stage
return
}
func (backRepoLinkAnchoredText *BackRepoLinkAnchoredTextStruct) GetDB() *gorm.DB {
return backRepoLinkAnchoredText.db
}
// GetLinkAnchoredTextDBFromLinkAnchoredTextPtr is a handy function to access the back repo instance from the stage instance
func (backRepoLinkAnchoredText *BackRepoLinkAnchoredTextStruct) GetLinkAnchoredTextDBFromLinkAnchoredTextPtr(linkanchoredtext *models.LinkAnchoredText) (linkanchoredtextDB *LinkAnchoredTextDB) {
id := backRepoLinkAnchoredText.Map_LinkAnchoredTextPtr_LinkAnchoredTextDBID[linkanchoredtext]
linkanchoredtextDB = backRepoLinkAnchoredText.Map_LinkAnchoredTextDBID_LinkAnchoredTextDB[id]
return
}
// BackRepoLinkAnchoredText.CommitPhaseOne commits all staged instances of LinkAnchoredText to the BackRepo
// Phase One is the creation of instance in the database if it is not yet done to get the unique ID for each staged instance
func (backRepoLinkAnchoredText *BackRepoLinkAnchoredTextStruct) CommitPhaseOne(stage *models.StageStruct) (Error error) {
for linkanchoredtext := range stage.LinkAnchoredTexts {
backRepoLinkAnchoredText.CommitPhaseOneInstance(linkanchoredtext)
}
// parse all backRepo instance and checks wether some instance have been unstaged
// in this case, remove them from the back repo
for id, linkanchoredtext := range backRepoLinkAnchoredText.Map_LinkAnchoredTextDBID_LinkAnchoredTextPtr {
if _, ok := stage.LinkAnchoredTexts[linkanchoredtext]; !ok {
backRepoLinkAnchoredText.CommitDeleteInstance(id)
}
}
return
}
// BackRepoLinkAnchoredText.CommitDeleteInstance commits deletion of LinkAnchoredText to the BackRepo
func (backRepoLinkAnchoredText *BackRepoLinkAnchoredTextStruct) CommitDeleteInstance(id uint) (Error error) {
linkanchoredtext := backRepoLinkAnchoredText.Map_LinkAnchoredTextDBID_LinkAnchoredTextPtr[id]
// linkanchoredtext is not staged anymore, remove linkanchoredtextDB
linkanchoredtextDB := backRepoLinkAnchoredText.Map_LinkAnchoredTextDBID_LinkAnchoredTextDB[id]
query := backRepoLinkAnchoredText.db.Unscoped().Delete(&linkanchoredtextDB)
if query.Error != nil {
log.Fatal(query.Error)
}
// update stores
delete(backRepoLinkAnchoredText.Map_LinkAnchoredTextPtr_LinkAnchoredTextDBID, linkanchoredtext)
delete(backRepoLinkAnchoredText.Map_LinkAnchoredTextDBID_LinkAnchoredTextPtr, id)
delete(backRepoLinkAnchoredText.Map_LinkAnchoredTextDBID_LinkAnchoredTextDB, id)
return
}
// BackRepoLinkAnchoredText.CommitPhaseOneInstance commits linkanchoredtext staged instances of LinkAnchoredText to the BackRepo
// Phase One is the creation of instance in the database if it is not yet done to get the unique ID for each staged instance
func (backRepoLinkAnchoredText *BackRepoLinkAnchoredTextStruct) CommitPhaseOneInstance(linkanchoredtext *models.LinkAnchoredText) (Error error) {
// check if the linkanchoredtext is not commited yet
if _, ok := backRepoLinkAnchoredText.Map_LinkAnchoredTextPtr_LinkAnchoredTextDBID[linkanchoredtext]; ok {
return
}
// initiate linkanchoredtext
var linkanchoredtextDB LinkAnchoredTextDB
linkanchoredtextDB.CopyBasicFieldsFromLinkAnchoredText(linkanchoredtext)
query := backRepoLinkAnchoredText.db.Create(&linkanchoredtextDB)
if query.Error != nil {
log.Fatal(query.Error)
}
// update stores
backRepoLinkAnchoredText.Map_LinkAnchoredTextPtr_LinkAnchoredTextDBID[linkanchoredtext] = linkanchoredtextDB.ID
backRepoLinkAnchoredText.Map_LinkAnchoredTextDBID_LinkAnchoredTextPtr[linkanchoredtextDB.ID] = linkanchoredtext
backRepoLinkAnchoredText.Map_LinkAnchoredTextDBID_LinkAnchoredTextDB[linkanchoredtextDB.ID] = &linkanchoredtextDB
return
}
// BackRepoLinkAnchoredText.CommitPhaseTwo commits all staged instances of LinkAnchoredText to the BackRepo
// Phase Two is the update of instance with the field in the database
func (backRepoLinkAnchoredText *BackRepoLinkAnchoredTextStruct) CommitPhaseTwo(backRepo *BackRepoStruct) (Error error) {
for idx, linkanchoredtext := range backRepoLinkAnchoredText.Map_LinkAnchoredTextDBID_LinkAnchoredTextPtr {
backRepoLinkAnchoredText.CommitPhaseTwoInstance(backRepo, idx, linkanchoredtext)
}
return
}
// BackRepoLinkAnchoredText.CommitPhaseTwoInstance commits {{structname }} of models.LinkAnchoredText to the BackRepo
// Phase Two is the update of instance with the field in the database
func (backRepoLinkAnchoredText *BackRepoLinkAnchoredTextStruct) CommitPhaseTwoInstance(backRepo *BackRepoStruct, idx uint, linkanchoredtext *models.LinkAnchoredText) (Error error) {
// fetch matching linkanchoredtextDB
if linkanchoredtextDB, ok := backRepoLinkAnchoredText.Map_LinkAnchoredTextDBID_LinkAnchoredTextDB[idx]; ok {
linkanchoredtextDB.CopyBasicFieldsFromLinkAnchoredText(linkanchoredtext)
// insertion point for translating pointers encodings into actual pointers
// 1. reset
linkanchoredtextDB.LinkAnchoredTextPointersEncoding.Animates = make([]int, 0)
// 2. encode
for _, animateAssocEnd := range linkanchoredtext.Animates {
animateAssocEnd_DB :=
backRepo.BackRepoAnimate.GetAnimateDBFromAnimatePtr(animateAssocEnd)
// the stage might be inconsistant, meaning that the animateAssocEnd_DB might
// be missing from the stage. In this case, the commit operation is robust
// An alternative would be to crash here to reveal the missing element.
if animateAssocEnd_DB == nil {
continue
}
linkanchoredtextDB.LinkAnchoredTextPointersEncoding.Animates =
append(linkanchoredtextDB.LinkAnchoredTextPointersEncoding.Animates, int(animateAssocEnd_DB.ID))
}
query := backRepoLinkAnchoredText.db.Save(&linkanchoredtextDB)
if query.Error != nil {
log.Fatalln(query.Error)
}
} else {
err := errors.New(
fmt.Sprintf("Unkown LinkAnchoredText intance %s", linkanchoredtext.Name))
return err
}
return
}
// BackRepoLinkAnchoredText.CheckoutPhaseOne Checkouts all BackRepo instances to the Stage
//
// Phase One will result in having instances on the stage aligned with the back repo
// pointers are not initialized yet (this is for phase two)
func (backRepoLinkAnchoredText *BackRepoLinkAnchoredTextStruct) CheckoutPhaseOne() (Error error) {
linkanchoredtextDBArray := make([]LinkAnchoredTextDB, 0)
query := backRepoLinkAnchoredText.db.Find(&linkanchoredtextDBArray)
if query.Error != nil {
return query.Error
}
// list of instances to be removed
// start from the initial map on the stage and remove instances that have been checked out
linkanchoredtextInstancesToBeRemovedFromTheStage := make(map[*models.LinkAnchoredText]any)
for key, value := range backRepoLinkAnchoredText.stage.LinkAnchoredTexts {
linkanchoredtextInstancesToBeRemovedFromTheStage[key] = value
}
// copy orm objects to the the map
for _, linkanchoredtextDB := range linkanchoredtextDBArray {
backRepoLinkAnchoredText.CheckoutPhaseOneInstance(&linkanchoredtextDB)
// do not remove this instance from the stage, therefore
// remove instance from the list of instances to be be removed from the stage
linkanchoredtext, ok := backRepoLinkAnchoredText.Map_LinkAnchoredTextDBID_LinkAnchoredTextPtr[linkanchoredtextDB.ID]
if ok {
delete(linkanchoredtextInstancesToBeRemovedFromTheStage, linkanchoredtext)
}
}
// remove from stage and back repo's 3 maps all linkanchoredtexts that are not in the checkout
for linkanchoredtext := range linkanchoredtextInstancesToBeRemovedFromTheStage {
linkanchoredtext.Unstage(backRepoLinkAnchoredText.GetStage())
// remove instance from the back repo 3 maps
linkanchoredtextID := backRepoLinkAnchoredText.Map_LinkAnchoredTextPtr_LinkAnchoredTextDBID[linkanchoredtext]
delete(backRepoLinkAnchoredText.Map_LinkAnchoredTextPtr_LinkAnchoredTextDBID, linkanchoredtext)
delete(backRepoLinkAnchoredText.Map_LinkAnchoredTextDBID_LinkAnchoredTextDB, linkanchoredtextID)
delete(backRepoLinkAnchoredText.Map_LinkAnchoredTextDBID_LinkAnchoredTextPtr, linkanchoredtextID)
}
return
}
// CheckoutPhaseOneInstance takes a linkanchoredtextDB that has been found in the DB, updates the backRepo and stages the
// models version of the linkanchoredtextDB
func (backRepoLinkAnchoredText *BackRepoLinkAnchoredTextStruct) CheckoutPhaseOneInstance(linkanchoredtextDB *LinkAnchoredTextDB) (Error error) {
linkanchoredtext, ok := backRepoLinkAnchoredText.Map_LinkAnchoredTextDBID_LinkAnchoredTextPtr[linkanchoredtextDB.ID]
if !ok {
linkanchoredtext = new(models.LinkAnchoredText)
backRepoLinkAnchoredText.Map_LinkAnchoredTextDBID_LinkAnchoredTextPtr[linkanchoredtextDB.ID] = linkanchoredtext
backRepoLinkAnchoredText.Map_LinkAnchoredTextPtr_LinkAnchoredTextDBID[linkanchoredtext] = linkanchoredtextDB.ID
// append model store with the new element
linkanchoredtext.Name = linkanchoredtextDB.Name_Data.String
linkanchoredtext.Stage(backRepoLinkAnchoredText.GetStage())
}
linkanchoredtextDB.CopyBasicFieldsToLinkAnchoredText(linkanchoredtext)
// in some cases, the instance might have been unstaged. It is necessary to stage it again
linkanchoredtext.Stage(backRepoLinkAnchoredText.GetStage())
// preserve pointer to linkanchoredtextDB. Otherwise, pointer will is recycled and the map of pointers
// Map_LinkAnchoredTextDBID_LinkAnchoredTextDB)[linkanchoredtextDB hold variable pointers
linkanchoredtextDB_Data := *linkanchoredtextDB
preservedPtrToLinkAnchoredText := &linkanchoredtextDB_Data
backRepoLinkAnchoredText.Map_LinkAnchoredTextDBID_LinkAnchoredTextDB[linkanchoredtextDB.ID] = preservedPtrToLinkAnchoredText
return
}
// BackRepoLinkAnchoredText.CheckoutPhaseTwo Checkouts all staged instances of LinkAnchoredText to the BackRepo
// Phase Two is the update of instance with the field in the database
func (backRepoLinkAnchoredText *BackRepoLinkAnchoredTextStruct) CheckoutPhaseTwo(backRepo *BackRepoStruct) (Error error) {
// parse all DB instance and update all pointer fields of the translated models instance
for _, linkanchoredtextDB := range backRepoLinkAnchoredText.Map_LinkAnchoredTextDBID_LinkAnchoredTextDB {
backRepoLinkAnchoredText.CheckoutPhaseTwoInstance(backRepo, linkanchoredtextDB)
}
return
}
// BackRepoLinkAnchoredText.CheckoutPhaseTwoInstance Checkouts staged instances of LinkAnchoredText to the BackRepo
// Phase Two is the update of instance with the field in the database
func (backRepoLinkAnchoredText *BackRepoLinkAnchoredTextStruct) CheckoutPhaseTwoInstance(backRepo *BackRepoStruct, linkanchoredtextDB *LinkAnchoredTextDB) (Error error) {
linkanchoredtext := backRepoLinkAnchoredText.Map_LinkAnchoredTextDBID_LinkAnchoredTextPtr[linkanchoredtextDB.ID]
linkanchoredtextDB.DecodePointers(backRepo, linkanchoredtext)
return
}
func (linkanchoredtextDB *LinkAnchoredTextDB) DecodePointers(backRepo *BackRepoStruct, linkanchoredtext *models.LinkAnchoredText) {
// insertion point for checkout of pointer encoding
// This loop redeem linkanchoredtext.Animates in the stage from the encode in the back repo
// It parses all AnimateDB in the back repo and if the reverse pointer encoding matches the back repo ID
// it appends the stage instance
// 1. reset the slice
linkanchoredtext.Animates = linkanchoredtext.Animates[:0]
for _, _Animateid := range linkanchoredtextDB.LinkAnchoredTextPointersEncoding.Animates {
linkanchoredtext.Animates = append(linkanchoredtext.Animates, backRepo.BackRepoAnimate.Map_AnimateDBID_AnimatePtr[uint(_Animateid)])
}
return
}
// CommitLinkAnchoredText allows commit of a single linkanchoredtext (if already staged)
func (backRepo *BackRepoStruct) CommitLinkAnchoredText(linkanchoredtext *models.LinkAnchoredText) {
backRepo.BackRepoLinkAnchoredText.CommitPhaseOneInstance(linkanchoredtext)
if id, ok := backRepo.BackRepoLinkAnchoredText.Map_LinkAnchoredTextPtr_LinkAnchoredTextDBID[linkanchoredtext]; ok {
backRepo.BackRepoLinkAnchoredText.CommitPhaseTwoInstance(backRepo, id, linkanchoredtext)
}
backRepo.CommitFromBackNb = backRepo.CommitFromBackNb + 1
}
// CommitLinkAnchoredText allows checkout of a single linkanchoredtext (if already staged and with a BackRepo id)
func (backRepo *BackRepoStruct) CheckoutLinkAnchoredText(linkanchoredtext *models.LinkAnchoredText) {
// check if the linkanchoredtext is staged
if _, ok := backRepo.BackRepoLinkAnchoredText.Map_LinkAnchoredTextPtr_LinkAnchoredTextDBID[linkanchoredtext]; ok {
if id, ok := backRepo.BackRepoLinkAnchoredText.Map_LinkAnchoredTextPtr_LinkAnchoredTextDBID[linkanchoredtext]; ok {
var linkanchoredtextDB LinkAnchoredTextDB
linkanchoredtextDB.ID = id
if err := backRepo.BackRepoLinkAnchoredText.db.First(&linkanchoredtextDB, id).Error; err != nil {
log.Fatalln("CheckoutLinkAnchoredText : Problem with getting object with id:", id)
}
backRepo.BackRepoLinkAnchoredText.CheckoutPhaseOneInstance(&linkanchoredtextDB)
backRepo.BackRepoLinkAnchoredText.CheckoutPhaseTwoInstance(backRepo, &linkanchoredtextDB)
}
}
}
// CopyBasicFieldsFromLinkAnchoredText
func (linkanchoredtextDB *LinkAnchoredTextDB) CopyBasicFieldsFromLinkAnchoredText(linkanchoredtext *models.LinkAnchoredText) {
// insertion point for fields commit
linkanchoredtextDB.Name_Data.String = linkanchoredtext.Name
linkanchoredtextDB.Name_Data.Valid = true
linkanchoredtextDB.Content_Data.String = linkanchoredtext.Content
linkanchoredtextDB.Content_Data.Valid = true
linkanchoredtextDB.AutomaticLayout_Data.Bool = linkanchoredtext.AutomaticLayout
linkanchoredtextDB.AutomaticLayout_Data.Valid = true
linkanchoredtextDB.LinkAnchorType_Data.String = linkanchoredtext.LinkAnchorType.ToString()
linkanchoredtextDB.LinkAnchorType_Data.Valid = true
linkanchoredtextDB.X_Offset_Data.Float64 = linkanchoredtext.X_Offset
linkanchoredtextDB.X_Offset_Data.Valid = true
linkanchoredtextDB.Y_Offset_Data.Float64 = linkanchoredtext.Y_Offset
linkanchoredtextDB.Y_Offset_Data.Valid = true
linkanchoredtextDB.FontWeight_Data.String = linkanchoredtext.FontWeight
linkanchoredtextDB.FontWeight_Data.Valid = true
linkanchoredtextDB.FontSize_Data.String = linkanchoredtext.FontSize
linkanchoredtextDB.FontSize_Data.Valid = true
linkanchoredtextDB.LetterSpacing_Data.String = linkanchoredtext.LetterSpacing
linkanchoredtextDB.LetterSpacing_Data.Valid = true
linkanchoredtextDB.Color_Data.String = linkanchoredtext.Color
linkanchoredtextDB.Color_Data.Valid = true
linkanchoredtextDB.FillOpacity_Data.Float64 = linkanchoredtext.FillOpacity
linkanchoredtextDB.FillOpacity_Data.Valid = true
linkanchoredtextDB.Stroke_Data.String = linkanchoredtext.Stroke
linkanchoredtextDB.Stroke_Data.Valid = true
linkanchoredtextDB.StrokeOpacity_Data.Float64 = linkanchoredtext.StrokeOpacity
linkanchoredtextDB.StrokeOpacity_Data.Valid = true
linkanchoredtextDB.StrokeWidth_Data.Float64 = linkanchoredtext.StrokeWidth
linkanchoredtextDB.StrokeWidth_Data.Valid = true
linkanchoredtextDB.StrokeDashArray_Data.String = linkanchoredtext.StrokeDashArray
linkanchoredtextDB.StrokeDashArray_Data.Valid = true
linkanchoredtextDB.StrokeDashArrayWhenSelected_Data.String = linkanchoredtext.StrokeDashArrayWhenSelected
linkanchoredtextDB.StrokeDashArrayWhenSelected_Data.Valid = true
linkanchoredtextDB.Transform_Data.String = linkanchoredtext.Transform
linkanchoredtextDB.Transform_Data.Valid = true
}
// CopyBasicFieldsFromLinkAnchoredText_WOP
func (linkanchoredtextDB *LinkAnchoredTextDB) CopyBasicFieldsFromLinkAnchoredText_WOP(linkanchoredtext *models.LinkAnchoredText_WOP) {
// insertion point for fields commit
linkanchoredtextDB.Name_Data.String = linkanchoredtext.Name
linkanchoredtextDB.Name_Data.Valid = true
linkanchoredtextDB.Content_Data.String = linkanchoredtext.Content
linkanchoredtextDB.Content_Data.Valid = true
linkanchoredtextDB.AutomaticLayout_Data.Bool = linkanchoredtext.AutomaticLayout
linkanchoredtextDB.AutomaticLayout_Data.Valid = true
linkanchoredtextDB.LinkAnchorType_Data.String = linkanchoredtext.LinkAnchorType.ToString()
linkanchoredtextDB.LinkAnchorType_Data.Valid = true
linkanchoredtextDB.X_Offset_Data.Float64 = linkanchoredtext.X_Offset
linkanchoredtextDB.X_Offset_Data.Valid = true
linkanchoredtextDB.Y_Offset_Data.Float64 = linkanchoredtext.Y_Offset
linkanchoredtextDB.Y_Offset_Data.Valid = true
linkanchoredtextDB.FontWeight_Data.String = linkanchoredtext.FontWeight
linkanchoredtextDB.FontWeight_Data.Valid = true
linkanchoredtextDB.FontSize_Data.String = linkanchoredtext.FontSize
linkanchoredtextDB.FontSize_Data.Valid = true
linkanchoredtextDB.LetterSpacing_Data.String = linkanchoredtext.LetterSpacing
linkanchoredtextDB.LetterSpacing_Data.Valid = true
linkanchoredtextDB.Color_Data.String = linkanchoredtext.Color
linkanchoredtextDB.Color_Data.Valid = true
linkanchoredtextDB.FillOpacity_Data.Float64 = linkanchoredtext.FillOpacity
linkanchoredtextDB.FillOpacity_Data.Valid = true
linkanchoredtextDB.Stroke_Data.String = linkanchoredtext.Stroke
linkanchoredtextDB.Stroke_Data.Valid = true
linkanchoredtextDB.StrokeOpacity_Data.Float64 = linkanchoredtext.StrokeOpacity
linkanchoredtextDB.StrokeOpacity_Data.Valid = true
linkanchoredtextDB.StrokeWidth_Data.Float64 = linkanchoredtext.StrokeWidth
linkanchoredtextDB.StrokeWidth_Data.Valid = true
linkanchoredtextDB.StrokeDashArray_Data.String = linkanchoredtext.StrokeDashArray
linkanchoredtextDB.StrokeDashArray_Data.Valid = true
linkanchoredtextDB.StrokeDashArrayWhenSelected_Data.String = linkanchoredtext.StrokeDashArrayWhenSelected
linkanchoredtextDB.StrokeDashArrayWhenSelected_Data.Valid = true
linkanchoredtextDB.Transform_Data.String = linkanchoredtext.Transform
linkanchoredtextDB.Transform_Data.Valid = true
}
// CopyBasicFieldsFromLinkAnchoredTextWOP
func (linkanchoredtextDB *LinkAnchoredTextDB) CopyBasicFieldsFromLinkAnchoredTextWOP(linkanchoredtext *LinkAnchoredTextWOP) {
// insertion point for fields commit
linkanchoredtextDB.Name_Data.String = linkanchoredtext.Name
linkanchoredtextDB.Name_Data.Valid = true
linkanchoredtextDB.Content_Data.String = linkanchoredtext.Content
linkanchoredtextDB.Content_Data.Valid = true
linkanchoredtextDB.AutomaticLayout_Data.Bool = linkanchoredtext.AutomaticLayout
linkanchoredtextDB.AutomaticLayout_Data.Valid = true
linkanchoredtextDB.LinkAnchorType_Data.String = linkanchoredtext.LinkAnchorType.ToString()
linkanchoredtextDB.LinkAnchorType_Data.Valid = true
linkanchoredtextDB.X_Offset_Data.Float64 = linkanchoredtext.X_Offset
linkanchoredtextDB.X_Offset_Data.Valid = true
linkanchoredtextDB.Y_Offset_Data.Float64 = linkanchoredtext.Y_Offset
linkanchoredtextDB.Y_Offset_Data.Valid = true
linkanchoredtextDB.FontWeight_Data.String = linkanchoredtext.FontWeight
linkanchoredtextDB.FontWeight_Data.Valid = true
linkanchoredtextDB.FontSize_Data.String = linkanchoredtext.FontSize
linkanchoredtextDB.FontSize_Data.Valid = true
linkanchoredtextDB.LetterSpacing_Data.String = linkanchoredtext.LetterSpacing
linkanchoredtextDB.LetterSpacing_Data.Valid = true
linkanchoredtextDB.Color_Data.String = linkanchoredtext.Color
linkanchoredtextDB.Color_Data.Valid = true
linkanchoredtextDB.FillOpacity_Data.Float64 = linkanchoredtext.FillOpacity
linkanchoredtextDB.FillOpacity_Data.Valid = true
linkanchoredtextDB.Stroke_Data.String = linkanchoredtext.Stroke
linkanchoredtextDB.Stroke_Data.Valid = true
linkanchoredtextDB.StrokeOpacity_Data.Float64 = linkanchoredtext.StrokeOpacity
linkanchoredtextDB.StrokeOpacity_Data.Valid = true
linkanchoredtextDB.StrokeWidth_Data.Float64 = linkanchoredtext.StrokeWidth
linkanchoredtextDB.StrokeWidth_Data.Valid = true
linkanchoredtextDB.StrokeDashArray_Data.String = linkanchoredtext.StrokeDashArray
linkanchoredtextDB.StrokeDashArray_Data.Valid = true
linkanchoredtextDB.StrokeDashArrayWhenSelected_Data.String = linkanchoredtext.StrokeDashArrayWhenSelected
linkanchoredtextDB.StrokeDashArrayWhenSelected_Data.Valid = true
linkanchoredtextDB.Transform_Data.String = linkanchoredtext.Transform
linkanchoredtextDB.Transform_Data.Valid = true
}
// CopyBasicFieldsToLinkAnchoredText
func (linkanchoredtextDB *LinkAnchoredTextDB) CopyBasicFieldsToLinkAnchoredText(linkanchoredtext *models.LinkAnchoredText) {
// insertion point for checkout of basic fields (back repo to stage)
linkanchoredtext.Name = linkanchoredtextDB.Name_Data.String
linkanchoredtext.Content = linkanchoredtextDB.Content_Data.String
linkanchoredtext.AutomaticLayout = linkanchoredtextDB.AutomaticLayout_Data.Bool
linkanchoredtext.LinkAnchorType.FromString(linkanchoredtextDB.LinkAnchorType_Data.String)
linkanchoredtext.X_Offset = linkanchoredtextDB.X_Offset_Data.Float64
linkanchoredtext.Y_Offset = linkanchoredtextDB.Y_Offset_Data.Float64
linkanchoredtext.FontWeight = linkanchoredtextDB.FontWeight_Data.String
linkanchoredtext.FontSize = linkanchoredtextDB.FontSize_Data.String
linkanchoredtext.LetterSpacing = linkanchoredtextDB.LetterSpacing_Data.String
linkanchoredtext.Color = linkanchoredtextDB.Color_Data.String
linkanchoredtext.FillOpacity = linkanchoredtextDB.FillOpacity_Data.Float64
linkanchoredtext.Stroke = linkanchoredtextDB.Stroke_Data.String
linkanchoredtext.StrokeOpacity = linkanchoredtextDB.StrokeOpacity_Data.Float64
linkanchoredtext.StrokeWidth = linkanchoredtextDB.StrokeWidth_Data.Float64
linkanchoredtext.StrokeDashArray = linkanchoredtextDB.StrokeDashArray_Data.String
linkanchoredtext.StrokeDashArrayWhenSelected = linkanchoredtextDB.StrokeDashArrayWhenSelected_Data.String
linkanchoredtext.Transform = linkanchoredtextDB.Transform_Data.String
}
// CopyBasicFieldsToLinkAnchoredText_WOP
func (linkanchoredtextDB *LinkAnchoredTextDB) CopyBasicFieldsToLinkAnchoredText_WOP(linkanchoredtext *models.LinkAnchoredText_WOP) {
// insertion point for checkout of basic fields (back repo to stage)
linkanchoredtext.Name = linkanchoredtextDB.Name_Data.String
linkanchoredtext.Content = linkanchoredtextDB.Content_Data.String
linkanchoredtext.AutomaticLayout = linkanchoredtextDB.AutomaticLayout_Data.Bool
linkanchoredtext.LinkAnchorType.FromString(linkanchoredtextDB.LinkAnchorType_Data.String)
linkanchoredtext.X_Offset = linkanchoredtextDB.X_Offset_Data.Float64
linkanchoredtext.Y_Offset = linkanchoredtextDB.Y_Offset_Data.Float64
linkanchoredtext.FontWeight = linkanchoredtextDB.FontWeight_Data.String
linkanchoredtext.FontSize = linkanchoredtextDB.FontSize_Data.String
linkanchoredtext.LetterSpacing = linkanchoredtextDB.LetterSpacing_Data.String
linkanchoredtext.Color = linkanchoredtextDB.Color_Data.String
linkanchoredtext.FillOpacity = linkanchoredtextDB.FillOpacity_Data.Float64
linkanchoredtext.Stroke = linkanchoredtextDB.Stroke_Data.String
linkanchoredtext.StrokeOpacity = linkanchoredtextDB.StrokeOpacity_Data.Float64
linkanchoredtext.StrokeWidth = linkanchoredtextDB.StrokeWidth_Data.Float64
linkanchoredtext.StrokeDashArray = linkanchoredtextDB.StrokeDashArray_Data.String
linkanchoredtext.StrokeDashArrayWhenSelected = linkanchoredtextDB.StrokeDashArrayWhenSelected_Data.String
linkanchoredtext.Transform = linkanchoredtextDB.Transform_Data.String
}
// CopyBasicFieldsToLinkAnchoredTextWOP
func (linkanchoredtextDB *LinkAnchoredTextDB) CopyBasicFieldsToLinkAnchoredTextWOP(linkanchoredtext *LinkAnchoredTextWOP) {
linkanchoredtext.ID = int(linkanchoredtextDB.ID)
// insertion point for checkout of basic fields (back repo to stage)
linkanchoredtext.Name = linkanchoredtextDB.Name_Data.String
linkanchoredtext.Content = linkanchoredtextDB.Content_Data.String
linkanchoredtext.AutomaticLayout = linkanchoredtextDB.AutomaticLayout_Data.Bool
linkanchoredtext.LinkAnchorType.FromString(linkanchoredtextDB.LinkAnchorType_Data.String)
linkanchoredtext.X_Offset = linkanchoredtextDB.X_Offset_Data.Float64
linkanchoredtext.Y_Offset = linkanchoredtextDB.Y_Offset_Data.Float64
linkanchoredtext.FontWeight = linkanchoredtextDB.FontWeight_Data.String
linkanchoredtext.FontSize = linkanchoredtextDB.FontSize_Data.String
linkanchoredtext.LetterSpacing = linkanchoredtextDB.LetterSpacing_Data.String
linkanchoredtext.Color = linkanchoredtextDB.Color_Data.String
linkanchoredtext.FillOpacity = linkanchoredtextDB.FillOpacity_Data.Float64
linkanchoredtext.Stroke = linkanchoredtextDB.Stroke_Data.String
linkanchoredtext.StrokeOpacity = linkanchoredtextDB.StrokeOpacity_Data.Float64
linkanchoredtext.StrokeWidth = linkanchoredtextDB.StrokeWidth_Data.Float64
linkanchoredtext.StrokeDashArray = linkanchoredtextDB.StrokeDashArray_Data.String
linkanchoredtext.StrokeDashArrayWhenSelected = linkanchoredtextDB.StrokeDashArrayWhenSelected_Data.String
linkanchoredtext.Transform = linkanchoredtextDB.Transform_Data.String
}
// Backup generates a json file from a slice of all LinkAnchoredTextDB instances in the backrepo
func (backRepoLinkAnchoredText *BackRepoLinkAnchoredTextStruct) Backup(dirPath string) {
filename := filepath.Join(dirPath, "LinkAnchoredTextDB.json")
// organize the map into an array with increasing IDs, in order to have repoductible
// backup file
forBackup := make([]*LinkAnchoredTextDB, 0)
for _, linkanchoredtextDB := range backRepoLinkAnchoredText.Map_LinkAnchoredTextDBID_LinkAnchoredTextDB {
forBackup = append(forBackup, linkanchoredtextDB)
}
sort.Slice(forBackup[:], func(i, j int) bool {
return forBackup[i].ID < forBackup[j].ID
})
file, err := json.MarshalIndent(forBackup, "", " ")
if err != nil {
log.Fatal("Cannot json LinkAnchoredText ", filename, " ", err.Error())
}
err = ioutil.WriteFile(filename, file, 0644)
if err != nil {
log.Fatal("Cannot write the json LinkAnchoredText file", err.Error())
}
}
// Backup generates a json file from a slice of all LinkAnchoredTextDB instances in the backrepo
func (backRepoLinkAnchoredText *BackRepoLinkAnchoredTextStruct) BackupXL(file *xlsx.File) {
// organize the map into an array with increasing IDs, in order to have repoductible
// backup file
forBackup := make([]*LinkAnchoredTextDB, 0)
for _, linkanchoredtextDB := range backRepoLinkAnchoredText.Map_LinkAnchoredTextDBID_LinkAnchoredTextDB {
forBackup = append(forBackup, linkanchoredtextDB)
}
sort.Slice(forBackup[:], func(i, j int) bool {
return forBackup[i].ID < forBackup[j].ID
})
sh, err := file.AddSheet("LinkAnchoredText")
if err != nil {
log.Fatal("Cannot add XL file", err.Error())
}
_ = sh
row := sh.AddRow()
row.WriteSlice(&LinkAnchoredText_Fields, -1)
for _, linkanchoredtextDB := range forBackup {
var linkanchoredtextWOP LinkAnchoredTextWOP
linkanchoredtextDB.CopyBasicFieldsToLinkAnchoredTextWOP(&linkanchoredtextWOP)
row := sh.AddRow()
row.WriteStruct(&linkanchoredtextWOP, -1)
}
}
// RestoreXL from the "LinkAnchoredText" sheet all LinkAnchoredTextDB instances
func (backRepoLinkAnchoredText *BackRepoLinkAnchoredTextStruct) RestoreXLPhaseOne(file *xlsx.File) {
// resets the map
BackRepoLinkAnchoredTextid_atBckpTime_newID = make(map[uint]uint)
sh, ok := file.Sheet["LinkAnchoredText"]
_ = sh
if !ok {
log.Fatal(errors.New("sheet not found"))
}
// log.Println("Max row is", sh.MaxRow)
err := sh.ForEachRow(backRepoLinkAnchoredText.rowVisitorLinkAnchoredText)
if err != nil {
log.Fatal("Err=", err)
}
}
func (backRepoLinkAnchoredText *BackRepoLinkAnchoredTextStruct) rowVisitorLinkAnchoredText(row *xlsx.Row) error {
log.Printf("row line %d\n", row.GetCoordinate())
log.Println(row)
// skip first line
if row.GetCoordinate() > 0 {
var linkanchoredtextWOP LinkAnchoredTextWOP
row.ReadStruct(&linkanchoredtextWOP)
// add the unmarshalled struct to the stage
linkanchoredtextDB := new(LinkAnchoredTextDB)
linkanchoredtextDB.CopyBasicFieldsFromLinkAnchoredTextWOP(&linkanchoredtextWOP)
linkanchoredtextDB_ID_atBackupTime := linkanchoredtextDB.ID
linkanchoredtextDB.ID = 0
query := backRepoLinkAnchoredText.db.Create(linkanchoredtextDB)
if query.Error != nil {
log.Fatal(query.Error)
}
backRepoLinkAnchoredText.Map_LinkAnchoredTextDBID_LinkAnchoredTextDB[linkanchoredtextDB.ID] = linkanchoredtextDB
BackRepoLinkAnchoredTextid_atBckpTime_newID[linkanchoredtextDB_ID_atBackupTime] = linkanchoredtextDB.ID
}
return nil
}
// RestorePhaseOne read the file "LinkAnchoredTextDB.json" in dirPath that stores an array
// of LinkAnchoredTextDB and stores it in the database
// the map BackRepoLinkAnchoredTextid_atBckpTime_newID is updated accordingly
func (backRepoLinkAnchoredText *BackRepoLinkAnchoredTextStruct) RestorePhaseOne(dirPath string) {
// resets the map
BackRepoLinkAnchoredTextid_atBckpTime_newID = make(map[uint]uint)
filename := filepath.Join(dirPath, "LinkAnchoredTextDB.json")
jsonFile, err := os.Open(filename)
// if we os.Open returns an error then handle it
if err != nil {
log.Fatal("Cannot restore/open the json LinkAnchoredText file", filename, " ", err.Error())
}
// read our opened jsonFile as a byte array.
byteValue, _ := ioutil.ReadAll(jsonFile)
var forRestore []*LinkAnchoredTextDB
err = json.Unmarshal(byteValue, &forRestore)
// fill up Map_LinkAnchoredTextDBID_LinkAnchoredTextDB
for _, linkanchoredtextDB := range forRestore {
linkanchoredtextDB_ID_atBackupTime := linkanchoredtextDB.ID
linkanchoredtextDB.ID = 0
query := backRepoLinkAnchoredText.db.Create(linkanchoredtextDB)
if query.Error != nil {
log.Fatal(query.Error)
}
backRepoLinkAnchoredText.Map_LinkAnchoredTextDBID_LinkAnchoredTextDB[linkanchoredtextDB.ID] = linkanchoredtextDB
BackRepoLinkAnchoredTextid_atBckpTime_newID[linkanchoredtextDB_ID_atBackupTime] = linkanchoredtextDB.ID
}
if err != nil {
log.Fatal("Cannot restore/unmarshall json LinkAnchoredText file", err.Error())
}
}
// RestorePhaseTwo uses all map BackRepo<LinkAnchoredText>id_atBckpTime_newID
// to compute new index
func (backRepoLinkAnchoredText *BackRepoLinkAnchoredTextStruct) RestorePhaseTwo() {
for _, linkanchoredtextDB := range backRepoLinkAnchoredText.Map_LinkAnchoredTextDBID_LinkAnchoredTextDB {
// next line of code is to avert unused variable compilation error
_ = linkanchoredtextDB
// insertion point for reindexing pointers encoding
// update databse with new index encoding
query := backRepoLinkAnchoredText.db.Model(linkanchoredtextDB).Updates(*linkanchoredtextDB)
if query.Error != nil {
log.Fatal(query.Error)
}
}
}
// BackRepoLinkAnchoredText.ResetReversePointers commits all staged instances of LinkAnchoredText to the BackRepo
// Phase Two is the update of instance with the field in the database
func (backRepoLinkAnchoredText *BackRepoLinkAnchoredTextStruct) ResetReversePointers(backRepo *BackRepoStruct) (Error error) {
for idx, linkanchoredtext := range backRepoLinkAnchoredText.Map_LinkAnchoredTextDBID_LinkAnchoredTextPtr {
backRepoLinkAnchoredText.ResetReversePointersInstance(backRepo, idx, linkanchoredtext)
}
return
}
func (backRepoLinkAnchoredText *BackRepoLinkAnchoredTextStruct) ResetReversePointersInstance(backRepo *BackRepoStruct, idx uint, linkanchoredtext *models.LinkAnchoredText) (Error error) {
// fetch matching linkanchoredtextDB
if linkanchoredtextDB, ok := backRepoLinkAnchoredText.Map_LinkAnchoredTextDBID_LinkAnchoredTextDB[idx]; ok {
_ = linkanchoredtextDB // to avoid unused variable error if there are no reverse to reset
// insertion point for reverse pointers reset
// end of insertion point for reverse pointers reset
}
return
}
// this field is used during the restauration process.
// it stores the ID at the backup time and is used for renumbering
var BackRepoLinkAnchoredTextid_atBckpTime_newID map[uint]uint