--- Sprout.pm 2005/10/20 10:20:27 1.45 +++ Sprout.pm 2005/10/21 03:29:35 1.50 @@ -1153,7 +1153,7 @@ =item RETURN -Returns a hash mapping the functional assignment IDs to user IDs. +Returns a hash mapping the user IDs to functional assignment IDs. =back @@ -1163,28 +1163,25 @@ # Get the parameters. my ($self, $featureID) = @_; # Get all of the feature's annotations. - my @query = $self->GetAll(['IsTargetOfAnnotation', 'Annotation'], + my @query = $self->GetAll(['IsTargetOfAnnotation', 'Annotation', 'MadeAnnotation'], "IsTargetOfAnnotation(from-link) = ?", - [$featureID], ['Annotation(time)', 'Annotation(annotation)']); + [$featureID], ['Annotation(time)', 'Annotation(annotation)', + 'MadeAnnotation(from-link)']); # Declare the return hash. my %retVal; - # Declare a hash for insuring we only make one assignment per user. - my %timeHash = (); # Now we sort the assignments by timestamp in reverse. my @sortedQuery = sort { -($a->[0] <=> $b->[0]) } @query; # Loop until we run out of annotations. for my $annotation (@sortedQuery) { # Get the annotation fields. - my ($timeStamp, $text) = @{$annotation}; + my ($timeStamp, $text, $user) = @{$annotation}; # Check to see if this is a functional assignment. - my ($user, $function) = _ParseAssignment($text); - if ($user && ! exists $timeHash{$user}) { + my ($actualUser, $function) = _ParseAssignment($user, $text); + if ($actualUser && ! exists $retVal{$actualUser}) { # Here it is a functional assignment and there has been no # previous assignment for this user, so we stuff it in the # return hash. - $retVal{$function} = $user; - # Insure we don't assign to this user again. - $timeHash{$user} = 1; + $retVal{$actualUser} = $function; } } # Return the hash of assignments found. @@ -1262,20 +1259,22 @@ } } # Build a query for all of the feature's annotations, sorted by date. - my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation'], + my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation', 'MadeAnnotation'], "IsTargetOfAnnotation(from-link) = ? ORDER BY Annotation(time) DESC", [$featureID]); my $timeSelected = 0; # Loop until we run out of annotations. while (my $annotation = $query->Fetch()) { # Get the annotation text. - my ($text, $time) = $annotation->Values(['Annotation(annotation)','Annotation(time)']); + my ($text, $time, $user) = $annotation->Values(['Annotation(annotation)', + 'Annotation(time)', 'MadeAnnotation(from-link)']); # Check to see if this is a functional assignment for a trusted user. - my ($user, $function) = _ParseAssignment($text); - if ($user) { + my ($actualUser, $function) = _ParseAssignment($user, $text); + Trace("Assignment user is $actualUser, text is $function.") if T(4); + if ($actualUser) { # Here it is a functional assignment. Check the time and the user # name. The time must be recent and the user must be trusted. - if ((exists $trusteeTable{$user}) && ($time > $timeSelected)) { + if ((exists $trusteeTable{$actualUser}) && ($time > $timeSelected)) { $retVal = $function; $timeSelected = $time; } @@ -1334,26 +1333,30 @@ # users. my %trusteeTable = (); # Build a query for all of the feature's annotations, sorted by date. - my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation'], + my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation', 'MadeAnnotation'], "IsTargetOfAnnotation(from-link) = ? ORDER BY Annotation(time) DESC", [$featureID]); my $timeSelected = 0; # Loop until we run out of annotations. while (my $annotation = $query->Fetch()) { # Get the annotation text. - my ($text, $time) = $annotation->Values(['Annotation(annotation)','Annotation(time)']); + my ($text, $time, $user) = $annotation->Values(['Annotation(annotation)', + 'Annotation(time)', + 'MadeAnnotation(user)']); # Check to see if this is a functional assignment for a trusted user. - my ($user, $function) = _ParseAssignment($text); - if ($user) { + my ($actualUser, $function) = _ParseAssignment($user, $text); + if ($actualUser) { # Here it is a functional assignment. - push @retVal, [$user, $function]; + push @retVal, [$actualUser, $function]; } } } else { # Here we have a non-FIG feature ID. In this case the user ID does not # matter. We simply get the information from the External Alias Function # table. - push @retVal, $self->GetEntityValues('ExternalAliasFunc', $featureID, ['ExternalAliasFunc(func)']); + my @assignments = $self->GetEntityValues('ExternalAliasFunc', $featureID, + ['ExternalAliasFunc(func)']); + push @retVal, map { ['master', $_] } @assignments; } # Return the assignments found. return @retVal; @@ -3228,16 +3231,20 @@ A functional assignment is always of the form - IC<\nset >IC< function to\n>I + CIC< function to\n>I -where I is the B, I is the B, and I is the -actual functional role. In most cases, the user and the assigning user will be the -same, but that is not always the case. +where I is the B, and I is the actual functional role. In most cases, +the user and the assigning user (from MadeAnnotation) will be the same, but that is +not always the case. This is a static method. =over 4 +=item user + +Name of the assigning user. + =item text Text of the annotation. @@ -3253,14 +3260,16 @@ sub _ParseAssignment { # Get the parameters. - my ($text) = @_; + my ($user, $text) = @_; # Declare the return value. my @retVal = (); # Check to see if this is a functional assignment. my ($type, $function) = split(/\n/, $text); - if ($type =~ m/^set ([^ ]+) function to$/i) { - # Here it is, so we return the user name (which is in $1), the functional role text, - # and the assigning user. + if ($type =~ m/^set function to$/i) { + # Here we have an assignment without a user, so we use the incoming user ID. + @retVal = ($user, $function); + } elsif ($type =~ m/^set (\S+) function to$/i) { + # Here we have an assignment with a user, that is passed back to the caller. @retVal = ($1, $function); } # Return the result list. @@ -3350,6 +3359,4 @@ $self->Insert('HasProperty', { 'from-link' => $featureID, 'to-link' => $propID, evidence => $url }); } - - -1; +1; \ No newline at end of file