Search in sources :

Example 16 with UsernamePasswordAuthenticationInfo

use of org.bimserver.shared.UsernamePasswordAuthenticationInfo in project BIMserver by opensourceBIM.

the class TestRemoveReferenceList method test.

// This test makes no sense, since getContainedInStructure is a Set (unordered)
@Test
public void test() {
    try {
        // Create a new BimServerClient with authentication
        BimServerClientInterface bimServerClient = getFactory().create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
        // Get the service interface
        bimServerClient.getSettingsInterface().setGenerateGeometryOnCheckin(false);
        // Create a new project
        SProject newProject = bimServerClient.getServiceInterface().addProject("test" + Math.random(), "ifc2x3tc1");
        IfcModelInterface model = bimServerClient.newModel(newProject, true);
        IfcFurnishingElement furnishingElement = model.create(IfcFurnishingElement.class);
        furnishingElement.setName("Furnishing 1");
        IfcRelContainedInSpatialStructure link1 = model.create(IfcRelContainedInSpatialStructure.class);
        link1.setName("link1");
        IfcRelContainedInSpatialStructure link2 = model.create(IfcRelContainedInSpatialStructure.class);
        link2.setName("link2");
        IfcRelContainedInSpatialStructure link3 = model.create(IfcRelContainedInSpatialStructure.class);
        link3.setName("link3");
        link1.getRelatedElements().add(furnishingElement);
        link2.getRelatedElements().add(furnishingElement);
        link3.getRelatedElements().add(furnishingElement);
        model.commit("initial");
        // refresh
        newProject = bimServerClient.getServiceInterface().getProjectByPoid(newProject.getOid());
        bimServerClient.download(newProject.getLastRevisionId(), bimServerClient.getServiceInterface().getSerializerByContentType("application/ifc").getOid(), Paths.get("testX.ifc"));
        model = bimServerClient.getModel(newProject, newProject.getLastRevisionId(), true, true);
        for (IfcFurnishingElement ifcFurnishingElement : model.getAll(IfcFurnishingElement.class)) {
            if (ifcFurnishingElement.getContainedInStructure().size() != 3) {
                fail("Size should be 3, is " + ifcFurnishingElement.getContainedInStructure().size());
            }
            // Remove the middle one
            IfcRelContainedInSpatialStructure middleOne = null;
            for (IfcRelContainedInSpatialStructure rel : ifcFurnishingElement.getContainedInStructure()) {
                if (rel.getName().equals("link2")) {
                    middleOne = rel;
                    break;
                }
            }
            ifcFurnishingElement.getContainedInStructure().remove(middleOne);
        }
        model.commit("removed middle link");
        // refresh
        newProject = bimServerClient.getServiceInterface().getProjectByPoid(newProject.getOid());
        model = bimServerClient.getModel(newProject, newProject.getLastRevisionId(), true, false);
        for (IfcFurnishingElement ifcFurnishingElement : model.getAll(IfcFurnishingElement.class)) {
            assertTrue("Size should be 2, is " + ifcFurnishingElement.getContainedInStructure().size(), ifcFurnishingElement.getContainedInStructure().size() == 2);
            assertEquals("link", "link1", ifcFurnishingElement.getContainedInStructure().get(0).getName());
            assertEquals("link", "link3", ifcFurnishingElement.getContainedInStructure().get(1).getName());
        }
    } catch (Throwable e) {
        e.printStackTrace();
        if (e instanceof AssertionError) {
            throw (AssertionError) e;
        }
        fail(e.getMessage());
    }
}
Also used : IfcFurnishingElement(org.bimserver.models.ifc2x3tc1.IfcFurnishingElement) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) IfcModelInterface(org.bimserver.emf.IfcModelInterface) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) IfcRelContainedInSpatialStructure(org.bimserver.models.ifc2x3tc1.IfcRelContainedInSpatialStructure) SProject(org.bimserver.interfaces.objects.SProject) Test(org.junit.Test)

Example 17 with UsernamePasswordAuthenticationInfo

use of org.bimserver.shared.UsernamePasswordAuthenticationInfo in project BIMserver by opensourceBIM.

the class TestManyRevisions method start.

