Search in sources :

Example 56 with Solution

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

the class SelectNGSolutionFilter method doFilter.

public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
    if (Utils.getAsBoolean(Settings.getInstance().getProperty("servoy.allowSolutionBrowsing", "true"))) {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        String uri = request.getServletPath();
        if (uri != null) {
            if (uri.equals("/servoy-ngclient")) {
                // html contents
                ((HttpServletResponse) servletResponse).setContentType("text/html");
                PrintWriter w = servletResponse.getWriter();
                addNeededJSAndCSS(getClass().getResource("solution_list.html"), w);
                w.flush();
                return;
            } else if (uri.equals("/servoy-ngclient/solutions.js")) {
                HTTPUtils.setNoCacheHeaders((HttpServletResponse) servletResponse);
                IApplicationServerSingleton as = ApplicationServerRegistry.get();
                // js contents giving the actual solutions list
                List<Solution> ngCompatibleSolutions = new ArrayList<Solution>();
                if (as.isDeveloperStartup()) {
                    Solution active = as.getDebugClientHandler().getDebugSmartClient().getCurrent();
                    if ((((SolutionMetaData) active.getMetaData()).getSolutionType() & (SolutionMetaData.SOLUTION | SolutionMetaData.NG_CLIENT_ONLY)) != 0)
                        ngCompatibleSolutions.add(active);
                } else {
                    try {
                        RootObjectMetaData[] smds = as.getLocalRepository().getRootObjectMetaDatasForType(IRepository.SOLUTIONS);
                        int solutionType;
                        for (RootObjectMetaData element : smds) {
                            solutionType = ((SolutionMetaData) element).getSolutionType();
                            if ((solutionType & (SolutionMetaData.SOLUTION | SolutionMetaData.NG_CLIENT_ONLY)) > 0) {
                                Solution solution = (Solution) as.getLocalRepository().getActiveRootObject(element.getRootObjectId());
                                if (solution != null) {
                                    ngCompatibleSolutions.add(solution);
                                }
                            }
                        }
                    } catch (RepositoryException e) {
                        Debug.error(e);
                    }
                }
                // now generate the js containing these solutions
                ((HttpServletResponse) servletResponse).setContentType("text/javascript");
                PrintWriter w = servletResponse.getWriter();
                w.println("angular.module('solutionsListModule', []).value('$solutionsList', {");
                w.println("    ngSolutions: [");
                boolean putComma = false;
                for (Solution s : ngCompatibleSolutions) {
                    if (putComma)
                        w.println(",");
                    else
                        putComma = true;
                    String titleText = (s.getTitleText() != null ? "'" + s.getTitleText() + "'" : null);
                    // it wouldn't look nice in the list of solutions to pick + client can't convert those
                    if (titleText != null && (titleText.contains("#") || titleText.startsWith("i18n:")))
                        titleText = null;
                    w.print("        { name : '" + s.getName() + "', titleText : " + titleText + ", requiresAuth : " + s.requireAuthentication() + " }");
                }
                if (putComma)
                    w.println("");
                w.println("    ]");
                w.println("});");
                w.flush();
                return;
            }
        }
    }
    filterChain.doFilter(servletRequest, servletResponse);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) RootObjectMetaData(com.servoy.j2db.persistence.RootObjectMetaData) IApplicationServerSingleton(com.servoy.j2db.server.shared.IApplicationServerSingleton) HttpServletResponse(javax.servlet.http.HttpServletResponse) ArrayList(java.util.ArrayList) List(java.util.List) RepositoryException(com.servoy.j2db.persistence.RepositoryException) Solution(com.servoy.j2db.persistence.Solution) SolutionMetaData(com.servoy.j2db.persistence.SolutionMetaData) PrintWriter(java.io.PrintWriter)

Example 57 with Solution

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

the class FormElementHelper method getFormComponentCache.

