Search in sources :

Example 31 with Solution

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

the class RemoteActiveSolutionHandler method loadCachedSolution.

private Solution loadCachedSolution(RootObjectMetaData solutionDef, long lastModified, ConcurrentMap<String, IServer> serverProxies) {
    int solID = solutionDef.getRootObjectId();
    Solution s = null;
    // try disk load
    File file = null;
    FileInputStream fis = null;
    BufferedInputStream bis = null;
    GZIPInputStream zip = null;
    ObjectInputStream ois = null;
    try {
        URL url = getServiceProvider().getServerURL();
        String name = (url.getHost() + '_' + url.getPort()) + '_' + solutionDef.getName();
        file = new // $NON-NLS-1$
        File(// $NON-NLS-1$
        getServiceProvider().getSettings().getProperty(SMARTCLIENT_SHARED_SOLUTION_DIR_PROPERTY_NAME, System.getProperty("user.home")), // $NON-NLS-1$
        J2DBGlobals.CLIENT_LOCAL_DIR + name + ".solution");
        if (file.exists()) {
            fis = new FileInputStream(file);
            bis = new BufferedInputStream(fis);
            zip = new GZIPInputStream(bis);
            ois = new ObjectInputStream(zip);
            long stored_asus = ois.readLong();
            if (stored_asus == lastModified) {
                Solution fileSolution = (Solution) ois.readObject();
                if (// check if same
                fileSolution.getSolutionID() == solID) {
                    s = fileSolution;
                    s.setServerProxies(serverProxies);
                    Utils.closeInputStream(ois);
                    if (Debug.tracing()) {
                        Debug.trace("Loaded cached solution from: " + file);
                    }
                } else {
                    Utils.closeInputStream(ois);
                    file.delete();
                    if (Debug.tracing()) {
                        Debug.trace("Cached solution from: " + file + " was not valid");
                    }
                }
            } else {
                Utils.closeInputStream(ois);
                file.delete();
                if (Debug.tracing()) {
                    Debug.trace("Cached solution from: " + file + " was not to old");
                }
            }
        }
    } catch (// can fail when classes are changed and do not longer match
    Exception e) {
        s = null;
        // no need to show to user
        Debug.trace(e);
        Utils.closeInputStream(ois);
        Utils.closeInputStream(fis);
        try {
            // if error happens just delete the file
            if (file != null)
                file.delete();
        } catch (Exception e1) {
            Debug.error(e1);
        }
    }
    return s;
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) BufferedInputStream(java.io.BufferedInputStream) File(java.io.File) Solution(com.servoy.j2db.persistence.Solution) FileInputStream(java.io.FileInputStream) URL(java.net.URL) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) RepositoryException(com.servoy.j2db.persistence.RepositoryException) ObjectInputStream(java.io.ObjectInputStream)

Example 32 with Solution

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

the class RemoteActiveSolutionHandler method loadActiveSolutions.

@Override
public Solution[] loadActiveSolutions(final RootObjectMetaData[] solutionDefs) throws RepositoryException, RemoteException {
    final int[] sol_ids = new int[solutionDefs.length];
    for (int i = 0; i < sol_ids.length; i++) {
        sol_ids[i] = solutionDefs[i].getRootObjectId();
    }
    final Solution[] retval = new Solution[solutionDefs.length];
    ThrowingRunnable<RepositoryException, RemoteException> r = new ThrowingRunnable<RepositoryException, RemoteException>() {

        @Override
        public void run() {
            try {
                long[] asus = getApplicationServer().getActiveRootObjectsLastModified(sol_ids);
                ConcurrentMap<String, IServer> sps = getRepository().getServerProxies(solutionDefs);
                for (int i = 0; i < solutionDefs.length; i++) {
                    Solution s = loadCachedSolution(solutionDefs[i], asus[i], sps);
                    if (s == null) {
                        // do full load
                        s = loadSolution(solutionDefs[i]);
                    }
                    if (s != null) {
                        if (s.getRepository() == null) {
                            // transient
                            s.setRepository(getRepository());
                        }
                        loadedActiveSolutionUpdateSequences.put(new Integer(s.getSolutionID()), new Long(asus[i]));
                        s.setServerProxies(sps);
                    }
                    retval[i] = s;
                }
            } catch (RepositoryException eo) {
                e1 = eo;
            } catch (RemoteException et) {
                e2 = et;
            }
        }
    };
    UIUtils.runWhileDispatchingEvents(r, getServiceProvider());
    return retval;
}
Also used : IServer(com.servoy.j2db.persistence.IServer) RepositoryException(com.servoy.j2db.persistence.RepositoryException) ThrowingRunnable(com.servoy.j2db.util.UIUtils.ThrowingRunnable) RemoteException(java.rmi.RemoteException) Solution(com.servoy.j2db.persistence.Solution)

