Search in sources :

Example 71 with SProject

use of org.bimserver.interfaces.objects.SProject in project BIMserver by opensourceBIM.

the class TestMultiple method main.

public static void main(String[] args) throws InterruptedException {
    try (BimServerClientFactory factory = new JsonBimServerClientFactory("http://localhost:8080")) {
        BimServerClientInterface client = factory.create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
        ThreadPoolExecutor executor = new ThreadPoolExecutor(2, 2, 1, TimeUnit.DAYS, new ArrayBlockingQueue<>(2));
        for (int i = 0; i < 2; i++) {
            executor.submit(new Runnable() {

                @Override
                public void run() {
                    try {
                        SProject project = client.getServiceInterface().addProject("P" + new Random().nextInt(), "ifc2x3tc1");
                        SDeserializerPluginConfiguration deserializer = client.getServiceInterface().getSuggestedDeserializerForExtension("ifc", project.getOid());
                        client.checkin(project.getOid(), "Test", deserializer.getOid(), false, Flow.ASYNC, Paths.get("C:\\Git\\TestFiles\\TestData\\data\\HITOS_070308.ifc"));
                    } catch (ServerException e) {
                        e.printStackTrace();
                    } catch (UserException e) {
                        e.printStackTrace();
                    } catch (PublicInterfaceNotFoundException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            });
        }
        executor.shutdown();
        executor.awaitTermination(1, TimeUnit.HOURS);
    } catch (BimServerClientException e) {
        e.printStackTrace();
    } catch (ServiceException e) {
        e.printStackTrace();
    } catch (ChannelConnectionException e) {
        e.printStackTrace();
    } catch (Exception e1) {
        e1.printStackTrace();
    }
}
Also used : SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) ServerException(org.bimserver.shared.exceptions.ServerException) ChannelConnectionException(org.bimserver.shared.ChannelConnectionException) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) IOException(java.io.IOException) SProject(org.bimserver.interfaces.objects.SProject) BimServerClientException(org.bimserver.shared.exceptions.BimServerClientException) JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) BimServerClientFactory(org.bimserver.shared.BimServerClientFactory) ChannelConnectionException(org.bimserver.shared.ChannelConnectionException) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) BimServerClientException(org.bimserver.shared.exceptions.BimServerClientException) ServiceException(org.bimserver.shared.exceptions.ServiceException) IOException(java.io.IOException) UserException(org.bimserver.shared.exceptions.UserException) ServerException(org.bimserver.shared.exceptions.ServerException) Random(java.util.Random) ServiceException(org.bimserver.shared.exceptions.ServiceException) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) UserException(org.bimserver.shared.exceptions.UserException)

Example 72 with SProject

use of org.bimserver.interfaces.objects.SProject in project BIMserver by opensourceBIM.

the class TestNewQueryViaClient method start.

private void start() {
    try (JsonBimServerClientFactory factory = new JsonBimServerClientFactory("http://localhost:8080")) {
        BimServerClient client = factory.create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
        String projectName = "Test " + new Random().nextInt();
        SProject project = client.getServiceInterface().addProject(projectName, "ifc2x3tc1");
        SDeserializerPluginConfiguration deserializer = client.getServiceInterface().getSuggestedDeserializerForExtension("ifc", project.getOid());
        client.checkin(project.getOid(), "Test Model", deserializer.getOid(), false, Flow.SYNC, Paths.get("C:/Git/TestFiles/TestData/data/AC11-FZK-Haus-IFC.ifc"));
        project = client.getServiceInterface().getProjectByPoid(project.getOid());
        System.out.println(project.getName());
        ClientIfcModel model = client.getModel(project, project.getLastRevisionId(), false, false);
        Query query = new Query(model.getPackageMetaData());
        QueryPart queryPart = query.createQueryPart();
        queryPart.addType(Ifc2x3tc1Package.eINSTANCE.getIfcWall(), true);
        for (IfcWall ifcWall : model.getAllWithSubTypes(IfcWall.class)) {
            System.out.println(ifcWall.getGlobalId());
        }
    } catch (ServiceException e) {
        e.printStackTrace();
    } catch (ChannelConnectionException e) {
        e.printStackTrace();
    } catch (PublicInterfaceNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (BimServerClientException e) {
        e.printStackTrace();
    } catch (Exception e1) {
        e1.printStackTrace();
    }
}
Also used : IfcWall(org.bimserver.models.ifc2x3tc1.IfcWall) ClientIfcModel(org.bimserver.client.ClientIfcModel) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) Query(org.bimserver.database.queries.om.Query) ChannelConnectionException(org.bimserver.shared.ChannelConnectionException) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) QueryPart(org.bimserver.database.queries.om.QueryPart) JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) IOException(java.io.IOException) SProject(org.bimserver.interfaces.objects.SProject) BimServerClientException(org.bimserver.shared.exceptions.BimServerClientException) BimServerClient(org.bimserver.client.BimServerClient) ChannelConnectionException(org.bimserver.shared.ChannelConnectionException) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) BimServerClientException(org.bimserver.shared.exceptions.BimServerClientException) ServiceException(org.bimserver.shared.exceptions.ServiceException) IOException(java.io.IOException) Random(java.util.Random) ServiceException(org.bimserver.shared.exceptions.ServiceException) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException)

