Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
6887 dpurdie 1
########################################################################
2
# COPYRIGHT - VIX IP PTY LTD ("VIX"). ALL RIGHTS RESERVED.
3
#
4
# Module name   : rmMerge_spitRelease.pl
5
# Module type   : JATS Utility
6
# Compiler(s)   : Perl
7
# Environment(s): jats
8
#
9
# Description   : Insert Extacted Release data into a different RM instance
10
#
11
# Usage         : See POD at the end of this file
12
#
13
#......................................................................#
14
 
15
require 5.008_002;
16
use strict;
17
use warnings;
18
 
19
use Pod::Usage;
20
use Getopt::Long;
21
 
22
use JatsError;
23
use JatsRmApi;
24
use JatsSystem;
25
use FileUtils;
26
use ConfigurationFile;
27
use File::Copy;
28
use DBI;
29
my $RM_DB;
30
my $VERSION = "1.0";
31
my $testRMCred = ['TST', 'jdbc:oracle:thin:@relmanu1.coidtfba5ouc.ap-southeast-2.rds.amazonaws.com:1521:relmanu1', 'RELEASE_MANAGER', 'MPM0$U74'];
32
my $oldRMCred =  ['OLD', 'jdbc:oracle:thin:@auawsards001:1521:RELEASEM', 'RELEASE_MANAGER', 'ske2k0se'];
33
my $useRmCred;
34
 
35
my $opt_reuse=1;
36
my $opt_help=0;
37
my $opt_verbose=0;
38
my $opt_debug=0;
39
my $opt_live = 0;
40
my $opt_rtagId;
41
my $opt_infile;
42
my $opt_name;
43
my $opt_sloppy;
44
 
45
our %rmData;
46
my %keyFieldsData;
47
my $rtagId;
48
 
49
 
50
#-------------------------------------------------------------------------------
51
# Function        : Mainline Entry Point
52
#
53
# Description     :
54
#
55
# Inputs          :
56
#
57
my $result = GetOptions (
58
                "help:+"        => \$opt_help,
59
                "manual:3"      => \$opt_help,
60
                "verbose:+"     => \$opt_verbose,
61
                "debug:+"       => \$opt_debug,
62
                "live!"         => \$opt_live,
63
                "sloppy!"       => \$opt_sloppy,
64
                "rtagid:i"      => \$opt_rtagId,            # Used to idenify the input file
65
                "infile:s"      => \$opt_infile,            # Name of the imput file
66
                "name:s"        => \$opt_name,
67
                );
68
 
69
                #
70
                #   UPDATE THE DOCUMENTATION AT THE END OF THIS FILE !!!
71
                #
72
 
