Search in sources :

Example 46 with IMetaverseNode

use of org.pentaho.metaverse.api.IMetaverseNode in project pentaho-metaverse by pentaho.

the class ExternalResourceStepAnalyzer method createInputFieldNode.

@Override
protected IMetaverseNode createInputFieldNode(IAnalysisContext context, ValueMetaInterface fieldMeta, String previousStepName, String nodeType) {
    // if the previousStepName is 'resource' then this is HAS to be a resource field
    boolean isResource = RESOURCE.equals(previousStepName);
    nodeType = isResource ? getResourceInputNodeType() : nodeType;
    IMetaverseNode inputFieldNode = super.createInputFieldNode(context, fieldMeta, previousStepName, nodeType);
    inputFieldNode.setType(nodeType);
    if (isResource) {
        // add the node so it's not virtual
        getMetaverseBuilder().addNode(inputFieldNode);
    }
    return inputFieldNode;
}
Also used : IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode)

Example 47 with IMetaverseNode

use of org.pentaho.metaverse.api.IMetaverseNode in project pentaho-metaverse by pentaho.

the class StepAnalyzer method mapChange.

/**
 * Add the required "derives" links to the metaverse for a ComponentDerivationRecord
 *
 * @param change
 */
protected void mapChange(ComponentDerivationRecord change) {
    if (change != null) {
        List<IMetaverseNode> inputNodes = new ArrayList<>();
        List<IMetaverseNode> outputNodes = new ArrayList<>();
        if (StringUtils.isNotEmpty(change.getOriginalEntityStepName())) {
            inputNodes.add(getInputs().findNode(change.getOriginalField()));
        } else {
            inputNodes.addAll(getInputs().findNodes(change.getOriginalEntityName()));
        }
        if (StringUtils.isNotEmpty(change.getChangedEntityStepName())) {
            outputNodes.add(getOutputs().findNode(change.getChangedField()));
        } else {
            outputNodes.addAll(getOutputs().findNodes(change.getChangedEntityName()));
        }
        if (CollectionUtils.isEmpty(inputNodes)) {
            // see if it's one of the output nodes
            inputNodes = getOutputs().findNodes(change.getOriginalEntityName());
            // if we still don't have it, we need a transient node created
            if (CollectionUtils.isEmpty(inputNodes)) {
                // create a transient node for it
                ValueMetaInterface tmp = new ValueMeta(change.getOriginalEntityName());
                IMetaverseNode fieldNode = createOutputFieldNode(getDescriptor().getContext(), tmp, null, getTransientNodeType());
                // Add link to show that this step created this as a transient field
                getMetaverseBuilder().addLink(rootNode, DictionaryConst.LINK_TRANSIENT, fieldNode);
                getMetaverseBuilder().addLink(rootNode, DictionaryConst.LINK_USES, fieldNode);
                inputNodes.add(fieldNode);
            }
        }
        if (CollectionUtils.isEmpty(outputNodes)) {
            // create a transient node for it
            ValueMetaInterface tmp = new ValueMeta(change.getChangedEntityName());
            IMetaverseNode fieldNode = createOutputFieldNode(getDescriptor().getContext(), tmp, null, getTransientNodeType());
            // Add link to show that this step created this as a transient field
            getMetaverseBuilder().addLink(rootNode, DictionaryConst.LINK_TRANSIENT, fieldNode);
            getMetaverseBuilder().addLink(rootNode, DictionaryConst.LINK_USES, fieldNode);
            outputNodes.add(fieldNode);
        }
        // no input step was defined, link all field name matches together, regardless of origin step
        for (IMetaverseNode inputNode : inputNodes) {
            for (IMetaverseNode outputNode : outputNodes) {
                if (change.getOperations().size() > 0) {
                    outputNode.setProperty(DictionaryConst.PROPERTY_OPERATIONS, change.toString());
                }
                linkChangeNodes(inputNode, outputNode);
            }
        }
    }
}
Also used : IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) ArrayList(java.util.ArrayList) ValueMeta(org.pentaho.di.core.row.ValueMeta) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 48 with IMetaverseNode

use of org.pentaho.metaverse.api.IMetaverseNode in project pentaho-metaverse by pentaho.

the class StepAnalyzer method processInputs.

/**
 * Add links to nodes in the metaverse for each of the fields that are input into this step. The fields are uniquely
 * identified based on the step that created the node and the intended target step.
 *
 * @param meta
 * @return
 */
protected StepNodes processInputs(T meta) {
    StepNodes inputs = new StepNodes();
    // get all input steps
    Map<String, RowMetaInterface> inputRowMetaInterfaces = getInputRowMetaInterfaces(meta);
    if (MapUtils.isNotEmpty(inputRowMetaInterfaces)) {
        for (Map.Entry<String, RowMetaInterface> entry : inputRowMetaInterfaces.entrySet()) {
            String prevStepName = entry.getKey();
            RowMetaInterface inputFields = entry.getValue();
            if (inputFields != null) {
                for (ValueMetaInterface valueMetaInterface : inputFields.getValueMetaList()) {
                    IMetaverseNode prevFieldNode = createInputFieldNode(getDescriptor().getContext(), valueMetaInterface, prevStepName, getInputNodeType());
                    getMetaverseBuilder().addLink(prevFieldNode, DictionaryConst.LINK_INPUTS, rootNode);
                    inputs.addNode(prevStepName, valueMetaInterface.getName(), prevFieldNode);
                }
            } else {
                LOGGER.warn("No input fields found for step " + getStepName());
            }
        }
    }
    return inputs;
}
Also used : IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) HashMap(java.util.HashMap) Map(java.util.Map) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 49 with IMetaverseNode

