From a25231f67dc04b2d7d740570aeba554a8646d9df Mon Sep 17 00:00:00 2001 From: bellerbrock Date: Fri, 6 Sep 2019 21:31:41 +0000 Subject: [PATCH] handle additional fields in image post --- lib/CXGN/BrAPI/v1/Images.pm | 27 ++++++++++++++++++++------- lib/SGN/Controller/AJAX/BrAPI.pm | 13 +++++++++++-- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/lib/CXGN/BrAPI/v1/Images.pm b/lib/CXGN/BrAPI/v1/Images.pm index 3340e9d27..7097fb29b 100644 --- a/lib/CXGN/BrAPI/v1/Images.pm +++ b/lib/CXGN/BrAPI/v1/Images.pm @@ -155,21 +155,34 @@ sub detail { sub image_metadata_store { my $self = shift; + my $params = shift; my $image_dir = shift; - my $inputs = shift; + my $user_id = shift; + + print STDERR "inputs to image metadata store: ".Dumper($params); + + my $imageName = $params->{imageName} || ""; + my $imageFileName = $params->{imageFileName} || ""; + my $imageTimeStamp = $params->{imageTimeStamp} || ""; + my $observationUnitDbId = $params->{observationUnitDbId} || ""; + my $description = $params->{description} || ""; + my $descriptiveOntologyTerms_arrayref = $params->{descriptiveOntologyTerms} || (); + my $observationDbIds_arrayref = $params->{observationDbIds} || (); + my $imageLocation_hashref = $params->{imageLocation} || (); - print STDERR "inputs to image metadata store: ".Dumper($inputs); my $image = CXGN::Image->new(dbh=>$self->bcs_schema()->storage()->dbh(), image_dir => $image_dir); - my $imageName = ""; - my $description = ""; - if (defined($inputs->{imageName})) { $imageName = $inputs->{imageName}->[0] } - if (defined($inputs->{description})) { $description = $inputs->{description}->[0] } + #$image->process_image($image_dir."/".$tempfile, $type, $observationUnitDbId); $image->set_name($imageName); $image->set_description($description); + $image->set_sp_person_id($user_id); my $image_id = $image->store(); + my %result = ( + image_id => $image->get_image_id(), + ); + my $pagination = CXGN::BrAPI::Pagination->pagination_response(1, 10, 0); - return CXGN::BrAPI::JSONResponse->return_success( { image_id => $image_id }, $pagination, undef, $self->status()); + return CXGN::BrAPI::JSONResponse->return_success( { \%result }, $pagination, undef, $self->status()); } diff --git a/lib/SGN/Controller/AJAX/BrAPI.pm b/lib/SGN/Controller/AJAX/BrAPI.pm index f75771af0..9a2978736 100644 --- a/lib/SGN/Controller/AJAX/BrAPI.pm +++ b/lib/SGN/Controller/AJAX/BrAPI.pm @@ -142,7 +142,7 @@ sub _authenticate_user { } } - return 1; + return $person_id; } sub _standard_response_construction { @@ -2857,6 +2857,15 @@ sub images_POST { my $self = shift; my $c = shift; + my $user = _authenticate_user($c); + my $clean_inputs = $c->stash->{clean_inputs}; + #print STDERR "Clean inputs at image_store_PUT: ".Dumper($clean_inputs); + my $brapi = $self->brapi_module; + my $brapi_module = $brapi->brapi_wrapper('Images'); + my $image_dir = File::Spec->catfile($c->config->{static_datasets_path}, $c->config->{image_dir}); + my $brapi_package_result = $brapi_module->image_metadata_store($clean_inputs, $image_dir, $user); + _standard_response_construction($c, $brapi_package_result); + } sub images_by_id : Chained('brapi') PathPart('images') CaptureArgs(1) { @@ -2890,7 +2899,7 @@ sub images_single_PUT { my $brapi = $self->brapi_module; my $brapi_module = $brapi->brapi_wrapper('Images'); my $image_dir = File::Spec->catfile($c->config->{static_datasets_path}, $c->config->{image_dir}); - my $brapi_package_result = $brapi_module->image_metadata_store($image_dir, $clean_inputs, $c->stash->{image_id}); + my $brapi_package_result = $brapi_module->image_metadata_store($clean_inputs, $image_dir); _standard_response_construction($c, $brapi_package_result); } -- 2.11.4.GIT