Example 73 with SProject

use of org.bimserver.interfaces.objects.SProject in project BIMserver by opensourceBIM.

the class TestNotification method main.

@SuppressWarnings("unused")
public static void main(String[] args) {
    try {
        BimServerClientInterface client = LocalDevSetup.setupJson("http://localhost:8080");
        // SProject newProject = client.getServiceInterface().addProject("test" + Math.random());
        // SDeserializerPluginConfiguration deserializerByName = client.getServiceInterface().getDeserializerByName("IfcStepDeserializer");
        // client.checkin(newProject.getOid(), "test", deserializerByName.getOid(), false, true, new File("../TestData/data/AC11-Institute-Var-2-IFC.ifc"));
        // newProject = client.getServiceInterface().getProjectByPoid(newProject.getOid());
        SProject project = client.getServiceInterface().getProjectByPoid(458753L);
        SSerializerPluginConfiguration geometrySerializer = client.getServiceInterface().getSerializerByName("JsonGeometrySerializer");
        for (int i = 0; i < 100; i++) {
        // final CountDownLatch countDownLatch = new CountDownLatch(1);
        // final Long downloadByTypes = client.getServiceInterface().downloadByTypes(Collections.singleton(project.getLastRevisionId()), "ifc2x3tc1", Collections.singleton("IfcWindow"), geometrySerializer.getOid(), true, false, false, false);
        // final ProgressHandler progressHandler = new ProgressHandler() {
        // @Override
        // public void progress(SLongActionState state) {
        // if (state.getProgress() == 100) {
        // countDownLatch.countDown();
        // }
        // }
        // };
        // client.getNotificationsManager().registerProgressHandler(downloadByTypes, progressHandler);
        // try {
        // countDownLatch.await(20, TimeUnit.SECONDS);
        // client.getNotificationsManager().unregisterProgressHandler(downloadByTypes, progressHandler);
        // } catch (InterruptedException e) {
        // e.printStackTrace();
        // }
        }
        client.disconnect();
        System.out.println("Done");
    } catch (ServiceException e) {
        e.printStackTrace();
    } catch (PublicInterfaceNotFoundException e) {
        e.printStackTrace();
    }
}
Also used : ServiceException(org.bimserver.shared.exceptions.ServiceException) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) SProject(org.bimserver.interfaces.objects.SProject)

Example 74 with SProject

use of org.bimserver.interfaces.objects.SProject in project BIMserver by opensourceBIM.

the class TestUploadDir method process.

