Bug 9295: Introduce operator equal/ notequal to OAI set mapping instead of hardcoded...
authorMirko Tietgen <mirko@abunchofthings.net>
Fri, 14 Dec 2012 17:01:37 +0000 (18:01 +0100)
committerGalen Charlton <gmc@esilibrary.com>
Thu, 10 Oct 2013 23:03:30 +0000 (23:03 +0000)
In OAI set mappings, the value "is equal to" is hardcoded. This
enhancement changes it to a dropdown menu to choose between "is equal
to" and "not equal to".

To test:

* define a set
* define a mapping for said set with "is equal to"
* run /misc/migration_tools/build_oai_sets.pl -r -v
* confirm that you have correct entries in SQL: select * from
  oai_sets_biblios;
* change mapping to 'not equal to', save
* run /misc/migration_tools/build_oai_sets.pl -r -v
* confirm that you have correct entries in SQL: select * from
  oai_sets_biblios;

Signed-off-by: Julian Maurice <julian.maurice@biblibre.com>
Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Amended patch: Fix bug id in updatedb.pl

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
C4/OAI/Sets.pm
admin/oai_set_mappings.pl
installer/data/mysql/kohastructure.sql
installer/data/mysql/updatedatabase.pl
koha-tmpl/intranet-tmpl/prog/en/modules/admin/oai_set_mappings.tt
koha-tmpl/intranet-tmpl/prog/en/modules/help/admin/oai_set_mappings.tt

