Search in sources :

Example 6 with SProject

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

the class SingleCheckinAndDownload 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 = false;
        // 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
        Long progressId = -1L;
        // 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 {
        progressId = bimServerClient.checkin(newProject.getOid(), "test", deserializer.getOid(), false, Flow.SYNC, new URL("https://github.com/opensourceBIM/TestFiles/raw/master/TestData/data/AC11-Institute-Var-2-IFC.ifc"));
        // }
        // Get the status
        SLongActionState longActionState = bimServerClient.getRegistry().getProgress(progressId);
        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) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) SLongActionState(org.bimserver.interfaces.objects.SLongActionState) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SProject(org.bimserver.interfaces.objects.SProject) URL(java.net.URL) Test(org.junit.Test)

Example 7 with SProject

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

the class SingleCheckinAndDownloadSimplified method test.

@Test
public void test() {
    try {
        // Create a new BimServerClient with authentication
        BimServerClientInterface bimServerClient = getFactory().create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
        // Create a new project
        SProject newProject = bimServerClient.getServiceInterface().addProject("test" + Math.random(), "ifc2x3tc1");
        // This is the file we will be checking in
        Path ifcFile = Paths.get("../TestData/data/AC11-FZK-Haus-IFC.ifc");
        // Find a deserializer to use
        SDeserializerPluginConfiguration deserializer = bimServerClient.getServiceInterface().getSuggestedDeserializerForExtension("ifc", newProject.getOid());
        // Checkin
        bimServerClient.checkin(newProject.getOid(), "test", deserializer.getOid(), false, Flow.SYNC, ifcFile);
        // Find a serializer
        SSerializerPluginConfiguration colladaSerializer = bimServerClient.getServiceInterface().getSerializerByContentType("application/collada");
        // Get the project details
        newProject = bimServerClient.getServiceInterface().getProjectByPoid(newProject.getOid());
        // Download the latest revision  (the one we just checked in)
        // Note: sync: false
        Long topicIdId = bimServerClient.getServiceInterface().download(Collections.singleton(newProject.getLastRevisionId()), DefaultQueries.allAsString(), colladaSerializer.getOid(), false);
        InputStream downloadData = bimServerClient.getDownloadData(topicIdId);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        IOUtils.copy(downloadData, baos);
        System.out.println(baos.size() + " bytes downloaded");
    } catch (Exception e) {
        fail(e.getMessage());
    }
}
Also used : Path(java.nio.file.Path) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) InputStream(java.io.InputStream) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SProject(org.bimserver.interfaces.objects.SProject) Test(org.junit.Test)

Example 8 with SProject

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

the class TestCreateLists method test.

