Search in sources :

Example 16 with IDynamicPlugin

use of org.talend.core.runtime.dynamic.IDynamicPlugin in project tbd-studio-se by Talend.

the class DynamicDistributionManager method getAllUsersDynamicPluginsForProject.

public List<IDynamicPlugin> getAllUsersDynamicPluginsForProject(Project project, IDynamicMonitor monitor) throws Exception {
    IProject eProject = ResourceUtils.getProject(project);
    IFolder usersFolder = ResourceUtils.getFolder(eProject, getUserStoragePath(), false);
    if (usersFolder == null || !usersFolder.exists()) {
        return null;
    }
    List<IDynamicPlugin> dynamicPlugins = new ArrayList<>();
    String absoluteFolderPath = usersFolder.getLocation().toPortableString();
    File folder = new File(absoluteFolderPath);
    List<String> files = getAllFiles(folder);
    if (files != null && 0 < files.size()) {
        String projTechName = project.getTechnicalLabel();
        for (String absolutePath : files) {
            try {
                String jsonContent = DynamicServiceUtil.readFile(new File(absolutePath));
                IDynamicPlugin dynamicPlugin = DynamicFactory.getInstance().createPluginFromJson(jsonContent);
                IDynamicPluginConfiguration pluginConfiguration = dynamicPlugin.getPluginConfiguration();
                pluginConfiguration.setAttribute(DynamicConstants.ATTR_FILE_PATH, absolutePath);
                pluginConfiguration.setAttribute(DynamicConstants.ATTR_IS_BUILTIN, Boolean.FALSE.toString());
                pluginConfiguration.setAttribute(DynamicConstants.ATTR_PROJECT_TECHNICAL_NAME, projTechName);
                dynamicPlugins.add(dynamicPlugin);
            } catch (Exception e) {
                ExceptionHandler.process(e);
            }
        }
    }
    return dynamicPlugins;
}
Also used : IDynamicPlugin(org.talend.core.runtime.dynamic.IDynamicPlugin) ArrayList(java.util.ArrayList) File(java.io.File) IDynamicPluginConfiguration(org.talend.core.runtime.dynamic.IDynamicPluginConfiguration) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder)

Example 17 with IDynamicPlugin

use of org.talend.core.runtime.dynamic.IDynamicPlugin in project tbd-studio-se by Talend.

the class DynamicDistributionManager method unregisterAllUsers.

public void unregisterAllUsers(IDynamicMonitor monitor, boolean cleanCache) throws Exception {
    List<IDynamicPlugin> allUsersDynamicPlugins = getAllUsersDynamicPlugins(monitor);
    if (allUsersDynamicPlugins == null || allUsersDynamicPlugins.isEmpty()) {
        return;
    }
    List<IDynamicDistributionsGroup> dynDistriGroups = getDynamicDistributionsGroups();
    if (dynDistriGroups == null || dynDistriGroups.isEmpty()) {
        throw new Exception("No dynamic distribution group found.");
    }
    for (IDynamicPlugin dynamicPlugin : allUsersDynamicPlugins) {
        boolean registed = false;
        for (IDynamicDistributionsGroup dynDistriGroup : dynDistriGroups) {
            try {
                if (dynDistriGroup.canRegister(dynamicPlugin, monitor)) {
                    dynDistriGroup.unregister(dynamicPlugin, monitor, false);
                    registed = true;
                }
            } catch (Throwable e) {
                ExceptionHandler.process(e);
            }
        }
        if (!registed) {
            ExceptionHandler.process(new Exception("Can't regist dynamic distribution: " + dynamicPlugin.getPluginConfiguration().getTemplateId()));
        }
    }
    if (cleanCache) {
        resetSystemCache();
    }
}
Also used : IDynamicPlugin(org.talend.core.runtime.dynamic.IDynamicPlugin)

Example 18 with IDynamicPlugin

use of org.talend.core.runtime.dynamic.IDynamicPlugin in project tbd-studio-se by Talend.

the class DynamicDistributionManager method registerAllUsers.