public FormComponentCache getFormComponentCache(INGFormElement formElement, PropertyDescription pd, JSONObject formElementValue, Form form, FlattenedSolution fs) {
    ConcurrentMap<UUID, Map<String, FormComponentCache>> cache = formElement.getDesignId() != null ? formComponentElementsForDesign : formComponentElements;
    Solution solutionCopy = fs.getSolutionCopy(false);
    FlattenedSolution usedFS = getSharedFlattenedSolution(fs);
    if (solutionCopy != null && solutionCopy.getForm(formElement.getForm().getName()) != null) {
        usedFS = fs;
        // if the form is a solution model for we can't use the standard caches.
        cache = solutionCopy.getRuntimeProperty(SOLUTION_MODEL_CACHE);
        if (cache == null) {
            cache = new ConcurrentHashMap<UUID, Map<String, FormComponentCache>>();
            solutionCopy.setRuntimeProperty(SOLUTION_MODEL_CACHE, cache);
        }
    }
    return getFormComponentFromCache(formElement, pd, formElementValue, form, usedFS, cache);
}
Also used : FlattenedSolution(com.servoy.j2db.FlattenedSolution) UUID(com.servoy.j2db.util.UUID) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) WeakHashMap(java.util.WeakHashMap) FlattenedSolution(com.servoy.j2db.FlattenedSolution) Solution(com.servoy.j2db.persistence.Solution)

Example 58 with Solution

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

the class EditRecordList method stopEditing.

/**
 * stop/save
 *
 * @param javascriptStop
 * @param recordsToSave null means all records
 * @return IRowChangeListener static final
 */
@SuppressWarnings("nls")
public int stopEditing(boolean javascriptStop, List<IRecord> recordsToSave) {
    int stopped = stopEditingImpl(javascriptStop, recordsToSave, 0);
    if ((stopped == ISaveConstants.VALIDATION_FAILED || stopped == ISaveConstants.SAVE_FAILED) && !javascriptStop) {
        IApplication application = fsm.getApplication();
        Solution solution = application.getSolution();
        int mid = solution.getOnAutoSaveFailedMethodID();
        if (mid > 0) {
            ScriptMethod sm = application.getFlattenedSolution().getScriptMethod(mid);
            if (sm != null) {
                // the validation failed in a none javascript stop (so this was an autosave failure)
                List<JSRecordMarkers> failedMarkers = failedRecords.stream().map(record -> record.getRecordMarkers()).collect(Collectors.toList());
                try {
                    application.getScriptEngine().getScopesScope().executeGlobalFunction(sm.getScopeName(), sm.getName(), Utils.arrayMerge((new Object[] { failedMarkers.toArray() }), Utils.parseJSExpressions(solution.getFlattenedMethodArguments(IContentSpecConstants.PROPERTY_ONAUTOSAVEDFAILEDMETHODID))), false, false);
                } catch (Exception e) {
                    application.reportJSError("Failed to run the solutions auto save failed method", e);
                }
            } else {
                application.reportJSWarning("Solution " + application.getSolutionName() + " onautosavefailed method not found for id " + mid);
            }
        }
    }
    return stopped;
}
Also used : DbIdentValue(com.servoy.j2db.dataprocessing.ValueFactory.DbIdentValue) Arrays(java.util.Arrays) Placeholder(com.servoy.j2db.query.Placeholder) LoggerFactory(org.slf4j.LoggerFactory) Debug(com.servoy.j2db.util.Debug) HashMap(java.util.HashMap) Solution(com.servoy.j2db.persistence.Solution) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) NativeObject(org.mozilla.javascript.NativeObject) Utils(com.servoy.j2db.util.Utils) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod) StaticContentSpecLoader(com.servoy.j2db.persistence.StaticContentSpecLoader) Map(java.util.Map) StreamSupport(java.util.stream.StreamSupport) ServoyException(com.servoy.j2db.util.ServoyException) ApplicationException(com.servoy.j2db.ApplicationException) Utils.equalObjects(com.servoy.j2db.util.Utils.equalObjects) Logger(org.slf4j.Logger) IBaseColumn(com.servoy.base.persistence.IBaseColumn) Iterator(java.util.Iterator) ReentrantLock(java.util.concurrent.locks.ReentrantLock) JavaScriptException(org.mozilla.javascript.JavaScriptException) Predicate(java.util.function.Predicate) IContentSpecConstants(com.servoy.j2db.persistence.IContentSpecConstants) IRepository(com.servoy.j2db.persistence.IRepository) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ITable(com.servoy.j2db.persistence.ITable) Collectors(java.util.stream.Collectors) Table(com.servoy.j2db.persistence.Table) IApplication(com.servoy.j2db.IApplication) IntHashMap(com.servoy.j2db.util.IntHashMap) Objects(java.util.Objects) IServer(com.servoy.j2db.persistence.IServer) List(java.util.List) Entry(java.util.Map.Entry) BlobMarkerValue(com.servoy.j2db.dataprocessing.ValueFactory.BlobMarkerValue) Column(com.servoy.j2db.persistence.Column) RepositoryException(com.servoy.j2db.persistence.RepositoryException) IPrepareForSave(com.servoy.j2db.IPrepareForSave) Arrays.stream(java.util.Arrays.stream) Collections(java.util.Collections) QueryInsert(com.servoy.j2db.query.QueryInsert) IApplication(com.servoy.j2db.IApplication) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod) Solution(com.servoy.j2db.persistence.Solution) ServoyException(com.servoy.j2db.util.ServoyException) ApplicationException(com.servoy.j2db.ApplicationException) JavaScriptException(org.mozilla.javascript.JavaScriptException) RepositoryException(com.servoy.j2db.persistence.RepositoryException)

