Search in sources :

Example 41 with Solution

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

the class FlattenedSolution method updatePersistInSolutionCopy.

public void updatePersistInSolutionCopy(final IPersist persist) {
    if (mainSolution == null && loginFlattenedSolution != null) {
        loginFlattenedSolution.updatePersistInSolutionCopy(persist);
        return;
    }
    if (copySolution == null)
        return;
    IPersist copyPersist = (IPersist) copySolution.acceptVisitor(new IPersistVisitor() {

        public Object visit(IPersist o) {
            if (o.getUUID().equals(persist.getUUID())) {
                return o;
            }
            return IPersistVisitor.CONTINUE_TRAVERSAL;
        }
    });
    if (copyPersist != null) {
        ((AbstractBase) copyPersist).copyPropertiesMap(((AbstractBase) persist).getPropertiesMap(), false);
        ISupportChilds parent = copyPersist.getParent();
        flush(persist);
        if (parent instanceof Form) {
            ((Form) parent).setLastModified(System.currentTimeMillis());
        } else if (copyPersist instanceof Form) {
            ((Form) copyPersist).setLastModified(System.currentTimeMillis());
        }
    } else if (persist.getParent() != null && !(persist.getParent() instanceof Solution)) {
        ISupportChilds copyParent = (ISupportChilds) copySolution.acceptVisitor(new IPersistVisitor() {

            public Object visit(IPersist o) {
                if (o.getUUID().equals(persist.getParent().getUUID())) {
                    return o;
                }
                return IPersistVisitor.CONTINUE_TRAVERSAL;
            }
        });
        if (copyParent != null) {
            if (persist instanceof ICloneable) {
                ((ICloneable) persist).clonePersist((AbstractBase) copyParent);
            } else {
                copyParent.addChild(persist);
            }
            flush(persist);
            if (copyParent instanceof Form) {
                ((Form) copyParent).setLastModified(System.currentTimeMillis());
            }
        }
    }
}
Also used : ICloneable(com.servoy.j2db.persistence.ICloneable) ISupportChilds(com.servoy.j2db.persistence.ISupportChilds) IPersist(com.servoy.j2db.persistence.IPersist) Form(com.servoy.j2db.persistence.Form) FlattenedForm(com.servoy.j2db.persistence.FlattenedForm) AbstractBase(com.servoy.j2db.persistence.AbstractBase) IPersistVisitor(com.servoy.j2db.persistence.IPersistVisitor) JSONObject(org.json.JSONObject) IRootObject(com.servoy.j2db.persistence.IRootObject) Solution(com.servoy.j2db.persistence.Solution)

Example 42 with Solution

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

the class FlattenedSolution method getScopesPerSolution.

private Map<String, Pair<String, IRootObject>> getScopesPerSolution() {
    if (mainSolution == null && loginFlattenedSolution != null) {
        return loginFlattenedSolution.getScopesPerSolution();
    }
    Map<String, Pair<String, IRootObject>> scopes = new HashMap<String, Pair<String, IRootObject>>();
    if (mainSolution != null) {
        for (String scopeName : mainSolution.getScopeNames()) {
            scopes.put(scopeName, new Pair<String, IRootObject>(scopeName, mainSolution));
        }
        if (modules != null) {
            for (Solution s : modules) {
                if (s != mainSolution) {
                    for (String scopeName : s.getScopeNames()) {
                        if (!scopes.containsKey(scopeName)) {
                            // TODO: check if same scope exists with different modules
                            scopes.put(scopeName, new Pair<String, IRootObject>(scopeName, s));
                        }
                    }
                }
            }
        }
    }
    addGlobalsScope(scopes);
    return scopes;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) IRootObject(com.servoy.j2db.persistence.IRootObject) Solution(com.servoy.j2db.persistence.Solution) Pair(com.servoy.j2db.util.Pair)

Example 43 with Solution

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

the class FormManager method makeSolutionSettings.

