Exemplo n.º 1
0
 public Map<String, String> getParameterMapFromConfiguration(final Configuration configuration) {
   final Map<String, String> result = new HashMap<String, String>();
   for (final Parameter p : configuration.getParameters()) {
     if (p.getValue() != null) {
       result.put(p.getName(), p.getValue());
     }
   }
   return result;
 }
  @Before
  public void setUp() throws Exception {
    if (pool == null) {
      final NewDiagramCommandHandler newDiagram = new NewDiagramCommandHandler();
      final DiagramFileStore diagramFileStore = newDiagram.execute(null);
      pool = (AbstractProcess) EcoreUtil.copy(diagramFileStore.getContent()).getElements().get(0);
      final Configuration conf = ConfigurationFactory.eINSTANCE.createConfiguration();

      conf.setName(CONF_NAME);
      pool.getConfigurations().add(conf);

      final Parameter p1 = ParameterFactory.eINSTANCE.createParameter();
      p1.setName("dbUrl");
      p1.setTypeClassname(String.class.getName());
      pool.getParameters().add(p1);

      final Parameter p2 = ParameterFactory.eINSTANCE.createParameter();
      p2.setName("password");
      p2.setTypeClassname(String.class.getName());
      pool.getParameters().add(p2);

      final Parameter p3 = ParameterFactory.eINSTANCE.createParameter();
      p3.setName("port");
      p3.setTypeClassname(Integer.class.getName());
      pool.getParameters().add(p3);

      pool.getFormMapping().setType(FormMappingType.LEGACY);
      for (final Task t : ModelHelper.getAllElementOfTypeIn(pool, Task.class)) {
        t.getFormMapping().setType(FormMappingType.LEGACY);
      }

      new ConfigurationSynchronizer(pool, pool.getConfigurations().get(0)).synchronize();
    }
  }
  @Test
  public void testImportParameters() throws Exception {
    Assert.assertNotNull(pool);
    Assert.assertEquals("Parameter import failed", 3, pool.getParameters().size());

    new ConfigurationSynchronizer(pool, pool.getConfigurations().get(0)).synchronize();
    Assert.assertEquals(
        "Parameter import failed", 3, pool.getConfigurations().get(0).getParameters().size());

    importParamters();

    boolean allValueImported = true;
    for (final Parameter p : pool.getConfigurations().get(0).getParameters()) {
      if (p.getValue() == null) {
        allValueImported = false;
      }
    }
    Assert.assertTrue("Parameter import failed", allValueImported);
  }
 @Override
 public void run() {
   if (filePath == null) {
     final FileDialog fd = new FileDialog(Display.getDefault().getActiveShell(), SWT.OPEN);
     fd.setFilterExtensions(new String[] {"*.properties"});
     filePath = fd.open();
   }
   if (filePath != null) {
     final Properties p = loadProperties(filePath);
     for (final Entry<Object, Object> entry : p.entrySet()) {
       final String name = (String) entry.getKey();
       final String value = (String) entry.getValue();
       for (final Parameter param : configuration.getParameters()) {
         if (param.getName().equals(name)) {
           param.setValue(value);
         }
       }
     }
   }
 }