use of org.apache.hop.metadata.api.IHopMetadataSerializer in project hop by apache.
the class CheckConnectionsDialog method open.
@Override
public IAction open() {
Shell parent = getParent();
shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MIN | SWT.MAX);
props.setLook(shell);
WorkflowDialog.setShellImage(shell, action);
ModifyListener lsMod = e -> action.setChanged();
changed = action.hasChanged();
FormLayout formLayout = new FormLayout();
formLayout.marginWidth = Const.FORM_MARGIN;
formLayout.marginHeight = Const.FORM_MARGIN;
shell.setLayout(formLayout);
shell.setText("Check Neo4j Connections");
int middle = props.getMiddlePct();
int margin = Const.MARGIN;
// Add buttons first, then the list of connections dynamically sizing
// Put these buttons at the bottom
//
Button wOk = new Button(shell, SWT.PUSH);
wOk.setText(BaseMessages.getString(PKG, "System.Button.OK"));
wOk.addListener(SWT.Selection, e -> ok());
Button wCancel = new Button(shell, SWT.PUSH);
wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
wCancel.addListener(SWT.Selection, e -> cancel());
BaseTransformDialog.positionBottomButtons(shell, new Button[] { wOk, wCancel }, margin, null);
Label wlName = new Label(shell, SWT.RIGHT);
wlName.setText("Action name");
props.setLook(wlName);
FormData fdlName = new FormData();
fdlName.left = new FormAttachment(0, 0);
fdlName.right = new FormAttachment(middle, -margin);
fdlName.top = new FormAttachment(0, margin);
wlName.setLayoutData(fdlName);
wName = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
props.setLook(wName);
wName.addModifyListener(lsMod);
FormData fdName = new FormData();
fdName.left = new FormAttachment(middle, 0);
fdName.top = new FormAttachment(0, margin);
fdName.right = new FormAttachment(100, 0);
wName.setLayoutData(fdName);
Label wlConnections = new Label(shell, SWT.LEFT);
wlConnections.setText(BaseMessages.getString(PKG, "CheckConnectionsDialog.Connections.Label"));
props.setLook(wlConnections);
FormData fdlConnections = new FormData();
fdlConnections.left = new FormAttachment(0, 0);
fdlConnections.right = new FormAttachment(middle, -margin);
fdlConnections.top = new FormAttachment(wName, margin);
wlConnections.setLayoutData(fdlConnections);
String[] availableConnectionNames;
try {
IHopMetadataSerializer<NeoConnection> connectionSerializer = getMetadataProvider().getSerializer(NeoConnection.class);
List<String> names = connectionSerializer.listObjectNames();
Collections.sort(names);
availableConnectionNames = names.toArray(new String[0]);
} catch (HopException e) {
availableConnectionNames = new String[] {};
}
ColumnInfo[] columns = new ColumnInfo[] { new ColumnInfo(BaseMessages.getString(PKG, "CheckConnectionsDialog.ConnectionName.Column.Label"), ColumnInfo.COLUMN_TYPE_CCOMBO, availableConnectionNames, false) };
columns[0].setUsingVariables(true);
wConnections = new TableView(action, shell, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI, columns, action.getConnectionNames().size(), false, lsMod, props);
FormData fdConnections = new FormData();
fdConnections.left = new FormAttachment(0, 0);
fdConnections.top = new FormAttachment(wlConnections, margin);
fdConnections.right = new FormAttachment(100, 0);
fdConnections.bottom = new FormAttachment(wOk, -margin * 2);
wConnections.setLayoutData(fdConnections);
getData();
BaseDialog.defaultShellHandling(shell, c -> ok(), c -> cancel());
return action;
}
use of org.apache.hop.metadata.api.IHopMetadataSerializer in project hop by apache.
the class MemoryMetadataProvider method getSerializer.
@Override
public <T extends IHopMetadata> IHopMetadataSerializer<T> getSerializer(Class<T> managedClass) throws HopException {
IHopMetadataSerializer<IHopMetadata> serializer = serializerMap.get(managedClass.getName());
if (serializer == null) {
HopMetadata hopMetadata = managedClass.getAnnotation(HopMetadata.class);
String description = managedClass.getSimpleName();
if (hopMetadata != null) {
description = hopMetadata.name();
}
serializer = (IHopMetadataSerializer<IHopMetadata>) new MemoryMetadataSerializer<>(this, managedClass, variables, description);
serializerMap.put(managedClass.getName(), serializer);
}
return (IHopMetadataSerializer<T>) serializer;
}
use of org.apache.hop.metadata.api.IHopMetadataSerializer in project hop by apache.
the class CypherScript method execute.
@Override
public Result execute(Result result, int nr) throws HopException {
IHopMetadataSerializer<NeoConnection> serializer = getMetadataProvider().getSerializer(NeoConnection.class);
// Replace variables & parameters
//
NeoConnection connection;
String realConnectionName = resolve(connectionName);
try {
if (StringUtils.isEmpty(realConnectionName)) {
throw new HopException("The Neo4j connection name is not set");
}
connection = serializer.load(realConnectionName);
if (connection == null) {
throw new HopException("Unable to find connection with name '" + realConnectionName + "'");
}
} catch (Exception e) {
result.setResult(false);
result.increaseErrors(1L);
throw new HopException("Unable to gencsv or find connection with name '" + realConnectionName + "'", e);
}
String realScript;
if (replacingVariables) {
realScript = resolve(script);
} else {
realScript = script;
}
int nrExecuted;
try (Driver driver = connection.getDriver(log, this)) {
//
try (Session session = connection.getSession(log, driver, this)) {
TransactionWork<Integer> transactionWork = transaction -> {
int executed = 0;
try {
// Split the script into parts : semi-colon at the start of a separate line
//
String[] commands = realScript.split("\\r?\\n;");
for (String command : commands) {
// Cleanup command: replace leading and trailing whitespaces and newlines
//
String cypher = command.replaceFirst("^\\s+", "").replaceFirst("\\s+$", "");
//
if (StringUtils.isNotEmpty(cypher)) {
transaction.run(cypher);
executed++;
log.logDetailed("Executed cypher statement: " + cypher);
}
}
// All statements executed successfully so commit
//
transaction.commit();
} catch (Exception e) {
log.logError("Error executing cypher statements...", e);
result.increaseErrors(1L);
transaction.rollback();
result.setResult(false);
}
return executed;
};
nrExecuted = session.writeTransaction(transactionWork);
}
}
if (result.getNrErrors() == 0) {
logBasic("Neo4j script executed " + nrExecuted + " statements without error");
} else {
logBasic("Neo4j script executed with error(s)");
}
return result;
}
Aggregations