@Test
public void test() {
    try {
        // Create a new BimServerClient with authentication
        BimServerClientInterface bimServerClient = getFactory().create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
        LowLevelInterface lowLevelInterface = bimServerClient.getLowLevelInterface();
        // Create a new project
        SProject newProject = bimServerClient.getServiceInterface().addProject("test" + Math.random(), "ifc2x3tc1");
        // Start a transaction
        Long tid = lowLevelInterface.startTransaction(newProject.getOid());
        Long cartesianPointOid = lowLevelInterface.createObject(tid, "IfcCartesianPoint", false);
        double firstVal = 5.1;
        lowLevelInterface.addDoubleAttribute(tid, cartesianPointOid, "Coordinates", firstVal);
        double secondVal = 6.2;
        lowLevelInterface.addDoubleAttribute(tid, cartesianPointOid, "Coordinates", secondVal);
        double thirdVal = 7.3;
        lowLevelInterface.addDoubleAttribute(tid, cartesianPointOid, "Coordinates", thirdVal);
        // Commit the transaction
        lowLevelInterface.commitTransaction(tid, "test");
        tid = lowLevelInterface.startTransaction(newProject.getOid());
        List<Double> coordinates = lowLevelInterface.getDoubleAttributes(tid, cartesianPointOid, "Coordinates");
        assertTrue(coordinates.get(0) == firstVal && coordinates.get(1) == secondVal && coordinates.get(2) == thirdVal);
        tid = lowLevelInterface.startTransaction(newProject.getOid());
        ArrayList<Double> al = new ArrayList<Double>();
        al.add(1.0);
        al.add(2.0);
        al.add(3.0);
        lowLevelInterface.setDoubleAttributes(tid, cartesianPointOid, "Coordinates", al);
        lowLevelInterface.commitTransaction(tid, "replace");
        tid = lowLevelInterface.startTransaction(newProject.getOid());
        coordinates = lowLevelInterface.getDoubleAttributes(tid, cartesianPointOid, "Coordinates");
        if (coordinates.size() != 3) {
            fail("Coordinates size should be 3, it is " + coordinates.size());
        }
        assertTrue(coordinates.get(0) == 1.0 && coordinates.get(1) == 2.0 && coordinates.get(2) == 3.0);
        tid = lowLevelInterface.startTransaction(newProject.getOid());
        lowLevelInterface.setDoubleAttributeAtIndex(tid, cartesianPointOid, "Coordinates", 1, 5.0);
        lowLevelInterface.commitTransaction(tid, "changed middle one");
        tid = lowLevelInterface.startTransaction(newProject.getOid());
        coordinates = lowLevelInterface.getDoubleAttributes(tid, cartesianPointOid, "Coordinates");
        if (coordinates.size() != 3) {
            fail("Coordinates size should be 3, it is " + coordinates.size());
        }
        assertTrue(coordinates.get(0) + ", " + coordinates.get(1) + ", " + coordinates.get(2), coordinates.get(0) == 1.0 && coordinates.get(1) == 5.0 && coordinates.get(2) == 3.0);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) ArrayList(java.util.ArrayList) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) SProject(org.bimserver.interfaces.objects.SProject) LowLevelInterface(org.bimserver.shared.interfaces.LowLevelInterface) Test(org.junit.Test)

Example 9 with SProject

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

the class TestGeometry method test.

@Test
public void test() {
    try {
        // Create a new BimServerClient with authentication
        BimServerClientInterface bimServerClient = getFactory().create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
        // Get the low level interface
        LowLevelInterface lowLevelInterface = bimServerClient.getLowLevelInterface();
        // Create a new project
        SProject project = bimServerClient.getServiceInterface().addProject("test" + Math.random(), "ifc2x3tc1");
        // Look for a deserializer
        SDeserializerPluginConfiguration deserializer = bimServerClient.getServiceInterface().getSuggestedDeserializerForExtension("ifc", project.getOid());
        // Checkin file
        long start = System.nanoTime();
        bimServerClient.checkin(project.getOid(), "test", deserializer.getOid(), false, Flow.SYNC, new URL("https://github.com/opensourceBIM/TestFiles/raw/master/TestData/data/AC11-Institute-Var-2-IFC.ifc"));
        // bimServerClient.checkin(project.getOid(), "test", deserializer.getOid(), false, Flow.SYNC, Paths.get("D:\\Dropbox\\Shared\\IFC files\\ArenA 2014\\3D IFC\\arena.ifc"));
        long end = System.nanoTime();
        System.out.println(((end - start) / 1000000) + " ms");
        // Refresh project
        project = bimServerClient.getServiceInterface().getProjectByPoid(project.getOid());
        int nrTriangles = 0;
        // Load model without lazy loading (complete model at once)
        IfcModelInterface model = bimServerClient.getModel(project, project.getLastRevisionId(), true, true, true);
        Assert.assertNotNull(model.getModelMetaData().getMinBounds());
        Assert.assertNotNull(model.getModelMetaData().getMaxBounds());
        for (IfcProduct ifcProduct : model.getAllWithSubTypes(IfcProduct.class)) {
            GeometryInfo geometryInfo = ifcProduct.getGeometry();
            if (geometryInfo != null) {
                Vector3f minBounds = geometryInfo.getMinBounds();
                Vector3f maxBounds = geometryInfo.getMinBounds();
                Assert.assertNotNull(minBounds);
                Assert.assertNotNull(maxBounds);
                nrTriangles += geometryInfo.getPrimitiveCount();
            }
        }
        Assert.assertEquals(45260, nrTriangles);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) IfcModelInterface(org.bimserver.emf.IfcModelInterface) SProject(org.bimserver.interfaces.objects.SProject) URL(java.net.URL) Vector3f(org.bimserver.models.geometry.Vector3f) GeometryInfo(org.bimserver.models.geometry.GeometryInfo) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) IfcProduct(org.bimserver.models.ifc2x3tc1.IfcProduct) LowLevelInterface(org.bimserver.shared.interfaces.LowLevelInterface) Test(org.junit.Test)

