line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
2
|
|
|
2
|
|
15
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
85
|
|
2
|
2
|
|
|
2
|
|
27
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
61
|
|
3
|
|
|
|
|
|
|
|
4
|
2
|
|
|
2
|
|
12
|
use utf8; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
12
|
|
5
|
2
|
|
|
2
|
|
39
|
no utf8; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
7
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
package Smartcat::App::ProjectApi; |
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
90
|
use Smartcat::Client::ProjectApi; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
70
|
|
10
|
2
|
|
|
2
|
|
11
|
use Smartcat::Client::Object::CreateDocumentPropertyModel; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
15
|
|
11
|
2
|
|
|
2
|
|
1145
|
use Smartcat::Client::Object::ProjectChangesModel; |
|
2
|
|
|
|
|
4668
|
|
|
2
|
|
|
|
|
14
|
|
12
|
2
|
|
|
2
|
|
1004
|
use Smartcat::App::Utils; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
182
|
|
13
|
|
|
|
|
|
|
|
14
|
2
|
|
|
2
|
|
14
|
use Carp; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
140
|
|
15
|
|
|
|
|
|
|
$Carp::Internal{ ('Smartcat::Client::ProjectApi') }++; |
16
|
|
|
|
|
|
|
$Carp::Internal{ (__PACKAGE__) }++; |
17
|
|
|
|
|
|
|
|
18
|
2
|
|
|
2
|
|
11
|
use Log::Any qw($log); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
16
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub new { |
21
|
3
|
|
|
3
|
0
|
12
|
my ( $class, $api, $rundata ) = @_; |
22
|
|
|
|
|
|
|
|
23
|
3
|
|
|
|
|
36
|
my $self = bless( |
24
|
|
|
|
|
|
|
{ |
25
|
|
|
|
|
|
|
api => Smartcat::Client::ProjectApi->new($api), |
26
|
|
|
|
|
|
|
rundata => $rundata |
27
|
|
|
|
|
|
|
}, |
28
|
|
|
|
|
|
|
$class |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
3
|
|
|
|
|
4633
|
return $self; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub get_project { |
35
|
2
|
|
|
2
|
0
|
7
|
my $self = shift @_; |
36
|
|
|
|
|
|
|
|
37
|
2
|
|
|
|
|
22
|
$log->info("Getting project '$self->{rundata}->{project_id}'..."); |
38
|
2
|
|
|
|
|
2330
|
my $project = eval { |
39
|
|
|
|
|
|
|
$self->{api} |
40
|
2
|
|
|
|
|
18
|
->project_get( project_id => $self->{rundata}->{project_id} ); |
41
|
|
|
|
|
|
|
}; |
42
|
|
|
|
|
|
|
carp $log->error( |
43
|
|
|
|
|
|
|
sprintf( |
44
|
|
|
|
|
|
|
"Failed to get project '%s'.\nError:\n%s", |
45
|
|
|
|
|
|
|
$self->{rundata}->{project_id}, |
46
|
2
|
50
|
|
|
|
60377
|
format_error_message($@) |
47
|
|
|
|
|
|
|
) |
48
|
|
|
|
|
|
|
) unless $project; |
49
|
|
|
|
|
|
|
|
50
|
2
|
|
|
|
|
18
|
return $project; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub update_project_external_tag { |
54
|
0
|
|
|
0
|
0
|
|
my ($self, $project, $external_tag) = @_; |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
my %args = ( |
57
|
|
|
|
|
|
|
name => $project->name, |
58
|
|
|
|
|
|
|
description => $project->description, |
59
|
|
|
|
|
|
|
deadline => $project->deadline, |
60
|
|
|
|
|
|
|
clientId => $project->client_id, |
61
|
|
|
|
|
|
|
domainId => $project->domain_id, |
62
|
|
|
|
|
|
|
vendorAccountId => $project->vendor_account_id |
63
|
|
|
|
|
|
|
); |
64
|
|
|
|
|
|
|
|
65
|
0
|
0
|
|
|
|
|
$args{externalTag} = $external_tag if defined $external_tag; |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
my $model = |
68
|
|
|
|
|
|
|
Smartcat::Client::Object::ProjectChangesModel->new(%args); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
%args = ( |
71
|
|
|
|
|
|
|
project_id => $self->{rundata}->{project_id}, |
72
|
0
|
|
|
|
|
|
model => $model); |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
$log->info("Updating project '$self->{rundata}->{project_id}' with '$external_tag' external tag..."); |
75
|
0
|
|
|
|
|
|
eval { |
76
|
0
|
|
|
|
|
|
$self->{api}->project_update_project( %args ); |
77
|
|
|
|
|
|
|
}; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
carp $log->error( |
80
|
|
|
|
|
|
|
sprintf( |
81
|
|
|
|
|
|
|
"Failed to update project '%s' with external_tag '%s'.\nError:\n%s", |
82
|
|
|
|
|
|
|
$self->{rundata}->{project_id}, |
83
|
0
|
0
|
|
|
|
|
$external_tag, |
84
|
|
|
|
|
|
|
format_error_message($@) |
85
|
|
|
|
|
|
|
) |
86
|
|
|
|
|
|
|
) if $@; |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
return; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub get_all_projects { |
92
|
0
|
|
|
0
|
0
|
|
my $self = shift @_; |
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
$log->info("Getting all projects..."); |
95
|
0
|
|
|
|
|
|
my $projects = eval { $self->{api}->project_get_all; }; |
|
0
|
|
|
|
|
|
|
96
|
0
|
0
|
|
|
|
|
die $log->error( |
97
|
|
|
|
|
|
|
sprintf( "Failed to get all projects.\nError:\n%s", |
98
|
|
|
|
|
|
|
format_error_message($@) ) |
99
|
|
|
|
|
|
|
) unless $projects; |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
return $projects; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub upload_file { |
105
|
0
|
|
|
0
|
0
|
|
my ( $self, $path, $filename, $external_id, $target_languages ) = @_; |
106
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
my %args; |
108
|
0
|
0
|
0
|
|
|
|
$args{targetLanguages} = $target_languages |
109
|
|
|
|
|
|
|
if defined $target_languages && @$target_languages > 0; |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
|
my $document = |
112
|
|
|
|
|
|
|
Smartcat::Client::Object::CreateDocumentPropertyModel->new(%args); |
113
|
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
$log->info("Uploading file '$path'..."); |
115
|
0
|
|
|
|
|
|
my $utf8_path = $path; |
116
|
0
|
|
|
|
|
|
my $utf8_filename = $filename; |
117
|
0
|
|
|
|
|
|
utf8::encode($utf8_path); |
118
|
0
|
|
|
|
|
|
utf8::encode($utf8_filename); |
119
|
|
|
|
|
|
|
%args = ( |
120
|
|
|
|
|
|
|
project_id => $self->{rundata}->{project_id}, |
121
|
0
|
|
|
|
|
|
document_model => $document, |
122
|
|
|
|
|
|
|
file => { |
123
|
|
|
|
|
|
|
path => $utf8_path, |
124
|
|
|
|
|
|
|
filename => $utf8_filename |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
); |
127
|
0
|
0
|
|
|
|
|
$args{external_id} = $external_id |
128
|
|
|
|
|
|
|
if defined $external_id; |
129
|
|
|
|
|
|
|
$args{disassemble_algorithm_name} = |
130
|
|
|
|
|
|
|
$self->{rundata}->{disassemble_algorithm_name} |
131
|
0
|
0
|
|
|
|
|
if defined $self->{rundata}->{disassemble_algorithm_name}; |
132
|
|
|
|
|
|
|
$args{preset_disassemble_algorithm} = |
133
|
|
|
|
|
|
|
$self->{rundata}->{preset_disassemble_algorithm} |
134
|
0
|
0
|
|
|
|
|
if defined $self->{rundata}->{preset_disassemble_algorithm}; |
135
|
|
|
|
|
|
|
|
136
|
0
|
|
|
|
|
|
my $documents = eval { $self->{api}->project_add_document(%args) }; |
|
0
|
|
|
|
|
|
|
137
|
0
|
0
|
|
|
|
|
unless ($documents) { |
138
|
0
|
|
|
|
|
|
carp $log->error( |
139
|
|
|
|
|
|
|
sprintf( |
140
|
|
|
|
|
|
|
"Failed to upload file '%s'.\nError:\n%s", |
141
|
|
|
|
|
|
|
$path, format_error_message($@) |
142
|
|
|
|
|
|
|
) |
143
|
|
|
|
|
|
|
); |
144
|
0
|
|
|
|
|
|
exit -1; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
0
|
|
|
|
|
|
return $documents; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
1; |