Search in sources :

Example 61 with FlattenedSolution

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

the class FormPropertyType method toJSON.

@Override
public JSONWriter toJSON(JSONWriter writer, String key, Object sabloValue, PropertyDescription pd, DataConversion clientConversion, IBrowserConverterContext dataConverterContext) throws JSONException {
    if (key != null) {
        writer.key(key);
    }
    String formName = null;
    if (sabloValue instanceof String) {
        formName = (String) sabloValue;
        if (dataConverterContext != null && dataConverterContext.getWebObject() instanceof IContextProvider) {
            FlattenedSolution flattenedSolution = ((IContextProvider) dataConverterContext.getWebObject()).getDataConverterContext().getApplication().getFlattenedSolution();
            Form form = flattenedSolution.getForm(formName);
            // form name
            if (form == null) {
                form = (Form) flattenedSolution.searchPersist((String) sabloValue);
            }
            if (form != null) {
                formName = form.getName();
            }
        }
    } else if (sabloValue instanceof CharSequence) {
        formName = ((CharSequence) sabloValue).toString();
    } else if (sabloValue instanceof Form) {
        formName = ((Form) sabloValue).getName();
    } else if (sabloValue instanceof FormController) {
        formName = ((FormController) sabloValue).getName();
    } else if (sabloValue instanceof FormScope) {
        formName = ((FormScope) sabloValue).getFormController().getName();
    } else {
        formName = null;
        Debug.error("Cannot handle unknown value for Form type: " + sabloValue);
    }
    writer.value(formName);
    if (CurrentWindow.get() instanceof INGClientWindow) {
        // if this is a web component that triggered it, register to only allow this form for that component
        if (dataConverterContext != null && dataConverterContext.getWebObject() instanceof WebFormComponent)
            ((INGClientWindow) CurrentWindow.get()).registerAllowedForm(formName, ((WebFormComponent) dataConverterContext.getWebObject()).getFormElement());
        else
            // else register it for null then this form is allowed globally (a form in dialog of popup)
            ((INGClientWindow) CurrentWindow.get()).registerAllowedForm(formName, null);
    }
    return writer;
}
Also used : FormController(com.servoy.j2db.FormController) IContextProvider(com.servoy.j2db.server.ngclient.IContextProvider) INGClientWindow(com.servoy.j2db.server.ngclient.INGClientWindow) Form(com.servoy.j2db.persistence.Form) JSForm(com.servoy.j2db.scripting.solutionmodel.JSForm) WebFormComponent(com.servoy.j2db.server.ngclient.WebFormComponent) FlattenedSolution(com.servoy.j2db.FlattenedSolution) FormScope(com.servoy.j2db.scripting.FormScope)

Example 62 with FlattenedSolution

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

the class FormPropertyType method toTemplateJSONValue.

@Override
public JSONWriter toTemplateJSONValue(JSONWriter writer, String key, Object formElementValue, PropertyDescription pd, DataConversion browserConversionMarkers, FormElementContext formElementContext) throws JSONException {
    if (formElementValue == null)
        return writer;
    FlattenedSolution fs = formElementContext.getFlattenedSolution();
    Form form = null;
    if (formElementValue instanceof Integer) {
        form = fs.getForm(((Integer) formElementValue).intValue());
    } else if (formElementValue instanceof String || formElementValue instanceof UUID) {
        form = fs.getForm(formElementValue.toString());
        if (form == null) {
            form = (Form) fs.searchPersist(formElementValue.toString());
        }
    }
    if (form != null) {
        writer.key(key);
        writer.value(form.getName());
        if (CurrentWindow.safeGet() instanceof INGClientWindow) {
            ((INGClientWindow) CurrentWindow.get()).registerAllowedForm(form.getName(), formElementContext.getFormElement());
        }
    }
    return writer;
}
Also used : INGClientWindow(com.servoy.j2db.server.ngclient.INGClientWindow) Form(com.servoy.j2db.persistence.Form) JSForm(com.servoy.j2db.scripting.solutionmodel.JSForm) FlattenedSolution(com.servoy.j2db.FlattenedSolution) UUID(com.servoy.j2db.util.UUID)

Example 63 with FlattenedSolution

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

the class NGClientEntryFilter method doFilter.

