Search in sources :

Example 6 with BufferedDataSet

use of com.servoy.j2db.dataprocessing.BufferedDataSet in project servoy-client by Servoy.

the class JSSecurity method js_getUserGroups.

/**
 * Get all the groups for given user UID.
 *
 * @sample
 * //get all the users in the security settings (Returns a JSDataset)
 * var dsUsers = security.getUsers()
 *
 * //loop through each user to get their group
 * //The getValue call is (row,column) where column 1 == id and 2 == name
 * for(var i=1 ; i<=dsUsers.getMaxRowIndex() ; i++)
 * {
 * 	//print to the output debugger tab: "user: " and the username
 * 	application.output("user:" + dsUsers.getValue(i,2));
 *
 * 	//set p to the user group for the current user
 * 	/** @type {JSDataSet} *&#47;
 * 	var p = security.getUserGroups(dsUsers.getValue(i,1));
 *
 * 	for(k=1;k<=p.getMaxRowIndex();k++)
 * 	{
 * 		//print to the output debugger tab: "group" and the group(s)
 * 		//the user belongs to
 * 		application.output("group: " + p.getValue(k,2));
 * 	}
 * }
 *
 * @param userUID to retrieve the user groups
 *
 * @return dataset with groupnames
 */
public JSDataSet js_getUserGroups(Object userUID) throws ServoyException {
    checkAuthorized();
    if (userUID == null)
        return null;
    String n_userUID = normalizeUID(userUID);
    try {
        String[] groups = null;
        if (n_userUID.equals(application.getUserUID())) {
            groups = application.getClientInfo().getUserGroups();
        }
        if (groups == null) {
            groups = application.getUserManager().getUserGroups(application.getClientID(), n_userUID.toString());
        }
        if (groups != null) {
            List rows = new ArrayList();
            for (String element : groups) {
                // fetch the id.
                int groupId = getGroupId(element);
                rows.add(new Object[] { new Integer(groupId), element });
            }
            // $NON-NLS-1$ //$NON-NLS-2$
            return new JSDataSet(application, new BufferedDataSet(new String[] { "group_id", "group_name" }, rows));
        }
    } catch (Exception e) {
        Debug.error(e);
    }
    return new JSDataSet();
}
Also used : BufferedDataSet(com.servoy.j2db.dataprocessing.BufferedDataSet) ArrayList(java.util.ArrayList) JSDataSet(com.servoy.j2db.dataprocessing.JSDataSet) ArrayList(java.util.ArrayList) List(java.util.List) ServoyException(com.servoy.j2db.util.ServoyException) ApplicationException(com.servoy.j2db.ApplicationException) RepositoryException(com.servoy.j2db.persistence.RepositoryException)

Example 7 with BufferedDataSet

use of com.servoy.j2db.dataprocessing.BufferedDataSet in project servoy-client by Servoy.

the class SwingForm method getFormContext.