Example 10 with SProject

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

the class TestRemoveObject method test.

@Test
public void test() {
    try {
        // Create a new BimServerClient with authentication
        BimServerClientInterface bimServerClient = getFactory().create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
        LowLevelInterface lowLevelInterface = bimServerClient.getLowLevelInterface();
        // Create a new project
        SProject newProject = bimServerClient.getServiceInterface().addProject("test" + Math.random(), "ifc2x3tc1");
        // Start a transaction
        Long tid = lowLevelInterface.startTransaction(newProject.getOid());
        Long ifcRelContainedInSpatialStructureOid = lowLevelInterface.createObject(tid, "IfcRelContainedInSpatialStructure", true);
        Long ifcBuildingOid = lowLevelInterface.createObject(tid, "IfcBuilding", true);
        lowLevelInterface.addReference(tid, ifcBuildingOid, "ContainsElements", ifcRelContainedInSpatialStructureOid);
        lowLevelInterface.commitTransaction(tid, "Initial");
        tid = lowLevelInterface.startTransaction(newProject.getOid());
        lowLevelInterface.removeObject(tid, ifcBuildingOid);
        lowLevelInterface.commitTransaction(tid, "removed");
        tid = lowLevelInterface.startTransaction(newProject.getOid());
        long reference = lowLevelInterface.getReference(tid, ifcRelContainedInSpatialStructureOid, "RelatingStructure");
        if (reference != -1) {
            fail("Should be unset (is " + reference + ")");
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) SProject(org.bimserver.interfaces.objects.SProject) LowLevelInterface(org.bimserver.shared.interfaces.LowLevelInterface) Test(org.junit.Test)

Aggregations

SProject (org.bimserver.interfaces.objects.SProject)79 BimServerClientInterface (org.bimserver.plugins.services.BimServerClientInterface)57 UsernamePasswordAuthenticationInfo (org.bimserver.shared.UsernamePasswordAuthenticationInfo)45 Test (org.junit.Test)39 SDeserializerPluginConfiguration (org.bimserver.interfaces.objects.SDeserializerPluginConfiguration)37 SSerializerPluginConfiguration (org.bimserver.interfaces.objects.SSerializerPluginConfiguration)24 UserException (org.bimserver.shared.exceptions.UserException)24 PublicInterfaceNotFoundException (org.bimserver.shared.exceptions.PublicInterfaceNotFoundException)22 IOException (java.io.IOException)21 IfcModelInterface (org.bimserver.emf.IfcModelInterface)21 ServerException (org.bimserver.shared.exceptions.ServerException)20 URL (java.net.URL)19 LowLevelInterface (org.bimserver.shared.interfaces.LowLevelInterface)18 ServiceException (org.bimserver.shared.exceptions.ServiceException)16 BimServerClientException (org.bimserver.shared.exceptions.BimServerClientException)12 Path (java.nio.file.Path)10 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)9 DatabaseSession (org.bimserver.database.DatabaseSession)8 DeserializeException (org.bimserver.plugins.deserializers.DeserializeException)7 SerializerException (org.bimserver.plugins.serializers.SerializerException)7