use of org.pentaho.metaverse.api.model.IExternalResourceInfo in project pentaho-metaverse by pentaho.
the class KettleAnalyzerUtil method getResourcesFromMeta.
public static Collection<IExternalResourceInfo> getResourcesFromMeta(final BaseFileInputMeta meta, final IAnalysisContext context) {
Collection<IExternalResourceInfo> resources = Collections.emptyList();
final StepMeta parentStepMeta = meta.getParentStepMeta();
if (parentStepMeta != null) {
final TransMeta parentTransMeta = parentStepMeta.getParentTransMeta();
if (parentTransMeta != null) {
final FileInputList inputList = meta.getFileInputList(parentTransMeta);
if (inputList != null) {
final String[] paths = inputList.getFileStrings();
if (paths != null) {
resources = new ArrayList<>(paths.length);
for (final String path : paths) {
if (!Const.isEmpty(path)) {
try {
final IExternalResourceInfo resource = ExternalResourceInfoFactory.createFileResource(KettleVFS.getFileObject(path), true);
if (resource != null) {
resources.add(resource);
} else {
throw new KettleFileException("Error getting file resource!");
}
} catch (KettleFileException kfe) {
// TODO throw or ignore?
}
}
}
}
}
}
}
return resources;
}
use of org.pentaho.metaverse.api.model.IExternalResourceInfo in project pentaho-metaverse by pentaho.
the class ExternalResourceStepAnalyzer method customAnalyze.
@Override
protected void customAnalyze(T meta, IMetaverseNode node) throws MetaverseAnalyzerException {
// handle all of the external resources
if (getExternalResourceConsumer() != null) {
IAnalysisContext context = getDescriptor().getContext();
Collection<IExternalResourceInfo> resources = getExternalResourceConsumer().getResources(meta, context);
for (IExternalResourceInfo resource : resources) {
try {
if (resource.isInput()) {
String label = DictionaryConst.LINK_READBY;
IMetaverseNode resourceNode = createResourceNode(resource);
getMetaverseBuilder().addNode(resourceNode);
getMetaverseBuilder().addLink(resourceNode, label, node);
}
if (resource.isOutput()) {
String label = DictionaryConst.LINK_WRITESTO;
IMetaverseNode resourceNode = createResourceNode(resource);
getMetaverseBuilder().addNode(resourceNode);
getMetaverseBuilder().addLink(node, label, resourceNode);
}
} catch (MetaverseException e) {
LOGGER.warn(e.getLocalizedMessage());
LOGGER.debug(Messages.getString("ERROR.ErrorDuringAnalysisStackTrace"), e);
}
}
}
}
use of org.pentaho.metaverse.api.model.IExternalResourceInfo in project pentaho-metaverse by pentaho.
the class ConnectionExternalResourceStepAnalyzerTest method testCreateResourceNode_outputs.
@Test
public void testCreateResourceNode_outputs() throws Exception {
IExternalResourceInfo resInfo = mock(IExternalResourceInfo.class);
StepNodes inputs = null;
StepNodes outputs = mock(StepNodes.class);
doReturn(inputs).when(analyzer).getInputs();
doReturn(outputs).when(analyzer).getOutputs();
doReturn(tableNode).when(analyzer).createTableNode(resInfo);
doReturn(false).when(analyzer).isInput();
IMetaverseNode resourceNode = analyzer.createResourceNode(resInfo);
assertEquals(tableNode, resourceNode);
verify(analyzer).linkResourceToFields(outputs);
verify(analyzer, never()).linkResourceToFields(inputs);
}
use of org.pentaho.metaverse.api.model.IExternalResourceInfo in project pentaho-metaverse by pentaho.
the class ConnectionExternalResourceStepAnalyzerTest method testCreateResourceNode_inputs.
@Test
public void testCreateResourceNode_inputs() throws Exception {
IExternalResourceInfo resInfo = mock(IExternalResourceInfo.class);
StepNodes inputs = mock(StepNodes.class);
StepNodes outputs = null;
doReturn(inputs).when(analyzer).getInputs();
doReturn(outputs).when(analyzer).getOutputs();
doReturn(tableNode).when(analyzer).createTableNode(resInfo);
doReturn(true).when(analyzer).isInput();
IMetaverseNode resourceNode = analyzer.createResourceNode(resInfo);
assertEquals(tableNode, resourceNode);
verify(analyzer).linkResourceToFields(inputs);
verify(analyzer, never()).linkResourceToFields(outputs);
assertEquals(tableNode, analyzer.getTableNode());
}
use of org.pentaho.metaverse.api.model.IExternalResourceInfo in project pentaho-metaverse by pentaho.
the class ExternalResourceStepAnalyzerTest method testAnalyze_input.
@Test
public void testAnalyze_input() throws Exception {
// fake the super.analyze call
doReturn(node).when((StepAnalyzer<BaseStepMeta>) analyzer).analyze(descriptor, meta);
analyzer.setExternalResourceConsumer(erc);
List<IExternalResourceInfo> resources = new ArrayList<>();
IExternalResourceInfo resInfo = mock(IExternalResourceInfo.class);
resources.add(resInfo);
when(resInfo.isInput()).thenReturn(true);
when(erc.getResources(eq(meta), any(IAnalysisContext.class))).thenReturn(resources);
analyzer.customAnalyze(meta, node);
verify(builder).addNode(resourceNode);
verify(builder).addLink(resourceNode, DictionaryConst.LINK_READBY, node);
}
Aggregations