Search in sources :

Example 1 with DataTransferNodeDescriptor

use of org.jkiss.dbeaver.tools.transfer.registry.DataTransferNodeDescriptor in project dbeaver by serge-rider.

the class DataImportHandler method getProcessorByFile.

private DataTransferProcessorDescriptor getProcessorByFile(IFile file) {
    String extension = file.getFileExtension();
    if (CommonUtils.isEmpty(extension)) {
        return null;
    }
    extension = extension.toLowerCase(Locale.ENGLISH);
    DataTransferNodeDescriptor producerDesc = DataTransferRegistry.getInstance().getNodeById(StreamTransferProducer.NODE_ID);
    if (producerDesc != null) {
        for (DataTransferProcessorDescriptor processor : producerDesc.getProcessors()) {
            DBPPropertyDescriptor extList = processor.getProperty("extension");
            if (extList == null) {
                continue;
            }
            String[] defExtensions = CommonUtils.split(CommonUtils.toString(extList.getDefaultValue()), ",");
            if (ArrayUtils.contains(defExtensions, extension)) {
                return processor;
            }
        }
    }
    return null;
}
Also used : DataTransferNodeDescriptor(org.jkiss.dbeaver.tools.transfer.registry.DataTransferNodeDescriptor) DataTransferProcessorDescriptor(org.jkiss.dbeaver.tools.transfer.registry.DataTransferProcessorDescriptor) DBPPropertyDescriptor(org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor)

Example 2 with DataTransferNodeDescriptor

use of org.jkiss.dbeaver.tools.transfer.registry.DataTransferNodeDescriptor in project dbeaver by serge-rider.

the class DataTransferPagePipes method loadConsumers.

private void loadConsumers() {
    DataTransferSettings settings = getWizard().getSettings();
    Collection<DBSObject> objects = settings.getSourceObjects();
    List<TransferTarget> transferTargets = new ArrayList<>();
    for (DataTransferNodeDescriptor consumer : DataTransferRegistry.getInstance().getAvailableConsumers(objects)) {
        Collection<DataTransferProcessorDescriptor> processors = consumer.getAvailableProcessors(objects);
        if (CommonUtils.isEmpty(processors)) {
            transferTargets.add(new TransferTarget(consumer, null));
        } else {
            for (DataTransferProcessorDescriptor processor : processors) {
                transferTargets.add(new TransferTarget(consumer, processor));
            }
        }
    }
    nodesTable.setInput(transferTargets);
}
Also used : DataTransferSettings(org.jkiss.dbeaver.tools.transfer.DataTransferSettings) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) ArrayList(java.util.ArrayList) DataTransferNodeDescriptor(org.jkiss.dbeaver.tools.transfer.registry.DataTransferNodeDescriptor) DataTransferProcessorDescriptor(org.jkiss.dbeaver.tools.transfer.registry.DataTransferProcessorDescriptor)

Example 3 with DataTransferNodeDescriptor

use of org.jkiss.dbeaver.tools.transfer.registry.DataTransferNodeDescriptor in project dbeaver by serge-rider.

the class DataTransferSettings method loadSettings.

