Search in sources :

Example 16 with FlattenedSolution

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

the class FormElementHelper method generateFormComponentCacheObject.

private static FormComponentCache generateFormComponentCacheObject(INGFormElement parentElement, PropertyDescription pd, Form frm, FlattenedSolution fs, final List<FormElement> list) {
    IFormElementCache cache = new IFormElementCache() {

        @Override
        public FormElement getFormElement(IFormElement component, FlattenedSolution flattendSol, PropertyPath path, boolean design) {
            for (FormElement formElement : list) {
                if (component.getID() == formElement.getPersistIfAvailable().getID()) {
                    return formElement;
                }
            }
            return FormElementHelper.INSTANCE.getFormElement(component, flattendSol, path, design);
        }
    };
    String template = FormLayoutGenerator.generateFormComponent(frm, fs, cache);
    return new FormComponentCache(list, template, frm.getUUID().toString());
}
Also used : IFormElement(com.servoy.j2db.persistence.IFormElement) PropertyPath(com.servoy.j2db.server.ngclient.property.types.PropertyPath) FlattenedSolution(com.servoy.j2db.FlattenedSolution) IFormElement(com.servoy.j2db.persistence.IFormElement)

Example 17 with FlattenedSolution

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

the class FormElementHelper method getSharedFlattenedSolution.

private FlattenedSolution getSharedFlattenedSolution(FlattenedSolution fs) {
    FlattenedSolution flattenedSolution = globalFlattendSolutions.get(fs.getMainSolutionMetaData().getName());
    if (flattenedSolution == null) {
        try {
            flattenedSolution = new FlattenedSolution(true);
            flattenedSolution.setSolution(fs.getMainSolutionMetaData(), false, true, new AbstractActiveSolutionHandler(ApplicationServerRegistry.getService(IApplicationServer.class)) {

                @Override
                public IRepository getRepository() {
                    return ApplicationServerRegistry.get().getLocalRepository();
                }
            });
            FlattenedSolution alreadyCreated = globalFlattendSolutions.putIfAbsent(flattenedSolution.getName(), flattenedSolution);
            if (alreadyCreated != null) {
                flattenedSolution.close(null);
                flattenedSolution = alreadyCreated;
            }
        } catch (Exception e) {
            throw new RuntimeException("Can't create FlattenedSolution for: " + fs, e);
        }
    }
    return flattenedSolution;
}
Also used : AbstractActiveSolutionHandler(com.servoy.j2db.AbstractActiveSolutionHandler) FlattenedSolution(com.servoy.j2db.FlattenedSolution) IRepository(com.servoy.j2db.persistence.IRepository) JSONException(org.json.JSONException)

Example 18 with FlattenedSolution

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

the class WebTabPanel method addTab.

public boolean addTab(IForm formController, String formName, String tabname, String tabText, String tabtooltip, String iconURL, String fg, String bg, String relationName, RelatedFoundSet relatedFs, int idx) {
    if (formController != null) {
        // to make sure we don't have recursion on adding a tab, to a tabpanel, that is based
        // on the form that the tabpanel is placed on
        WebForm webForm = findParent(WebForm.class);
        if (webForm != null) {
            FormController parentFormController = webForm.getController();
            if (parentFormController != null && parentFormController.equals(formController)) {
                return false;
            }
        }
    }
    WebTabFormLookup flp = (WebTabFormLookup) createFormLookupPanel(tabname, relationName, formName);
    if (formController != null)
        flp.setReadOnly(formController.isReadOnly());
    FlattenedSolution fl = application.getFlattenedSolution();
    int mediaId = -1;
    if (iconURL != null && !"".equals(iconURL)) {
        Media media = fl.getMedia(iconURL.replaceAll("media:///", ""));
        if (media != null)
            mediaId = media.getID();
        if (mediaId == -1) {
            Debug.warn("Form '" + formController.getName() + "' with tabpanel  '" + this.name + "' has tabicon  for tab '" + tabname + "'in with icon media url : " + iconURL + " not found");
        }
    }
    byte[] iconData = (mediaId == -1 ? null : ComponentFactory.loadIcon(fl, new Integer(mediaId)));
    int count = allTabs.size();
    int tabIndex = idx;
    if (tabIndex == -1 || tabIndex >= count) {
        tabIndex = count;
    }
    insertTab(application.getI18NMessageIfPrefixed(tabText), iconData, flp, application.getI18NMessageIfPrefixed(tabtooltip), tabIndex, true);
    if (fg != null)
        setTabForegroundAt(tabIndex, PersistHelper.createColor(fg));
    if (bg != null)
        setTabBackgroundAt(tabIndex, PersistHelper.createColor(bg));
    // from the relatedFs - which is already in the relationName param
    if (relatedFs != null && currentForm == flp) {
        FormController fp = flp.getWebForm().getController();
        if (fp != null && flp.getRelationName() != null && flp.getRelationName().equals(relationName)) {
            fp.loadData(relatedFs, null);
        }
    }
    return true;
}
Also used : FormController(com.servoy.j2db.FormController) WebForm(com.servoy.j2db.server.headlessclient.WebForm) Media(com.servoy.j2db.persistence.Media) FlattenedSolution(com.servoy.j2db.FlattenedSolution) Point(java.awt.Point)

