public void setDataSourceDef(final DataSourceDef dataSourceDef) { this.dataSourceDef = dataSourceDef; mainPanel.clear(); mainPanel.setName(dataSourceDef.getName()); mainPanel.setConnectionURL(dataSourceDef.getConnectionURL()); mainPanel.setUser(dataSourceDef.getUser()); mainPanel.setPassword(dataSourceDef.getPassword()); mainPanel.setDriver(dataSourceDef.getDriverUuid()); }
/** * Creates a data source in the Wildfly server. * @param dataSourceDef Data source definition to be created. * @param jndi jndi name to be use the Wildly server to bound the data source in the jndi context. * @return returns the deployment information for the created data source. * @throws Exception exceptions may be thrown if the data source couldn't be created. */ private DataSourceDeploymentInfo deploy(final DataSourceDef dataSourceDef, final String jndi, String deploymentId) throws Exception { DriverDeploymentInfo driverDeploymentInfo = driverProvider.getDeploymentInfo(dataSourceDef.getDriverUuid()); if (driverDeploymentInfo == null) { throw new Exception("Required driver: " + dataSourceDef.getDriverUuid() + " is not deployed."); } WildflyDataSourceDef wfDataSourceDef = buildWFDataSource(deploymentId, jndi, dataSourceDef, driverDeploymentInfo.getDriverDeploymentId()); dataSourceMgmtClient.createDataSource(wfDataSourceDef); return new DataSourceDeploymentInfo(deploymentId, true, dataSourceDef.getUuid(), jndi, false); }
protected void setup( ) throws Exception { dataSourceDef = new DataSourceDef( ); dataSourceDef.setUuid( DS1_UUID ); dataSourceDef.setName( DS1_NAME ); dataSourceDef.setDriverUuid( DRIVER1_UUID ); dataSourceDef.setConnectionURL( DS1_CONNECTION_URL ); dataSourceDef.setUser( DS1_USER ); dataSourceDef.setPassword( DS1_PASSWORD ); }
private DataSourceDefInfo createDataSourceDefInfo(final org.uberfire.java.nio.file.Path path) { String content = ioService.readAllString(path); DataSourceDef dataSourceDef = DataSourceDefSerializer.deserialize(content); DataSourceDeploymentInfo deploymentInfo = null; try { deploymentInfo = runtimeManager.getDataSourceDeploymentInfo(dataSourceDef.getUuid()); } catch (Exception e) { logger.warn("It was not possible to read deployment info when building DataSourceDefInfo for data source: " + dataSourceDef.getUuid(), e); } return new DataSourceDefInfo(dataSourceDef.getUuid(), dataSourceDef.getName(), Paths.convert(path), deploymentInfo); }
if (isEmpty(dataSourceDef.getConnectionURL())) { result.setMessage("A valid connection url is required"); return result; if (isEmpty(dataSourceDef.getUser()) || isEmpty(dataSourceDef.getPassword())) { result.setMessage("A valid user and password are required"); return result; if (isEmpty(dataSourceDef.getDriverUuid())) { result.setMessage("A valid driver is required"); return result; driverDefInfo = dataSourceDefQueryService.findModuleDriver(dataSourceDef.getDriverUuid(), module.getRootPath()); } else { driverDefInfo = dataSourceDefQueryService.findGlobalDriver(dataSourceDef.getDriverUuid()); result.setMessage("Data source driver: " + dataSourceDef.getUuid() + " was not found"); return result; Properties properties = new Properties(); properties.put("user", dataSourceDef.getUser()); properties.put("password", dataSourceDef.getPassword()); dataSourceDef.getConnectionURL(), properties);
private WildflyDataSourceDef buildWFDataSource(String deploymentId, String jndi, DataSourceDef dataSourceDef, String driverDeploymentId) { WildflyDataSourceDef wfDataSourceDef = new WildflyDataSourceDef(); wfDataSourceDef.setName(deploymentId); wfDataSourceDef.setDriverName(driverDeploymentId); wfDataSourceDef.setJndi(jndi); wfDataSourceDef.setConnectionURL(dataSourceDef.getConnectionURL()); wfDataSourceDef.setUser(dataSourceDef.getUser()); wfDataSourceDef.setPassword(dataSourceDef.getPassword()); wfDataSourceDef.setUseJTA(true); return wfDataSourceDef; }
public static String generateJNDIName( final DataSourceDef dataSourceDef ) { return "java:jboss/kie/datasources/" + dataSourceDef.getUuid(); }
@Override protected String buildFileName(DataSourceDef def) { return def.getName() + ".datasource"; }
@Override public void execute() { mainPanel.setDriver(getContent().getDef().getDriverUuid()); } };
@Override public void start() { dataSourceDefPage.clear(); dataSourceDefPage.setComplete(false); dataSourceDef = new DataSourceDef(); dataSourceDefPage.setDataSourceDef(dataSourceDef); dataSourceDefPage.setModule(module); dataSourceDefPage.loadDrivers(getLoadDriversSuccessCommand(), getLoadDriversFailureCommand()); }
public void onDriverChange() { DriverDefInfo driverDef = driverDefMap.get(mainPanel.getDriver()); driverValid = driverDef != null; if (!driverValid) { mainPanel.setDriverErrorMessage( getMessage(DataSourceManagementConstants.DataSourceDefEditor_DriverRequiredMessage)); dataSourceDef.setDriverUuid(null); } else { mainPanel.clearDriverErrorMessage(); dataSourceDef.setDriverUuid(driverDef.getUuid()); } if (handler != null) { handler.onDriverChange(); } }
private void onNameChange(String newValue, boolean isValid) { dataSourceDef.setName(newValue); nameValid = isValid; if (!nameValid) { mainPanel.setNameErrorMessage( getMessage(DataSourceManagementConstants.DataSourceDefEditor_InvalidNameMessage)); } else { mainPanel.clearNameErrorMessage(); } if (handler != null) { handler.onNameChange(); } }
private void onConnectionURLChange(String newValue, boolean isValid) { dataSourceDef.setConnectionURL(newValue); connectionURLValid = isValid; if (!connectionURLValid) { mainPanel.setConnectionURLErrorMessage( getMessage(DataSourceManagementConstants.DataSourceDefEditor_InvalidConnectionURLMessage)); } else { mainPanel.clearConnectionURLErrorMessage(); } if (handler != null) { handler.onConnectionURLChange(); } }
private void testConnectionURLChange(boolean isValid) { if (isValid) { when(mainPanel.getConnectionURL()).thenReturn(CONNECTION_URL); } else { when(mainPanel.getConnectionURL()).thenReturn(INVALID_CONNECTION_URL); } when(translationService.getTranslation( DataSourceManagementConstants.DataSourceDefEditor_InvalidConnectionURLMessage)).thenReturn(ERROR); //emulates the helper receiving the change event editorHelper.onConnectionURLChange(); if (isValid) { assertTrue(editorHelper.isConnectionURLValid()); assertEquals(CONNECTION_URL, dataSourceDef.getConnectionURL()); verify(mainPanel, times(1)).clearConnectionURLErrorMessage(); } else { assertFalse(editorHelper.isConnectionURLValid()); assertEquals(INVALID_CONNECTION_URL, dataSourceDef.getConnectionURL()); verify(mainPanel, times(1)).setConnectionURLErrorMessage(ERROR); } verify(handler, times(1)).onConnectionURLChange(); }
private void testPasswordChange(boolean isValid) { if (isValid) { when(mainPanel.getPassword()).thenReturn(PASSWORD); } else { when(mainPanel.getPassword()).thenReturn(""); } when(translationService.getTranslation( DataSourceManagementConstants.DataSourceDefEditor_InvalidPasswordMessage)).thenReturn(ERROR); //emulates the helper receiving the change event editorHelper.onPasswordChange(); if (isValid) { assertTrue(editorHelper.isPasswordValid()); assertEquals(PASSWORD, dataSourceDef.getPassword()); verify(mainPanel, times(1)).clearPasswordErrorMessage(); } else { assertFalse(editorHelper.isPasswordValid()); assertEquals("", dataSourceDef.getPassword()); verify(mainPanel, times(1)).setPasswordErrorMessage(ERROR); } verify(handler, times(1)).onPasswordChange(); }
private void testUserChange(boolean isValid) { if (isValid) { when(mainPanel.getUser()).thenReturn(USER); } else { when(mainPanel.getUser()).thenReturn(""); } when(translationService.getTranslation( DataSourceManagementConstants.DataSourceDefEditor_InvalidUserMessage)).thenReturn(ERROR); //emulates the helper receiving the change event editorHelper.onUserChange(); if (isValid) { assertTrue(editorHelper.isUserValid()); assertEquals(USER, dataSourceDef.getUser()); verify(mainPanel, times(1)).clearUserErrorMessage(); } else { assertFalse(editorHelper.isUserValid()); assertEquals("", dataSourceDef.getUser()); verify(mainPanel, times(1)).setUserErrorMessage(ERROR); } verify(handler, times(1)).onUserChange(); }
@Override public Collection<DataSourceDefInfo> findGlobalDataSources(boolean includeUnManaged) { Collection<DataSourceDefInfo> result = resolveDataSources(serviceHelper.getGlobalDataSourcesContext()); if (includeUnManaged) { Map<String, DataSourceDefInfo> managedDataSources = new HashMap<>(); for (DataSourceDefInfo dataSourceDefInfo : result) { managedDataSources.put(dataSourceDefInfo.getUuid(), dataSourceDefInfo); } try { List<DataSourceDef> allDeployments = providerFactory.getDataSourceProvider().getDeployments(); DeploymentInfo deploymentInfo; for (DataSourceDef dataSourceDef : allDeployments) { deploymentInfo = runtimeManager.getDataSourceDeploymentInfo(dataSourceDef.getUuid()); if (!managedDataSources.containsKey(dataSourceDef.getUuid()) && (deploymentInfo != null && !deploymentInfo.isManaged())) { result.add(new DataSourceDefInfo(dataSourceDef.getUuid(), dataSourceDef.getName(), runtimeManager.getDataSourceDeploymentInfo(dataSourceDef.getUuid()))); } } } catch (Exception e) { logger.warn("It was not possible to read all deployed data sources. ", e); } } return result; }
public static String generateDeploymentId( final DataSourceDef dataSourceDef ) { return generateDeploymentId( dataSourceDef.getUuid() ); }
@Override protected String getExpectedFileName() { return dataSourceDef.getName() + ".datasource"; }
private void testDriverChange(boolean isValid) { if (isValid) { when(mainPanel.getDriver()).thenReturn(DRIVER_UUID); } else { when(mainPanel.getDriver()).thenReturn(null); } when(translationService.getTranslation( DataSourceManagementConstants.DataSourceDefEditor_DriverRequiredMessage)).thenReturn(ERROR); //emulates the helper receiving the change event editorHelper.onDriverChange(); if (isValid) { assertTrue(editorHelper.isDriverValid()); assertEquals(DRIVER_UUID, dataSourceDef.getDriverUuid()); verify(mainPanel, times(1)).clearDriverErrorMessage(); } else { assertFalse(editorHelper.isDriverValid()); assertNull(dataSourceDef.getDriverUuid()); verify(mainPanel, times(1)).setDriverErrorMessage(ERROR); } verify(handler, times(1)).onDriverChange(); }