Search in sources :

Example 16 with BimServerClient

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

the class GetGeometry method main.

public static void main(String[] args) throws BimServerClientException, Exception {
    try (JsonBimServerClientFactory factory = new JsonBimServerClientFactory("http://localhost:8080")) {
        try (BimServerClient client = factory.create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"))) {
            SProject project = client.getServiceInterface().getTopLevelProjectByName("Types");
            ClientIfcModel model = client.getModel(project, project.getLastRevisionId(), true, false, true);
            for (IfcProduct ifcProduct : model.getAllWithSubTypes(IfcProduct.class)) {
                if (ifcProduct.getGeometry() == null) {
                    boolean hasParts = false;
                    for (IfcRelDecomposes ifcRelDecomposes : ifcProduct.getIsDecomposedBy()) {
                        for (IfcObjectDefinition ifcObjectDefinition : ifcRelDecomposes.getRelatedObjects()) {
                            if (ifcObjectDefinition instanceof IfcProduct) {
                                hasParts = true;
                                if (((IfcProduct) ifcObjectDefinition).getGeometry() == null) {
                                    checkGeometry(((IfcProduct) ifcObjectDefinition));
                                }
                            }
                        }
                    }
                    if (!hasParts) {
                        checkGeometry(ifcProduct);
                    }
                }
            }
        }
    }
}
Also used : ClientIfcModel(org.bimserver.client.ClientIfcModel) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) IfcObjectDefinition(org.bimserver.models.ifc2x3tc1.IfcObjectDefinition) IfcProduct(org.bimserver.models.ifc2x3tc1.IfcProduct) SProject(org.bimserver.interfaces.objects.SProject) BimServerClient(org.bimserver.client.BimServerClient) IfcRelDecomposes(org.bimserver.models.ifc2x3tc1.IfcRelDecomposes)

Example 17 with BimServerClient

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

the class TestCheckinFromUrlAsync 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.random(10), "ifc2x3tc1");
            SDeserializerPluginConfiguration deserializer = client.getServiceInterface().getSuggestedDeserializerForExtension("ifc", project.getOid());
            String url = "https://github.com/opensourceBIM/TestFiles/raw/master/TestData/data/AC11-Institute-Var-2-IFC.ifc";
            Long topicId = client.getServiceInterface().checkinFromUrlAsync(project.getOid(), "test", deserializer.getOid(), "test", url, false);
            for (int i = 0; i < 100; i++) {
                SLongActionState progress = client.getNotificationRegistryInterface().getProgress(topicId);
                System.out.println(progress.getState());
                if (progress.getState() == SActionState.FINISHED) {
                    break;
                }
                Thread.sleep(1000);
            }
        }
    }
}
Also used : SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) SLongActionState(org.bimserver.interfaces.objects.SLongActionState) SProject(org.bimserver.interfaces.objects.SProject) BimServerClient(org.bimserver.client.BimServerClient) Test(org.junit.Test)

Example 18 with BimServerClient

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

the class TestCheckinAndGeometryDownload method test.

