X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_export%2Fprizm.pm;h=75b10a763e16d79eb5ebd0664350051ad519ac36;hb=df82b9e2945a50797d72ea42d6c75f869e6c5959;hp=a8ea02a09448fd53dda0c69b7302c1eb0a888639;hpb=c9e9a041acb5066cfd3c67b94a695df8efc03844;p=freeside.git diff --git a/FS/FS/part_export/prizm.pm b/FS/FS/part_export/prizm.pm index a8ea02a09..75b10a763 100644 --- a/FS/FS/part_export/prizm.pm +++ b/FS/FS/part_export/prizm.pm @@ -2,7 +2,7 @@ package FS::part_export::prizm; use vars qw(@ISA %info %options $DEBUG); use Tie::IxHash; -use FS::Record qw(fields); +use FS::Record qw(fields dbh); use FS::part_export; @ISA = qw(FS::part_export); @@ -13,20 +13,82 @@ tie %options, 'Tie::IxHash', 'user' => { label => 'Northbound username', default=>'nbi' }, 'password' => { label => 'Password', default => '' }, 'ems' => { label => 'Full EMS', type => 'checkbox' }, + 'always_bam' => { label => 'Always activate/suspend authentication', type => 'checkbox' }, + 'element_name_length' => { label => 'Size of siteName (best left blank)' }, ; +my $notes = <<'EOT'; +Real-time export of svc_broadband, cust_pkg, and cust_main +record data to Motorola +Canopy Prizm +software via the Northbound interface.

+ +Freeside will attempt to create an element in an existing network with the +values provided in svc_broadband. Of particular interest are + + +In addition freeside attempts to set the service plan name in prizm to the +name of the package in which the service resides. + +The service is associated with a customer in prizm as well, and freeside +will create the customer should none already exist with import id matching +the freeside customer number. The following fields are set. + + + + Additionally set on the element are + + +Freeside provisions, suspends, and unsuspends elements BAM only unless the +'Full EMS' checkbox is checked.