Example 19 with FlattenedSolution

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

the class MediaResourcesServlet method findAndSendMediaData.

protected boolean findAndSendMediaData(HttpServletRequest request, HttpServletResponse response, String mediaName, FlattenedSolution fs) throws IOException {
    Media media = fs.getMedia(mediaName);
    if (media == null && mediaName.endsWith(".css")) {
        media = fs.getMedia(mediaName.replace(".css", ".less"));
        Solution sc = fs.getSolutionCopy(false);
        if (media != null && media.getParent() != sc) {
            // is a less file, try to load the compiled version
            URL url = getServletConfig().getServletContext().getResource('/' + SERVOY_SOLUTION_CSS + '/' + mediaName);
            if (url != null) {
                setHeaders(request, response);
                // cache resources on client until changed
                if (HTTPUtils.checkAndSetUnmodified(request, response, media.getLastModifiedTime() != -1 ? media.getLastModifiedTime() : fs.getLastModifiedTime()))
                    return true;
                response.setContentType("text/css");
                URLConnection con = url.openConnection();
                long lenght = con.getContentLengthLong();
                if (lenght > 0)
                    response.setContentLengthLong(lenght);
                try (InputStream is = con.getInputStream()) {
                    IOUtils.copy(is, response.getOutputStream());
                }
                return true;
            }
        }
    }
    if (media != null) {
        return sendMediaData(request, response, fs, media);
    }
    return false;
}
Also used : InputStream(java.io.InputStream) Media(com.servoy.j2db.persistence.Media) FlattenedSolution(com.servoy.j2db.FlattenedSolution) Solution(com.servoy.j2db.persistence.Solution) URL(java.net.URL) URLConnection(java.net.URLConnection)

Example 20 with FlattenedSolution

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

the class SQLGenerator method addSorts.

