| 1 | package NOLookup::Patent::Entry; | ||
| 2 | |||
| 3 | use warnings; | ||
| 4 | use strict; | ||
| 5 | use base qw(Class::Accessor::Chained); ## provides a new() method | ||
| 6 | use Encode; | ||
| 7 | use POSIX qw(locale_h); | ||
| 8 | |||
| 9 | use Data::Dumper; | ||
| 10 | $Data::Dumper::Indent=1; | ||
| 11 | |||
| 12 | # module methods | ||
| 13 | my @module_methods = ( | ||
| 14 | |||
| 15 | qw / | ||
| 16 | status | ||
| 17 | error | ||
| 18 | warning | ||
| 19 | |||
| 20 | result_count | ||
| 21 | total_result_count | ||
| 22 | |||
| 23 | map_json_entries | ||
| 24 | |||
| 25 | /); | ||
| 26 | |||
| 27 | my @json_data_methods = ( | ||
| 28 | |||
| 29 | # search lookup methods | ||
| 30 | qw / | ||
| 31 | thumbnail_url | ||
| 32 | trademark_image | ||
| 33 | trademark_text | ||
| 34 | status | ||
| 35 | toplevelstatus | ||
| 36 | applicant | ||
| 37 | application_number | ||
| 38 | /, | ||
| 39 | |||
| 40 | # id lookup methods | ||
| 41 | qw / | ||
| 42 | trademark_text | ||
| 43 | status | ||
| 44 | toplevelstatus | ||
| 45 | application_number | ||
| 46 | registration_number | ||
| 47 | registered_date | ||
| 48 | filed_date | ||
| 49 | case_type | ||
| 50 | trademark_category | ||
| 51 | type_of_mark | ||
| 52 | goods_and_services | ||
| 53 | applicant | ||
| 54 | owner | ||
| 55 | agent | ||
| 56 | |||
| 57 | trademark_image | ||
| 58 | last_updated | ||
| 59 | / | ||
| 60 | ); | ||
| 61 | |||
| 62 | # The new method and also the accessor methods | ||
| 63 | __PACKAGE__->mk_accessors( | ||
| 64 | @module_methods, | ||
| 65 | @json_data_methods | ||
| 66 | ); | ||
| 67 | |||
| 68 | sub map_json_entries { | ||
| 69 | my ($self, $json) = @_; | ||
| 70 | |||
| 71 | return unless ($json); | ||
| 72 | |||
| 73 | my @aj; | ||
| 74 | my @ao; | ||
| 75 | |||
| 76 | $self->status(""); | ||
| 77 | |||
| 78 | if ($json->{status} ne 'OK') { | ||
| 79 | $self->error(1); | ||
| 80 | $self->status($json->{status}); | ||
| 81 | |||
| 82 | } elsif ($json->{search_results}) { | ||
| 83 | # multiple search results | ||
| 84 | push @aj, @{$json->{search_results}}; | ||
| 85 | $self->result_count($json->{result_count}); | ||
| 86 | $self->total_result_count($json->{total_result_count}); | ||
| 87 | |||
| 88 | } elsif ($json->{key_info}) { | ||
| 89 | # single application id, return key info only | ||
| 90 | my $res = $json->{key_info}; | ||
| 91 | $res->{trademark_image} = $json->{trademark_image}; | ||
| 92 | $res->{last_updated} = $json->{last_updated}; | ||
| 93 | push @aj, $res; | ||
| 94 | $self->result_count(1); | ||
| 95 | $self->total_result_count(1); | ||
| 96 | } | ||
| 97 | |||
| 98 | #print STDERR "key_info: ", Dumper \@aj; | ||
| 99 | |||
| 100 | # Check entry array for supported keys | ||
| 101 | # set a warning if some are not expected | ||
| 102 | foreach my $ej (@aj) { | ||
| 103 | foreach my $k (keys %$ej) { | ||
| 104 | unless ($self->can($k)) { | ||
| 105 | $self->status($self->status . "JSON data key entry not expected: $k\n"); | ||
| 106 | $self->warning(1); | ||
| 107 | } | ||
| 108 | } | ||
| 109 | my $eo = NOLookup::Patent::Entry->new($ej); | ||
| 110 | push @ao, $eo; | ||
| 111 | } | ||
| 112 | |||
| 113 | # return a ref to the data array | ||
| 114 | return \@ao; | ||
| 115 | } | ||
| 116 | |||
| 117 | =pod | ||
| 118 | |||
| 119 | =encoding ISO-8859-1 | ||
| 120 | |||
| 121 | =head1 NAME | ||
| 122 | |||
| 123 | NOLookup::Patent::Entry - Map a Patentstyret json data structure element | ||
| 124 | to a NOLookup::Patent::Entry data objects. | ||
| 125 | |||
| 126 | =head1 DESCRIPTION | ||
| 127 | |||
| 128 | Map the json data to data objects. | ||
| 129 | |||
| 130 | Return a reference to an array of NOLookup::Patent::Entry objects. | ||
| 131 | |||
| 132 | =head1 METHODS | ||
| 133 | |||
| 134 | =head2 module methods | ||
| 135 | |||
| 136 | The methods provided by this module. | ||
| 137 | |||
| 138 | =head3 error() | ||
| 139 | |||
| 140 | Set if an error has occured. | ||
| 141 | On errors, the lookup terminates. | ||
| 142 | |||
| 143 | =head3 warning() | ||
| 144 | |||
| 145 | Set if a warning has occured. | ||
| 146 | On warnings, the lookup continues. | ||
| 147 | |||
| 148 | =head3 status() | ||
| 149 | |||
| 150 | Further description of an error/warning situation. | ||
| 151 | |||
| 152 | If the returned JSON structure contains an unsupported data element, | ||
| 153 | the lookup will be performed, but a warning may be returned and | ||
| 154 | and with a status saying: | ||
| 155 | |||
| 156 | 'Warning: JSON data key entry not expected: xxxx' | ||
| 157 | |||
| 158 | where 'xxxx' is the unexpected key. If this happens, the module | ||
| 159 | should be updated with a new method to support the element 'xxx'. | ||
| 160 | |||
| 161 | =head3 map_json_entries() | ||
| 162 | |||
| 163 | Map the JSON data structure from Brreg to NOLookup::Patent::Entry | ||
| 164 | data objects. | ||
| 165 | |||
| 166 | Returns a ref. to an array of NOLookup::Patent::Entry data objects. | ||
| 167 | |||
| 168 | =head3 result_count | ||
| 169 | |||
| 170 | The count of data entries in this page. | ||
| 171 | |||
| 172 | =head3 total_result_count | ||
| 173 | |||
| 174 | The total count of data entries for all pages matching the search. | ||
| 175 | |||
| 176 | |||
| 177 | =head2 Accessor methods | ||
| 178 | |||
| 179 | Data elements are available through acessors in the | ||
| 180 | NOLookup::Patent::Entry object. This is the possible JSON data methods, | ||
| 181 | which are the accessor methods that can be used to find the returned | ||
| 182 | data elements. | ||
| 183 | |||
| 184 | The accessor methods are listed in the @json_data_methods array. | ||
| 185 | |||
| 186 | =head1 SUPPORT | ||
| 187 | |||
| 188 | For now, support questions should be sent to: | ||
| 189 | |||
| 190 | E<lt>(nospam)info(at)norid.noE<gt> | ||
| 191 | |||
| 192 | Please also see the SUPPORT file in the distribution. | ||
| 193 | |||
| 194 | =head1 SEE ALSO | ||
| 195 | |||
| 196 | C<NOLookup::Patent::DataLookup> | ||
| 197 | |||
| 198 | =head1 AUTHOR | ||
| 199 | |||
| 200 | Trond Haugen, E<lt>(nospam)info(at)norid.noE<gt> | ||
| 201 | |||
| 202 | =head1 COPYRIGHT | ||
| 203 | |||
| 204 | Copyright (c) 2017 Trond Haugen <(nospam)info(at)norid.no>. | ||
| 205 | All rights reserved. | ||
| 206 | |||
| 207 | This program is free software; you can redistribute it and/or modify | ||
| 208 | it under the terms of the GNU General Public License as published by | ||
| 209 | the Free Software Foundation; either version 2 of the License, or | ||
| 210 | (at your option) any later version. | ||
| 211 | |||
| 212 | =head1 LICENSE | ||
| 213 | |||
| 214 | This library is free software. You can redistribute it and/or modify | ||
| 215 | it under the same terms as Perl itself. | ||
| 216 | |||
| 217 | =cut | ||
| 218 | |||
| 219 | 1; |