73
#
74
#   Process help and manual options
75
#
76
pod2usage(-verbose => 0, -message => "Version: $VERSION") if ($opt_help == 1 || ! $result);
77
pod2usage(-verbose => 1) if ( $opt_help == 2 );
78
pod2usage(-verbose => 2) if ( $opt_help > 2 );
79
pod2usage(-verbose => 0, -message => "Version: $VERSION") if ( $#ARGV >= 0 );
80
 
81
#
82
#   Configure the error reporting rmMerge_process now that we have the user options
83
#
84
ErrorConfig( 'name'    =>'SPITRELEASE',
85
             'verbose' => $opt_verbose,
86
             'debug' => $opt_debug,
87
            );
88
Error("Must specify rtagID or Infile") unless (defined $opt_infile or defined $opt_rtagId);
89
 
90
#
91
# 
92
if ($opt_live) {
93
    Message("Using Live Database");
94
    $useRmCred = $oldRMCred;
95
} else  {
96
    $useRmCred = $testRMCred;
97
}
98
 
99
#   Generate the output filename
100
#   
101
$opt_infile = join('.', $opt_rtagId, 'releaseinfo', 'txt') unless $opt_infile;
102
Message("Using: $opt_infile") ;
103
my $localDataStore = $opt_infile;
104
 
105
$ENV{GBE_RM_LOCATION} = $useRmCred->[1];
106
$ENV{GBE_RM_USERNAME} = $useRmCred->[2];
107
$ENV{GBE_RM_PASSWORD} = $useRmCred->[3];
108
connectRM(\$RM_DB) unless ( $RM_DB );
109
 
110
#
111
#   Get the data saved by rmMerge_suck
112
#
113
restoreLocalData();
114
 
115
# Use existing rtag name, unless a new one has been provided
116
my $rtagName = GetRtagName(); 
117
unless ($opt_name) {
118
    $opt_name = $rtagName;
119
} else {
120
    $opt_name =~ s~\%~$rtagName~g;
121
}
122
Message ("Creating Release:$opt_name");
123
 
124
$rtagId = GetRtagByName($opt_name);
125
Error ("Named Release already exists") if defined $rtagId;
126
 
127
#
128
#   Potentially massage the data a bit
129
#
130
MassageRtagId();
131
 
132
#
133
#   Generate Cross reference information for the various tables
134
#   Need to have all the cross references in place first
135
#
136
GetXrefsUsers(qw(CREATOR_ID RELEASOR_ID OFFICIAL_ID INSERTOR_ID));
137
GetXrefsPvid(qw(PV_ID ROOT_PV_ID));
138
GetXrefsRtagId(qw( RTAG_ID PARENT_RTAG_ID ));
139
GetXrefsProjId(qw( PROJ_ID ));
140
GetXrefsGbeId(qw( GBE_ID ));
141
#GetXrefsPkgId(qw( PKG_ID ));
142
GetXrefsBaseViewId(qw( BASE_VIEW_ID ));
143
 
144
ErrorDoExit();
145
 
146
#GetXrefsIgnore(qw( TEST_ID TESTRUN_ID DOC_ID BUILD_ID));        # Primary keys - ignore
147
#GetXrefsIgnore(qw( BE_ID BM_ID BSA_ID BS_ID VCS_TYPE_ID));      # Assume these have not changed
148
 
149
#
150
#   Now insert data into tables in the target database
151
#   Need to MAP some fields
152
#
153
CreateNewRtagId();
154
CreateRelease('RELEASE_TAGS');
155
CreateReleaseData('RELEASE_CONTENT');
156
CreateReleaseData('PEGGED_VERSIONS');
157
CreateReleaseData('ADVISORY_RIPPLE');
158
CreateReleaseConfig();
159
RebuildReleaseIcons();
160
 
161
disconnectRM(\$RM_DB);
162
#DebugDumpData("keyFieldsData",\%keyFieldsData);
163
exit 0;
164
 
165
#-------------------------------------------------------------------------------
166
# Function        : GetRtagName 
167
#
168
# Description     : Get the Rtag Name of the release 
169
#
170
# Inputs          : 
171
#
172
# Returns         : 
173
#
174
sub GetRtagName
175
{
176
    my $index = getIndex('RELEASE_TAGS', 'RTAG_NAME');
177
    my $table = $rmData{'RELEASE_TAGS_DATA'};
178
    return $table->[0][$index] ;
179
}
180
 
181
#-------------------------------------------------------------------------------
182
# Function        : MassageRtagId 
183
#
184
# Description     : Need to massage the data for my own RTAG_ID as we are renaming
185
#                   the Release 
186
#
187
# Inputs          : 
188
#
189
# Returns         : 
190
#
191
sub MassageRtagId
192
{
193
}
194
 
195
#-------------------------------------------------------------------------------
196
# Function        : RebuildReleaseIcons 
197
#
198
# Description     : Mark the Release to that its icons are rebuild on the next access
199
#
200
# Inputs          : 
201
#
202
# Returns         : 
203
#
204
sub RebuildReleaseIcons 
205
{
206
    #   Force the Release Icons to be rebuilt
207
    my $m_sqlstr =  "BEGIN RELEASE_MANAGER.TOUCH_RELEASE ( $rtagId ); END;";
208
    getDataFromRm('addToRelease', $m_sqlstr, {});
209
}
210
 
211
#-------------------------------------------------------------------------------
212
# Function        : CreateReleaseConfig 
213
#
214
# Description     : Create must of the Release Config 
215
#
216
# Inputs          : 
217
#
218
# Returns         : 
219
#
220
sub CreateReleaseConfig
221
{
222
    my ($tableName) = 'RELEASE_CONFIG';
223
    my $tableData = $tableName. '_DATA';
224
 
225
    #
226
    #   Get one row of data and massage it into a form suitable for insertion
227
    #
228
    unless ( $rmData{$tableData}[0]) {
229
        Message ("No data found for $tableName");
230
        return;
231
    }
232
 
233
    foreach my $data (@{$rmData{$tableData}}) {
234
        my $rconId;
235
 
236
        InsertTableRow($tableName, $data, {
237
            'RCON_ID' => sub {
238
                my ($fname, $value) = @_;  
239
                $rconId  = GetNextSeqNum('SEQ_RCON_ID');
240
                return $rconId;
241
                },
242
            'BMCON_ID' => sub {my ($fname, $value) = @_;  return '';},
243
            });
244
 
245
        CreateRunLevel($rconId) if $rconId;
246
    }
247
}
248
 
249
#-------------------------------------------------------------------------------
250
# Function        : CreateRunLevel 
251
#
252
# Description     : Create a run_level entry and return its rcon_id
253
#
254
# Inputs          : None 
255
#
256
# Returns         : rcon_id - unique seqience number
257
#
258
sub CreateRunLevel
259
{
260
    my ($rconId) =  @_;
261
    getDataFromRm('CreateRunLevel', "INSERT INTO release_manager.RUN_LEVEL (RCON_ID, PAUSE) VALUES ($rconId, 1)", {});
262
    return $rconId;
263
}
264
 
265
#-------------------------------------------------------------------------------
266
# Function        : CreateRelease 
267
#
268
# Description     : Create a new Release 
269
#
270
# Inputs          : $tableName 
271
#
272
# Returns         : 
273
#
274
sub CreateRelease
275
{
276
    my ($tableName) = @_;
277
    my $tableData = $tableName. '_DATA';
278
 
279
    #
280
    #   Get one row of data and massage it into a form suitable for insertion
281
    #
282
    my $data = $rmData{$tableData}[0];
283
    Error ("Internal: No data found for $tableName") unless $data;
284
 
285
    InsertTableRow($tableName, $data, {
286
        'REBUILD_STAMP' => sub {my ($fname, $value) = @_;  return 0;},
287
        'RTAG_NAME' => sub {my ($fname, $value) = @_;  return $opt_name;},
288
        });
289
}
290
 
291
#-------------------------------------------------------------------------------
292
# Function        : CreateNewRtagId 
293
#
294
# Description     : Create a new RTAG_ID 
295
#
296
# Inputs          : 
297
#
298
# Returns         : 
299
#
300
sub CreateNewRtagId
301
{
302
    $rtagId = GetNextSeqNum('seq_rtag_id');
303
    Message("ReleaseTag: RTAG_ID: $rtagId");
304
 
305
    #
306
    #   PV_ID in the origin
307
    #   
308
    my $rtagIdOrigin = $rmData{METADATA}{RTAG_ID};
309
    $keyFieldsData{RTAG_ID}{$rtagIdOrigin} = $rtagId;
310
}
311
 
312
 
313
#-------------------------------------------------------------------------------
314
# Function        : getIndex 
315
#
316
# Description     : Get the index of a data item from specified meta data
317
#
318
# Inputs          : $table  - Name of table to access
319
#                   $field  - Name of field to locate
320
#
321
# Returns         : Will generate an error if not found 
322
#
323
sub getIndex
324
{
325
    my ($table,$field) = @_;
326
    my $rv;
327
    my $tableName = $table . "_NAMES";
328
    Error ("Internal: getIndex. Metadata not found for: $table") unless exists $rmData{$tableName};
329
 
330
    my $pvMetaData = $rmData{$tableName};
331
 
332
    foreach ( @{$pvMetaData} ) {
333
        next unless $_->[0] eq $field;
334
        $rv =  $_->[3] - 1;
335
        last;
336
    }
337
 
338
    Error("Internal: getIndex. Cannot find metadata for field($field) in table($table)") unless $rv;
339
    return $rv;
340
}
341
 
342
#-------------------------------------------------------------------------------
343
# Function        : GetNextSeqNum 
344
#
345
# Description     : Get the next sequence numbber froom a named sequence 
346
#
347
# Inputs          : $seqName 
348
#
349
# Returns         : A number
350
#
351
sub GetNextSeqNum
352
{
353
    my ($seqName) = @_;
354
    my $row = getDataFromRm('GetNextSeqNum',"SELECT $seqName.NEXTVAL from DUAL", {oneRow => 1});
355
    #Debug0("Generate $seqName: $row[0]");
356
    return $row->[0];
357
}
358
 
359
#-------------------------------------------------------------------------------
360
# Function        : GetRtagByName 
361
#
362
# Description     : Get an rtag_id based on a user name
363
#
364
# Inputs          : $name 
365
#
366
# Returns         : ratg_id 
367
#
368
sub GetRtagByName
369
{
370
    my ($name) = @_;
371
    my $data = getDataFromRm('GetRtagByName',"SELECT rtag_id from release_tags where upper(rtag_name) = upper('$name')", {oneRow => 1});
372
    return $data unless $data;
373
    return $data->[0];
374
}
375
 
376
#-------------------------------------------------------------------------------
377
# Function        : CreateReleaseData  
378
#
379
# Description     : Insert one or more rows into a table
380
#                   Assumes no data massaging needs to be done
381
#
382
# Inputs          : $tableName      - Not sure it will be used
383
#
384
# Returns         : 
385
#
386
sub CreateReleaseData
387
{
388
    my ($tableName) = @_;
389
    my $tableData = $tableName. '_DATA';
390
 
391
    my $pvidIndex = getIndex($tableName, 'PV_ID');
392
 
393
    #
394
    #   Get one row of data and massage it into a form suitable for insertion
395
    #
396
    foreach my $data (@{$rmData{$tableData}}) {
397
 
398
        if ($opt_sloppy)
399
        {
400
            #
401
            #   Only insert data for packagaes that exist in the target Release
402
            #
403
            my $pvid = $data->[$pvidIndex];
404
            next if ( $keyFieldsData{PV_ID}{$pvid} =~ m~^MISSING-~);
405
 
406
        }
407
        InsertTableRow($tableName, $data);
408
    }
409
 
410
}
411
 
412
#-------------------------------------------------------------------------------
413
# Function        : InsertTableRow 
414
#
415
# Description     : Insert a row into a table
416
#   
417
# Inputs          : $tableName
418
#                   $data   - Ref to data
419
#                   $metaData - REf to meta data    
420
#                   $callBacks - Hash of FieldNames, functions
421
#
422
# Returns         : 
423
#
424
sub InsertTableRow
425
{
426
    my ($tableName, $data, $callBacks) = @_;
427
    my $tableMetaData = $tableName. '_NAMES';
428
    my $metaData = $rmData{$tableMetaData};
429
 
430
    my @insertFields;
431
    my @insertValues;
432
 
433
    #
434
    #   Scan the metadata and fiddle the data
435
    #
436
    foreach my $entry ( @$metaData) {
437
        my $fname = $entry->[0];
438
        my $ftype = $entry->[1];
439
        my $isNullable = $entry->[2] eq 'Y';
440
        my $findex = $entry->[3]-1;
441
        my $value = $data->[$findex];
442
        $value = '' unless (defined($value));
443
 
444
        # Does this field need to be mapped
445
        if (exists $rmData{XREF_MAP}{$fname}) {
446
            my $mapTable = $rmData{XREF_MAP}{$fname}; 
447
            Error ("Mapping table not found: $mapTable") unless exists $keyFieldsData{$mapTable};
448
 
449
            unless ( $value eq '' && $isNullable) {
450
 
451
                unless (exists $keyFieldsData{$mapTable}{$value}) {
452
                    DebugDumpData("keyFieldsData",\%keyFieldsData);
453
                    DebugDumpData("Data",$data);
454
                    Error ("Mapping value not found: $mapTable, $value, while rmMerge_processing $tableName, $fname\[$findex\]") ;
455
                }
456
                my $newValue = $keyFieldsData{$mapTable}{$value};
457
                unless (defined $newValue) {
458
                    DebugDumpData("keyFieldsData",\%keyFieldsData);
459
                    DebugDumpData("Data",$data);
460
                    Error("Undefined map for: $tableName, $fname, $value");
461
                }
462
                if ($newValue ne $value) {
463
Verbose("Mapping $tableName:$mapTable:$fname:$value -> $newValue");
464
                    $value = $newValue;
465
                }
466
            }
467
        }
468
 
469
        #
470
        #   Does the field need to be massaged
471
        #
472
        if (defined $callBacks && $callBacks->{$fname}) {
473
            my $newValue = $callBacks->{$fname}->($fname, $value);
474
            if ($newValue ne $value) {
475
Verbose("Massage $tableName:$fname:$value -> $newValue");
476
                $value = $newValue;
477
            }
478
        }
479
 
480
        #
481
        #   Does the field need to be quoted
482
        #   Assume that the 'suck' rmMerge_process has quoted special characters
483
        #   %0D -> return
484
        #   %0A -> newLine
485
        #   %09 -> Tab
486
        #   %25 -> As a percent
487
        #   %27 -> Single Quote
488
        #   Also need to handle a single quote char
489
        #
490
        if ($ftype =~ m~CHAR|VARCHAR~) {
491
            $value =~ s~'~'||chr(39)||'~g;
492
            $value =~ s~%0D~'||chr(13)||'~g;
493
            $value =~ s~%0A~'||chr(10)||'~g;
494
            $value =~ s~%09~'||chr(9)||'~g;
495
            $value =~ s~%27~'||chr(39)||'~g;
496
            $value =~ s~%25~%~g;
497
            $value = "'" . $value . "'";
498
#print("String Length ($fname):", length($value),"\n");
499
 
500
        } elsif ($ftype =~ m~DATE|TIMESTAMP~) {
501
            $value = "TO_TIMESTAMP('$value','YYYY-MM-DD HH24:MI:SS.FF')"
502
        }
503
 
504
        # Null item if we are allowed to
505
        if ($isNullable && length($value) <= 0) {
506
            $value = 'null';
507
        }
508
 
509
        push @insertFields, $fname;
510
        push @insertValues, $value;
511
    }
512
 
513
    #
514
    #   Generate the SQL
515
    #
516
    my $m_sqlstr = "insert into $tableName (" . join(',', @insertFields) . ")" . " VALUES (". join(',', @insertValues) .")";
517
    Debug("$m_sqlstr");
518
 
519
    my $sth = $RM_DB->prepare($m_sqlstr);
520
    my @row;
521
    if ( defined($sth) )
522
    {
523
        if ( $sth->execute( ) )
524
        {
525
            if ( $sth->rows )
526
            {
527
                while ( @row = $sth->fetchrow_array )
528
                {
529
                    print("@row\n");
530
                }
531
            }
532
            $sth->finish();
533
        }
534
        else
535
        {
536
            Error("Execute failure: $m_sqlstr", $sth->errstr() );
537
        }
538
    }
539
    else
540
    {
541
        Error("Prepare failure" );
542
    }
543
}
544
 
545
#-------------------------------------------------------------------------------
546
# Function        : GetXrefCommon 
547
#
548
# Description     : Common code for fetch XREF data from the database 
549
#
550
# Inputs          : $name       - Tag name
551
#                   $sql        - sql fragment to do the work    
552
#                   $options    - Ref to a hack of options
553
#                                   'default' - Value to use when not found
554
#                                   'delete'  - Key to delete from rmMerge_process list
555
#                                   'call'   - sub so call when data is missing
556
#
557
# Returns         : 
558
#
559
sub GetXrefCommon
560
{
561
    my ($name,$sql, $options) = @_;
562
 
563
    my (@fields) = @_;
564
    my %idList;
565
    my %data;
566
    $options = {} unless $options;
567
 
568
    #
569
    #   Generate a hash of items that we need
570
    #
571
    foreach my $tableName ( keys %rmData ) {
572
        next unless $tableName =~ m~_XREF$~;
573
        next unless exists $rmData{$tableName}{$name};
574
        foreach my $id (keys %{ $rmData{$tableName}{$name} }) {
575
            if (exists $options->{delete}) {
576
                next if $options->{delete} eq $id;
577
            }
578
            $idList{ $rmData{$tableName}{$name}{$id} } = $id;
579
        }
580
    }
581
 
582
    #DebugDumpData("GetXrefCommon, $name", \%idList);
583
    return unless %idList;
584
 
585
    #
586
    #   Get all the table data
587
    #
588
    my $m_sqlstr =  $sql . " in (". quoteList(keys %idList) .")";
589
    my $rawData = getDataFromRm('GetXrefsCommon', $m_sqlstr, {} );
590
 
591
    #
592
    #   Post rmMerge_process the data
593
    #
594
    foreach my $row ( @{$rawData} ){
595
        $data{$row->[1]} = $row->[0];
596
    }
597
 
598
    #
599
    #   Check that all required values have been found
600
    #
601
    foreach my $id (keys %idList) {
602
        if (exists $data{$id}) {
603
            $keyFieldsData{$name}{$idList{$id}} = $data{$id};
604
        } elsif (defined $options->{default}) {
605
            $keyFieldsData{$name}{$idList{$id}} = $options->{default};
606
        } elsif (defined $options->{call}) {
607
            $keyFieldsData{$name}{$idList{$id}} = $options->{call}->($name, $id);
608
        } else {
609
            ReportError("No Crossref for $name matching: $id");
610
            #DebugDumpData("RmData", \%rmData);
611
        }
612
    }
613
 
614
    #
615
    #   Keep the raw data in the output hash - possibly for debugging purposes
616
    $keyFieldsData{$name . '_DEBUG'} = \%data;
617
}
618
 
619
#-------------------------------------------------------------------------------
620
# Function        : GetXrefsBaseViewId 
621
#
622
# Description     : Get cross references to other entites     
623
#
624
# Inputs          : list of keyFieldData keys to rmMerge_process
625
#
626
# Returns         : 
627
#
628
sub GetXrefsBaseViewId
629
{
630
    my (@fields) = @_;
631
    GetXrefCommon('VIEW_ID',"select view_id, view_name from views where view_name");
632
}
633
 
634
#-------------------------------------------------------------------------------
635
# Function        : GetXrefsPkgId
636
#
637
# Description     : Get cross references to other entites     
638
#
639
# Inputs          : list of keyFieldData keys to rmMerge_process
640
#
641
# Returns         : 
642
#
643
sub GetXrefsPkgId
644
{
645
    my (@fields) = @_;
646
    GetXrefCommon('PKG_ID',"select pkg_id, pkg_name from packages where pkg_name");
647
    DebugDumpData("keyFieldsData", \%keyFieldsData);
648
    Error("Test");
649
}
650
 
651
#-------------------------------------------------------------------------------
652
# Function        : GetXrefsProjId 
653
#
654
# Description     : Get cross references to other entites     
655
#
656
# Inputs          : list of keyFieldData keys to rmMerge_process
657
#
658
# Returns         : 
659
#
660
sub GetXrefsProjId
661
{
662
    my (@fields) = @_;
663
    GetXrefCommon('PROJ_ID', "select proj_id, proj_name from projects where proj_name");
664
}
665
 
666
#-------------------------------------------------------------------------------
667
# Function        : GetXrefsGbeId 
668
#
669
# Description     : Get cross references to other entites     
670
#
671
# Inputs          : list of keyFieldData keys to rmMerge_process
672
#
673
# Returns         : 
674
#
675
sub GetXrefsGbeId
676
{
677
    my (@fields) = @_;
678
    GetXrefCommon('GBE_ID', "select gbe_id, gbe_value from release_manager.gbe_machtype where gbe_value");
679
}
680
 
681
#-------------------------------------------------------------------------------
682
# Function        : GetXrefsRtagId 
683
#
684
# Description     : Get cross references to other entites     
685
#
686
# Inputs          : list of keyFieldData keys to rmMerge_process
687
#
688
# Returns         : 
689
#
690
sub GetXrefsRtagId
691
{
692
    my (@fields) = @_;
693
    GetXrefCommon('RTAG_ID', 'select rtag_id, rtag_name from release_tags where rtag_name', {
694
        'delete' => $rmData{METADATA}{RTAG_ID},
695
        });
696
}
697
 
698
#-------------------------------------------------------------------------------
699
# Function        : GetXrefsPvid 
700
#
701
# Description     : Get cross references to other entites     
702
#
703
# Inputs          : list of keyFieldData keys to rmMerge_process
704
#
705
# Returns         : 
706
#
707
sub GetXrefsPvid
708
{
709
    my (@fields) = @_;
710
    my $options;
711
 
712
    #
713
    #   Callback functio to handle missing packages
714
    #   The PVID will be marked and rmMerge_processed later
715
    #
716
    if ($opt_sloppy) {
717
        $options->{call} = sub{
718
            my ($name, $id) = @_;
719
            Message("Package not found: " . join( ' ', split($;,$id)));
720
            return "MISSING-".$id;
721
        };
722
    }
723
 
724
    GetXrefCommon('PV_ID', "select pv.pv_id, p.pkg_name || '$;' ||pv.pkg_version from release_manager.packages p, release_manager.package_versions pv" . 
725
                   " where p.pkg_id = pv.pkg_id and p.pkg_name || '$;' || pv.pkg_version",
726
                   $options
727
                   );
728
 
729
}
730
 
731
#-------------------------------------------------------------------------------
732
# Function        : GetXrefsUsers 
733
#
734
# Description     : Get cross references to other entites     
735
#
736
# Inputs          : list of keyFieldData keys to rmMerge_process
737
#
738
# Returns         : 
739
#
740
sub GetXrefsUsers
741
{
742
    my (@fields) = @_;
743
    GetXrefCommon('USER_ID', 'select user_id, user_name from access_manager.users where user_name');
744
}
745
 
746
#-------------------------------------------------------------------------------
747
# Function        : quoteList  
748
#
749
# Description     : Convert an array of strings into a quoted comma-sep string
750
#                   Used in sql of the form select ... in ( 'aaa','bbb',ccc') 
751
#
752
# Inputs          : An array of strings 
753
#
754
# Returns         : quoted comma-sep string
755
#
756
 
757
sub quoteList
758
{
759
    my $rv = '';
760
    my $join = '';
761
    foreach  (@_) {
762
        $rv .= $join . "'" . $_ . "'";
763
        $join = ',';
764
    }
765
    return $rv;
766
}
767
 
768
#-------------------------------------------------------------------------------
769
# Function        : getDataFromRm 
770
#
771
# Description     : Get an array of data from RM 
772
#
773
# Inputs          : $name           - Query Name
774
#                   $m_sqlstr       - Query
775
#                   $options        - Ref to a hash of options
776
#                                       sql     - show sql
777
#                                       data    - show data
778
#                                       dump    - show results
779
#                                       oneRow  - Only feth one row
780
#                                       error   - Must find data
781
#                                       
782
# Returns         : 
783
#
784
sub getDataFromRm
785
{
786
    my ($name,$m_sqlstr, $options ) = @_;
787
    my @row;
788
    my $data;
789
 
790
    if (ref $options ne 'HASH') {
791
        $options = {}; 
792
    }
793
 
794
    if ($options->{sql}) {
795
        Message("$name: $m_sqlstr")
796
    }
797
    my $sth = $RM_DB->prepare($m_sqlstr);
798
    if ( defined($sth) )
799
    {
800
        if ( $sth->execute( ) ) {
801
            if ( $sth->rows ) {
802
                while ( @row = $sth->fetchrow_array ) {
803
                    if ($options->{data}) {
804
                        Message ("$name: @row");
805
                    }
806
                    #Debug0("$name: @row");
807
                    push @{$data}, [@row];
808
 
809
                    last if $options->{oneRow};
810
                }
811
            }
812
            $sth->finish();
813
        } else {
814
            Error("Execute failure:$name: $m_sqlstr", $sth->errstr() );
815
        }
816
    } else {
817
        Error("Prepare failure:$name" );
818
    }
819
 
820
    if (!$data && $options->{error}) {
821
        Error( $options->{error} );
822
    }
823
 
824
    if ($data && $options->{oneRow}) {
825
        $data = $data->[0];
826
    }
827
 
828
    if ($options->{dump}) {
829
        DebugDumpData("$name", $data);
830
    }
831
    return $data;
832
}
833
 
834
#-------------------------------------------------------------------------------
835
# Function        : saveLocalData 
836
#
837
# Description     : Saves a hash of data to disk 
838
#
839
# Inputs          : 
840
#
841
# Returns         : 
842
#
843
sub saveLocalData
844
{
845
    #
846
    #   Dump out the configuration information
847
    #
848
    my $fh = ConfigurationFile::New( $localDataStore);
849
 
850
    $fh->DumpData( "\n# rmData\n#\n", "rmData", \%rmData );
851
    $fh->Close();
852
 
853
    DebugDumpData("rmData", \%rmData);
854
}
855
 
856
#-------------------------------------------------------------------------------
857
# Function        : restoreLocalData 
858
#
859
# Description     : Read in the locally preserved data 
860
#
861
# Inputs          : 
862
#
863
# Returns         : 
864
#
865
sub restoreLocalData
866
{
867
    if (-f $localDataStore) {
868
        require ( $localDataStore );
869
    } else {
870
        Error ("Extracted data not found: $localDataStore");
871
    }
872
}
873
 
874
#-------------------------------------------------------------------------------
875
#   Documentation
876
#
877
 
878
=pod
879
 
880
=for htmltoc    GENERAL::ClearCase::
881
 
882
=head1 NAME
883
 
884
rmMerge_suck - Inject Package-Version info into RM from a previous extraction
885
 
886
=head1 SYNOPSIS
887
 
888
jats rmMerge_spit [options] PackageName PackageVersion
889
 
890
 Options:
891
    -help              - brief help message
892
    -help -help        - Detailed help message
893
    -man               - Full documentation
894
    -live              - Operation on Live data
895
    -prev=txt          - Prevous package version
896
    -[no]placeKeeper   - Only partial package creation
897
    -[no]history       - Append a text summary of the package history
898
    -newPackage        - Special Handling for a new package
899
    -[no]Sloppy        - Ignore packages that can't be found in the Release
900
 
901
=head1 OPTIONS
902
 
903
=over 8
904
 
905
=item B<-help>
906
 
907
Print a brief help message and exits.
908
 
909
=item B<-help -help>
910
 
911
Print a detailed help message with an explanation for each option.
912
 
913
=back
914
 
915
=head2 OPTIONS
916
 
917
=over
918
 
919
=item -placeKeeper
920
 
921
This mode will only insert some of the package information. Suffiecient to preserve the
922
version number.
923
 
924
The dependencies are not imported. The package will not build.
925
 
926
Used to capture package-versions with some history.
927
 
928
=item -history
929
 
930
This option will cause a textual summary of the packages history to be added created.
931
 
932
The summary track non-ripple builds back to the Release Manager split.
933
 
934
=item -newPackage
935
 
936
Enable special handling of a new package. In particular the Previous version will be set to null.
937
 
938
=back
939
 
940
=head1 EXAMPLE
941
 
942
jats eprog rmMerge_spit PackageName PackageVersion
943
 
944
=cut
945
 
946