Search in sources :

Example 6 with Solution

use of com.servoy.j2db.persistence.Solution in project servoy-client by Servoy.

the class HeadlessClientFactoryInternal method createImportHookClient.

public static ISessionClient createImportHookClient(final Solution importHookModule, final IXMLImportUserChannel channel) throws Exception {
    final String[] loadException = new String[1];
    // assuming no login and no method args for import hooks
    SessionClient sc = new SessionClient(null, null, null, null, null, importHookModule.getName()) {

        @Override
        protected IActiveSolutionHandler createActiveSolutionHandler() {
            IApplicationServer as = ApplicationServerRegistry.getService(IApplicationServer.class);
            return new LocalActiveSolutionHandler(as, this) {

                @Override
                protected Solution loadSolution(RootObjectMetaData solutionDef) throws RemoteException, RepositoryException {
                    // grab the latest version (-1) not the active one, because the hook was not yet activated.
                    return (Solution) ((IDeveloperRepository) getRepository()).getRootObject(solutionDef.getRootObjectId(), -1);
                }
            };
        }

        @Override
        protected IExecutingEnviroment createScriptEngine() {
            return new ScriptEngine(this) {

                @Override
                public Object executeFunction(Function f, Scriptable scope, Scriptable thisObject, Object[] args, boolean focusEvent, boolean throwException) throws Exception {
                    // always throw exception
                    return super.executeFunction(f, scope, thisObject, args, focusEvent, true);
                }
            };
        }

        @Override
        public void reportError(String msg, Object detail) {
            super.reportError(msg, detail);
            loadException[0] = msg;
            if (detail instanceof JavaScriptException && ((JavaScriptException) detail).getValue() instanceof Scriptable) {
                loadException[0] += " " + Utils.getScriptableString((Scriptable) ((JavaScriptException) detail).getValue());
            }
            if (detail instanceof Exception) {
                loadException[0] += " " + ((Exception) detail).getMessage();
            }
        }
    };
    sc.setUseLoginSolution(false);
    String userName = channel.getImporterUsername();
    if (userName != null) {
        // let the import hook client run with credentials from the logged in user from the admin page.
        sc.getClientInfo().setUserUid(ApplicationServerRegistry.get().getUserManager().getUserUID(sc.getClientID(), userName));
        sc.getClientInfo().setUserName(userName);
    }
    sc.setOutputChannel(channel);
    sc.loadSolution(importHookModule.getName());
    if (loadException[0] != null) {
        sc.shutDown(true);
        throw new RepositoryException(loadException[0]);
    }
    return sc;
}
Also used : RootObjectMetaData(com.servoy.j2db.persistence.RootObjectMetaData) ISessionClient(com.servoy.j2db.ISessionClient) IApplicationServer(com.servoy.j2db.server.shared.IApplicationServer) RepositoryException(com.servoy.j2db.persistence.RepositoryException) LocalActiveSolutionHandler(com.servoy.j2db.LocalActiveSolutionHandler) Scriptable(org.mozilla.javascript.Scriptable) ScriptEngine(com.servoy.j2db.scripting.ScriptEngine) JavaScriptException(org.mozilla.javascript.JavaScriptException) RemoteException(java.rmi.RemoteException) RepositoryException(com.servoy.j2db.persistence.RepositoryException) JavaScriptException(org.mozilla.javascript.JavaScriptException) Function(org.mozilla.javascript.Function) Solution(com.servoy.j2db.persistence.Solution)

Example 7 with Solution

use of com.servoy.j2db.persistence.Solution in project servoy-client by Servoy.

the class AbstractApplication method setI18NMessagesFilter.

public void setI18NMessagesFilter(String columnname, String[] value) {
    Properties properties = new Properties();
    Messages.loadMessagesFromDatabaseInternal(null, getClientInfo().getClientId(), getSettings(), getDataServer(), getRepository(), properties, locale, Messages.ALL_LOCALES, null, null, columnname, value, getFoundSetManager());
    Solution solution = getSolution();
    Messages.loadMessagesFromDatabaseInternal(solution != null ? solution.getI18nDataSource() : null, getClientInfo().getClientId(), getSettings(), getDataServer(), getRepository(), properties, locale, Messages.ALL_LOCALES, null, null, columnname, value, getFoundSetManager());
    synchronized (messages) {
        messages.put(locale, properties);
    }
}
Also used : Properties(java.util.Properties) Solution(com.servoy.j2db.persistence.Solution)

