public WriteDataResultImpl(final int writtenRowCount, final int updatesCount, final String datastoreName, final String schemaName, final String tableName) { _writtenRowCount = writtenRowCount; _updatesCount = updatesCount; _schemaName = schemaName; _tableName = tableName; _datastoreName = datastoreName; _datastoreFunc = catalog -> catalog.getDatastore(datastoreName); _errorRowCount = 0; _errorDatastore = null; }
private DatastoreBeanWrapper[] prepareDatastoreWrappers(DatastoreCatalog datastoreCatalog) { final String[] datastoreNames = datastoreCatalog.getDatastoreNames(); final DatastoreBeanWrapper[] beanWrapperArray = new DatastoreBeanWrapper[datastoreNames.length]; for (int i = 0; i < beanWrapperArray.length; i++) { final String datastoreName = datastoreNames[i]; final Datastore datastore = datastoreCatalog.getDatastore(datastoreName); beanWrapperArray[i] = new DatastoreBeanWrapper(datastore); } return beanWrapperArray; } }
/** * Determines if a datastore by a specific name is contained in the * {@link DatastoreCatalog}. * * @param name * @return */ default boolean containsDatastore(final String name) { return getDatastore(name) != null; }
@RequestMapping(method = RequestMethod.GET, produces = "application/json") @ResponseBody public List<Map<String, String>> datastoresFolderJson(@PathVariable("tenant") String tenant) { final TenantContext context = _contextFactory.getContext(tenant); final DatastoreCatalog datastoreCatalog = context.getConfiguration().getDatastoreCatalog(); final String[] names = datastoreCatalog.getDatastoreNames(); final List<Map<String, String>> result = new ArrayList<Map<String, String>>(); for (String name : names) { final Datastore datastore = datastoreCatalog.getDatastore(name); final Map<String, String> map = new LinkedHashMap<String, String>(); map.put("name", name); map.put("description", datastore.getDescription()); map.put("type", datastore.getClass().getSimpleName()); result.add(map); } return result; }
public ComboBoxUpdater(final JDialog parent) { final String datastoreName = (String) _datastoreCombobox.getSelectedItem(); _datastore = _datastoreCatalog.getDatastore(datastoreName); }
private PopupButton createExistingDatastoresButton() { final PopupButton existingDatastoresButton = WidgetFactory.createDefaultPopupButton("Existing datastores", IconUtils.FILE_FOLDER); final JPopupMenu menu = existingDatastoresButton.getMenu(); final String[] datastoreNames = _datastoreCatalog.getDatastoreNames(); for (final String datastoreName : datastoreNames) { final Datastore datastore = _datastoreCatalog.getDatastore(datastoreName); final JMenuItem menuItem = WidgetFactory.createMenuItem(datastoreName, IconUtils.getDatastoreIcon(datastore, IconUtils.ICON_SIZE_MENU_ITEM)); menuItem.addActionListener(e -> _datastoreSelectedListener.datastoreSelected(datastore)); menu.add(menuItem); } return existingDatastoresButton; }
@Override public Datastore getDatastore(final DatastoreCatalog datastoreCatalog) { if (_datastoreFunc == null) { if (_datastoreName == null) { return null; } return datastoreCatalog.getDatastore(_datastoreName); } return _datastoreFunc.apply(datastoreCatalog); }
public MutableDatastoreCatalog(final DatastoreCatalog immutableDelegate, final DomConfigurationWriter configurationWriter, final UserPreferences userPreferences) { _configurationWriter = configurationWriter; _userPreferences = userPreferences; final String[] datastoreNames = immutableDelegate.getDatastoreNames(); for (final String name : datastoreNames) { if (containsDatastore(name)) { // remove any copies of the datastore - the immutable (XML) // version should always win removeDatastore(getDatastore(name), false); } addDatastore(immutableDelegate.getDatastore(name), false); } }
@Override public Datastore getSingleDatastore(final DatastoreCatalog datastoreCatalog) { final String ds = _arguments.getDatastoreName(); return datastoreCatalog.getDatastore(ds); }
public void updateDatastores() { removeAll(); final String[] datastoreNames = _datastoreCatalog.getDatastoreNames(); for (int i = 0; i < datastoreNames.length; i++) { final Datastore datastore = _datastoreCatalog.getDatastore(datastoreNames[i]); final DetailedListItemPanel datastorePanel = new DetailedListItemPanel(IconUtils.getDatastoreIcon(datastore, IconUtils.ICON_SIZE_LARGE), "<html><b>" + datastore.getName() + "</b></html>", DatastorePanel.getDescription(datastore)); datastorePanel.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(final MouseEvent e) { _datastoreSelectListener.datastoreSelected(datastore); } }); add(datastorePanel); } } }
public AnalysisJobBuilder setDatastore(final String datastoreName) { final Datastore datastore = _configuration.getDatastoreCatalog().getDatastore(datastoreName); if (datastore == null) { throw new IllegalArgumentException("No such datastore: " + datastoreName); } return setDatastore(datastore); }
@RolesAllowed(SecurityRoles.TASK_QUERY) @RequestMapping(value = "/{tenant}/datastores/{datastore}.schemas", method = RequestMethod.GET, produces = "application/json") @ResponseBody public Map<String, Object> getSchemas(HttpServletResponse response, @PathVariable("tenant") final String tenant, @PathVariable("datastore") String datastoreName) throws IOException { datastoreName = datastoreName.replaceAll("\\+", " "); final DataCleanerConfiguration configuration = _tenantContextFactory.getContext(tenant).getConfiguration(); final Datastore datastore = configuration.getDatastoreCatalog().getDatastore(datastoreName); if (datastore == null) { response.sendError(HttpServletResponse.SC_NOT_FOUND, "No such datastore: " + datastoreName); return Collections.emptyMap(); } String username = getUsername(); try (final DatastoreConnection connection = datastore.openConnection()) { final DataContext dataContext = connection.getDataContext(); logger.info("Serving schemas in datastore {} to user: {}.", new Object[] { datastoreName, username }); final Map<String, Object> schemas = new HashMap<>(); schemas.put("schemas", createSchemaList(dataContext)); return schemas; } }
@Override public WizardPageController nextPageController(Map<String, List<String>> formParameters) throws DCUserInputException { final String name = formParameters.get("name").get(0); if (StringUtils.isNullOrEmpty(name)) { throw new DCUserInputException("Please provide a datastore name."); } final TenantContext tenantContext = _context.getTenantContext(); final Datastore datastore = tenantContext.getConfiguration().getDatastoreCatalog().getDatastore(name); if (datastore != null) { throw new DCUserInputException("A datastore with the name '" + name + "' already exist."); } final String description = formParameters.get("description").get(0); return nextPageController(name, description); }
private Map<String, Object> getJsonResult(String tenant, String datastoreName, String query, HttpServletResponse response) throws IOException { datastoreName = datastoreName.replaceAll("\\+", " "); final DataCleanerConfiguration configuration = _tenantContextFactory.getContext(tenant).getConfiguration(); final Datastore ds = configuration.getDatastoreCatalog().getDatastore(datastoreName); if (ds == null) { response.sendError(HttpServletResponse.SC_NOT_FOUND, "No such datastore: " + datastoreName); return null; } String username = getUsername(); if (StringUtils.isNullOrEmpty(query)) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No query defined"); return null; } logger.info("Serving query result of datastore {} to user: {}. Query: {}", new Object[] { datastoreName, username, query }); try (final DatastoreConnection con = ds.openConnection()) { final DataContext dataContext = con.getDataContext(); try (final DataSet dataSet = dataContext.executeQuery(query)) { return getJsonResult(dataSet); } } }
@Override public List<WizardIdentifier> getJobWizardIdentifiers(TenantIdentifier tenant, DatastoreIdentifier datastoreIdentifier, String localeString) { final TenantContext tenantContext = _tenantContextFactory.getContext(tenant); final Datastore datastore = tenantContext.getConfiguration().getDatastoreCatalog() .getDatastore(datastoreIdentifier.getName()); final Func<String, Object> sessionFunc = _wizardDao.createSessionFunc(); final Locale locale = getLocale(localeString); final JobWizardContext context = new JobWizardContextImpl(null, tenantContext, datastore, sessionFunc, locale); final List<WizardIdentifier> result = new ArrayList<>(); for (JobWizard jobWizard : _wizardDao.getWizardsOfType(JobWizard.class)) { if (jobWizard.isDatastoreConsumer() && jobWizard.isApplicableTo(context)) { WizardIdentifier wizardIdentifier = createJobWizardIdentifier(jobWizard); result.add(wizardIdentifier); } } return result; }
@Override public SynonymCatalogConnection openConnection(final DataCleanerConfiguration configuration) { final Datastore datastore = configuration.getDatastoreCatalog().getDatastore(_datastoreName); if (datastore == null) { throw new NoSuchDatastoreException(_datastoreName); } final DatastoreConnection datastoreConnection = datastore.openConnection(); if (_loadIntoMemory) { final SimpleSynonymCatalog simpleSynonymCatalog = loadIntoMemory(datastoreConnection); // no need for the connection anymore datastoreConnection.close(); return simpleSynonymCatalog.openConnection(configuration); } return new DatastoreSynonymCatalogConnection(this, datastoreConnection); }
@Override public DictionaryConnection openConnection(final DataCleanerConfiguration configuration) { final Datastore datastore = configuration.getDatastoreCatalog().getDatastore(_datastoreName); if (datastore == null) { throw new NoSuchDatastoreException(_datastoreName); } final DatastoreConnection datastoreConnection = datastore.openConnection(); if (_loadIntoMemory) { final SimpleDictionary simpleDictionary = loadIntoMemory(datastoreConnection); // no need for the connection anymore datastoreConnection.close(); return simpleDictionary.openConnection(configuration); } return new DatastoreDictionaryConnection(this, datastoreConnection); }
/** * A main method that will display the results of a few example number * analyzers. Useful for tweaking the charts and UI. * * @param args */ public static void main(final String[] args) throws Exception { LookAndFeelManager.get().init(); final Injector injector = Guice.createInjector(new DCModuleImpl(VFSUtils.getFileSystemManager().resolveFile("."), null)); // run a small job final AnalysisJobBuilder ajb = injector.getInstance(AnalysisJobBuilder.class); final Datastore ds = injector.getInstance(DatastoreCatalog.class).getDatastore("orderdb"); final DatastoreConnection con = ds.openConnection(); final Table table = con.getSchemaNavigator().convertToTable("PUBLIC.CUSTOMERS"); ajb.setDatastore(ds); ajb.addSourceColumns(table.getNumberColumns()); ajb.addAnalyzer(NumberAnalyzer.class).addInputColumns(ajb.getSourceColumns()); final ResultWindow resultWindow = injector.getInstance(ResultWindow.class); resultWindow.setVisible(true); resultWindow.startAnalysis(); } }
public Column resolveForeignColumn(final DatastoreCatalog datastoreCatalog) { final Datastore datastore = datastoreCatalog.getDatastore(getForeignDatastoreName()); if (datastore == null) { return null; } try (DatastoreConnection connection = datastore.openConnection()) { final DataContext dataContext = connection.getDataContext(); final Schema schema = dataContext.getSchemaByName(getForeignSchemaName()); if (schema == null) { return null; } final Table table = schema.getTableByName(getForeignTableName()); if (table == null) { return null; } return table.getColumnByName(getForeignColumnName()); } } }
@Override public WizardPage startJobWizard(TenantIdentifier tenant, WizardIdentifier wizardIdentifier, DatastoreIdentifier selectedDatastore, String localeString) throws IllegalArgumentException { final JobWizard wizard = instantiateJobWizard(wizardIdentifier); final TenantContext tenantContext = _tenantContextFactory.getContext(tenant); final Datastore datastore; if (selectedDatastore == null) { datastore = null; } else { datastore = tenantContext.getConfiguration().getDatastoreCatalog() .getDatastore(selectedDatastore.getName()); } final Func<String, Object> sessionFunc = _wizardDao.createSessionFunc(); final Locale locale = getLocale(localeString); final JobWizardContext context = new JobWizardContextImpl(wizard, tenantContext, datastore, sessionFunc, locale); final WizardSession session = wizard.start(context); return startSession(session, wizardIdentifier); }