private void start(String[] args) {
    try {
        Path home = Paths.get("home");
        PluginManager pluginManager = LocalDevPluginLoader.createPluginManager(home);
        MetaDataManager metaDataManager = new MetaDataManager(home.resolve("tmp"));
        pluginManager.setMetaDataManager(metaDataManager);
        try (BimServerClientFactory factory = new JsonBimServerClientFactory(metaDataManager, "http://localhost:8080")) {
            BimServerClientInterface client = factory.create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
            try {
                SProject project = client.getServiceInterface().addProject("lots2", "ifc2x3tc1");
                Path[] files = new Path[] { Paths.get("../TestData/data/AC11-Institute-Var-2-IFC.ifc"), Paths.get("../TestData/data/AC11-FZK-Haus-IFC - Alt.ifc") };
                SDeserializerPluginConfiguration deserializer = client.getServiceInterface().getSuggestedDeserializerForExtension("ifc", project.getOid());
                int fn = 0;
                for (int i = 0; i < 20; i++) {
                    System.out.println(i + ": " + files[fn].getFileName().toString());
                    client.checkin(project.getOid(), "comment" + i, deserializer.getOid(), false, Flow.SYNC, files[fn]);
                    fn = 1 - fn;
                }
            } catch (ServerException | UserException | PublicInterfaceNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Path(java.nio.file.Path) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) ServerException(org.bimserver.shared.exceptions.ServerException) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) MetaDataManager(org.bimserver.emf.MetaDataManager) IOException(java.io.IOException) SProject(org.bimserver.interfaces.objects.SProject) JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) BimServerClientFactory(org.bimserver.shared.BimServerClientFactory) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) IOException(java.io.IOException) UserException(org.bimserver.shared.exceptions.UserException) ServerException(org.bimserver.shared.exceptions.ServerException) PluginManager(org.bimserver.plugins.PluginManager) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) UserException(org.bimserver.shared.exceptions.UserException)

Example 18 with UsernamePasswordAuthenticationInfo

use of org.bimserver.shared.UsernamePasswordAuthenticationInfo in project BIMserver by opensourceBIM.

the class TestBigModelEmf method test.

@Test
public void test() {
    try {
        BimServerClientInterface bimServerClient = getFactory().create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
        SProject newProject = bimServerClient.getServiceInterface().addProject("test" + Math.random(), "ifc2x3tc1");
        IfcModelInterface model = bimServerClient.newModel(newProject, true);
        RichIfcModel richIfcModel = new RichIfcModel(model);
        IfcBuilding ifcBuilding = richIfcModel.createDefaultProjectStructure();
        IfcRelAggregates buildingAggregation = richIfcModel.create(IfcRelAggregates.class);
        buildingAggregation.setRelatingObject(ifcBuilding);
        for (int i = 1; i <= 10; i++) {
            IfcBuildingStorey ifcBuildingStorey = richIfcModel.create(IfcBuildingStorey.class);
            ifcBuildingStorey.setName("Storey " + i);
            ifcBuildingStorey.setCompositionType(IfcElementCompositionEnum.ELEMENT);
            ifcBuildingStorey.setElevation(3000 * i);
            IfcLocalPlacement storeyPlacement = richIfcModel.create(IfcLocalPlacement.class);
            storeyPlacement.setRelativePlacement(richIfcModel.createBasicPosition(0, 0, i * 3000));
            ifcBuildingStorey.setObjectPlacement(storeyPlacement);
            buildingAggregation.getRelatedObjects().add(ifcBuildingStorey);
            IfcRelAggregates storeyAggregation = richIfcModel.create(IfcRelAggregates.class);
            storeyAggregation.setRelatingObject(ifcBuildingStorey);
            for (int x = 1; x <= 10; x++) {
                for (int y = 1; y <= 10; y++) {
                    createSpace(richIfcModel, richIfcModel.getDefaultRepresentationContext(), storeyPlacement, storeyAggregation, x, y);
                }
            }
        }
        long roid = model.commit("Initial model");
        SSerializerPluginConfiguration serializerByContentType = bimServerClient.getServiceInterface().getSerializerByName("Ifc2x3tc1 (Streaming)");
        bimServerClient.download(roid, serializerByContentType.getOid(), new FileOutputStream(new File("created.ifc")));
    } catch (Throwable e) {
        e.printStackTrace();
        if (e instanceof AssertionError) {
            throw (AssertionError) e;
        }
        fail(e.getMessage());
    }
}
Also used : RichIfcModel(org.bimserver.utils.RichIfcModel) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) IfcModelInterface(org.bimserver.emf.IfcModelInterface) SProject(org.bimserver.interfaces.objects.SProject) IfcRelAggregates(org.bimserver.models.ifc2x3tc1.IfcRelAggregates) IfcLocalPlacement(org.bimserver.models.ifc2x3tc1.IfcLocalPlacement) FileOutputStream(java.io.FileOutputStream) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) IfcBuildingStorey(org.bimserver.models.ifc2x3tc1.IfcBuildingStorey) File(java.io.File) IfcBuilding(org.bimserver.models.ifc2x3tc1.IfcBuilding) Test(org.junit.Test)

Example 19 with UsernamePasswordAuthenticationInfo

use of org.bimserver.shared.UsernamePasswordAuthenticationInfo in project BIMserver by opensourceBIM.

