2 package CXGN
::List
::Validate
::Plugin
::LabelDesign
;
8 use Scalar
::Util
qw(looks_like_number);
11 return "label_design";
21 my %page_param_check = (
22 "page_format" => \
&check_page_format
,
23 "page_width" => \
&check_is_numeric
,
24 "page_height" => \
&check_is_numeric
,
25 "left_margin" => \
&check_is_numeric
,
26 "top_margin" => \
&check_is_numeric
,
27 "horizontal_gap" => \
&check_is_numeric
,
28 "vertical_gap" => \
&check_is_numeric
,
29 "number_of_columns" => \
&check_is_numeric
,
30 "number_of_rows" => \
&check_is_numeric
,
31 "copies_per_plot" => \
&check_is_numeric
,
32 "sort_order" => \
&check_sort_order
,
33 "label_format" => \
&check_label_format
,
34 "label_width" => \
&check_is_numeric
,
35 "label_height" => \
&check_is_numeric
,
39 "x" => \
&check_is_numeric
,
40 "y" => \
&check_is_numeric
,
41 "height" => \
&check_is_numeric
,
42 "width" => \
&check_is_numeric
,
43 "scale" => \
&check_scale
,
44 "value" => \
&check_field
,
45 "type" => \
&check_type
,
46 "font" => \
&check_font
,
47 "size" => \
&check_is_numeric
,
50 my $JSON = "{". join(",", @
$list) . "}";
53 print STDERR
"Trying now . . .\n";
54 $obj_ref = JSON
::Any
->decode($JSON);
56 push @problems, "\nInvalid JSON in list items\n";
57 push @problems, "$_\n";
58 print STDERR
"Returning with error . . .\n";
61 if ( scalar @problems ) {
62 return { missing
=> \
@problems };
65 my %obj = %{$obj_ref};
67 foreach my $key (keys %obj) {
68 my $value = $obj{$key};
69 if ( $key =~ m/element/ ) {
70 my %elem_hash = %{$value};
71 foreach my $elem_key (keys %elem_hash) {
72 my $elem_value = $elem_hash{$elem_key};
73 print STDERR
"Elem Key is $elem_key and Elem value is $elem_value\n";
74 $element_check{$elem_key}($elem_value) ?
print STDERR
"Check returned: ".$element_check{$elem_key}($elem_value)."\n" : push @problems, $elem_key . ":" . $elem_value;
77 print STDERR
"Key is $key and value is $value\n";
78 $page_param_check{$key}($value) ?
print STDERR
"Check returned: ".$page_param_check{$key}($value) : push @problems, $key . ":" . $value;
82 return { missing
=> \
@problems };
86 sub check_is_numeric
{
88 looks_like_number
($num) ?
return 1 : return 0;
91 sub check_page_format
{
96 "Zebra printer file" => 1,
99 return $valid_formats{$format};
102 sub check_label_format
{
104 my %valid_formats = (
112 return $valid_formats{$format};
115 sub check_sort_order
{
118 "accession_name" => 1,
123 "column_number" => 1,
125 return $valid_orders{$order};
130 my @scale = @
{$scale};
133 print STDERR
"X is $x and Y is $y\n";
134 looks_like_number
($x) ?
1 : return 0;
135 looks_like_number
($y) ?
return 1 : return 0;
142 "accession_name" => 1,
145 "pedigree_string" => 1,
156 $field =~ s/\{(.*?)\}/process_field($1,\%valid_fields,\%return_values)/ge;
157 foreach my $key (keys %return_values) {
158 if (!$return_values{$key}) {
173 return $valid_types{$type};
181 "Courier-Oblique" => 1,
182 "Courier-BoldOblique" => 1,
184 "Helvetica-Bold" => 1,
185 "Helvetica-Oblique" => 1,
186 "Helvetica-BoldOblique" => 1,
190 "Times-BoldItalic" => 1,
192 return $valid_fonts{$font};
197 my $valid_fields = shift;
198 my $return_values = shift;
199 my %valid_fields = %{$valid_fields};
200 my %return_values = %{$return_values};
202 print STDERR
"Field is $field\n";
203 if ($field =~ m/Number:/) {
204 our ($placeholder, $start_num, $increment) = split ':', $field;
205 my $length = length($start_num);
206 #print STDERR "Increment is $increment\nKey Number is $key_number\n";
207 my $custom_num = $start_num + ($increment * 1);
208 my $final_num = sprintf("%0${length}d", $custom_num);
209 $return_values{$field} = looks_like_number
($final_num);
211 $return_values{$field} = $valid_fields{$field};