Example 8 with Solution

use of com.servoy.j2db.persistence.Solution in project servoy-client by Servoy.

the class WebClientSession method startSessionClient.

@SuppressWarnings("nls")
public IWebClientApplication startSessionClient(RootObjectMetaData sd, String method, StartupArguments argumentsScope) throws Exception {
    String firstArgument = argumentsScope.getFirstArgument();
    IWebClientApplication webClient = getWebClient();
    if (webClient != null) {
        boolean solutionLoaded = webClient.getSolution() != null;
        if (solutionLoaded && !webClient.closeSolution(false, null)) {
            // not allowed to close solution?
            return webClient;
        }
        if (solutionLoaded && isSignedIn() && !Utils.getAsBoolean(Settings.getInstance().getProperty("servoy.allowSolutionBrowsing", "true")) && !sd.getName().equals(keepCredentialsSolutionName)) {
            webClient.logout(null);
        }
        if (!isSignedIn()) {
            SolutionMetaData smd = (SolutionMetaData) sd;
            IRepository repository = ApplicationServerRegistry.get().getLocalRepository();
            Solution sol = (Solution) repository.getActiveRootObject(smd.getName(), IRepository.SOLUTIONS);
            if (sol.getLoginSolutionName() == null && sol.getLoginFormID() <= 0 && smd.getMustAuthenticate()) {
                // signin first
                throw new RestartResponseAtInterceptPageException(SignIn.class);
            }
        }
        keepCredentialsSolutionName = null;
    }
    if (webClient == null || webClient.isShutDown()) {
        HttpServletRequest req = ((WebRequest) RequestCycle.get().getRequest()).getHttpServletRequest();
        httpSession = req.getSession();
        webClient = createWebClient(req, credentials, method, firstArgument == null ? null : new Object[] { firstArgument, argumentsScope.toJSMap() }, sd.getName());
        webClient.handleArguments(new String[] { sd.getName() }, argumentsScope);
        if (RequestCycle.get() != null) {
            // if this is inside a request cycle set the service provider.
            // will be reset by the detach of the RequestCycle.
            J2DBGlobals.setServiceProvider(webClient);
        }
        setAttribute("servoy_webclient", webClient);
    } else {
        webClient.handleArguments(firstArgument != null ? new String[] { sd.getName(), method, firstArgument } : new String[] { sd.getName(), method }, argumentsScope);
    }
    // fake first load
    webClient.handleClientUserUidChanged(null, "");
    if (webClient.getSolution() != null)
        getSolutionLastModifiedTime(webClient.getSolution());
    else {
        if (webClient.getPreferedSolutionNameToLoadOnInit() != null) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("s", webClient.getPreferedSolutionNameToLoadOnInit());
            map.put("m", webClient.getPreferedSolutionMethodNameToCall());
            if (webClient.getPreferedSolutionMethodArguments() != null && webClient.getPreferedSolutionMethodArguments().length > 0) {
                map.put("a", webClient.getPreferedSolutionMethodArguments()[0]);
            }
            throw new RestartResponseException(SolutionLoader.class, new PageParameters(map));
        }
    }
    return webClient;
}
Also used : HashMap(java.util.HashMap) RestartResponseAtInterceptPageException(org.apache.wicket.RestartResponseAtInterceptPageException) PageParameters(org.apache.wicket.PageParameters) SolutionMetaData(com.servoy.j2db.persistence.SolutionMetaData) HttpServletRequest(javax.servlet.http.HttpServletRequest) WebRequest(org.apache.wicket.protocol.http.WebRequest) RestartResponseException(org.apache.wicket.RestartResponseException) IWebClientApplication(com.servoy.j2db.IWebClientApplication) IRepository(com.servoy.j2db.persistence.IRepository) Solution(com.servoy.j2db.persistence.Solution)

Example 9 with Solution

use of com.servoy.j2db.persistence.Solution in project servoy-client by Servoy.

the class NGClientEntryFilter method getFormScriptReferences.

/**
 * Get form script references, useful for debugging
 * @param fs the flattened solution
 * @return the form script contributions
 */