public JSDataSet getFormContext() {
    SwingForm current = this;
    FormLookupPanel currentLookupPanel = null;
    SpecialTabPanel currentTabPanel = null;
    String currentBeanName = null;
    SpecialSplitPane currentSplitPane = null;
    IDataSet set = new BufferedDataSet(// $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$//$NON-NLS-5$//$NON-NLS-6$
    new String[] { "containername", "formname", "tabpanel/splitpane/accordion/beanname", "tabname", "tabindex", "tabindex1based" }, new ArrayList<Object[]>());
    set.addRow(new Object[] { null, current.formController.getName(), null, null, null, null });
    Container parent = getParent();
    while (parent != null) {
        if (parent instanceof SpecialTabPanel) {
            currentTabPanel = (SpecialTabPanel) parent;
        } else if (parent instanceof SpecialSplitPane) {
            currentSplitPane = (SpecialSplitPane) parent;
        } else if (parent instanceof FormLookupPanel) {
            currentLookupPanel = (FormLookupPanel) parent;
        } else if (parent instanceof IServoyAwareBean && parent instanceof IComponent) {
            currentBeanName = ((IComponent) parent).getName();
        } else if (parent instanceof SwingForm) {
            current = (SwingForm) parent;
            if (currentTabPanel != null) {
                ITabPaneAlike panel = currentTabPanel.getEnclosingComponent();
                int index = -1;
                String tabName = null;
                if (currentLookupPanel != null) {
                    index = panel.getTabIndex(currentLookupPanel);
                    if (index != -1) {
                        tabName = panel.getNameAt(index);
                    }
                }
                set.addRow(0, new Object[] { null, current.formController.getName(), currentTabPanel.getName(), tabName, new Integer(index), new Integer(index + 1) });
            } else if (currentBeanName != null) {
                set.addRow(0, new Object[] { null, current.formController.getName(), currentBeanName, null, null, null });
            } else if (currentSplitPane != null) {
                int idx = currentLookupPanel != null && currentLookupPanel.equals(currentSplitPane.getLeftForm()) ? 0 : 1;
                set.addRow(0, new Object[] { null, current.formController.getName(), currentSplitPane.getName(), currentSplitPane.getTabNameAt(idx), new Integer(idx + 1), new Integer(idx + 1) });
            } else {
                set.addRow(0, new Object[] { null, current.formController.getName(), null, null, null, null });
            }
            currentBeanName = null;
            currentTabPanel = null;
            currentLookupPanel = null;
            currentSplitPane = null;
        } else if (parent instanceof MainPanel) {
            String containerName = ((MainPanel) parent).getContainerName();
            if (containerName != null) {
                for (int i = 0; i < set.getRowCount(); i++) {
                    set.getRow(i)[0] = containerName;
                }
            }
            return new JSDataSet(formController.getApplication(), set);
        }
        parent = parent.getParent();
    }
    return new JSDataSet(formController.getApplication(), set);
}
Also used : IComponent(com.servoy.j2db.ui.IComponent) JSDataSet(com.servoy.j2db.dataprocessing.JSDataSet) ITabPaneAlike(com.servoy.j2db.util.ITabPaneAlike) Point(java.awt.Point) Container(java.awt.Container) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) IServoyAwareBean(com.servoy.j2db.dataui.IServoyAwareBean) BufferedDataSet(com.servoy.j2db.dataprocessing.BufferedDataSet) SpecialSplitPane(com.servoy.j2db.smart.dataui.SpecialSplitPane) SpecialTabPanel(com.servoy.j2db.smart.dataui.SpecialTabPanel) TwoNativeJavaObject(com.servoy.j2db.smart.scripting.TwoNativeJavaObject) NativeJavaObject(org.mozilla.javascript.NativeJavaObject) ScriptableObject(org.mozilla.javascript.ScriptableObject) IDataSet(com.servoy.j2db.dataprocessing.IDataSet) FormLookupPanel(com.servoy.j2db.smart.dataui.FormLookupPanel)

Example 8 with BufferedDataSet

use of com.servoy.j2db.dataprocessing.BufferedDataSet in project servoy-client by Servoy.

the class FoundsetTest method setupData.

