brapi refactor error response
[sgn.git] / lib / CXGN / ZipFile.pm
blobd89f12b3f0317cccb8c80c7a2c1c3a494e515a96
2 package CXGN::ZipFile;
4 use Moose;
5 use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
6 use SGN::Model::Cvterm;
7 use Data::Dumper;
9 has 'archived_zipfile_path' => (isa => 'Str',
10 is => 'rw',
11 required => 1,
14 has 'extract_directory' => (isa => 'Str',
15 is => 'rw',
18 has 'archived_zip' => (isa => 'Archive::Zip::Archive',
19 is => 'rw',
23 my $archived_zip = Archive::Zip->new();
25 sub BUILD {
26 my $self = shift;
27 unless ( $archived_zip->read( $self->archived_zipfile_path() ) == AZ_OK ) {
28 die "cannot read given zipfile";
30 $self->archived_zip($archived_zip);
34 #Assuming that zipfile is a flat list of files.
35 sub file_names {
36 my $self = shift;
37 my @file_names = $self->archived_zip()->memberNames();
38 my @file_names_stripped;
39 my @file_names_full;
40 foreach (@file_names) {
41 my @zip_names_split = split(/\//, $_);
42 if ($zip_names_split[1]) {
43 if ($zip_names_split[1] ne '.DS_Store' && $zip_names_split[1] ne '.fieldbook' && $zip_names_split[1] ne '.thumbnails') {
44 my @zip_names_split_ext = split(/\./, $zip_names_split[1]);
45 push @file_names_stripped, $zip_names_split_ext[0];
46 push @file_names_full, $zip_names_split[1];
51 return (\@file_names_stripped, \@file_names_full);
54 sub file_members {
55 my $self = shift;
56 my @ret_members;
57 my @file_members = $self->archived_zip()->members();
58 #print STDERR Dumper \@file_members;
59 my %seen_files;
60 foreach (@file_members) {
61 if (exists($seen_files{$_->{'fileName'}}) || $_->{'compressedSize'} == 0 || index($_->{'fileName'}, '.DS_Store') != -1 || index($_->{'fileName'}, '.fieldbook') != -1 || index($_->{'fileName'}, '.thumbnails') != -1) {
62 next;
63 } else {
64 $seen_files{$_->{'fileName'}} = 1;
65 push @ret_members, $_;
68 return \@ret_members;
71 sub extract_files_into_tempdir {
72 my $self = shift;
73 my $temp_dir = shift;