Changeset 37059 for gs3-extensions


Ignore:
Timestamp:
2022-12-25T18:05:46+13:00 (16 months ago)
Author:
davidb
Message:

Turns out each canvas/page needs its own annotation-list

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gs3-extensions/structured-image/trunk/perllib/plugins/GoogleVisionAPIConverter.pm

    r37046 r37059  
    327327{
    328328    my $self = shift (@_);
     329    my ($doc_obj,$section) = @_;
     330
     331    my $OID = $doc_obj->get_OID();
     332
     333    my $openannotation_list = {
     334        "\@context" => "http://www.shared-canvas.org/ns/context.json",
     335    # "\@id"      => "https://iiif.harvardartmuseums.org/manifests/object/299843/list/47174896",
     336    "\@id"      => "${OID}/openannotation-list.json",  # #### **** make full URL to be unique? or greenstone3:site:collect:OID ??
     337    "\@type"    => "sc:AnnotationList",
     338    "resources" => []
     339    };
     340
     341    $self->{'openannotation-list'} = $openannotation_list;
     342}
     343
     344
     345
     346sub start_openannotation_list_ALLINONE
     347{
     348    my $self = shift (@_);
    329349    my ($doc_obj) = @_;
    330350
     
    511531
    512532    my $outhandle = $self->{'outhandle'};
     533
     534    my $all_saved_ok = 1;
     535   
     536    for my $gv_json_filename_rec (@$gv_dococr_json_filename_recs) {
     537    my $gv_json_filename = $gv_json_filename_rec->{'filename'};
     538    my $section = $gv_json_filename_rec->{'section'};
     539
     540
     541    my ($gv_dococr_filename_root) = ($gv_dococr_json_filename_recs->[0]->{'filename'} =~ m/^(.+)\.json$/);
     542
     543    # slight of hand so new directory spot in cache_dir picked out is where we want it!
     544    $gv_dococr_filename_root .= "/";
     545   
     546    my $collect_dir = $ENV{'GSDLCOLLECTDIR'};
     547    my $toplevel_cached_dir = &FileUtils::filenameConcatenate($collect_dir,"cached");
     548   
     549    $self->init_cache_for_file($gv_dococr_filename_root);
     550    my $cached_dir = $self->{'cached_dir'};
     551
     552    my $assoc_openannotation_json_ofile = "openannotation-list${section}.json";
     553    my $cached_openannotation_json_ofilename = &FileUtils::filenameConcatenate($cached_dir,$assoc_openannotation_json_ofile);   
     554
     555    my $needs_json_regen = 0;
     556
     557    if (!-f $cached_openannotation_json_ofilename) {
     558        $needs_json_regen = 1;
     559    }
     560    else {
     561        if (-M $gv_json_filename > -M $cached_openannotation_json_ofilename) {
     562        $needs_json_regen = 1;
     563        }
     564    }
     565
     566    my $saved_ok = 1;
     567   
     568    if ($needs_json_regen) {
     569
     570        print $outhandle "  OpenAnnotation-List: Generating $cached_openannotation_json_ofilename\n";
     571   
     572        $self->start_openannotation_list($doc_obj);
     573        $self->convert_and_append_openannotation_resources($gv_json_filename, $doc_obj,$section);
     574       
     575        $saved_ok = $self->end_openannotation_list($doc_obj,$cached_openannotation_json_ofilename);
     576    }
     577    else {
     578        print $outhandle "  OpenAnnotation-List: Cached file $cached_openannotation_json_ofilename already exists\n";
     579    }
     580
     581    if ($saved_ok) {
     582        my $top_section = $doc_obj->get_top_section();
     583        $doc_obj->associate_file($cached_openannotation_json_ofilename,$assoc_openannotation_json_ofile,"application/json",$top_section);
     584    }
     585    else {
     586        $all_saved_ok = 0;
     587    }
     588    }
     589
     590    return $all_saved_ok;
     591}
     592
     593
     594
     595sub openannotation_list_associate_json_ALLINONE
     596{
     597    my $self = shift (@_);
     598    my ($doc_obj, $gv_dococr_json_filename_recs) = @_;
     599
     600    my $outhandle = $self->{'outhandle'};
    513601   
    514602    # Guaranteed to have at least one value in gv_dococr_json_filename_recs
     
    573661}
    574662
     663
    575664sub opt_run_gen_openannotation
    576665{   
Note: See TracChangeset for help on using the changeset viewer.