diff --git a/lib/CXGN/BrAPI/v2/ObservationUnits.pm b/lib/CXGN/BrAPI/v2/ObservationUnits.pm index 9d289f4750..16120bc414 100644 --- a/lib/CXGN/BrAPI/v2/ObservationUnits.pm +++ b/lib/CXGN/BrAPI/v2/ObservationUnits.pm @@ -428,6 +428,15 @@ sub observationunits_update { my $level_number = $params->{observationUnitPosition}->{observationLevel}->{levelCode} ? $params->{observationUnitPosition}->{observationLevel}->{levelCode} : undef; my $raw_additional_info = $params->{additionalInfo} || undef; my $is_a_control = $raw_additional_info->{control} ? $raw_additional_info->{control} : undef; + + my $entry_type = $params->{observationUnitPosition}->{entryType} ? $params->{observationUnitPosition}->{entryType} : undef; + my $is_a_control = $params->{additionalInfo}->{control} ? $params->{additionalInfo}->{control} : undef; + + # BrAPI entryType overrides additionalinfo.control + if ($entry_type) { + $is_a_control = uc($entry_type) eq 'CHECK' ? 1 : 0; + } + my $range_number = $raw_additional_info->{range} ? $raw_additional_info->{range} : undef; my %specific_keys = map { $_ => 1 } ("observationUnitParent","control","range"); my %additional_info; @@ -633,7 +642,14 @@ sub observationunits_store { my $plot_parent_id = $params->{additionalInfo}->{observationUnitParent} ? $params->{additionalInfo}->{observationUnitParent} : undef; my $accession_id = $params->{germplasmDbId} ? $params->{germplasmDbId} : undef; my $accession_name = $params->{germplasmName} ? $params->{germplasmName} : undef; + my $entry_type = $params->{observationUnitPosition}->{entryType} ? $params->{observationUnitPosition}->{entryType} : undef; my $is_a_control = $params->{additionalInfo}->{control} ? $params->{additionalInfo}->{control} : undef; + + # BrAPI entryType overrides additionalinfo.control + if ($entry_type) { + $is_a_control = uc($entry_type) eq 'CHECK' ? 1 : 0; + } + my $range_number = $params->{additionalInfo}->{range} ? $params->{additionalInfo}->{range} : undef; my $row_number = $params->{observationUnitPosition}->{positionCoordinateY} ? $params->{observationUnitPosition}->{positionCoordinateY} : undef; my $col_number = $params->{observationUnitPosition}->{positionCoordinateX} ? $params->{observationUnitPosition}->{positionCoordinateX} : undef; diff --git a/t/unit_mech/AJAX/_BrAPIv2_phenotyping.t b/t/unit_mech/AJAX/_BrAPIv2_phenotyping.t index 4d8dc48cef..be81f58413 100644 --- a/t/unit_mech/AJAX/_BrAPIv2_phenotyping.t +++ b/t/unit_mech/AJAX/_BrAPIv2_phenotyping.t @@ -80,7 +80,7 @@ my $row = $rs->next(); my $stock_id = $row->stock_id(); #11 -is_deeply($response, {'result' => {'data' => [{'observationUnitDbId' => $stock_id,'observationUnitPUI' => 'localhost/stock/'.$stock_id.'/view','externalReferences' => [],'additionalInfo' => {},'observationUnitPosition' => {'geoCoordinates' => undef,'observationLevel' => {'levelCode' => '10','levelOrder' => 2,'levelName' => 'plot'},'positionCoordinateY' => 3,'entryType' => 'check','positionCoordinateXType' => 'GRID_COL','positionCoordinateYType' => 'GRID_ROW','observationLevelRelationships' => [{'levelName' => 'rep','levelOrder' => 0,'levelCode' => '1'}, {'levelName' => 'replicate','levelOrder' => 0,'levelCode' => '1'},{'levelCode' => 'Block_12','levelName' => 'block','levelOrder' => 1},{'levelCode' => '10','levelOrder' => 2,'levelName' => 'plot'}],'positionCoordinateX' => 74},'studyName' => 'CASS_6Genotypes_Sampling_2015','trialDbId' => '165','programDbId' => '134','plotImageDbIds' => [],'locationName' => 'test_location','studyDbId' => '165','locationDbId' => '23','observationUnitName' => 'Testing Plot','germplasmName' => 'IITA-TMS-IBA011412','seedLotDbId' => undef,'seedLotName' => undef,'programName' => 'test','treatments' => [{'factor' => 'No ManagementFactor','modality' => undef}],'trialName' => 'CASS_6Genotypes_Sampling_2015','germplasmDbId' => '41281','observations' => []}]},'metadata' => {'pagination' => {'totalCount' => 1,'totalPages' => 1,'pageSize' => 1,'currentPage' => 0},'datafiles' => [],'status' => [{'messageType' => 'INFO','message' => 'BrAPI base call found with page=0, pageSize=10'},{'message' => 'Loading CXGN::BrAPI::v2::ObservationUnits','messageType' => 'INFO'},{'message' => 'Observation Units search result constructed','messageType' => 'INFO'}]}} ,"POST observationunits test"); +is_deeply($response, {'result' => {'data' => [{'observationUnitDbId' => $stock_id,'observationUnitPUI' => 'localhost/stock/'.$stock_id.'/view','externalReferences' => [],'additionalInfo' => {},'observationUnitPosition' => {'geoCoordinates' => undef,'observationLevel' => {'levelCode' => '10','levelOrder' => 2,'levelName' => 'plot'},'positionCoordinateY' => 3,'entryType' => 'test','positionCoordinateXType' => 'GRID_COL','positionCoordinateYType' => 'GRID_ROW','observationLevelRelationships' => [{'levelName' => 'rep','levelOrder' => 0,'levelCode' => '1'}, {'levelName' => 'replicate','levelOrder' => 0,'levelCode' => '1'},{'levelCode' => 'Block_12','levelName' => 'block','levelOrder' => 1},{'levelCode' => '10','levelOrder' => 2,'levelName' => 'plot'}],'positionCoordinateX' => 74},'studyName' => 'CASS_6Genotypes_Sampling_2015','trialDbId' => '165','programDbId' => '134','plotImageDbIds' => [],'locationName' => 'test_location','studyDbId' => '165','locationDbId' => '23','observationUnitName' => 'Testing Plot','germplasmName' => 'IITA-TMS-IBA011412','seedLotDbId' => undef,'seedLotName' => undef,'programName' => 'test','treatments' => [{'factor' => 'No ManagementFactor','modality' => undef}],'trialName' => 'CASS_6Genotypes_Sampling_2015','germplasmDbId' => '41281','observations' => []}]},'metadata' => {'pagination' => {'totalCount' => 1,'totalPages' => 1,'pageSize' => 1,'currentPage' => 0},'datafiles' => [],'status' => [{'messageType' => 'INFO','message' => 'BrAPI base call found with page=0, pageSize=10'},{'message' => 'Loading CXGN::BrAPI::v2::ObservationUnits','messageType' => 'INFO'},{'message' => 'Observation Units search result constructed','messageType' => 'INFO'}]}} ,"POST observationunits test"); $mech->get_ok('http://localhost:3010/brapi/v2/observationunits/41284'); @@ -351,7 +351,7 @@ $data = '{ "'.$stock_id.'": { "observationUnitName":"Testing Plot", "studyDbId" $resp = $ua->put("http://localhost:3010/brapi/v2/observationunits/", Content => $data); $response = decode_json $resp->{_content}; -is_deeply($response, {'metadata' => {'pagination' => {'totalCount' => 1,'currentPage' => 0,'pageSize' => 10,'totalPages' => 1},'datafiles' => [],'status' => [{'messageType' => 'INFO','message' => 'BrAPI base call found with page=0, pageSize=10'},{'message' => 'Loading CXGN::BrAPI::v2::ObservationUnits','messageType' => 'INFO'},{'message' => 'Observation Units search result constructed','messageType' => 'INFO'}]},'result' => {'data' => [{'observationUnitDbId' => $stock_id, 'observationUnitPUI' => 'localhost/stock/'. $stock_id .'/view', 'locationDbId' => '23','programDbId' => '134','observationUnitName' => 'Testing Plot','locationName' => 'test_location','trialDbId' => '165','studyDbId' => '165','germplasmDbId' => '41281','observationUnitPosition' => {'positionCoordinateYType' => 'GRID_ROW','observationLevel' => {'levelOrder' => 2,'levelCode' => 'Plot_123','levelName' => 'plot'},'positionCoordinateY' => 3,'observationLevelRelationships' => [{'levelName' => 'rep','levelCode' => 'Rep_1','levelOrder' => 0}, {'levelName' => 'replicate','levelCode' => 'Rep_1','levelOrder' => 0},{'levelCode' => 'Block_12','levelOrder' => 1,'levelName' =>'block'},{'levelCode' => 'Plot_123','levelOrder' => 2,'levelName' => 'plot'}],'positionCoordinateX' => 74,'entryType' => 'check','positionCoordinateXType' => 'GRID_COL','geoCoordinates' => {'type' => 'Feature','geometry' => {'coordinates' => ['-76.506042','42.417373',10],'type' => 'Point'}}},'trialName' => 'CASS_6Genotypes_Sampling_2015','studyName' => 'CASS_6Genotypes_Sampling_2015','germplasmName' => 'IITA-TMS-IBA011412','programName' => 'test','treatments' => [{'factor' => 'No ManagementFactor','modality' => undef}],'externalReferences' => [],'observations' => [],'additionalInfo' => {},'seedLotDbId' => undef, 'seedLotName' => undef,'plotImageDbIds' => []}]}}, "observationunits put test"); +is_deeply($response, {'metadata' => {'pagination' => {'totalCount' => 1,'currentPage' => 0,'pageSize' => 10,'totalPages' => 1},'datafiles' => [],'status' => [{'messageType' => 'INFO','message' => 'BrAPI base call found with page=0, pageSize=10'},{'message' => 'Loading CXGN::BrAPI::v2::ObservationUnits','messageType' => 'INFO'},{'message' => 'Observation Units search result constructed','messageType' => 'INFO'}]},'result' => {'data' => [{'observationUnitDbId' => $stock_id, 'observationUnitPUI' => 'localhost/stock/'. $stock_id .'/view', 'locationDbId' => '23','programDbId' => '134','observationUnitName' => 'Testing Plot','locationName' => 'test_location','trialDbId' => '165','studyDbId' => '165','germplasmDbId' => '41281','observationUnitPosition' => {'positionCoordinateYType' => 'GRID_ROW','observationLevel' => {'levelOrder' => 2,'levelCode' => 'Plot_123','levelName' => 'plot'},'positionCoordinateY' => 3,'observationLevelRelationships' => [{'levelName' => 'rep','levelCode' => 'Rep_1','levelOrder' => 0}, {'levelName' => 'replicate','levelCode' => 'Rep_1','levelOrder' => 0},{'levelCode' => 'Block_12','levelOrder' => 1,'levelName' =>'block'},{'levelCode' => 'Plot_123','levelOrder' => 2,'levelName' => 'plot'}],'positionCoordinateX' => 74,'entryType' => 'test','positionCoordinateXType' => 'GRID_COL','geoCoordinates' => {'type' => 'Feature','geometry' => {'coordinates' => ['-76.506042','42.417373',10],'type' => 'Point'}}},'trialName' => 'CASS_6Genotypes_Sampling_2015','studyName' => 'CASS_6Genotypes_Sampling_2015','germplasmName' => 'IITA-TMS-IBA011412','programName' => 'test','treatments' => [{'factor' => 'No ManagementFactor','modality' => undef}],'externalReferences' => [],'observations' => [],'additionalInfo' => {},'seedLotDbId' => undef, 'seedLotName' => undef,'plotImageDbIds' => []}]}}, "observationunits put test"); # $mech->post_ok('http://localhost:3010/brapi/v2/search/observationunits', ['observationUnitDbIds'=>['41300','41301']]); @@ -368,7 +368,7 @@ $data = '{ "additionalInfo": { "control": 1 }, "germplasmDbId": "41280", "germpl $resp = $ua->put("http://localhost:3010/brapi/v2/observationunits/41300", Content => $data); $response = decode_json $resp->{_content}; print STDERR "\n\n Observation Unit Response is : " . Dumper $response; -my $expected = {'metadata' => {'pagination' => {'totalCount' => 1,'pageSize' => 10,'currentPage' => 0,'totalPages' => 1},'status' => [{'messageType' => 'INFO','message' => 'BrAPI base call found with page=0, pageSize=10'},{'message' => 'Loading CXGN::BrAPI::v2::ObservationUnits','messageType' => 'INFO'},{'messageType' => 'INFO','message' => 'Observation Units search result constructed'}],'datafiles' => []},'result' => {'data' => [{'treatments' => [{'factor' => 'No ManagementFactor','modality' => undef}],'studyName' => 'CASS_6Genotypes_Sampling_2015','trialName' => 'CASS_6Genotypes_Sampling_2015','plotImageDbIds' => [],'observationUnitPosition' => {'observationLevel' => {'levelCode' => '10','levelName' => 'plot','levelOrder' => 2},'positionCoordinateX' => 75,'entryType' => 'check','positionCoordinateY' => 30,'geoCoordinates' => {'geometry' => {'coordinates' => ['-76.506042','42.417373',157],'type' => 'Point'},'type' => 'Feature'},'positionCoordinateXType' => 'GRID_COL','observationLevelRelationships' => [{'levelName' => 'rep','levelCode' => 'Rep_2','levelOrder' => 0}, {'levelName' => 'replicate','levelCode' => 'Rep_2','levelOrder' => 0},{'levelOrder' => 1,'levelCode' => 'Block_12','levelName' => 'block'},{'levelCode' => '10','levelName' => 'plot','levelOrder' => 2}],'positionCoordinateYType' => 'GRID_ROW'},'locationDbId' => '23','seedLotDbId' => undef,'studyDbId' => '165','observationUnitPUI' => 'localhost/stock/41300/view','additionalInfo' => undef,'externalReferences' => [],'observations' => [],'programName' => 'test','trialDbId' => '165','germplasmName' => 'TMEB693','germplasmDbId' => '41280','programDbId' => '134','locationName' => 'test_location','seedLotName' => undef,'observationUnitName' => 'CASS_6Genotypes_202','observationUnitDbId' => '41300'}]}}; +my $expected = {'metadata' => {'pagination' => {'totalCount' => 1,'pageSize' => 10,'currentPage' => 0,'totalPages' => 1},'status' => [{'messageType' => 'INFO','message' => 'BrAPI base call found with page=0, pageSize=10'},{'message' => 'Loading CXGN::BrAPI::v2::ObservationUnits','messageType' => 'INFO'},{'messageType' => 'INFO','message' => 'Observation Units search result constructed'}],'datafiles' => []},'result' => {'data' => [{'treatments' => [{'factor' => 'No ManagementFactor','modality' => undef}],'studyName' => 'CASS_6Genotypes_Sampling_2015','trialName' => 'CASS_6Genotypes_Sampling_2015','plotImageDbIds' => [],'observationUnitPosition' => {'observationLevel' => {'levelCode' => '10','levelName' => 'plot','levelOrder' => 2},'positionCoordinateX' => 75,'entryType' => 'test','positionCoordinateY' => 30,'geoCoordinates' => {'geometry' => {'coordinates' => ['-76.506042','42.417373',157],'type' => 'Point'},'type' => 'Feature'},'positionCoordinateXType' => 'GRID_COL','observationLevelRelationships' => [{'levelName' => 'rep','levelCode' => 'Rep_2','levelOrder' => 0}, {'levelName' => 'replicate','levelCode' => 'Rep_2','levelOrder' => 0},{'levelOrder' => 1,'levelCode' => 'Block_12','levelName' => 'block'},{'levelCode' => '10','levelName' => 'plot','levelOrder' => 2}],'positionCoordinateYType' => 'GRID_ROW'},'locationDbId' => '23','seedLotDbId' => undef,'studyDbId' => '165','observationUnitPUI' => 'localhost/stock/41300/view','additionalInfo' => undef,'externalReferences' => [],'observations' => [],'programName' => 'test','trialDbId' => '165','germplasmName' => 'TMEB693','germplasmDbId' => '41280','programDbId' => '134','locationName' => 'test_location','seedLotName' => undef,'observationUnitName' => 'CASS_6Genotypes_202','observationUnitDbId' => '41300'}]}}; print STDERR "\n\n Observation Unit Expected is : " . Dumper($expected); is_deeply($response, $expected, "PUT OU 41300 test" );