@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
    try {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        if ("GET".equalsIgnoreCase(request.getMethod())) {
            if (request.getCharacterEncoding() == null)
                request.setCharacterEncoding("UTF8");
            String uri = request.getRequestURI();
            if (handleShortSolutionRequest(request, response)) {
                return;
            }
            if (handleDeeplink(request, response)) {
                return;
            }
            if (handleRecording(request, response)) {
                return;
            }
            if (uri != null && (uri.endsWith(".html") || uri.endsWith(".js"))) {
                String solutionName = getSolutionNameFromURI(uri);
                if (solutionName != null) {
                    String clientnr = AngularIndexPageWriter.getClientNr(uri, request);
                    INGClientWebsocketSession wsSession = null;
                    HttpSession httpSession = request.getSession(false);
                    if (clientnr != null && httpSession != null) {
                        wsSession = (INGClientWebsocketSession) WebsocketSessionManager.getSession(CLIENT_ENDPOINT, httpSession, Integer.parseInt(clientnr));
                    }
                    FlattenedSolution fs = null;
                    boolean closeFS = false;
                    if (wsSession != null) {
                        fs = wsSession.getClient().getFlattenedSolution();
                    }
                    if (fs == null) {
                        try {
                            closeFS = true;
                            IApplicationServer as = ApplicationServerRegistry.getService(IApplicationServer.class);
                            if (AngularIndexPageWriter.applicationServerUnavailable(response, as)) {
                                return;
                            }
                            SolutionMetaData solutionMetaData = (SolutionMetaData) ApplicationServerRegistry.get().getLocalRepository().getRootObjectMetaData(solutionName, SOLUTIONS);
                            if (AngularIndexPageWriter.solutionMissing(response, solutionName, solutionMetaData)) {
                                return;
                            }
                            fs = new FlattenedSolution(solutionMetaData, new AbstractActiveSolutionHandler(as) {

                                @Override
                                public IRepository getRepository() {
                                    return ApplicationServerRegistry.get().getLocalRepository();
                                }
                            });
                        } catch (Exception e) {
                            Debug.error("error loading solution: " + solutionName + " for clientnr: " + clientnr, e);
                        }
                    }
                    if (fs != null) {
                        try {
                            if (handleMainJs(request, response, fs)) {
                                return;
                            }
                            if (handleForm(request, response, wsSession, fs)) {
                                return;
                            }
                            if (AngularIndexPageWriter.handleMaintenanceMode(request, response, wsSession)) {
                                return;
                            }
                            // prepare for possible index.html lookup
                            Map<String, Object> variableSubstitution = getSubstitutions(request, solutionName, clientnr, fs);
                            List<String> extraMeta = new ArrayList<String>();
                            addManifest(fs, extraMeta);
                            addHeadIndexContributions(fs, extraMeta);
                            ContentSecurityPolicyConfig contentSecurityPolicyConfig = addcontentSecurityPolicyHeader(request, response, true);
                            super.doFilter(servletRequest, servletResponse, filterChain, asList(SERVOY_CSS), new ArrayList<String>(getFormScriptReferences(fs)), extraMeta, variableSubstitution, contentSecurityPolicyConfig == null ? null : contentSecurityPolicyConfig.getNonce());
                            return;
                        } finally {
                            if (closeFS) {
                                fs.close(null);
                            }
                        }
                    }
                }
            }
            if (!uri.contains(ModifiablePropertiesGenerator.PUSH_TO_SERVER_BINDINGS_LIST))
                Debug.log("No solution found for this request, calling the default filter: " + uri);
        }
        super.doFilter(servletRequest, servletResponse, filterChain, null, null, null, null, null);
    } catch (RuntimeException | Error e) {
        Debug.error(e);
        throw e;
    }
}
Also used : HttpSession(javax.servlet.http.HttpSession) ArrayList(java.util.ArrayList) HttpServletResponse(javax.servlet.http.HttpServletResponse) FlattenedSolution(com.servoy.j2db.FlattenedSolution) IApplicationServer(com.servoy.j2db.server.shared.IApplicationServer) SolutionMetaData(com.servoy.j2db.persistence.SolutionMetaData) ServletException(javax.servlet.ServletException) URISyntaxException(java.net.URISyntaxException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ContentSecurityPolicyConfig(org.sablo.security.ContentSecurityPolicyConfig) HttpServletRequest(javax.servlet.http.HttpServletRequest) AbstractActiveSolutionHandler(com.servoy.j2db.AbstractActiveSolutionHandler) JSONObject(org.json.JSONObject)

Example 64 with FlattenedSolution

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

the class NGClientWindow method getRealFormURLAndSeeIfItIsACopy.

protected Pair<String, Boolean> getRealFormURLAndSeeIfItIsACopy(Form form, String realFormName) {
    FlattenedSolution fs = getSession().getClient().getFlattenedSolution();
    Solution sc = fs.getSolutionCopy(false);
    String realUrl = getDefaultFormURLStart(form, realFormName);
    boolean copy = false;
    if (sc != null && sc.getChild(form.getUUID()) != null) {
        realUrl = realUrl + "?lm:" + form.getLastModified() + "&clientnr=" + getSession().getSessionKey().getClientnr();
        copy = true;
    } else if (!form.getName().endsWith(realFormName)) {
        realUrl = realUrl + "?lm:" + form.getLastModified() + "&clientnr=" + getSession().getSessionKey().getClientnr();
    } else {
        realUrl = realUrl + "?clientnr=" + getSession().getSessionKey().getClientnr();
    }
    return new Pair<String, Boolean>(realUrl, Boolean.valueOf(copy));
}
Also used : FlattenedSolution(com.servoy.j2db.FlattenedSolution) FlattenedSolution(com.servoy.j2db.FlattenedSolution) Solution(com.servoy.j2db.persistence.Solution) Pair(com.servoy.j2db.util.Pair)

Example 65 with FlattenedSolution

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

the class AngularIndexPageWriter method getFlattenedSolution.

private static Pair<FlattenedSolution, Boolean> getFlattenedSolution(String solutionName, String clientnr, HttpServletRequest request, HttpServletResponse response) {
    INGClientWebsocketSession wsSession = null;
    HttpSession httpSession = request.getSession(false);
    if (clientnr != null && httpSession != null) {
        wsSession = (INGClientWebsocketSession) WebsocketSessionManager.getSession(CLIENT_ENDPOINT, httpSession, Integer.parseInt(clientnr));
    }
    FlattenedSolution fs = null;
    boolean closeFS = false;
    if (wsSession != null) {
        fs = wsSession.getClient().getFlattenedSolution();
    }
    if (fs == null) {
        try {
            closeFS = true;
            IApplicationServer as = ApplicationServerRegistry.getService(IApplicationServer.class);
            if (applicationServerUnavailable(response, as)) {
                return new Pair<FlattenedSolution, Boolean>(null, Boolean.FALSE);
            }
            SolutionMetaData solutionMetaData = (SolutionMetaData) ApplicationServerRegistry.get().getLocalRepository().getRootObjectMetaData(solutionName, SOLUTIONS);
            if (solutionMissing(response, solutionName, solutionMetaData)) {
                return new Pair<FlattenedSolution, Boolean>(null, Boolean.FALSE);
            }
            fs = new FlattenedSolution(solutionMetaData, new AbstractActiveSolutionHandler(as) {

                @Override
                public IRepository getRepository() {
                    return ApplicationServerRegistry.get().getLocalRepository();
                }
            });
        } catch (Exception e) {
            Debug.error("error loading solution: " + solutionName + " for clientnr: " + clientnr, e);
        }
    }
    return new Pair<FlattenedSolution, Boolean>(fs, Boolean.valueOf(closeFS));
}
Also used : AbstractActiveSolutionHandler(com.servoy.j2db.AbstractActiveSolutionHandler) HttpSession(javax.servlet.http.HttpSession) FlattenedSolution(com.servoy.j2db.FlattenedSolution) IApplicationServer(com.servoy.j2db.server.shared.IApplicationServer) SolutionMetaData(com.servoy.j2db.persistence.SolutionMetaData) ServletException(javax.servlet.ServletException) JSONException(org.json.JSONException) IOException(java.io.IOException) Pair(com.servoy.j2db.util.Pair)

Aggregations

FlattenedSolution (com.servoy.j2db.FlattenedSolution)79 JSFunction (org.mozilla.javascript.annotations.JSFunction)27 Form (com.servoy.j2db.persistence.Form)20 RepositoryException (com.servoy.j2db.persistence.RepositoryException)17 ArrayList (java.util.ArrayList)17 Relation (com.servoy.j2db.persistence.Relation)15 Media (com.servoy.j2db.persistence.Media)10 Solution (com.servoy.j2db.persistence.Solution)10 ScriptMethod (com.servoy.j2db.persistence.ScriptMethod)9 IBaseSMForm (com.servoy.base.solutionmodel.IBaseSMForm)7 AbstractActiveSolutionHandler (com.servoy.j2db.AbstractActiveSolutionHandler)7 ISMForm (com.servoy.j2db.solutionmodel.ISMForm)7 FormController (com.servoy.j2db.FormController)6 TableNode (com.servoy.j2db.persistence.TableNode)6 ValueList (com.servoy.j2db.persistence.ValueList)6 JSForm (com.servoy.j2db.scripting.solutionmodel.JSForm)6 IApplicationServer (com.servoy.j2db.server.shared.IApplicationServer)6 ITable (com.servoy.j2db.persistence.ITable)5 QueryTable (com.servoy.j2db.query.QueryTable)5 SafeArrayList (com.servoy.j2db.util.SafeArrayList)5