Search in sources :

Example 1 with BimServerClient

use of org.bimserver.client.BimServerClient in project BIMserver by opensourceBIM.

the class TestServerRestart method test.

// @Test // This test requires user interaction, should be moved to non/semiautomated tests in Test module
public void test() {
    try (JsonBimServerClientFactory factory = new JsonBimServerClientFactory("http://localhost:8080")) {
        try (BimServerClient client = factory.create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"))) {
            try (Scanner scanner = new Scanner(System.in)) {
                for (int i = 0; i < 10; i++) {
                    System.out.println("Restart server now, then press key");
                    scanner.nextLine();
                    try {
                        checkin(client);
                    } catch (UserException e) {
                        if (e.getErrorCode() == DefaultErrorCode.ENDPOINT_NOT_FOUND) {
                            client.getNotificationsManager().startAndWaitForInit();
                            checkin(client);
                        } else {
                            System.err.println(e.getMessage());
                        }
                    }
                }
            }
            Thread.sleep(5000);
        }
    } catch (BimServerClientException e) {
        e.printStackTrace();
    } catch (Exception e1) {
        e1.printStackTrace();
    }
}
Also used : Scanner(java.util.Scanner) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) UserException(org.bimserver.shared.exceptions.UserException) BimServerClientException(org.bimserver.shared.exceptions.BimServerClientException) BimServerClient(org.bimserver.client.BimServerClient) BimServerClientException(org.bimserver.shared.exceptions.BimServerClientException) UserException(org.bimserver.shared.exceptions.UserException) ServerException(org.bimserver.shared.exceptions.ServerException)

Example 2 with BimServerClient

use of org.bimserver.client.BimServerClient in project BIMserver by opensourceBIM.

the class TestGetGeometry2 method test.

@Test
public void test() throws Exception {
    try (JsonBimServerClientFactory factory = new JsonBimServerClientFactory("http://localhost:8080")) {
        try (BimServerClient client = factory.create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"))) {
            SProject project = client.getServiceInterface().addProject(RandomStringUtils.randomAlphanumeric(10), "ifc2x3tc1");
            SDeserializerPluginConfiguration deserializer = client.getServiceInterface().getSuggestedDeserializerForExtension("ifc", project.getOid());
            Path path = Paths.get("../../TestFiles/TestData/data/export1.ifc");
            SLongCheckinActionState actionState = client.checkinSync(project.getOid(), "test", deserializer.getOid(), path, new CheckinProgressHandler() {

                @Override
                public void progress(String title, int progress) {
                    System.out.println(title + ": " + progress);
                }
            });
            ClientIfcModel model = client.getModel(project, actionState.getRoid(), false, false, true);
            for (IfcProduct product : model.getAllWithSubTypes(IfcProduct.class)) {
                GeometryInfo geometry = product.getGeometry();
                if (geometry != null) {
                    System.out.println(product.getGeometry().getData().getNrVertices());
                    System.out.println(product.getGeometry().getData().getVertices().getData().length);
                }
            }
        }
    }
    Thread.sleep(1000);
}
Also used : Path(java.nio.file.Path) ClientIfcModel(org.bimserver.client.ClientIfcModel) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) SLongCheckinActionState(org.bimserver.interfaces.objects.SLongCheckinActionState) SProject(org.bimserver.interfaces.objects.SProject) BimServerClient(org.bimserver.client.BimServerClient) GeometryInfo(org.bimserver.models.geometry.GeometryInfo) IfcProduct(org.bimserver.models.ifc2x3tc1.IfcProduct) CheckinProgressHandler(org.bimserver.plugins.services.CheckinProgressHandler) Test(org.junit.Test)

Example 3 with BimServerClient

use of org.bimserver.client.BimServerClient in project BIMserver by opensourceBIM.

the class TestGetUuid method test.

