seedlot upload with accession synonyms. seedlot upload works to update existing seedlots
[sgn.git] / lib / SGN / Controller / Cvterm.pm
bloba28017ce754c9a39b3addcb4ba168c7674733921
2 package SGN::Controller::Cvterm;
4 use CXGN::Chado::Cvterm; #DEPRECATE this !!
5 use CXGN::Cvterm;
7 use Moose;
9 BEGIN { extends 'Catalyst::Controller' };
10 with 'Catalyst::Component::ApplicationAttribute';
12 has 'schema' => (
13 is => 'rw',
14 isa => 'DBIx::Class::Schema',
15 lazy_build => 1,
17 sub _build_schema {
18 shift->_app->dbic_schema( 'Bio::Chado::Schema', 'sgn_chado' )
22 =head2 view_cvterm
24 Public path: /cvterm/<cvterm_id>/view
26 View a cvterm detail page.
28 Chained off of L</get_cvterm> below.
30 =cut
32 sub view_cvterm : Chained('get_cvterm') PathPart('view') Args(0) {
33 my ( $self, $c, $action) = @_;
34 my $cvterm = $c->stash->{cvterm};
35 my $cvterm_id = $cvterm ? $cvterm->cvterm_id : undef ;
37 my $bcs_cvterm = $cvterm->cvterm;
39 my $logged_user = $c->user;
40 my $person_id = $logged_user->get_object->get_sp_person_id if $logged_user;
41 my $user_role = 1 if $logged_user;
42 my $curator = $logged_user->check_roles('curator') if $logged_user;
43 my $submitter = $logged_user->check_roles('submitter') if $logged_user;
44 my $sequencer = $logged_user->check_roles('sequencer') if $logged_user;
45 my $props = $self->_cvtermprops($cvterm);
46 my $editable_cvterm_props = "trait_format,trait_default_value,trait_minimum,trait_maximum,trait_details,trait_categories";
49 $c->stash(
50 template => '/chado/cvterm.mas',
51 cvterm => $cvterm, #deprecate this maybe?
52 cvtermref => {
53 cvterm => $bcs_cvterm,
54 curator => $curator,
55 submitter => $submitter,
56 sequencer => $sequencer,
57 person_id => $person_id,
58 props => $props,
59 editable_cvterm_props => $editable_cvterm_props,
66 =head2 get_cvterm
68 Chain root for fetching a cvterm object to operate on.
70 Path part: /cvterm/<cvterm_id>
72 =cut
74 sub get_cvterm : Chained('/') PathPart('cvterm') CaptureArgs(1) {
75 my ($self, $c, $cvterm_id) = @_;
77 my $identifier_type = $c->stash->{identifier_type}
78 || $cvterm_id =~ /[^-\d]/ ? 'accession' : 'cvterm_id';
80 my $cvterm;
81 if( $identifier_type eq 'cvterm_id' ) {
82 $cvterm = CXGN::Cvterm->new({ schema=>$self->schema, cvterm_id => $cvterm_id } );
83 } elsif ( $identifier_type eq 'accession' ) {
84 $cvterm = CXGN::Cvterm->new({ schema=>$self->schema, accession=>$cvterm_id } ) ;
86 my $found_cvterm = $cvterm->cvterm
87 or $c->throw_404( "Cvterm $cvterm_id not found" );
89 $c->stash->{cvterm} = $cvterm;
91 return 1;
96 sub _cvtermprops {
97 my ($self,$cvterm) = @_;
99 my $properties ;
100 if ($cvterm) {
101 my $bcs_cvterm = $cvterm->cvterm;
102 if (!$bcs_cvterm) { return undef ; }
103 my $cvtermprops = $bcs_cvterm->search_related("cvtermprops");
104 while ( my $prop = $cvtermprops->next ) {
105 push @{ $properties->{$prop->type->name} } , $prop->value ;
108 return $properties;
110 ####
111 1;##
112 ####