Skip to content

Commit

Permalink
Merge pull request #5316 from solgenomics/topic/transformation
Browse files Browse the repository at this point in the history
Deletion section on transformation project and transformation details page
  • Loading branch information
lukasmueller authored Feb 17, 2025
2 parents 9effc4b + 2b87127 commit 89efa8f
Show file tree
Hide file tree
Showing 12 changed files with 566 additions and 78 deletions.
30 changes: 30 additions & 0 deletions js/source/legacy/CXGN/Transformation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
function deleteTransformationID(transformation_stock_id){

const confirmation = confirm('Are you sure you want to delete this transformation ID? The deletion cannot be undone.');

if (confirmation) {
jQuery.ajax({
url: '/ajax/transformation/delete',
data: {'transformation_stock_id' : transformation_stock_id},
method: 'POST',
destroy: true,
beforeSend: function(response) {
jQuery('#working_modal').modal('show');
},
success: function(response) {
jQuery('#working_modal').modal('hide');
if (response.success == 1) {
alert('Deletion was successful');
location.reload();
}
if (response.error) {
alert(response.error);
}
},
error: function(response) {
jQuery('#working_modal').modal('hide');
alert('An error occurred during deletion');
}
});
}
}
147 changes: 139 additions & 8 deletions lib/CXGN/Transformation/Transformation.pm
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,27 @@ has 'transformation_stock_id' => (
is => 'rw',
);

has 'transformants' => (
isa => 'ArrayRef|Undef',
is => 'rw',
lazy => 1,
builder => '_get_transformants',
);

has 'obsoleted_transformants' => (
isa => 'ArrayRef|Undef',
is => 'rw',
lazy => 1,
builder => '_get_obsoleted_transformants',
);

has 'tracking_identifier' => (
isa => 'ArrayRef|Undef',
is => 'rw',
lazy => 1,
builder => '_get_tracking_identifier',
);


