add skip_dcontext_suffix to skip CDRs with dcontext ending in a definable string...
[freeside.git] / FS / FS / part_export / test.pm
1 package FS::part_export::test;
2
3 use strict;
4 use vars qw(%options %info);
5 use Tie::IxHash;
6 use base qw(FS::part_export);
7
8 tie %options, 'Tie::IxHash',
9   'result'  => { label    => 'Result',
10                  type     => 'select',
11                  options  => [ 'success', 'failure', 'exception' ],
12                  default  => 'success',
13                },
14   'errormsg'=> { label    => 'Error message',
15                  default  => 'Test export' },
16   'insert'  => { label    => 'Insert', type => 'checkbox', default => 1, },
17   'delete'  => { label    => 'Delete', type => 'checkbox', default => 1, },
18   'replace' => { label    => 'Replace',type => 'checkbox', default => 1, },
19   'suspend' => { label    => 'Suspend',type => 'checkbox', default => 1, },
20   'unsuspend'=>{ label => 'Unsuspend', type => 'checkbox', default => 1, },
21   'get_dids_npa_select' => { label => 'DIDs by NPA', type => 'checkbox' },
22 ;
23
24 %info = (
25   'svc'     => [ qw(svc_acct svc_broadband svc_phone svc_domain) ],
26   'desc'    => 'Test export for development',
27   'options' => \%options,
28   'notes'   => <<END,
29 <P>Test export.  Do not use this in production systems.</P>
30 <P>This export either always succeeds, always fails (returning an error),
31 or always dies, according to the "Result" option.  It does nothing else; the
32 purpose is purely to simulate success or failure within an export module.</P>
33 <P>The checkbox options can be used to turn the export off for certain
34 actions, if this is needed.</P>
35 <P>This export will produce a small set of DIDs, in either Alabama (if the
36 "DIDs by NPA" option is on) or California (if not).</P>
37 END
38 );
39
40 sub export_insert {
41   my $self = shift;
42   $self->run(@_) if $self->option('insert');
43 }
44
45 sub export_delete {
46   my $self = shift;
47   $self->run(@_) if $self->option('delete');
48 }
49
50 sub export_replace {
51   my $self = shift;
52   $self->run(@_) if $self->option('replace');
53 }
54
55 sub export_suspend {
56   my $self = shift;
57   $self->run(@_) if $self->option('suspend');
58 }
59
60 sub export_unsuspend {
61   my $self = shift;
62   $self->run(@_) if $self->option('unsuspend');
63 }
64
65 sub run {
66   my $self = shift;
67   my $svc_x = shift;
68   my $result = $self->option('result');
69   if ( $result eq 'failure' ) {
70     return $self->option('errormsg');
71   } elsif ( $result eq 'exception' ) {
72     die $self->option('errormsg');
73   } else {
74     return '';
75   }
76 }
77
78 sub can_get_dids { 1 }
79
80 sub get_dids_npa_select {
81   my $self = shift;
82   $self->option('get_dids_npa_select') ? 1 : 0;
83 }
84
85 # we don't yet have tollfree
86
87 my $dids_by_npa = {
88   'states' => [ 'AK', 'AL' ],
89   # states
90   'AK' => [],
91   'AL' => [ '205', '998', '999' ],
92   # NPAs
93   '205' => [ 'ALABASTER (205-555-XXXX)', # an NPA-NXX
94              'EMPTY (205-998-XXXX)',
95              'INVALID (205-999-XXXX)',
96              'ALBERTVILLE, AL', # a ratecenter
97            ],
98   '998' => [],
99   '999' => undef,
100   # exchanges
101   '205555' => 
102     [
103       '2055550101',
104       '2055550102'
105     ],
106   '205998' => [],
107   '205999' => undef,
108   # ratecenters
109   'ALBERTVILLE' => [
110     '2055550111',
111     '2055550112',
112   ],
113 },
114
115 my $dids_by_region = {
116   'states' => [ 'CA', 'CO' ],
117   'CA' => [ 'CALIFORNIA',
118             'EMPTY',
119             'INVALID'
120           ],
121   'CO' => [],
122   # regions
123   'CALIFORNIA' => [
124     '4155550200',
125     '4155550201',
126   ],
127   'EMPTY' => [],
128   'INVALID' => undef,
129 };
130
131 sub get_dids {
132   my $self = shift;
133   my %opt = @_;
134   my $data = $self->get_dids_npa_select ? $dids_by_npa : $dids_by_region;
135
136   my $key;
137   if ( $opt{'exchange'} ) {
138     $key = $opt{'areacode'} . $opt{'exchange'};
139   } else {
140     $key =    $opt{'ratecenter'}
141           ||  $opt{'areacode'}
142           ||  $opt{'region'}
143           ||  $opt{'state'}
144           ||  'states';
145   }
146   if ( defined $data->{ $key } ) {
147     return $data->{ $key };
148   } else {
149     die "[test] '$key' is invalid\n";
150   }
151 }
152
153 1;