// initialize this manager for the solution
protected void makeSolutionSettings(Solution s) {
    destroyed = false;
    Solution solution = s;
    boolean isHeadlessClient = application.getApplicationType() == IApplication.HEADLESS_CLIENT;
    Iterator<Form> e = application.getFlattenedSolution().getForms(true);
    // add all forms first, they may be referred to in the login form
    Form first = isHeadlessClient ? null : application.getFlattenedSolution().getForm(solution.getFirstFormID());
    boolean firstFormCanBeInstantiated = application.getFlattenedSolution().formCanBeInstantiated(first);
    while (e.hasNext()) {
        Form form = e.next();
        if (!isHeadlessClient && 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) {
        // hmm no forms
        showSolutionLoading(false);
    } else {
        // 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;
            showSolutionLoading(false);
            showFormInMainPanel(login.getName());
            getMainContainer(null).setComponentVisible(true);
            // 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;
    }
    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);
        }
        if (mainContainer.getController() != null && loginForm.getName().equals(mainContainer.getController().getForm().getName())) {
            hideFormIfVisible(mainContainer.getController());
            mainContainer.setController(null);
        }
        // clear and continue
        loginForm = null;
    }
    ScriptMethod sm = null;
    // $NON-NLS-1$
    int modifiers = Utils.getAsInteger(application.getRuntimeProperties().get("load.solution.modifiers"));
    if ((modifiers & Event.SHIFT_MASK) != Event.SHIFT_MASK) {
        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);
        }
    }
    showSolutionLoading(false);
    if (first != null && currentContainer != null && currentContainer.getController() != null && currentContainer.getController().getName().equals(first.getName())) {
        currentContainer.setController(null);
    }
    // onOpen event might have opened a modal popup with another form
    IMainContainer modalContainer = getModalDialogContainer();
    if (first != null && mainContainer.getController() == null) {
        if (modalContainer != mainContainer) {
            currentContainer.setComponentVisible(true);
            // if we had a modal dialog displayed, it must remain the current container
            setCurrentContainer(modalContainer, null);
            if (currentContainer.getController() == null) {
                showFormInCurrentContainer(first.getName());
            } else {
                // we only set if the solution startup did not yet show a form already
                showFormInMainPanel(first.getName());
            }
        } else {
            // we only set if the solution startup did not yet show a form already
            showFormInMainPanel(first.getName());
        }
    }
    currentContainer.setComponentVisible(true);
    if (preferedSolutionMethodName != null && application.getFlattenedSolution().isMainSolutionLoaded()) {
        try {
            Object[] args = ((ClientState) application).getPreferedSolutionMethodArguments();
            // avoid stack overflows when an execute method URL is used to open the solution, and that method does call JSSecurity login
            ((ClientState) application).resetPreferedSolutionMethodNameToCall();
            Pair<String, String> scope = ScopesUtils.getVariableScope(preferedSolutionMethodName);
            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);
            }
        } catch (Exception e1) {
            // $NON-NLS-1$
            application.reportError(// $NON-NLS-1$
            Messages.getString("servoy.formManager.error.ExecutingOpenSolutionMethod", new Object[] { preferedSolutionMethodName }), e1);
        }
    }
}
Also used : JSForm(com.servoy.j2db.BasicFormController.JSForm) Form(com.servoy.j2db.persistence.Form) FlattenedForm(com.servoy.j2db.persistence.FlattenedForm) NativeJavaObject(org.mozilla.javascript.NativeJavaObject) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod) Solution(com.servoy.j2db.persistence.Solution)

Example 44 with Solution

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

the class PersistIndex method destroy.

public void destroy() {
    Solution[] sols = solutions.toArray(new Solution[solutions.size()]);
    solutions.clear();
    for (Solution solution : sols) {
        solution.getChangeHandler().removeIPersistListener(this);
    }
    uuidToPersist.clear();
    idToPersist.clear();
    nameToPersist.clear();
    datasourceToPersist.clear();
    scopeCacheByName.clear();
}
Also used : Solution(com.servoy.j2db.persistence.Solution)

Example 45 with Solution

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

the class PersistIndex method initDatasourceCache.