private Collection<String> getFormScriptReferences(FlattenedSolution fs) {
    List<String> formScripts = new ArrayList<>();
    if (Boolean.valueOf(System.getProperty("servoy.generateformscripts", "false")).booleanValue()) {
        Iterator<Form> it = fs.getForms(false);
        while (it.hasNext()) {
            Form form = it.next();
            Solution sol = (Solution) form.getAncestor(SOLUTIONS);
            formScripts.add("solutions/" + sol.getName() + "/forms/" + form.getName() + ".js");
        }
    }
    return formScripts;
}
Also used : Form(com.servoy.j2db.persistence.Form) ArrayList(java.util.ArrayList) FlattenedSolution(com.servoy.j2db.FlattenedSolution) Solution(com.servoy.j2db.persistence.Solution)

Example 10 with Solution

use of com.servoy.j2db.persistence.Solution in project servoy-client by Servoy.

the class NGFormManager method makeSolutionSettings.

public void makeSolutionSettings(Solution s) {
    Solution solution = s;
    Iterator<Form> e = application.getFlattenedSolution().getForms(true);
    // add all forms first, they may be referred to in the login form
    Form first = application.getFlattenedSolution().getForm(solution.getFirstFormID());
    boolean firstFormCanBeInstantiated = application.getFlattenedSolution().formCanBeInstantiated(first);
    if (!firstFormCanBeInstantiated) {
        Solution[] modules = application.getFlattenedSolution().getModules();
        if (modules != null) {
            for (Solution module : modules) {
                if (module.getFirstFormID() > 0) {
                    first = application.getFlattenedSolution().getForm(module.getFirstFormID());
                    firstFormCanBeInstantiated = application.getFlattenedSolution().formCanBeInstantiated(first);
                    if (firstFormCanBeInstantiated)
                        break;
                }
            }
        }
    }
    while (e.hasNext()) {
        Form form = e.next();
        if (application.getFlattenedSolution().formCanBeInstantiated(form)) {
            if (!firstFormCanBeInstantiated)
                first = form;
            firstFormCanBeInstantiated = true;
        }
        // add anyway, the form may be used in scripting
        addForm(form, form.equals(first));
    }
    if (firstFormCanBeInstantiated) {
        // start in browse mode
        application.getModeManager().setMode(IModeManager.EDIT_MODE);
    }
    boolean showLoginForm = (solution.getLoginFormID() > 0 && solution.getMustAuthenticate() && application.getUserUID() == null);
    if (application.getUserUID() == null) {
        ScriptMethod onBeforeLogin = application.getFlattenedSolution().getScriptMethod(solution.getOnBeforeLoginMethodID());
        if (onBeforeLogin != null) {
            try {
                Object[] paramArray = null;
                Object[] clientArray = ((ClientState) application).getPreferedSolutionMethodArguments();
                if (clientArray != null && clientArray.length > 1) {
                    paramArray = new Object[] { clientArray[1] };
                }
                application.getScriptEngine().getScopesScope().executeGlobalFunction(onBeforeLogin.getScopeName(), onBeforeLogin.getName(), Utils.arrayMerge(paramArray, Utils.parseJSExpressions(solution.getFlattenedMethodArguments("onBeforeLoginMethodID"))), false, false);
            } catch (Exception e1) {
                application.reportError(// $NON-NLS-1$
                Messages.getString("servoy.formManager.error.ExecutingOpenSolutionMethod", new Object[] { onBeforeLogin.getName() }), e1);
            }
        }
    }
    if (solution.getLoginFormID() > 0 && solution.getMustAuthenticate() && application.getUserUID() == null) {
        Form login = application.getFlattenedSolution().getForm(solution.getLoginFormID());
        if (application.getFlattenedSolution().formCanBeInstantiated(login) && loginForm == null) {
            // must set the login form early so its even correct if onload of login form is called
            loginForm = login;
            showFormInMainPanel(login.getName());
            // stop and recall this method from security.login(...)!
            return;
        }
    } else if (showLoginForm) {
        // there was a login in onBeforeLogin, so only second call to makeSolutionSettings should go further
        return;
    }
    IBasicMainContainer currentContainer = getCurrentContainer();
    if (solution.getLoginFormID() > 0 && solution.getMustAuthenticate() && application.getUserUID() != null && loginForm != null) {
        if (currentContainer.getController() != null && loginForm.getName().equals(currentContainer.getController().getForm().getName())) {
            hideFormIfVisible(currentContainer.getController());
            currentContainer.setController(null);
        }
        // clear and continue
        loginForm = null;
    }
    ScriptMethod sm = application.getFlattenedSolution().getScriptMethod(solution.getOnOpenMethodID());
    Object[] solutionOpenMethodArgs = null;
    String preferedSolutionMethodName = ((ClientState) application).getPreferedSolutionMethodNameToCall();
    if (preferedSolutionMethodName == null && ((ClientState) application).getPreferedSolutionMethodArguments() != null) {
        solutionOpenMethodArgs = ((ClientState) application).getPreferedSolutionMethodArguments();
    }
    if (sm != null) {
        try {
            application.getScriptEngine().getScopesScope().executeGlobalFunction(sm.getScopeName(), sm.getName(), Utils.arrayMerge(solutionOpenMethodArgs, Utils.parseJSExpressions(solution.getFlattenedMethodArguments("onOpenMethodID"))), false, false);
            if (application.getSolution() == null)
                return;
        } catch (Exception e1) {
            // $NON-NLS-1$
            application.reportError(Messages.getString("servoy.formManager.error.ExecutingOpenSolutionMethod", new Object[] { sm.getName() }), e1);
        }
    }
    if (first != null && getCurrentForm() == null) {
        // we only set if the solution startup did not yet show a form already
        showFormInMainPanel(first.getName());
    }
    if (preferedSolutionMethodName != null && (application.getFlattenedSolution().isMainSolutionLoaded() || solution.getSolutionType() == SolutionMetaData.LOGIN_SOLUTION)) {
        try {
            Object[] args = ((ClientState) application).getPreferedSolutionMethodArguments();
            Pair<String, String> scope = ScopesUtils.getVariableScope(preferedSolutionMethodName);
            GlobalScope gs = application.getScriptEngine().getScopesScope().getGlobalScope(scope.getLeft());
            if (// make sure the function is found before resetting preferedSolutionMethodName
            gs != null && gs.get(scope.getRight()) instanceof Function) {
                // avoid stack overflows when an execute method URL is used to open the solution, and that method does call JSSecurity login
                ((ClientState) application).resetPreferedSolutionMethodNameToCall();
                Object result = application.getScriptEngine().getScopesScope().executeGlobalFunction(scope.getLeft(), scope.getRight(), args, false, false);
                if (application.getSolution().getSolutionType() == SolutionMetaData.AUTHENTICATOR) {
                    application.getRuntimeProperties().put(IServiceProvider.RT_OPEN_METHOD_RESULT, result);
                }
            } else if (application.getFlattenedSolution().isMainSolutionLoaded()) {
                Debug.error("Preferred method '" + preferedSolutionMethodName + "' not found in " + application.getFlattenedSolution() + ".");
                ((ClientState) application).resetPreferedSolutionMethodNameToCall();
            }
        } catch (Exception e1) {
            // $NON-NLS-1$
            application.reportError(// $NON-NLS-1$
            Messages.getString("servoy.formManager.error.ExecutingOpenSolutionMethod", new Object[] { preferedSolutionMethodName }), e1);
        }
    }
}
Also used : ClientState(com.servoy.j2db.ClientState) GlobalScope(com.servoy.j2db.scripting.GlobalScope) IBasicMainContainer(com.servoy.j2db.IBasicMainContainer) Form(com.servoy.j2db.persistence.Form) FlattenedForm(com.servoy.j2db.persistence.FlattenedForm) Function(org.mozilla.javascript.Function) NativeJavaObject(org.mozilla.javascript.NativeJavaObject) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod) Solution(com.servoy.j2db.persistence.Solution)

Aggregations

Solution (com.servoy.j2db.persistence.Solution)59 FlattenedSolution (com.servoy.j2db.FlattenedSolution)17 Form (com.servoy.j2db.persistence.Form)16 ScriptMethod (com.servoy.j2db.persistence.ScriptMethod)14 RepositoryException (com.servoy.j2db.persistence.RepositoryException)12 ArrayList (java.util.ArrayList)9 RemoteException (java.rmi.RemoteException)8 HashMap (java.util.HashMap)8 FlattenedForm (com.servoy.j2db.persistence.FlattenedForm)7 IPersist (com.servoy.j2db.persistence.IPersist)6 TableNode (com.servoy.j2db.persistence.TableNode)6 ServoyException (com.servoy.j2db.util.ServoyException)6 JSONObject (org.json.JSONObject)6 IFormController (com.servoy.j2db.IFormController)5 Map (java.util.Map)5 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 JavaScriptException (org.mozilla.javascript.JavaScriptException)5 IRepository (com.servoy.j2db.persistence.IRepository)4 List (java.util.List)4 ApplicationException (com.servoy.j2db.ApplicationException)3