Search in sources :

Example 1 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 2 with RepositoryException

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

the class FlattenedSolution method getDataproviderLookup.

public IDataProviderLookup getDataproviderLookup(IFoundSetManagerInternal foundSetManager, final IPersist p) {
    IDataProviderLookup retval = null;
    synchronized (this) {
        if (dataProviderLookups == null)
            dataProviderLookups = new HashMap<IPersist, IDataProviderLookup>();
        retval = dataProviderLookups.get(p);
        if (retval != null)
            return retval;
    }
    if (p instanceof Form) {
        ITable t = null;
        try {
            if (foundSetManager == null) {
                t = getTable(((Form) p).getDataSource());
            } else {
                t = foundSetManager.getTable(((Form) p).getDataSource());
            }
        } catch (RepositoryException e) {
            Debug.error(e);
        }
        retval = new FormAndTableDataProviderLookup(this, (Form) p, t);
    } else if (p instanceof Portal) {
        ITable t = null;
        Relation[] relations = getRelationSequence(((Portal) p).getRelationName());
        if (relations == null) {
            return null;
        }
        t = getTable(relations[relations.length - 1].getForeignDataSource());
        retval = new FormAndTableDataProviderLookup(this, (Form) p.getParent(), t);
    } else // solution
    {
        retval = new IDataProviderLookup() {

            public IDataProvider getDataProvider(String id) throws RepositoryException {
                return getGlobalDataProvider(id);
            }

            public Table getTable() throws RepositoryException {
                return null;
            }
        };
    }
    synchronized (this) {
        dataProviderLookups.put(p, retval);
    }
    return retval;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Form(com.servoy.j2db.persistence.Form) FlattenedForm(com.servoy.j2db.persistence.FlattenedForm) Portal(com.servoy.j2db.persistence.Portal) ITable(com.servoy.j2db.persistence.ITable) RepositoryException(com.servoy.j2db.persistence.RepositoryException) IDataProviderLookup(com.servoy.j2db.persistence.IDataProviderLookup)

Example 3 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 4 with RepositoryException

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

the class ClientState method selectSolutionToLoad.

protected SolutionMetaData selectSolutionToLoad() throws RepositoryException {
    // get a list from the server to choose from
    int solutionTypeFilter = getSolutionTypeFilter();
    if (getPreferedSolutionNameToLoadOnInit() != null) {
        try {
            SolutionMetaData startSolution = applicationServer.getSolutionDefinition(getPreferedSolutionNameToLoadOnInit(), solutionTypeFilter);
            if (startSolution != null)
                return startSolution;
        } catch (RemoteException e) {
            throw new RepositoryException(e);
        }
    }
    SolutionMetaData[] solutions;
    try {
        solutions = applicationServer.getSolutionDefinitions(solutionTypeFilter);
    } catch (RemoteException e) {
        throw new RepositoryException(e);
    }
    if (solutions == null || solutions.length == 0) {
        if (!Utils.getAsBoolean(Settings.getInstance().getProperty("servoy.allowSolutionBrowsing", "true"))) {
            if (argumentsScope != null) {
                try {
                    SolutionMetaData smd = applicationServer.getSolutionDefinition(argumentsScope.getSolutionName(), solutionTypeFilter);
                    if (smd != null)
                        return smd;
                } catch (RemoteException e) {
                    throw new RepositoryException(e);
                }
            }
        }
        // $NON-NLS-1$
        throw new RuntimeException(Messages.getString("servoy.client.error.opensolution"));
    }
    if (solutions.length == 1) {
        return solutions[0];
    }
    // show a dialog
    return showSolutionSelection(solutions);
}
Also used : RepositoryException(com.servoy.j2db.persistence.RepositoryException) RemoteException(java.rmi.RemoteException) SolutionMetaData(com.servoy.j2db.persistence.SolutionMetaData)

Example 5 with RepositoryException

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

the class ClientState method authenticate.

public Object authenticate(String authenticator_solution, String method, Object[] credentials) throws RepositoryException {
    String jscredentials;
    JSONConverter jsonConverter;
    try {
        jsonConverter = new JSONConverter(foundSetManager);
        jscredentials = jsonConverter.convertToJSON(credentials);
    } catch (Exception e) {
        // $NON-NLS-1$
        Debug.error("Could not convert credentials object to json", e);
        return null;
    }
    String jsReturn = authenticate(new Credentials(clientInfo.getClientId(), authenticator_solution, method, jscredentials));
    try {
        return jsonConverter.convertFromJSON(jsReturn);
    } catch (Exception e) {
        // $NON-NLS-1$
        Debug.error("Could not convert authentication json result to object", e);
        return null;
    }
}
Also used : JSONConverter(com.servoy.j2db.util.serialize.JSONConverter) UnmarshalException(java.rmi.UnmarshalException) RhinoException(org.mozilla.javascript.RhinoException) RemoteException(java.rmi.RemoteException) ServoyException(com.servoy.j2db.util.ServoyException) JavaScriptException(org.mozilla.javascript.JavaScriptException) RepositoryException(com.servoy.j2db.persistence.RepositoryException)

Aggregations

RepositoryException (com.servoy.j2db.persistence.RepositoryException)114 RemoteException (java.rmi.RemoteException)43 QuerySelect (com.servoy.j2db.query.QuerySelect)25 JSFunction (org.mozilla.javascript.annotations.JSFunction)22 ITable (com.servoy.j2db.persistence.ITable)21 ServoyException (com.servoy.j2db.util.ServoyException)20 Column (com.servoy.j2db.persistence.Column)19 ArrayList (java.util.ArrayList)18 Table (com.servoy.j2db.persistence.Table)16 BaseQueryTable (com.servoy.base.query.BaseQueryTable)15 QueryTable (com.servoy.j2db.query.QueryTable)15 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 IBaseColumn (com.servoy.base.persistence.IBaseColumn)12 IColumn (com.servoy.j2db.persistence.IColumn)12 ApplicationException (com.servoy.j2db.ApplicationException)10 ScriptNameValidator (com.servoy.j2db.persistence.ScriptNameValidator)10 SafeArrayList (com.servoy.j2db.util.SafeArrayList)10