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());
}
}
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);
}
}
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);
}
}
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;
}
}
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;
}
Aggregations