Search in sources :

Example 16 with BimServerClientInterface

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

the class TestReadTrim 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");
        // Get the appropriate deserializer
        SDeserializerPluginConfiguration deserializer = bimServerClient.getServiceInterface().getSuggestedDeserializerForExtension("ifc", newProject.getOid());
        // Checkin the file
        bimServerClient.checkin(newProject.getOid(), "test", deserializer.getOid(), false, Flow.SYNC, new URL("https://github.com/opensourceBIM/TestFiles/raw/master/TestData/data/TST.ifc"));
        // Refresh project info
        newProject = bimServerClient.getServiceInterface().getProjectByPoid(newProject.getOid());
        IfcModelInterface model = bimServerClient.getModel(newProject, newProject.getLastRevisionId(), true, false);
        for (IfcTrimmedCurve ifcTrimmedCurve : model.getAllWithSubTypes(IfcTrimmedCurve.class)) {
            for (IfcTrimmingSelect ifcTrimmingSelect : ifcTrimmedCurve.getTrim1()) {
                if (ifcTrimmingSelect instanceof IfcParameterValue) {
                    IfcParameterValue ifcParameterValue = (IfcParameterValue) ifcTrimmingSelect;
                    System.out.println("Trim1: " + ifcParameterValue.getWrappedValue());
                }
            }
            for (IfcTrimmingSelect ifcTrimmingSelect : ifcTrimmedCurve.getTrim2()) {
                if (ifcTrimmingSelect instanceof IfcParameterValue) {
                    IfcParameterValue ifcParameterValue = (IfcParameterValue) ifcTrimmingSelect;
                    System.out.println("Trim2: " + ifcParameterValue.getWrappedValue());
                }
            }
        }
    } catch (Throwable e) {
        e.printStackTrace();
        if (e instanceof AssertionError) {
            throw (AssertionError) e;
        }
        fail(e.getMessage());
    }
}
Also used : SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) IfcModelInterface(org.bimserver.emf.IfcModelInterface) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) IfcTrimmedCurve(org.bimserver.models.ifc2x3tc1.IfcTrimmedCurve) IfcTrimmingSelect(org.bimserver.models.ifc2x3tc1.IfcTrimmingSelect) IfcParameterValue(org.bimserver.models.ifc2x3tc1.IfcParameterValue) SProject(org.bimserver.interfaces.objects.SProject) URL(java.net.URL) Test(org.junit.Test)

Example 17 with BimServerClientInterface

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

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

the class TestInOut method start.