sub get_active_transformations_in_project {
my $self = shift;
Expand Down Expand Up @@ -121,7 +142,7 @@ sub get_inactive_transformations_in_project {
}


sub get_transformants {
sub _get_transformants {
my $self = shift;
my $schema = $self->schema();
my $transformation_stock_id = $self->transformation_stock_id();
Expand All @@ -143,11 +164,11 @@ sub get_transformants {
push @transformants, [$stock_id, $stock_name]
}

return \@transformants;
$self->transformants(\@transformants);
}


sub get_obsoleted_transformants {
sub _get_obsoleted_transformants {
my $self = shift;
my $schema = $self->schema();
my $transformation_stock_id = $self->transformation_stock_id();
Expand All @@ -171,7 +192,8 @@ sub get_obsoleted_transformants {
push @obsoleted_transformants, [$stock_id, $stock_name, $obsolete_note, $obsolete_date, $sp_person_id]
}

return \@obsoleted_transformants;
$self->obsoleted_transformants(\@obsoleted_transformants);

}


Expand Down Expand Up @@ -241,7 +263,7 @@ sub get_associated_projects {
}


sub get_tracking_identifier {
sub _get_tracking_identifier {
my $self = shift;
my $schema = $self->schema();
my $transformation_stock_id = $self->transformation_stock_id();
Expand All @@ -256,12 +278,13 @@ sub get_tracking_identifier {

$h->execute($material_of_type_id, $transformation_stock_id);

my @tracking_identifiers = ();
my @tracking_identifier_info = ();
while (my ($stock_id, $stock_name) = $h->fetchrow_array()){
push @tracking_identifiers, [$stock_id, $stock_name]
push @tracking_identifier_info, [$stock_id, $stock_name]
}

return \@tracking_identifiers;
$self->tracking_identifier(\@tracking_identifier_info);

}


Expand Down Expand Up @@ -311,6 +334,114 @@ sub get_default_plant_material {
}


sub delete {
my $self = shift;
my $schema = $self->schema();
my $dbh = $self->schema()->storage()->dbh();
my $transformation_stock_id = $self->transformation_stock_id();
my $tracking_identifier = $self->tracking_identifier();
my $transformants = $self->transformants();
my $number_of_transformants = scalar(@$transformants);
my $obsoleted_transformants = $self->obsoleted_transformants();
my $number_of_obsoleted_transformants = scalar(@$obsoleted_transformants);

eval {
$dbh->begin_work();

my $transformation_type_id = SGN::Model::Cvterm->get_cvterm_row($schema, "transformation", "stock_type")->cvterm_id();
my $tracking_type_id = SGN::Model::Cvterm->get_cvterm_row($schema, "tracking_identifier", "stock_type")->cvterm_id();
my $transformation_experiment_type_id = SGN::Model::Cvterm->get_cvterm_row($schema, 'transformation_experiment', 'experiment_type')->cvterm_id();
my $tracking_experiment_type_id = SGN::Model::Cvterm->get_cvterm_row($schema, 'tracking_activity', 'experiment_type')->cvterm_id();

if (($number_of_transformants > 0) || ($number_of_obsoleted_transformants > 0)) {
die "Transformation ID has associated transformants. Cannot delete.\n";
}

my $transformation_rs = $schema->resultset("Stock::Stock")->find ({stock_id => $transformation_stock_id, type_id => $transformation_type_id});
if (!$transformation_rs) {
die "This stock id is not a transformation ID. Cannot delete.\n";
}

my $transformation_experiment_id;
my $nd_q = "SELECT nd_experiment.nd_experiment_id FROM nd_experiment_stock
JOIN nd_experiment ON (nd_experiment_stock.nd_experiment_id = nd_experiment.nd_experiment_id)
WHERE nd_experiment.type_id = ? AND nd_experiment_stock.stock_id = ?";

my $nd_h = $schema->storage->dbh()->prepare($nd_q);
$nd_h->execute($transformation_experiment_type_id, $transformation_stock_id);
my @nd_experiment_ids= $nd_h->fetchrow_array();
if (scalar @nd_experiment_ids == 1) {
$transformation_experiment_id = $nd_experiment_ids[0];
} else {
die "Error retrieving experiment id";
}

#delete the nd_experiment_md_files entries
my $md_files_q = "DELETE FROM phenome.nd_experiment_md_files WHERE nd_experiment_id = ?";
my $md_files_h = $schema->storage->dbh()->prepare($md_files_q);
$md_files_h->execute($transformation_experiment_id);

# delete the nd_experiment entries
my $q2= "delete from nd_experiment where nd_experiment.nd_experiment_id = ? AND nd_experiment.type_id = ?";
my $h2 = $dbh->prepare($q2);
$h2->execute($transformation_experiment_id, $transformation_experiment_type_id);

# delete stock owner entries
#
my $q3 = "delete from phenome.stock_owner where stock_id=?";
my $h3 = $dbh->prepare($q3);
$h3->execute($transformation_stock_id);

# delete the stock entries
my $q4 = "delete from stock where stock.stock_id=? and stock.type_id = ?";
my $h4 = $dbh->prepare($q4);
$h4->execute($transformation_stock_id, $transformation_type_id);

#if linking with tracking tool, delete tracking identifier entry
if (scalar @$tracking_identifier > 0) {
my $tracking_experiment_id;
my $tracking_stock_id = $tracking_identifier->[0]->[0];
my $tracking_nd_q = "SELECT nd_experiment.nd_experiment_id FROM nd_experiment_stock
JOIN nd_experiment ON (nd_experiment_stock.nd_experiment_id = nd_experiment.nd_experiment_id)
WHERE nd_experiment.type_id = ? AND nd_experiment_stock.stock_id = ?";

my $tracking_nd_h = $schema->storage->dbh()->prepare($tracking_nd_q);
$tracking_nd_h->execute($tracking_experiment_type_id, $tracking_stock_id);
my @tracking_nd_experiment_ids= $tracking_nd_h->fetchrow_array();
if (scalar @tracking_nd_experiment_ids == 1) {
$tracking_experiment_id = $tracking_nd_experiment_ids[0];
} else {
die "Error retrieving experiment id";
}

# delete the tracking nd_experiment entries
my $tracking_q2= "delete from nd_experiment where nd_experiment.nd_experiment_id = ? AND nd_experiment.type_id = ?";
my $tracking_h2 = $dbh->prepare($tracking_q2);
$tracking_h2->execute($tracking_experiment_id, $tracking_experiment_type_id);

# delete tracking stock owner entries
my $tracking_q3 = "delete from phenome.stock_owner where stock_id=?";
my $tracking_h3 = $dbh->prepare($tracking_q3);
$tracking_h3->execute($tracking_stock_id);

# delete the tracking stock entries
my $tracking_q4 = "delete from stock where stock.stock_id=? and stock.type_id = ?";
my $tracking_h4 = $dbh->prepare($tracking_q4);
$h4->execute($tracking_stock_id, $tracking_type_id);
}
};

if ($@) {
print STDERR "An error occurred while deleting transformation id ".$transformation_stock_id."$@\n";
$dbh->rollback();
return $@;
} else {
$dbh->commit();
return 0;
}
}


###
1;
###
34 changes: 9 additions & 25 deletions lib/SGN/Controller/AJAX/TrackingActivity.pm
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ sub get_activity_summary :Path('/ajax/tracking_activity/summary') :Args(1) {
my $obsoleted_transformant_count;
if ($material_stock_type eq 'transformation') {
my $transformation_obj = CXGN::Transformation::Transformation->new({schema=>$schema, dbh=>$dbh, transformation_stock_id=>$material_stock_id});
my $obsoleted_transformants = $transformation_obj->get_obsoleted_transformants();
my $obsoleted_transformants = $transformation_obj->obsoleted_transformants();
if ($obsoleted_transformants) {
$obsoleted_transformant_count = scalar @$obsoleted_transformants;
}
Expand Down Expand Up @@ -652,26 +652,19 @@ sub update_status_POST : Args(0) {
return;
}

my @user_roles = $c->user->roles();
my %has_roles = ();
map { $has_roles{$_} = 1; } @user_roles;

if (! ( (exists($has_roles{$program_name}) && exists($has_roles{submitter})) || exists($has_roles{curator}))) {
$c->stash->{rest} = { error => "You need to be either a curator, or a submitter associated with breeding program $program_name to update status." };
return;
}

my $user_id = $c->user()->get_object()->get_sp_person_id();

my $tracking_identifier_type_id = SGN::Model::Cvterm->get_cvterm_row($schema, "tracking_identifier", 'stock_type')->cvterm_id();
my $transformation_type_id = SGN::Model::Cvterm->get_cvterm_row($schema, "transformation", 'stock_type')->cvterm_id();

my $identifier_rs = $schema->resultset("Stock::Stock")->find( { stock_id => $identifier_id, type_id => $tracking_identifier_type_id });
if (!$identifier_rs) {
$c->stash->{rest} = { error_string => 'Error. No tracking identifier entry found in the database.' };
return;
} else {
push @stocks_to_update, $identifier_id;
if ($identifier_id ne 'NA') {
my $identifier_rs = $schema->resultset("Stock::Stock")->find( { stock_id => $identifier_id, type_id => $tracking_identifier_type_id });
if (!$identifier_rs) {
$c->stash->{rest} = { error_string => 'Error. No tracking identifier entry found in the database.' };
return;
} else {
push @stocks_to_update, $identifier_id;
}
}

my $material_stock_type_id;
Expand Down Expand Up @@ -739,15 +732,6 @@ sub reverse_status_POST : Args(0) {
return;
}

my @user_roles = $c->user->roles();
my %has_roles = ();
map { $has_roles{$_} = 1; } @user_roles;

if (! ( (exists($has_roles{$program_name}) && exists($has_roles{submitter})) || exists($has_roles{curator}))) {
$c->stash->{rest} = { error => "You need to be either a curator, or a submitter associated with breeding program $program_name to update status." };
return;
}

my $user_id = $c->user()->get_object()->get_sp_person_id();

my $status_type_id;
Expand Down
Loading

0 comments on commit 89efa8f

Please sign in to comment.