Skip to content

Commit

Permalink
Cleaned up defunct region & gcmd params. Fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
lomky committed Dec 12, 2018
1 parent 1bb518e commit 0a011bd
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 37 deletions.
3 changes: 1 addition & 2 deletions lib/Tuba/Activity.pm
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ sub make_tree_for_show {
my $c = shift;
my $obj = shift;
my $tree = $obj->as_tree(c => $c,
( $c->param('brief') ? (bonsai => 1) : ()),
( $c->param('with_gcmd') ? (with_gcmd => 1) : ())
( $c->param('brief') ? (bonsai => 1) : ())
);
$tree->{methodologies} = [
map $_->as_tree(c => $c), $obj->methodologies
Expand Down
7 changes: 3 additions & 4 deletions lib/Tuba/Controller.pm
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,6 @@ sub make_tree_for_show {
my $c = shift;
my $obj = shift;
my %params;
$params{with_gcmd} = 1 unless $c->param('with_gcmd') == 0;
$params{with_regions} = 1 unless $c->param('with_regions' == 0);
$params{bonsai} = 1 if $c->param('brief');
my $ret = $obj->as_tree(c => $c, %params);
if (my $gcid = $ret->{uri}) {
Expand Down Expand Up @@ -244,12 +242,13 @@ sub make_tree_for_show {
}

sub maybe_include_generic_pub_rels {
# these are no longer maybe
my $c = shift;
my $obj = shift;
my $pub = $obj->get_publication or return ();
my $tree = {};
$tree->{gcmd_keywords} = [ map $_->as_tree(@_), $pub->gcmd_keywords ] unless $c->param('with_gcmd') == 0;
$tree->{regions} = [ map $_->as_tree(@_), $pub->regions] if $c->param('with_regions');
$tree->{gcmd_keywords} = [ map $_->as_tree(@_), $pub->gcmd_keywords ];
$tree->{regions} = [ map $_->as_tree(@_), $pub->regions];
return %$tree;
}

Expand Down
10 changes: 4 additions & 6 deletions lib/Tuba/DB/Object.pm
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,8 @@ information :
- a list of parent publications
- a list of files
- a list of gcmd keywords (iff with_gcmd is sent)
- a list of regions (iff with_regions is sent)
- a list of gcmd keywords
- a list of regions
- a list of contributors (if this is a publication)
- a list of publications for each contributor record (if this is a contributor)
Expand All @@ -315,8 +315,6 @@ sub as_tree {
my %a = @_;
my $c = $a{c}; # controller object
my $bonsai = delete $a{bonsai}; # a small tree
my $with_gcmd = delete $a{with_gcmd}; # a large tree
my $with_regions = delete $a{with_regions}; # a large tree
$a{deflate} = 0 unless exists($a{deflate});

my $tree = $s->Rose::DB::Object::Helpers::as_tree(%a);
Expand All @@ -336,8 +334,8 @@ sub as_tree {
};
}
$tree->{files} = [ map $_->as_tree(@_), $pub->files ];
$tree->{gcmd_keywords} = [ map $_->as_tree(@_), $pub->gcmd_keywords ] if $with_gcmd;
$tree->{regions} = [ map $_->as_tree(@_), $pub->regions] if $with_regions;
$tree->{gcmd_keywords} = [ map $_->as_tree(@_), $pub->gcmd_keywords ];
$tree->{regions} = [ map $_->as_tree(@_), $pub->regions];
}
my $uri = $s->uri($c);
my $href = $uri->clone->to_abs;
Expand Down
37 changes: 15 additions & 22 deletions lib/Tuba/DocManager.pm
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ our %RouteDoc = (
list_scenario => { tags => [qw/model/], _list_defaults('scenario') },
list_lexicon => { tags => [qw/lexicon/], _list_defaults('lexicon') },

show_report => { tags => [qw/report/], _show_defaults('report', withs => 1) },
show_chapter => {tags => [qw/report/], _show_defaults('chapter', withs => 1) },
show_report => { tags => [qw/report/], _show_defaults('report') },
show_chapter => {tags => [qw/report/], _show_defaults('chapter') },
show_platform => {tags => [qw/obs/], _show_defaults('platform') },
show_instrument => {tags => [qw/obs/], _show_defaults('instrument') },
show_instrument_instance => {tags => [qw/obs/], _show_defaults('instrument', add => 'on a platform' ) },
Expand All @@ -161,20 +161,20 @@ our %RouteDoc = (
model_run_lookup => {tags => [qw/model/], _show_defaults('model run') },
show_scenario => {tags => [qw/model/], _show_defaults('scenario') },

show_figure => { tags => [qw/figure/], _show_defaults('figure', withs => 1, add => "in a chapter") },
show_finding => { tags => [qw/finding/], _show_defaults('finding', withs => 1, add => "in a chapter") },
show_table => { tags => [qw/table/], _show_defaults('table', withs => 1, add => "in a chapter") },
show_figure => { tags => [qw/figure/], _show_defaults('figure', add => "in a chapter") },
show_finding => { tags => [qw/finding/], _show_defaults('finding', add => "in a chapter") },
show_table => { tags => [qw/table/], _show_defaults('table', add => "in a chapter") },

show_report_figure => { tags => [qw/report figure/], _show_defaults('figure', withs => 1) },
show_report_finding => {tags => [qw/report finding/], _show_defaults('finding', withs => 1) },
show_report_table => {tags => [qw/report table/], _show_defaults('table', withs => 1) },
show_report_figure => { tags => [qw/report figure/], _show_defaults('figure') },
show_report_finding => {tags => [qw/report finding/], _show_defaults('finding') },
show_report_table => {tags => [qw/report table/], _show_defaults('table') },

show_article => { tags => [qw/publication/], _show_defaults('article', withs => 1) },
show_article => { tags => [qw/publication/], _show_defaults('article') },
show_journal => {tags => [qw/publication/], _show_defaults('journal') },
show_image => {tags => [qw/figure/], _show_defaults('image', withs => 1) },
show_array => {tags => [qw/table/], _show_defaults('array', withs => 1) },
show_webpage => {tags => [qw/publication/], _show_defaults('web page', withs => 1) },
show_book => {tags => [qw/publication/], _show_defaults('book', withs => 1) },
show_image => {tags => [qw/figure/], _show_defaults('image') },
show_array => {tags => [qw/table/], _show_defaults('array') },
show_webpage => {tags => [qw/publication/], _show_defaults('web page') },
show_book => {tags => [qw/publication/], _show_defaults('book') },
show_activity => {tags => [qw/dataset/], _show_defaults('activity') },
show_person => { tags => [qw/contributor/], _show_defaults('person') },
show_organization => { tags => [qw/contributor/], _show_defaults('organization') },
Expand Down Expand Up @@ -315,15 +315,8 @@ sub _show_defaults {
'application/json', 'application/x-turtle', 'text/turtle',
'application/n-triples', 'text/n3', 'text/rdf+n3', 'application/ld+json',
'application/rdf+xml', 'application/rdf+json',
],
$a{withs} ?
(
params => [
{ name => "with_regions", type => "boolean", description => "Include regions associated with the $what." },
{ name => "with_gcmd", type => "boolean", description => "Include GCMD keywords associated with the $what." },
]
) : ()
)
]
)
}

sub _route_to_path {
Expand Down
2 changes: 1 addition & 1 deletion lib/Tuba/Report.pm
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ sub make_tree_for_show {
my $format = $c->stash('format');
$href .= ".$format" if $format;
my %regions;
if ($pub && $c->param('with_regions')) {
if ($pub) {
$regions{regions} = [ map $_->as_tree(c => $c), $pub->regions];
}
my @parents;
Expand Down
4 changes: 2 additions & 2 deletions t/006_figure.t
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ $t->post_ok(
"/report/vegetables/chapter/carrots/figure/keywords/orange" => { Accept => "application/json" } => json =>
{identifier => "001f18d3-7e61-430b-9883-1960c6256fe5"})->status_is(200);

$t->get_ok( "/report/vegetables/chapter/carrots/figure/orange.json?with_gcmd=1")
$t->get_ok( "/report/vegetables/chapter/carrots/figure/orange.json")
->json_is( "/gcmd_keywords/0/identifier", "001f18d3-7e61-430b-9883-1960c6256fe5" );

# Create a region.
Expand All @@ -170,7 +170,7 @@ $t->post_ok(
"/report/vegetables/chapter/carrots/figure/regions/orange" => { Accept => "application/json" } => json =>
{identifier => "bermuda_triangle"})->status_is(200);

$t->get_ok( "/report/vegetables/chapter/carrots/figure/orange.json?with_regions=1")
$t->get_ok( "/report/vegetables/chapter/carrots/figure/orange.json")
->json_is( "/regions/0/identifier", "bermuda_triangle" );

$t->post_ok("/report/vegetables/chapter/carrots/figure/rel/orange" => { Accept => "application/json" } => json =>
Expand Down
1 change: 1 addition & 0 deletions t/010_stringify.t
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ $t->get_ok("/report/test-report.json")->json_is(
href => "${base}report/test-report.json",
report_type_identifier => 'report',
report_tables => [],
regions => [],
report_figures => [],
report_findings => [],
parents => [],
Expand Down
2 changes: 2 additions & 0 deletions t/014_array.t
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,13 @@ $t->get_ok("/report/vegetables/table/veggietable.json")->status_is(200)
'chapter_identifier' => undef,
'contributors' => [],
'files' => [],
'gcmd_keywords' => [],
'href' => "$base/report/vegetables/table/veggietable.json",
'identifier' => 'veggietable',
'ordinal' => '1-b',
'parents' => [],
'references' => [],
'regions' => [],
'cited_by' => [],
'report_identifier' => 'vegetables',
'title' => 'veggie table',
Expand Down

0 comments on commit 0a011bd

Please sign in to comment.