private void start(String[] args) {
    BimServerConfig config = new BimServerConfig();
    Path homeDir = Paths.get("home");
    try {
        if (Files.isDirectory(homeDir)) {
            PathUtils.removeDirectoryWithContent(homeDir);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    config.setClassPath(System.getProperty("java.class.path"));
    config.setHomeDir(homeDir);
    config.setPort(8080);
    config.setStartEmbeddedWebServer(true);
    config.setResourceFetcher(new LocalDevelopmentResourceFetcher(Paths.get("../")));
    BimServer bimServer = new BimServer(config);
    try {
        LocalDevPluginLoader.loadPlugins(bimServer.getPluginManager(), new OptionsParser(args).getPluginDirectories());
        bimServer.start();
        if (bimServer.getServerInfo().getServerState() == ServerState.NOT_SETUP) {
            AdminInterface adminInterface = bimServer.getServiceFactory().get(new SystemAuthorization(1, TimeUnit.HOURS), AccessMethod.INTERNAL).get(AdminInterface.class);
            adminInterface.setup("http://localhost:8080", "Administrator", "admin@bimserver.org", "admin", null, null, null);
            SettingsInterface settingsInterface = bimServer.getServiceFactory().get(new SystemAuthorization(1, TimeUnit.HOURS), AccessMethod.INTERNAL).get(SettingsInterface.class);
            settingsInterface.setCacheOutputFiles(false);
        }
        BimServerClientInterface client = LocalDevSetup.setupJson("http://localhost:8080");
        SProject project = client.getServiceInterface().addProject("test", "ifc2x3tc1");
        SDeserializerPluginConfiguration deserializer = client.getServiceInterface().getSuggestedDeserializerForExtension("ifc", project.getOid());
        Path inputFile = Paths.get("../TestData/data/AC11-Institute-Var-2-IFC.ifc");
        client.checkin(project.getOid(), "test", deserializer.getOid(), false, Flow.SYNC, inputFile);
        project = client.getServiceInterface().getProjectByPoid(project.getOid());
        SSerializerPluginConfiguration serializer = client.getServiceInterface().getSerializerByContentType("application/ifc");
        Path outputFile = Paths.get("output.ifc");
        client.download(project.getLastRevisionId(), serializer.getOid(), outputFile);
        Diff diff = new Diff(false, false, false, inputFile, outputFile);
        diff.start();
    } catch (ServerException e) {
        e.printStackTrace();
    } catch (DatabaseInitException e) {
        e.printStackTrace();
    } catch (BimserverDatabaseException e) {
        e.printStackTrace();
    } catch (PluginException e) {
        e.printStackTrace();
    } catch (DatabaseRestartRequiredException e) {
        e.printStackTrace();
    } catch (UserException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (PublicInterfaceNotFoundException e) {
        e.printStackTrace();
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (CompareException e) {
        e.printStackTrace();
    } catch (BimServerClientException e) {
        e.printStackTrace();
    }
}
Also used : Path(java.nio.file.Path) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) ServerException(org.bimserver.shared.exceptions.ServerException) Diff(org.bimserver.tests.diff.Diff) BimServer(org.bimserver.BimServer) PluginException(org.bimserver.shared.exceptions.PluginException) IOException(java.io.IOException) SystemAuthorization(org.bimserver.webservices.authorization.SystemAuthorization) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) BimServerConfig(org.bimserver.BimServerConfig) OptionsParser(org.bimserver.plugins.OptionsParser) SProject(org.bimserver.interfaces.objects.SProject) BimServerClientException(org.bimserver.shared.exceptions.BimServerClientException) LocalDevelopmentResourceFetcher(org.bimserver.shared.LocalDevelopmentResourceFetcher) AdminInterface(org.bimserver.shared.interfaces.AdminInterface) DatabaseInitException(org.bimserver.database.berkeley.DatabaseInitException) SettingsInterface(org.bimserver.shared.interfaces.SettingsInterface) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) DatabaseRestartRequiredException(org.bimserver.database.DatabaseRestartRequiredException) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) UserException(org.bimserver.shared.exceptions.UserException) CompareException(org.bimserver.tests.diff.CompareException)

Example 19 with BimServerClientInterface

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

use of org.bimserver.plugins.services.BimServerClientInterface 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)

Aggregations

BimServerClientInterface (org.bimserver.plugins.services.BimServerClientInterface)66 SProject (org.bimserver.interfaces.objects.SProject)57 UsernamePasswordAuthenticationInfo (org.bimserver.shared.UsernamePasswordAuthenticationInfo)46 Test (org.junit.Test)40 SDeserializerPluginConfiguration (org.bimserver.interfaces.objects.SDeserializerPluginConfiguration)31 SSerializerPluginConfiguration (org.bimserver.interfaces.objects.SSerializerPluginConfiguration)23 IfcModelInterface (org.bimserver.emf.IfcModelInterface)20 PublicInterfaceNotFoundException (org.bimserver.shared.exceptions.PublicInterfaceNotFoundException)20 URL (java.net.URL)19 LowLevelInterface (org.bimserver.shared.interfaces.LowLevelInterface)19 IOException (java.io.IOException)16 ServiceException (org.bimserver.shared.exceptions.ServiceException)15 UserException (org.bimserver.shared.exceptions.UserException)13 ServerException (org.bimserver.shared.exceptions.ServerException)11 BimServerClientException (org.bimserver.shared.exceptions.BimServerClientException)10 Path (java.nio.file.Path)8 JsonBimServerClientFactory (org.bimserver.client.json.JsonBimServerClientFactory)7 BimServerClientFactory (org.bimserver.shared.BimServerClientFactory)7 IfcPropertySingleValue (org.bimserver.models.ifc2x3tc1.IfcPropertySingleValue)6 File (java.io.File)4