Search in sources :

Example 61 with NotePadMeta

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

the class JobDelegate method dataNodeToElement.

public void dataNodeToElement(final DataNode rootNode, final RepositoryElementInterface element) throws KettleException {
    JobMeta jobMeta = (JobMeta) element;
    Set<String> privateDatabases = null;
    // read the private databases
    DataNode privateDbsNode = rootNode.getNode(NODE_JOB_PRIVATE_DATABASES);
    // BACKLOG-6635
    if (privateDbsNode != null) {
        privateDatabases = new HashSet<String>();
        if (privateDbsNode.hasProperty(PROP_JOB_PRIVATE_DATABASE_NAMES)) {
            for (String privateDatabaseName : getString(privateDbsNode, PROP_JOB_PRIVATE_DATABASE_NAMES).split(JOB_PRIVATE_DATABASE_DELIMITER)) {
                if (!privateDatabaseName.isEmpty()) {
                    privateDatabases.add(privateDatabaseName);
                }
            }
        } else {
            for (DataNode privateDatabase : privateDbsNode.getNodes()) {
                privateDatabases.add(privateDatabase.getName());
            }
        }
    }
    jobMeta.setPrivateDatabases(privateDatabases);
    jobMeta.setSharedObjectsFile(getString(rootNode, PROP_SHARED_FILE));
    // Keep a unique list of job entries to facilitate in the loading.
    // 
    List<JobEntryInterface> jobentries = new ArrayList<JobEntryInterface>();
    // Read the job entry copies
    // 
    DataNode entriesNode = rootNode.getNode(NODE_ENTRIES);
    int nrCopies = (int) entriesNode.getProperty(PROP_NR_JOB_ENTRY_COPIES).getLong();
    // 
    for (DataNode copyNode : entriesNode.getNodes()) {
        // String name = copyNode.getName();
        // Read the entry...
        // 
        JobEntryInterface jobEntry = readJobEntry(copyNode, jobMeta, jobentries);
        JobEntryCopy copy = new JobEntryCopy(jobEntry);
        copy.setName(getString(copyNode, PROP_NAME));
        copy.setDescription(getString(copyNode, PROP_DESCRIPTION));
        copy.setObjectId(new StringObjectId(copyNode.getId().toString()));
        copy.setNr((int) copyNode.getProperty(PROP_NR).getLong());
        int x = (int) copyNode.getProperty(PROP_GUI_LOCATION_X).getLong();
        int y = (int) copyNode.getProperty(PROP_GUI_LOCATION_Y).getLong();
        copy.setLocation(x, y);
        copy.setDrawn(copyNode.getProperty(PROP_GUI_DRAW).getBoolean());
        copy.setLaunchingInParallel(copyNode.getProperty(PROP_PARALLEL).getBoolean());
        // 
        if (jobEntry instanceof JobEntryBase) {
            AttributesMapUtil.loadAttributesMap(copyNode, (JobEntryBase) jobEntry);
        }
        AttributesMapUtil.loadAttributesMap(copyNode, copy);
        jobMeta.getJobCopies().add(copy);
    }
    if (jobMeta.getJobCopies().size() != nrCopies) {
        throw new KettleException("The number of job entry copies read [" + jobMeta.getJobCopies().size() + "] was not the number we expected [" + nrCopies + "]");
    }
    // Read the notes...
    // 
    DataNode notesNode = rootNode.getNode(NODE_NOTES);
    int nrNotes = (int) notesNode.getProperty(PROP_NR_NOTES).getLong();
    for (DataNode noteNode : notesNode.getNodes()) {
        // String name = noteNode.getName();
        String xml = getString(noteNode, PROP_XML);
        jobMeta.addNote(new NotePadMeta(XMLHandler.getSubNode(XMLHandler.loadXMLString(xml), NotePadMeta.XML_TAG)));
    }
    if (jobMeta.nrNotes() != nrNotes) {
        throw new KettleException("The number of notes read [" + jobMeta.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 name = hopNode.getName();
        String copyFromName = getString(hopNode, JOB_HOP_FROM);
        int copyFromNr = (int) hopNode.getProperty(JOB_HOP_FROM_NR).getLong();
        String copyToName = getString(hopNode, JOB_HOP_TO);
        int copyToNr = (int) hopNode.getProperty(JOB_HOP_TO_NR).getLong();
        boolean enabled = true;
        if (hopNode.hasProperty(JOB_HOP_ENABLED)) {
            enabled = hopNode.getProperty(JOB_HOP_ENABLED).getBoolean();
        }
        boolean evaluation = true;
        if (hopNode.hasProperty(JOB_HOP_EVALUATION)) {
            evaluation = hopNode.getProperty(JOB_HOP_EVALUATION).getBoolean();
        }
        boolean unconditional = true;
        if (hopNode.hasProperty(JOB_HOP_UNCONDITIONAL)) {
            unconditional = hopNode.getProperty(JOB_HOP_UNCONDITIONAL).getBoolean();
        }
        JobEntryCopy copyFrom = jobMeta.findJobEntry(copyFromName, copyFromNr, true);
        JobEntryCopy copyTo = jobMeta.findJobEntry(copyToName, copyToNr, true);
        JobHopMeta jobHopMeta = new JobHopMeta(copyFrom, copyTo);
        jobHopMeta.setEnabled(enabled);
        jobHopMeta.setEvaluation(evaluation);
        jobHopMeta.setUnconditional(unconditional);
        jobMeta.addJobHop(jobHopMeta);
    }
    if (jobMeta.nrJobHops() != nrHops) {
        throw new KettleException("The number of hops read [" + jobMeta.nrJobHops() + "] was not the number we expected [" + nrHops + "]");
    }
    // Load the details at the end, to make sure we reference the databases correctly, etc.
    // 
    loadJobMetaDetails(rootNode, jobMeta);
    jobMeta.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(PARAM_PREFIX + idx);
        String key = getString(paramNode, PARAM_KEY);
        String def = getString(paramNode, PARAM_DEFAULT);
        String desc = getString(paramNode, PARAM_DESC);
        jobMeta.addParameterDefinition(key, def, desc);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) JobMeta(org.pentaho.di.job.JobMeta) JobHopMeta(org.pentaho.di.job.JobHopMeta) JobEntryInterface(org.pentaho.di.job.entry.JobEntryInterface) ArrayList(java.util.ArrayList) StringObjectId(org.pentaho.di.repository.StringObjectId) JobEntryBase(org.pentaho.di.job.entry.JobEntryBase) JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) NotePadMeta(org.pentaho.di.core.NotePadMeta)

