Skip to content

Commit

Permalink
Merge 3dedd2b into 234dff7
Browse files Browse the repository at this point in the history
  • Loading branch information
lomky committed Aug 10, 2018
2 parents 234dff7 + 3dedd2b commit b27f780
Show file tree
Hide file tree
Showing 14 changed files with 5,502 additions and 59 deletions.
21 changes: 21 additions & 0 deletions db/patches/2410_activity_v2_deprecations.sql
@@ -0,0 +1,21 @@
/* Changes to create a modern version of the Activity */

COMMENT ON COLUMN activity.duration
IS 'DEPRECATED - use activity_duration to document the time taken to perform the activity.';
COMMENT ON COLUMN activity.data_usage
IS 'DEPRECATED - A description of the way in which input data were used for this activity.';
COMMENT ON COLUMN activity.notes
IS 'DEPRECATED - Other information about this activity which might be useful for traceability or reproducability.';

COMMENT ON COLUMN activity.output_artifacts
IS 'Deprecated outside of NCO assessment activities. The final output filenames from the process.';

COMMENT ON COLUMN activity.methodology
IS 'The process of creating the resulting object from the input, in the author’s own words and in such a way that another expert partycould reproduce the output.';
COMMENT ON COLUMN activity.visualization_software
IS 'Primary visualization software (with version) used.';

COMMENT ON COLUMN activity.start_time
IS 'Time bounds used to restrict the input object. Optional, depending on applicability. If equal to end_time, indicates a temporal moment.';
COMMENT ON COLUMN activity.end_time
IS 'Time bounds used to restrict the input object. Optional, depending on applicability. If equal to start_time, indicates a temporal moment.';
30 changes: 30 additions & 0 deletions db/patches/2420_activity_v2_new_columns.sql
@@ -0,0 +1,30 @@
/* New activity fields */

ALTER table activity ADD COLUMN activity_duration interval;
ALTER table activity ADD COLUMN source_access_date date;
ALTER table activity ADD COLUMN interim_artifacts text;
ALTER table activity ADD COLUMN source_modifications text;
ALTER table activity ADD COLUMN modified_source_location text;
ALTER table activity ADD COLUMN visualization_methodology text;
ALTER table activity ADD COLUMN methodology_citation text;
ALTER table activity ADD COLUMN methodology_contact text;
ALTER table activity ADD COLUMN database_variables text;

COMMENT ON COLUMN activity.activity_duration
IS 'Captures the time taken in the process to get from the source object to the final one.';
COMMENT ON COLUMN activity.source_access_date
IS 'The date the parent resource was accessed.';
COMMENT ON COLUMN activity.interim_artifacts
IS 'Deprecated outside of NCO assessment activities. The names of files created along the way to create the final product.';
COMMENT ON COLUMN activity.source_modifications
IS 'A written description of modifications done to the source object.';
COMMENT ON COLUMN activity.modified_source_location
IS 'The location of the modified source, if available.';
COMMENT ON COLUMN activity.visualization_methodology
IS 'The process of creating the visual portion of the output object, if any and if distinguished from the main methodology.';
COMMENT ON COLUMN activity.methodology_citation
IS 'The citation to the methodology, if it has been published.';
COMMENT ON COLUMN activity.methodology_contact
IS 'The point of contact for the methodology, if any.';
COMMENT ON COLUMN activity.database_variables
IS 'A list of Dataset Variables applied in this activity.';
4 changes: 4 additions & 0 deletions db/patches/2430_activity_v2_spatial_extent.sql
@@ -0,0 +1,4 @@
/* New activity field */

ALTER TABLE activity ADD COLUMN spatial_extent json;
COMMENT ON COLUMN activity.spatial_extent IS 'Spatial bounds used to restrict the input object. GeoJSON. Optional, depending on applicability.';
2 changes: 1 addition & 1 deletion lib/Tuba.pm
Expand Up @@ -258,7 +258,7 @@ sub startup {
)
]x;
for my $format (@supported_formats) {
$resource->get("(*$identifier).$format" => \@restrict => { format => $format } )
$resource->get("<*$identifier>.$format" => \@restrict => { format => $format } )
->over(not_match => { $identifier => $reserved })
->to('#show')->name("_show_${name}_$format");
}
Expand Down
86 changes: 84 additions & 2 deletions lib/Tuba/Activity.pm
Expand Up @@ -7,6 +7,7 @@ Tuba::Activity : Controller class for books
package Tuba::Activity;
use Mojo::Base qw/Tuba::Controller/;
use Tuba::DB::Objects qw/-nicknames/;
use JSON::XS;