Example 59 with Solution

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

the class FoundSetManager method notifyDataChange.

/*
 * _____________________________________________________________ dataNotification
 */
public void notifyDataChange(final String ds, IDataSet pks, final int action, Object[] insertColumnData) {
    RowManager rm = rowManagers.get(ds);
    if (rm != null) {
        List<Row> insertedRows = null;
        if (action == ISQLActionTypes.INSERT_ACTION && insertColumnData == null) {
            // in this case the insert notification is probably triggered by rawSQL; so we need to read the new rows from DB to get correct newly inserted content
            try {
                insertedRows = rm.getRows(pks, 0, pks.getRowCount(), false);
                if (insertedRows.size() != pks.getRowCount()) {
                    insertedRows = rm.getRows(pks, 0, pks.getRowCount(), true);
                }
            } catch (ServoyException e) {
                Debug.error("Cannot get newly inserted rows.", e);
            }
        }
        boolean didHaveRowAndIsUpdated = false;
        IDataSet newPks = pks;
        try {
            // Convert the pk dataset to the column type of the pk columns
            newPks = BufferedDataSetInternal.convertPksToRightType(pks, getTable(ds));
        } catch (RepositoryException e) {
            Debug.error(e);
        }
        final IDataSet fnewPks = newPks;
        for (int i = 0; i < fnewPks.getRowCount(); i++) {
            boolean b = rm.changeByOther(RowManager.createPKHashKey(fnewPks.getRow(i)), action, insertColumnData, insertedRows == null ? null : insertedRows.get(i));
            didHaveRowAndIsUpdated = (didHaveRowAndIsUpdated || b);
        }
        // changed by other calls don't notify the table change for every row, call it once now.
        notifyChange(rm.getSQLSheet().getTable());
        final boolean didHaveDataCached = didHaveRowAndIsUpdated;
        Runnable r = new Runnable() {

            public void run() {
                Solution solution = application.getSolution();
                if (solution != null) {
                    ScriptMethod sm = application.getFlattenedSolution().getScriptMethod(solution.getOnDataBroadcastMethodID());
                    if (sm != null) {
                        try {
                            application.getScriptEngine().getScopesScope().executeGlobalFunction(sm.getScopeName(), sm.getName(), arrayMerge(new Object[] { ds, new Integer(action), new JSDataSet(application, fnewPks), Boolean.valueOf(didHaveDataCached) }, // $NON-NLS-1$
                            parseJSExpressions(solution.getFlattenedMethodArguments("onDataBroadcastMethodID"))), false, false);
                        } catch (Exception e1) {
                            application.reportError(Messages.getString("servoy.foundsetManager.error.ExecutingDataBroadcastMethod", new Object[] { sm.getName() }), // $NON-NLS-1$
                            e1);
                        }
                    }
                }
            }
        };
        application.invokeLater(r);
        if (didHaveRowAndIsUpdated) {
            if (infoListener != null)
                infoListener.showDataChange();
        } else // TODO if(action == INSERT) This is called to often now.
        {
            fireTableEvent(rm.getSQLSheet().getTable());
        }
    }
}
Also used : RepositoryException(com.servoy.j2db.persistence.RepositoryException) ServoyException(com.servoy.j2db.util.ServoyException) ServoyException(com.servoy.j2db.util.ServoyException) JavaScriptException(org.mozilla.javascript.JavaScriptException) IOException(java.io.IOException) MarshallException(org.jabsorb.serializer.MarshallException) ApplicationException(com.servoy.j2db.ApplicationException) RemoteException(java.rmi.RemoteException) RepositoryException(com.servoy.j2db.persistence.RepositoryException) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod) FlattenedSolution(com.servoy.j2db.FlattenedSolution) 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