Add NCIP::PhysicalAddress object.
authorJason Stephenson <jason@sigio.com>
Fri, 24 Oct 2014 12:29:00 +0000 (08:29 -0400)
committerJason Stephenson <jason@sigio.com>
Fri, 24 Oct 2014 12:32:34 +0000 (08:32 -0400)
I started to add this to the code last night to make addresses even
more abstract and extensible. Instead, I took a short cut. In the
light of the new day, I decided to go back and add this class as the
right thing to do.

We modify NCIP::ILS::Evergreen, NCIP::User::AddressInformation, and
the include for UserOptionalFields to make use of the new object.

Signed-off-by: Jason Stephenson <jason@sigio.com>
lib/NCIP/ILS/Evergreen.pm
lib/NCIP/PhysicalAddress.pm [new file with mode: 0644]
lib/NCIP/User/AddressInformation.pm
templates/includes/UserOptionalFields.inc

index 87b4a77..4b444bd 100644 (file)
@@ -50,6 +50,7 @@ use NCIP::User::PrivilegeStatus;
 use NCIP::StructuredPersonalUserName;
 use NCIP::StructuredAddress;
 use NCIP::ElectronicAddress;
+use NCIP::PhysicalAddress;
 use NCIP::RequestId;
 use NCIP::Item::Id;
 use NCIP::Item::OptionalFields;
@@ -1319,14 +1320,21 @@ sub handle_user_elements {
         foreach my $addr (@{$user->addresses()}) {
             next if ($U->is_true($addr->pending()));
             my $address = NCIP::User::AddressInformation->new({UserAddressRoleType=>$addr->address_type()});
-            my $physical = NCIP::StructuredAddress->new();
-            $physical->Line1($addr->street1());
-            $physical->Line2($addr->street2());
-            $physical->Locality($addr->city());
-            $physical->Region($addr->state());
-            $physical->PostalCode($addr->post_code());
-            $physical->Country($addr->country());
-            $address->PhysicalAddress($physical);
+            my $structured = NCIP::StructuredAddress->new();
+            $structured->Line1($addr->street1());
+            $structured->Line2($addr->street2());
+            $structured->Locality($addr->city());
+            $structured->Region($addr->state());
+            $structured->PostalCode($addr->post_code());
+            $structured->Country($addr->country());
+            $address->PhysicalAddress(
+                NCIP::PhysicalAddress->new(
+                    {
+                        StructuredAddress => $structured,
+                        Type => 'Postal Address'
+                    }
+                )
+            );
             push @$addresses, $address;
         }
 
diff --git a/lib/NCIP/PhysicalAddress.pm b/lib/NCIP/PhysicalAddress.pm
new file mode 100644 (file)
index 0000000..61d1d97
--- /dev/null
@@ -0,0 +1,55 @@
+# ---------------------------------------------------------------
+# Copyright © 2014 Jason J.A. Stephenson <jason@sigio.com>
+#
+# This file is part of NCIPServer.
+#
+# NCIPServer is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# NCIPServer is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with NCIPServer.  If not, see <http://www.gnu.org/licenses/>.
+# ---------------------------------------------------------------
+package NCIP::PhysicalAddress;
+use parent qw(Class::Accessor);
+
+
+=head1 NAME
+
+PhysicalAddress - A "PhysicalAddress" as defined by Z39.83-1-2012
+
+=head1 SYNOPSIS
+
+
+
+=head1 DESCRIPTION
+
+This a "PhysicalAddress" as defined by Z39.83-1-2012.  It is used
+for returning user address information when requested.  The fields
+are as defined in the standard.
+
+=head1 FIELDS
+
+=head2 StructuredAddress
+
+A NCIP::StructuredAddress object to hold the actual address.
+
+=head2 UnstructuredAddress
+
+Not presently implemented.
+
+=head2 Type
+
+The PhysicalAddressType field. Usually "Postal Address" or "Street Address."
+
+=cut
+
+NCIP::PhysicalAddress->mk_accessors(qw(StructuredAddress Type));
+
+1;
index c8886ff..dde29ba 100644 (file)
@@ -42,7 +42,7 @@ A text string to indicate the role of the address.
 
 =head2 PhysicalAddress
 
-A physical address stored in a NCIP::StructuredAddress.
+A physical address stored in a NCIP::PhysicalAddress.
 
 =head2 ElectronicAddress
 
index cf4436d..5ef3dda 100644 (file)
 [% IF element.PhysicalAddress -%]
 <PhysicalAddress>
 <StructuredAddress>
-<Line1>[% element.PhysicalAddress.Line1 | xml %]</Line1>
-[% IF element.PhysicalAddress.Line2 -%]
-<Line2>[% element.PhysicalAddress.Line2 | xml %]</Line2>
+<Line1>[% element.PhysicalAddress.StructuredAddress.Line1 | xml %]</Line1>
+[% IF element.PhysicalAddress.StructuredAddress.Line2 -%]
+<Line2>[% element.PhysicalAddress.StructuredAddress.Line2 | xml %]</Line2>
 [% END -%]
-[% IF element.PhysicalAddress.Locality -%]
-<Locality>[% element.PhysicalAddress.Locality | xml %]</Locality>
+[% IF element.PhysicalAddress.StructuredAddress.Locality -%]
+<Locality>[% element.PhysicalAddress.StructuredAddress.Locality | xml %]</Locality>
 [% END -%]
-[% IF element.PhysicalAddress.Region -%]
-<Region>[% element.PhysicalAddress.Region | xml %]</Region>
+[% IF element.PhysicalAddress.StructuredAddress.Region -%]
+<Region>[% element.PhysicalAddress.StructuredAddress.Region | xml %]</Region>
 [% END -%]
-[% IF element.PhysicalAddress.Country -%]
-<Country>[% element.PhysicalAddress.Country | xml %]</Country>
+[% IF element.PhysicalAddress.StructuredAddress.Country -%]
+<Country>[% element.PhysicalAddress.StructuredAddress.Country | xml %]</Country>
 [% END -%]
-[% IF element.PhysicalAddress.PostalCode -%]
-<PostalCode>[% element.PhysicalAddress.PostalCode | xml %]</PostalCode>
+[% IF element.PhysicalAddress.StructuredAddress.PostalCode -%]
+<PostalCode>[% element.PhysicalAddress.StructuredAddress.PostalCode | xml %]</PostalCode>
 [% END -%]
 </StructuredAddress>
-<PhysicalAddressType>Postal Address</PhysicalAddressType>
+<PhysicalAddressType>[% element.PhysicalAddress.Type | xml %]</PhysicalAddressType>
 </PhysicalAddress>
 [% ELSIF element.ElectronicAddress -%]
 <ElectronicAddress>