Example 62 with NotePadMeta

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

the class JobHasANoteImportRuleIT method testRule.

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

Example 63 with NotePadMeta

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

the class JobMetaTest method shouldUseCoordinatesOfItsStepsAndNotesWhenCalculatingMinimumPoint.

@Test
public void shouldUseCoordinatesOfItsStepsAndNotesWhenCalculatingMinimumPoint() {
    Point jobEntryPoint = new Point(500, 500);
    Point notePadMetaPoint = new Point(400, 400);
    JobEntryCopy jobEntryCopy = mock(JobEntryCopy.class);
    when(jobEntryCopy.getLocation()).thenReturn(jobEntryPoint);
    NotePadMeta notePadMeta = mock(NotePadMeta.class);
    when(notePadMeta.getLocation()).thenReturn(notePadMetaPoint);
    // empty Job return 0 coordinate point
    Point point = jobMeta.getMinimum();
    assertEquals(0, point.x);
    assertEquals(0, point.y);
    // when Job contains a single step or note, then jobMeta should return coordinates of it, subtracting borders
    jobMeta.addJobEntry(0, jobEntryCopy);
    Point actualStepPoint = jobMeta.getMinimum();
    assertEquals(jobEntryPoint.x - JobMeta.BORDER_INDENT, actualStepPoint.x);
    assertEquals(jobEntryPoint.y - JobMeta.BORDER_INDENT, actualStepPoint.y);
    // when Job contains step or notes, then jobMeta should return minimal coordinates of them, subtracting borders
    jobMeta.addNote(notePadMeta);
    Point stepPoint = jobMeta.getMinimum();
    assertEquals(notePadMetaPoint.x - JobMeta.BORDER_INDENT, stepPoint.x);
    assertEquals(notePadMetaPoint.y - JobMeta.BORDER_INDENT, stepPoint.y);
}
Also used : JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) Point(org.pentaho.di.core.gui.Point) NotePadMeta(org.pentaho.di.core.NotePadMeta) Test(org.junit.Test)

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