use of org.pentaho.metaverse.api.model.IExternalResourceInfo in project pentaho-metaverse by pentaho.
the class ConnectionExternalResourceStepAnalyzerTest method testCustomAnalyze_input.
@Test
public void testCustomAnalyze_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.getResourcesFromMeta(meta, context)).thenReturn(resources);
IMetaverseNode connectionNode = mock(IMetaverseNode.class);
doReturn(connectionNode).when(analyzer).getConnectionNode();
doReturn(resourceNode).when(analyzer).createResourceNode(any(IExternalResourceInfo.class));
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);
verify(builder).addNode(connectionNode);
verify(builder).addLink(connectionNode, DictionaryConst.LINK_DEPENDENCYOF, node);
}
use of org.pentaho.metaverse.api.model.IExternalResourceInfo in project pentaho-metaverse by pentaho.
the class ExternalResourceStepAnalyzerTest method testAnalyze_output.
@Test
public void testAnalyze_output() 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(false);
when(resInfo.isOutput()).thenReturn(true);
when(erc.getResources(eq(meta), any(IAnalysisContext.class))).thenReturn(resources);
analyzer.customAnalyze(meta, node);
verify(builder).addNode(resourceNode);
verify(builder).addLink(node, DictionaryConst.LINK_WRITESTO, resourceNode);
}
use of org.pentaho.metaverse.api.model.IExternalResourceInfo in project pentaho-metaverse by pentaho.
the class TableOutputExternalResourceConsumer method getResourcesFromMeta.
@Override
public Collection<IExternalResourceInfo> getResourcesFromMeta(TableOutputMeta meta, IAnalysisContext context) {
Set<IExternalResourceInfo> resources = new HashSet<IExternalResourceInfo>();
DatabaseMeta dbMeta = meta.getDatabaseMeta();
if (dbMeta != null) {
IExternalResourceInfo databaseResource = ExternalResourceInfoFactory.createDatabaseResource(dbMeta, false);
String tableName = context.equals(DictionaryConst.CONTEXT_RUNTIME) ? meta.getParentStepMeta().getParentTransMeta().environmentSubstitute(meta.getTableName()) : meta.getTableName();
String schema = context.getContextName().equals(DictionaryConst.CONTEXT_RUNTIME) ? meta.getParentStepMeta().getParentTransMeta().environmentSubstitute(meta.getSchemaName()) : meta.getSchemaName();
databaseResource.getAttributes().put(DictionaryConst.PROPERTY_TABLE, tableName);
databaseResource.getAttributes().put(DictionaryConst.PROPERTY_SCHEMA, schema);
resources.add(databaseResource);
}
return resources;
}
use of org.pentaho.metaverse.api.model.IExternalResourceInfo in project pentaho-metaverse by pentaho.
the class TextFileOutputExternalResourceConsumer method getResourcesFromRow.
@Override
public Collection<IExternalResourceInfo> getResourcesFromRow(TextFileOutput textFileOutput, RowMetaInterface rowMeta, Object[] row) {
Collection<IExternalResourceInfo> resources = new LinkedList<IExternalResourceInfo>();
// For some reason the step doesn't return the StepMetaInterface directly, so go around it
TextFileOutputMeta meta = (TextFileOutputMeta) textFileOutput.getStepMeta().getStepMetaInterface();
try {
TextFileOutputData data = ((TextFileOutputData) textFileOutput.getStepDataInterface());
String filename = rowMeta.getString(row, meta.getFileNameField(), meta.getFileName());
if (null != data) {
// For some reason, the first call to process row doesn't have the data.fileName filled in, so
// fall back to the filename field value, and then to the meta's filename
filename = textFileOutput.buildFilename(Const.isEmpty(data.fileName) ? filename : data.fileName, true);
}
if (!Const.isEmpty(filename)) {
FileObject fileObject = KettleVFS.getFileObject(filename);
resources.add(ExternalResourceInfoFactory.createFileResource(fileObject, false));
}
} catch (KettleException kve) {
// TODO throw exception or ignore?
}
return resources;
}
use of org.pentaho.metaverse.api.model.IExternalResourceInfo in project pentaho-metaverse by pentaho.
the class AbstractJobEntryJsonSerializer method writeExternalResources.
protected void writeExternalResources(T meta, JsonGenerator json, SerializerProvider serializerProvider) throws IOException, JsonGenerationException {
json.writeArrayFieldStart(JSON_PROPERTY_EXTERNAL_RESOURCES);
JobMeta jobMeta = new JobMeta();
if (meta.getParentJob() != null && meta.getParentJob().getJobMeta() != null) {
jobMeta = meta.getParentJob().getJobMeta();
}
List<ResourceReference> dependencies = meta.getResourceDependencies(jobMeta);
for (ResourceReference dependency : dependencies) {
for (ResourceEntry resourceEntry : dependency.getEntries()) {
IExternalResourceInfo resourceInfo = ExternalResourceInfoFactory.createResource(resourceEntry);
json.writeObject(resourceInfo);
}
}
json.writeEndArray();
}
Aggregations