protected void initDatasourceCache(String datasource) {
    if ((datasourceToPersist.size() == 0) || (datasource != null && datasourceToPersist.get(datasource) == null)) {
        visit((persist) -> {
            if (persist instanceof TableNode) {
                String tableDs = ((TableNode) persist).getDataSource();
                if (tableDs != null) {
                    ConcurrentMap<Class<? extends IPersist>, ConcurrentMap<String, IPersist>> dsMap = datasourceToPersist.get(tableDs);
                    if (dsMap == null) {
                        dsMap = new ConcurrentHashMap<>(4);
                        dsMap.put(ScriptCalculation.class, new ConcurrentHashMap<String, IPersist>(4));
                        dsMap.put(TableNode.class, new ConcurrentHashMap<String, IPersist>(4));
                        dsMap.put(AggregateVariable.class, new ConcurrentHashMap<String, IPersist>(4));
                        dsMap.put(ScriptMethod.class, new ConcurrentHashMap<String, IPersist>(4));
                        datasourceToPersist.put(tableDs, dsMap);
                    }
                    ConcurrentMap<String, IPersist> tableNodeCache = dsMap.get(TableNode.class);
                    Solution solution = (Solution) ((TableNode) persist).getAncestor(IRepository.SOLUTIONS);
                    tableNodeCache.put(solution.getName(), persist);
                    return IPersistVisitor.CONTINUE_TRAVERSAL;
                }
            } else {
                ISupportChilds parent = persist.getParent();
                if (persist instanceof ScriptCalculation) {
                    if (parent instanceof TableNode) {
                        ConcurrentMap<Class<? extends IPersist>, ConcurrentMap<String, IPersist>> dsMap = datasourceToPersist.get(((TableNode) parent).getDataSource());
                        addInDatasourceCache(dsMap.get(ScriptCalculation.class), persist, datasource);
                    } else {
                        Debug.error("Something wrong with ScriptCalculation " + ((ScriptCalculation) persist).getName() + " should  have table as parent but the parent is: " + parent);
                    }
                } else if (persist instanceof AggregateVariable) {
                    if (parent instanceof TableNode) {
                        ConcurrentMap<Class<? extends IPersist>, ConcurrentMap<String, IPersist>> dsMap = datasourceToPersist.get(((TableNode) parent).getDataSource());
                        addInDatasourceCache(dsMap.get(AggregateVariable.class), persist, datasource);
                    } else {
                        Debug.error("Something wrong with AggregateVariable " + ((ScriptCalculation) persist).getName() + " should  have table as parent but the parent is: " + parent);
                    }
                } else if (persist instanceof ScriptMethod && parent instanceof TableNode) {
                    ConcurrentMap<Class<? extends IPersist>, ConcurrentMap<String, IPersist>> dsMap = datasourceToPersist.get(((TableNode) parent).getDataSource());
                    addInDatasourceCache(dsMap.get(ScriptMethod.class), persist, datasource);
                }
            }
            return persist instanceof Solution ? IPersistVisitor.CONTINUE_TRAVERSAL : IPersistVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
        });
        if (datasource != null && datasourceToPersist.get(datasource) == null) {
            ConcurrentMap<Class<? extends IPersist>, ConcurrentMap<String, IPersist>> dsMap = new ConcurrentHashMap<>(4);
            dsMap.put(ScriptCalculation.class, new ConcurrentHashMap<String, IPersist>(4));
            dsMap.put(TableNode.class, new ConcurrentHashMap<String, IPersist>(4));
            dsMap.put(AggregateVariable.class, new ConcurrentHashMap<String, IPersist>(4));
            dsMap.put(ScriptMethod.class, new ConcurrentHashMap<String, IPersist>(4));
            datasourceToPersist.put(datasource, dsMap);
        }
    }
}
Also used : ISupportChilds(com.servoy.j2db.persistence.ISupportChilds) ConcurrentMap(java.util.concurrent.ConcurrentMap) AggregateVariable(com.servoy.j2db.persistence.AggregateVariable) ScriptCalculation(com.servoy.j2db.persistence.ScriptCalculation) IPersist(com.servoy.j2db.persistence.IPersist) TableNode(com.servoy.j2db.persistence.TableNode) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) 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