| 1 | package OpenInteract2::Action::Common; | ||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||
| 3 | # $Id: Common.pm,v 1.25 2005/03/18 04:09:48 lachoy Exp $ | ||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 6 | 5 | ▶ | use base qw( OpenInteract2::Action ); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 7 | 5 | ▶ | use Log::Log4perl qw( get_logger ); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use OpenInteract2::Constants qw( :log ); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 9 | 5 | ▶ | use OpenInteract2::Context qw( CTX ); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 10 | 5 | ▶ | use OpenInteract2::Exception qw( oi_error oi_security_error ); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||
| 12 | 5 | $OpenInteract2::Action::Common::VERSION = sprintf("%d.%02d", q$Revision: 1.25 $ =~ /(\d+)\.(\d+)/); | |||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||
| 14 | 5 | my ( $log ); | |||||||||||||||||||||||||||||||||
| 15 | 5 | $OpenInteract2::Action::Common::AUTOLOAD = ''; | |||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||
| 17 | 5 | my %COMMON_TASKS = ( | |||||||||||||||||||||||||||||||||
| 18 | search_form => q{Capability to display a search form is not built into action '%s'.}, | ||||||||||||||||||||||||||||||||||
| 19 | search => q{Search capability is not built into action '%s'.}, | ||||||||||||||||||||||||||||||||||
| 20 | display => q{Display capability is not built into action '%s'.}, | ||||||||||||||||||||||||||||||||||
| 21 | display_new => q{Capability to display a form for a new record is not built into action '%s'.}, | ||||||||||||||||||||||||||||||||||
| 22 | add => q{Add capability is not built into action '%s'.}, | ||||||||||||||||||||||||||||||||||
| 23 | display_form => q{Capability to display a form for an existing record is not built into action '%s'.}, | ||||||||||||||||||||||||||||||||||
| 24 | update => q{Update capability is not built into action '%s'.}, | ||||||||||||||||||||||||||||||||||
| 25 | remove => q{Remove capability is not built into action '%s'.}, | ||||||||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||
| 28 | # TODO: We should probably have the messages be put into a template, | ||||||||||||||||||||||||||||||||||
| 29 | # or the template have the entire message... | ||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||
| 32 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||
| 33 | 0 | my $request = $OpenInteract2::Action::Common::AUTOLOAD; | |||||||||||||||||||||||||||||||||
| 34 | 0 | $request =~ s/.*://; | |||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | $log ||= get_logger( LOG_ACTION ); | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$log ||= get_logger("OI2.ACTION")
MC/DC0%0/2
$log ||= get_logger("OI2.ACTION")
$log
get_logger("OI2.ACTION")
Truth table0%0/3
A ||= B
A= $logB= get_logger("OI2.ACTION")
| |||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | if ( my $msg = $COMMON_TASKS{ $request } ) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 38 | 0 | return sprintf( $msg, $self->name ); | |||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||
| 40 | elsif ( $request =~ /^_/ ) { | ||||||||||||||||||||||||||||||||||
| 41 | 0 | my $msg = sprintf( "Private function '%s' not found in action %s.", | |||||||||||||||||||||||||||||||||
| 42 | $request, $self->name ); | ||||||||||||||||||||||||||||||||||
| 43 | 0 | $log->warn( $msg ); | |||||||||||||||||||||||||||||||||
| 44 | 0 | return $msg; | |||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||
| 46 | else { | ||||||||||||||||||||||||||||||||||
| 47 | 0 | my $msg = sprintf( "Task '%s' not available in action %s", | |||||||||||||||||||||||||||||||||
| 48 | $request, $self->name ); | ||||||||||||||||||||||||||||||||||
| 49 | # cut down on noise in log messages... | ||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | if ( $request eq 'DESTROY' ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | $log->is_debug && $log->debug( $msg ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||
| 53 | else { | ||||||||||||||||||||||||||||||||||
| 54 | 0 | $log->warn( $msg ); | |||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||
| 56 | 0 | return $msg | |||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | sub common_error { | ||||||||||||||||||||||||||||||||
|
Subroutine
common_error: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 61 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||
| 62 | 0 | my $error_template = $self->_common_error_template; | |||||||||||||||||||||||||||||||||
| 63 | 0 | return $self->generate_content( | |||||||||||||||||||||||||||||||||
| 64 | {}, { name => $error_template } ); | ||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | sub _common_error_template { | ||||||||||||||||||||||||||||||||
|
Subroutine
_common_error_template: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 68 | 0 | return 'common_action_error'; | |||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | sub _common_set_defaults { | ||||||||||||||||||||||||||||||||
|
Subroutine
_common_set_defaults: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||
| 72 | 0 | my ( $self, $defaults ) = @_; | |||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | return unless ( ref $defaults eq 'HASH' ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | $log ||= get_logger( LOG_ACTION ); | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$log ||= get_logger("OI2.ACTION")
MC/DC0%0/2
$log ||= get_logger("OI2.ACTION")
$log
get_logger("OI2.ACTION")
Truth table0%0/3
A ||= B
A= $logB= get_logger("OI2.ACTION")
| |||||||||||||||||||||||||||||||||||
| 75 | 0 | my $tag = join( ' -> ', $self->name, $self->task ); | |||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | while ( my ( $key, $value ) = each %{ $defaults } ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | if ( $self->param( $key ) ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | $log->is_debug && | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 79 | $log->debug( "NOT settting default for '$tag' = '$key', value ", | ||||||||||||||||||||||||||||||||||
| 80 | "already exists '", $self->param( $key ), "'" ); | ||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||
| 82 | else { | ||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | $log->is_debug && | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 84 | $log->debug( "Setting default for '$tag' = '$key' '$value'" ); | ||||||||||||||||||||||||||||||||||
| 85 | 0 | $self->param( $key, $value ); | |||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||
| 88 | 0 | return; | |||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||
| 91 | ######################################## | ||||||||||||||||||||||||||||||||||
| 92 | # CHECKS | ||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | sub _common_check_object_class { | ||||||||||||||||||||||||||||||||
|
Subroutine
_common_check_object_class: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||
| 95 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||
| 96 | 0 | my $object_type = $self->param( 'c_object_type' ); | |||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | $log ||= get_logger( LOG_ACTION ); | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$log ||= get_logger("OI2.ACTION")
MC/DC0%0/2
$log ||= get_logger("OI2.ACTION")
$log
get_logger("OI2.ACTION")
Truth table0%0/3
A ||= B
A= $logB= get_logger("OI2.ACTION")
| |||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | unless ( $object_type ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 99 | 0 | $log->warn( "No object type specified" ); | |||||||||||||||||||||||||||||||||
| 100 | 0 | $self->add_error_key( 'action.error.no_object_type' ); | |||||||||||||||||||||||||||||||||
| 101 | 0 | return 1; | |||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||
| 103 | 0 | my $object_class = eval { CTX->lookup_object( $object_type ) }; | |||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | if ( $@ or ! $object_class ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$@ or not $object_class
MC/DC0%0/2
$@ or not $object_class
$@
not $object_class
Truth table0%0/3
A or not(B)
A= $@B= not $object_class
| |||||||||||||||||||||||||||||||||||
| 105 | 0 | $log->warn( "No object class for '$object_type'" ); | |||||||||||||||||||||||||||||||||
| 106 | 0 | $self->add_error_key( 'action.error.no_class_for_type', $object_type ); | |||||||||||||||||||||||||||||||||
| 107 | 0 | return 1; | |||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||
| 109 | 0 | $self->param( c_object_class => $object_class ); | |||||||||||||||||||||||||||||||||
| 110 | 0 | return 0; | |||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | sub _common_check_id_field { | ||||||||||||||||||||||||||||||||
|
Subroutine
_common_check_id_field: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||
| 114 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | $log ||= get_logger( LOG_ACTION ); | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$log ||= get_logger("OI2.ACTION")
MC/DC0%0/2
$log ||= get_logger("OI2.ACTION")
$log
get_logger("OI2.ACTION")
Truth table0%0/3
A ||= B
A= $logB= get_logger("OI2.ACTION")
| |||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||
| 117 | 0 | my $object_class = $self->param( 'c_object_class' ); | |||||||||||||||||||||||||||||||||
| 118 | 0 | my $id_field = eval { $object_class->id_field }; | |||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | if ( ! $id_field or $@ ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $id_field or $@
MC/DC0%0/2
not $id_field or $@
not $id_field
$@
Truth table0%0/3
not(A) or B
A= not $id_fieldB= $@
| |||||||||||||||||||||||||||||||||||
| 120 | 0 | $log->warn( "No ID field for '$object_class'" ); | |||||||||||||||||||||||||||||||||
| 121 | 0 | $self->add_error_key( 'action.error.no_id_field' ); | |||||||||||||||||||||||||||||||||
| 122 | 0 | return 1; | |||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||
| 124 | 0 | $self->param( c_id_field => $id_field ); | |||||||||||||||||||||||||||||||||
| 125 | 0 | return 0; | |||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | sub _common_check_id { | ||||||||||||||||||||||||||||||||
|
Subroutine
_common_check_id: not called CC=18 SCAR=58.3
| |||||||||||||||||||||||||||||||||||
| 129 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | $log ||= get_logger( LOG_ACTION ); | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$log ||= get_logger("OI2.ACTION")
MC/DC0%0/2
$log ||= get_logger("OI2.ACTION")
$log
get_logger("OI2.ACTION")
Truth table0%0/3
A ||= B
A= $logB= get_logger("OI2.ACTION")
| |||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||
| 132 | # First see if the object itself has been defined; if so we don't | ||||||||||||||||||||||||||||||||||
| 133 | # care if the ID has been set | ||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | if ( my $object = $self->param( 'c_object' ) ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | return 0 if ( $object->is_saved ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||
| 139 | # Next, find the ID | ||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||
| 141 | 0 | my $id = $self->param( 'c_id' ); | |||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | if ( $id ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 143 | 0 | return 0; | |||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||
| 146 | 0 | my $request = CTX->request; | |||||||||||||||||||||||||||||||||
| 147 | 0 | my $id_field = $self->param( 'c_id_field' ); | |||||||||||||||||||||||||||||||||
| 148 | 0 | my ( $alt_id_field ); | |||||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | if ( ! defined $id and $id_field ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $id and $id_field
MC/DC0%0/2
not defined $id and $id_field
not defined $id
$id_field
Truth table0%0/3
not(A) and B
A= not defined $idB= $id_field
| |||||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | $id = $self->param( $id_field ) | ||||||||||||||||||||||||||||||||
|
Condition0%0/6
$self->param($id_field) || $request->param($id_field) || $request->param('id')
$self->param($id_field) or $request->param($id_field)
MC/DC0%0/3
$self->param($id_field) || $request->param($id_field) || $request->param('id')
$self->param($id_field)
$request->param($id_field)
$request->param('id')
Truth table0%0/4
A or B || C
A= $self->param($id_field)B= $request->param($id_field)C= $request->param('id')
| |||||||||||||||||||||||||||||||||||
| 151 | || $request->param( $id_field ) | ||||||||||||||||||||||||||||||||||
| 152 | || $request->param( 'id' ); | ||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||
| 155 | # If it's not found using that ID field, see if we've got another | ||||||||||||||||||||||||||||||||||
| 156 | # field mapped to the given ID field in the SPOPS object | ||||||||||||||||||||||||||||||||||
| 157 | # | ||||||||||||||||||||||||||||||||||
| 158 | # For example, in 'group' using LDAP you have: | ||||||||||||||||||||||||||||||||||
| 159 | # | ||||||||||||||||||||||||||||||||||
| 160 | # id_field = cn | ||||||||||||||||||||||||||||||||||
| 161 | # ... | ||||||||||||||||||||||||||||||||||
| 162 | # [group field_map] | ||||||||||||||||||||||||||||||||||
| 163 | # notes = description | ||||||||||||||||||||||||||||||||||
| 164 | # group_id = cn | ||||||||||||||||||||||||||||||||||
| 165 | # name = cn | ||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||
| 167 | # If you pass in: | ||||||||||||||||||||||||||||||||||
| 168 | # /group/display/?group_id=groupname | ||||||||||||||||||||||||||||||||||
| 169 | # this will see that 'group_id' is mapped to 'cn' and find that | ||||||||||||||||||||||||||||||||||
| 170 | # field value and use it | ||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||
| 172 | 0 | ▶ | unless ( defined $id ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 173 | 0 | my $object_class = $self->param( 'c_object_class' ); | |||||||||||||||||||||||||||||||||
| 174 | 0 | ▶ | my $field_map = eval { $object_class->CONFIG->{field_map} } || {}; | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
eval {
do {
$object_class->CONFIG->{'field_map'}
}
} || {}
MC/DC0%0/1
eval {
do {
$object_class->CONFIG->{'field_map'}
}
} || {}
eval {
do {
$object_class->CONFIG->{'field_map'}
}
}
Truth table0%0/2
A
A= eval {
do {
$object_class->CONFIG->{'field_map'}
}
}
| |||||||||||||||||||||||||||||||||||
| 175 | 0 | ▶ | while ( my ( $alt_id_field, $mapped ) = each %{ $field_map } ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 176 | 0 | ▶ | next unless ( $mapped eq $id_field ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 177 | 0 | ▶ | $id = $self->param( $alt_id_field ) | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->param($alt_id_field) || $request->param($alt_id_field)
MC/DC0%0/2
$self->param($alt_id_field) || $request->param($alt_id_field)
$self->param($alt_id_field)
$request->param($alt_id_field)
Truth table0%0/3
A || B
A= $self->param($alt_id_field)B= $request->param($alt_id_field)
| |||||||||||||||||||||||||||||||||||
| 178 | || $request->param( $alt_id_field ); | ||||||||||||||||||||||||||||||||||
| 179 | 0 | ▶ | if ( $id ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 180 | 0 | ▶ | $log->is_debug && | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 181 | $log->debug( "Using mapped ID field '$alt_id_field' ", | ||||||||||||||||||||||||||||||||||
| 182 | "got ID value '$id'" ); | ||||||||||||||||||||||||||||||||||
| 183 | 0 | $self->param( c_id_field => $alt_id_field ); | |||||||||||||||||||||||||||||||||
| 184 | 0 | last; | |||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | if ( defined $id ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 190 | 0 | $self->param( c_id => $id ); | |||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||
| 192 | else { | ||||||||||||||||||||||||||||||||||
| 193 | 0 | $log->warn( "No ID found in '$id_field' or '$alt_id_field'" ); | |||||||||||||||||||||||||||||||||
| 194 | 0 | $self->add_error_key( 'action.error.no_id_value', $id_field ); | |||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | if ( $alt_id_field ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 196 | 0 | $self->add_error_key( 'action.error.no_alt_id_value', $alt_id_field ); | |||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||
| 198 | 0 | return 1; | |||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||
| 200 | 0 | return 0; | |||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | sub _common_check_template_specified { | ||||||||||||||||||||||||||||||||
|
Subroutine
_common_check_template_specified: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||
| 204 | 0 | my ( $self, @template_params ) = @_; | |||||||||||||||||||||||||||||||||
| 205 | 0 | ▶ | $log ||= get_logger( LOG_ACTION ); | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$log ||= get_logger("OI2.ACTION")
MC/DC0%0/2
$log ||= get_logger("OI2.ACTION")
$log
get_logger("OI2.ACTION")
Truth table0%0/3
A ||= B
A= $logB= get_logger("OI2.ACTION")
| |||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||
| 207 | 0 | my $num_errors = 0; | |||||||||||||||||||||||||||||||||
| 208 | 0 | for ( @template_params ) { | |||||||||||||||||||||||||||||||||
| 209 | 0 | ▶ | next unless ( $_ ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 210 | 0 | ▶ | unless ( $self->param( $_ ) ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 211 | 0 | $log->warn( "No value in template parameter '$_'" ); | |||||||||||||||||||||||||||||||||
| 212 | 0 | $self->add_error_key( 'action.error.no_template', $_ ); | |||||||||||||||||||||||||||||||||
| 213 | 0 | $num_errors++; | |||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||
| 216 | 0 | return $num_errors; | |||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | sub _common_check_param { | ||||||||||||||||||||||||||||||||
|
Subroutine
_common_check_param: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||
| 220 | 0 | my ( $self, @params ) = @_; | |||||||||||||||||||||||||||||||||
| 221 | 0 | ▶ | $log ||= get_logger( LOG_ACTION ); | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$log ||= get_logger("OI2.ACTION")
MC/DC0%0/2
$log ||= get_logger("OI2.ACTION")
$log
get_logger("OI2.ACTION")
Truth table0%0/3
A ||= B
A= $logB= get_logger("OI2.ACTION")
| |||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||
| 223 | 0 | my $num_errors = 0; | |||||||||||||||||||||||||||||||||
| 224 | 0 | for ( @params ) { | |||||||||||||||||||||||||||||||||
| 225 | 0 | ▶ | unless ( $self->param( $_ ) ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 226 | 0 | $log->warn( "No value in parameter '$_'" ); | |||||||||||||||||||||||||||||||||
| 227 | 0 | $self->add_error_key( 'action.error.param_required', $_ ); | |||||||||||||||||||||||||||||||||
| 228 | 0 | $num_errors++; | |||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||
| 231 | 0 | return $num_errors; | |||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||
| 234 | ######################################## | ||||||||||||||||||||||||||||||||||
| 235 | # ASSIGN FIELDS | ||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||
| 237 | 0 | ▶ | sub _common_assign_properties { | ||||||||||||||||||||||||||||||||
|
Subroutine
_common_assign_properties: not called CC=23 SCAR=63.1
| |||||||||||||||||||||||||||||||||||
| 238 | 0 | my ( $self, $object, $fields ) = @_; | |||||||||||||||||||||||||||||||||
| 239 | 0 | my $request = CTX->request; | |||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||
| 241 | 0 | ▶ | $log ||= get_logger( LOG_ACTION ); | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$log ||= get_logger("OI2.ACTION")
MC/DC0%0/2
$log ||= get_logger("OI2.ACTION")
$log
get_logger("OI2.ACTION")
Truth table0%0/3
A ||= B
A= $logB= get_logger("OI2.ACTION")
| |||||||||||||||||||||||||||||||||||
| 242 | 0 | foreach my $field ( _norm( $fields->{standard} ) ) { | |||||||||||||||||||||||||||||||||
| 243 | 0 | ▶ | next unless ( $field ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 244 | 0 | my ( $value ); | |||||||||||||||||||||||||||||||||
| 245 | 0 | eval { | |||||||||||||||||||||||||||||||||
| 246 | 0 | $value = $request->param( $field ); | |||||||||||||||||||||||||||||||||
| 247 | 0 | $object->{ $field } = $value; | |||||||||||||||||||||||||||||||||
| 248 | }; | ||||||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 250 | 0 | $log->warn( "Failed to set object value for '$field': $@" ); | |||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||
| 252 | else { | ||||||||||||||||||||||||||||||||||
| 253 | 0 | ▶ | $log->is_debug && | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 254 | $log->debug( "Set standard '$field' from request to '$value'" ); | ||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||
| 258 | 0 | foreach my $field ( _norm( $fields->{toggled} ) ) { | |||||||||||||||||||||||||||||||||
| 259 | 0 | ▶ | next unless ( $field ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 260 | 0 | my ( $value ); | |||||||||||||||||||||||||||||||||
| 261 | 0 | eval { | |||||||||||||||||||||||||||||||||
| 262 | 0 | $value = $request->param_toggled( $field ); | |||||||||||||||||||||||||||||||||
| 263 | 0 | $object->{ $field } = $value; | |||||||||||||||||||||||||||||||||
| 264 | }; | ||||||||||||||||||||||||||||||||||
| 265 | 0 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 266 | 0 | $log->warn( "Failed to set object toggle for '$field': $@" ); | |||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||
| 268 | else { | ||||||||||||||||||||||||||||||||||
| 269 | 0 | ▶ | $log->is_debug && | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 270 | $log->debug( "Set toggled '$field' from request to '$value'" ); | ||||||||||||||||||||||||||||||||||
| 271 | }; | ||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||
| 274 | 0 | foreach my $field ( _norm( $fields->{boolean} ) ) { | |||||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | next unless ( $field ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 276 | 0 | my ( $value ); | |||||||||||||||||||||||||||||||||
| 277 | 0 | eval { | |||||||||||||||||||||||||||||||||
| 278 | 0 | $value = $request->param_boolean( $field ); | |||||||||||||||||||||||||||||||||
| 279 | 0 | $object->{ $field } = $value; | |||||||||||||||||||||||||||||||||
| 280 | }; | ||||||||||||||||||||||||||||||||||
| 281 | 0 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 282 | 0 | $log->warn( "Failed to set object boolean for '$field': $@" ); | |||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||
| 284 | else { | ||||||||||||||||||||||||||||||||||
| 285 | 0 | ▶ | $log->is_debug && | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 286 | $log->debug( "Set boolean '$field' from request to '$value'" ); | ||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||
| 290 | 0 | foreach my $field ( _norm( $fields->{date} ) ) { | |||||||||||||||||||||||||||||||||
| 291 | 0 | ▶ | next unless ( $field ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 292 | 0 | my ( $value ); | |||||||||||||||||||||||||||||||||
| 293 | 0 | eval { | |||||||||||||||||||||||||||||||||
| 294 | 0 | $value = $request->param_date( $field, $fields->{date_format} ); | |||||||||||||||||||||||||||||||||
| 295 | 0 | $object->{ $field }= $value; | |||||||||||||||||||||||||||||||||
| 296 | }; | ||||||||||||||||||||||||||||||||||
| 297 | 0 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 298 | 0 | $log->warn( "Failed to set object date for '$field': $@" ); | |||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||
| 300 | else { | ||||||||||||||||||||||||||||||||||
| 301 | 0 | ▶ | $log->is_debug && | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 302 | $log->debug( "Set date '$field' from request to '$value'" ); | ||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||
| 306 | 0 | foreach my $field ( _norm( $fields->{datetime} ) ) { | |||||||||||||||||||||||||||||||||
| 307 | 0 | ▶ | next unless ( $field ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 308 | 0 | my ( $value ); | |||||||||||||||||||||||||||||||||
| 309 | 0 | eval { | |||||||||||||||||||||||||||||||||
| 310 | 0 | $value = $request->param_datetime( $field, $fields->{datetime_format} ); | |||||||||||||||||||||||||||||||||
| 311 | 0 | $object->{ $field }= $value; | |||||||||||||||||||||||||||||||||
| 312 | }; | ||||||||||||||||||||||||||||||||||
| 313 | 0 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 314 | 0 | $log->warn( "Failed to set object datetime for '$field': $@" ); | |||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||
| 316 | else { | ||||||||||||||||||||||||||||||||||
| 317 | 0 | ▶ | $log->is_debug && | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 318 | $log->debug( "Set datetime '$field' from request to '$value'" ); | ||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||
| 321 | $log->is_debug && | ||||||||||||||||||||||||||||||||||
| 322 | 0 | ▶ | $log->debug( "Done setting fields into object from request" ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 323 | 0 | return $object; | |||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||
| 327 | ######################################## | ||||||||||||||||||||||||||||||||||
| 328 | # FETCH | ||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||
| 330 | 0 | ▶ | sub _common_fetch_object { | ||||||||||||||||||||||||||||||||
|
Subroutine
_common_fetch_object: not called CC=10 SCAR=47.0
| |||||||||||||||||||||||||||||||||||
| 331 | 0 | my ( $self, $id ) = @_; | |||||||||||||||||||||||||||||||||
| 332 | 0 | ▶ | $log ||= get_logger( LOG_ACTION ); | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$log ||= get_logger("OI2.ACTION")
MC/DC0%0/2
$log ||= get_logger("OI2.ACTION")
$log
get_logger("OI2.ACTION")
Truth table0%0/3
A ||= B
A= $logB= get_logger("OI2.ACTION")
| |||||||||||||||||||||||||||||||||||
| 333 | 0 | my ( $object ); | |||||||||||||||||||||||||||||||||
| 334 | 0 | ▶ | if ( $object = $self->param( 'c_object' ) ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 335 | 0 | $self->param( c_id => $object->id ); | |||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||
| 337 | else { | ||||||||||||||||||||||||||||||||||
| 338 | 0 | my $object_class = $self->param( 'c_object_class' ); | |||||||||||||||||||||||||||||||||
| 339 | 0 | ▶ | $id ||= $self->param( 'c_id' ); | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$id ||= $self->param("c_id")
MC/DC0%0/2
$id ||= $self->param("c_id")
$id
$self->param("c_id")
Truth table0%0/3
A ||= B
A= $idB= $self->param("c_id")
| |||||||||||||||||||||||||||||||||||
| 340 | 0 | ▶ | unless ( $id ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 341 | 0 | ▶ | $log->is_info && | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 342 | $log->info( "No ID found, returning new object" ); | ||||||||||||||||||||||||||||||||||
| 343 | 0 | return $object_class->new; | |||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||||
| 345 | $log->is_debug && | ||||||||||||||||||||||||||||||||||
| 346 | 0 | ▶ | $log->debug( "Trying to fetch '$object_class': '$id'" ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 347 | 0 | $object = eval { $object_class->fetch( $id ) }; | |||||||||||||||||||||||||||||||||
| 348 | 0 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 349 | 0 | my $error = $@; | |||||||||||||||||||||||||||||||||
| 350 | 0 | $log->warn( "Caught exception fetching object: $error" ); | |||||||||||||||||||||||||||||||||
| 351 | 0 | ▶ | if ( $error->isa( 'SPOPS::Exception::Security' ) ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 352 | 0 | $self->add_error_key( 'action.error.security' ); | |||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||
| 354 | else { | ||||||||||||||||||||||||||||||||||
| 355 | 0 | $self->add_error_key( 'action.error.fetch', $error ); | |||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||||
| 357 | 0 | oi_error $error; | |||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||
| 359 | 0 | ▶ | $object ||= $object_class->new; | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$object ||= $object_class->new
MC/DC0%0/2
$object ||= $object_class->new
$object
$object_class->new
Truth table0%0/3
A ||= B
A= $objectB= $object_class->new
| |||||||||||||||||||||||||||||||||||
| 360 | 0 | $self->param( c_id => $id ); | |||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||
| 362 | 0 | return $object; | |||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||
| 365 | ######################################## | ||||||||||||||||||||||||||||||||||
| 366 | # MISC | ||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||
| 368 | 0 | ▶ | sub _norm { | ||||||||||||||||||||||||||||||||
|
Subroutine
_norm: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||
| 369 | 0 | my ( $item ) = @_; | |||||||||||||||||||||||||||||||||
| 370 | 0 | ▶ | return ( ref $item eq 'ARRAY' ) ? @{ $item } : ( $item ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||
| 373 | 5 | 1; | |||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||
| 375 | __END__ | ||||||||||||||||||||||||||||||||||