| 1 | package StoredHash::ARSMeta; | ||
| 2 | |||
| 3 | use ARS; | ||
| 4 | use Data::Dumper; | ||
| 5 | |||
| 6 | use strict; | ||
| 7 | use warnings; | ||
| 8 | |||
| 9 | sub nofilter {1;} # To Storehash ? | ||
| 10 | #=head2 meta($shp, %opts) | ||
| 11 | #Get Information about Remedy Schema. | ||
| 12 | #=cut | ||
| 13 | # ars_GetListSchema(ctrl, [changedSince, schemaType, name]) | ||
| 14 | sub meta { | ||
| 15 | my ($p, %c) = @_; | ||
| 16 | if (!$p->isa('StoredHash::ARS')) {die("StoredHash not passed");} | ||
| 17 | my $fcb = $c{'filter'} || sub { | ||
| 18 | my ($h) = @_; | ||
| 19 | my $fn = $h->{'fieldName'}; | ||
| 20 | if ($fn =~ /^zTmp/i) {return(0);} | ||
| 21 | if ($fn =~ /^btn:/) {return(0);} | ||
| 22 | #if ($fn =~ /^btn:/) {return(0);} | ||
| 23 | #if ($fn =~ /^TXT:/i) {return(0);} | ||
| 24 | if ($h->{'dataType'} eq 'control') {return(0);} | ||
| 25 | #if ($e->{'dataType'} eq 'trim') {return(0);} # Fset ? | ||
| 26 | 1; | ||
| 27 | }; | ||
| 28 | my $debug = $p->{'debug'}; | ||
| 29 | my ($sc, $ctrl) = @$p{'table', 'dbh'}; | ||
| 30 | if (!$sc || !$ctrl) {die("Tab or ctl Missing ()\n");} | ||
| 31 | # OR StoredHash::ARSMeta->can($fcb); | ||
| 32 | if (ref($fcb) ne 'CODE') {die("Filter NOT Code");} | ||
| 33 | |||
| 34 | # Attr - ALl or explicit from 'attr' | ||
| 35 | my $attr = $c{'attr'}; | ||
| 36 | if (ref($attr) eq 'ARRAY') {} | ||
| 37 | # | ||
| 38 | else { | ||
| 39 | #my %fld = ars_GetFieldTable($ctrl, $sc); | ||
| 40 | #my %fldr = reverse(%fld); | ||
| 41 | # changedsince=0 ... fieldtype | ||
| 42 | if ($debug) {print(STDERR "Calling ars_GetListField($ctrl, '$sc')");} | ||
| 43 | # [ERROR] Cannot open catalog; Message number = 161 () (ARERR #161) | ||
| 44 | my @fld = ars_GetListField($ctrl,$sc); | ||
| 45 | if ($ars_errstr) {die("Error with ars_GetListField(): $ars_errstr");} | ||
| 46 | if ($debug) {print(Dumper(\@fld));} | ||
| 47 | $attr = \@fld; | ||
| 48 | |||
| 49 | } | ||
| 50 | my $acnt = scalar(@$attr); | ||
| 51 | if ($debug) {print(STDERR "$acnt attrs for '$sc'\n");} | ||
| 52 | ######## | ||
| 53 | my @fattr = (); | ||
| 54 | my $skipcnt = 0; | ||
| 55 | for my $aid (@$attr) { | ||
| 56 | |||
| 57 | my $h = ars_GetField($ctrl, $sc, $aid); | ||
| 58 | #my $fn = $h->{'fieldName'}; | ||
| 59 | # print("SKIP: $fn\n"); ~28% | ||
| 60 | if (!$fcb->($h)) {$skipcnt++;next;} | ||
| 61 | if ($c{'std'}) {$h = stdmeta($h, 'schema' => $sc);} | ||
| 62 | #push(@fattr, $h); | ||
| 63 | push(@fattr, $h); | ||
| 64 | } | ||
| 65 | if ($p->{'debug'}) {print(STDERR "$skipcnt attrs skipped by filter\n");} | ||
| 66 | #DEBUG:print(Dumper(\@fattr)); | ||
| 67 | #DEBUG:print("Skipped $skipcnt (Valid: ".scalar(@fattr).")\n"); | ||
| 68 | return(\@fattr); | ||
| 69 | } | ||
| 70 | |||
| 71 | # Helper for meta() to modify Field Information. | ||
| 72 | sub stdmeta { | ||
| 73 | my ($h, %c) = @_; | ||
| 74 | my $sc = $c{'schema'} || 'Unknown_'.time(); | ||
| 75 | no warnings; | ||
| 76 | delete($h->{'displayInstanceList'}); | ||
| 77 | # Owners | ||
| 78 | delete($h->{'owner'});delete($h->{'lastChanged'}); | ||
| 79 | delete($h->{'timestamp'}); | ||
| 80 | if ($h->{'helpText'}) {$h->{'helpText'} =~ s/\s+$//;} | ||
| 81 | #DEBUG:print(Dumper($h)); | ||
| 82 | # 'helpText' | ||
| 83 | # | ||
| 84 | # $h->{'option'} 1..4 | ||
| 85 | # - 1 limit: dataType=4(char) maxLength 254 'fieldName' => 'Submitted By' | ||
| 86 | # sometimes: 'dataType' => 6, has limit.enumLimits.regularList 'fieldName' => 'Status' | ||
| 87 | # - 2 (sometimes E) | ||
| 88 | # sometimes no enum, 'maxLength' => 254, 'fieldName' => 'Assignee Login Name' | ||
| 89 | # no enuym, 'maxLength' => 30,'dataType' => 4, 'fieldName' => 'Assignee Group' | ||
| 90 | # example: 'fieldName' => 'Phone Number' | ||
| 91 | # - 3 limit: dataType=4(char) no emums 'fieldName' => 'Case ID+' | ||
| 92 | # sometimes limit: undef 'fieldName' => 'Arrival Time' | ||
| 93 | # - 4 'limit' => undef, 'fieldName' => 'Submit' 'dataType' => 'control', | ||
| 94 | # Seems to be controls only ('fieldName' => 'Query''defaultVal' => undef,) | ||
| 95 | # Sometimes limit => {...} 'fieldName' => 'Search Bar' 'dataType' => 'char', | ||
| 96 | # 'fieldName' => 'Results List' 'numColumns' => 12, 'dataType' => 'table', | ||
| 97 | # Control in Remedy means button (action), these buttons have 'limit' => undef | ||
| 98 | # 'dataType' => 'table', Means listview | ||
| 99 | # 'limit'->'schema' => '@', means current schema (for datatype table) | ||
| 100 | # 'limit'->'qualifier' = {} | ||
| 101 | # 'limit'->'charmenu' = "HDP:HPD-Inventory Users"; gives optsrc 'fieldName' => 'User Name_INV' | ||
| 102 | # Could collect associated / related tables from 'limit'.'charMenu' | ||
| 103 | # (Example 'fieldName' => 'Category') | ||
| 104 | # 'limit'->'match' = 'equal' behaviour on search ? | ||
| 105 | # 'dataType' => 'diary', Child ent / events on entry | ||
| 106 | # dataType on 3 levels | ||
| 107 | # - Top: time,char,integer,real,enum, | ||
| 108 | # control,table,diary,column,page,trim,view,currency,page_holder | ||
| 109 | # - $h->{'limit'}{'dataType'}: 2 (integ.),3(real),4(char),6(enum),33(table) | ||
| 110 | # 34(column),42(view) | ||
| 111 | # ('dataType' => 6, 'enumLimits') | ||
| 112 | # 'dataType' => 'trim', in fielname: 'fieldName' => 'box_top' (fieldset) | ||
| 113 | # 'defaultVal' 'fieldName' 'fieldId' | ||
| 114 | # diary examples: work Log ,'Audit Trail' | ||
| 115 | # Limit / Constrain | ||
| 116 | my $lim = $h->{'limit'}; | ||
| 117 | my $opts; | ||
| 118 | #'createMode' => 'protected', | ||
| 119 | my $uit = 'textinput'; # Maybe after all others ... | ||
| 120 | my $uil = 16; | ||
| 121 | # Enum opts | ||
| 122 | my $optse = $lim->{'enumLimits'}->{'regularList'}; | ||
| 123 | # Schema ? | ||
| 124 | #my $optss = $lim->{'enumLimits'}->{'schema'}; # ??? # Self Ref ? | ||
| 125 | # Fk opts | ||
| 126 | my $optsf = $lim->{'charMenu'}; | ||
| 127 | if ($optsf) {$opts = [$optsf,'?','?'];$uit = 'optionmenu';} | ||
| 128 | elsif ($optse) {$opts = $optse;$uit = 'optionmenu';} | ||
| 129 | else {$opts = undef;} | ||
| 130 | # colLength for col maxLength for prim. | ||
| 131 | my $dlen = $lim->{'maxLength'} || $lim->{'colLength'}; # || 16; | ||
| 132 | #if ($opts) {} | ||
| 133 | #$h->{'fieldMap'}->{'fieldType'}; | ||
| 134 | # ^@USER^@' | ||
| 135 | #if ($h->{'defaultVal'} =~ //) {} | ||
| 136 | # UIT Overr. | ||
| 137 | # Many Date field configured as 'char' | ||
| 138 | # || $h->{'fieldName'} =~ /Date/ | ||
| 139 | if ($h->{'dataType'} =~ /time/) {$uit = 'timewidget';$uil = 20;$dlen = 20;} | ||
| 140 | my %ma; | ||
| 141 | # Map to nat | ||
| 142 | @ma{'tabname','attrname','alias','dtype','dlen','uitype','uilen', | ||
| 143 | 'defval', | ||
| 144 | 'optsrc',} = | ||
| 145 | @$h{'','fieldId','fieldName','dataType','','','', | ||
| 146 | 'defaultVal', | ||
| 147 | '',}; | ||
| 148 | my %tt = ('real' => 'float', 'time' => 'datetime',); #'' => '', | ||
| 149 | #if (my $nt = $tt{$ma{'dtype'}} ) {$ma{'dtype'} = $nt;} | ||
| 150 | @ma{'tabname','dlen','uitype','uilen','optsrc',} = ($sc, $dlen, $uit, $uil, $opts); | ||
| 151 | return(\%ma); | ||
| 152 | } | ||
| 153 | |||
| 154 | # Doc: (in 'limit'.charmenu | ||
| 155 | # Category: HPD:HelpDeskCategory | ||
| 156 | # Type: SHR:Type | ||
| 157 | # Item: SHR:Item | ||
| 158 | #'prop' => 230, | ||
| 159 | # 'value' => '6\\0\\New\\1\\Assigned\\2\\Work In Progress\\3\\Pending\\4\\Resolved\\5\\Closed', | ||
| 160 | # 'valueType' => 'char' | ||
| 161 | 1; | ||
| 162 | ################## JUNK ################ | ||
| 163 | #if (0) { | ||
| 164 | # my $arsconn = new ARS(-server => $rcred->{'host'}, -username => $rcred->{'uid'}, | ||
| 165 | # -password => $rcred->{'pwd'}); | ||
| 166 | # my $f = $arsconn->openForm(-form => $sc); | ||
| 167 | # delete($f->{'connection'}); | ||
| 168 | # } | ||
| 169 |