use of org.pentaho.di.trans.dataservice.DataServiceMeta in project pdi-dataservice-server-plugin by pentaho.
the class DataServiceClient method getServiceInformation.
@Override
public List<IThinServiceInformation> getServiceInformation() throws SQLException {
List<IThinServiceInformation> services = Lists.newArrayList();
for (DataServiceMeta service : resolver.getDataServices(logErrors()::apply)) {
TransMeta transMeta = service.getServiceTrans();
try {
transMeta.activateParameters();
RowMetaInterface serviceFields = transMeta.getStepFields(service.getStepname());
IThinServiceInformation serviceInformation = new ThinServiceInformation(service.getName(), service.isStreaming(), serviceFields);
services.add(serviceInformation);
} catch (Exception e) {
String message = MessageFormat.format("Unable to get fields for service {0}, transformation: {1}", service.getName(), transMeta.getName());
log.logError(message, e);
}
}
return services;
}
use of org.pentaho.di.trans.dataservice.DataServiceMeta in project pdi-dataservice-server-plugin by pentaho.
the class DataServiceClient method getServiceInformation.
@Override
public ThinServiceInformation getServiceInformation(String name) throws SQLException {
DataServiceMeta dataServiceMeta = resolver.getDataService(name);
if (dataServiceMeta != null) {
TransMeta transMeta = dataServiceMeta.getServiceTrans();
try {
transMeta.activateParameters();
RowMetaInterface serviceFields = transMeta.getStepFields(dataServiceMeta.getStepname());
return new ThinServiceInformation(dataServiceMeta.getName(), dataServiceMeta.isStreaming(), serviceFields);
} catch (Exception e) {
String message = MessageFormat.format("Unable to get fields for service {0}, transformation: {1}", dataServiceMeta.getName(), transMeta.getName());
log.logError(message, e);
}
}
return null;
}
use of org.pentaho.di.trans.dataservice.DataServiceMeta in project pdi-dataservice-server-plugin by pentaho.
the class DataServiceMetaStoreUtil method getDataServiceByStepName.
public DataServiceMeta getDataServiceByStepName(TransMeta transMeta, String stepName) {
Set<Integer> cacheKeys = createCacheKeys(transMeta, stepName);
for (Map.Entry<Integer, String> entry : stepCache.getAll(cacheKeys).entrySet()) {
String serviceName = entry.getValue();
if (serviceName.isEmpty()) {
// Step is marked as not having a Data Service
return null;
}
// Check if Data Service is still valid
DataServiceMeta dataServiceMeta;
try {
dataServiceMeta = getDataService(serviceName, transMeta);
} catch (MetaStoreException e) {
dataServiceMeta = null;
}
if (dataServiceMeta != null && dataServiceMeta.getStepname().equals(stepName)) {
return dataServiceMeta;
} else {
stepCache.remove(entry.getKey(), serviceName);
}
}
// Look up from embedded metastore
for (DataServiceMeta dataServiceMeta : getDataServices(transMeta)) {
if (dataServiceMeta.getStepname().equalsIgnoreCase(stepName)) {
return dataServiceMeta;
}
}
// Data service not found on step, store negative result in the cache
stepCache.putAll(Maps.asMap(cacheKeys, Functions.constant("")));
return null;
}
use of org.pentaho.di.trans.dataservice.DataServiceMeta in project pdi-dataservice-server-plugin by pentaho.
the class SynchronizationListener method contentSafe.
@Override
public void contentSafe(Object parentObject) {
synchronizer.sync((TransMeta) parentObject, (e) -> {
String message = e.getMessage();
if (prompt) {
if (e instanceof DataServiceAlreadyExistsException) {
DataServiceMeta dataService = ((DataServiceAlreadyExistsException) e).getDataServiceMeta();
delegate.syncExec(suggestEdit(dataService, message));
}
if (e instanceof UndefinedDataServiceException) {
DataServiceMeta dataService = ((UndefinedDataServiceException) e).getDataServiceMeta();
delegate.syncExec(suggestRemove(dataService, message));
}
}
delegate.getLogChannel().logError(message, e);
return null;
});
}
use of org.pentaho.di.trans.dataservice.DataServiceMeta in project pdi-dataservice-server-plugin by pentaho.
the class DataServiceDialogTest method testBuilder.
@Test
public void testBuilder() throws Exception {
final DataServiceDelegate mockDelegate = mock(DataServiceDelegate.class);
final DataServiceDialog dialog = mock(DataServiceDialog.class);
when(dialog.getController()).thenReturn(controller);
// Intercept actual creation so we can inject our mock
DataServiceDialog.Builder builder = new DataServiceDialog.Builder(model) {
@Override
protected DataServiceDialog createDialog(DataServiceDelegate delegate) {
assertThat(delegate, sameInstance(mockDelegate));
assertThat(super.createDialog(delegate), isA(DataServiceDialog.class));
return dialog;
}
};
builder.serviceStep("step");
verify(model).setServiceStep("step");
builder.serviceStep("");
builder.serviceStep(null);
verify(model, times(2)).setServiceStep("");
DataServiceMeta dataService = mock(DataServiceMeta.class);
when(dataService.getName()).thenReturn("Service");
when(dataService.getStepname()).thenReturn("OUTPUT");
ArrayList<PushDownOptimizationMeta> optimizations = Lists.newArrayList(mock(PushDownOptimizationMeta.class));
when(dataService.getPushDownOptimizationMeta()).thenReturn(optimizations);
builder.edit(dataService);
verify(model).setServiceName("Service");
verify(model).setServiceStep("OUTPUT");
verify(model).setPushDownOptimizations(optimizations);
Shell shell = mock(Shell.class);
ArrayList<PushDownFactory> factories = Lists.newArrayList(mock(PushDownFactory.class));
when(mockDelegate.getShell()).thenReturn(shell);
when(mockDelegate.getPushDownFactories()).thenReturn(factories);
assertThat(builder.build(mockDelegate), sameInstance(dialog));
verify(controller).setDataService(dataService);
verify(dialog).loadXul(same(shell), any(KettleXulLoader.class), any(SwtXulRunner.class));
verify(dialog).initOptimizations(factories);
Throwable xulException = new XulException();
when(dialog.loadXul(same(shell), any(KettleXulLoader.class), any(SwtXulRunner.class))).thenThrow(xulException);
try {
builder.build(mockDelegate);
fail("Expected exception was not thrown");
} catch (KettleException e) {
assertThat(e.getCause(), equalTo(xulException));
}
}
Aggregations