Search in sources :

Example 6 with RepositoryException

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

the class AbstractSolutionTest method buildSolution.

@Before
public void buildSolution() throws Exception {
    TestNGClient.initSettings();
    Types.getTypesInstance().registerTypes();
    final File f = new File(NGClient.class.getProtectionDomain().getCodeSource().getLocation().getPath());
    IPackageReader[] servicesReaders = null;
    IPackageReader[] componentsReaders = null;
    InMemPackageReader inMemPackageReader = getTestComponents();
    if (f.isFile() && f.getName().startsWith("servoy_ngclient") && f.getName().endsWith(".jar")) {
        // it is running from bundles/jars
        ZipFile zipFile = new ZipFile(f);
        componentsReaders = inMemPackageReader != null ? new IPackageReader[] { new ZipPackageReader(zipFile, "war/servoycore/"), new ZipPackageReader(zipFile, "war/servoydefault/"), inMemPackageReader } : new IPackageReader[] { new ZipPackageReader(zipFile, "war/servoycore/"), new ZipPackageReader(zipFile, "war/servoydefault/") };
        servicesReaders = new IPackageReader[] { new ZipPackageReader(zipFile, "war/servoyservices/") };
    } else {
        // it is running from sources/projects
        File ngClientProjDir = f;
        if (!new File(ngClientProjDir, "/war/servoycore/").exists()) {
            ngClientProjDir = ngClientProjDir.getParentFile();
        }
        componentsReaders = getReaders(new File[] { new File(ngClientProjDir.getAbsoluteFile() + "/war/servoycore/"), new File(ngClientProjDir.getAbsoluteFile() + "/war/servoydefault/") }, // in eclipse we .. out of bin, in jenkins we .. out of @dot
        inMemPackageReader);
        servicesReaders = getReaders(new File[] { new File(ngClientProjDir.getAbsoluteFile(), "/war/servoyservices/") }, null);
    }
    WebComponentSpecProvider.init(componentsReaders, DefaultComponentPropertiesProvider.instance);
    WebServiceSpecProvider.init(servicesReaders);
    final TestRepository tr = new TestRepository();
    try {
        ApplicationServerRegistry.setApplicationServerSingleton(new TestApplicationServer(tr));
        UUID uuid = UUID.randomUUID();
        final RootObjectMetaData metadata = tr.createRootObjectMetaData(tr.getElementIdForUUID(uuid), uuid, "Test", IRepository.SOLUTIONS, 1, 1);
        solution = (Solution) tr.createRootObject(metadata);
        tr.cacheRootObject(solution);
        solution.setChangeHandler(new ChangeHandler(tr));
        fillTestSolution();
        HttpSession testHttpsession = new TestHttpsession();
        endpoint = new NGClientEndpoint() {

            // for testing onstart of the NGClientEndpoint should not run
            @Override
            public void onStart() {
            }

            @Override
            protected HttpSession getHttpSession(Session session) {
                return testHttpsession;
            }
        };
        NGClientWebsocketSession session = new NGClientWebsocketSession(new WebsocketSessionKey(testHttpsession.getId(), 1)) {

            @Override
            public void init(Map<String, List<String>> requestParams) throws Exception {
            // override default init, shouldnt make another client.
            }

            @Override
            protected IEventDispatcher createEventDispatcher() {
                return new TestNGEventDispatcher(endpoint);
            }
        };
        WebsocketSessionManager.addSession(session);
        NGClientWebsocketSessionWindows windows = new NGClientWebsocketSessionWindows(session);
        CurrentWindow.set(windows);
        client = new TestNGClient(tr, session) {

            @Override
            public boolean loadSolutionsAndModules(SolutionMetaData solutionMetaData) {
                boolean b = super.loadSolutionsAndModules(solutionMetaData);
                IPersistIndex index = PersistIndexCache.getCachedIndex(solution);
                solution.getChangeHandler().addIPersistListener((IItemChangeListener<IPersist>) index);
                try {
                    setupData();
                } catch (ServoyException e) {
                    e.printStackTrace();
                }
                return b;
            }
        };
        J2DBGlobals.setServiceProvider(client);
        client.setUseLoginSolution(false);
        endpoint.start(new TestSession(), String.valueOf(session.getSessionKey().getClientnr()), "null", "42");
        CurrentWindow.set(session.getWindows().iterator().next());
    } catch (RepositoryException e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }
}
Also used : RootObjectMetaData(com.servoy.j2db.persistence.RootObjectMetaData) IPackageReader(org.sablo.specification.Package.IPackageReader) ServoyException(com.servoy.j2db.util.ServoyException) ChangeHandler(com.servoy.j2db.persistence.ChangeHandler) InMemPackageReader(org.sablo.InMemPackageReader) UUID(com.servoy.j2db.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) HttpSession(javax.servlet.http.HttpSession) NGClientWebsocketSessionWindows(com.servoy.j2db.server.ngclient.eventthread.NGClientWebsocketSessionWindows) RepositoryException(com.servoy.j2db.persistence.RepositoryException) SolutionMetaData(com.servoy.j2db.persistence.SolutionMetaData) NGClientEndpoint(com.servoy.j2db.server.ngclient.endpoint.NGClientEndpoint) ZipFile(java.util.zip.ZipFile) WebsocketSessionKey(org.sablo.websocket.WebsocketSessionKey) NGClientWebsocketSession(com.servoy.j2db.server.ngclient.NGClientWebsocketSession) IPersistIndex(com.servoy.j2db.IPersistIndex) ZipFile(java.util.zip.ZipFile) File(java.io.File) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) HttpSession(javax.servlet.http.HttpSession) Session(javax.websocket.Session) NGClientWebsocketSession(com.servoy.j2db.server.ngclient.NGClientWebsocketSession) IItemChangeListener(com.servoy.j2db.persistence.IItemChangeListener) Before(org.junit.Before)