public void registerAllUsers(IDynamicMonitor monitor, boolean cleanCache) throws Exception {
    isLoaded = true;
    List<IDynamicPlugin> allUsersDynamicPlugins = getAllUsersDynamicPlugins(monitor);
    if (allUsersDynamicPlugins == null || allUsersDynamicPlugins.isEmpty()) {
        return;
    }
    List<IDynamicDistributionsGroup> dynDistriGroups = getDynamicDistributionsGroups();
    if (dynDistriGroups == null || dynDistriGroups.isEmpty()) {
        throw new Exception("No dynamic distribution group found.");
    }
    for (IDynamicPlugin dynamicPlugin : allUsersDynamicPlugins) {
        boolean registed = false;
        for (IDynamicDistributionsGroup dynDistriGroup : dynDistriGroups) {
            try {
                if (dynDistriGroup.canRegister(dynamicPlugin, monitor)) {
                    dynDistriGroup.register(dynamicPlugin, monitor);
                    registed = true;
                }
            } catch (Throwable e) {
                ExceptionHandler.process(e);
            }
        }
        if (!registed) {
            ExceptionHandler.process(new Exception("Can't regist dynamic distribution: " + dynamicPlugin.getPluginConfiguration().getTemplateId()));
        }
    }
    if (cleanCache) {
        resetSystemCache();
    }
}
Also used : IDynamicPlugin(org.talend.core.runtime.dynamic.IDynamicPlugin)

Example 19 with IDynamicPlugin

use of org.talend.core.runtime.dynamic.IDynamicPlugin in project tbd-studio-se by Talend.

the class DynamicDistributionOptionForm method checkSelectExistingConfig.

private boolean checkSelectExistingConfig() {
    if (!editExistingConfigBtn.getSelection()) {
        return true;
    }
    IStructuredSelection selection = (IStructuredSelection) existingConfigsComboViewer.getSelection();
    if (selection == null) {
        // $NON-NLS-1$
        String errorMessage = Messages.getString("DynamicDistributionOptionForm.importConfigText.check.existingConfig.empty");
        showMessage(errorMessage, WizardPage.ERROR);
        return false;
    }
    Object firstElement = selection.getFirstElement();
    if (firstElement == null) {
        // $NON-NLS-1$
        String errorMessage = Messages.getString("DynamicDistributionOptionForm.importConfigText.check.existingConfig.empty");
        showMessage(errorMessage, WizardPage.ERROR);
        return false;
    }
    IDynamicPlugin dynamicPlugin = (IDynamicPlugin) firstElement;
    existingConfigsComboViewer.getControl().setToolTipText(existingConfigsComboViewer.getCombo().getText());
    getDynamicDistributionSetupData().setDynamicPlugin(dynamicPlugin);
    IDynamicPluginConfiguration pluginConfiguration = dynamicPlugin.getPluginConfiguration();
    boolean isBuiltin = isBuiltinDynamicConfiguration(dynamicPlugin);
    boolean isInCurrentProject = isInCurrentProject(dynamicPlugin);
    getDynamicDistributionSetupData().setReadonly(isBuiltin || !isInCurrentProject || isReadonly());
    if (isBuiltin) {
        String warnMessage = // $NON-NLS-1$
        Messages.getString(// $NON-NLS-1$
        "DynamicDistributionOptionForm.editExisting.builtin", pluginConfiguration.getName());
        showMessage(warnMessage, WizardPage.WARNING);
    }
    if (!isInCurrentProject) {
        String warnMessage = // $NON-NLS-1$
        Messages.getString(// $NON-NLS-1$
        "DynamicDistributionOptionForm.editExisting.notInCurrentProject", pluginConfiguration.getName(), pluginConfiguration.getAttribute(DynamicConstants.ATTR_PROJECT_TECHNICAL_NAME));
        showMessage(warnMessage, WizardPage.WARNING);
    }
    return true;
}
Also used : IDynamicPlugin(org.talend.core.runtime.dynamic.IDynamicPlugin) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IDynamicPluginConfiguration(org.talend.core.runtime.dynamic.IDynamicPluginConfiguration)

Example 20 with IDynamicPlugin

use of org.talend.core.runtime.dynamic.IDynamicPlugin in project tbd-studio-se by Talend.

the class AbstractDynamicDistributionSetupForm method saveDynamicDistribution.

