use of org.bimserver.plugins.services.BimServerClientInterface in project BIMserver by opensourceBIM.
the class TestIfcEngineEmbedded method main.
public static void main(String[] args) {
// Create a config
BimServerConfig config = new BimServerConfig();
Path home = Paths.get("home");
// Remove the home dir if it's there
if (WIPE_HOMEDIR) {
try {
PathUtils.removeDirectoryWithContent(home);
} catch (IOException e) {
e.printStackTrace();
}
}
config.setHomeDir(home);
config.setStartEmbeddedWebServer(true);
config.setPort(8080);
config.setResourceFetcher(new LocalDevelopmentResourceFetcher(Paths.get("../")));
config.setClassPath(System.getProperty("java.class.path"));
// Create a BIMserver
BimServer bimServer = new BimServer(config);
BimServerClientInterface client = null;
try {
// Load plugins
Path[] pluginDirs = new Path[] {// TODO: Set these up yourself...
};
LocalDevPluginLoader.loadPlugins(bimServer.getPluginManager(), pluginDirs);
// Start it
bimServer.start();
// Get a client, not using any protocol (direct connection)
client = bimServer.getBimServerClientFactory().create();
// Setup the server
if (bimServer.getServerInfo().getServerState() == ServerState.NOT_SETUP) {
client.getAdminInterface().setup("http://localhost:8080", "Administrator", "admin@bimserver.org", "admin", null, null, null);
}
// Authenticate
client.setAuthentication(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
// Iterate over the IfcEngines and see if there is one matching the classname specified above
boolean engineFound = false;
for (SRenderEnginePluginConfiguration conf : client.getPluginInterface().getAllRenderEngines(false)) {
SPluginDescriptor pluginDescriptor = client.getPluginInterface().getPluginDescriptor(conf.getPluginDescriptorId());
if (RENDER_ENGINE.equals(pluginDescriptor.getPluginClassName())) {
client.getPluginInterface().setDefaultRenderEngine(conf.getOid());
engineFound = true;
LOGGER.info("Using " + conf.getName());
break;
}
}
if (!engineFound) {
throw new RenderEngineException("No IfcEnginePlugin found with name " + RENDER_ENGINE);
}
// Get a deserializer
SDeserializerPluginConfiguration deserializer = client.getServiceInterface().getSuggestedDeserializerForExtension("ifc", -1L);
if (deserializer == null) {
throw new Exception("No deserializer found for IFC-SPF. Make sure plugin directories are correctly configured");
}
Thread[] threads = new Thread[TEST_FILES.length];
AddProjectCheckinDownloadAction[] contexts = new AddProjectCheckinDownloadAction[TEST_FILES.length];
for (int i = 0; i < TEST_FILES.length; ++i) {
(threads[i] = new Thread(contexts[i] = new AddProjectCheckinDownloadAction(bimServer, TEST_FILES[i]))).start();
}
for (int i = 0; i < TEST_FILES.length; ++i) {
threads[i].join();
}
for (int i = 0; i < TEST_FILES.length; ++i) {
contexts[i].verify();
}
System.exit(0);
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
} finally {
try {
client.disconnect();
} catch (Throwable t) {
}
try {
bimServer.stop();
} catch (Throwable t) {
}
}
}
use of org.bimserver.plugins.services.BimServerClientInterface in project BIMserver by opensourceBIM.
the class TestJsonSerializerMultipleRevisions method main.
public static void main(String[] args) {
try {
BimServerClientInterface client = LocalDevSetup.setupJson("http://localhost:8080");
SSerializerPluginConfiguration jsonSerializer = client.getServiceInterface().getSerializerByContentType("application/json");
long roid1 = 65539;
long roid2 = 131075;
Long download1 = client.getServiceInterface().download(Collections.singleton(roid1), DefaultQueries.allAsString(), jsonSerializer.getOid(), true);
InputStream downloadData1 = client.getDownloadData(download1);
IOUtils.copy(downloadData1, new FileOutputStream(Paths.get("roid1.json").toFile()));
Long download2 = client.getServiceInterface().download(Collections.singleton(roid2), DefaultQueries.allAsString(), jsonSerializer.getOid(), true);
InputStream downloadData2 = client.getDownloadData(download2);
IOUtils.copy(downloadData2, new FileOutputStream(Paths.get("roid2.json").toFile()));
} catch (ServiceException e) {
e.printStackTrace();
} catch (PublicInterfaceNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.bimserver.plugins.services.BimServerClientInterface in project BIMserver by opensourceBIM.
the class TestSceneJsDownload method start.
private void start() {
try {
BimServerClientInterface bimServerClient = LocalDevSetup.setupJson("http://localhost:8080");
bimServerClient.getAuthInterface().login("admin@bimserver.org", "admin");
SSerializerPluginConfiguration serializerByContentType = bimServerClient.getServiceInterface().getSerializerByContentType("application/json");
List<SProject> projects = bimServerClient.getServiceInterface().getProjectsByName("test");
if (!projects.isEmpty()) {
SProject project = projects.get(0);
if (project.getLastRevisionId() != -1) {
long start = System.nanoTime();
Long download = bimServerClient.getServiceInterface().download(Collections.singleton(project.getLastRevisionId()), DefaultQueries.allAsString(), serializerByContentType.getOid(), true);
System.out.println(((System.nanoTime() - start) / 1000000) + " ms");
start = System.nanoTime();
InputStream inputStream = bimServerClient.getDownloadData(download);
FileOutputStream fileOutputStream = new FileOutputStream(Paths.get("test.json").toFile());
IOUtils.copy(inputStream, fileOutputStream);
fileOutputStream.close();
System.out.println(((System.nanoTime() - start) / 1000000) + " ms");
}
}
} catch (ServerException e) {
e.printStackTrace();
} catch (UserException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (PublicInterfaceNotFoundException e) {
e.printStackTrace();
}
}
use of org.bimserver.plugins.services.BimServerClientInterface in project BIMserver by opensourceBIM.
the class TestListWalls method test.
@Test
public void test() {
try {
// Create a new BimServerClient with authentication
BimServerClientInterface bimServerClient = getFactory().create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
// Create a new project
SProject newProject = bimServerClient.getServiceInterface().addProject("test" + Math.random(), "ifc2x3tc1");
// Get the appropriate deserializer
SDeserializerPluginConfiguration deserializer = bimServerClient.getServiceInterface().getSuggestedDeserializerForExtension("ifc", newProject.getOid());
// Checkin the file
bimServerClient.checkin(newProject.getOid(), "test", deserializer.getOid(), false, Flow.SYNC, new URL("https://github.com/opensourceBIM/TestFiles/raw/master/TestData/data/Jesse.1.ifc"));
// Refresh project info
newProject = bimServerClient.getServiceInterface().getProjectByPoid(newProject.getOid());
IfcModelInterface model = bimServerClient.getModel(newProject, newProject.getLastRevisionId(), true, false);
model.getAllWithSubTypes(IfcWallStandardCase.class);
} catch (Throwable e) {
e.printStackTrace();
if (e instanceof AssertionError) {
throw (AssertionError) e;
}
fail(e.getMessage());
}
}
use of org.bimserver.plugins.services.BimServerClientInterface in project BIMserver by opensourceBIM.
the class TestLoadCompleteModel method start.
@Test
public void start() {
try {
// New client
BimServerClientInterface bimServerClient = getFactory().create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
// Create a project
SProject project = bimServerClient.getServiceInterface().addProject("test" + Math.random(), "ifc2x3tc1");
// Look for a deserializer
SDeserializerPluginConfiguration deserializer = bimServerClient.getServiceInterface().getSuggestedDeserializerForExtension("ifc", project.getOid());
// Checkin file
bimServerClient.checkin(project.getOid(), "test", deserializer.getOid(), false, Flow.SYNC, new URL("https://github.com/opensourceBIM/TestFiles/raw/master/TestData/data/AC11-Institute-Var-2-IFC.ifc"));
// Refresh project
project = bimServerClient.getServiceInterface().getProjectByPoid(project.getOid());
// Load model without lazy loading (complete model at once)
IfcModelInterface model = bimServerClient.getModel(project, project.getLastRevisionId(), false, true);
// Change the window names
for (IfcWindow window : model.getAllWithSubTypes(IfcWindow.class)) {
window.setName(window.getName() + " Changed");
}
long newRoid = model.commit("Changed window names");
IfcModelInterface newModel = bimServerClient.getModel(project, newRoid, true, false);
List<IfcWindow> windows = newModel.getAllWithSubTypes(Ifc2x3tc1Package.eINSTANCE.getIfcWindow());
for (IfcWindow window : windows) {
assertTrue(window.getName().endsWith(" Changed"));
}
} catch (Exception e) {
fail(e.getMessage());
}
}
Aggregations