Example 7 with RepositoryException

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

the class NGClient method loadSolution.

public void loadSolution(String solutionName) throws RepositoryException {
    try {
        SolutionMetaData solutionMetaData = getApplicationServer().getSolutionDefinition(solutionName, getSolutionTypeFilter());
        if (solutionMetaData == null) {
            throw new IllegalArgumentException(Messages.getString("servoy.exception.solutionNotFound", new Object[] { solutionName, IApplication.getApplicationTypeAsString(getClientInfo().getApplicationType()), SolutionMetaData.getSolutionNamesByFilter(getSolutionTypeFilter()) }));
        }
        loadSolution(solutionMetaData);
    } catch (RemoteException e) {
        throw new RepositoryException(e);
    }
}
Also used : BaseWebObject(org.sablo.BaseWebObject) JSONObject(org.json.JSONObject) RepositoryException(com.servoy.j2db.persistence.RepositoryException) RemoteException(java.rmi.RemoteException) SolutionMetaData(com.servoy.j2db.persistence.SolutionMetaData)

Example 8 with RepositoryException

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

the class NGClientWebsocketSession method onOpen.

@SuppressWarnings("nls")
@Override
public void onOpen(final Map<String, List<String>> requestParams) {
    super.onOpen(requestParams);
    if (requestParams == null) {
        CurrentWindow.get().cancelSession("Solution name is required");
        return;
    }
    if (requestParams.containsKey("clienttype")) {
        clientType = Utils.getAsInteger(requestParams.get("clienttype").get(0), 1);
        if (clientType == 2)
            client.getRuntimeProperties().put("NG2", Boolean.TRUE);
        else
            client.getRuntimeProperties().remove("NG2");
    } else {
        clientType = 1;
        client.getRuntimeProperties().remove("NG2");
    }
    lastSentStyleSheets = null;
    final StartupArguments args = new StartupArguments(requestParams);
    final String solutionName = args.getSolutionName();
    if (Utils.stringIsEmpty(solutionName)) {
        CurrentWindow.get().cancelSession("Invalid solution name");
        return;
    }
    if (!client.isEventDispatchThread())
        J2DBGlobals.setServiceProvider(client);
    try {
        FlattenedSolution solution = client.getFlattenedSolution();
        if (solution != null) {
            // test for the main solution meta data else a login solution will constantly be closed even if it is for the right main solution.
            if (solution.getSolution() != null && !solutionName.equals(solution.getMainSolutionMetaData().getName())) {
                client.closeSolution(true, null);
            } else {
                if (solution.isMainSolutionLoaded() || solution.getSolution() != null && solution.getSolution().getSolutionType() == SolutionMetaData.LOGIN_SOLUTION) {
                    // this is needed for the situation when the solution is already loaded and the deeplink url was changed (different arg values for instance)
                    String method = args.getMethodName();
                    String firstArgument = args.getFirstArgument();
                    if (method != null) {
                        try {
                            client.getScriptEngine().getScopesScope().executeGlobalFunction(null, method, (args.toJSMap().isEmpty() ? null : new Object[] { firstArgument, args.toJSMap() }), false, false);
                        } catch (Exception e1) {
                            // $NON-NLS-1$
                            client.reportError(Messages.getString("servoy.formManager.error.ExecutingOpenSolutionMethod", new Object[] { method }), e1);
                        }
                    }
                }
                client.getRuntimeWindowManager().setCurrentWindowName(String.valueOf(CurrentWindow.get().getNr()));
                IWebFormController currentForm = client.getFormManager().getCurrentForm();
                if (currentForm != null) {
                    // we have to call setcontroller again so that switchForm is called and the form is loaded into the reloaded/new window.
                    startHandlingEvent();
                    try {
                        client.getClientFunctions().clear();
                        sendUIProperties();
                        client.getRuntimeWindowManager().getCurrentWindow().setController(currentForm);
                        sendSolutionCSSURL(solution.getSolution());
                    } finally {
                        stopHandlingEvent();
                    }
                    return;
                }
            }
        }
        getEventDispatcher().addEvent(new Runnable() {

            @Override
            public void run() {
                try {
                    sendUIProperties();
                    // the solution was not loaded or another was loaded, now create a main window and load the solution.
                    client.getRuntimeWindowManager().createMainWindow(CurrentWindow.get().getNr());
                    client.handleArguments(args.getFirstArgument() != null ? new String[] { args.getSolutionName(), args.getMethodName(), args.getFirstArgument() } : new String[] { args.getSolutionName(), args.getMethodName() }, args);
                    client.loadSolution(solutionName);
                    client.showInfoPanel();
                } catch (RepositoryException e) {
                    Debug.error("Failed to load the solution: " + solutionName, e);
                    sendInternalError(e);
                }
            }
        });
    } catch (Exception e) {
        Debug.error(e);
        sendInternalError(e);
    } finally {
        if (!client.isEventDispatchThread())
            J2DBGlobals.setServiceProvider(null);
    }
}
Also used : StartupArguments(com.servoy.j2db.scripting.StartupArguments) FlattenedSolution(com.servoy.j2db.FlattenedSolution) RepositoryException(com.servoy.j2db.persistence.RepositoryException) RepositoryException(com.servoy.j2db.persistence.RepositoryException)

