Search in sources :

Example 26 with BimServerClientInterface

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) {
        }
    }
}
Also used : Path(java.nio.file.Path) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) SRenderEnginePluginConfiguration(org.bimserver.interfaces.objects.SRenderEnginePluginConfiguration) BimServer(org.bimserver.BimServer) IOException(java.io.IOException) BimServerConfig(org.bimserver.BimServerConfig) LocalDevelopmentResourceFetcher(org.bimserver.shared.LocalDevelopmentResourceFetcher) IOException(java.io.IOException) RenderEngineException(org.bimserver.plugins.renderengine.RenderEngineException) SPluginDescriptor(org.bimserver.interfaces.objects.SPluginDescriptor) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) RenderEngineException(org.bimserver.plugins.renderengine.RenderEngineException)

Example 27 with BimServerClientInterface

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();
    }
}
Also used : ServiceException(org.bimserver.shared.exceptions.ServiceException) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) IOException(java.io.IOException)

Example 28 with BimServerClientInterface

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();
    }
}
Also used : ServerException(org.bimserver.shared.exceptions.ServerException) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) SProject(org.bimserver.interfaces.objects.SProject) FileOutputStream(java.io.FileOutputStream) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) UserException(org.bimserver.shared.exceptions.UserException)

Example 29 with BimServerClientInterface

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());
    }
}
Also used : SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) IfcModelInterface(org.bimserver.emf.IfcModelInterface) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) SProject(org.bimserver.interfaces.objects.SProject) URL(java.net.URL) Test(org.junit.Test)

Example 30 with BimServerClientInterface

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());
    }
}
Also used : SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) IfcWindow(org.bimserver.models.ifc2x3tc1.IfcWindow) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) IfcModelInterface(org.bimserver.emf.IfcModelInterface) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) SProject(org.bimserver.interfaces.objects.SProject) URL(java.net.URL) Test(org.junit.Test)

Aggregations

BimServerClientInterface (org.bimserver.plugins.services.BimServerClientInterface)66 SProject (org.bimserver.interfaces.objects.SProject)57 UsernamePasswordAuthenticationInfo (org.bimserver.shared.UsernamePasswordAuthenticationInfo)46 Test (org.junit.Test)40 SDeserializerPluginConfiguration (org.bimserver.interfaces.objects.SDeserializerPluginConfiguration)31 SSerializerPluginConfiguration (org.bimserver.interfaces.objects.SSerializerPluginConfiguration)23 IfcModelInterface (org.bimserver.emf.IfcModelInterface)20 PublicInterfaceNotFoundException (org.bimserver.shared.exceptions.PublicInterfaceNotFoundException)20 URL (java.net.URL)19 LowLevelInterface (org.bimserver.shared.interfaces.LowLevelInterface)19 IOException (java.io.IOException)16 ServiceException (org.bimserver.shared.exceptions.ServiceException)15 UserException (org.bimserver.shared.exceptions.UserException)13 ServerException (org.bimserver.shared.exceptions.ServerException)11 BimServerClientException (org.bimserver.shared.exceptions.BimServerClientException)10 Path (java.nio.file.Path)8 JsonBimServerClientFactory (org.bimserver.client.json.JsonBimServerClientFactory)7 BimServerClientFactory (org.bimserver.shared.BimServerClientFactory)7 IfcPropertySingleValue (org.bimserver.models.ifc2x3tc1.IfcPropertySingleValue)6 File (java.io.File)4