Example 33 with Solution

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

the class Debug method insertClientInfo.

@SuppressWarnings("nls")
private static boolean insertClientInfo(boolean insert) {
    IServiceProvider serviceProvider = J2DBGlobals.getServiceProvider();
    if (insert && serviceProvider != null) {
        Solution solution = serviceProvider.getSolution();
        String clientID = serviceProvider.getClientID();
        if (solution != null && clientID != null) {
            if (MDC.get("clientid") == null) {
                MDC.put("clientid", clientID);
                MDC.put("solution", solution.getName());
                String username = serviceProvider.getUserName();
                if (username != null)
                    MDC.put("username", username);
                String useruuid = serviceProvider.getUserUID();
                if (useruuid != null)
                    MDC.put("useruuid", username);
                ClientInfo clientInfo = serviceProvider.getClientInfo();
                if (clientInfo != null) {
                    MDC.put("clienttype", IApplication.getApplicationTypeAsString(clientInfo.getApplicationType()));
                    MDC.put("hostname", clientInfo.getHostName());
                    MDC.put("hostaddress", clientInfo.getHostAddress());
                }
                return true;
            }
        } else {
            MDC.remove("clientid");
            MDC.remove("solution");
            MDC.remove("username");
            MDC.remove("useruuid");
            MDC.remove("clienttype");
            MDC.remove("hostname");
            MDC.remove("hostaddress");
        }
    } else {
        MDC.remove("clientid");
        MDC.remove("solution");
        MDC.remove("username");
        MDC.remove("useruuid");
        MDC.remove("clienttype");
        MDC.remove("hostname");
        MDC.remove("hostaddress");
    }
    return false;
}
Also used : IServiceProvider(com.servoy.j2db.IServiceProvider) ClientInfo(com.servoy.j2db.dataprocessing.ClientInfo) Solution(com.servoy.j2db.persistence.Solution)

Example 34 with Solution

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

the class PersistHelper method getOrderedStyleSheets.

public static List<String> getOrderedStyleSheets(FlattenedSolution fs) {
    List<String> styleSheets = new ArrayList<String>();
    List<Solution> orderedModules = new ArrayList<Solution>();
    orderedModules.add(fs.getSolution());
    if (fs.getModules() != null) {
        buildOrderedModulesList(fs.getSolution(), orderedModules, new ArrayList<Solution>(Arrays.asList(fs.getModules())));
    }
    for (Solution solution : orderedModules) {
        if (solution.getStyleSheetID() > 0) {
            Media media = fs.getMedia(solution.getStyleSheetID());
            if (media != null) {
                if (!styleSheets.contains(media.getName())) {
                    styleSheets.add(media.getName());
                }
            } else {
                // $NON-NLS-1$ //$NON-NLS-2$
                Debug.warn("Stylesheet set for solution '" + solution.getName() + "' cannot be found");
            }
        }
    }
    return styleSheets;
}
Also used : ArrayList(java.util.ArrayList) Media(com.servoy.j2db.persistence.Media) FlattenedSolution(com.servoy.j2db.FlattenedSolution) Solution(com.servoy.j2db.persistence.Solution)

Example 35 with Solution

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

the class ClientState method loadSecuritySettings.

public void loadSecuritySettings(FlattenedSolution root) throws ServoyException, RemoteException {
    if (clientInfo.getUserUid() != null) {
        Solution sol = root.getSolution();
        String[] groups = clientInfo.getUserGroups();
        if (// fall back on retrieval of groups based on user_uid
        groups == null) {
            groups = getUserManager().getUserGroups(clientInfo.getClientId(), clientInfo.getUserUid());
        }
        root.clearSecurityAccess();
        int[] sids = new int[] { sol.getSolutionID() };
        int[] srns = new int[] { sol.getReleaseNumber() };
        Solution[] modules = root.getModules();
        if (modules != null) {
            sids = new int[modules.length + 1];
            sids[0] = sol.getSolutionID();
            srns = new int[modules.length + 1];
            srns[0] = sol.getReleaseNumber();
            for (int i = 0; i < modules.length; i++) {
                Solution module = modules[i];
                sids[i + 1] = module.getSolutionID();
                srns[i + 1] = module.getReleaseNumber();
            }
        }
        Pair<Map<Object, Integer>, Set<Object>> securityAccess = getUserManager().getSecurityAccess(clientInfo.getClientId(), sids, srns, groups);
        root.addSecurityAccess(securityAccess);
        if (foundSetManager != null) {
            ((FoundSetManager) foundSetManager).flushSecuritySettings();
        }
    }
}
Also used : FoundSetManager(com.servoy.j2db.dataprocessing.FoundSetManager) Set(java.util.Set) Map(java.util.Map) HashMap(java.util.HashMap) 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