Changeset 22819


Ignore:
Timestamp:
09/09/10 10:28:40 (17 months ago)
Author:
alex
Message:

rewrote to reflect changes in ClassDescriptor? (extends => parents, parents => ancestors)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/mnw21/pathquery_refactor/intermine/perl/lib/IMUtils/UpdatePath.pm

    r21940 r22819  
    99 
    1010    our @EXPORT= qw/changed dead update_path update_query check_class_name/; 
    11      
     11 
    1212    my ($model, $changes, $log); 
    1313    our $prefix = 'org.intermine.model.bio.'; 
    1414 
    1515    sub set_up { 
    16     # args: model, changes,  
     16    # args: model, changes, 
    1717    my $class = shift; 
    1818    my %args  = @_; 
     
    2121 
    2222    # Read the details of the model changes from the .json config file 
    23     die 'No model change details supplied - please list a file with the --changesfile flag '  
     23    die 'No model change details supplied - please list a file with the --changesfile flag ' 
    2424        unless $args{changes}; 
    2525    open my $changesFH, '<', $args{changes} or die "Could not open $args{changes}, $!"; 
    2626    my $content = join('', <$changesFH>); 
    2727    close $changesFH or die "could not close $args{changes}, $!"; 
    28      
     28 
    2929    # Decode it into a hash reference 
    3030    my $json  = new JSON; 
     
    3737    } 
    3838 
    39     sub dead {     
     39    sub dead { 
    4040    my $key = shift; 
    4141    $key =~ s/$prefix//; 
     
    4949 
    5050    # otherwise you get @dbl_array[0,0], ie. doubling. 
    51     return @dbl_array if (@dbl_array == 1);  
     51    return @dbl_array if (@dbl_array == 1); 
    5252 
    5353    # find the length of the first array (ie. half the total) 
    54     my $midpoint = @dbl_array / 2;      
     54    my $midpoint = @dbl_array / 2; 
    5555 
    5656    # pair up the elements 
    57     return @dbl_array[ map { $_, $_ + $midpoint } 0 .. $midpoint - 1 ];  
     57    return @dbl_array[ map { $_, $_ + $midpoint } 0 .. $midpoint - 1 ]; 
    5858    } 
    5959 
     
    6565    return $class; 
    6666    } 
    67       
     67 
    6868    my %processed; 
    69      
     69 
    7070    sub update_path { 
    7171    my $path = shift; 
     
    8080        $prefixed++;          # but remember that we did so 
    8181    } 
    82      
     82 
    8383    my $query = shift; 
    84      
     84 
    8585    my $query_name = (ref $query) ? $query->get_name : $query; 
    86      
     86 
    8787 
    8888    my @new_bits; 
     
    9292 
    9393    my $class_name = shift @bits; 
    94      
     94 
    9595    my $class = check_class_name($class_name); 
    9696 
     
    103103        } 
    104104        else { 
    105         $log->warning($query_name, qq{Unexpected deletion of class "$class_name"})  
     105        $log->warning($query_name, qq{Unexpected deletion of class "$class_name"}) 
    106106            unless dead($class_name); 
    107107        return; 
    108108        } 
    109109    } 
    110      
     110 
    111111    my $current_class = $class; 
    112112    my $current_field = undef; 
    113      
     113 
    114114    my @path_so_far = ($class_name,); 
    115115      FIELD: for my $bit (@bits) { 
     
    117117      if ($bit eq 'id' and $bit eq $bits[-1]) { # id is an internal attribute for all tables 
    118118          push @new_bits, $bit; 
    119           $current_class = undef; # id must be the final attribute  
     119          $current_class = undef; # id must be the final attribute 
    120120          # - this will catch it if it isn't 
    121121      } 
     
    132132          } 
    133133          } 
    134           if (not UNIVERSAL::can($current_class, 'isa')  
     134          if (not UNIVERSAL::can($current_class, 'isa') 
    135135          or not $current_class->isa('InterMine::Model::ClassDescriptor')) { 
    136136          croak "Could not find class of $new_bits[-1] when searching for $bit in $path"; 
     
    140140          } 
    141141          if (!defined $current_field) { 
    142            
     142 
    143143          # Maybe this field is declared in a parent class? 
    144           my @parents = map {$_->name} $current_class->get_parents; 
    145  
    146           foreach my $parent (@parents) { 
    147               my $key = "$parent.$bit"; 
     144          my @ancestors = map {$_->name} $current_class->get_ancestors; 
     145 
     146          foreach my $ancestor (@ancestors) { 
     147              my $key = "$ancestor.$bit"; 
    148148              if (my $translation = changed($key)) { 
    149149              if ($current_field = $current_class->get_field_by_name($translation)){ 
     
    151151                  push @new_bits, $translation; 
    152152                  push @path_so_far, $bit; 
    153                    
     153 
    154154                  $current_class = next_class($current_field); 
    155155                  next FIELD; 
    156156              } 
    157157              } 
    158                
     158 
    159159          } 
    160160          if (!defined $current_field) { # still! 
     
    198198    } 
    199199    } 
    200      
     200 
    201201    sub update_query { 
    202202    my $query  = shift; 
    203203    my $origin = shift; 
    204      
     204 
    205205    my ($is_broken, $is_changed); 
    206206 
     
    209209    confess "$query is not a reference" unless (ref $query); 
    210210    $log->info('Processing', $query->{type}, '"'.$query->get_name. '"'); 
    211      
     211 
    212212    if ($query->type_hash) { 
    213213        while (my ($key, $path) = each %{$query->type_hash}) { 
     
    227227        } 
    228228        # to prevent undefined in string errors 
    229         $translation = '' unless $translation;  
     229        $translation = '' unless $translation; 
    230230 
    231231        $log->info(eval $change) unless ($path eq $translation); 
     
    247247    } 
    248248    $query->{view} = \@new_views; 
    249      
     249 
    250250    if ($query->sort_order) { 
    251251        my ($sort_order, $direction) = split(/\s/, $query->sort_order); 
     
    262262            } 
    263263        } 
    264         $query->{sort_order} = $sort_order .  
     264        $query->{sort_order} = $sort_order . 
    265265            (($direction) ? ' ' . $direction : ''); 
    266266        } 
     
    293293        } 
    294294        else { 
    295         $log->info(eval $deletion, ' (with its '.  
     295        $log->info(eval $deletion, ' (with its '. 
    296296               scalar(@{$query->{constraints}{$path}}). 
    297297               ' constraints)'); 
     
    315315        $query->type_hash(\%new_typehash); 
    316316    } 
    317      
    318     if ($is_broken) {    
     317 
     318    if ($is_broken) { 
    319319        $log->warning($origin, $query->{type}, '"'.$query->get_name.'"', '"is broken'); 
    320320    } 
Note: See TracChangeset for help on using the changeset viewer.