public void addSorts(QuerySelect sqlSelect, BaseQueryTable selectTable, IGlobalValueEntry provider, ITable table, List<SortColumn> orderByFields, boolean includeRelated, boolean permanentJoins) throws RepositoryException {
    List<Column> unusedRowidentColumns = new ArrayList<Column>(table.getRowIdentColumns());
    for (int i = 0; orderByFields != null && i < orderByFields.size(); i++) {
        SortColumn sc = orderByFields.get(i);
        // can be column or aggregate
        IColumn column = sc.getColumn();
        if (column.getDataProviderType() == MEDIA && (column.getFlags() & (IDENT_COLUMNS | UUID_COLUMN)) == 0) {
            // skip cannot sort blob columns
            continue;
        }
        SortOptions sortOptions = application.getFoundSetManager().getSortOptions(sc.getColumn());
        Relation[] relations = sc.getRelations();
        // compare on server objects, relation.foreignServerName may be different in case of duplicates
        boolean doRelatedJoin = (includeRelated && relations != null);
        if (doRelatedJoin) {
            FlattenedSolution fs = application.getFlattenedSolution();
            for (Relation relation : relations) {
                if (relation.isMultiServer() && !fs.getTable(relation.getForeignDataSource()).getServerName().equals(table.getServerName())) {
                    doRelatedJoin = false;
                    break;
                }
            }
        }
        if (doRelatedJoin) // related sort, cannot join across multiple servers
        {
            BaseQueryTable primaryQtable = selectTable;
            BaseQueryTable foreignQtable = null;
            for (Relation relation : relations) {
                // join must be re-created as it is possible to have globals involved;
                // first remove, then create it
                ISQLTableJoin join = (ISQLTableJoin) sqlSelect.getJoin(primaryQtable, relation.getName());
                if (join != null)
                    sqlSelect.getJoins().remove(join);
                if (join == null) {
                    ITable foreignTable = application.getFlattenedSolution().getTable(relation.getForeignDataSource());
                    foreignQtable = new QueryTable(foreignTable.getSQLName(), foreignTable.getDataSource(), foreignTable.getCatalog(), foreignTable.getSchema());
                } else {
                    foreignQtable = join.getForeignTable();
                }
                sqlSelect.addJoin(createJoin(application.getFlattenedSolution(), relation, primaryQtable, foreignQtable, permanentJoins, provider));
                primaryQtable = foreignQtable;
            }
            IQuerySelectValue queryColumn;
            if (column instanceof Column) {
                queryColumn = ((Column) column).queryColumn(foreignQtable);
                unusedRowidentColumns.remove(column);
            } else if (column instanceof AggregateVariable) {
                AggregateVariable aggregate = (AggregateVariable) column;
                queryColumn = new QueryAggregate(aggregate.getType(), new QueryColumn(foreignQtable, -1, aggregate.getColumnNameToAggregate(), aggregate.getDataProviderType(), aggregate.getLength(), 0, null, aggregate.getFlags()), aggregate.getName());
                // there has to be a group-by clause for all selected fields
                List<IQuerySelectValue> columns = sqlSelect.getColumns();
                for (IQuerySelectValue selectVal : columns) {
                    List<IQuerySelectValue> groupBy = sqlSelect.getGroupBy();
                    if (selectVal instanceof QueryColumn && (groupBy == null || !groupBy.contains(selectVal))) {
                        sqlSelect.addGroupBy(selectVal);
                    }
                }
                // if the aggregate has not been selected yet, add it and skip it in the result
                QueryAggregate skippedAggregate = new QueryAggregate(aggregate.getType(), QueryAggregate.ALL, new QueryColumn(foreignQtable, -1, aggregate.getColumnNameToAggregate(), aggregate.getDataProviderType(), aggregate.getLength(), 0, null, aggregate.getFlags()), aggregate.getName(), null, true);
                if (!columns.contains(skippedAggregate)) {
                    sqlSelect.addColumn(skippedAggregate);
                }
            } else {
                // $NON-NLS-1$
                Debug.log("Skipping sort on unexpected related column type " + column.getClass());
                continue;
            }
            sqlSelect.addSort(new QuerySort(queryColumn, sc.getSortOrder() == ASCENDING, sortOptions));
        } else {
            // make sure an invalid sort is not possible
            if (column instanceof Column && column.getTable().getName().equals(table.getName())) {
                sqlSelect.addSort(new QuerySort(((Column) column).queryColumn(selectTable), sc.getSortOrder() == ASCENDING, sortOptions));
                unusedRowidentColumns.remove(column);
            } else {
                // $NON-NLS-1$ //$NON-NLS-2$
                Debug.log("Skipping sort on unrelated column " + column.getName() + '.' + column.getTable().getName() + " for table " + table.getName());
            }
        }
    }
    // Make sure pk is part of the sort, in case of non-unique sort columns, the sorted result may not be the same in each fetch
    if (enforcePkInSort) {
        for (Column column : unusedRowidentColumns) {
            SortOptions sortOptions = application.getFoundSetManager().getSortOptions(column);
            sqlSelect.addSort(new QuerySort(column.queryColumn(selectTable), true, sortOptions));
        }
    }
}
Also used : QueryAggregate(com.servoy.j2db.query.QueryAggregate) ArrayList(java.util.ArrayList) SafeArrayList(com.servoy.j2db.util.SafeArrayList) FlattenedSolution(com.servoy.j2db.FlattenedSolution) AggregateVariable(com.servoy.j2db.persistence.AggregateVariable) BaseQueryTable(com.servoy.base.query.BaseQueryTable) QueryTable(com.servoy.j2db.query.QueryTable) Relation(com.servoy.j2db.persistence.Relation) IRelation(com.servoy.j2db.persistence.IRelation) BaseQueryTable(com.servoy.base.query.BaseQueryTable) QueryColumn(com.servoy.j2db.query.QueryColumn) BaseQueryColumn(com.servoy.base.query.BaseQueryColumn) IColumn(com.servoy.j2db.persistence.IColumn) Column(com.servoy.j2db.persistence.Column) IColumn(com.servoy.j2db.persistence.IColumn) ISQLTableJoin(com.servoy.j2db.query.ISQLTableJoin) QueryColumn(com.servoy.j2db.query.QueryColumn) BaseQueryColumn(com.servoy.base.query.BaseQueryColumn) QuerySort(com.servoy.j2db.query.QuerySort) IQuerySort(com.servoy.j2db.query.IQuerySort) ITable(com.servoy.j2db.persistence.ITable) List(java.util.List) ArrayList(java.util.ArrayList) SafeArrayList(com.servoy.j2db.util.SafeArrayList) Collectors.toList(java.util.stream.Collectors.toList) SortOptions(com.servoy.j2db.query.SortOptions) IQuerySelectValue(com.servoy.j2db.query.IQuerySelectValue)

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