Example 9 with RepositoryException

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

the class FlattenedSolution method setSolution.

public void setSolution(SolutionMetaData sol, boolean loadLoginSolution, boolean loadMainSolution, IActiveSolutionHandler activeSolutionHandler) throws RepositoryException, RemoteException {
    // $NON-NLS-1$
    if (sol == null)
        throw new IllegalArgumentException("use close method!");
    isLoadingSolution = true;
    try {
        copySolution = null;
        persistFactory = null;
        mainSolution = null;
        user_created_styles = null;
        all_styles = null;
        if (index != null) {
            index.destroy();
            index = null;
        }
        mainSolutionMetaData = sol;
        if (loadLoginSolution) {
            // get login solution
            Solution[] loginSolutionAndModules = activeSolutionHandler.loadLoginSolutionAndModules(mainSolutionMetaData);
            if (loginSolutionAndModules != null && loginSolutionAndModules.length > 0) {
                if (loginFlattenedSolution == null) {
                    loginFlattenedSolution = new ExtendsConfiguratingFlattenedSolution();
                }
                loginFlattenedSolution.setSolutionAndModules(loginSolutionAndModules[0].getName(), loginSolutionAndModules);
                loginFlattenedSolution.setParentSolution(this);
            }
        }
        // get regular solution if available
        if (// local or already access to repository
        loadMainSolution && activeSolutionHandler.haveRepositoryAccess()) {
            // Note: referencedModules includes main solution
            List<RootObjectReference> referencedModules = activeSolutionHandler.getRepository().getActiveSolutionModuleMetaDatas(mainSolutionMetaData.getRootObjectId());
            if (referencedModules != null && referencedModules.size() != 0) {
                List<RootObjectMetaData> solutionAndModuleMetaDatas = new ArrayList<RootObjectMetaData>();
                for (RootObjectReference moduleReference : referencedModules) {
                    RootObjectMetaData moduleMetaData = moduleReference.getMetaData();
                    if (moduleMetaData == null) {
                        // $NON-NLS-1$
                        throw new RepositoryException(Messages.getString("servoy.client.module.notfound", new Object[] { moduleReference.toString() }));
                    }
                    solutionAndModuleMetaDatas.add(moduleMetaData);
                }
                Solution[] mods = activeSolutionHandler.loadActiveSolutions(solutionAndModuleMetaDatas.toArray(new RootObjectMetaData[solutionAndModuleMetaDatas.size()]));
                setSolutionAndModules(mainSolutionMetaData.getName(), mods);
            }
        }
    } finally {
        isLoadingSolution = false;
    }
}
Also used : RootObjectMetaData(com.servoy.j2db.persistence.RootObjectMetaData) RootObjectReference(com.servoy.j2db.persistence.RootObjectReference) ArrayList(java.util.ArrayList) RepositoryException(com.servoy.j2db.persistence.RepositoryException) JSONObject(org.json.JSONObject) IRootObject(com.servoy.j2db.persistence.IRootObject) Solution(com.servoy.j2db.persistence.Solution)

