[Bio] / Sprout / CustomAttributes.pm Repository:
ViewVC logotype

Diff of /Sprout/CustomAttributes.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.17, Thu Jan 25 02:41:12 2007 UTC revision 1.18, Tue Feb 6 16:28:40 2007 UTC
# Line 40  Line 40 
40  New attribute keys must be defined before they can be used. A web interface  New attribute keys must be defined before they can be used. A web interface
41  is provided for this purpose.  is provided for this purpose.
42    
43    Major attribute activity is recorded in a log (C<attributes.log>) in the
44    C<$FIG_Config::var> directory. The log reports the user name, time, and
45    the details of the operation. The user name will almost always be unknown,
46    except when it is specified in this object's constructor (see L</new>).
47    
48  =head2 FIG_Config Parameters  =head2 FIG_Config Parameters
49    
50  The following configuration parameters are used to manage custom attributes.  The following configuration parameters are used to manage custom attributes.
# Line 88  Line 93 
93    
94  =head3 new  =head3 new
95    
96  C<< my $attrDB = CustomAttributes->new($splitter); >>  C<< my $attrDB = CustomAttributes->new(%options); >>
97    
98  Construct a new CustomAttributes object.  Construct a new CustomAttributes object. The following options are
99    supported.
100    
101  =over 4  =over 4
102    
103  =item splitter  =item splitter
104    
105  Value to be used to split attribute values into sections in the  Value to be used to split attribute values into sections in the
106  L</Fig Replacement Methods>. The default is a double colon C<::>.  L</Fig Replacement Methods>. The default is a double colon C<::>,
107  If you do not use the replacement methods, you do not need to  and should only be overridden in extreme circumstances.
108  worry about this parameter.  
109    =item user
110    
111    Name of the current user. This will appear in the attribute log.
112    
113  =back  =back
114    
# Line 107  Line 116 
116    
117  sub new {  sub new {
118      # Get the parameters.      # Get the parameters.
119      my ($class, $splitter) = @_;      my ($class, %options) = @_;
120      # Connect to the database.      # Connect to the database.
121      my $dbh = DBKernel->new($FIG_Config::attrDbms, $FIG_Config::attrDbName,      my $dbh = DBKernel->new($FIG_Config::attrDbms, $FIG_Config::attrDbName,
122                              $FIG_Config::attrUser, $FIG_Config::attrPass,                              $FIG_Config::attrUser, $FIG_Config::attrPass,
# Line 117  Line 126 
126      my $xmlFileName = $FIG_Config::attrDBD;      my $xmlFileName = $FIG_Config::attrDBD;
127      my $retVal = ERDB::new($class, $dbh, $xmlFileName);      my $retVal = ERDB::new($class, $dbh, $xmlFileName);
128      # Store the splitter value.      # Store the splitter value.
129      $retVal->{splitter} = (defined($splitter) ? $splitter : '::');      $retVal->{splitter} = $options{splitter} || '::';
130        # Store the user name.
131        $retVal->{user} = $options{user} || '<unknown>';
132        Trace("User $retVal->{user} selected for attribute object.") if T(3);
133      # Return the result.      # Return the result.
134      return $retVal;      return $retVal;
135  }  }
# Line 168  Line 180 
180      } elsif (! exists $types{$type}) {      } elsif (! exists $types{$type}) {
181          Confess("Invalid data type \"$type\" for $attributeName.");          Confess("Invalid data type \"$type\" for $attributeName.");
182      } else {      } else {
183            # Create a variable to hold the action to be displayed for the log (Add or Update).
184            my $action;
185          # Okay, we're ready to begin. See if this key exists.          # Okay, we're ready to begin. See if this key exists.
186          my $attribute = $self->GetEntity('AttributeKey', $attributeName);          my $attribute = $self->GetEntity('AttributeKey', $attributeName);
187          if (defined($attribute)) {          if (defined($attribute)) {
188              # It does, so we do an update.              # It does, so we do an update.
189                $action = "Update Key";
190              $self->UpdateEntity('AttributeKey', $attributeName,              $self->UpdateEntity('AttributeKey', $attributeName,
191                                  { description => $notes, 'data-type' => $type });                                  { description => $notes, 'data-type' => $type });
192              # Detach the key from its current groups.              # Detach the key from its current groups.
193              $self->Disconnect('IsInGroup', 'AttributeKey', $attributeName);              $self->Disconnect('IsInGroup', 'AttributeKey', $attributeName);
194          } else {          } else {
195              # It doesn't, so we do an insert.              # It doesn't, so we do an insert.
196                $action = "Insert Key";
197              $self->InsertObject('AttributeKey', { id => $attributeName,              $self->InsertObject('AttributeKey', { id => $attributeName,
198                                  description => $notes, 'data-type' => $type });                                  description => $notes, 'data-type' => $type });
199          }          }
# Line 187  Line 203 
203              $self->InsertObject('IsInGroup', { 'from-link' => $attributeName,              $self->InsertObject('IsInGroup', { 'from-link' => $attributeName,
204                                                 'to-link'   => $group });                                                 'to-link'   => $group });
205          }          }
206            # Log the operation.
207            $self->LogOperation($action, $attributeName, "Group list is " . join(" ", @{$groups}));
208      }      }
209  }  }
210    
# Line 246  Line 264 
264      # Get the parameters.      # Get the parameters.
265      my ($self, $keyName, $fh, $idCol, $dataCol, %options) = @_;      my ($self, $keyName, $fh, $idCol, $dataCol, %options) = @_;
266      # Create the return variable.      # Create the return variable.
267      my $retVal = Stats->new("lineIn", "shortLine", "newObject");      my $retVal = Stats->new("lineIn", "shortLine");
268      # Compute the minimum number of fields required in each input line.      # Compute the minimum number of fields required in each input line. The user specifies two
269        # columns, and we need to make sure both columns are in every record.
270      my $minCols = ($idCol < $dataCol ? $idCol : $idCol) + 1;      my $minCols = ($idCol < $dataCol ? $idCol : $idCol) + 1;
271      # Insure the attribute key exists.      # Insure the attribute key exists.
272      my $found = $self->GetEntity('AttributeKey', $keyName);      my $found = $self->GetEntity('AttributeKey', $keyName);
# Line 277  Line 296 
296                  $retVal->Add(newValue => 1);                  $retVal->Add(newValue => 1);
297              }              }
298          }          }
299            # Log this operation.
300            $self->LogOperation("Load Key", $keyName, $retVal->Display());
301      }      }
302      # Return the statistics.      # Return the statistics.
303      return $retVal;      return $retVal;
# Line 308  Line 329 
329      my ($self, $attributeName) = @_;      my ($self, $attributeName) = @_;
330      # Delete the attribute key.      # Delete the attribute key.
331      my $retVal = $self->Delete('AttributeKey', $attributeName);      my $retVal = $self->Delete('AttributeKey', $attributeName);
332        # Log this operation.
333        $self->LogOperation("Delete Key", $attributeName, "Key will no longer be available for use by anyone.");
334      # Return the result.      # Return the result.
335      return $retVal;      return $retVal;
336    
# Line 581  Line 604 
604          # is nonempty.          # is nonempty.
605          Tracer::PutLine($fh, ['#GROUPS', @groups]);          Tracer::PutLine($fh, ['#GROUPS', @groups]);
606      }      }
607        # Log the operation.
608        $self->LogOperation("Backup Keys", $fileName, $retVal->Display());
609      # Return the result.      # Return the result.
610      return $retVal;      return $retVal;
611  }  }
# Line 651  Line 676 
676              }              }
677          }          }
678      }      }
679        # Log the operation.
680        $self->LogOperation("Backup Keys", $fileName, $retVal->Display());
681      # Return the result.      # Return the result.
682      return $retVal;      return $retVal;
683  }  }
# Line 711  Line 738 
738          Trace("$valuesFound values backed up for key $key.") if T(3);          Trace("$valuesFound values backed up for key $key.") if T(3);
739          $retVal->Add(values => $valuesFound);          $retVal->Add(values => $valuesFound);
740      }      }
741        # Log the operation.
742        $self->LogOperation("Backup Data", $fileName, $retVal->Display());
743      # Return the result.      # Return the result.
744      return $retVal;      return $retVal;
745  }  }
# Line 975  Line 1004 
1004      return %retVal;      return %retVal;
1005  }  }
1006    
1007    =head3 LogOperation
1008    
1009    C<< $ca->LogOperation($action, $target, $description); >>
1010    
1011    Write an operation description to the attribute activity log (C<$FIG_Config::var/attributes.log>).
1012    
1013    =over 4
1014    
1015    =item action
1016    
1017    Action being logged (e.g. C<Delete Group> or C<Load Key>).
1018    
1019    =item target
1020    
1021    ID of the key or group affected.
1022    
1023    =item description
1024    
1025    Short description of the action.
1026    
1027    =back
1028    
1029    =cut
1030    
1031    sub LogOperation {
1032        # Get the parameters.
1033        my ($self, $action, $target, $description) = @_;
1034        # Get the user ID.
1035        my $user = $self->{user};
1036        # Get a timestamp.
1037        my $timeString = Tracer::Now();
1038        # Open the log file for appending.
1039        my $oh = Open(undef, ">>$FIG_Config::var/attributes.log");
1040        # Write the data to it.
1041        Tracer::PutLine($oh, [$timeString, $user, $action, $target, $description]);
1042        # Close the log file.
1043        close $oh;
1044    }
1045    
1046  =head2 Internal Utility Methods  =head2 Internal Utility Methods
1047    
1048  =head3 _KeywordString  =head3 _KeywordString
# Line 1430  Line 1498 
1498      for my $tuple (@retVal) {      for my $tuple (@retVal) {
1499          $self->DeleteAttribute(@{$tuple});          $self->DeleteAttribute(@{$tuple});
1500      }      }
1501        # Log this operation.
1502        my $count = @retVal;
1503        $self->LogOperation("Mass Delete", $key, "$count matching attributes deleted.");
1504      # Return the deleted attributes.      # Return the deleted attributes.
1505      return @retVal;      return @retVal;
1506  }  }
# Line 1508  Line 1579 
1579      my ($self, $key) = @_;      my ($self, $key) = @_;
1580      # Delete everything connected to the key.      # Delete everything connected to the key.
1581      $self->Disconnect('HasValueFor', 'AttributeKey', $key);      $self->Disconnect('HasValueFor', 'AttributeKey', $key);
1582        # Log the operation.
1583        $self->LogOperation("Erase Data", $key);
1584      # Return a 1, for backward compatability.      # Return a 1, for backward compatability.
1585      return 1;      return 1;
1586  }  }

Legend:
Removed from v.1.17  
changed lines
  Added in v.1.18

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3