private void process(Path directory, SProject parentProject) throws ServerException, UserException, PublicInterfaceNotFoundException, IOException {
    if (Files.isDirectory(directory)) {
        SProject project = null;
        if (parentProject == null) {
            project = client.getServiceInterface().addProject(directory.getFileName().toString(), "ifc2x3tc1");
        } else {
            project = client.getServiceInterface().addProjectAsSubProject(directory.getFileName().toString(), parentProject.getOid(), "ifc2x3tc1");
        }
        for (Path file : PathUtils.list(directory)) {
            process(file, project);
        }
    } else {
        String lowerCase = directory.getFileName().toString().toLowerCase();
        if (lowerCase.endsWith("ifc") || lowerCase.endsWith("ifcxml") || lowerCase.endsWith("ifczip")) {
            SDeserializerPluginConfiguration deserializerForExtension = client.getServiceInterface().getSuggestedDeserializerForExtension(directory.getFileName().toString().substring(directory.getFileName().toString().lastIndexOf(".") + 1), parentProject.getOid());
            System.out.println("Checking in " + directory.toString() + " - " + Formatters.bytesToString(directory.toFile().length()));
            try {
                client.checkin(parentProject.getOid(), "", deserializerForExtension.getOid(), false, Flow.SYNC, directory);
            } catch (UserException e) {
                e.printStackTrace();
            }
        } else {
            System.out.println("Ignoring " + directory.toString());
        }
    }
}
Also used : Path(java.nio.file.Path) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) UserException(org.bimserver.shared.exceptions.UserException) SProject(org.bimserver.interfaces.objects.SProject)

Example 75 with SProject

use of org.bimserver.interfaces.objects.SProject in project BIMserver by opensourceBIM.

the class FileLoader method load.

private void load(Path dir) {
    // JsonBimServerClientFactory factory = new JsonBimServerClientFactory("http://sandbox.bimserver.org");
    try {
        final BimServerClientInterface client = LocalDevSetup.setupJson("http://localhost:8080");
        ExecutorService executorService = new ThreadPoolExecutor(1, 1, 1, TimeUnit.HOURS, new ArrayBlockingQueue<Runnable>(200));
        for (final Path file : PathUtils.list(dir)) {
            executorService.submit(new Runnable() {

                @Override
                public void run() {
                    System.out.println(file.getFileName());
                    SProject project;
                    try {
                        project = client.getServiceInterface().addProject(file.getFileName().toString(), "ifc2x3tc1");
                        SDeserializerPluginConfiguration deserializer = client.getServiceInterface().getSuggestedDeserializerForExtension("ifc", project.getOid());
                        client.checkin(project.getOid(), file.getFileName().toString(), deserializer.getOid(), false, Flow.SYNC, file);
                    } catch (ServerException e) {
                        e.printStackTrace();
                    } catch (UserException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    } catch (PublicInterfaceNotFoundException e) {
                        e.printStackTrace();
                    }
                }
            });
        }
        executorService.awaitTermination(1, TimeUnit.HOURS);
        System.out.println("Done");
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : Path(java.nio.file.Path) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) ServerException(org.bimserver.shared.exceptions.ServerException) IOException(java.io.IOException) SProject(org.bimserver.interfaces.objects.SProject) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) ExecutorService(java.util.concurrent.ExecutorService) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) UserException(org.bimserver.shared.exceptions.UserException)

Aggregations

SProject (org.bimserver.interfaces.objects.SProject)79 BimServerClientInterface (org.bimserver.plugins.services.BimServerClientInterface)57 UsernamePasswordAuthenticationInfo (org.bimserver.shared.UsernamePasswordAuthenticationInfo)45 Test (org.junit.Test)39 SDeserializerPluginConfiguration (org.bimserver.interfaces.objects.SDeserializerPluginConfiguration)37 SSerializerPluginConfiguration (org.bimserver.interfaces.objects.SSerializerPluginConfiguration)24 UserException (org.bimserver.shared.exceptions.UserException)24 PublicInterfaceNotFoundException (org.bimserver.shared.exceptions.PublicInterfaceNotFoundException)22 IOException (java.io.IOException)21 IfcModelInterface (org.bimserver.emf.IfcModelInterface)21 ServerException (org.bimserver.shared.exceptions.ServerException)20 URL (java.net.URL)19 LowLevelInterface (org.bimserver.shared.interfaces.LowLevelInterface)18 ServiceException (org.bimserver.shared.exceptions.ServiceException)16 BimServerClientException (org.bimserver.shared.exceptions.BimServerClientException)12 Path (java.nio.file.Path)10 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)9 DatabaseSession (org.bimserver.database.DatabaseSession)8 DeserializeException (org.bimserver.plugins.deserializers.DeserializeException)7 SerializerException (org.bimserver.plugins.serializers.SerializerException)7