protected void saveDynamicDistribution(IDynamicPlugin dynamicPlugin, IDynamicDistributionsGroup dynDistrGroup, ActionType actionType, IDynamicMonitor dMonitor) throws Exception {
    IDynamicPluginConfiguration pluginConfiguration = dynamicPlugin.getPluginConfiguration();
    dMonitor.beginTask(// $NON-NLS-1$
    Messages.getString("AbstractDynamicDistributionSetupForm.progress.saving", pluginConfiguration.getName()), IDynamicMonitor.UNKNOWN);
    // step 1: clean unused modules
    IDynamicDistributionPreference dynamicDistributionPreference = dynDistrGroup.getDynamicDistributionPreference(ProjectManager.getInstance().getCurrentProject());
    DynamicPluginAdapter pluginAdapter = new DynamicPluginAdapter(dynamicPlugin, dynamicDistributionPreference, null);
    pluginAdapter.cleanUnusedAndRefresh();
    // step 2: save
    final IDynamicPlugin fDynPlugin = pluginAdapter.getPlugin();
    ProxyRepositoryFactory.getInstance().executeRepositoryWorkUnit(new RepositoryWorkUnit<Boolean>(Messages.getString("AbstractDynamicDistributionSetupForm.repositoryWorkUnit.title", // $NON-NLS-1$
    pluginConfiguration.getName())) {

        @Override
        protected void run() throws LoginException, PersistenceException {
            result = false;
            try {
                DynamicDistributionManager.getInstance().saveUsersDynamicPlugin(fDynPlugin, dMonitor);
            } catch (Exception e) {
                throw new PersistenceException(e);
            }
            result = true;
        }
    });
    // step 3: regist
    dMonitor.setTaskName(// $NON-NLS-1$
    Messages.getString("AbstractDynamicDistributionSetupForm.progress.registing", pluginConfiguration.getName()));
    if (ActionType.EditExisting.equals(actionType)) {
        dynDistrGroup.unregister(fDynPlugin, dMonitor, false);
    }
    dynDistrGroup.register(fDynPlugin, dMonitor);
    // step 4: reset system cache
    // $NON-NLS-1$
    dMonitor.setTaskName(Messages.getString("AbstractDynamicDistributionSetupForm.progress.resetCache"));
    DynamicDistributionManager.getInstance().resetSystemCache();
}
Also used : IDynamicDistributionPreference(org.talend.hadoop.distribution.dynamic.pref.IDynamicDistributionPreference) DynamicPluginAdapter(org.talend.hadoop.distribution.dynamic.adapter.DynamicPluginAdapter) IDynamicPlugin(org.talend.core.runtime.dynamic.IDynamicPlugin) PersistenceException(org.talend.commons.exception.PersistenceException) LoginException(org.talend.commons.exception.LoginException) IDynamicPluginConfiguration(org.talend.core.runtime.dynamic.IDynamicPluginConfiguration) LoginException(org.talend.commons.exception.LoginException) PersistenceException(org.talend.commons.exception.PersistenceException)

Aggregations

IDynamicPlugin (org.talend.core.runtime.dynamic.IDynamicPlugin)25 IDynamicPluginConfiguration (org.talend.core.runtime.dynamic.IDynamicPluginConfiguration)16 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 DummyDynamicMonitor (org.talend.designer.maven.aether.DummyDynamicMonitor)6 IDynamicMonitor (org.talend.designer.maven.aether.IDynamicMonitor)6 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)5 LinkedList (java.util.LinkedList)4 Project (org.talend.core.model.general.Project)4 DynamicPluginAdapter (org.talend.hadoop.distribution.dynamic.adapter.DynamicPluginAdapter)4 DynamicDistributionSetupData (org.talend.repository.hadoopcluster.ui.dynamic.DynamicDistributionSetupData)4 File (java.io.File)3 LoginException (org.talend.commons.exception.LoginException)3 PersistenceException (org.talend.commons.exception.PersistenceException)3 IDynamicDistributionsGroup (org.talend.hadoop.distribution.dynamic.IDynamicDistributionsGroup)3 ArrayList (java.util.ArrayList)2 IProject (org.eclipse.core.resources.IProject)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 Bundle (org.osgi.framework.Bundle)2 DynamicPluginComparator (org.talend.hadoop.distribution.dynamic.comparator.DynamicPluginComparator)2 IDynamicDistributionPreference (org.talend.hadoop.distribution.dynamic.pref.IDynamicDistributionPreference)2