From 37d0bdfc54044864d78d7650005659eaf0e7465a Mon Sep 17 00:00:00 2001 From: Ian Young Date: Mon, 19 Sep 2016 17:01:02 +0100 Subject: [PATCH] Archive tools used to inject orgID values --- utilities/2016-09-16/README.md | 42 +++++++++++++++++++++++ utilities/2016-09-16/doall.pl | 26 ++++++++++++++ utilities/2016-09-16/gen-id-to-name.xsl | 19 ++++++++++ utilities/2016-09-16/gen-ukid-to-name.xsl | 19 ++++++++++ utilities/2016-09-16/patch.pl | 10 ++++++ 5 files changed, 116 insertions(+) create mode 100644 utilities/2016-09-16/README.md create mode 100755 utilities/2016-09-16/doall.pl create mode 100644 utilities/2016-09-16/gen-id-to-name.xsl create mode 100644 utilities/2016-09-16/gen-ukid-to-name.xsl create mode 100755 utilities/2016-09-16/patch.pl diff --git a/utilities/2016-09-16/README.md b/utilities/2016-09-16/README.md new file mode 100644 index 00000000..f825db1a --- /dev/null +++ b/utilities/2016-09-16/README.md @@ -0,0 +1,42 @@ +# `utilities/2016-09-16` + +These transforms and scripts were used to add an `orgID` attribute to the +`UKFederationMember` elements on all currently registered entities. + +## Step 1 + +Generate `id-to-name.txt` as follows: + + xsltproc --output=id-to-name.txt gen-id-to-name.xsl members/members.xml + +This file contains a mapping between organization IDs and canonical +organization names, like this: + +ukforg4590 Ian A. Young + +The first field is separated from the second by a single tab character. + +## Step 2 + +Generate `ukid-to-name.txt` as follows: + + xsltproc gen-ukid-to-name.xsl entities/uk*.xml >ukid-to-name.txt + +This file contains a mapping between entity `ID` attributes and canonical +organization names, like this: + + uk000006 Ian A. Young + +Again, the separator between the first and second fields is a single tab character. + +## Step 3 + +Combining the results of steps 1 and 2, we can generate a list of all entity +files (named after entity `ID` values as in `ukid-to-name.txt`), via +the canonical organization name, to the organization ID values found in +`members.xml`. + +This is then applied to all entity fragment files by executing `./doall.pl`. + +`doall` reads both data files, then iterates across all fragment files calling +`patch.pl` to inject the appropriate `orgID` value. diff --git a/utilities/2016-09-16/doall.pl b/utilities/2016-09-16/doall.pl new file mode 100755 index 00000000..7056b5d1 --- /dev/null +++ b/utilities/2016-09-16/doall.pl @@ -0,0 +1,26 @@ +#!/usr/bin/env perl -W + +open(F, "id-to-name.txt") || die "could not open id-to-name map"; +while () { + my ($orgid, $name) = split /[\t\n]/; + # print "name='$name' --> orgid='$orgid'\n"; + $name_to_orgid{$name} = $orgid; +} +close(F); + +open(F, "ukid-to-name.txt") || die "could not open ukid-to-name map"; +while () { + my ($ukid, $name) = split /[\t\n]/; + # print "ukid='$ukid' --> name='$name'\n"; + if (defined $name_to_orgid{$name}) { + # print " --> orgid='$name_to_orgid{$name}'\n" + my $orgid = $name_to_orgid{$name}; + $command = "perl -i patch.pl $orgid entities/$ukid.xml"; + print "$ukid --> $orgid $command\n"; + system($command); + } else { + die "'$name' unmapped"; + # print " --> undefined\n"; + } +} +close(F); diff --git a/utilities/2016-09-16/gen-id-to-name.xsl b/utilities/2016-09-16/gen-id-to-name.xsl new file mode 100644 index 00000000..a2c477cc --- /dev/null +++ b/utilities/2016-09-16/gen-id-to-name.xsl @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + diff --git a/utilities/2016-09-16/gen-ukid-to-name.xsl b/utilities/2016-09-16/gen-ukid-to-name.xsl new file mode 100644 index 00000000..3df2bd3b --- /dev/null +++ b/utilities/2016-09-16/gen-ukid-to-name.xsl @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + diff --git a/utilities/2016-09-16/patch.pl b/utilities/2016-09-16/patch.pl new file mode 100755 index 00000000..c47766c3 --- /dev/null +++ b/utilities/2016-09-16/patch.pl @@ -0,0 +1,10 @@ +#!/usr/bin/env perl -W + +my $orgID = shift @ARGV; + +while (<>) { + if (/UKFederationMember/ && !/orgID/) { + s/UKFederationMember/UKFederationMember orgID="$orgID"/; + } + print $_; +}