App-Dochazka-REST
view release on metacpan or search on metacpan
lib/App/Dochazka/REST/Fillup.pm view on Meta::CPAN
# *************************************************************************
# Copyright (c) 2014-2017, SUSE LLC
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# 3. Neither the name of SUSE LLC nor the names of its contributors may be
# used to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
# *************************************************************************
package App::Dochazka::REST::Fillup;
use 5.012;
use strict;
use warnings;
use App::CELL qw( $CELL $log $meta $site );
use App::Dochazka::Common::Model;
use App::Dochazka::REST::ConnBank qw( $dbix_conn );
use App::Dochazka::REST::Model::Employee;
use App::Dochazka::REST::Model::Interval qw(
fetch_intervals_by_eid_and_tsrange_inclusive
);
use App::Dochazka::REST::Model::Shared qw(
canonicalize_tsrange
split_tsrange
);
use App::Dochazka::REST::Model::Tempintvl qw(
fetch_tempintvls_by_tiid_and_tsrange
);
use App::Dochazka::REST::Holiday qw(
calculate_hours
canon_date_diff
canon_to_ymd
get_tomorrow
holidays_in_daterange
tsrange_to_dates_and_times
ymd_to_canon
);
use Data::Dumper;
use Date::Calc qw(
Add_Delta_Days
Date_to_Days
Day_of_Week
check_date
);
use JSON qw( decode_json );
use Params::Validate qw( :all );
use Try::Tiny;
BEGIN {
no strict 'refs';
our %attr= (
act_obj => {
type => HASHREF,
isa => 'App::Dochazka::REST::Model::Activity',
optional => 1
},
clobber => { type => BOOLEAN, optional => 1 },
constructor_status => {
type => HASHREF,
isa => 'App::CELL::Status',
optional => 1
},
context => { type => HASHREF, optional => 1 },
date_list => { type => ARRAYREF, optional => 1 },
dry_run => { type => BOOLEAN, optional => 1 },
emp_obj => {
type => HASHREF,
isa => 'App::Dochazka::REST::Model::Employee',
optional => 1
},
intervals => { type => ARRAYREF, optional => 1 },
long_desc => { type => SCALAR, optional => 1 },
remark => { type => SCALAR, optional => 1 },
tiid => { type => SCALAR, optional => 1 },
tsrange => { type => HASHREF, optional => 1 },
tsranges => { type => ARRAYREF, optional => 1 },
);
map {
my $fn = __PACKAGE__ . "::$_";
$log->debug( "BEGIN BLOCK: $_ $fn" );
*{ $fn } =
App::Dochazka::Common::Model::make_accessor( $_, $attr{ $_ } );
} keys %attr;
*{ 'reset' } = sub {
# process arguments
my $self = shift;
my %ARGS = validate( @_, \%attr ) if @_ and defined $_[0];
# Wipe out current TIID
$self->DESTROY;
# Set attributes to run-time values sent in argument list.
# Attributes that are not in the argument list will get set to undef.
map { $self->{$_} = $ARGS{$_}; } keys %attr;
# run the populate function, if any
$self->populate() if $self->can( 'populate' );
( run in 0.664 second using v1.01-cache-2.11-cpan-39bf76dae61 )