Book a Demo

Author Topic: Imported images have different ID  (Read 3110 times)

gfranz

  • EA User
  • **
  • Posts: 37
  • Karma: +0/-0
    • View Profile
Imported images have different ID
« on: July 10, 2013, 05:46:38 pm »
Hello,

I tried to transfer images to another EAP with the export/import reference data feature of EA10. But the images have a different ID in the second EAP, so when I also transfer models to this EAP, diagram objects referencing images will have the default appearance.

I haven't found any "Strip GUID" option in the reference data import dialog or the general options. So I don't know, how sharing of reference data works.

Thanks!

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Imported images have different ID
« Reply #1 on: July 10, 2013, 07:28:45 pm »
I have reported this as bug some years ago. I'm not astonished that it is not yet corrected.

Instead write a script like I did to produce correct behavior.

q.

gfranz

  • EA User
  • **
  • Posts: 37
  • Karma: +0/-0
    • View Profile
Re: Imported images have different ID
« Reply #2 on: July 11, 2013, 07:23:08 pm »
Quote
I have reported this as bug some years ago. I'm not astonished that it is not yet corrected.

Instead write a script like I did to produce correct behavior.

q.

Hello qwerty

Do you reset the IDs of the imported pictures to the original ones? How do you know, which pic is meant? Just by comparing the name? Do you read in the XML content?

thanks for the answer!

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Imported images have different ID
« Reply #3 on: July 12, 2013, 08:23:05 am »
I save and import the ids in my own format. Here's the Perl script:
Code: [Select]
use strict;
no strict 'refs';
use Win32::OLE qw (in);
use XML::Simple;
use MIME::Base64 ();
use DBI;

#use EaSimulator;
#EaSimulator->new ({'PACKAGE'=>"{088A0FC2-E1E4-41d8-9661-900C18E2243D}"});

my %tableData =
  ('t_image' => {PRIMARY => 'ImageID', COLUMNS => ['Type', 'Name', 'ImageID', 'Image']},
   't_propertytypes' => {PRIMARY => 'Property', COLUMNS => ['Property', 'Description', 'Notes']},
   't_statustypes' => {PRIMARY => 'Status', COLUMNS => ['Status', 'Description']});

my $rep = $ENV{'REP'};

my $dbName = $rep->ConnectionString;
my $dbi;
if ($dbName =~ /\.eap$/i) { $dbi = "dbi:ADO:Data Source=$dbName;Provider=Microsoft.Jet.OLEDB.4.0" }
elsif ($dbName =~ /Data Source=([^;]*)/) { $dbi = "dbi:ODBC:$1" }
else { die "can not figure out DB type from $dbName" }
my $dbh = DBI->connect($dbi, "") or die "Can't connect to $dbi";

my $fn = $rep->xmiPath($rep->GetTreeSelectedObject()) . 'RefData.xml';

my $xs = XML::Simple->new(); # convert the XML return string into a hash
my $ref = $xs->XMLin($fn);

for my $key (keys %{$ref->{'DataSet'}}) {
  import ($ref->{'DataSet'}->{$key});
}

return 1;

sub import {
  my $data = shift;
  my $table = $data->{'table'};
  my $primary = $tableData{$table}->{PRIMARY} or return;

  my %xref;
  my $columns = "`" . join ("`, `", @{$tableData{$table}->{COLUMNS}}) . "`";
  my $sth;
  $sth = $dbh->prepare("delete * from $table where 1");
  $sth->execute();

  if (ref ($data->{'DataRow'}) eq "HASH") {
    $data->{'DataRow'} = [$data->{'DataRow'}];
  }
  for (in @{$data->{'DataRow'}}) {
    my $row = $_->{ 'Column'};
    next if $#{$tableData{$table}->{COLUMNS}} < 0;
    my $sql;

    $sql = "INSERT INTO $table (";
    my $values = "";
    my $sep = "";
    for my $col (@{$tableData{$table}->{COLUMNS}}) {
      if ($row->{$col}->{'dt:dt'} eq "bin.base64") {
        $values .= $sep . '?';
      } else {
        next unless $row->{$col}->{'value'};
        $values .= $sep . quote ($row->{$col}->{'value'});
      }
      $sql .= "$sep`$col`";
      $sep = ", ";
    }
    $sql .= ") VALUES ($values)";
    $sth = $dbh->prepare($sql);
    my $param = 0;
    for my $col (@{$tableData{$table}->{COLUMNS}}) {
      if ($row->{$col}->{'dt:dt'} eq "bin.base64") {
        $param++;
        $sth->bind_param($param, MIME::Base64::decode($row->{$col}->{'content'}), DBI::SQL_BLOB);
      }
    }
    $sth->execute();
  }
}

sub quote {
  $_ = shift();
  s/'/''/gm;
  s/‰/&auml;/gm;
  s/ˆ/&ouml;/gm;
  s/¸/&uuml;/gm;
  s/ƒ/&Auml;/gm;
  s/÷/&Ouml;/gm;
  s/‹/&Uuml;/gm;
  s/[ch64258]/&szlig;/gm;
  return "'$_'";
}

q.