Example 10 with RepositoryException

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

the class FlattenedSolution method getSolutionCopy.

public Solution getSolutionCopy(boolean create) {
    if (mainSolution == null) {
        if (loginFlattenedSolution != null) {
            return loginFlattenedSolution.getSolutionCopy(create);
        }
        return null;
    }
    if (copySolution != null || !create)
        return copySolution;
    try {
        SimplePersistFactory factory = getPersistFactory();
        copySolution = SimplePersistFactory.createDummyCopy(mainSolution);
        copySolution.setChangeHandler(new ChangeHandler(factory) {

            // overwrite this new Object to skip the call to rootObject.registerNewObject(object); which shouldn't be needed for solution model solutions.
            @Override
            public IPersist createNewObject(ISupportChilds parent, int object_type_id, int element_id, UUID uuid) throws RepositoryException {
                return factory.createObject(parent, object_type_id, element_id, uuid);
            }
        });
        copySolution.getChangeHandler().addIPersistListener(this);
        getIndex().setSolutionModelSolution(copySolution);
    } catch (Exception e) {
        Debug.error(e);
    }
    return copySolution;
}
Also used : ISupportChilds(com.servoy.j2db.persistence.ISupportChilds) ChangeHandler(com.servoy.j2db.persistence.ChangeHandler) IPersist(com.servoy.j2db.persistence.IPersist) RepositoryException(com.servoy.j2db.persistence.RepositoryException) UUID(com.servoy.j2db.util.UUID) SimplePersistFactory(com.servoy.j2db.persistence.SimplePersistFactory) RemoteException(java.rmi.RemoteException) RepositoryException(com.servoy.j2db.persistence.RepositoryException)

Aggregations

RepositoryException (com.servoy.j2db.persistence.RepositoryException)116 RemoteException (java.rmi.RemoteException)45 QuerySelect (com.servoy.j2db.query.QuerySelect)25 ITable (com.servoy.j2db.persistence.ITable)22 JSFunction (org.mozilla.javascript.annotations.JSFunction)22 ServoyException (com.servoy.j2db.util.ServoyException)21 Column (com.servoy.j2db.persistence.Column)19 ArrayList (java.util.ArrayList)19 BaseQueryTable (com.servoy.base.query.BaseQueryTable)16 Table (com.servoy.j2db.persistence.Table)16 QueryTable (com.servoy.j2db.query.QueryTable)16 FlattenedSolution (com.servoy.j2db.FlattenedSolution)14 Point (java.awt.Point)14 IDataProvider (com.servoy.j2db.persistence.IDataProvider)13 QueryColumn (com.servoy.j2db.query.QueryColumn)13 IColumn (com.servoy.j2db.persistence.IColumn)12 ApplicationException (com.servoy.j2db.ApplicationException)11 ScriptNameValidator (com.servoy.j2db.persistence.ScriptNameValidator)10 SafeArrayList (com.servoy.j2db.util.SafeArrayList)10 FoundSetManager (com.servoy.j2db.dataprocessing.FoundSetManager)8