Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update to ukf-members 1.4.0
Handles members.xml schema 1.7, which introduces a mandatory orgID
attribute for all Grant and GrantAll elements.
Move to presenting the schema from ukf-data/members to the Members
constructor; this allows minor additional schema evolutions to be made
without needing ukf-members to be rebuilt.
utilities/2016-10-06 holds scripts used for the members.xml conversion.
iay committed Oct 8, 2016
1 parent 8c9f93d commit 7d8851d
Showing 6 changed files with 91 additions and 1 deletion.
16 changes: 15 additions & 1 deletion mdx/uk/beans.xml
@@ -137,13 +137,27 @@
</bean>


<!--
uk_membersSchemaDocument
This bean loads the schema for the members.xml file as a DOM Document.
-->
<bean id="uk_membersSchemaDocument" parent="DOMDocumentFactoryBean">
<property name="resource">
<bean parent="FileSystemResource" c:_="${members.dir}/ukfederation-members.xsd"/>
</property>
<property name="parserPool" ref="parserPool"/>
</bean>


<!--
uk_members
This bean implements an API for access to the contents of the members.xml document.
-->
<bean id="uk_members" class="uk.org.ukfederation.members.Members"
c:_-ref="uk_membersDocument"/>
c:_0-ref="uk_membersDocument"
c:_1-ref="uk_membersSchemaDocument"/>


<!--
Binary file removed tools/ukf-mda/ukf-members-1.3.0.jar
Binary file not shown.
Binary file added tools/ukf-mda/ukf-members-1.4.0.jar
Binary file not shown.
25 changes: 25 additions & 0 deletions utilities/2016-10-06/README.md
@@ -0,0 +1,25 @@
# `utilities/2016-10-06`

These transforms and scripts were used to add an `orgID` attribute to the
`Grant` and `GrantAll` elements on all participants in the `members.xml` file.

## 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

Apply the `patch.pl` script to generate a new version of `members.xml`.

./patch.pl members/members.xml >members/members-new.xml

Compare the two versions of the file before replacing the old one.
19 changes: 19 additions & 0 deletions utilities/2016-10-06/gen-id-to-name.xsl
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:members="http://ukfederation.org.uk/2007/01/members"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<xsl:output method="text" encoding="UTF-8"/>

<xsl:template match="members:Member">
<xsl:value-of select="@ID"/>
<xsl:text>&#9;</xsl:text>
<xsl:value-of select="members:Name"/>
<xsl:text>&#10;</xsl:text>
</xsl:template>

<xsl:template match="text()">
<!-- do nothing -->
</xsl:template>
</xsl:stylesheet>
32 changes: 32 additions & 0 deletions utilities/2016-10-06/patch.pl
@@ -0,0 +1,32 @@
#!/usr/bin/env perl -W

open(F, "id-to-name.txt") || die "could not open id-to-name map";
while (<F>) {
my ($orgid, $name) = split /[\t\n]/;
#print "name='$name' --> orgid='$orgid'\n";
$name_to_orgid{$name} = $orgid;
}
close(F);

while (<>) {
# 12 2 3 3 1 4 4 5 5
if (/^((.*)<Grant(All)?)\s+to=\"([^\"]+)\"(.*)$/) {
my $pre = $1;
my $xmlName = $4;
my $post = $5;
my $name = $xmlName;
$name =~ s/\&amp\;/\&/;
#print "pre -$pre- xmlName -$xmlName- name -$name- post -$post-\n";
my $orgID = $name_to_orgid{$name};
if (!defined($orgID)) {
die "no map for -$xmlName- -$name-\n";
}
print "$pre to=\"$xmlName\" orgID=\"$orgID\"$post\n";
#print "$pre orgID=\"$orgID\" to=\"$xmlName\"$post\n";
} elsif (/<Grant(All)?\s+/) {
die "bad Grant $_";
} else {
print $_;
}
}
close(F);

0 comments on commit 7d8851d

Please sign in to comment.