<field name="label" reporter:datatype="text" reporter:label="Label" oils_obj:required="true"/>
<field name="institution" reporter:datatype="text" reporter:label="SIP Institution" oils_obj:required="true"/>
<field name="settings" reporter:datatype="link" reporter:label="Settings" oils_persist:virtual="true"/>
+ <field name="filters" reporter:datatype="link" reporter:label="Filters" oils_persist:virtual="true"/>
</fields>
<links>
<link field="settings" reltype="has_many" key="setting_group" map="" class="sipset"/>
+ <link field="filters" reltype="has_many" key="setting_group" map="" class="sipfilter"/>
</links>
<permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
<actions>
</actions>
</permacrud>
</class>
+ <class id="sipfilter" controller="open-ils.cstore open-ils.pcrud"
+ oils_obj:fieldmapper="sip::filter"
+ oils_persist:tablename="sip.filter"
+ reporter:label="SIP Filter">
+ <fields oils_persist:primary="id" oils_persist:sequence="sip.filter_id_seq">
+ <field name="id" reporter:datatype="id" reporter:label="ID" reporter:selector="name"/>
+ <field name="enabled" reporter:datatype="bool" reporter:label="Enabled"/>
+ <field name="setting_group" reporter:datatype="link" reporter:label="Settings Group" oils_obj:required="true" config_field="true"/>
+ <field name="identifier" reporter:datatype="text" reporter:label="Field Identifier" oils_obj:required="true"/>
+ <field name="strip" reporter:datatype="bool" reporter:label="Strip Field" />
+ <field name="replace_with" reporter:datatype="text" reporter:label="Replacement Field Value" />
+ </fields>
+ <links>
+ <link field="setting_group" reltype="has_a" key="id" map="" class="sipsetg"/>
+ </links>
+ <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
+ <actions>
+ <create permission="SIP_ADMIN" global_required="true"/>
+ <retrieve permission="SIP_ADMIN" global_required="true"/>
+ <update permission="SIP_ADMIN" global_required="true"/>
+ <delete permission="SIP_ADMIN" global_required="true"/>
+ </actions>
+ </permacrud>
+ </class>
<!-- ********************************************************************************************************************* -->
</IDL>
$config->{settings} =
{map {$_->name => $json->decode($_->value)} @{$group->settings}};
- $logger->info("SIP settings " . $json->encode($config->{settings}));
+ $logger->info("SIP2: settings = " . $json->encode($config->{settings}));
return $self->{config} = $config;
}
+sub filters {
+ my $self = shift;
+ return $self->{filters} if $self->{filters};
+
+ my $group = $self->editor->retrieve_sip_setting_group([
+ $self->sip_account->setting_group,
+ {flesh => 1, flesh_fields => {sipsetg => ['filters']}}
+ ]);
+
+ $logger->info("SIP2: found " . scalar(@{ $group->filters }) . " filters");
+ return $self->{filters} = $group->filters;
+}
+
# Retrieve an existing SIP session via SIP session token
sub find {
my ($class, $seskey) = @_;
use OpenSRF::System;
use OpenSRF::Utils::Logger q/$logger/;
use OpenILS::Application::AppUtils;
+use OpenILS::Application::SIP2::Common;
+use OpenILS::Application::SIP2::Session;
my $U = 'OpenILS::Application::AppUtils';
my $json = JSON::XS->new;
# This key is required even if the client has not yet authenticated.
return Apache2::Const::FORBIDDEN unless $seskey;
+ # so we can grab config and filter data
+ my $session = OpenILS::Application::SIPSession->find($seskey);
+ my $session_config = $session ? $session->config : undef;
+ my $session_filters = $session ? $session->filters : undef;
+
if ($msg_json) {
eval { $message = $json->decode($msg_json) };
if ($message) {
$r->content_type('application/json');
# response = $VAR1 = {'fields' => [{'AO' => 'example'},{'BX' => 'YYYNYNYYNYYNNNYN'}],'fixed_fields' => ['Y','Y','Y','Y','N','N','999','999','20220706 154418','2.00'],'code' => '98'};
- # filters v1 = $VAR1 = { 'field' => { 'identifier' => 'AE', 'replace_with' => 'John Doe' } };
- # filters v1 = $VAR1 = { 'field' => { 'identifier' => 'AE', 'remove' => 'true' } };
- # filters v1 = $VAR1 = { 'field' => [ { 'identifier' => 'AE', 'replace_with' => 'John Doe' }, { 'replace_with' => 'Jane Doe', 'identifier' => 'AE' } ] };
- my $filters = { 'field' => [ { 'identifier' => 'AE', 'replace_with' => 'John Doe' }, { 'replace_with' => 'Jane Doe', 'identifier' => 'AE' } ] };
+ #my $filters = { 'field' => [ { 'identifier' => 'AE', 'replace_with' => 'John Doe' }, { 'replace_with' => 'Jane Doe', 'identifier' => 'AE' } ] };
sub find_field_config {
+ my $filters = shift;
my $field_id = shift;
- my @relavent_field_configs = grep { $_->{identifier} eq $field_id } @{ $filters->{'field'} };
+ my @relavent_field_configs = grep { $_->identifier eq $field_id && $_->enabled eq 't' } @{ $filters };
# since we can't do anything complicated yet, let's just return the first match
return @relavent_field_configs ? $relavent_field_configs[0] : undef;
}
- if (defined $filters && defined $response->{fields} && ref $response->{fields} eq 'ARRAY') {
+ if (defined $session_filters && defined $response->{fields} && ref $response->{fields} eq 'ARRAY') {
$response->{fields} = [
grep {
my $keep = 1;
my @fids = keys(%{$_});
my $fid = $fids[0];
- my $field_config = find_field_config( $fid );
- if ($field_config && defined $field_config->{remove}) {
- if (($field_config->{remove} =~ /true|y|yes/i)) { # test truthiness
- $keep = 0; # strip the entire field
- }
+ my $field_config = find_field_config( $session_filters, $fid );
+ if ($field_config && $field_config->strip eq 't') {
+ $keep = 0; # strip the entire field
}
$keep; # or not
}
map {
my @fids = keys(%{$_});
my $fid = $fids[0];
- my $field_config = find_field_config( $fid );
- $field_config && defined $field_config->{replace_with}
- ? { $fid => $field_config->{replace_with} }
+ my $field_config = find_field_config( $session_filters, $fid );
+ $field_config && defined $field_config->replace_with
+ ? { $fid => $field_config->replace_with }
: $_;
}
@{ $response->{fields} }
message TEXT NOT NULL
);
+CREATE TABLE sip.filter (
+ id SERIAL PRIMARY KEY,
+ enabled BOOLEAN NOT NULL DEFAULT FALSE,
+ setting_group INTEGER NOT NULL REFERENCES sip.setting_group (id)
+ ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
+ identifier TEXT NOT NULL,
+ strip BOOLEAN NOT NULL DEFAULT FALSE,
+ replace_with TEXT
+);
+
COMMIT;
--- /dev/null
+
+BEGIN;
+
+-- SELECT evergreen.upgrade_deps_block_check('TODO', :eg_version);
+
+CREATE TABLE sip.filter (
+ id SERIAL PRIMARY KEY,
+ enabled BOOLEAN NOT NULL DEFAULT FALSE,
+ setting_group INTEGER NOT NULL REFERENCES sip.setting_group (id)
+ ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
+ identifier TEXT NOT NULL,
+ strip BOOLEAN NOT NULL DEFAULT FALSE,
+ replace_with TEXT
+);
+
+COMMIT;
+
+