the class TestChangeGeometryError 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");
        // Look for a deserializer
        SDeserializerPluginConfiguration deserializer = bimServerClient.getServiceInterface().getSuggestedDeserializerForExtension("ifc", newProject.getOid());
        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"));
        newProject = bimServerClient.getServiceInterface().getProjectByPoid(newProject.getOid());
        IfcModelInterface model = bimServerClient.getModel(newProject, newProject.getLastRevisionId(), false, true, true);
        List<IfcWall> walls = model.getAllWithSubTypes(Ifc2x3tc1Package.eINSTANCE.getIfcWall());
        IfcWall firstWall = walls.get(0);
        firstWall.getGeometry().getData().setVertices(new byte[10]);
        model.commit("Tried to change geometry, which should not be possible");
        fail("This have thrown an error");
    } catch (Throwable e) {
        if (e instanceof AssertionError) {
            throw (AssertionError) e;
        }
        e.printStackTrace();
        assertEquals("Only objects from the following schemas are allowed to be changed: Ifc2x3tc1 and IFC4, this object (GeometryData) is from the \"geometry\" package", e.getMessage());
    }
}
Also used : IfcWall(org.bimserver.models.ifc2x3tc1.IfcWall) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) IfcModelInterface(org.bimserver.emf.IfcModelInterface) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) SProject(org.bimserver.interfaces.objects.SProject) URL(java.net.URL) Test(org.junit.Test)

Example 20 with UsernamePasswordAuthenticationInfo

use of org.bimserver.shared.UsernamePasswordAuthenticationInfo in project BIMserver by opensourceBIM.

the class TestInstall method main.

public static void main(String[] args) {
    ArrayList<String> pluginList = new ArrayList<>();
    pluginList.add("C:/plugins/ifcplugins-0.0.15.jar");
    try (BimServerClientFactory factory = new JsonBimServerClientFactory("http://localhost:8080")) {
        BimServerClientInterface client = factory.create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
        for (String each : pluginList) {
            try {
                DataSource fds = new FileDataSource(new File(each));
                DataHandler handler = new DataHandler(fds);
                client.getPluginInterface().installPluginBundleFromFile(handler, true, true);
                System.out.println("Plugin " + each + " successfully installed !");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    } catch (BimServerClientException e1) {
        e1.printStackTrace();
    } catch (ServiceException e1) {
        e1.printStackTrace();
    } catch (ChannelConnectionException e1) {
        e1.printStackTrace();
    } catch (Exception e2) {
        e2.printStackTrace();
    }
}
Also used : ChannelConnectionException(org.bimserver.shared.ChannelConnectionException) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) ArrayList(java.util.ArrayList) DataHandler(javax.activation.DataHandler) BimServerClientException(org.bimserver.shared.exceptions.BimServerClientException) BimServerClientFactory(org.bimserver.shared.BimServerClientFactory) JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) ChannelConnectionException(org.bimserver.shared.ChannelConnectionException) BimServerClientException(org.bimserver.shared.exceptions.BimServerClientException) ServiceException(org.bimserver.shared.exceptions.ServiceException) FileDataSource(org.bimserver.utils.FileDataSource) DataSource(javax.activation.DataSource) ServiceException(org.bimserver.shared.exceptions.ServiceException) FileDataSource(org.bimserver.utils.FileDataSource) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) File(java.io.File)

Aggregations

UsernamePasswordAuthenticationInfo (org.bimserver.shared.UsernamePasswordAuthenticationInfo)55 BimServerClientInterface (org.bimserver.plugins.services.BimServerClientInterface)46 SProject (org.bimserver.interfaces.objects.SProject)45 Test (org.junit.Test)41 SDeserializerPluginConfiguration (org.bimserver.interfaces.objects.SDeserializerPluginConfiguration)27 URL (java.net.URL)20 LowLevelInterface (org.bimserver.shared.interfaces.LowLevelInterface)19 IfcModelInterface (org.bimserver.emf.IfcModelInterface)17 SSerializerPluginConfiguration (org.bimserver.interfaces.objects.SSerializerPluginConfiguration)15 JsonBimServerClientFactory (org.bimserver.client.json.JsonBimServerClientFactory)11 Path (java.nio.file.Path)10 IOException (java.io.IOException)9 ChannelConnectionException (org.bimserver.shared.ChannelConnectionException)9 BimServerClientException (org.bimserver.shared.exceptions.BimServerClientException)9 ServiceException (org.bimserver.shared.exceptions.ServiceException)9 PublicInterfaceNotFoundException (org.bimserver.shared.exceptions.PublicInterfaceNotFoundException)8 BimServerClientFactory (org.bimserver.shared.BimServerClientFactory)7 UserException (org.bimserver.shared.exceptions.UserException)6 IfcPropertySingleValue (org.bimserver.models.ifc2x3tc1.IfcPropertySingleValue)5 File (java.io.File)4