use of org.pentaho.metaverse.api.IMetaverseNode in project pentaho-metaverse by pentaho.

the class StepAnalyzer method getStepFieldOriginDescriptor.

protected IComponentDescriptor getStepFieldOriginDescriptor(IComponentDescriptor descriptor, String fieldName) throws MetaverseAnalyzerException {
    if (descriptor == null || stepFields == null) {
        return null;
    }
    ValueMetaInterface vmi = stepFields.searchValueMeta(fieldName);
    String origin = (vmi == null) ? fieldName : vmi.getOrigin();
    // if we can't determine the origin, throw an exception
    if (origin == null && !ArrayUtils.isEmpty(prevStepNames)) {
        throw new MetaverseAnalyzerException(Messages.getString("ERROR.NoOriginForField", fieldName));
    }
    IMetaverseNode tmpOriginNode = metaverseObjectFactory.createNodeObject(UUID.randomUUID().toString(), origin, DictionaryConst.NODE_TYPE_TRANS_STEP);
    tmpOriginNode.setProperty(DictionaryConst.PROPERTY_NAMESPACE, rootNode.getProperty(DictionaryConst.PROPERTY_NAMESPACE));
    INamespace stepFieldNamespace = new Namespace(tmpOriginNode.getLogicalId());
    MetaverseComponentDescriptor d = new MetaverseComponentDescriptor(fieldName, DictionaryConst.NODE_TYPE_TRANS_FIELD, tmpOriginNode, descriptor.getContext());
    return d;
}
Also used : MetaverseAnalyzerException(org.pentaho.metaverse.api.MetaverseAnalyzerException) INamespace(org.pentaho.metaverse.api.INamespace) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) INamespace(org.pentaho.metaverse.api.INamespace) Namespace(org.pentaho.metaverse.api.Namespace) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) MetaverseComponentDescriptor(org.pentaho.metaverse.api.MetaverseComponentDescriptor)

Example 50 with IMetaverseNode

use of org.pentaho.metaverse.api.IMetaverseNode in project pentaho-metaverse by pentaho.

the class BaseKettleMetaverseComponentTest method testCreateNodeFromDescriptor.

@Test
public void testCreateNodeFromDescriptor() throws Exception {
    String namespaceId = "{namespace: 'my namespace', name: 'my name', type: 'my type'}";
    ILogicalIdGenerator idGenerator = DictionaryConst.LOGICAL_ID_GENERATOR_DEFAULT;
    IComponentDescriptor descriptor = mock(IComponentDescriptor.class);
    INamespace ns = mock(INamespace.class);
    when(descriptor.getParentNamespace()).thenReturn(mock(INamespace.class));
    when(descriptor.getNamespace()).thenReturn(ns);
    when(ns.getNamespaceId()).thenReturn(namespaceId);
    component.metaverseObjectFactory = spy(new MetaverseObjectFactory());
    IMetaverseNode node = component.createNodeFromDescriptor(descriptor, idGenerator);
    assertNotNull(node);
    assertTrue(node.getLogicalId().contains(namespaceId));
}
Also used : IComponentDescriptor(org.pentaho.metaverse.api.IComponentDescriptor) ILogicalIdGenerator(org.pentaho.metaverse.api.ILogicalIdGenerator) INamespace(org.pentaho.metaverse.api.INamespace) MetaverseObjectFactory(org.pentaho.metaverse.api.MetaverseObjectFactory) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

IMetaverseNode (org.pentaho.metaverse.api.IMetaverseNode)131 Test (org.junit.Test)77 IComponentDescriptor (org.pentaho.metaverse.api.IComponentDescriptor)30 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)23 MetaverseComponentDescriptor (org.pentaho.metaverse.api.MetaverseComponentDescriptor)16 ValueMeta (org.pentaho.di.core.row.ValueMeta)13 IExternalResourceInfo (org.pentaho.metaverse.api.model.IExternalResourceInfo)12 IAnalysisContext (org.pentaho.metaverse.api.IAnalysisContext)11 MetaverseAnalyzerException (org.pentaho.metaverse.api.MetaverseAnalyzerException)11 Vertex (com.tinkerpop.blueprints.Vertex)10 ArrayList (java.util.ArrayList)10 INamespace (org.pentaho.metaverse.api.INamespace)10 TransMeta (org.pentaho.di.trans.TransMeta)9 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)9 MetaverseTransientNode (org.pentaho.dictionary.MetaverseTransientNode)9 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)8 Namespace (org.pentaho.metaverse.api.Namespace)8 StepField (org.pentaho.metaverse.api.StepField)8 HashMap (java.util.HashMap)7 Matchers.anyString (org.mockito.Matchers.anyString)7