Search in sources :

Example 6 with JobEntryBase

use of org.pentaho.di.job.entry.JobEntryBase in project pentaho-kettle by pentaho.

the class JobDelegate method elementToDataNode.

public DataNode elementToDataNode(final RepositoryElementInterface element) throws KettleException {
    JobMeta jobMeta = (JobMeta) element;
    DataNode rootNode = new DataNode(NODE_JOB);
    if (jobMeta.getPrivateDatabases() != null) {
        // save all private database names http://jira.pentaho.com/browse/PPP-3413
        String privateDatabaseNames = StringUtils.join(jobMeta.getPrivateDatabases(), JOB_PRIVATE_DATABASE_DELIMITER);
        DataNode privateDatabaseNode = rootNode.addNode(NODE_JOB_PRIVATE_DATABASES);
        privateDatabaseNode.setProperty(PROP_JOB_PRIVATE_DATABASE_NAMES, privateDatabaseNames);
    }
    // Save the notes
    // 
    DataNode notesNode = rootNode.addNode(NODE_NOTES);
    notesNode.setProperty(PROP_NR_NOTES, jobMeta.nrNotes());
    for (int i = 0; i < jobMeta.nrNotes(); i++) {
        NotePadMeta note = jobMeta.getNote(i);
        DataNode noteNode = notesNode.addNode(NOTE_PREFIX + i);
        noteNode.setProperty(PROP_XML, note.getXML());
    }
    // 
    if (log.isDetailed()) {
        // $NON-NLS-1$ //$NON-NLS-2$
        log.logDetailed(toString(), "Saving " + jobMeta.nrJobEntries() + " Job entry copies to repository...");
    }
    DataNode entriesNode = rootNode.addNode(NODE_ENTRIES);
    entriesNode.setProperty(PROP_NR_JOB_ENTRY_COPIES, jobMeta.nrJobEntries());
    for (int i = 0; i < jobMeta.nrJobEntries(); i++) {
        JobEntryCopy copy = jobMeta.getJobEntry(i);
        JobEntryInterface entry = copy.getEntry();
        // Create a new node for each entry...
        // 
        DataNode copyNode = entriesNode.addNode(// $NON-NLS-1$
        sanitizeNodeName(copy.getName()) + "_" + (i + 1) + EXT_JOB_ENTRY_COPY);
        copyNode.setProperty(PROP_NAME, copy.getName());
        copyNode.setProperty(PROP_DESCRIPTION, copy.getDescription());
        copyNode.setProperty(PROP_NR, copy.getNr());
        copyNode.setProperty(PROP_GUI_LOCATION_X, copy.getLocation().x);
        copyNode.setProperty(PROP_GUI_LOCATION_Y, copy.getLocation().y);
        copyNode.setProperty(PROP_GUI_DRAW, copy.isDrawn());
        copyNode.setProperty(PROP_PARALLEL, copy.isLaunchingInParallel());
        // Save the job entry group attributes map
        if (entry instanceof JobEntryBase) {
            AttributesMapUtil.saveAttributesMap(copyNode, (JobEntryBase) entry);
        }
        // And save the job entry copy group attributes map
        AttributesMapUtil.saveAttributesMap(copyNode, copy, PROP_ATTRIBUTES_JOB_ENTRY_COPY);
        // Save the entry information here as well, for completeness.
        // TODO: since this slightly stores duplicate information, figure out how to store this separately.
        // 
        copyNode.setProperty(PROP_JOBENTRY_TYPE, entry.getPluginId());
        DataNode customNode = new DataNode(NODE_CUSTOM);
        RepositoryProxy proxy = new RepositoryProxy(customNode);
        entry.saveRep(proxy, proxy.getMetaStore(), null);
        compatibleEntrySaveRep(entry, proxy, null);
        copyNode.addNode(customNode);
    }
    // Finally, save the hops
    // 
    DataNode hopsNode = rootNode.addNode(NODE_HOPS);
    hopsNode.setProperty(PROP_NR_HOPS, jobMeta.nrJobHops());
    for (int i = 0; i < jobMeta.nrJobHops(); i++) {
        JobHopMeta hop = jobMeta.getJobHop(i);
        DataNode hopNode = hopsNode.addNode(JOB_HOP_PREFIX + i);
        hopNode.setProperty(JOB_HOP_FROM, hop.getFromEntry().getName());
        hopNode.setProperty(JOB_HOP_FROM_NR, hop.getFromEntry().getNr());
        hopNode.setProperty(JOB_HOP_TO, hop.getToEntry().getName());
        hopNode.setProperty(JOB_HOP_TO_NR, hop.getToEntry().getNr());
        hopNode.setProperty(JOB_HOP_ENABLED, hop.isEnabled());
        hopNode.setProperty(JOB_HOP_EVALUATION, hop.getEvaluation());
        hopNode.setProperty(JOB_HOP_UNCONDITIONAL, hop.isUnconditional());
    }
    String[] paramKeys = jobMeta.listParameters();
    DataNode paramsNode = rootNode.addNode(NODE_PARAMETERS);
    paramsNode.setProperty(PROP_NR_PARAMETERS, paramKeys == null ? 0 : paramKeys.length);
    for (int idx = 0; idx < paramKeys.length; idx++) {
        DataNode paramNode = paramsNode.addNode(PARAM_PREFIX + idx);
        String key = paramKeys[idx];
        String description = jobMeta.getParameterDescription(paramKeys[idx]);
        String defaultValue = jobMeta.getParameterDefault(paramKeys[idx]);
        // $NON-NLS-1$
        paramNode.setProperty(PARAM_KEY, key != null ? key : "");
        // $NON-NLS-1$
        paramNode.setProperty(PARAM_DEFAULT, defaultValue != null ? defaultValue : "");
        // $NON-NLS-1$
        paramNode.setProperty(PARAM_DESC, description != null ? description : "");
    }
    // Let's not forget to save the details of the transformation itself.
    // This includes logging information, parameters, etc.
    // 
    saveJobDetails(rootNode, jobMeta);
    return rootNode;
}
Also used : JobEntryBase(org.pentaho.di.job.entry.JobEntryBase) JobMeta(org.pentaho.di.job.JobMeta) JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) JobHopMeta(org.pentaho.di.job.JobHopMeta) JobEntryInterface(org.pentaho.di.job.entry.JobEntryInterface) DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) NotePadMeta(org.pentaho.di.core.NotePadMeta)

Aggregations

JobEntryBase (org.pentaho.di.job.entry.JobEntryBase)6 JobEntryInterface (org.pentaho.di.job.entry.JobEntryInterface)6 JobEntryCopy (org.pentaho.di.job.entry.JobEntryCopy)5 KettleException (org.pentaho.di.core.exception.KettleException)4 ObjectId (org.pentaho.di.repository.ObjectId)3 NotePadMeta (org.pentaho.di.core.NotePadMeta)2 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)2 Job (org.pentaho.di.job.Job)2 JobHopMeta (org.pentaho.di.job.JobHopMeta)2 JobMeta (org.pentaho.di.job.JobMeta)2 LongObjectId (org.pentaho.di.repository.LongObjectId)2 StringObjectId (org.pentaho.di.repository.StringObjectId)2 DataNode (org.pentaho.platform.api.repository2.unified.data.node.DataNode)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Test (org.junit.Test)1 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)1 PluginInterface (org.pentaho.di.core.plugins.PluginInterface)1 PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)1