@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();
    }
  }
 /* (non-Javadoc)
  * @see org.bonitasoft.studio.configuration.AbstractConnectorConfigurationSynchronizer#updateJarDependencies(org.bonitasoft.studio.model.configuration.FragmentContainer, org.bonitasoft.studio.connector.model.implementation.ConnectorImplementation, org.eclipse.emf.edit.domain.EditingDomain, org.eclipse.emf.common.command.CompoundCommand)
  */
 @Override
 protected void updateJarDependencies(
     FragmentContainer connectorContainer,
     ConnectorImplementation implementation,
     EditingDomain editingDomain,
     CompoundCommand cc,
     boolean forceDriver) {
   super.updateJarDependencies(connectorContainer, implementation, editingDomain, cc, forceDriver);
   store =
       (DatabaseConnectorPropertiesRepositoryStore)
           RepositoryManager.getInstance()
               .getRepositoryStore(DatabaseConnectorPropertiesRepositoryStore.class);
   DatabaseConnectorPropertiesFileStore fileStore =
       (DatabaseConnectorPropertiesFileStore)
           store.getChild(
               implementation.getDefinitionId()
                   + "."
                   + DatabaseConnectorPropertiesRepositoryStore.CONF_EXT);
   if (fileStore != null) {
     String defaultDriver = fileStore.getDefault();
     List<String> jars = fileStore.getJarList();
     boolean autoAddDriver = fileStore.getAutoAddDriver() || forceDriver;
     Configuration conf = (Configuration) connectorContainer.eContainer().eContainer();
     FragmentContainer otherDependencies = null;
     for (FragmentContainer c : conf.getProcessDependencies()) {
       if (FragmentTypes.OTHER.equals(c.getId())) {
         otherDependencies = c;
       }
     }
     for (String jar : jars) {
       boolean exists = false;
       for (Fragment dep : otherDependencies.getFragments()) {
         if (dep.getValue().equals(jar)) {
           exists = true;
           break;
         }
       }
       if (!exists) {
         Fragment depFragment = ConfigurationFactory.eINSTANCE.createFragment();
         if (jar.equals(defaultDriver) && autoAddDriver) {
           depFragment.setExported(true);
         } else {
           depFragment.setExported(false);
         }
         depFragment.setKey(jar);
         depFragment.setValue(jar);
         depFragment.setType(FragmentTypes.JAR);
         cc.append(
             AddCommand.create(
                 editingDomain,
                 otherDependencies,
                 ConfigurationPackage.Literals.FRAGMENT_CONTAINER__FRAGMENTS,
                 depFragment));
       }
     }
   }
 }
Ejemplo n.º 3
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;
 }
 @Override
 protected FragmentContainer getContainer(Configuration configuration) {
   for (FragmentContainer container : configuration.getProcessDependencies()) {
     if (container.getId().equals(FragmentTypes.GROOVY_SCRIPT)) {
       return container;
     }
   }
   return null;
 }
  public byte[] toByteArray(final Configuration configuration) throws ActorMappingExportException {
    if (containsActorMapping(configuration)) {
      final StringBuffer result = new StringBuffer("");
      for (final ActorMapping mapping : configuration.getActorMappings().getActorMapping()) {
        if (!checkActorMappingGroup(mapping)) {
          result.append("- " + mapping.getName() + "\n");
        }
      }
      if (result.length() > 0) {
        throw new ActorMappingExportException(
            Messages.errorActorMappingGroup + " : \n" + result.toString());
      }

      final File tmpFile = new File(getTempFolder(), EcoreUtil.generateUUID() + ".xml");
      final org.eclipse.emf.common.util.URI uri =
          org.eclipse.emf.common.util.URI.createFileURI(tmpFile.getAbsolutePath());
      final Resource resource = new ActorMappingResourceFactoryImpl().createResource(uri);
      final DocumentRoot root = ActorMappingFactory.eINSTANCE.createDocumentRoot();
      final ActorMappingsType mapping = EcoreUtil.copy(configuration.getActorMappings());
      cleanMapping(mapping);
      root.setActorMappings(mapping);
      resource.getContents().add(root);
      final Map<String, String> options = new HashMap<String, String>();
      options.put(XMLResource.OPTION_ENCODING, "UTF-8");
      options.put(XMLResource.OPTION_XML_VERSION, "1.0");
      ByteArrayOutputStream byteArrayOutputStream = null;
      try {
        byteArrayOutputStream = new ByteArrayOutputStream();
        resource.save(options);
        new XMLProcessor().save(byteArrayOutputStream, resource, options);
        resource.delete(Collections.EMPTY_MAP);
        return byteArrayOutputStream.toByteArray();
      } catch (final IOException e) {
        throw new ActorMappingExportException("Failed to save actor mapping", e);
      } finally {
        try {
          byteArrayOutputStream.close();
        } catch (final IOException e) {

        }
      }
    }
    return null;
  }
 @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);
         }
       }
     }
   }
 }
