| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
2
|
|
|
2
|
|
14
|
use strict; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
63
|
|
|
2
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
66
|
|
|
3
|
|
|
|
|
|
|
|
|
4
|
2
|
|
|
2
|
|
11
|
use utf8; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
12
|
|
|
5
|
2
|
|
|
2
|
|
41
|
no utf8; |
|
|
2
|
|
|
|
|
36
|
|
|
|
2
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
package Smartcat::App::DocumentApi; |
|
8
|
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
88
|
use Smartcat::Client::DocumentApi; |
|
|
2
|
|
|
|
|
6
|
|
|
|
2
|
|
|
|
|
62
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
19
|
use Smartcat::Client::Object::BilingualFileImportSetingsModel; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
20
|
|
|
12
|
2
|
|
|
2
|
|
124
|
use Smartcat::Client::Object::UploadDocumentPropertiesModel; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
41
|
|
|
13
|
2
|
|
|
2
|
|
101
|
use Smartcat::App::Utils; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
197
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
2
|
|
|
2
|
|
13
|
use Carp; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
166
|
|
|
16
|
|
|
|
|
|
|
$Carp::Internal{ ('Smartcat::Client::DocumentApi') }++; |
|
17
|
|
|
|
|
|
|
$Carp::Internal{ (__PACKAGE__) }++; |
|
18
|
|
|
|
|
|
|
|
|
19
|
2
|
|
|
2
|
|
20
|
use Log::Any qw($log); |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
29
|
|
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub new { |
|
22
|
1
|
|
|
1
|
0
|
6
|
my ( $class, $api, $rundata ) = @_; |
|
23
|
|
|
|
|
|
|
|
|
24
|
1
|
|
|
|
|
14
|
my $self = bless( |
|
25
|
|
|
|
|
|
|
{ |
|
26
|
|
|
|
|
|
|
api => Smartcat::Client::DocumentApi->new($api), |
|
27
|
|
|
|
|
|
|
rundata => $rundata |
|
28
|
|
|
|
|
|
|
}, |
|
29
|
|
|
|
|
|
|
$class |
|
30
|
|
|
|
|
|
|
); |
|
31
|
|
|
|
|
|
|
|
|
32
|
1
|
|
|
|
|
445
|
return $self; |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub rename_document { |
|
36
|
0
|
|
|
0
|
0
|
|
my ( $self, $document_id, $document_name ) = @_; |
|
37
|
0
|
0
|
0
|
|
|
|
return unless $document_id && $document_name; |
|
38
|
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
$log->info("Renaming document '$document_id' to '$document_name'..."); |
|
40
|
0
|
|
|
|
|
|
my $utf8_name = $document_name; |
|
41
|
0
|
|
|
|
|
|
utf8::encode($utf8_name); |
|
42
|
0
|
|
|
|
|
|
my %args = ( |
|
43
|
|
|
|
|
|
|
document_id => $document_id, |
|
44
|
|
|
|
|
|
|
name => $utf8_name, |
|
45
|
|
|
|
|
|
|
); |
|
46
|
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
eval { $self->{api}->document_rename(%args) }; |
|
|
0
|
|
|
|
|
|
|
|
48
|
0
|
0
|
|
|
|
|
die $log->error( |
|
49
|
|
|
|
|
|
|
sprintf( |
|
50
|
|
|
|
|
|
|
"Failed to rename document '%s' to '%s'.\nError:\n%s", |
|
51
|
|
|
|
|
|
|
$document_id, $document_name, format_error_message($@) |
|
52
|
|
|
|
|
|
|
) |
|
53
|
|
|
|
|
|
|
) if $@; |
|
54
|
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
return; |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub update_document { |
|
59
|
0
|
|
|
0
|
0
|
|
my ( $self, $path, $document_id ) = @_; |
|
60
|
0
|
0
|
0
|
|
|
|
return unless $path && $document_id; |
|
61
|
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
my $settings = |
|
63
|
|
|
|
|
|
|
Smartcat::Client::Object::BilingualFileImportSetingsModel->new( |
|
64
|
|
|
|
|
|
|
confirmMode => "atLastStage" ); |
|
65
|
0
|
|
|
|
|
|
my $doc_props = |
|
66
|
|
|
|
|
|
|
Smartcat::Client::Object::UploadDocumentPropertiesModel->new( |
|
67
|
|
|
|
|
|
|
bilingualFileImportSetings => $settings ); |
|
68
|
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
$log->info("Updating document '$document_id' with '$path'..."); |
|
70
|
0
|
|
|
|
|
|
my $utf8_path = $path; |
|
71
|
0
|
|
|
|
|
|
utf8::encode($utf8_path); |
|
72
|
0
|
|
|
|
|
|
my %args = ( |
|
73
|
|
|
|
|
|
|
document_id => $document_id, |
|
74
|
|
|
|
|
|
|
update_document_model => $doc_props, |
|
75
|
|
|
|
|
|
|
file => $utf8_path |
|
76
|
|
|
|
|
|
|
); |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
$args{disassemble_algorithm_name} = |
|
79
|
|
|
|
|
|
|
$self->{rundata}->{disassemble_algorithm_name} |
|
80
|
0
|
0
|
|
|
|
|
if defined $self->{rundata}->{disassemble_algorithm_name}; |
|
81
|
|
|
|
|
|
|
$args{preset_disassemble_algorithm} = |
|
82
|
|
|
|
|
|
|
$self->{rundata}->{preset_disassemble_algorithm} |
|
83
|
0
|
0
|
|
|
|
|
if defined $self->{rundata}->{preset_disassemble_algorithm}; |
|
84
|
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
my $document = eval { $self->{api}->document_update(%args) }; |
|
|
0
|
|
|
|
|
|
|
|
86
|
0
|
0
|
|
|
|
|
die $log->error( |
|
87
|
|
|
|
|
|
|
sprintf( |
|
88
|
|
|
|
|
|
|
"Failed to update document '%s' with '%s'.\nError:\n%s", |
|
89
|
|
|
|
|
|
|
$document_id, $path, format_error_message($@) |
|
90
|
|
|
|
|
|
|
) |
|
91
|
|
|
|
|
|
|
) unless $document; |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub get_document { |
|
95
|
0
|
|
|
0
|
0
|
|
my ( $self, $document_id ) = @_; |
|
96
|
0
|
0
|
|
|
|
|
return unless $document_id; |
|
97
|
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
$log->info("Getting document '$document_id'..."); |
|
99
|
0
|
|
|
|
|
|
my %args = ( document_id => $document_id, ); |
|
100
|
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
my $document = eval { $self->{api}->document_get(%args); }; |
|
|
0
|
|
|
|
|
|
|
|
102
|
0
|
0
|
|
|
|
|
die $log->error( |
|
103
|
|
|
|
|
|
|
sprintf( |
|
104
|
|
|
|
|
|
|
"Failed to get document '%s'.\nError:\n%s", |
|
105
|
|
|
|
|
|
|
$document_id, format_error_message($@) |
|
106
|
|
|
|
|
|
|
) |
|
107
|
|
|
|
|
|
|
) unless $document; |
|
108
|
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
return $document; |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub delete_documents { |
|
113
|
0
|
|
|
0
|
0
|
|
my ( $self, $document_ids ) = @_; |
|
114
|
0
|
0
|
|
|
|
|
return unless $document_ids; |
|
115
|
|
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
$log->info( 'Deleting documents: ' . join( ', ', @$document_ids ) . '...' ); |
|
117
|
0
|
|
|
|
|
|
my %args = ( document_ids => $document_ids, ); |
|
118
|
|
|
|
|
|
|
|
|
119
|
0
|
|
|
|
|
|
eval { $self->{api}->document_delete(%args); }; |
|
|
0
|
|
|
|
|
|
|
|
120
|
0
|
0
|
|
|
|
|
die $log->error( |
|
121
|
|
|
|
|
|
|
sprintf( |
|
122
|
|
|
|
|
|
|
"Failed to delete documents: %s.\nError:\n%s", |
|
123
|
|
|
|
|
|
|
join( ', ', @$document_ids ), |
|
124
|
|
|
|
|
|
|
format_error_message($@) |
|
125
|
|
|
|
|
|
|
) |
|
126
|
|
|
|
|
|
|
) if $@; |
|
127
|
|
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
return; |
|
129
|
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
1; |