+sub check_department {
+ my ($self, $entry) = @_;
+
+ my $object = $entry->{object};
+
+ # Check wether or not department ID is valid.
+ if ($object->department_id && !$self->departments_by->{id}->{ $object->department_id }) {
+ push @{ $entry->{errors} }, $::locale->text('Error: Invalid department');
+ return 0;
+ }
+
+ # Map description to ID if given.
+ if (!$object->department_id && $entry->{raw_data}->{department}) {
+ my $dep = $self->departments_by->{description}->{ $entry->{raw_data}->{department} };
+ if (!$dep) {
+ push @{ $entry->{errors} }, $::locale->text('Error: Invalid department');
+ return 0;
+ }
+
+ $object->department_id($dep->id);
+ }
+
+ return 1;
+}
+
+sub check_project {
+ my ($self, $entry, %params) = @_;
+
+ my $id_column = ($params{global} ? 'global' : '') . 'project_id';
+ my $number_column = ($params{global} ? 'global' : '') . 'projectnumber';
+ my $description_column = ($params{global} ? 'global' : '') . 'project';
+
+ my $object = $entry->{object};
+
+ # Check wether or not projetc ID is valid.
+ if ($object->$id_column && !$self->projects_by->{id}->{ $object->$id_column }) {
+ push @{ $entry->{errors} }, $::locale->text('Error: Invalid project');
+ return 0;
+ }
+
+ # Map number to ID if given.
+ if (!$object->$id_column && $entry->{raw_data}->{$number_column}) {
+ my $proj = $self->projects_by->{projectnumber}->{ $entry->{raw_data}->{$number_column} };
+ if (!$proj) {
+ push @{ $entry->{errors} }, $::locale->text('Error: Invalid project');
+ return 0;
+ }
+
+ $object->$id_column($proj->id);
+ }
+
+ # Map description to ID if given.
+ if (!$object->$id_column && $entry->{raw_data}->{$description_column}) {
+ my $proj = $self->projects_by->{description}->{ $entry->{raw_data}->{$description_column} };
+ if (!$proj) {
+ push @{ $entry->{errors} }, $::locale->text('Error: Invalid project');
+ return 0;
+ }
+
+ $object->$id_column($proj->id);
+ }
+
+ return 1;
+}
+
+
+