@Override
protected void setupData() throws ServoyException {
    BufferedDataSet ds = new BufferedDataSet(new String[] { "pk", "test1", "test2" }, new int[] { IColumnTypes.INTEGER, IColumnTypes.TEXT, IColumnTypes.TEXT });
    ds.addRow(new Object[] { Integer.valueOf(1), "value1", "value2" });
    ds.addRow(new Object[] { Integer.valueOf(2), "value3", "value4" });
    ds.addRow(new Object[] { Integer.valueOf(3), "value1", "value2" });
    ds.addRow(new Object[] { Integer.valueOf(4), "value3", "value4" });
    ds.addRow(new Object[] { Integer.valueOf(5), "value1", "value2" });
    ds.addRow(new Object[] { Integer.valueOf(6), "value3", "value4" });
    ds.addRow(new Object[] { Integer.valueOf(7), "value1", "value2" });
    ds.addRow(new Object[] { Integer.valueOf(8), "value3", "value4" });
    ds.addRow(new Object[] { Integer.valueOf(9), "value1", "value2" });
    ds.addRow(new Object[] { Integer.valueOf(10), "value3", "value4" });
    ds.addRow(new Object[] { Integer.valueOf(11), "value1", "value2" });
    ds.addRow(new Object[] { Integer.valueOf(12), "value3", "value4" });
    ds.addRow(new Object[] { Integer.valueOf(13), "value1", "value2" });
    ds.addRow(new Object[] { Integer.valueOf(14), "value3", "value4" });
    ds.addRow(new Object[] { Integer.valueOf(15), "value1", "value2" });
    ds.addRow(new Object[] { Integer.valueOf(16), "value3", "value4" });
    ds.addRow(new Object[] { Integer.valueOf(17), "value1", "value2" });
    ds.addRow(new Object[] { Integer.valueOf(18), "value3", "value4" });
    client.getFoundSetManager().insertToDataSource("test", ds, null, new WrappedObjectReference<String[]>(new String[] { "pk" }), true, false);
    BufferedDataSet separateDSs = new BufferedDataSet(new String[] { "pk", "test1", "test2" }, new int[] { IColumnTypes.INTEGER, IColumnTypes.TEXT, IColumnTypes.TEXT });
    for (int i = 0; i < 943; i++) {
        separateDSs.addRow(new Object[] { Integer.valueOf(i), "value" + i + "0", "value" + i + "1" });
    }
    client.getFoundSetManager().insertToDataSource("testseparatefoundset", separateDSs, null, new WrappedObjectReference<String[]>(new String[] { "pk" }), true, false);
    BufferedDataSet relatedDS = new BufferedDataSet(new String[] { "relatedtestpk", "testpk", "relatedtest1", "relatedtest2" }, new int[] { IColumnTypes.INTEGER, IColumnTypes.INTEGER, IColumnTypes.TEXT, IColumnTypes.TEXT });
    relatedDS.addRow(new Object[] { Integer.valueOf(1), Integer.valueOf(1), "relatedvalue111", "relatedvalue112" });
    relatedDS.addRow(new Object[] { Integer.valueOf(2), Integer.valueOf(1), "relatedvalue121", "relatedvalue122" });
    relatedDS.addRow(new Object[] { Integer.valueOf(3), Integer.valueOf(1), "relatedvalue131", "relatedvalue132" });
    relatedDS.addRow(new Object[] { Integer.valueOf(4), Integer.valueOf(2), "relatedvalue241", "relatedvalue242" });
    relatedDS.addRow(new Object[] { Integer.valueOf(5), Integer.valueOf(1), "relatedvalue111", "relatedvalue112" });
    relatedDS.addRow(new Object[] { Integer.valueOf(6), Integer.valueOf(1), "relatedvalue121", "relatedvalue122" });
    relatedDS.addRow(new Object[] { Integer.valueOf(7), Integer.valueOf(1), "relatedvalue131", "relatedvalue132" });
    relatedDS.addRow(new Object[] { Integer.valueOf(8), Integer.valueOf(2), "relatedvalue241", "relatedvalue242" });
    relatedDS.addRow(new Object[] { Integer.valueOf(9), Integer.valueOf(1), "relatedvalue111", "relatedvalue112" });
    relatedDS.addRow(new Object[] { Integer.valueOf(10), Integer.valueOf(1), "relatedvalue121", "relatedvalue122" });
    relatedDS.addRow(new Object[] { Integer.valueOf(11), Integer.valueOf(1), "relatedvalue131", "relatedvalue132" });
    relatedDS.addRow(new Object[] { Integer.valueOf(12), Integer.valueOf(2), "relatedvalue241", "relatedvalue242" });
    relatedDS.addRow(new Object[] { Integer.valueOf(13), Integer.valueOf(1), "relatedvalue111", "relatedvalue112" });
    relatedDS.addRow(new Object[] { Integer.valueOf(14), Integer.valueOf(1), "relatedvalue121", "relatedvalue122" });
    relatedDS.addRow(new Object[] { Integer.valueOf(15), Integer.valueOf(1), "relatedvalue131", "relatedvalue132" });
    relatedDS.addRow(new Object[] { Integer.valueOf(16), Integer.valueOf(2), "relatedvalue241", "relatedvalue242" });
    client.getFoundSetManager().insertToDataSource("relatedtest", relatedDS, null, new WrappedObjectReference<String[]>(new String[] { "relatedtestpk" }), true, false);
    ConcurrentHashMap<String, IServer> serverProxies = new ConcurrentHashMap<String, IServer>();
    serverProxies.put("_sv_inmem", DUMMY_ISERVER);
    solution.setServerProxies(serverProxies);
    Relation relation = solution.createNewRelation(validator, "test_to_relatedtest", "mem:test", "mem:relatedtest", LEFT_OUTER_JOIN);
    Column primaryColumn = ((Table) client.getFoundSetManager().getTable(relation.getPrimaryDataSource())).getColumn("pk");
    Column foreignColumn = ((Table) client.getFoundSetManager().getTable(relation.getForeignDataSource())).getColumn("testpk");
    relation.createNewRelationItem(client.getFoundSetManager(), primaryColumn, IBaseSQLCondition.EQUALS_OPERATOR, foreignColumn);
}
Also used : IServer(com.servoy.j2db.persistence.IServer) Relation(com.servoy.j2db.persistence.Relation) Table(com.servoy.j2db.persistence.Table) BufferedDataSet(com.servoy.j2db.dataprocessing.BufferedDataSet) Column(com.servoy.j2db.persistence.Column) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 9 with BufferedDataSet

use of com.servoy.j2db.dataprocessing.BufferedDataSet in project servoy-client by Servoy.