Ejemplo n.º 7
0
 public Configuration getConfiguration(final AbstractProcess process, String configurationId) {
   Configuration configuration = null;
   final ProcessConfigurationRepositoryStore processConfStore =
       RepositoryManager.getInstance()
           .getRepositoryStore(ProcessConfigurationRepositoryStore.class);
   if (configurationId == null) {
     configurationId =
         ConfigurationPlugin.getDefault()
             .getPreferenceStore()
             .getString(ConfigurationPreferenceConstants.DEFAULT_CONFIGURATION);
   }
   if (configurationId.equals(ConfigurationPreferenceConstants.LOCAL_CONFIGURAITON)) {
     final String id = ModelHelper.getEObjectID(process);
     IRepositoryFileStore file = processConfStore.getChild(id + ".conf");
     if (file == null) {
       file = processConfStore.createRepositoryFileStore(id + ".conf");
       configuration = ConfigurationFactory.eINSTANCE.createConfiguration();
       configuration.setName(configurationId);
       configuration.setVersion(ModelVersion.CURRENT_VERSION);
       file.save(configuration);
     }
     try {
       configuration = (Configuration) file.getContent();
     } catch (final ReadFileStoreException e) {
       BonitaStudioLog.error("Failed to read process configuration", e);
     }
   } else {
     for (final Configuration conf : process.getConfigurations()) {
       if (configurationId.equals(conf.getName())) {
         configuration = conf;
       }
     }
   }
   if (configuration == null) {
     configuration = ConfigurationFactory.eINSTANCE.createConfiguration();
     configuration.setName(configurationId);
     configuration.setVersion(ModelVersion.CURRENT_VERSION);
   }
   // Synchronize configuration with definition
   new ConfigurationSynchronizer(process, configuration).synchronize();
   return configuration;
 }
 private void addNewKPIConnectorDefinition(
     Configuration configuration,
     AbstractProcess process,
     CompoundCommand cc,
     EditingDomain editingDomain) {
   List<DatabaseKPIBinding> kpiBindings =
       ModelHelper.getAllItemsOfType(process, KpiPackage.Literals.DATABASE_KPI_BINDING);
   if (!kpiBindings.isEmpty()) {
     String defId = DB_CONNECTOR_FOR_KPI_ID;
     String defVersion = DB_CONNECTOR_VERSION;
     boolean exists = false;
     for (DefinitionMapping association : configuration.getDefinitionMappings()) {
       if (FragmentTypes.CONNECTOR.equals(association.getType())
           && association.getDefinitionId().equals(defId)
           && association.getDefinitionVersion().equals(defVersion)) {
         exists = true;
         updateAssociation(configuration, association, cc, editingDomain);
         break;
       }
     }
     if (!exists) {
       DefinitionMapping newAssociation = ConfigurationFactory.eINSTANCE.createDefinitionMapping();
       newAssociation.setDefinitionId(defId);
       newAssociation.setDefinitionVersion(defVersion);
       newAssociation.setType(getFragmentContainerId());
       editingDomain
           .getCommandStack()
           .execute(
               AddCommand.create(
                   editingDomain,
                   configuration,
                   ConfigurationPackage.Literals.CONFIGURATION__DEFINITION_MAPPINGS,
                   newAssociation));
       updateAssociation(configuration, newAssociation, cc, editingDomain);
     }
   }
 }
 protected boolean containsActorMapping(final Configuration configuration) {
   return configuration.getActorMappings() != null
       && configuration.getActorMappings().getActorMapping() != null
       && !configuration.getActorMappings().getActorMapping().isEmpty();
 }