@Test
public void test() throws Exception {
    try (JsonBimServerClientFactory factory = new JsonBimServerClientFactory("http://localhost:8080")) {
        for (int i = 0; i < 100; i++) {
            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 checkinSync = client.checkinSync(project.getOid(), "test", deserializer.getOid(), path, (title, progress) -> {
                });
                PackageMetaData packageMetaData = client.getMetaDataManager().getPackageMetaData("ifc2x3tc1");
                Query query = new Query(packageMetaData);
                QueryPart queryPart = query.createQueryPart();
                queryPart.addType(packageMetaData.getEClass("IfcProduct"), true);
                Tiles tiles = new Tiles();
                tiles.add(0);
                tiles.setMaximumThreshold(1000);
                tiles.setMaxDepth(0);
                queryPart.setTiles(tiles);
                Include include1 = queryPart.createInclude();
                include1.addType(packageMetaData.getEClass("IfcProduct"), true);
                include1.addField("geometry");
                Include include2 = include1.createInclude();
                include2.addType(GeometryPackage.eINSTANCE.getGeometryInfo(), false);
                include2.addField("data");
                Include include3 = include2.createInclude();
                include3.addType(GeometryPackage.eINSTANCE.getGeometryData(), false);
                include3.addFieldDirect("indices");
                include3.addFieldDirect("normals");
                include3.addFieldDirect("normalsQuantized");
                include3.addFieldDirect("vertices");
                include3.addFieldDirect("verticesQuantized");
                include3.addFieldDirect("colorsQuantized");
                include3.addFieldDirect("colorPack");
                SSerializerPluginConfiguration serializer = client.getPluginInterface().getSerializerByPluginClassName("org.bimserver.serializers.binarygeometry.BinaryGeometryMessagingStreamingSerializerPlugin");
                ObjectNode queryJson = new JsonQueryObjectModelConverter(packageMetaData).toJson(query);
                queryJson.set("loaderSettings", generateLoaderSettings());
                String queryString = queryJson.toString();
                Long topicId = client.getServiceInterface().download(Collections.singleton(checkinSync.getRoid()), queryString, serializer.getOid(), false);
                ObjectNode downloadMessage = OBJECT_MAPPER.createObjectNode();
                downloadMessage.put("action", "download");
                downloadMessage.put("token", client.getToken());
                downloadMessage.put("topicId", topicId);
                CountDownLatch doneCountdown = new CountDownLatch(1);
                client.getNotificationsManager().setBinaryMessageListener(topicId, new BinaryMessageListener() {

                    @Override
                    public void newData(byte[] bytes, int start, int length) {
                        ByteBuffer buffer = ByteBuffer.wrap(bytes, start, length).order(ByteOrder.LITTLE_ENDIAN);
                        // TopicId
                        buffer.getLong();
                        int type = buffer.getInt();
                        if (type == 0) {
                        } else if (type == 1) {
                            doneCountdown.countDown();
                        }
                    }
                });
                client.getNotificationsManager().send(downloadMessage);
                if (!doneCountdown.await(5, TimeUnit.MINUTES)) {
                    LOGGER.error("Not finished after 5 minutes!");
                }
                LOGGER.info("Done");
                client.getServiceInterface().cleanupLongAction(topicId);
            }
        }
    }
    Thread.sleep(30000);
}
Also used : Path(java.nio.file.Path) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) JsonQueryObjectModelConverter(org.bimserver.database.queries.om.JsonQueryObjectModelConverter) Query(org.bimserver.database.queries.om.Query) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) PackageMetaData(org.bimserver.emf.PackageMetaData) QueryPart(org.bimserver.database.queries.om.QueryPart) JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) SLongCheckinActionState(org.bimserver.interfaces.objects.SLongCheckinActionState) Include(org.bimserver.database.queries.om.Include) SProject(org.bimserver.interfaces.objects.SProject) CountDownLatch(java.util.concurrent.CountDownLatch) BinaryMessageListener(org.bimserver.client.notifications.BinaryMessageListener) ByteBuffer(java.nio.ByteBuffer) BimServerClient(org.bimserver.client.BimServerClient) Tiles(org.bimserver.database.queries.om.Tiles) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) Test(org.junit.Test)

Example 19 with BimServerClient

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

the class TestCheckinUTF8From 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/174240904075130-12-泰州金融中心(全).IFC");
            client.checkinSync(project.getOid(), "test", deserializer.getOid(), path, (title, progress) -> System.out.println(title + ": " + progress));
        }
    }
}
Also used : Path(java.nio.file.Path) 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) Test(org.junit.Test)

Example 20 with BimServerClient

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

the class TestDeserializerErrorCode 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"))) {
            Path path = Paths.get("../../TestFiles/TestData/data/ADT-FZK-Haus-2005-2006.ifc");
            try (InputStream fis = Files.newInputStream(path)) {
                byte[] initialBytes = ByteUtils.extractHead(new BufferedInputStream(fis), 4096);
                client.getServiceInterface().determineIfcVersion(initialBytes, false);
            }
        }
        Assert.fail("Expected UserException to be thrown");
    } catch (UserException e1) {
        Assert.assertEquals(DeserializerErrorCode.UNSUPPORTED_IFC_SCHEMA_VERSION, e1.getErrorCode());
    }
}
Also used : Path(java.nio.file.Path) BufferedInputStream(java.io.BufferedInputStream) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) UserException(org.bimserver.shared.exceptions.UserException) BimServerClient(org.bimserver.client.BimServerClient) 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