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;
}
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);
}
}
}
}
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;
}
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;
}
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));
}
Aggregations