Search in sources :

Example 11 with SLongCheckinActionState

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

the class BimServerClient method checkinSync.

public SLongCheckinActionState checkinSync(long poid, String comment, long deserializerOid, Path file, CheckinProgressHandler progressHandler) throws ServerException, UserException, PublicInterfaceNotFoundException {
    long topicId = getServiceInterface().initiateCheckin(poid, deserializerOid);
    ProgressHandler progressHandlerWrapper = new ProgressHandler() {

        @Override
        public void progress(SLongActionState state) {
            progressHandler.progress(state.getTitle(), state.getProgress());
        }
    };
    getNotificationsManager().registerProgressHandler(topicId, progressHandlerWrapper);
    try (InputStream newInputStream = Files.newInputStream(file)) {
        SLongCheckinActionState checkinSync = channel.checkinSync(baseAddress, token, poid, comment, deserializerOid, false, Files.size(file), file.getFileName().toString(), newInputStream, topicId);
        getNotificationsManager().unregisterProgressHandler(topicId, progressHandlerWrapper);
        return checkinSync;
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : ProgressHandler(org.bimserver.plugins.services.ProgressHandler) CheckinProgressHandler(org.bimserver.plugins.services.CheckinProgressHandler) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) SLongCheckinActionState(org.bimserver.interfaces.objects.SLongCheckinActionState) SLongActionState(org.bimserver.interfaces.objects.SLongActionState) IOException(java.io.IOException)

Example 12 with SLongCheckinActionState

use of org.bimserver.interfaces.objects.SLongCheckinActionState 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 13 with SLongCheckinActionState

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

the class TestGetProperties 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/AC9R1-Haus-G-H-Ver2-2x3.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);
            for (IfcWall wall : model.getAllWithSubTypes(IfcWall.class)) {
                String layerName = IfcUtils.getStringProperty(wall, "Layername");
                Assert.assertNotNull(layerName);
                Assert.assertFalse(layerName.isEmpty());
            }
        }
    }
    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) 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) CheckinProgressHandler(org.bimserver.plugins.services.CheckinProgressHandler) Test(org.junit.Test)

Example 14 with SLongCheckinActionState

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

the class TestIfc4TwoDimensional3 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), "ifc4");
            SDeserializerPluginConfiguration deserializer = client.getServiceInterface().getSuggestedDeserializerForExtension("ifc", project.getOid());
            Path path = Paths.get("../../TestFiles/TestData/data/ifc4add2tc1/slab-standard-case.ifc");
            SLongCheckinActionState actionState = client.checkinSync(project.getOid(), "test", deserializer.getOid(), path, (title, progress) -> System.out.println(title + ": " + progress));
            ClientIfcModel model = client.getModel(project, actionState.getRoid(), true, false);
            List<IfcIndexedPolyCurve> polyCurves = model.getAll(IfcIndexedPolyCurve.class);
            Assert.assertEquals(1, polyCurves.size());
            for (IfcIndexedPolyCurve ifcIndexedPolyCurve : polyCurves) {
                EList<IfcSegmentIndexSelect> segments = ifcIndexedPolyCurve.getSegments();
                Assert.assertEquals(4, segments.size());
                for (IfcSegmentIndexSelect ifcSegmentIndexSelect : segments) {
                    if (ifcSegmentIndexSelect instanceof IfcLineIndex) {
                        Assert.assertEquals(2, ((IfcLineIndex) ifcSegmentIndexSelect).getWrappedValue().size());
                    } else if (ifcSegmentIndexSelect instanceof IfcArcIndex) {
                        Assert.assertEquals(3, ((IfcArcIndex) ifcSegmentIndexSelect).getWrappedValue().size());
                    }
                }
            }
        }
        Thread.sleep(500);
    }
}
Also used : Path(java.nio.file.Path) IfcLineIndex(org.bimserver.models.ifc4.IfcLineIndex) 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) IfcIndexedPolyCurve(org.bimserver.models.ifc4.IfcIndexedPolyCurve) SProject(org.bimserver.interfaces.objects.SProject) IfcArcIndex(org.bimserver.models.ifc4.IfcArcIndex) BimServerClient(org.bimserver.client.BimServerClient) IfcSegmentIndexSelect(org.bimserver.models.ifc4.IfcSegmentIndexSelect) Test(org.junit.Test)

Example 15 with SLongCheckinActionState

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

the class TestCopy 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));
            long roid = actionState.getRoid();
            client.getServiceInterface().clone(roid, "Clone-" + RandomStringUtils.randomAlphabetic(10), "Cloned", true);
        }
    }
    Thread.sleep(1000);
}
Also used : Path(java.nio.file.Path) 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) Test(org.junit.Test)

Aggregations

SLongCheckinActionState (org.bimserver.interfaces.objects.SLongCheckinActionState)19 SDeserializerPluginConfiguration (org.bimserver.interfaces.objects.SDeserializerPluginConfiguration)14 SProject (org.bimserver.interfaces.objects.SProject)14 UsernamePasswordAuthenticationInfo (org.bimserver.shared.UsernamePasswordAuthenticationInfo)11 Test (org.junit.Test)11 Path (java.nio.file.Path)10 JsonBimServerClientFactory (org.bimserver.client.json.JsonBimServerClientFactory)10 BimServerClient (org.bimserver.client.BimServerClient)9 IOException (java.io.IOException)6 InputStream (java.io.InputStream)6 ClientIfcModel (org.bimserver.client.ClientIfcModel)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 CheckinProgressHandler (org.bimserver.plugins.services.CheckinProgressHandler)5 BimServerClientInterface (org.bimserver.plugins.services.BimServerClientInterface)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 SLongActionState (org.bimserver.interfaces.objects.SLongActionState)3 UserException (org.bimserver.shared.exceptions.UserException)3 URL (java.net.URL)2 IfcModelInterface (org.bimserver.emf.IfcModelInterface)2