Search in sources :

Example 11 with SDeserializerPluginConfiguration

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

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

the class TestJapaneseChars method test.

public void test(URL url, String expectedMessage) {
    try {
        SProject newProject = bimServerClient.getServiceInterface().addProject("test" + Math.random(), "ifc2x3tc1");
        // Find a deserializer to use
        SDeserializerPluginConfiguration deserializer = bimServerClient.getServiceInterface().getSuggestedDeserializerForExtension("ifc", newProject.getOid());
        bimServerClient.checkin(newProject.getOid(), "initial", deserializer.getOid(), false, Flow.SYNC, url);
        newProject = bimServerClient.getServiceInterface().getProjectByPoid(newProject.getOid());
        SSerializerPluginConfiguration serializer = bimServerClient.getServiceInterface().getSerializerByContentType("application/ifc");
        bimServerClient.download(newProject.getLastRevisionId(), serializer.getOid(), Paths.get("bimserver_" + url.getFile().substring(url.getFile().lastIndexOf("/") + 1)));
    } catch (Exception e) {
        e.printStackTrace();
        Assert.assertEquals(expectedMessage, e.getMessage());
    }
}
Also used : SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) SProject(org.bimserver.interfaces.objects.SProject)

Example 13 with SDeserializerPluginConfiguration

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

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

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

Aggregations

SDeserializerPluginConfiguration (org.bimserver.interfaces.objects.SDeserializerPluginConfiguration)45 SProject (org.bimserver.interfaces.objects.SProject)39 BimServerClientInterface (org.bimserver.plugins.services.BimServerClientInterface)31 UsernamePasswordAuthenticationInfo (org.bimserver.shared.UsernamePasswordAuthenticationInfo)27 Test (org.junit.Test)21 IOException (java.io.IOException)19 URL (java.net.URL)19 SSerializerPluginConfiguration (org.bimserver.interfaces.objects.SSerializerPluginConfiguration)18 UserException (org.bimserver.shared.exceptions.UserException)16 IfcModelInterface (org.bimserver.emf.IfcModelInterface)15 ServerException (org.bimserver.shared.exceptions.ServerException)15 PublicInterfaceNotFoundException (org.bimserver.shared.exceptions.PublicInterfaceNotFoundException)12 Path (java.nio.file.Path)9 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)9 DatabaseSession (org.bimserver.database.DatabaseSession)8 BimServerClientException (org.bimserver.shared.exceptions.BimServerClientException)7 ServiceException (org.bimserver.shared.exceptions.ServiceException)7 JsonBimServerClientFactory (org.bimserver.client.json.JsonBimServerClientFactory)5 IfcPropertySingleValue (org.bimserver.models.ifc2x3tc1.IfcPropertySingleValue)5 DeserializerPluginConfiguration (org.bimserver.models.store.DeserializerPluginConfiguration)5