Search in sources :

Example 6 with CheckinProgressHandler

use of org.bimserver.plugins.services.CheckinProgressHandler 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 7 with CheckinProgressHandler

use of org.bimserver.plugins.services.CheckinProgressHandler 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 8 with CheckinProgressHandler

use of org.bimserver.plugins.services.CheckinProgressHandler in project BIMserver by opensourceBIM.

the class TestDeserializerErrorCode2 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");
            Path path = Paths.get("../../TestFiles/TestData/data/ADT-FZK-Haus-2005-2006.ifc");
            SDeserializerPluginConfiguration deserializer = client.getServiceInterface().getSuggestedDeserializerForExtension("ifc", project.getOid());
            SLongCheckinActionState checkinSync = client.checkinSync(project.getOid(), "test", deserializer.getOid(), path, new CheckinProgressHandler() {

                @Override
                public void progress(String title, int progress) {
                    System.out.println(title + ": " + progress);
                }
            });
            Assert.assertEquals(DeserializerErrorCode.IFC_SCHEMA_NOT_SUPPORTED_BY_DESERIALIZER, ErrorCode.fromCode(checkinSync.getDeserializeErrorCode()));
        }
    }
}
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) CheckinProgressHandler(org.bimserver.plugins.services.CheckinProgressHandler) BimServerClient(org.bimserver.client.BimServerClient) Test(org.junit.Test)

Example 9 with CheckinProgressHandler

use of org.bimserver.plugins.services.CheckinProgressHandler in project BIMserver by opensourceBIM.

the class TestSimultaneousCheckin 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");
            client.checkinSync(project.getOid(), "test", deserializer.getOid(), path, new CheckinProgressHandler() {

                @Override
                public void progress(String title, int progress) {
                    System.out.println(title + ": " + progress);
                }
            });
        }
        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) SProject(org.bimserver.interfaces.objects.SProject) CheckinProgressHandler(org.bimserver.plugins.services.CheckinProgressHandler) BimServerClient(org.bimserver.client.BimServerClient) Test(org.junit.Test)

Example 10 with CheckinProgressHandler

use of org.bimserver.plugins.services.CheckinProgressHandler in project BIMserver by opensourceBIM.

the class TestCheckinWithProgress method test.

@Test
public void test() {
    try {
        // Create a new BimServerClient with authentication
        BimServerClientInterface bimServerClient = getFactory().create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
        // When you use the channel for checkin/download calls, all data will have to be converted to the used channel's format, for example for JSON, binary data will be Base64 encoded, which will make things slower and larger
        // The alternative is to use the Servlets, those will also use compression where possible
        // Using the channel is slower
        boolean useChannel = true;
        // Create a new project
        SProject newProject = bimServerClient.getServiceInterface().addProject("test" + Math.random(), "ifc2x3tc1");
        // Find a deserializer to use
        SDeserializerPluginConfiguration deserializer = bimServerClient.getServiceInterface().getSuggestedDeserializerForExtension("ifc", newProject.getOid());
        // Checkin
        // if (useChannel) {
        // progressId = bimServerClient.getServiceInterface().checkin(newProject.getOid(), "test", deserializer.getOid(), ifcFile.toFile().length(), ifcFile.getFileName().toString(), new DataHandler(new FileDataSource(ifcFile.toFile())), true, true);
        // } else {
        SLongCheckinActionState longActionState = bimServerClient.checkin(newProject.getOid(), "test", deserializer.getOid(), new URL("https://github.com/opensourceBIM/TestFiles/raw/master/TestData/data/AC11-Institute-Var-2-IFC.ifc"), new CheckinProgressHandler() {

            @Override
            public void progress(String title, int progress) {
                System.out.println(title + ": " + progress);
            }
        });
        if (longActionState.getState() == SActionState.FINISHED) {
            // Find a serializer
            SSerializerPluginConfiguration serializer = bimServerClient.getServiceInterface().getSerializerByContentType("application/ifc");
            // Get the project details
            newProject = bimServerClient.getServiceInterface().getProjectByPoid(newProject.getOid());
            // Download the latest revision  (the one we just checked in)
            if (useChannel) {
                Long topicId = bimServerClient.getServiceInterface().download(Collections.singleton(newProject.getLastRevisionId()), DefaultQueries.allAsString(), serializer.getOid(), true);
                SLongActionState downloadState = bimServerClient.getRegistry().getProgress(topicId);
                if (downloadState.getState() == SActionState.FINISHED) {
                    InputStream inputStream = bimServerClient.getServiceInterface().getDownloadData(topicId).getFile().getInputStream();
                    IOUtils.copy(inputStream, new ByteArrayOutputStream());
                    System.out.println("Success");
                }
            } else {
                // Note: sync: false
                Long topicId = bimServerClient.getServiceInterface().download(Collections.singleton(newProject.getLastRevisionId()), DefaultQueries.allAsString(), serializer.getOid(), false);
                InputStream downloadData = bimServerClient.getDownloadData(topicId);
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                IOUtils.copy(downloadData, baos);
                System.out.println(baos.size() + " bytes downloaded");
            }
        } else {
            System.out.println(longActionState.getState());
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) InputStream(java.io.InputStream) SLongCheckinActionState(org.bimserver.interfaces.objects.SLongCheckinActionState) SLongActionState(org.bimserver.interfaces.objects.SLongActionState) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SProject(org.bimserver.interfaces.objects.SProject) URL(java.net.URL) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) CheckinProgressHandler(org.bimserver.plugins.services.CheckinProgressHandler) Test(org.junit.Test)

Aggregations

CheckinProgressHandler (org.bimserver.plugins.services.CheckinProgressHandler)10 SDeserializerPluginConfiguration (org.bimserver.interfaces.objects.SDeserializerPluginConfiguration)7 SProject (org.bimserver.interfaces.objects.SProject)7 Path (java.nio.file.Path)6 SLongCheckinActionState (org.bimserver.interfaces.objects.SLongCheckinActionState)6 UsernamePasswordAuthenticationInfo (org.bimserver.shared.UsernamePasswordAuthenticationInfo)6 Test (org.junit.Test)6 BimServerClient (org.bimserver.client.BimServerClient)5 JsonBimServerClientFactory (org.bimserver.client.json.JsonBimServerClientFactory)5 SLongActionState (org.bimserver.interfaces.objects.SLongActionState)4 InputStream (java.io.InputStream)3 ClientIfcModel (org.bimserver.client.ClientIfcModel)3 ProgressHandler (org.bimserver.plugins.services.ProgressHandler)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 URL (java.net.URL)1 SSerializerPluginConfiguration (org.bimserver.interfaces.objects.SSerializerPluginConfiguration)1 SServerInfo (org.bimserver.interfaces.objects.SServerInfo)1 GeometryInfo (org.bimserver.models.geometry.GeometryInfo)1