index 8c28f7b..5de22ba 100644 (file)
@@ -290,11 +290,12 @@ sub AddOAISet {
 GetOAISetsMappings returns mappings for all OAI Sets.
 
 Mappings define how biblios are categorized in sets.
-A mapping is defined by three properties:
+A mapping is defined by four properties:
 
     {
         marcfield => 'XXX',     # the MARC field to check
         marcsubfield => 'Y',    # the MARC subfield to check
+        operator => 'A',        # the operator 'equal' or 'notequal'; 'equal' if ''
         marcvalue => 'zzzz',    # the value to check
     }
 
@@ -311,6 +312,7 @@ The first hashref keys are the sets IDs, so it looks like this:
             {
                 marcfield => 'XXX',
                 marcsubfield => 'Y',
+                operator => 'A',
                 marcvalue => 'zzzz'
             },
             {
@@ -337,6 +339,7 @@ sub GetOAISetsMappings {
         push @{ $mappings->{$result->{'set_id'}} }, {
             marcfield => $result->{'marcfield'},
             marcsubfield => $result->{'marcsubfield'},
+            operator => $result->{'operator'},
             marcvalue => $result->{'marcvalue'}
         };
     }
@@ -371,6 +374,7 @@ sub GetOAISetMappings {
         push @mappings, {
             marcfield => $result->{'marcfield'},
             marcsubfield => $result->{'marcsubfield'},
+            operator => $result->{'operator'},
             marcvalue => $result->{'marcvalue'}
         };
     }
@@ -384,6 +388,7 @@ sub GetOAISetMappings {
         {
             marcfield => 'XXX',
             marcsubfield => 'Y',
+            operator => 'A',
             marcvalue => 'zzzz'
         },
         ...
@@ -409,12 +414,12 @@ sub ModOAISetMappings {
 
     if(scalar @$mappings > 0) {
         $query = qq{
-            INSERT INTO oai_sets_mappings (set_id, marcfield, marcsubfield, marcvalue)
-            VALUES (?,?,?,?)
+            INSERT INTO oai_sets_mappings (set_id, marcfield, marcsubfield, operator, marcvalue)
+            VALUES (?,?,?,?,?)
         };
         $sth = $dbh->prepare($query);
         foreach (@$mappings) {
-            $sth->execute($set_id, $_->{'marcfield'}, $_->{'marcsubfield'}, $_->{'marcvalue'});
+            $sth->execute($set_id, $_->{'marcfield'}, $_->{'marcsubfield'}, $_->{'operator'}, $_->{'marcvalue'});
         }
     }
 }
@@ -491,12 +496,20 @@ sub CalcOAISetsBiblio {
             next if not $mapping;
             my $field = $mapping->{'marcfield'};
             my $subfield = $mapping->{'marcsubfield'};
+            my $operator = $mapping->{'operator'};
             my $value = $mapping->{'marcvalue'};
-
             my @subfield_values = $record->subfield($field, $subfield);
-            if(0 < grep /^$value$/, @subfield_values) {
-                push @biblio_sets, $set_id;
-                last;
+            if ($operator eq 'notequal') {
+                if(0 == grep /^$value$/, @subfield_values) {
+                    push @biblio_sets, $set_id;
+                    last;
+                }
+            }
+            else {
+                if(0 < grep /^$value$/, @subfield_values) {
+                    push @biblio_sets, $set_id;
+                    last;
+                }
             }
         }
     }
index fb4ee28..18a48bb 100755 (executable)
@@ -55,6 +55,7 @@ my $op = $input->param('op');
 if($op && $op eq "save") {
     my @marcfields = $input->param('marcfield');
     my @marcsubfields = $input->param('marcsubfield');
+    my @operators = $input->param('operator');
     my @marcvalues = $input->param('marcvalue');
 
     my @mappings;
@@ -64,6 +65,7 @@ if($op && $op eq "save") {
             push @mappings, {
                 marcfield    => $marcfields[$i],
                 marcsubfield => $marcsubfields[$i],
+                operator     => $operators[$i],
                 marcvalue    => $marcvalues[$i]
             };
         }
index e2ee43b..82da018 100644 (file)
@@ -1523,6 +1523,7 @@ CREATE TABLE `oai_sets_mappings` (
   `set_id` int(11) NOT NULL,
   `marcfield` char(3) NOT NULL,
   `marcsubfield` char(1) NOT NULL,
+  `operator` varchar(8) NOT NULL default 'equal',
   `marcvalue` varchar(80) NOT NULL,
   CONSTRAINT `oai_sets_mappings_ibfk_1` FOREIGN KEY (`set_id`) REFERENCES `oai_sets` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
index 9871cfd..d5769a7 100755 (executable)
@@ -7169,6 +7169,13 @@ if ( CheckVersion($DBversion) ) {
     SetVersion ($DBversion);
 }
 
+$DBversion = "3.13.00.XXX";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+   $dbh->do("ALTER TABLE oai_sets_mappings ADD COLUMN operator varchar(8) NOT NULL default 'equal' AFTER marcsubfield;");
+   print "Upgrade to $DBversion done (Bug 9295: OAI notequal: add operator column to OAI mappings table)\n";
+   SetVersion ($DBversion);
+}
+
 =head1 FUNCTIONS
 
 =head2 TableExists($table)
index b449191..c4a9b87 100644 (file)
@@ -65,7 +65,7 @@ function hideDialogBox() {
             <tr>
               <th>Field</th>
               <th>Subfield</th>
-              <th>&nbsp;</th>
+              <th>Operator</th>
               <th>Value</th>
               <th>&nbsp;</th>
               <th>&nbsp;</th>
@@ -77,7 +77,15 @@ function hideDialogBox() {
                 <tr>
                   <td><input type="text" name="marcfield" size="3" value="[% mapping.marcfield %]" /></td>
                   <td style="text-align:center"><input type="text" name="marcsubfield" size="1" value="[% mapping.marcsubfield %]" /></td>
-                  <td>is equal to</td>
+                  <td><select name=operator>
+                      [% IF mapping.operator == 'equal' %]
+                        <option selected value="equal">is equal to</option>
+                        <option value="notequal">not equal to</option>
+                      [% ELSE %]
+                        <option value="equal">is equal to</option>
+                        <option selected value="notequal">not equal to</option>
+                      [% END %]
+                      </select></td>
                   <td><input type="text" name="marcvalue" value="[% mapping.marcvalue %]" /></td>
                   <td style="text-align:center">
                     [% IF ( loop.last ) %]
@@ -93,7 +101,10 @@ function hideDialogBox() {
               <tr>
                 <td><input type="text" name="marcfield" size="3" /></td>
                 <td style="text-align:center"><input type="text" name="marcsubfield" size="1" /></td>
-                <td>is equal to</td>
+                <td><select name=operator>
+                    <option value="equal">is equal to</option>
+                    <option value="notequal">not equal to</option>
+                    </select></td>
                 <td><input type="text" name="marcvalue" /></td>
                 <td><input type="button" id="ORbutton" value="OR" /></td>
                 <td><a class="clear-field" href="#">Delete</a></td>
index 0a18139..1566523 100644 (file)
@@ -7,14 +7,14 @@
 <h2>Defining a mapping</h2>
 
 <ol>
-    <li>Fill the fields 'Field', 'Subfield' and 'Value'. For example if you want to include in this set all records that have a 999$9 equal to 'XXX'. Fill 'Field' with 999, 'Subfield' with 9 and 'Value' with XXX.</li>
+    <li>Fill the fields 'Field', 'Subfield', 'Operator' and 'Value'. For example if you want to include in this set all records that have a 999$9 equal to 'XXX'. Fill 'Field' with 999, 'Subfield' with 9, 'Operator' with is equal to and 'Value' with XXX.</li>
     <li>If you want to add another condition, click on 'OR' button and repeat step 1.</li>
     <li>Click on 'Save'</li>
 </ol>
 
-<p>To delete a condition, just leave at least one of 'Field', 'Subfield' or 'Value' empty and click on 'Save'.</p>
+<p>To delete a condition, just leave at least one of 'Field' or 'Subfield' empty and click on 'Save'.</p>
 
-<p>Note: Actually, a condition is true if value in the corresponding subfield is strictly equal to what is defined if 'Value'. A record having 999$9 = 'XXX YYY' will not belong to a set where condition is 999$9 = 'XXX'.</p>
+<p>Note: Actually, a condition is true if value in the corresponding subfield is strictly 'equal' or 'not equal' to what is defined if 'Value'. A record having 999$9 = 'XXX YYY' will not belong to a set where condition is 999$9 = 'XXX'.</p>
 
 <p>And it is case sensitive : a record having 999$9 = 'xxx' will not belong to a set where condition is 999$9 = 'XXX'.</p>