use of org.jkiss.dbeaver.tools.transfer.registry.DataTransferProcessorDescriptor in project dbeaver by serge-rider.
the class StreamProducerPageSettings method activatePage.
@Override
public void activatePage() {
// Initialize property editor
DataTransferProcessorDescriptor processor = getProducerProcessor();
DBPPropertyDescriptor[] properties = processor == null ? new DBPPropertyDescriptor[0] : processor.getProperties();
propertySource = new PropertySourceCustom(properties, getWizard().getSettings().getProcessorProperties());
propsEditor.loadProperties(propertySource);
// Init pipes
reloadPipes();
updatePageCompletion();
UIUtils.asyncExec(() -> UIUtils.packColumns(filesTable, true));
}
use of org.jkiss.dbeaver.tools.transfer.registry.DataTransferProcessorDescriptor 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);
}
use of org.jkiss.dbeaver.tools.transfer.registry.DataTransferProcessorDescriptor in project dbeaver by serge-rider.
the class DataTransferSettings method setDataPipes.
public void setDataPipes(List<DataTransferPipe> dataPipes, boolean isExport) {
this.dataPipes = dataPipes;
// Now determine main producer and consumer and processor
DataTransferRegistry registry = DataTransferRegistry.getInstance();
this.consumerOptional = isExport;
this.producerOptional = !isExport;
// Don't update producer and consumer if it's not required (#9687)
if (!nodeUpdateRestricted) {
this.producer = null;
this.consumer = null;
if (!dataPipes.isEmpty()) {
DataTransferPipe pipe = dataPipes.get(0);
this.producer = pipe.getProducer() == null ? null : registry.getNodeByType(pipe.getProducer().getClass());
this.consumer = pipe.getConsumer() == null ? null : registry.getNodeByType(pipe.getConsumer().getClass());
}
}
DataTransferProcessorDescriptor savedProcessor = this.processor;
if (this.consumerOptional && this.consumer != null) {
this.selectConsumer(this.consumer, savedProcessor, false);
}
if (this.producerOptional && this.producer != null) {
this.selectProducer(this.producer, savedProcessor, false);
}
// Collect objects
initObjects.clear();
for (DataTransferPipe pipe : dataPipes) {
DBSObject object = isExport ? pipe.getProducer().getDatabaseObject() : pipe.getConsumer().getDatabaseObject();
if (object != null) {
initObjects.add(object);
}
}
}
use of org.jkiss.dbeaver.tools.transfer.registry.DataTransferProcessorDescriptor 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);
}
}
}
}
use of org.jkiss.dbeaver.tools.transfer.registry.DataTransferProcessorDescriptor in project dbeaver by serge-rider.
the class DataTransferWizard method saveConfiguration.
private Map<String, Object> saveConfiguration(Map<String, Object> config) {
config.put("maxJobCount", settings.getMaxJobCount());
config.put("showFinalMessage", settings.isShowFinalMessage());
// Save nodes' settings
boolean isTask = getCurrentTask() != null;
for (Map.Entry<Class, NodePageSettings> entry : nodeSettings.entrySet()) {
NodePageSettings nodePageSettings = entry.getValue();
if (isTask) {
// Do not save settings for nodes not involved in this task
if (nodePageSettings.sourceNode.getNodeType() == DataTransferNodeDescriptor.NodeType.PRODUCER && settings.getProducer() != null && !settings.getProducer().getId().equals(nodePageSettings.sourceNode.getId())) {
continue;
}
if (nodePageSettings.sourceNode.getNodeType() == DataTransferNodeDescriptor.NodeType.CONSUMER && settings.getConsumer() != null && !settings.getConsumer().getId().equals(nodePageSettings.sourceNode.getId())) {
continue;
}
}
Map<String, Object> nodeSection = new LinkedHashMap<>();
IDataTransferSettings settings = this.settings.getNodeSettings(nodePageSettings.sourceNode);
if (settings != null) {
settings.saveSettings(nodeSection);
}
// Note: do it in the end because of limitation of IDialogSettings wrapper
config.put(entry.getKey().getSimpleName(), nodeSection);
}
if (settings.getProducer() != null) {
config.put("producer", settings.getProducer().getId());
}
if (settings.getConsumer() != null) {
config.put("consumer", settings.getConsumer().getId());
}
if (settings.getProcessor() != null) {
config.put("processor", settings.getProcessor().getId());
}
// Save processors' properties
Map<String, Object> processorsSection = new LinkedHashMap<>();
for (DataTransferProcessorDescriptor procDescriptor : settings.getProcessorPropsHistory().keySet()) {
if (isTask) {
// Do not save settings for nodes not involved in this task
if (settings.getProcessor() == null || !settings.getProcessor().getId().equals(procDescriptor.getId())) {
continue;
}
}
Map<String, Object> procSettings = new LinkedHashMap<>();
Map<String, Object> props = settings.getProcessorPropsHistory().get(procDescriptor);
if (!CommonUtils.isEmpty(props)) {
StringBuilder propNames = new StringBuilder();
for (Map.Entry<String, Object> prop : props.entrySet()) {
propNames.append(prop.getKey()).append(',');
}
procSettings.put("@propNames", propNames.toString());
for (Map.Entry<String, Object> prop : props.entrySet()) {
procSettings.put(CommonUtils.toString(prop.getKey()), CommonUtils.toString(prop.getValue()));
}
}
processorsSection.put(procDescriptor.getFullId(), procSettings);
}
config.put("processors", processorsSection);
return config;
}
Aggregations