TT#35516 Apply simplest filter logic for subscribersregistrations

Untill new requirements will be defined

Change-Id: Id0d1f2ade21d0bd8c0759077577685f4c45fdf9a
changes/84/20684/6
Irina Peshinskaya 7 years ago
parent ce3fde0c50
commit 174bfc9c02

@ -150,41 +150,30 @@ sub _filter {
my $match = 0; my $match = 0;
my $filter_applied = 0; my $filter_applied = 0;
my %attr = map { $_->name => 1 } $row->meta->get_all_attributes; my %attr = map { $_->name => 1 } $row->meta->get_all_attributes;
foreach my $f (keys %{ $filter }) { foreach my $colname (keys %{ $filter }) {
if ($f eq "-and" && ref $filter->{$f} eq "ARRAY") { my $condition = $filter->{$colname};
foreach my $col (@{ $filter->{$f} }) {
next unless (ref $col eq "ARRAY");
foreach my $innercol (@{ $col }) {
if (ref $innercol eq "HASH") {
foreach my $colname (keys %{ $innercol }) {
my $searchname = $colname; my $searchname = $colname;
$colname =~ s/^me\.//; $colname =~ s/^me\.//;
next if ($colname =~ /\./); # we don't support joined table columns next if ($colname =~ /\./); # we don't support joined table columns
$filter_applied = 1; $filter_applied = 1;
if (ref $innercol->{$searchname} eq "") { if (ref $condition eq "") {
if (!exists $attr{$colname} || lc($row->$colname) ne lc($innercol->{$searchname})) { if (!exists $attr{$colname} || lc($row->$colname) ne lc($condition)) {
$match = 0;
last;
} else { } else {
$match = 1; $match = 1;
last;
} }
} elsif (ref $innercol->{$searchname} eq "HASH" && exists $innercol->{$searchname}->{like}) { } elsif (ref $condition eq "HASH" && exists $condition->{like}) {
my $fil = $innercol->{$searchname}->{like}; my $fil = $condition->{like};
$fil =~ s/^\%//; $fil =~ s/^\%//;
$fil =~ s/\%$//; $fil =~ s/\%$//;
if (!exists $attr{$colname} || $row->$colname !~ /$fil/i) { if (!exists $attr{$colname} || $row->$colname !~ /$fil/i) {
$match = 0;
last;
} else { } else {
$match = 1; $match = 1;
last;
}
} }
} }
last if ($match);
}
}
}
last if ($match);
}
} }
next if ($filter_applied && !$match); next if ($filter_applied && !$match);
push @newrows, $row; push @newrows, $row;

@ -48,7 +48,10 @@ $test_machine->check_bundle();
$test_machine->clear_test_data_all(); $test_machine->clear_test_data_all();
$test_machine->check_create_correct( 1, sub{ $_[0]->{contact} .= time().'_'.$_[1]->{i} ; } ); $test_machine->check_create_correct( 1, sub{ $_[0]->{contact} .= time().'_'.$_[1]->{i} ; } );
#$test_machine->check_get2put(undef, undef, { ignore_fields => [qw/id _links/] });
for (my $i=0; $i < 15; $i++) {
$test_machine->check_get2put(undef, undef, { ignore_fields => [qw/id _links/] });
}
$test_machine->clear_data_created(); $test_machine->clear_data_created();
$test_machine->check_create_correct( 1, sub{ $_[0]->{contact} .= time().'_'.$_[1]->{i} ; } ); $test_machine->check_create_correct( 1, sub{ $_[0]->{contact} .= time().'_'.$_[1]->{i} ; } );

@ -487,6 +487,7 @@ sub get_uri_item{
$resuri = $self->normalize_uri('/'.( $item->{location} // '' )); $resuri = $self->normalize_uri('/'.( $item->{location} // '' ));
return $resuri; return $resuri;
} }
sub get_item_hal{ sub get_item_hal{
my($self, $name, $uri, $reload, $number) = @_; my($self, $name, $uri, $reload, $number) = @_;
$name ||= $self->name; $name ||= $self->name;
@ -1320,13 +1321,20 @@ sub check_get2put{
delete $put_out->{content_in}->{_embedded}; delete $put_out->{content_in}->{_embedded};
# check if put is ok # check if put is ok
$put_out->{content_in} = $self->process_data($put_in->{data_cb}, $put_out->{content_in}); $put_out->{content_in} = $self->process_data($put_in->{data_cb}, $put_out->{content_in});
#we are going to use created or loaded item - lets take it to redefine it's uri if will be necessary after put
@{$put_out}{qw/response content request/} = $self->request_put( $put_out->{content_in}, $put_in->{uri} ); @{$put_out}{qw/response content request/} = $self->request_put( $put_out->{content_in}, $put_in->{uri} );
foreach my $field (@{$ignore_fields}){ foreach my $field (@{$ignore_fields}){
delete $get_out->{content}->{$field}; delete $get_out->{content}->{$field};
delete $put_out->{content}->{$field}; delete $put_out->{content}->{$field};
} }
$self->http_code_msg(200, "check_get2put: check put successful", $put_out->{response}, $put_out->{content} ); $self->http_code_msg(200, "check_get2put: check put successful", $put_out->{response}, $put_out->{content} );
is_deeply($get_out->{content}, $put_out->{content}, "$self->{name}: check_get2put: check put if unmodified put returns the same"); if (!is_deeply($get_out->{content}, $put_out->{content}, "$self->{name}: check_get2put: check put if unmodified put returns the same")) {
diag(Dumper([$put_out->{content},$get_out->{content}]));
}
if ($put_out->{response}->header('Location') && ! $put_in->{uri} ) {
my $default_item = $self->get_item_hal($self->name);
$default_item->{location} = $put_out->{response}->header('Location');
}
return ($put_out,$get_out); return ($put_out,$get_out);
} }

Loading…
Cancel
Save