@Test
public void test() throws Exception {
    try (JsonBimServerClientFactory factory = new JsonBimServerClientFactory("http://localhost:8080")) {
        try (BimServerClient client = factory.create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"))) {
            SServerInfo serverInfo = client.getAdminInterface().getServerInfo();
            System.out.println(serverInfo.getServerState());
            System.out.println(serverInfo.getUuid());
            SProject project = client.getServiceInterface().addProject(RandomStringUtils.randomAlphanumeric(10), "ifc2x3tc1");
            SDeserializerPluginConfiguration deserializer = client.getServiceInterface().getSuggestedDeserializerForExtension("ifc", project.getOid());
            Path path = Paths.get("../../TestFiles/TestData/data/AC11-Institute-Var-2-IFC.ifc");
            client.checkinSync(project.getOid(), "test", deserializer.getOid(), path, new CheckinProgressHandler() {

                @Override
                public void progress(String title, int progress) {
                    System.out.println(title + ": " + progress);
                }
            });
            project = client.getServiceInterface().getProjectByPoid(project.getOid());
            ClientIfcModel model = client.getModel(project, project.getLastRevisionId(), true, true);
            for (IfcBuildingStorey ifcBuildingStorey : model.getAll(IfcBuildingStorey.class)) {
                System.out.println(ifcBuildingStorey.getUuid() + ":" + ifcBuildingStorey.getRid());
            }
            System.out.println("Length unit: " + IfcUtils.getLengthUnitPrefix(model));
            IfcProject ifcProject = model.getAll(IfcProject.class).iterator().next();
            ifcProject.setName(ifcProject.getName() + " updated");
            long newRoid = model.commit("commit message");
            model = client.getModel(project, newRoid, true, true);
            ifcProject = model.getAll(IfcProject.class).iterator().next();
            System.out.println(ifcProject.getName());
        }
    }
    Thread.sleep(1000);
}
Also used : Path(java.nio.file.Path) IfcProject(org.bimserver.models.ifc2x3tc1.IfcProject) ClientIfcModel(org.bimserver.client.ClientIfcModel) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) SProject(org.bimserver.interfaces.objects.SProject) BimServerClient(org.bimserver.client.BimServerClient) SServerInfo(org.bimserver.interfaces.objects.SServerInfo) CheckinProgressHandler(org.bimserver.plugins.services.CheckinProgressHandler) IfcBuildingStorey(org.bimserver.models.ifc2x3tc1.IfcBuildingStorey) Test(org.junit.Test)

Example 4 with BimServerClient

use of org.bimserver.client.BimServerClient in project BIMserver by opensourceBIM.

the class SoapBimServerClientFactory method create.

@Override
public BimServerClient create(AuthenticationInfo authenticationInfo) throws ServiceException, ChannelConnectionException {
    SoapChannel soapChannel = new SoapChannel(getHttpClient(), address + "/soap11", true, getServicesMap().getInterfaceClasses());
    BimServerClient bimServerClient = new BimServerClient(this.getMetaDataManager(), address, getServicesMap(), soapChannel);
    soapChannel.connect(bimServerClient);
    bimServerClient.setAuthentication(authenticationInfo);
    bimServerClient.connect();
    return bimServerClient;
}
Also used : BimServerClient(org.bimserver.client.BimServerClient)

Example 5 with BimServerClient

use of org.bimserver.client.BimServerClient in project BIMserver by opensourceBIM.

the class TestGetGeometry method test.

