Initial commit for AAI-UI(sparky-backend)
[aai/sparky-be.git] / src / test / resources / es_test_scripts / prepareGeoEntityBulkImport.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 my $filename = $ARGV[0];
7 my $outputfile= $ARGV[1];
8
9 open my $fh_input, '<', $filename or die "Cannot open $filename: $!";
10 open my $fh_output, '>', $outputfile or die "Cannot open $outputfile: $!";
11
12 while ( my $line = <$fh_input> ) {
13     chomp ($line);
14
15     if ( $line =~ /(.*)(\".*\")(.*)/ ) {
16
17        # we have seen examples of the status field containing quoted comma-delimited
18        # strings which is messing up parsing of the record data which is supposed to be
19        # comma-separated at the field level.  This little block converts sections of
20        # this type of data into a single-quoted-string with a semi-colon delimiter instead.
21
22        my $beforeBadStr = $1;
23        my $badStr       = $2;
24        my $afterBadStr  = $3;
25
26        $badStr =~ s/,/;/g;
27        $badStr =~ s/"/'/g;
28
29        $line = $beforeBadStr . $badStr . $afterBadStr ;
30
31     }
32
33     my @row = split(",", $line);
34     print $fh_output "{\"index\":{\"_index\":\"topographicalsearchindex-localhost\",\"_type\":\"default\"}\n";
35     print $fh_output "{\"pkey\": \"$row[0]\", \"entityType\": \"$row[1]\", \"location\" : {\"lat\": \"$row[3]\", \"lon\": \"$row[2]\"}, \"selfLink\": \"$row[4]\"}\n";
36
37 }
38
39 close($fh_input);
40 close($fh_output);
41