use of com.servoy.j2db.dataprocessing.IDataSet in project servoy-client by Servoy.
the class Messages method fillLocaleMessages.
private static void fillLocaleMessages(String clientId, IDataServer dataServer, Table table, String serverName, Column filterColumn, Object columnValueFilter, String searchKey, String searchText, Locale language, Properties properties, int loadingType, IFoundSetManagerInternal fm) throws ServoyException, RemoteException {
QueryTable messagesTable = new QueryTable(table.getSQLName(), table.getDataSource(), table.getCatalog(), table.getSchema());
QuerySelect sql = new QuerySelect(messagesTable);
// $NON-NLS-1$
QueryColumn msgKey = new QueryColumn(messagesTable, -1, "message_key", Types.VARCHAR, 150, 0, null, 0);
// $NON-NLS-1$
QueryColumn msgVal = new QueryColumn(messagesTable, -1, "message_value", Types.VARCHAR, 2000, 0, null, 0);
// $NON-NLS-1$
QueryColumn msgLang = new QueryColumn(messagesTable, -1, "message_language", Types.VARCHAR, 150, 0, null, 0);
sql.addColumn(msgKey);
sql.addColumn(msgVal);
// $NON-NLS-1$
String condMessages = "MESSAGES";
String langValue = (loadingType == SPECIFIED_LOCALE) ? localeToString(language) : language.getLanguage();
// default
sql.addCondition(condMessages, new CompareCondition(IBaseSQLCondition.EQUALS_OPERATOR, msgLang, new QueryColumnValue(langValue, null)));
if (filterColumn != null) {
CompareCondition cc = new CompareCondition(IBaseSQLCondition.EQUALS_OPERATOR, filterColumn.queryColumn(messagesTable), new QueryColumnValue(columnValueFilter, null));
sql.addCondition(condMessages, cc);
}
// Filter to only include records with the default (null) value for columns flagged as Tenant column
for (Column column : table.getTenantColumns()) {
CompareCondition cc = new CompareCondition(IBaseSQLCondition.ISNULL_OPERATOR, column.queryColumn(messagesTable), null);
sql.addCondition("_svy_tenant_id_filter_" + column.getName(), cc);
}
if (searchKey != null || searchText != null) {
QueryTable subselectTable = new QueryTable(table.getSQLName(), table.getDataSource(), table.getCatalog(), table.getSchema());
QuerySelect subselect = new QuerySelect(subselectTable);
// $NON-NLS-1$
QueryColumn msgKeySub = new QueryColumn(subselectTable, -1, "message_key", Types.VARCHAR, 150, 0, null, 0);
// $NON-NLS-1$
QueryColumn msgValueSub = new QueryColumn(subselectTable, -1, "message_value", Types.VARCHAR, 2000, 0, null, 0);
// $NON-NLS-1$
QueryColumn msgLangSub = new QueryColumn(subselectTable, -1, "message_language", Types.VARCHAR, 150, 0, null, 0);
subselect.addColumn(msgKeySub);
// $NON-NLS-1$
String condSearch = "SEARCH";
if (searchKey != null) {
subselect.addCondition(condSearch, new CompareCondition(IBaseSQLCondition.LIKE_OPERATOR, msgKeySub, new QueryColumnValue('%' + searchKey + '%', null)));
}
if (searchText != null) {
subselect.addConditionOr(condSearch, new CompareCondition(IBaseSQLCondition.LIKE_OPERATOR, msgValueSub, new QueryColumnValue('%' + searchText + '%', null)));
}
sql.addCondition(condMessages, new SetCondition(IBaseSQLCondition.EQUALS_OPERATOR, new QueryColumn[] { msgKey }, subselect, true));
}
// $NON-NLS-1$
if (Debug.tracing())
Debug.trace("Loading messages from DB: SQL: " + sql);
IDataSet set = dataServer.performQuery(clientId, serverName, null, sql, null, fm != null ? fm.getTableFilterParams(serverName, sql) : null, false, 0, Integer.MAX_VALUE, IDataServer.MESSAGES_QUERY);
for (int i = 0; i < set.getRowCount(); i++) {
Object[] row = set.getRow(i);
if (// $NON-NLS-1$
row[1] != null && !"".equals(row[1])) {
properties.setProperty((String) row[0], (String) row[1]);
}
}
}
use of com.servoy.j2db.dataprocessing.IDataSet in project servoy-client by Servoy.
the class JSSecurity method js_login.
/**
* Login to be able to leave the solution loginForm.
*
* Example: Group names may be received from LDAP (Lightweight Directory Access Protocol) - a standard protocol used in web browsers and email applications to enable lookup queries that access a directory listing.
*
* @sample
* var groups = ['Administrators']; //normally these groups are for example received from LDAP
* var user_uid = scopes.globals.email; //also this uid might be received from external authentication method
* var ok = security.login(scopes.globals.username, user_uid , groups)
* if (!ok)
* {
* plugins.dialogs.showErrorDialog('Login failure', 'Already logged in? or no user_uid/groups specified?', 'OK')
* }
*
* @param username the username, like 'JamesWebb'
* @param a_userUID the user UID to process login for
* @param groups the groups array
* @return true if loggedin
*/
public boolean js_login(String username, Object a_userUID, String[] groups) {
if (application.getUserManager() == null) {
// cannot login locally in client because client has to be authenticated at the server first
return false;
}
String userUID = normalizeUID(a_userUID);
if (groups == null || groups.length == 0 || username == null || username.length() == 0 || userUID == null || userUID.length() == 0)
return false;
// check if the groups all exist
IDataSet groupsDataSet;
try {
groupsDataSet = application.getUserManager().getGroups(application.getClientID());
} catch (Exception e) {
Debug.error(e);
return false;
}
for (String group : groups) {
int i;
for (i = 0; i < groupsDataSet.getRowCount() && !groupsDataSet.getRow(i)[1].equals(group); i++) {
}
if (i == groupsDataSet.getRowCount()) {
// $NON-NLS-1$//$NON-NLS-2$
Debug.log("Could not log in user for unknown group '" + group + "'");
return false;
}
}
ClientInfo ci = application.getClientInfo();
if (ci.getUserUid() != null && !ci.getUserUid().equalsIgnoreCase(userUID)) {
// already logged in
return false;
}
ci.setUserName(username);
ci.setUserUid(userUID);
ci.setUserGroups(groups);
if (application.getSolution().getSolutionType() != SolutionMetaData.AUTHENTICATOR) {
application.clearLoginForm();
}
return true;
}
use of com.servoy.j2db.dataprocessing.IDataSet in project servoy-client by Servoy.
the class WebFormUI method getFormContext.
@Override
public JSDataSet getFormContext() {
IDataSet set = new // $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$//$NON-NLS-5$//$NON-NLS-6$
BufferedDataSet(// $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$//$NON-NLS-5$//$NON-NLS-6$
new String[] { "windowname", "formname", "containername", "tabname", "tabindex", "tabindex1based" }, new ArrayList<Object[]>());
set.addRow(new Object[] { null, formController.getName(), null, null, null, null });
Object currentContainer = parentContainerOrWindowName;
WebFormUI currentForm = this;
while (currentContainer instanceof WebFormComponent) {
WebFormComponent currentComponent = (WebFormComponent) currentContainer;
int index = currentComponent.getFormIndex(currentForm);
currentForm = currentComponent.findParent(WebFormUI.class);
if (currentForm != null) {
set.addRow(0, new Object[] { null, currentForm.formController.getName(), currentComponent.getName(), null, new Integer(index), new Integer(index + 1) });
currentContainer = currentForm.getParentContainer();
} else {
currentContainer = null;
}
}
if (currentContainer instanceof String) {
// fill in window name
for (int i = 0; i < set.getRowCount(); i++) {
set.getRow(i)[0] = currentContainer;
}
}
return new JSDataSet(formController.getApplication(), set);
}
use of com.servoy.j2db.dataprocessing.IDataSet in project servoy-client by Servoy.
the class TestNGClient method createDataServer.
@Override
protected IDataServer createDataServer() {
return new IDataServer() {
private final HashMap<String, IDataSet> dataSetMap = new HashMap<String, IDataSet>();
@Override
public void setServerMaintenanceMode(boolean maintenanceMode) throws RemoteException {
}
@Override
public void logMessage(String msg) throws RemoteException {
}
@Override
public boolean isInServerMaintenanceMode() throws RemoteException {
return false;
}
@Override
public boolean releaseLocks(String client_id, String server_name, String table_name, Set<Object> pkhashkeys) throws RemoteException, RepositoryException {
return false;
}
@Override
public IDataSet acquireLocks(String client_id, String server_name, String table_name, Set<Object> pkhashkeys, QuerySelect lockSelect, String transaction_id, ArrayList<TableFilter> filters, int chunkSize) throws RemoteException, RepositoryException {
return null;
}
@Override
public String startTransaction(String clientId, String server_name) throws RepositoryException, RemoteException {
return null;
}
@Override
public Object[] performUpdates(String clientId, ISQLStatement[] statements) throws ServoyException, RemoteException {
return statements;
}
@Override
public IDataSet[] performQuery(String client_id, String server_name, String transaction_id, QueryData[] array) throws ServoyException, RemoteException {
if (array.length > 0) {
String ds = array[0].getSqlSelect().getTable().getDataSource();
if ("mem:relatedtest".equals(ds)) {
IDataSet set = dataSetMap.get(ds);
IDataSet[] returnDataSet = new IDataSet[array.length];
for (int i = 0; i < array.length; i++) {
returnDataSet[i] = new BufferedDataSet();
for (int k = 0; k < set.getRowCount(); k++) {
Object[][] value = (Object[][]) ((Placeholder) ((SetCondition) ((QuerySelect) array[i].getSqlSelect()).getConditions().values().iterator().next().getConditions().get(0)).getValues()).getValue();
if (set.getRow(k)[1].equals(value[0][0])) {
returnDataSet[i].addRow(new Object[] { set.getRow(k)[0], set.getRow(k)[1], set.getRow(k)[2], set.getRow(k)[3] });
}
}
}
return returnDataSet;
}
}
return null;
}
@Override
public IDataSet performQuery(String client_id, String server_name, String driverTableName, String transaction_id, String sql, Object[] questiondata, int startRow, int rowsToRetrieve, boolean updateIdleTimestamp) throws ServoyException, RemoteException {
// don't know the
return dataSetMap.values().iterator().next();
// datasource,
// just return
// the first
// dataset
}
@Override
public IDataSet performQuery(String client_id, String server_name, String transaction_id, ISQLSelect sqlSelect, ColumnType[] resultTypes, ArrayList<TableFilter> filters, boolean distinctInMemory, int startRow, int rowsToRetrieve, boolean updateIdleTimestamp) throws ServoyException, RemoteException {
return dataSetMap.get(sqlSelect.getTable().getDataSource());
}
@Override
public IDataSet performQuery(String client_id, String server_name, String driverTableName, String transaction_id, String sql, Object[] questiondata, int startRow, int rowsToRetrieve, int type) throws ServoyException, RemoteException {
// don't know the
return dataSetMap.values().iterator().next();
// datasource,
// just return
// the first
// dataset
}
@Override
public IDataSet performQuery(String client_id, String server_name, String transaction_id, ISQLSelect sqlSelect, ColumnType[] resultTypes, ArrayList<TableFilter> filters, boolean distinctInMemory, int startRow, int rowsToRetrieve, int type, ITrackingSQLStatement trackingInfo) throws ServoyException, RemoteException {
return dataSetMap.get(sqlSelect.getTable().getDataSource());
}
@Override
public IDataSet performQuery(String client_id, String server_name, String transaction_id, ISQLSelect sqlSelect, ColumnType[] resultTypes, ArrayList<TableFilter> filters, boolean distinctInMemory, int startRow, int rowsToRetrieve, int type) throws ServoyException, RemoteException {
IDataSet set = dataSetMap.get(sqlSelect.getTable().getDataSource());
if (sqlSelect instanceof QuerySelect && ((QuerySelect) sqlSelect).getColumns().size() == 1) {
// pk select
int lastRow = Math.min(set.getRowCount(), startRow + rowsToRetrieve);
BufferedDataSet ds = BufferedDataSetInternal.createBufferedDataSet(null, null, new SafeArrayList<Object[]>(0), lastRow < set.getRowCount());
for (int i = startRow; i < lastRow; i++) {
ds.addRow(new Object[] { set.getRow(i)[0] });
}
return ds;
}
return set;
}
@Override
public IDataSet performQuery(String client_id, String server_name, String driverTableName, String transaction_id, String sql, Object[] questiondata, int startRow, int rowsToRetrieve) throws ServoyException, RemoteException {
// don't know the
return dataSetMap.values().iterator().next();
// datasource,
// just return
// the first
// dataset
}
@Override
public IDataSet performQuery(String client_id, String server_name, String transaction_id, ISQLSelect sqlSelect, ColumnType[] resultTypes, ArrayList<TableFilter> filters, boolean distinctInMemory, int startRow, int rowsToRetrieve) throws ServoyException, RemoteException {
return dataSetMap.get(sqlSelect.getTable().getDataSource());
}
@Override
public IDataSet performCustomQuery(String client_id, String server_name, String driverTableName, String transaction_id, ISQLSelect sqlSelect, ArrayList<TableFilter> filters, int startRow, int rowsToRetrieve) throws ServoyException, RemoteException {
return dataSetMap.get(sqlSelect.getTable().getDataSource());
}
@Override
public boolean notifyDataChange(String client_id, String server_name, String tableName, IDataSet pks, int action, String transaction_id) throws RemoteException {
return false;
}
@Override
public ITable insertQueryResult(String client_id, String queryServerName, String queryTid, ISQLSelect sqlSelect, ArrayList<TableFilter> filters, boolean distinctInMemory, int startRow, int rowsToRetrieve, int type, String dataSource, String targetServerName, String targetTableName, String targetTid, ColumnType[] columnTypes, String[] pkNames) throws ServoyException, RemoteException {
return null;
}
@Override
public InsertResult insertDataSet(String client_id, IDataSet set, final String dataSource, String serverName, String tableName, String tid, ColumnType[] columnTypes, String[] pkNames, HashMap<String, ColumnInfoDef> columnInfoDefinitions) throws ServoyException, RemoteException {
dataSetMap.put(dataSource, set);
Table table = new Table(serverName, serverName, true, ITable.TABLE, null, null);
table.setDataSource(dataSource);
for (int i = 0; i < set.getColumnCount(); i++) {
Column col = new Column(table, set.getColumnNames()[i], set.getColumnTypes()[i], 50, 50, true);
table.addColumn(col);
if (Arrays.binarySearch(pkNames, col.getName()) >= 0) {
col.setDatabasePK(true);
}
}
return new InsertResult(table, new Object[0]);
}
@Override
public QuerySet getSQLQuerySet(String serverName, ISQLQuery sqlQuery, ArrayList<TableFilter> filters, int startRow, int rowsToRetrieve, boolean forceQualifyColumns, boolean disableUseArrayForIn) throws RepositoryException, RemoteException {
QuerySet qs = new QuerySet();
qs.setSelect(new QueryString("select from test", false));
return qs;
}
@Override
public Object getNextSequence(String serverName, String tableName, String columnName, int columnInfoID, String columnInfoServer) throws RepositoryException, RemoteException {
return null;
}
@Override
public Blob getBlob(String clientId, String serverName, ISQLSelect blobSelect, ArrayList<TableFilter> filters, String tid) throws RepositoryException, RemoteException {
return null;
}
@Override
public boolean endTransactions(String client_id, String[] transaction_id, boolean commit) throws RepositoryException, RemoteException {
return false;
}
@Override
public void dropTemporaryTable(String client_id, String serverName, String tableName) throws RemoteException, RepositoryException {
}
@Override
public ISQLStatement createSQLStatement(int action, String server_name, String tableName, Object[] pkColumnData, String tid, ISQLUpdate sqlUpdate, ArrayList<TableFilter> filters) throws RemoteException {
return null;
}
@Override
public ISQLStatement createSQLStatement(int action, String server_name, String tableName, Object[] pkColumnData, String tid, String sql, Object[] questiondata) throws RemoteException, RepositoryException {
return null;
}
@Override
public void addClientAsTableUser(String client_id, String serverName, String tableName) throws RemoteException, RepositoryException {
}
@Override
public IDataSet[] executeProcedure(String clientId, String server_name, String tid, Procedure procedure, Object[] arguments) throws RepositoryException, RemoteException {
return null;
}
};
}
use of com.servoy.j2db.dataprocessing.IDataSet in project servoy-client by Servoy.
the class I18NUtil method loadSortedMessagesFromRepository.
public static TreeMap<String, MessageEntry> loadSortedMessagesFromRepository(IRepository repository, IDataServer dataServer, String clientID, String i18NServerName, String i18NTableName, String filterName, String[] filterValue, IFoundSetManagerInternal fm) throws Exception {
TreeMap<String, MessageEntry> sortedMessages = new TreeMap<String, MessageEntry>();
IServer i18NServer = repository.getServer(i18NServerName);
if (i18NServer != null) {
Table i18NTable = (Table) i18NServer.getTable(i18NTableName);
if (i18NTable != null) {
QueryTable messagesTable = new QueryTable(i18NTable.getSQLName(), i18NTable.getDataSource(), i18NTable.getCatalog(), i18NTable.getSchema());
QuerySelect sql = new QuerySelect(messagesTable);
QueryColumn msgLang = new QueryColumn(messagesTable, -1, "message_language", Types.VARCHAR, 150, 0, null, 0);
QueryColumn msgKey = new QueryColumn(messagesTable, -1, "message_key", Types.VARCHAR, 150, 0, null, 0);
QueryColumn msgVal = new QueryColumn(messagesTable, -1, "message_value", Types.VARCHAR, 2000, 0, null, 0);
sql.addColumn(msgLang);
sql.addColumn(msgKey);
sql.addColumn(msgVal);
// Filter to only include records with the default (null) value for columns flagged as Tenant column
for (Column column : i18NTable.getTenantColumns()) {
QueryColumn tenantColumn = new QueryColumn(messagesTable, column.getID(), column.getSQLName(), column.getType(), column.getLength(), column.getScale(), null, column.getFlags());
CompareCondition cc = new CompareCondition(IBaseSQLCondition.ISNULL_OPERATOR, tenantColumn, null);
sql.addCondition("_svy_tenant_id_filter_" + column.getName(), cc);
}
if (filterName != null) {
Column filterColumn = i18NTable.getColumn(filterName);
if (filterColumn != null && filterValue != null && filterValue.length > 0) {
QueryColumn columnFilter = new QueryColumn(messagesTable, filterColumn.getID(), filterColumn.getSQLName(), filterColumn.getType(), filterColumn.getLength(), filterColumn.getScale(), null, filterColumn.getFlags());
CompareCondition cc = new CompareCondition(IBaseSQLCondition.EQUALS_OPERATOR, columnFilter, new QueryColumnValue(filterValue[0], null));
// $NON-NLS-1$
sql.addCondition("FILTER", cc);
}
}
sql.addSort(new QuerySort(msgLang, true, SortOptions.NONE));
sql.addSort(new QuerySort(msgKey, true, SortOptions.NONE));
IDataSet set = dataServer.performQuery(clientID, i18NServerName, null, sql, null, fm != null ? fm.getTableFilterParams(i18NServerName, sql) : null, false, 0, Integer.MAX_VALUE, IDataServer.MESSAGES_QUERY);
int rowCount = set.getRowCount();
if (rowCount > 0) {
for (int i = 0; i < rowCount; i++) {
Object[] row = set.getRow(i);
MessageEntry messageEntry = new MessageEntry((String) row[0], (String) row[1], (String) row[2]);
sortedMessages.put(messageEntry.getLanguageKey(), messageEntry);
}
}
}
}
return sortedMessages;
}
Aggregations