Skip to content
Snippets Groups Projects
Commit 8305041d authored by Jens Steidl's avatar Jens Steidl :baby_chick:
Browse files

- init: base is original checkit_tiff plugin "add dnx mappings" script

parent 333450cc
No related branches found
No related tags found
No related merge requests found
How to automatically add Mappings between extracted Technical Metadata and DNX Significant Properties in Rosetta
================================================================================================================
:lang: en
:encoding: utf-8
:author: Jörg Sachse
== Prerequisites
* Desktop environment
* Perl programming language
* Selenium Perl module (download at https://metacpan.org/pod/Selenium::Remote::Driver)
* Chrome browser (download at https://www.google.com/intl/de_de/chrome/)
* Chrome driver compatible with the installed Chrome browser (download at https://sites.google.com/chromium.org/driver/)
== How to install on Debian 11 (Buster)
* sudo apt install perl chromium cpanminus unzip
* cpanm Selenium::Remote::Driver
* check Chromium version (i.e. "91.x.xxxx.xxx") --> download coresponding 'chromedriver_linux64.zip' from https://sites.google.com/chromium.org/driver/ (Downloads)
* unzip chromedriver_linux64.zip
== How to build
* You don't have to do anything, just run the script.
== How to run
* general invocation
** $# perl -I path/to/perl/modules .add_dnx_mappings.pl "Rosetta-Host.Domain.tld" "Rosetta-User" "Rosetta-Password" "Institution-Name" "Portnumber"
* example invocation:
** $# perl -I ~/perl5/lib/perl5 ./add_dnx_mappings.pl "sdvrosetta-test.slub-dresden.de" "su-user" "Sw0rdF!$h" "SLUB" "8443"
#!/usr/bin/env perl
# adds all dnx properties
# by Andreas Romeyke (andreas.romeyke@slub-dresden.de) and Serhiy Bolkun (serhiy.bolkun@slub-dresden.de)
#
# usage: perl add_dnx_mappings.pl rosetta-host rosetta-user rosetta-user-password rosetta-institution rosetta-login-port
# example: perl add_dnx_mappings.pl rosetta.my-archive.domain user1 12345 MYINSTITUTE 8443
#
# needs a geckodriver and the Selenium::Remote::Driver module
# see http://www.seleniumhq.org/
#
# tested against Rosetta 7.0 using chromedriver and chromium 90.0.4430.93
# under Windows 10 and Debian 10
#
# ensure, that the plugin is assigned to a classification, for example to
# "Image (Mix)"
use strict;
use warnings;
use utf8;
use Selenium::Remote::Driver;
use Selenium::Chrome;
use Term::ANSIColor; # colored print
use Data::Printer;
use v5.10;
BEGIN {
if ($^O eq 'MSWin32') {
require Win32::Console::ANSI;
Win32::Console::ANSI->import();
}
}
my $host = shift;
my $user = shift;
my $passwd = shift;
my $institution = shift;
my $ui_port = shift;
my $protocol = 'https';
my %exiftool2dnx = (
"ICC-header:ColorSpaceData" => "icc.colorspacedata",
"ICC-header:DeviceModel" => "icc.devicemodel",
"ICC-header:PrimaryPlatform" => "icc.primaryplatform",
"ICC-header:ProfileCMMType" => "icc.profilecmmtype",
"ICC-header:ProfileCreator" => "icc.profilecreator",
"ICC-header:ProfileDateTime" => "icc.profiledatetime",
"ICC-header:ProfileVersion" => "icc.profileversion",
"ICC_Profile:CalibrationDateTime" => "icc.profilecalibrationdatetime",
"ICC_Profile:MakeAndModel" => "icc.makeandmodel",
"ICC_Profile:ProfileCopyright" => "icc.profilecopyright",
"ICC_Profile:ProfileDescription" => "icc.profiledescription",
"IFD0:BitsPerSample" => "tiff.bitspersample", # TIFF-Tag 258 BitsPerSample ()
"IFD0:Compression" => "tiff.compression",
"IFD0:Copyright" => "tiff.copyright", # TIFF-Tag 33432 Copyright ()
"IFD0:DocumentName" => "tiff.documentname", # TIFF-Tag 269 DocumentName ()
"ExifIFD:GrayResponseCurve" => "tiff.grayresponsecurve", # TIFF-Tag 291 GrayResponseCurve ()
"IFD0:GrayResponseUnit" => "tiff.grayresponseunit", # TIFF-Tag 290 GrayResponseUnit ()
"IFD0:ImageDescription" => "tiff.imagedescription", # TIFF-Tag 270 ImageDescription ()
"IFD0:ImageHeight" => "image.height", # TIFF-Tag 257 ImageLength ()
"IFD0:ImageWidth" => "image.width", # TIFF-Tag 256 ImageWidth ( )
"IFD0:Make" => "tiff.make", # TIFF-Tag 271 Make ()
"IFD0:MaxSampleValue" => "tiff.maxsamplevalue", # TIFF-Tag 281 MaxSampleValue ( )
"IFD0:MinSampleValue" => "tiff.minsamplevalue", # TIFF-Tag 280 MinSampleValue ( )
"IFD0:Model" => "tiff.model", # TIFF-Tag 272 Model ()
"IFD0:ModifyDate" => "tiff.datetime", # TIFF-Tag 306 DateTime ()
"IFD0:PageNumber" => "tiff.pagenumber", # TIFF-Tag 297 PageNumber ()
"IFD0:PhotometricInterpretation" => "tiff.photometricinterpretation", # TIFF-Tag 262 PhotometricInterpretation ()
"IFD0:PrimaryChromaticities" => "tiff.primarychromaticities", # TIFF-Tag 319 PrimaryChromaticities ()
"IFD0:SamplesPerPixel" => "tiff.samplesperpixel", # TIFF-Tag 277 SamplesPerPixel ()
"IFD0:Software" => "tiff.software", # TIFF-Tag 305 Software ()
"IFD0:WhitePoint" => "tiff.whitepoint", # TIFF-Tag 318 WhitePoint ()
"IFD0:XResolution" => "image.xresolution", # TIFF-Tag 282 XResolution ( Angabe in dpi)
"IFD0:YResolution" => "image.yresolution", # TIFF-Tag 283 YResolution ( Angabe in dpi)
);
my $plugin_name = "SLUBTechnicalMetadataExtractorCheckItTiffPlugin";
my $classification_group = "Image (Mix)";
my $driver = Selenium::Chrome->new();
$driver->debug_on;
$driver->set_implicit_wait_timeout(1000);
$driver->set_timeout('script', 1000);
print "Try to mechanize adding DNX, using:
host=$host
user=$user
institution=$institution
\n";
sub login {
$driver->get("$protocol://$host:${ui_port}/mng?auth=local");
my $ele_institute = $driver->find_element("institution", "id");
$driver->find_child_element($ele_institute, "./option[\@value='$institution']", "xpath")->click;
$driver->find_element("userName", "id")->clear;
$driver->find_element("userName", "id")->send_keys($user);
$driver->find_element("password", "id")->clear;
$driver->find_element("password", "id")->send_keys($passwd);
$driver->find_element("login", "id")->click;
}
sub logout {
$driver->get("$protocol://$host:${ui_port}/mng/action/menus.do?first_time_key=com.exlibris.dps.wrk.general.menu");
my $ele = $driver->find_element("user", "id")->click;
$driver->pause();
$ele = $driver->find_element("Logout", "link")->click;
}
sub _change_to_xxx_format_library {
$driver->get("$protocol://$host:${ui_port}/mng/action/menus.do?first_time_key=com.exlibris.dps.wrk.general.menu");
$driver->find_element("//a[\@title='Administer the system']", "xpath")->click;
$driver->find_element("General Parameters", "link")->click;
$driver->find_element("modules_button", "id")->click;
$driver->find_element("//li[\@title='format_library']", "xpath")->click;
my $tr = $driver->find_element("//tr[starts-with(td,'format_library_is_global')]", "xpath");
my $td = $driver->find_child_element($tr, "./td[\@class='form-inline']", "xpath");
$driver->find_element("generalParameters_model_parameters_2__value_button", "id")->click;
say "click combobox button";
return $td;
}
sub change_to_global_format_library {
my $td = _change_to_xxx_format_library();
$driver->find_child_element($td, "descendant::li[text()='true']", "xpath")->click;
say "select true";
$driver->find_element("//button[\@value='Update']", "xpath")->click;
say "click update button";
}
sub change_to_local_format_library {
my $td = _change_to_xxx_format_library();
$driver->find_child_element($td, "descendant::li[text()='false']", "xpath")->click;
say "select false";
$driver->find_element("//button[\@value='Update']", "xpath")->click;
say "click update button";
$driver->pause();
}
sub add_dnx_property($$) {
my $dnx_property = shift;
my $dnx_description = shift;
my $dow = localtime;
$driver->get("$protocol://$host:${ui_port}/mng/action/pageAction.page_xml.page_sig_prop_list.xml.do?pageViewMode=Edit&pageBean.currentUserMode=GLOBAL&menuKey=com.exlibris.dps.wrk.general.menu.Preservation.AdvancedPreservationActivities.mngLibraryGLOBAL.mngLibraryHeader.SigProps.InnerMenu&menuKey=com.exlibris.dps.wrk.general.menu.Preservation.AdvancedPreservationActivities.mngLibraryGLOBAL.mngLibraryHeader.SigProps.InnerMenu&backUrl=");
$driver->pause();
$driver->find_element("Add Significant Property", "link")->click;
$driver->find_element("selectedSigPropname", "id")->clear;
$driver->find_element("selectedSigPropname", "id")->send_keys("$dnx_property");
$driver->find_element("selectedSigPropdescription", "id")->clear;
$driver->find_element("selectedSigPropdescription", "id")->send_keys("$dnx_description (automatisiert durch $0 hinzugefügt, $dow)");
$driver->find_element("SaveSigPropGenDetails", "name")->click;
}
sub join_dnx_property_to_classification_group($) {
my $dnx_property = shift;
say "try to join dnx property";
$driver->get("$protocol://$host:${ui_port}/mng/action/pageAction.page_xml.page_classification_list.xml.do?pageViewMode=Edit&pageBean.currentUserMode=GLOBAL&menuKey=com.exlibris.dps.wrk.general.menu.Preservation.AdvancedPreservationActivities.mngLibraryGLOBAL.mngLibraryHeader.Classifications.InnerMenu&menuKey=com.exlibris.dps.wrk.general.menu.Preservation.AdvancedPreservationActivities.mngLibraryGLOBAL.mngLibraryHeader.Classifications.InnerMenu&backUrl=");
$driver->pause();
$driver->find_element("find0.0", "id")->clear;
$driver->find_element("find0.0", "id")->send_keys($classification_group);
$driver->find_element("go", "name")->click;
$driver->find_element("Edit", "link")->click;
$driver->find_element("Related Properties", "link")->click;
$driver->find_element("//form[\@id='classificationDetails']//div[\@class='available']//div//input", "xpath")->clear;
$driver->find_element("//form[\@id='classificationDetails']//div[\@class='available']//div//input", "xpath")->send_keys($dnx_property);
$driver->pause();
$driver->find_element("Add all", "link")->click;
$driver->find_element("SaveClassificationGenDetails", "name")->click;
$driver->pause();
}
sub extractors_add_mapping($$) {
my $dnx_property = shift;
my $exiftool_property = shift;
say "try to add extractor mapping";
$driver->get("$protocol://$host:${ui_port}//mng/action/pageAction.page_xml.page_extractors_list.xml.do?pageBean.deploymentMode=BUNDLED&pageViewMode=Edit&pageBean.currentUserMode=LOCAL&RenewBean=true&menuKey=com.exlibris.dps.wrk.general.menu.Preservation.AdvancedPreservationActivities.mngLibraryLOCAL.mngLibraryHeader.Extractors.InnerMenu&menuKey=com.exlibris.dps.wrk.general.menu.Preservation.AdvancedPreservationActivities.mngLibraryLOCAL.mngLibraryHeader.Extractors.InnerMenu&backUrl=");
$driver->pause();
$driver->find_element("Custom", "link")->click;
$driver->find_element("find1.0", "id")->clear;
$driver->find_element("find1.0", "id")->send_keys($plugin_name);
$driver->find_element("go", "name")->click;
$driver->find_element("Edit", "link")->click;
$driver->find_element("Add Mapping", "link")->click;
$driver->find_element("pageBeancurrentMappingextractorProperty_input", "id")->clear;
$driver->find_element("pageBeancurrentMappingextractorProperty_button", "id")->click;
$driver->pause();
$driver->find_element("//li[\@title='$exiftool_property']", "xpath")->click;
$driver->pause();
$driver->find_element("pageBeancurrentMappingclassificationProperty_input", "id")->clear;
$driver->find_element("pageBeancurrentMappingclassificationProperty_button", "id")->click;
$driver->pause();
$driver->find_element("//li[\@title='$dnx_property']", "xpath")->click;
$driver->pause();
$driver->find_element("pageBeancurrentMappingnormalizer_input", "id")->click;
$driver->find_element("pageBeancurrentMappingnormalizer_input", "id")->click;
$driver->find_element("pageBeancurrentMappingnormalizer_input", "id")->clear;
$driver->pause();
$driver->find_element("page.buttons.operation", "name")->click;
$driver->pause();
}
# login
printf colored("Step 1 of 7: login \n", 'bold green');
login();
# change to global format library
printf colored("Step 2 of 7: change to global format library \n", 'bold green');
change_to_global_format_library();
# add dnx property
printf colored("Step 3 of 7: add dnx property \n", 'bold green');
foreach my $exiftool_property (sort keys %exiftool2dnx) {
my $dnx_property = $exiftool2dnx{ $exiftool_property };
add_dnx_property($dnx_property, "$dnx_property <- Exiftool '$exiftool_property'");
}
# include dnx property to classification group (Image(MIX))
printf colored("Step 4 of 7: join dnx property to classification group \n", 'bold green');
foreach my $exiftool_property (sort keys %exiftool2dnx) {
my $dnx_property = $exiftool2dnx{ $exiftool_property };
join_dnx_property_to_classification_group($dnx_property);
}
# add mapping
printf colored("Step 5 of 7: extractors add mapping \n", 'bold green');
foreach my $exiftool_property (sort keys %exiftool2dnx) {
my $dnx_property = $exiftool2dnx{ $exiftool_property };
extractors_add_mapping($dnx_property, $exiftool_property);
}
# change to local format library
printf colored("Step 6 of 7: change to local format library \n", 'bold green');
change_to_local_format_library();
# logout
printf colored("Step 7 of 7: logout \n", 'bold green');
logout();
$driver->quit();
$driver->shutdown_binary();
printf colored("Finish! \n", 'bold green');
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment