Search in sources :

Example 31 with NotePadMeta

use of org.pentaho.di.core.NotePadMeta in project pentaho-kettle by pentaho.

the class TransDelegate method dataNodeToElement.

public void dataNodeToElement(final DataNode rootNode, final RepositoryElementInterface element) throws KettleException {
    TransMeta transMeta = (TransMeta) element;
    Set<String> privateDatabases = null;
    // read the private databases
    DataNode privateDbsNode = rootNode.getNode(NODE_TRANS_PRIVATE_DATABASES);
    // BACKLOG-6635
    if (privateDbsNode != null) {
        privateDatabases = new HashSet<String>();
        if (privateDbsNode.hasProperty(PROP_TRANS_PRIVATE_DATABASE_NAMES)) {
            for (String privateDatabaseName : getString(privateDbsNode, PROP_TRANS_PRIVATE_DATABASE_NAMES).split(TRANS_PRIVATE_DATABASE_DELIMITER)) {
                if (!privateDatabaseName.isEmpty()) {
                    privateDatabases.add(privateDatabaseName);
                }
            }
        } else {
            for (DataNode privateDatabase : privateDbsNode.getNodes()) {
                privateDatabases.add(privateDatabase.getName());
            }
        }
    }
    transMeta.setPrivateDatabases(privateDatabases);
    // read the steps...
    // 
    DataNode stepsNode = rootNode.getNode(NODE_STEPS);
    for (DataNode stepNode : stepsNode.getNodes()) {
        StepMeta stepMeta = new StepMeta(new StringObjectId(stepNode.getId().toString()));
        // for tracing, retain hierarchy
        stepMeta.setParentTransMeta(transMeta);
        // Read the basics
        // 
        stepMeta.setName(getString(stepNode, PROP_NAME));
        if (stepNode.hasProperty(PROP_DESCRIPTION)) {
            stepMeta.setDescription(getString(stepNode, PROP_DESCRIPTION));
        }
        stepMeta.setDistributes(stepNode.getProperty(PROP_STEP_DISTRIBUTE).getBoolean());
        DataProperty rowDistributionProperty = stepNode.getProperty(PROP_STEP_ROW_DISTRIBUTION);
        String rowDistributionCode = rowDistributionProperty == null ? null : rowDistributionProperty.getString();
        RowDistributionInterface rowDistribution = PluginRegistry.getInstance().loadClass(RowDistributionPluginType.class, rowDistributionCode, RowDistributionInterface.class);
        stepMeta.setRowDistribution(rowDistribution);
        stepMeta.setDraw(stepNode.getProperty(PROP_STEP_GUI_DRAW).getBoolean());
        int copies = (int) stepNode.getProperty(PROP_STEP_COPIES).getLong();
        String copiesString = stepNode.getProperty(PROP_STEP_COPIES_STRING) != null ? stepNode.getProperty(PROP_STEP_COPIES_STRING).getString() : StringUtils.EMPTY;
        if (!Utils.isEmpty(copiesString)) {
            stepMeta.setCopiesString(copiesString);
        } else {
            // for backward compatibility
            stepMeta.setCopies(copies);
        }
        int x = (int) stepNode.getProperty(PROP_STEP_GUI_LOCATION_X).getLong();
        int y = (int) stepNode.getProperty(PROP_STEP_GUI_LOCATION_Y).getLong();
        stepMeta.setLocation(x, y);
        // Load the group attributes map
        // 
        AttributesMapUtil.loadAttributesMap(stepNode, stepMeta);
        String stepType = getString(stepNode, PROP_STEP_TYPE);
        // Create a new StepMetaInterface object...
        // 
        PluginRegistry registry = PluginRegistry.getInstance();
        PluginInterface stepPlugin = registry.findPluginWithId(StepPluginType.class, stepType);
        StepMetaInterface stepMetaInterface = null;
        if (stepPlugin != null) {
            stepMetaInterface = (StepMetaInterface) registry.loadClass(stepPlugin);
            // revert to the default in case we loaded an alternate version
            stepType = stepPlugin.getIds()[0];
        } else {
            stepMeta.setStepMetaInterface((StepMetaInterface) new MissingTrans(stepMeta.getName(), stepType));
            transMeta.addMissingTrans((MissingTrans) stepMeta.getStepMetaInterface());
        }
        stepMeta.setStepID(stepType);
        // Read the metadata from the repository too...
        // 
        RepositoryProxy proxy = new RepositoryProxy(stepNode.getNode(NODE_STEP_CUSTOM));
        if (!stepMeta.isMissing()) {
            readRepCompatibleStepMeta(stepMetaInterface, proxy, null, transMeta.getDatabases());
            stepMetaInterface.readRep(proxy, transMeta.getMetaStore(), null, transMeta.getDatabases());
            stepMeta.setStepMetaInterface(stepMetaInterface);
        }
        // Get the partitioning as well...
        StepPartitioningMeta stepPartitioningMeta = new StepPartitioningMeta();
        if (stepNode.hasProperty(PROP_PARTITIONING_SCHEMA)) {
            String partSchemaId = stepNode.getProperty(PROP_PARTITIONING_SCHEMA).getRef().getId().toString();
            String schemaName = repo.loadPartitionSchema(new StringObjectId(partSchemaId), null).getName();
            stepPartitioningMeta.setPartitionSchemaName(schemaName);
            String methodCode = getString(stepNode, PROP_PARTITIONING_METHOD);
            stepPartitioningMeta.setMethod(StepPartitioningMeta.getMethod(methodCode));
            if (stepPartitioningMeta.getPartitioner() != null) {
                proxy = new RepositoryProxy(stepNode.getNode(NODE_PARTITIONER_CUSTOM));
                stepPartitioningMeta.getPartitioner().loadRep(proxy, null);
            }
            stepPartitioningMeta.hasChanged(true);
        }
        stepMeta.setStepPartitioningMeta(stepPartitioningMeta);
        stepMeta.getStepPartitioningMeta().setPartitionSchemaAfterLoading(transMeta.getPartitionSchemas());
        // Get the cluster schema name
        String clusterSchemaName = getString(stepNode, PROP_CLUSTER_SCHEMA);
        stepMeta.setClusterSchemaName(clusterSchemaName);
        if (clusterSchemaName != null && transMeta.getClusterSchemas() != null) {
            // Get the cluster schema from the given name
            for (ClusterSchema clusterSchema : transMeta.getClusterSchemas()) {
                if (clusterSchema.getName().equals(clusterSchemaName)) {
                    stepMeta.setClusterSchema(clusterSchema);
                    break;
                }
            }
        }
        transMeta.addStep(stepMeta);
    }
    for (DataNode stepNode : stepsNode.getNodes()) {
        ObjectId stepObjectId = new StringObjectId(stepNode.getId().toString());
        StepMeta stepMeta = StepMeta.findStep(transMeta.getSteps(), stepObjectId);
        // 
        if (stepNode.hasProperty(PROP_STEP_ERROR_HANDLING_SOURCE_STEP)) {
            StepErrorMeta meta = new StepErrorMeta(transMeta, stepMeta);
            meta.setTargetStep(StepMeta.findStep(transMeta.getSteps(), stepNode.getProperty(PROP_STEP_ERROR_HANDLING_TARGET_STEP).getString()));
            meta.setEnabled(stepNode.getProperty(PROP_STEP_ERROR_HANDLING_IS_ENABLED).getBoolean());
            meta.setNrErrorsValuename(getString(stepNode, PROP_STEP_ERROR_HANDLING_NR_VALUENAME));
            meta.setErrorDescriptionsValuename(getString(stepNode, PROP_STEP_ERROR_HANDLING_DESCRIPTIONS_VALUENAME));
            meta.setErrorFieldsValuename(getString(stepNode, PROP_STEP_ERROR_HANDLING_FIELDS_VALUENAME));
            meta.setErrorCodesValuename(getString(stepNode, PROP_STEP_ERROR_HANDLING_CODES_VALUENAME));
            meta.setMaxErrors(getString(stepNode, PROP_STEP_ERROR_HANDLING_MAX_ERRORS));
            meta.setMaxPercentErrors(getString(stepNode, PROP_STEP_ERROR_HANDLING_MAX_PCT_ERRORS));
            meta.setMinPercentRows(getString(stepNode, PROP_STEP_ERROR_HANDLING_MIN_PCT_ROWS));
            // a bit of a trick, I know.
            meta.getSourceStep().setStepErrorMeta(meta);
        }
    }
    // 
    for (int i = 0; i < transMeta.nrSteps(); i++) {
        StepMeta stepMeta = transMeta.getStep(i);
        StepMetaInterface sii = stepMeta.getStepMetaInterface();
        if (sii != null) {
            sii.searchInfoAndTargetSteps(transMeta.getSteps());
        }
    }
    // Read the notes...
    // 
    DataNode notesNode = rootNode.getNode(NODE_NOTES);
    int nrNotes = (int) notesNode.getProperty(PROP_NR_NOTES).getLong();
    for (DataNode noteNode : notesNode.getNodes()) {
        String xml = getString(noteNode, PROP_XML);
        transMeta.addNote(new NotePadMeta(XMLHandler.getSubNode(XMLHandler.loadXMLString(xml), NotePadMeta.XML_TAG)));
    }
    if (transMeta.nrNotes() != nrNotes) {
        throw new KettleException("The number of notes read [" + transMeta.nrNotes() + "] was not the number we expected [" + nrNotes + "]");
    }
    // Read the hops...
    // 
    DataNode hopsNode = rootNode.getNode(NODE_HOPS);
    int nrHops = (int) hopsNode.getProperty(PROP_NR_HOPS).getLong();
    for (DataNode hopNode : hopsNode.getNodes()) {
        String stepFromName = getString(hopNode, TRANS_HOP_FROM);
        String stepToName = getString(hopNode, TRANS_HOP_TO);
        boolean enabled = true;
        if (hopNode.hasProperty(TRANS_HOP_ENABLED)) {
            enabled = hopNode.getProperty(TRANS_HOP_ENABLED).getBoolean();
        }
        StepMeta stepFrom = StepMeta.findStep(transMeta.getSteps(), stepFromName);
        StepMeta stepTo = StepMeta.findStep(transMeta.getSteps(), stepToName);
        // 
        if (stepFrom != null && stepTo != null) {
            transMeta.addTransHop(new TransHopMeta(stepFrom, stepTo, enabled));
        }
    }
    if (transMeta.nrTransHops() != nrHops) {
        throw new KettleException("The number of hops read [" + transMeta.nrTransHops() + "] was not the number we expected [" + nrHops + "]");
    }
    // Load the details at the end, to make sure we reference the databases correctly, etc.
    // 
    loadTransformationDetails(rootNode, transMeta);
    transMeta.eraseParameters();
    DataNode paramsNode = rootNode.getNode(NODE_PARAMETERS);
    int count = (int) paramsNode.getProperty(PROP_NR_PARAMETERS).getLong();
    for (int idx = 0; idx < count; idx++) {
        DataNode paramNode = paramsNode.getNode(TRANS_PARAM_PREFIX + idx);
        String key = getString(paramNode, PARAM_KEY);
        String def = getString(paramNode, PARAM_DEFAULT);
        String desc = getString(paramNode, PARAM_DESC);
        transMeta.addParameterDefinition(key, def, desc);
    }
    transMeta.activateParameters();
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) StringObjectId(org.pentaho.di.repository.StringObjectId) ObjectId(org.pentaho.di.repository.ObjectId) PluginInterface(org.pentaho.di.core.plugins.PluginInterface) TransMeta(org.pentaho.di.trans.TransMeta) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) StepErrorMeta(org.pentaho.di.trans.step.StepErrorMeta) DataProperty(org.pentaho.platform.api.repository2.unified.data.node.DataProperty) StepPartitioningMeta(org.pentaho.di.trans.step.StepPartitioningMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) StringObjectId(org.pentaho.di.repository.StringObjectId) DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) RowDistributionInterface(org.pentaho.di.trans.step.RowDistributionInterface) MissingTrans(org.pentaho.di.trans.steps.missing.MissingTrans) NotePadMeta(org.pentaho.di.core.NotePadMeta) TransHopMeta(org.pentaho.di.trans.TransHopMeta) ClusterSchema(org.pentaho.di.cluster.ClusterSchema)

Example 32 with NotePadMeta

use of org.pentaho.di.core.NotePadMeta in project pentaho-kettle by pentaho.

the class TransformationHasANoteImportRuleIT method testRule.

public void testRule() throws Exception {
    // Create a transformation to test.
    // 
    TransMeta transMeta = new TransMeta();
    NotePadMeta note = new NotePadMeta("A note documenting the transformation", 50, 50, 200, 50);
    transMeta.addNote(note);
    // Load the plugin to test from the registry.
    // 
    PluginRegistry registry = PluginRegistry.getInstance();
    PluginInterface plugin = registry.findPluginWithId(ImportRulePluginType.class, "TransformationHasANote");
    assertNotNull("The 'transformation has a note' rule could not be found in the plugin registry!", plugin);
    TransformationHasANoteImportRule rule = (TransformationHasANoteImportRule) registry.loadClass(plugin);
    assertNotNull("The 'transformation has a note' class could not be loaded by the plugin registry!", plugin);
    rule.setEnabled(true);
    List<ImportValidationFeedback> feedback = rule.verifyRule(transMeta);
    assertTrue("We didn't get any feedback from the 'transformation has a note' rule", !feedback.isEmpty());
    assertTrue("An approval ruling was expected", feedback.get(0).getResultType() == ImportValidationResultType.APPROVAL);
    transMeta.removeNote(0);
    feedback = rule.verifyRule(transMeta);
    assertTrue("We didn't get any feedback from the 'transformation has a note' rule", !feedback.isEmpty());
    assertTrue("An error ruling was expected", feedback.get(0).getResultType() == ImportValidationResultType.ERROR);
    rule.setEnabled(false);
    feedback = rule.verifyRule(transMeta);
    assertTrue("We didn't expect any feedback from the 'transformation has a note' rule while disabled", feedback.isEmpty());
}
Also used : TransformationHasANoteImportRule(org.pentaho.di.imp.rules.TransformationHasANoteImportRule) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) PluginInterface(org.pentaho.di.core.plugins.PluginInterface) TransMeta(org.pentaho.di.trans.TransMeta) NotePadMeta(org.pentaho.di.core.NotePadMeta)

Example 33 with NotePadMeta

use of org.pentaho.di.core.NotePadMeta in project pentaho-kettle by pentaho.

the class AbstractMetaTest method testNotes.

@Test
public void testNotes() throws Exception {
    assertNull(meta.getNotes());
    // most note methods will NPE at this point, so call clear() to create an empty note list
    meta.clear();
    assertNotNull(meta.getNotes());
    assertTrue(meta.getNotes().isEmpty());
    // Can't get a note from an empty list (i.e. no indices)
    Exception e = null;
    try {
        assertNull(meta.getNote(0));
    } catch (IndexOutOfBoundsException ioobe) {
        e = ioobe;
    }
    assertNotNull(e);
    assertNull(meta.getNote(20, 20));
    NotePadMeta note1 = mock(NotePadMeta.class);
    meta.removeNote(0);
    assertFalse(meta.hasChanged());
    meta.addNote(note1);
    assertTrue(meta.hasChanged());
    NotePadMeta note2 = mock(NotePadMeta.class);
    when(note2.getLocation()).thenReturn(new Point(0, 0));
    when(note2.isSelected()).thenReturn(true);
    meta.addNote(1, note2);
    assertEquals(note2, meta.getNote(0, 0));
    List<NotePadMeta> selectedNotes = meta.getSelectedNotes();
    assertNotNull(selectedNotes);
    assertEquals(1, selectedNotes.size());
    assertEquals(note2, selectedNotes.get(0));
    assertEquals(1, meta.indexOfNote(note2));
    meta.removeNote(2);
    assertEquals(2, meta.nrNotes());
    meta.removeNote(1);
    assertEquals(1, meta.nrNotes());
    assertTrue(meta.haveNotesChanged());
    meta.clearChanged();
    assertFalse(meta.haveNotesChanged());
    meta.addNote(1, note2);
    meta.lowerNote(1);
    assertTrue(meta.haveNotesChanged());
    meta.clearChanged();
    assertFalse(meta.haveNotesChanged());
    meta.raiseNote(0);
    assertTrue(meta.haveNotesChanged());
    meta.clearChanged();
    assertFalse(meta.haveNotesChanged());
    int[] indexes = meta.getNoteIndexes(Arrays.asList(note1, note2));
    assertNotNull(indexes);
    assertEquals(2, indexes.length);
}
Also used : NotePadMeta(org.pentaho.di.core.NotePadMeta) Point(org.pentaho.di.core.gui.Point) KettleException(org.pentaho.di.core.exception.KettleException) KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) Test(org.junit.Test)

Example 34 with NotePadMeta

use of org.pentaho.di.core.NotePadMeta in project pentaho-kettle by pentaho.

the class Spoon method copySelected.

public void copySelected(TransMeta transMeta, List<StepMeta> steps, List<NotePadMeta> notes) {
    if (steps == null || steps.size() == 0) {
        return;
    }
    if (RepositorySecurityUI.verifyOperations(shell, rep, RepositoryOperation.MODIFY_TRANSFORMATION, RepositoryOperation.EXECUTE_TRANSFORMATION)) {
        return;
    }
    StringBuilder xml = new StringBuilder(5000).append(XMLHandler.getXMLHeader());
    try {
        xml.append(XMLHandler.openTag(Spoon.XML_TAG_TRANSFORMATION_STEPS)).append(Const.CR);
        xml.append(XMLHandler.openTag(Spoon.XML_TAG_STEPS)).append(Const.CR);
        for (StepMeta step : steps) {
            xml.append(step.getXML());
        }
        xml.append(XMLHandler.closeTag(Spoon.XML_TAG_STEPS)).append(Const.CR);
        // Also check for the hops in between the selected steps...
        xml.append(XMLHandler.openTag(TransMeta.XML_TAG_ORDER)).append(Const.CR);
        for (StepMeta step1 : steps) {
            for (StepMeta step2 : steps) {
                if (step1 != step2) {
                    TransHopMeta hop = transMeta.findTransHop(step1, step2, true);
                    if (hop != null) {
                        // Ok, we found one...
                        xml.append(hop.getXML()).append(Const.CR);
                    }
                }
            }
        }
        xml.append(XMLHandler.closeTag(TransMeta.XML_TAG_ORDER)).append(Const.CR);
        xml.append(XMLHandler.openTag(TransMeta.XML_TAG_NOTEPADS)).append(Const.CR);
        if (notes != null) {
            for (NotePadMeta note : notes) {
                xml.append(note.getXML());
            }
        }
        xml.append(XMLHandler.closeTag(TransMeta.XML_TAG_NOTEPADS)).append(Const.CR);
        xml.append(XMLHandler.openTag(TransMeta.XML_TAG_STEP_ERROR_HANDLING)).append(Const.CR);
        for (StepMeta step : steps) {
            if (step.getStepErrorMeta() != null) {
                xml.append(step.getStepErrorMeta().getXML()).append(Const.CR);
            }
        }
        xml.append(XMLHandler.closeTag(TransMeta.XML_TAG_STEP_ERROR_HANDLING)).append(Const.CR);
        xml.append(XMLHandler.closeTag(Spoon.XML_TAG_TRANSFORMATION_STEPS)).append(Const.CR);
        toClipboard(xml.toString());
    } catch (Exception ex) {
        new ErrorDialog(getShell(), "Error", "Error encoding to XML", ex);
    }
}
Also used : ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) TransHopMeta(org.pentaho.di.trans.TransHopMeta) NotePadMeta(org.pentaho.di.core.NotePadMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) SWTException(org.eclipse.swt.SWTException) KettleRowException(org.pentaho.di.core.exception.KettleRowException) FileSystemException(org.apache.commons.vfs2.FileSystemException) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleAuthException(org.pentaho.di.core.exception.KettleAuthException) KettleRepositoryLostException(org.pentaho.di.repository.KettleRepositoryLostException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) LifecycleException(org.pentaho.di.core.lifecycle.LifecycleException) KettleMissingPluginsException(org.pentaho.di.core.exception.KettleMissingPluginsException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) KettleException(org.pentaho.di.core.exception.KettleException) MalformedURLException(java.net.MalformedURLException)

Example 35 with NotePadMeta

use of org.pentaho.di.core.NotePadMeta in project pentaho-kettle by pentaho.

the class TransGraph method editNote.

private void editNote(NotePadMeta ni) {
    NotePadMeta before = (NotePadMeta) ni.clone();
    String title = BaseMessages.getString(PKG, "TransGraph.Dialog.EditNote.Title");
    NotePadDialog dd = new NotePadDialog(transMeta, shell, title, ni);
    NotePadMeta n = dd.open();
    if (n != null) {
        ni.setChanged();
        ni.setNote(n.getNote());
        ni.setFontName(n.getFontName());
        ni.setFontSize(n.getFontSize());
        ni.setFontBold(n.isFontBold());
        ni.setFontItalic(n.isFontItalic());
        // font color
        ni.setFontColorRed(n.getFontColorRed());
        ni.setFontColorGreen(n.getFontColorGreen());
        ni.setFontColorBlue(n.getFontColorBlue());
        // background color
        ni.setBackGroundColorRed(n.getBackGroundColorRed());
        ni.setBackGroundColorGreen(n.getBackGroundColorGreen());
        ni.setBackGroundColorBlue(n.getBackGroundColorBlue());
        // border color
        ni.setBorderColorRed(n.getBorderColorRed());
        ni.setBorderColorGreen(n.getBorderColorGreen());
        ni.setBorderColorBlue(n.getBorderColorBlue());
        ni.setDrawShadow(n.isDrawShadow());
        ni.width = ConstUI.NOTE_MIN_SIZE;
        ni.height = ConstUI.NOTE_MIN_SIZE;
        NotePadMeta after = (NotePadMeta) ni.clone();
        spoon.addUndoChange(transMeta, new NotePadMeta[] { before }, new NotePadMeta[] { after }, new int[] { transMeta.indexOfNote(ni) });
        spoon.refreshGraph();
    }
}
Also used : NotePadDialog(org.pentaho.di.ui.spoon.dialog.NotePadDialog) NotePadMeta(org.pentaho.di.core.NotePadMeta)

Aggregations

NotePadMeta (org.pentaho.di.core.NotePadMeta)63 Point (org.pentaho.di.core.gui.Point)39 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)34 StepMeta (org.pentaho.di.trans.step.StepMeta)26 KettleException (org.pentaho.di.core.exception.KettleException)25 JobEntryCopy (org.pentaho.di.job.entry.JobEntryCopy)23 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)15 TransHopMeta (org.pentaho.di.trans.TransHopMeta)14 JobHopMeta (org.pentaho.di.job.JobHopMeta)11 ArrayList (java.util.ArrayList)10 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)10 SlaveServer (org.pentaho.di.cluster.SlaveServer)9 KettleStepException (org.pentaho.di.core.exception.KettleStepException)8 StepMetaInterface (org.pentaho.di.trans.step.StepMetaInterface)8 KettleRepositoryLostException (org.pentaho.di.repository.KettleRepositoryLostException)7 TransMeta (org.pentaho.di.trans.TransMeta)7 FileSystemException (org.apache.commons.vfs2.FileSystemException)6 KettleFileException (org.pentaho.di.core.exception.KettleFileException)6 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)6 StepErrorMeta (org.pentaho.di.trans.step.StepErrorMeta)6