if(connections.size() != 1) {
throw new SqoopException(ServerError.SERVER_0003,
"Expected one connection metadata but got " + connections.size());
}
MConnection connection = connections.get(0);
// Verify that user is not trying to spoof us
MConnectionForms connectorForms =
ConnectorManager.getInstance().getConnectorMetadata(connection.getConnectorId())
.getConnectionForms();
MConnectionForms frameworkForms = FrameworkManager.getInstance().getFramework()
.getConnectionForms();
if(!connectorForms.equals(connection.getConnectorPart())
|| !frameworkForms.equals(connection.getFrameworkPart())) {
throw new SqoopException(ServerError.SERVER_0003,
"Detected incorrect form structure");
}
// Responsible connector for this session
SqoopConnector connector =
ConnectorManager.getInstance().getConnector(connection.getConnectorId());
// Get validator objects
Validator connectorValidator = connector.getValidator();
Validator frameworkValidator = FrameworkManager.getInstance().getValidator();
// We need translate forms to configuration objects
Object connectorConfig = ClassUtils.instantiate(
connector.getConnectionConfigurationClass());
Object frameworkConfig = ClassUtils.instantiate(
FrameworkManager.getInstance().getConnectionConfigurationClass());
FormUtils.fromForms(
connection.getConnectorPart().getForms(), connectorConfig);
FormUtils.fromForms(
connection.getFrameworkPart().getForms(), frameworkConfig);
// Validate both parts
Validation connectorValidation =
connectorValidator.validateConnection(connectorConfig);
Validation frameworkValidation =
frameworkValidator.validateConnection(frameworkConfig);
Status finalStatus = Status.getWorstStatus(connectorValidation.getStatus(),
frameworkValidation.getStatus());
// Return back validations in all cases
ValidationBean outputBean =
new ValidationBean(connectorValidation, frameworkValidation);
// If we're good enough let's perform the action
if(finalStatus.canProceed()) {
if(update) {
AuditLoggerManager.getInstance()
.logAuditEvent(ctx.getUserName(), ctx.getRequest().getRemoteAddr(),
"update", "connection", String.valueOf(connection.getPersistenceId()));
connection.setLastUpdateUser(username);
RepositoryManager.getInstance().getRepository().updateConnection(connection);
} else {
connection.setCreationUser(username);
connection.setLastUpdateUser(username);
RepositoryManager.getInstance().getRepository().createConnection(connection);
outputBean.setId(connection.getPersistenceId());
AuditLoggerManager.getInstance()
.logAuditEvent(ctx.getUserName(), ctx.getRequest().getRemoteAddr(),
"create", "connection", String.valueOf(connection.getPersistenceId()));
}
}
return outputBean;
}