@Override
    public void run() {
      // Get available servers and launch SelectTranslatorDialog
      // vdbModelEntry should not be null and should be a Physical model only

      if (vdbModelEntry != null) {
        String transName = vdbModelEntry.getTranslator();

        SelectTranslatorDialog dialog =
            new SelectTranslatorDialog(Display.getCurrent().getActiveShell());

        TeiidTranslator initialSelection = null;
        Server defServer = getDefaultServer();
        if (defServer != null && defServer.isConnected()) {
          try {
            initialSelection = defServer.getAdmin().getTranslator(transName);
          } catch (Exception e) {
            UTIL.log(
                IStatus.ERROR,
                e,
                UTIL.getString(
                    "VdbSourceConnectionHandler.Error_could_not_find_translator_for_name",
                    transName)); //$NON-NLS-1$
          }
          dialog.setInitialSelection(initialSelection);
        }

        dialog.open();

        if (dialog.getReturnCode() == Window.OK) {
          Object result = dialog.getFirstResult();
          if (result != null && result instanceof TeiidTranslator) {
            vdbModelEntry.setTranslator(((TeiidTranslator) result).getName());
          }
        }
      }
    }
  /**
   * @param selection
   * @return
   */
  public boolean setSelection(ISelection selection) {
    if (SelectionUtilities.isMultiSelection(selection)) return false;

    Object obj = SelectionUtilities.getSelectedObject(selection);
    // If a VDB is selected and it contains a web service model then
    // enable
    if (!(obj instanceof IFile)) return false;

    if (!isVdb(obj)) return false;

    this.selectedVDB = (IFile) obj;

    boolean result = false;
    try {
      Vdb vdb = new Vdb(this.selectedVDB, new NullProgressMonitor());
      Set<VdbModelEntry> modelEntrySet = vdb.getModelEntries();
      for (VdbModelEntry vdbModelEntry : modelEntrySet) {
        final ModelResource modelResource =
            ModelerCore.getModelWorkspace().findModelResource(vdbModelEntry.getName());
        if (!ModelIdentifier.isVirtualModelType(modelResource)) continue;

        List<RestProcedure> restfulProcedureArray = findRestProcedures(modelResource);
        if (restfulProcedureArray.size() > 0) {
          String modelName =
              FileUtils.getFilenameWithoutExtension(vdbModelEntry.getName().lastSegment());
          restfulProcedureMap.put(modelName, restfulProcedureArray);
          result = true;
        }
      }
    } catch (Exception ex) {
      DqpPlugin.Util.log(ex);
      return false;
    }

    return result;
  }
  @Test
  public void convertDynamicVdbToXmiVdb() throws Exception {
    DynamicVdb dynVdb = VdbTestUtils.mockPortfolioDynamicVdb(modelWorkspaceMock);
    assertNotNull(dynVdb);

    IFile dynVdbSrcFile = dynVdb.getSourceFile();
    IProject parent = dynVdbSrcFile.getProject();
    assertNotNull(parent);

    File destFile = File.createTempFile(dynVdb.getName(), ITeiidVdb.VDB_DOT_EXTENSION);
    MockFileBuilder destination = new MockFileBuilder(destFile);

    XmiVdb xmiVdb = dynVdb.convert(XmiVdb.class, destination.getResourceFile(), new Properties());

    assertEquals(dynVdb.getName(), xmiVdb.getName());
    assertEquals(dynVdb.getDescription(), xmiVdb.getDescription());

    for (Map.Entry<Object, Object> entry : dynVdb.getProperties().entrySet()) {
      System.out.println(
          "VDB Property:  "
              + entry.getValue()
              + " == "
              + xmiVdb.getProperties().getProperty(entry.getKey().toString()));
      assertEquals(entry.getValue(), xmiVdb.getProperties().getProperty(entry.getKey().toString()));
    }

    assertEquals(destination.getResourceFile(), xmiVdb.getSourceFile());
    assertEquals(dynVdb.getVersion(), xmiVdb.getVersion());

    assertEquals(dynVdb.getConnectionType(), xmiVdb.getConnectionType());
    assertEquals(dynVdb.isPreview(), xmiVdb.isPreview());
    assertEquals(dynVdb.getQueryTimeout(), xmiVdb.getQueryTimeout());

    assertEquals(dynVdb.getAllowedLanguages().size(), xmiVdb.getAllowedLanguages().size());
    List<String> dynLanguageValues =
        Arrays.asList(xmiVdb.getAllowedLanguages().getAllowedLanguageValues());
    for (String language : dynVdb.getAllowedLanguages().getAllowedLanguageValues()) {
      assertTrue(dynLanguageValues.contains(language));
    }

    assertEquals(dynVdb.getSecurityDomain(), xmiVdb.getSecurityDomain());
    assertEquals(dynVdb.getGssPattern(), xmiVdb.getGssPattern());
    assertEquals(dynVdb.getPasswordPattern(), xmiVdb.getPasswordPattern());
    assertEquals(dynVdb.getAuthenticationType(), xmiVdb.getAuthenticationType());
    assertEquals(dynVdb.getValidationDateTime(), xmiVdb.getValidationDateTime());
    assertEquals(dynVdb.isAutoGenerateRESTWar(), xmiVdb.isAutoGenerateRESTWar());

    assertEquals(dynVdb.getImports().size(), xmiVdb.getImports().size());
    for (VdbImportVdbEntry entry : dynVdb.getImports()) {
      assertTrue(xmiVdb.getImports().contains(entry));
    }

    assertEquals(dynVdb.getTranslators().size(), xmiVdb.getTranslators().size());
    for (TranslatorOverride translator : dynVdb.getTranslators()) {
      assertTrue(xmiVdb.getTranslators().contains(translator));
    }

    assertEquals(dynVdb.getDataRoles().size(), xmiVdb.getDataRoles().size());
    for (DataRole role : dynVdb.getDataRoles()) {
      assertTrue(xmiVdb.getDataRoles().contains(role));
    }

    assertEquals(dynVdb.getDynamicModels().size(), xmiVdb.getModelEntries().size());
    for (DynamicModel dynModel : dynVdb.getDynamicModels()) {

      VdbModelEntry modelEntry = null;
      Collection<VdbModelEntry> entries = xmiVdb.getModelEntries();
      for (VdbModelEntry entry : entries) {
        if (dynModel.getName().equals(entry.getName())) {
          modelEntry = entry;
          break;
        }
      }
      assertNotNull(modelEntry);

      assertEquals(dynModel.getDescription(), modelEntry.getDescription());

      for (Map.Entry<Object, Object> prop : dynModel.getProperties().entrySet()) {
        assertEquals(
            prop.getValue(), modelEntry.getProperties().getProperty(prop.getKey().toString()));
      }

      VdbSourceInfo sourceInfo = modelEntry.getSourceInfo();

      assertEquals(dynModel.getModelType().toString(), modelEntry.getType());
      assertEquals(dynModel.isMultiSource(), sourceInfo.isMultiSource());
      assertEquals(dynModel.doAddColumn(), sourceInfo.isAddColumn());
      assertEquals(dynModel.getColumnAlias(), sourceInfo.getColumnAlias());

      assertEquals(dynModel.getSources().length, sourceInfo.getSources().size());
      List<VdbSource> entrySources = new ArrayList<VdbSource>(sourceInfo.getSources());
      for (VdbSource source : dynModel.getSources()) {
        assertTrue(entrySources.contains(source));
      }
    }
  }
  /**
   * Used to save a model entry
   *
   * @param entry
   * @throws Exception
   */
  ModelElement(final VdbModelEntry entry) throws Exception {
    super(entry);
    final String lastSeg = entry.getPath().lastSegment();
    final int ndx = lastSeg.lastIndexOf('.');
    name = (ndx < 0 ? lastSeg : lastSeg.substring(0, ndx));
    type = entry.getType();
    visible = entry.isVisible();
    description = entry.getDescription();

    for (VdbSource source : entry.getSourceInfo().getSources()) {
      getSources().add(new SourceElement(source));
    }
    for (final Problem problem : entry.getProblems())
      getProblems().add(new ProblemElement(problem));
    final List<PropertyElement> props = getProperties();
    String modelUuid = entry.getModelUuid();
    if (modelUuid != null) {
      props.add(new PropertyElement(MODEL_UUID, entry.getModelUuid()));
    }
    String modelClass = entry.getModelClass();
    if (modelClass != null) {
      props.add(new PropertyElement(MODEL_CLASS, entry.getModelClass()));
    }
    props.add(new PropertyElement(BUILT_IN, Boolean.toString(entry.isBuiltIn())));
    if (entry.getSourceInfo().isMultiSource()) {
      props.add(new PropertyElement(MULTI_SOURCE, Boolean.toString(true)));
      if (entry.getSourceInfo().isAddColumn()) {
        props.add(new PropertyElement(MULTI_SOURCE_ADD_COLUMN, Boolean.toString(true)));
      }
      String alias = entry.getSourceInfo().getColumnAlias();
      if (alias != null && alias.length() > 0) {
        props.add(new PropertyElement(MULTI_SOURCE_COLUMN_ALIAS, alias));
      }
    }

    for (Object key : entry.getProperties().keySet()) {
      props.add(new PropertyElement((String) key, (String) entry.getProperties().get(key)));
    }
    for (final VdbEntry importedEntry : entry.getImports())
      props.add(new PropertyElement(IMPORTS, importedEntry.getName().toString()));
    for (final String importedVdbName : entry.getImportVdbNames())
      props.add(new PropertyElement(IMPORT_VDB_REFERENCE, importedVdbName));

    if (entry.getSchemaText() != null) {
      getMetadata().add(new MetadataElement(entry.getSchemaText(), entry.getType()));
    }
  }