sub list {
my $c = shift;
Expand All @@ -19,6 +20,22 @@ sub show {
$c->SUPER::show(@_);
}

sub create {
my $c = shift;
my $spatial_extent = $c->_spatial_extent;
my $error = _check_valid_geojson($spatial_extent) if $spatial_extent;
return $c->create_error($error) if $error;
$c->SUPER::create(@_);
}

sub update {
my $c = shift;
my $spatial_extent = $c->_spatial_extent;
my $error = _check_valid_geojson($spatial_extent) if $spatial_extent;
return $c->update_error($error) if $error;
$c->SUPER::update(@_);
}

sub make_tree_for_show {
my $c = shift;
my $obj = shift;
Expand Down Expand Up @@ -54,8 +71,30 @@ sub normalize_form_parameter {

sub _default_order {
my $c = shift;
return ( $c->SUPER::_default_order(), qw/methodology_publication_id methodology_contributor_id/ );

return ( qw/
identifier
methodology
visualization_methodology
methodology_citation
methodology_contact
activity_duration
source_access_date
source_modifications
modified_source_location
interim_artifacts
output_artifacts
computing_environment
software
visualization_software
start_time
end_time
database_variables
spatial_extent
data_usage
notes
methodology_publication_id
methodology_contributor_id/
);
}

sub update_rel_form {
Expand Down Expand Up @@ -109,5 +148,48 @@ sub update_rel {
);
}

sub _spatial_extent {
my $c = shift;
return $c->param('spatial_extent') if $c->param('spatial_extent');

my $json = $c->req->json;
return unless $json;
return $json->{spatial_extent};

}

sub _check_valid_geojson {
my $spatial_param = shift;
my $valid_geojson_types = {
Point => 1,
MultiPoint => 1,
LineString => 1,
MultiLineString => 1,
Polygon => 1,
MultiPolygon => 1,
GeometryCollection => 1,
Feature => 1,
FeatureCollection => 1,
};
# parse valid JSON
my $error;
my $geojson = eval { JSON::XS->new->decode($spatial_param); };
if ($@ || (ref $geojson ne 'HASH')) {
$error = "Invalid geoJSON: could not parse json :".($@ || ref $geojson);
}
# check the field type exists
if ( !$error && $geojson->{'type'} ) {
# check the type value is valid
unless ( $valid_geojson_types->{ $geojson->{'type'} } ) {
$error = "Invalid geoJSON: Bad type '$geojson->{type}' not one of: " . join(', ', keys %$valid_geojson_types);
}
}
else {
$error = "Invalid geoJSON: missing type field" unless $error;
}

return $error;
}

1;

13 changes: 13 additions & 0 deletions lib/Tuba/DB/Mixin/Object/Activity.pm
@@ -1,6 +1,7 @@
package Tuba::DB::Object::Activity;
# Tuba::DB::Mixin::Object::Activity
use Tuba::Util qw[new_uuid];
use JSON::XS;
use strict;

__PACKAGE__->meta->primary_key_generator(sub {
Expand All @@ -12,5 +13,17 @@ sub stringify {
return $s->identifier;
}

sub bounding_box {
my $s = shift;

my $box;
if ( $s->spatial_extent ) {
my $j = JSON::XS->new->decode($s->spatial_extent);
$box = $j->{'bbox'} if $j->{'bbox'};
}

return $box;
};

1;

3 changes: 2 additions & 1 deletion lib/Tuba/Generic.pm
Expand Up @@ -39,7 +39,8 @@ sub update {
$generic->delete_attr( { del_attr => $params->{delete_pub_attr}, audit_user => $c->user, audit_note => "Setting attributes" });
$c->redirect_without_error('update_form');
}
elsif ( exists $params->{new_attr_key} || /^attribute/ ~~ %$params ) {
# find any new attr keys or attribute_* keys
elsif ( exists $params->{new_attr_key} || grep { /^attribute/ } keys %$params ) {
my $new_attributes = _collect_attributes($params);
$generic->set_attr( { new_attrs => $new_attributes, audit_user => $c->user, audit_note => "Setting attributes" });
$c->redirect_without_error('update_form');
Expand Down

0 comments on commit b27f780

Please sign in to comment.