the class MediaURLStreamHandler method getBlobLoaderMedia.

public static byte[] getBlobLoaderMedia(IServiceProvider application, String urlQueryPart) throws IOException {
    // cannot work without a solution
    if (application.getSolution() == null)
        return null;
    String datasource = null;
    String serverName = null;
    String tableName = null;
    try {
        if (urlQueryPart == null)
            return null;
        String dataProvider = null;
        List<String> pks = new SafeArrayList<String>();
        // $NON-NLS-1$
        StringTokenizer tk = new StringTokenizer(urlQueryPart, "?&");
        while (tk.hasMoreTokens()) {
            String token = tk.nextToken();
            if (// $NON-NLS-1$
            token.startsWith("global=")) {
                // $NON-NLS-1$
                String globalName = token.substring("global=".length());
                Object obj = application.getScriptEngine().getScopesScope().get(null, globalName);
                if (obj instanceof byte[]) {
                    return (byte[]) obj;
                }
                if (obj instanceof String) {
                    // TODO check can we always just convert to the default encoding of this machine (server if web)
                    return ((String) obj).getBytes();
                }
                return null;
            }
            if (// $NON-NLS-1$
            token.startsWith("servername=")) {
                // $NON-NLS-1$
                serverName = token.substring("servername=".length());
            } else if (// $NON-NLS-1$
            token.startsWith("tablename=")) {
                // $NON-NLS-1$
                tableName = token.substring("tablename=".length());
            } else if (// $NON-NLS-1$
            token.startsWith("datasource=")) {
                // $NON-NLS-1$
                datasource = token.substring("datasource=".length());
            } else if (// $NON-NLS-1$
            token.startsWith("dataprovider=")) {
                // $NON-NLS-1$
                dataProvider = token.substring("dataprovider=".length());
            } else if (// $NON-NLS-1$
            token.startsWith("rowid")) {
                // get id
                int index = Utils.getAsInteger(token.substring(5, 6));
                if (index > 0) {
                    // get value after 'rowidX='
                    pks.add(index - 1, token.substring(7));
                } else {
                    // get value after 'rowid='
                    pks.add(0, token.substring(6));
                }
            }
        }
        if (datasource == null && serverName != null && tableName != null) {
            datasource = DataSourceUtils.createDBTableDataSource(serverName, tableName);
        }
        if (application.getFoundSetManager().getTable(datasource) == null) {
            // $NON-NLS-1$
            throw new IOException(Messages.getString("servoy.exception.serverAndTableNotFound", DataSourceUtils.getDBServernameTablename(datasource)));
        }
        FoundSet fs = (FoundSet) application.getFoundSetManager().getNewFoundSet(datasource);
        // use mutable list here, elements are overwritten with Column.getAsRightType equivalent
        List<Object[]> rows = new ArrayList<Object[]>(1);
        rows.add(pks.toArray());
        if (!fs.loadExternalPKList(new BufferedDataSet(null, null, rows))) {
            return null;
        }
        IRecordInternal rec = fs.getRecord(0);
        if (rec == null) {
            return null;
        }
        Object blob_value = rec.getValue(dataProvider);
        if (blob_value instanceof byte[]) {
            return (byte[]) blob_value;
        }
        if (blob_value instanceof String) {
            // TODO check can we always just convert to the default encoding of this machine (server if web)
            return ((String) blob_value).getBytes();
        }
    } catch (Exception e) {
        throw new IOException(e.getMessage());
    }
    return null;
}
Also used : IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) ArrayList(java.util.ArrayList) SafeArrayList(com.servoy.j2db.util.SafeArrayList) SafeArrayList(com.servoy.j2db.util.SafeArrayList) FoundSet(com.servoy.j2db.dataprocessing.FoundSet) IOException(java.io.IOException) IOException(java.io.IOException) StringTokenizer(java.util.StringTokenizer) BufferedDataSet(com.servoy.j2db.dataprocessing.BufferedDataSet)

Example 10 with BufferedDataSet

use of com.servoy.j2db.dataprocessing.BufferedDataSet in project servoy-client by Servoy.

the class WebForm method getFormContext.

