Search in sources :

Example 16 with SLongCheckinActionState

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

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

the class TestIfc4TwoDimensional2 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/basin-advanced-brep.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<IfcBSplineCurveWithKnots> bSplineCurves = model.getAll(IfcBSplineCurveWithKnots.class);
            Assert.assertEquals(4, bSplineCurves.size());
            for (IfcBSplineCurveWithKnots bSplineCurve : bSplineCurves) {
                Assert.assertEquals(7, bSplineCurve.getControlPointsList().size());
                for (org.bimserver.models.ifc4.IfcCartesianPoint point : bSplineCurve.getControlPointsList()) {
                    Assert.assertNotNull(point);
                    Assert.assertTrue(point.getCoordinates().size() == 2 || point.getCoordinates().size() == 3);
                }
            }
            List<IfcBSplineSurfaceWithKnots> bSplineSurfaces = model.getAll(IfcBSplineSurfaceWithKnots.class);
            Assert.assertEquals(2, bSplineSurfaces.size());
            for (IfcBSplineSurfaceWithKnots bSplineSurface : bSplineSurfaces) {
                Assert.assertEquals(4, bSplineSurface.getControlPointsList().size());
                for (ListOfIfcCartesianPoint pointList : bSplineSurface.getControlPointsList()) {
                    // This assertion fails, error seems to be in client.
                    // 1st pointlist is of size 1, 2nd of size 2 and so on
                    // with duplication of the first point's coordinates
                    Assert.assertEquals(7, pointList.getList().size());
                    for (IfcCartesianPoint point : pointList.getList()) {
                        Assert.assertNotNull(point);
                        Assert.assertEquals(3, point.getCoordinates().size());
                    }
                }
            }
        }
        Thread.sleep(500);
    }
}
Also used : Path(java.nio.file.Path) ClientIfcModel(org.bimserver.client.ClientIfcModel) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) IfcBSplineSurfaceWithKnots(org.bimserver.models.ifc4.IfcBSplineSurfaceWithKnots) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) SLongCheckinActionState(org.bimserver.interfaces.objects.SLongCheckinActionState) IfcCartesianPoint(org.bimserver.models.ifc4.IfcCartesianPoint) SProject(org.bimserver.interfaces.objects.SProject) BimServerClient(org.bimserver.client.BimServerClient) ListOfIfcCartesianPoint(org.bimserver.models.ifc4.ListOfIfcCartesianPoint) IfcCartesianPoint(org.bimserver.models.ifc4.IfcCartesianPoint) ListOfIfcCartesianPoint(org.bimserver.models.ifc4.ListOfIfcCartesianPoint) IfcBSplineCurveWithKnots(org.bimserver.models.ifc4.IfcBSplineCurveWithKnots) Test(org.junit.Test)

Example 18 with SLongCheckinActionState

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

Example 19 with SLongCheckinActionState

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

the class TestAddExtendedData method start.

private void start() {
    try {
        BimServerClientInterface client = LocalDevSetup.setupJson("http://localhost:8080");
        SFile file = new SFile();
        file.setData("test".getBytes(Charsets.UTF_8));
        file.setMime("text");
        file.setFilename("test.txt");
        long fileId = client.getServiceInterface().uploadFile(file);
        SProject project = client.getServiceInterface().addProject("t2es035442t23", "ifc2x3tc1");
        SDeserializerPluginConfiguration deserializerForExtension = client.getServiceInterface().getSuggestedDeserializerForExtension("ifc", project.getOid());
        SLongCheckinActionState checkinSync = client.checkinSync(project.getOid(), "initial", deserializerForExtension.getOid(), false, Paths.get("../../TestFiles/TestData/data/AC11-FZK-Haus-IFC.ifc"));
        SExtendedDataSchema extendedDataSchemaByNamespace = client.getServiceInterface().getExtendedDataSchemaByName("GEOMETRY_GENERATION_REPORT_JSON_1_1");
        SExtendedData extendedData = new SExtendedData();
        extendedData.setFileId(fileId);
        extendedData.setTitle("test3");
        extendedData.setSchemaId(extendedDataSchemaByNamespace.getOid());
        client.getServiceInterface().addExtendedDataToRevision(checkinSync.getRoid(), extendedData);
    } catch (ServiceException e) {
        e.printStackTrace();
    } catch (PublicInterfaceNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) SExtendedData(org.bimserver.interfaces.objects.SExtendedData) ServiceException(org.bimserver.shared.exceptions.ServiceException) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) SLongCheckinActionState(org.bimserver.interfaces.objects.SLongCheckinActionState) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) IOException(java.io.IOException) SFile(org.bimserver.interfaces.objects.SFile) SProject(org.bimserver.interfaces.objects.SProject) SExtendedDataSchema(org.bimserver.interfaces.objects.SExtendedDataSchema)

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