@Test
public void test() throws Exception {
    try (JsonBimServerClientFactory factory = new JsonBimServerClientFactory("http://localhost:8080")) {
        try (BimServerClient client = factory.create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"))) {
            SProject project = client.getServiceInterface().addProject(RandomStringUtils.randomAlphanumeric(10), "ifc2x3tc1");
            SDeserializerPluginConfiguration deserializer = client.getServiceInterface().getSuggestedDeserializerForExtension("ifc", project.getOid());
            Path path = Paths.get("../../TestFiles/TestData/data/export1.ifc");
            SLongCheckinActionState actionState = client.checkinSync(project.getOid(), "test", deserializer.getOid(), path, (title, progress) -> System.out.println(title + ": " + progress));
            PackageMetaData packageMetaData = client.getMetaDataManager().getPackageMetaData("ifc2x3tc1");
            GeometryTargetImpl geometryTargetImpl = new GeometryTargetImpl(packageMetaData);
            GeometryLoader geometryLoader = new GeometryLoader(client, packageMetaData, geometryTargetImpl);
            Set<Long> oids = new HashSet<>();
            // Only to gather oids
            ClientIfcModel model = client.getModel(project, actionState.getRoid(), true, false, false);
            for (IfcWall ifcWall : model.getAllWithSubTypes(IfcWall.class)) {
                oids.add(ifcWall.getOid());
            }
            geometryLoader.loadProducts(actionState.getRoid(), oids);
            System.out.println(geometryTargetImpl);
            Set<Long> geometryDataOids = new HashSet<>();
            for (GeometryInfo geometryInfo : geometryTargetImpl.getAllGeometryInfo()) {
                GeometryData geometryData = geometryInfo.getData();
                System.out.println(geometryInfo.getPrimitiveCount());
                System.out.println(geometryData.getNrIndices());
                geometryDataOids.add(geometryData.getOid());
            }
            geometryTargetImpl = new GeometryTargetImpl(packageMetaData);
            geometryLoader = new GeometryLoader(client, packageMetaData, geometryTargetImpl);
            geometryLoader.loadGeometryData(actionState.getRoid(), geometryDataOids);
            System.out.println(geometryTargetImpl);
        }
    }
    Thread.sleep(1000);
}
Also used : Path(java.nio.file.Path) IfcWall(org.bimserver.models.ifc2x3tc1.IfcWall) ClientIfcModel(org.bimserver.client.ClientIfcModel) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) GeometryTargetImpl(org.bimserver.client.GeometryTargetImpl) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) PackageMetaData(org.bimserver.emf.PackageMetaData) JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) SLongCheckinActionState(org.bimserver.interfaces.objects.SLongCheckinActionState) GeometryData(org.bimserver.models.geometry.GeometryData) SProject(org.bimserver.interfaces.objects.SProject) GeometryLoader(org.bimserver.client.GeometryLoader) BimServerClient(org.bimserver.client.BimServerClient) GeometryInfo(org.bimserver.models.geometry.GeometryInfo) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

BimServerClient (org.bimserver.client.BimServerClient)27 JsonBimServerClientFactory (org.bimserver.client.json.JsonBimServerClientFactory)23 UsernamePasswordAuthenticationInfo (org.bimserver.shared.UsernamePasswordAuthenticationInfo)23 SProject (org.bimserver.interfaces.objects.SProject)20 SDeserializerPluginConfiguration (org.bimserver.interfaces.objects.SDeserializerPluginConfiguration)15 Test (org.junit.Test)15 Path (java.nio.file.Path)14 ClientIfcModel (org.bimserver.client.ClientIfcModel)11 SLongCheckinActionState (org.bimserver.interfaces.objects.SLongCheckinActionState)9 BimServerClientException (org.bimserver.shared.exceptions.BimServerClientException)6 CheckinProgressHandler (org.bimserver.plugins.services.CheckinProgressHandler)5 GeometryInfo (org.bimserver.models.geometry.GeometryInfo)3 IfcWall (org.bimserver.models.ifc2x3tc1.IfcWall)3 PublicInterfaceNotFoundException (org.bimserver.shared.exceptions.PublicInterfaceNotFoundException)3 DateFormat (java.text.DateFormat)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 Query (org.bimserver.database.queries.om.Query)2 QueryPart (org.bimserver.database.queries.om.QueryPart)2 PackageMetaData (org.bimserver.emf.PackageMetaData)2