public JSDataSet getFormContext() {
    WebForm current = this;
    ITabPanel currentTabPanel = null;
    String currentBeanName = null;
    WebSplitPane currentSplitPane = null;
    IDataSet set = new BufferedDataSet(// $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$//$NON-NLS-5$//$NON-NLS-6$
    new String[] { "containername", "formname", "tabpanel/splitpane/accordion/beanname", "tabname", "tabindex", "tabindex1based" }, new ArrayList<Object[]>());
    set.addRow(new Object[] { null, current.formController.getName(), null, null, null, null });
    MarkupContainer parent = getParent();
    while (parent != null) {
        if (parent instanceof WebSplitPane) {
            currentSplitPane = (WebSplitPane) parent;
        } else if (parent instanceof ITabPanel) {
            currentTabPanel = (ITabPanel) parent;
        } else if (parent instanceof IServoyAwareBean && parent instanceof IComponent) {
            currentBeanName = ((IComponent) parent).getName();
        } else if (parent instanceof WebForm) {
            if (currentTabPanel != null) {
                int index = -1;
                String tabName = null;
                if (currentTabPanel instanceof WebTabPanel) {
                    index = ((WebTabPanel) currentTabPanel).getTabIndex(current);
                } else if (currentTabPanel instanceof WebAccordionPanel) {
                    index = ((WebAccordionPanel) currentTabPanel).getTabIndex(current);
                }
                if (index != -1) {
                    // js method so +1
                    tabName = currentTabPanel.getTabNameAt(index);
                }
                current = (WebForm) parent;
                set.addRow(0, new Object[] { null, current.formController.getName(), currentTabPanel.getName(), tabName, new Integer(index), new Integer(index + 1) });
            } else if (currentBeanName != null) {
                current = (WebForm) parent;
                set.addRow(0, new Object[] { null, current.formController.getName(), currentBeanName, null, null, null });
            } else if (currentSplitPane != null) {
                int idx = currentSplitPane.getLeftForm() != null && current.equals(((WebTabFormLookup) currentSplitPane.getLeftForm()).getWebForm()) ? 0 : 1;
                current = (WebForm) parent;
                set.addRow(0, new Object[] { null, current.formController.getName(), currentSplitPane.getName(), currentSplitPane.getTabNameAt(idx), new Integer(idx + 1), new Integer(idx + 1) });
            }
            current = (WebForm) parent;
            currentTabPanel = null;
            currentBeanName = null;
            currentSplitPane = null;
        } else if (parent instanceof MainPage) {
            String containerName = ((MainPage) parent).getContainerName();
            if (containerName != null) {
                for (int i = 0; i < set.getRowCount(); i++) {
                    set.getRow(i)[0] = containerName;
                }
            }
            return new JSDataSet(formController.getApplication(), set);
        }
        parent = parent.getParent();
    }
    return new JSDataSet(formController.getApplication(), set);
}
Also used : MarkupContainer(org.apache.wicket.MarkupContainer) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) IComponent(com.servoy.j2db.ui.IComponent) JSDataSet(com.servoy.j2db.dataprocessing.JSDataSet) ITabPanel(com.servoy.j2db.ui.ITabPanel) WebTabFormLookup(com.servoy.j2db.server.headlessclient.dataui.WebTabFormLookup) WebSplitPane(com.servoy.j2db.server.headlessclient.dataui.WebSplitPane) Point(java.awt.Point) IServoyAwareBean(com.servoy.j2db.dataui.IServoyAwareBean) BufferedDataSet(com.servoy.j2db.dataprocessing.BufferedDataSet) WebAccordionPanel(com.servoy.j2db.server.headlessclient.dataui.WebAccordionPanel) WebTabPanel(com.servoy.j2db.server.headlessclient.dataui.WebTabPanel) NativeJavaObject(org.mozilla.javascript.NativeJavaObject) ScriptableObject(org.mozilla.javascript.ScriptableObject) IDataSet(com.servoy.j2db.dataprocessing.IDataSet)

Aggregations

BufferedDataSet (com.servoy.j2db.dataprocessing.BufferedDataSet)11 JSDataSet (com.servoy.j2db.dataprocessing.JSDataSet)7 IDataSet (com.servoy.j2db.dataprocessing.IDataSet)5 ArrayList (java.util.ArrayList)5 Point (java.awt.Point)3 IServoyAwareBean (com.servoy.j2db.dataui.IServoyAwareBean)2 Column (com.servoy.j2db.persistence.Column)2 IServer (com.servoy.j2db.persistence.IServer)2 Table (com.servoy.j2db.persistence.Table)2 IComponent (com.servoy.j2db.ui.IComponent)2 SafeArrayList (com.servoy.j2db.util.SafeArrayList)2 List (java.util.List)2 Locale (java.util.Locale)2 Map (java.util.Map)2 Entry (java.util.Map.Entry)2 TreeMap (java.util.TreeMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)2 NativeJavaObject (org.mozilla.javascript.NativeJavaObject)2 ScriptableObject (org.mozilla.javascript.ScriptableObject)2