push @EXPORT_OK, ( 'new_editor', 'new_rstore_editor' );
%EXPORT_TAGS = ( funcs => [ qw/ new_editor new_rstore_editor / ] );
+our $personality = 'open-ils.cstore';
+
+sub personality {
+ my( $self, $app ) = @_;
+ $personality = $app if $app;
+ init() if $app; # rewrite if we changed personalities
+ return $personality;
+}
+
+sub import {
+ my $class = shift;
+ my %args = @_;
+
+ $class->personality( $args{personality} ) if ($args{personality});
+
+ return 1;
+}
+
sub new_editor { return OpenILS::Utils::CStoreEditor->new(@_); }
sub new_rstore_editor {
sub app {
my( $self, $app ) = @_;
$self->{app} = $app if $app;
- $self->{app} = 'open-ils.cstore' unless $self->{app};
+ $self->{app} = $self->personality unless $self->{app};
return $self->{app};
}
sub authtoken {
my( $self, $auth ) = @_;
$self->{authtoken} = $auth if $auth;
+ return 'ANONYMOUS' if ($self->personality eq 'open-ils.pcrud' and !defined($self->{authtoken}));
return $self->{authtoken};
}
if( ($self->{xact} or $always_xact) and
$self->session->state != OpenSRF::AppSession::CONNECTED() ) {
#$logger->error("CStoreEditor lost it's connection!!");
- throw OpenSRF::EX::ERROR ("CStore connection timed out - transaction cannot continue");
+ throw OpenSRF::EX::ERROR ($self->app." connection timed out - transaction cannot continue");
}
}
my @arg = ( ref($arg) eq 'ARRAY' ) ? @$arg : ($arg);
- my $method = $self->app.".direct.$type.$action";
+ my $method = '';
+ if ($self->personality eq 'open-ils.pcrud') {
+ $method = $self->app.".$action.$type";
+ } else {
+ $method = $self->app.".direct.$type.$action";
+ }
if( $action eq 'search' ) {
$method .= '.atomic';
$self->log_activity($method, $type, $action, $arg);
}
- if($$options{checkperm}) {
+ # only check perms this way in non-pcrud mode
+ if($self->personality ne 'open-ils.pcrud' and $$options{checkperm}) {
my $a = ($action eq 'search') ? 'retrieve' : $action;
my $e = $self->_checkperm($type, $a, $$options{permorg});
if($e) {
my $obj;
my $err = '';
+ # In pcrud mode, sub authtoken returns 'ANONYMOUS' if one is not yet set
+ unshift(@$arg, $self->authtoken) if ($self->personality eq 'open-ils.pcrud');
+
try {
$obj = $self->request($method, @arg);
} catch Error with { $err = shift; };
}
if( $action eq 'search' ) {
- $self->log(I, "$type.$action : returned ".scalar(@$obj). " result(s)");
+ $self->log(I, "$method: returned ".scalar(@$obj). " result(s)");
$self->event(_mk_not_found($type, $arg)) unless @$obj;
}
my $map = $Fieldmapper::fieldmap;
for my $object (keys %$map) {
my $obj = __fm2meth($object, '_');
- my $type = __fm2meth($object, '.');
+ my $type;
+ if (__PACKAGE__->personality eq 'open-ils.pcrud') {
+ $type = $object->json_hint;
+ } else {
+ $type = __fm2meth($object, '.');
+ }
foreach my $command (qw/ update retrieve search create delete batch_retrieve retrieve_all /) {
eval "sub ${command}_$obj {return shift()->runmethod('$command', '$type', \@_);}\n";
}
sub json_query {
my( $self, $arg, $options ) = @_;
+
+ if( $self->personality eq 'open-ils.pcrud' ) {
+ $self->event(
+ OpenILS::Event->new(
+ 'JSON_QUERY_NOT_ALLOWED',
+ attempted_query => $arg,
+ debug => "json_query is not allowed when using the open-ils.pcrud personality of CStoreEditor"
+ )
+ );
+ return undef;
+ }
+
$options ||= {};
my @arg = ( ref($arg) eq 'ARRAY' ) ? @$arg : ($arg);
my $method = $self->app.'.json_query.atomic';