+ +When freeside provisions an element the siteName is copied internally by +prizm in such a manner that it is possible for the value to exceed the size +of the column used in the prizm database. Therefore freeside truncates +by default this value to 50 characters. It is thought that this +column is the account_name column of the element_user_account table. It +may be possible to lift this limit by modifying the prizm database and +setting a new appropriate value on this export. This is untested and +possibly harmful. + +EOT + %info = ( 'svc' => 'svc_broadband', 'desc' => 'Real-time export to Northbound Interface', 'options' => \%options, 'nodomain' => 'Y', - 'notes' => 'These are notes.' + 'notes' => $notes, ); sub prizm_command { my ($self,$namespace,$method) = (shift,shift,shift); - eval "use Net::Prizm qw(CustomerInfo PrizmElement);"; + eval "use Net::Prizm 0.04 qw(CustomerInfo PrizmElement);"; die $@ if $@; my $prizm = new Net::Prizm ( @@ -42,7 +104,7 @@ sub prizm_command { sub queued_prizm_command { # subroutine my( $url, $user, $password, $namespace, $method, @args ) = @_; - eval "use Net::Prizm qw(CustomerInfo PrizmElement);"; + eval "use Net::Prizm 0.04 qw(CustomerInfo PrizmElement);"; die $@ if $@; my $prizm = new Net::Prizm ( @@ -138,10 +200,14 @@ sub _export_insert { # } # } + my $element_name_length = 50; + $element_name_length = $1 + if $self->option('element_name_length') =~ /^\s*(\d+)\s*$/; $err_or_som = $self->prizm_command('NetworkIfService', 'addProvisionedElement', $networkid, $svc->mac_addr, - $name, # we fix this below (bug in prizm?) + substr($name . " " . $svc->description, + 0, $element_name_length), $location, $contact, sprintf("%032X", $svc->authkey), @@ -224,6 +290,10 @@ sub _export_insert { sub _export_delete { my( $self, $svc ) = ( shift, shift ); + my $oldAutoCommit = $FS::UID::AutoCommit; + local $FS::UID::AutoCommit = 0; + my $dbh = dbh; + my $cust_pkg = $svc->cust_svc->cust_pkg; my $depend = []; @@ -233,7 +303,7 @@ sub _export_delete { 'svcnum' => $svc->svcnum, 'job' => 'FS::part_export::prizm::queued_prizm_command', }; - $queue->insert( + my $error = $queue->insert( ( map { $self->option($_) } qw( url user password ) ), 'CustomerIfService', @@ -242,10 +312,27 @@ sub _export_delete { $cust_pkg->custnum, 0, $svc->mac_addr, - ) && push @$depend, $queue->jobnum; + ); + + if ($error) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + + push @$depend, $queue->jobnum; + } + + my $err_or_queue = + $self->queue_statuschange('deleteElement', $depend, $svc, 1); + + unless (ref($err_or_queue)) { + $dbh->rollback if $oldAutoCommit; + return $err_or_queue; } - $self->queue_statuschange('deleteElement', $depend, $svc, 1); + $dbh->commit or die $dbh->errstr if $oldAutoCommit; + + ''; } sub _export_replace { @@ -314,14 +401,74 @@ sub _export_replace { sub _export_suspend { my( $self, $svc ) = ( shift, shift ); + my $depend = []; my $ems = $self->option('ems') ? 1 : 0; - $self->queue_statuschange('suspendNetworkElements', [], $svc, 1, $ems); + my $err_or_queue = ''; + + my $oldAutoCommit = $FS::UID::AutoCommit; + local $FS::UID::AutoCommit = 0; + my $dbh = dbh; + + $err_or_queue = + $self->queue_statuschange('suspendNetworkElements', [], $svc, 1, $ems); + unless (ref($err_or_queue)) { + $dbh->rollback if $oldAutoCommit; + return $err_or_queue; + } + push @$depend, $err_or_queue->jobnum; + + if ($ems && $self->option('always_bam')) { + $err_or_queue = + $self->queue_statuschange('suspendNetworkElements', $depend, $svc, 1, 0); + unless (ref($err_or_queue)) { + $dbh->rollback if $oldAutoCommit; + return $err_or_queue; + } + } + + $dbh->commit or die $dbh->errstr if $oldAutoCommit; + + ''; } sub _export_unsuspend { my( $self, $svc ) = ( shift, shift ); + my $depend = []; my $ems = $self->option('ems') ? 1 : 0; - $self->queue_statuschange('activateNetworkElements', [], $svc, 1, $ems); + my $err_or_queue = ''; + + my $oldAutoCommit = $FS::UID::AutoCommit; + local $FS::UID::AutoCommit = 0; + my $dbh = dbh; + + if ($ems && $self->option('always_bam')) { + $err_or_queue = + $self->queue_statuschange('activateNetworkElements', [], $svc, 1, 0); + unless (ref($err_or_queue)) { + $dbh->rollback if $oldAutoCommit; + return $err_or_queue; + } + push @$depend, $err_or_queue->jobnum; + } + + $err_or_queue = + $self->queue_statuschange('activateNetworkElements', $depend, $svc, 1, $ems); + unless (ref($err_or_queue)) { + $dbh->rollback if $oldAutoCommit; + return $err_or_queue; + } + + $dbh->commit or die $dbh->errstr if $oldAutoCommit; + + ''; +} + +sub export_links { + my( $self, $svc, $arrayref ) = ( shift, shift, shift ); + + push @$arrayref, 'SM'; + + ''; } sub queue_statuschange { @@ -333,7 +480,7 @@ sub queue_statuschange { 'svcnum' => $svc->svcnum, 'job' => 'FS::part_export::prizm::statuschange', }; - $queue->insert( + my $error = $queue->insert( ( map { $self->option($_) } qw( url user password ) ), $method, @@ -341,18 +488,19 @@ sub queue_statuschange { @args, ); - if ($queue->jobnum) { # successful insertion + unless ($error) { # successful insertion foreach my $job ( @$jobs ) { - $queue->depend_insert($job); + $error ||= $queue->depend_insert($job); } } + $error or $queue; } sub statuschange { # subroutine my( $url, $user, $password, $method, $mac_addr, @args) = @_; - eval "use Net::Prizm qw(CustomerInfo PrizmElement);"; + eval "use Net::Prizm 0.04 qw(CustomerInfo PrizmElement);"; die $@ if $@; my $prizm = new Net::Prizm (