public void loadSettings(DBRProgressMonitor monitor, Map<String, Object> config) {
    this.setMaxJobCount(CommonUtils.toInt(config.get("maxJobCount"), DataTransferSettings.DEFAULT_THREADS_NUM));
    this.setShowFinalMessage(CommonUtils.getBoolean(config.get("showFinalMessage"), this.isShowFinalMessage()));
    DataTransferNodeDescriptor savedConsumer = null, savedProducer = null, processorNode = null;
    {
        // Restore consumer/producer from saved configuration
        // Do this only if consumer/producer weren't set explicitly
        {
            String consumerId = CommonUtils.toString(config.get("consumer"));
            if (!CommonUtils.isEmpty(consumerId)) {
                DataTransferNodeDescriptor consumerNode = DataTransferRegistry.getInstance().getNodeById(consumerId);
                // Check that this consumer is allowed
                if (!CommonUtils.isEmpty(initObjects)) {
                    if (!DataTransferRegistry.getInstance().getAvailableConsumers(initObjects).contains(consumerNode)) {
                        consumerNode = null;
                    }
                }
                if (consumerNode != null) {
                    if (this.consumer == null) {
                        savedConsumer = consumerNode;
                        this.setConsumer(consumerNode);
                    } else {
                        savedConsumer = this.consumer;
                    }
                    if (consumerNode.hasProcessors()) {
                        processorNode = consumerNode;
                    }
                }
            }
        }
        {
            String producerId = CommonUtils.toString(config.get("producer"));
            if (!CommonUtils.isEmpty(producerId)) {
                DataTransferNodeDescriptor producerNode = DataTransferRegistry.getInstance().getNodeById(producerId);
                // Check that this producer is allowed
                if (!CommonUtils.isEmpty(initObjects)) {
                    if (!DataTransferRegistry.getInstance().getAvailableProducers(initObjects).contains(producerNode)) {
                        producerNode = null;
                    }
                }
                if (producerNode != null) {
                    if (this.producer == null) {
                        savedProducer = producerNode;
                        this.setProducer(producerNode);
                    } else {
                        savedProducer = this.producer;
                    }
                    if (producerNode.hasProcessors()) {
                        processorNode = producerNode;
                    }
                }
            }
        }
    }
    DataTransferProcessorDescriptor savedProcessor = null;
    if (processorNode != null) {
        String processorId = CommonUtils.toString(config.get("processor"));
        if (!CommonUtils.isEmpty(processorId)) {
            savedProcessor = processorNode.getProcessor(processorId);
            if (savedProcessor == null) {
                state.addError(new DBException("Processor '" + processorId + "' not found in '" + processorNode.getName() + "'"));
            }
        }
    }
    if (this.consumerOptional && savedConsumer != null) {
        this.selectConsumer(savedConsumer, savedProcessor, false);
    }
    if (this.producerOptional && savedProducer != null) {
        this.selectProducer(savedProducer, savedProcessor, false);
    }
    if (processorNode == producer) {
        producerProcessor = true;
    } else if (processorNode == consumer) {
        producerProcessor = false;
    }
    // Load processor properties
    Map<String, Object> processorsSection = JSONUtils.getObject(config, "processors");
    {
        for (Map.Entry<String, Object> procIter : processorsSection.entrySet()) {
            Map<String, Object> procSection = (Map<String, Object>) procIter.getValue();
            String processorId = procIter.getKey();
            String nodeId = CommonUtils.toString(procSection.get("@node"));
            if (CommonUtils.isEmpty(nodeId)) {
                // Legacy code support
                int divPos = processorId.indexOf(':');
                if (divPos != -1) {
                    nodeId = processorId.substring(0, divPos);
                    processorId = processorId.substring(divPos + 1);
                }
            }
            String propNamesId = CommonUtils.toString(procSection.get("@propNames"));
            DataTransferNodeDescriptor node = DataTransferRegistry.getInstance().getNodeById(nodeId);
            if (node != null) {
                Map<String, Object> props = new HashMap<>();
                DataTransferProcessorDescriptor nodeProcessor = node.getProcessor(processorId);
                if (nodeProcessor != null) {
                    for (String prop : CommonUtils.splitString(propNamesId, ',')) {
                        props.put(prop, procSection.get(prop));
                    }
                    processorPropsHistory.put(nodeProcessor, props);
                }
            }
        }
    }
    // Load nodes' settings (key is impl class simple name, value is descriptor)
    Map<String, DataTransferNodeDescriptor> nodeNames = new LinkedHashMap<>();
    if (producer != null) {
        nodeNames.put(producer.getNodeClass().getSimpleName(), producer);
    }
    if (consumer != null) {
        nodeNames.put(consumer.getNodeClass().getSimpleName(), consumer);
    }
    MonitorRunnableContext runnableContext = new MonitorRunnableContext(monitor);
    for (Map.Entry<String, DataTransferNodeDescriptor> node : nodeNames.entrySet()) {
        Map<String, Object> nodeSection = JSONUtils.getObject(config, node.getKey());
        IDataTransferSettings nodeSettings = this.getNodeSettings(node.getValue());
        if (nodeSettings != null) {
            nodeSettings.loadSettings(runnableContext, this, nodeSection);
        }
    }
    // Initialize pipes with loaded settings
    for (int i = 0; i < dataPipes.size(); i++) {
        DataTransferPipe pipe = dataPipes.get(i);
        if (pipe.getProducer() != null && pipe.getConsumer() != null) {
            try {
                pipe.initPipe(this, i, dataPipes.size());
            } catch (Exception e) {
                state.addError(e);
            }
        }
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) MonitorRunnableContext(org.jkiss.dbeaver.model.runtime.MonitorRunnableContext) DataTransferProcessorDescriptor(org.jkiss.dbeaver.tools.transfer.registry.DataTransferProcessorDescriptor) DBCException(org.jkiss.dbeaver.model.exec.DBCException) DBException(org.jkiss.dbeaver.DBException) DataTransferNodeDescriptor(org.jkiss.dbeaver.tools.transfer.registry.DataTransferNodeDescriptor) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBPObject(org.jkiss.dbeaver.model.DBPObject)

Example 4 with DataTransferNodeDescriptor

use of org.jkiss.dbeaver.tools.transfer.registry.DataTransferNodeDescriptor in project dbeaver by serge-rider.

the class DataTransferSettings method initializePipes.

private void initializePipes(@Nullable Collection<IDataTransferProducer> producers, @Nullable Collection<IDataTransferConsumer> consumers, boolean isExport) {
    this.initProducers = producers == null ? null : producers.toArray(new IDataTransferProducer[0]);
    this.initConsumers = consumers == null ? null : consumers.toArray(new IDataTransferConsumer[0]);
    this.dataPipes = new ArrayList<>();
    this.initObjects.clear();
    this.consumerOptional = false;
    this.producerOptional = false;
    DataTransferRegistry registry = DataTransferRegistry.getInstance();
    if (!ArrayUtils.isEmpty(initProducers) && !ArrayUtils.isEmpty(initConsumers)) {
        // Processor belongs to non-database nodes anyway
        if (initProducers.length != initConsumers.length) {
            throw new IllegalArgumentException("Producers number must match consumers number");
        }
        // Make pipes
        for (int i = 0; i < initProducers.length; i++) {
            if (initProducers[i].getDatabaseObject() != null)
                initObjects.add(initProducers[i].getDatabaseObject());
            dataPipes.add(new DataTransferPipe(initProducers[i], initConsumers[i]));
        }
        // initProducers[0] instanceof IDataTransferNodePrimary;
        consumerOptional = isExport;
        // initConsumers[0] instanceof IDataTransferNodePrimary;
        producerOptional = !isExport;
        if (producerOptional && consumerOptional) {
            // Both producer and consumer set are primary
            // This may happen when task was saved for db-> settings
            // Leave only optional consumer then
            producerOptional = false;
        }
    } else if (!ArrayUtils.isEmpty(initProducers)) {
        // Make pipes
        for (IDataTransferProducer source : initProducers) {
            if (source.getDatabaseObject() != null)
                initObjects.add(source.getDatabaseObject());
            dataPipes.add(new DataTransferPipe(source, null));
        }
        // Set default producer
        Class<? extends IDataTransferProducer> producerType = dataPipes.get(0).getProducer().getClass();
        DataTransferNodeDescriptor producerDesc = registry.getNodeByType(producerType);
        if (producerDesc != null) {
            selectProducer(producerDesc);
            consumerOptional = true;
        } else {
            DBWorkbench.getPlatformUI().showError(DTMessages.data_transfer_settings_title_find_producer, DTMessages.data_transfer_settings_message_find_data_producer);
        }
    } else if (!ArrayUtils.isEmpty(initConsumers)) {
        // Make pipes
        for (IDataTransferConsumer target : initConsumers) {
            if (target.getDatabaseObject() != null)
                initObjects.add(target.getDatabaseObject());
            dataPipes.add(new DataTransferPipe(null, target));
        }
        // Set default consumer
        Class<? extends IDataTransferConsumer> consumerType = dataPipes.get(0).getConsumer().getClass();
        DataTransferNodeDescriptor consumerDesc = registry.getNodeByType(consumerType);
        if (consumerDesc != null) {
            selectConsumer(consumerDesc, null, false);
            consumerOptional = false;
        } else {
            DBWorkbench.getPlatformUI().showError(DTMessages.data_transfer_settings_title_find_consumer, DTMessages.data_transfer_settings_message_find_data_consumer);
        }
        producerOptional = true;
    } else {
        consumerOptional = true;
        producerOptional = true;
    }
    if (!ArrayUtils.isEmpty(initConsumers)) {
        for (IDataTransferConsumer target : initConsumers) {
            DataTransferNodeDescriptor node = registry.getNodeByType(target.getClass());
            if (node != null) {
                this.consumer = node;
            }
        }
    }
}
Also used : DataTransferRegistry(org.jkiss.dbeaver.tools.transfer.registry.DataTransferRegistry) DataTransferNodeDescriptor(org.jkiss.dbeaver.tools.transfer.registry.DataTransferNodeDescriptor)

Example 5 with DataTransferNodeDescriptor

use of org.jkiss.dbeaver.tools.transfer.registry.DataTransferNodeDescriptor in project dbeaver by serge-rider.

the class DataTransferWizard method loadSettings.

void loadSettings() {
    // Load node settings
    Collection<DBSObject> objectTypes = settings.getSourceObjects();
    List<DataTransferNodeDescriptor> nodes = new ArrayList<>();
    DataTransferRegistry registry = DataTransferRegistry.getInstance();
    if (ArrayUtils.isEmpty(settings.getInitProducers())) {
        nodes.addAll(registry.getAvailableProducers(objectTypes));
    } else {
        for (IDataTransferProducer source : settings.getInitProducers()) {
            DataTransferNodeDescriptor node = registry.getNodeByType(source.getClass());
            if (node != null && !nodes.contains(node)) {
                nodes.add(node);
            }
        }
    }
    if (ArrayUtils.isEmpty(settings.getInitConsumers())) {
        nodes.addAll(registry.getAvailableConsumers(objectTypes));
    } else {
        for (IDataTransferConsumer target : settings.getInitConsumers()) {
            DataTransferNodeDescriptor node = registry.getNodeByType(target.getClass());
            if (node != null && !nodes.contains(node)) {
                nodes.add(node);
            }
        }
    }
    boolean settingsChanged = nodeSettings.size() != nodes.size();
    if (!settingsChanged) {
        List<NodePageSettings> nsList = new ArrayList<>(nodeSettings.values());
        for (int i = 0; i < nodeSettings.size(); i++) {
            if (nsList.get(i).sourceNode != nodes.get(i)) {
                settingsChanged = true;
                break;
            }
        }
    }
    if (settingsChanged) {
        nodeSettings.clear();
        for (DataTransferNodeDescriptor node : nodes) {
            addNodeSettings(node);
        }
    }
    updateWizardTitle();
}
Also used : DataTransferRegistry(org.jkiss.dbeaver.tools.transfer.registry.DataTransferRegistry) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DataTransferNodeDescriptor(org.jkiss.dbeaver.tools.transfer.registry.DataTransferNodeDescriptor)

Aggregations

DataTransferNodeDescriptor (org.jkiss.dbeaver.tools.transfer.registry.DataTransferNodeDescriptor)22 DataTransferProcessorDescriptor (org.jkiss.dbeaver.tools.transfer.registry.DataTransferProcessorDescriptor)16 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)8 ArrayList (java.util.ArrayList)4 CommandContributionItem (org.eclipse.ui.menus.CommandContributionItem)4 CommandContributionItemParameter (org.eclipse.ui.menus.CommandContributionItemParameter)4 DBException (org.jkiss.dbeaver.DBException)4 DataTransferSettings (org.jkiss.dbeaver.tools.transfer.DataTransferSettings)4 DataTransferRegistry (org.jkiss.dbeaver.tools.transfer.registry.DataTransferRegistry)4 Collection (java.util.Collection)2 IWorkbenchPartSite (org.eclipse.ui.IWorkbenchPartSite)2 NotNull (org.jkiss.code.NotNull)2 DBPObject (org.jkiss.dbeaver.model.DBPObject)2 DBCException (org.jkiss.dbeaver.model.exec.DBCException)2 DBPPropertyDescriptor (org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor)2 MonitorRunnableContext (org.jkiss.dbeaver.model.runtime.MonitorRunnableContext)2