Search in sources :

Example 11 with UsernamePasswordAuthenticationInfo

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

the class AllTests method setup.

private static void setup() {
    // Create a config
    Path home = Paths.get("tmptestdata/home-" + new Random().nextInt(1000000000));
    // Remove the home dir if it's there
    if (Files.exists(home)) {
        try {
            PathUtils.removeDirectoryWithContent(home);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    BimServerConfig config = new BimServerConfig();
    config.setHomeDir(home);
    config.setStartEmbeddedWebServer(true);
    config.setPort(7010);
    config.setResourceFetcher(new LocalDevelopmentResourceFetcher(Paths.get("../")));
    config.setClassPath(System.getProperty("java.class.path"));
    bimServer = new BimServer(config);
    try {
        bimServer.setEmbeddedWebServer(new EmbeddedWebServer(bimServer, Paths.get("."), false));
        // CHANGE THESE TO MATCH YOUR CONFIGURATION
        // Path[] pluginDirectories = new Path[]{Paths.get("C:\\Git\\IfcPlugins\\IfcPlugins"), Paths.get("C:\\Git\\IfcOpenShell-BIMserver-plugin")};
        // Start it
        bimServer.start();
        // Load plugins
        // LocalDevPluginLoader.loadPlugins(bimServer.getPluginManager(), pluginDirectories);
        // Get a client, not using any protocol (direct connection)
        BimServerClientInterface client = bimServer.getBimServerClientFactory().create();
        // Setup the server
        client.getAdminInterface().setup("http://localhost:7010", "Test Name", "Test Description", "noicon", "Administrator", "admin@bimserver.org", "admin");
        ServiceMap serviceMap = bimServer.getServiceFactory().get(new SystemAuthorization(1, TimeUnit.HOURS), AccessMethod.INTERNAL);
        serviceMap.getSettingsInterface().setCacheOutputFiles(false);
        client.disconnect();
        client = bimServer.getBimServerClientFactory().create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
        String pluginsString = System.getProperty("plugins");
        if (pluginsString != null) {
            String[] plugins = pluginsString.split(";");
            Path[] paths = new Path[plugins.length];
            int i = 0;
            for (String p : plugins) {
                paths[i++] = Paths.get(p);
            }
            LocalDevPluginLoader.loadPlugins(bimServer.getPluginManager(), paths);
        } else {
            LoggerFactory.getLogger(AllTests.class).info("Installing plugins");
            client.getPluginInterface().installPluginBundle("http://archiva.logic-labs.nl/repository/snapshots", "org.opensourcebim", "ifcplugins", null, null);
            client.getPluginInterface().installPluginBundle("http://archiva.logic-labs.nl/repository/snapshots", "org.opensourcebim", "binaryserializers", null, null);
            client.getPluginInterface().installPluginBundle("http://archiva.logic-labs.nl/repository/snapshots", "org.opensourcebim", "ifcopenshellplugin", null, null);
        }
        client.disconnect();
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : Path(java.nio.file.Path) ServiceMap(org.bimserver.webservices.ServiceMap) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) BimServer(org.bimserver.BimServer) IOException(java.io.IOException) SystemAuthorization(org.bimserver.webservices.authorization.SystemAuthorization) BimServerConfig(org.bimserver.BimServerConfig) LocalDevelopmentResourceFetcher(org.bimserver.shared.LocalDevelopmentResourceFetcher) EmbeddedWebServer(org.bimserver.EmbeddedWebServer) IOException(java.io.IOException) Random(java.util.Random) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface)

Example 12 with UsernamePasswordAuthenticationInfo

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

the class TestCreateProperties method test.

@Test
public void test() {
    try {
        // New client
        BimServerClientInterface bimServerClient = getFactory().create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
        // Create a project
        SProject project = bimServerClient.getServiceInterface().addProject("test" + Math.random(), "ifc2x3tc1");
        // Look for a deserializer
        SDeserializerPluginConfiguration deserializer = bimServerClient.getServiceInterface().getSuggestedDeserializerForExtension("ifc", project.getOid());
        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"));
        // Refresh project
        project = bimServerClient.getServiceInterface().getProjectByPoid(project.getOid());
        // Load model without lazy loading (complete model at once)
        IfcModelInterface model = bimServerClient.getModel(project, project.getLastRevisionId(), true, true);
        String propertyName = "BooleanProperty";
        int nrWindowsFirst = 0;
        // Iterate over all projects, there should be 1
        for (IfcWindow window : model.getAllWithSubTypes(IfcWindow.class)) {
            nrWindowsFirst++;
            createProperty(window, model, propertyName, "Description of property", true);
        }
        long newRoid = model.commit("Added boolean properties to " + nrWindowsFirst + " windows");
        model = bimServerClient.getModel(project, newRoid, true, false);
        int foundOke = 0;
        int nrWindowsSecond = 0;
        Set<Long> counted = new HashSet<Long>();
        for (IfcWindow window : model.getAllWithSubTypes(IfcWindow.class)) {
            nrWindowsSecond++;
            for (IfcRelDefines ifcRelDefines : window.getIsDefinedBy()) {
                if (ifcRelDefines instanceof IfcRelDefinesByProperties) {
                    IfcRelDefinesByProperties ifcRelDefinesByProperties = (IfcRelDefinesByProperties) ifcRelDefines;
                    IfcPropertySetDefinition relatingPropertyDefinition = ifcRelDefinesByProperties.getRelatingPropertyDefinition();
                    if (relatingPropertyDefinition instanceof IfcPropertySet) {
                        IfcPropertySet ifcPropertySet = (IfcPropertySet) relatingPropertyDefinition;
                        for (IfcProperty ifcProperty : ifcPropertySet.getHasProperties()) {
                            if (ifcProperty instanceof IfcPropertySingleValue) {
                                IfcPropertySingleValue ifcPropertySingleValue = (IfcPropertySingleValue) ifcProperty;
                                if (ifcPropertySingleValue.getName().equals(propertyName)) {
                                    IfcValue nominalValue = ifcPropertySingleValue.getNominalValue();
                                    if (nominalValue instanceof IfcBoolean) {
                                        if (((IfcBoolean) nominalValue).getWrappedValue() == Tristate.TRUE) {
                                            if (!counted.contains(ifcPropertySingleValue.getOid())) {
                                                foundOke++;
                                                counted.add(ifcPropertySingleValue.getOid());
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        LOGGER.info("Windows first: " + nrWindowsFirst);
        LOGGER.info("Windows second: " + nrWindowsSecond);
        LOGGER.info("Found Oke: " + foundOke);
        if (foundOke != nrWindowsFirst) {
            fail(foundOke + " / " + nrWindowsFirst);
        }
    } catch (Throwable e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : IfcValue(org.bimserver.models.ifc2x3tc1.IfcValue) IfcProperty(org.bimserver.models.ifc2x3tc1.IfcProperty) IfcPropertySingleValue(org.bimserver.models.ifc2x3tc1.IfcPropertySingleValue) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) IfcWindow(org.bimserver.models.ifc2x3tc1.IfcWindow) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) IfcModelInterface(org.bimserver.emf.IfcModelInterface) SProject(org.bimserver.interfaces.objects.SProject) IfcRelDefinesByProperties(org.bimserver.models.ifc2x3tc1.IfcRelDefinesByProperties) URL(java.net.URL) IfcRelDefines(org.bimserver.models.ifc2x3tc1.IfcRelDefines) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) IfcPropertySet(org.bimserver.models.ifc2x3tc1.IfcPropertySet) IfcPropertySetDefinition(org.bimserver.models.ifc2x3tc1.IfcPropertySetDefinition) HashSet(java.util.HashSet) IfcBoolean(org.bimserver.models.ifc2x3tc1.IfcBoolean) Test(org.junit.Test)

Example 13 with UsernamePasswordAuthenticationInfo

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

the class TestDeleteObjects 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");
        IfcModelInterface model = bimServerClient.newModel(newProject, true);
        for (int i = 0; i < 10; i++) {
            IfcWall wall = model.create(Ifc2x3tc1Package.eINSTANCE.getIfcWall());
            wall.setName("Wall " + i);
            wall.setGlobalId("Wall " + i);
        }
        long roid = model.commit("Initial model");
        model = bimServerClient.getModel(newProject, roid, true, true);
        List<IfcWall> walls = model.getAllWithSubTypes(Ifc2x3tc1Package.eINSTANCE.getIfcWall());
        assertTrue(walls.size() == 10);
        IfcWall wall6 = (IfcWall) model.getByGuid("Wall 6");
        assertTrue(wall6 != null);
        wall6.remove();
        roid = model.commit("Removed wall 6");
        model = bimServerClient.getModel(newProject, roid, true, false);
        walls = model.getAllWithSubTypes(Ifc2x3tc1Package.eINSTANCE.getIfcWall());
        assertTrue(walls.size() == 9);
    } catch (Throwable e) {
        if (e instanceof AssertionError) {
            throw (AssertionError) e;
        }
        fail(e.getMessage());
    }
}
Also used : IfcWall(org.bimserver.models.ifc2x3tc1.IfcWall) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) IfcModelInterface(org.bimserver.emf.IfcModelInterface) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) SProject(org.bimserver.interfaces.objects.SProject) Test(org.junit.Test)

Example 14 with UsernamePasswordAuthenticationInfo

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

the class TestReadProperties method test.

@Test
public void test() {
    try {
        // New client
        BimServerClientInterface bimServerClient = getFactory().create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
        // Create a project
        SProject project = bimServerClient.getServiceInterface().addProject("test" + Math.random(), "ifc2x3tc1");
        // Look for a deserializer
        SDeserializerPluginConfiguration deserializer = bimServerClient.getServiceInterface().getSuggestedDeserializerForExtension("ifc", project.getOid());
        // Checkin file
        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"));
        // Refresh project
        project = bimServerClient.getServiceInterface().getProjectByPoid(project.getOid());
        // Load model without lazy loading (complete model at once)
        IfcModelInterface model = bimServerClient.getModel(project, project.getLastRevisionId(), true, false);
        // Iterate over all projects, there should be 1
        for (IfcProject ifcProject : model.getAllWithSubTypes(IfcProject.class)) {
            for (IfcRelDefines ifcRelDefines : ifcProject.getIsDefinedBy()) {
                if (ifcRelDefines instanceof IfcRelDefinesByProperties) {
                    IfcRelDefinesByProperties ifcRelDefinesByProperties = (IfcRelDefinesByProperties) ifcRelDefines;
                    IfcPropertySetDefinition relatingPropertyDefinition = ifcRelDefinesByProperties.getRelatingPropertyDefinition();
                    if (relatingPropertyDefinition instanceof IfcPropertySet) {
                        IfcPropertySet ifcPropertySet = (IfcPropertySet) relatingPropertyDefinition;
                        for (IfcProperty ifcProperty : ifcPropertySet.getHasProperties()) {
                            if (ifcProperty instanceof IfcPropertySingleValue) {
                                IfcPropertySingleValue ifcPropertySingleValue = (IfcPropertySingleValue) ifcProperty;
                                IfcValue nominalValue = ifcPropertySingleValue.getNominalValue();
                                String stringValue = "";
                                if (nominalValue instanceof IfcLabel) {
                                    stringValue = ((IfcLabel) nominalValue).getWrappedValue();
                                } else if (nominalValue instanceof IfcIdentifier) {
                                    stringValue = ((IfcIdentifier) nominalValue).getWrappedValue();
                                } else if (nominalValue instanceof IfcAreaMeasure) {
                                    stringValue = "" + ((IfcAreaMeasure) nominalValue).getWrappedValue();
                                }
                                if (ifcPropertySingleValue.getName().equals("ConstructionMode")) {
                                    if (!stringValue.equals("Massivbau")) {
                                        fail("Massivbau expected");
                                    }
                                } else if (ifcPropertySingleValue.getName().equals("BuildingPermitId")) {
                                    if (!stringValue.equals("4711")) {
                                        fail("4711 expected");
                                    }
                                } else if (ifcPropertySingleValue.getName().equals("GrossAreaPlanned")) {
                                    if (stringValue == null || !stringValue.equals("1000.0")) {
                                        fail("1000. expected");
                                    }
                                }
                                System.out.println(ifcPropertySingleValue.getName() + ": " + stringValue);
                            }
                        }
                    }
                }
            }
        }
    } catch (Throwable e) {
        if (!(e instanceof AssertionError)) {
            fail(e.getMessage());
        }
    }
}
Also used : IfcProject(org.bimserver.models.ifc2x3tc1.IfcProject) IfcValue(org.bimserver.models.ifc2x3tc1.IfcValue) IfcProperty(org.bimserver.models.ifc2x3tc1.IfcProperty) IfcPropertySingleValue(org.bimserver.models.ifc2x3tc1.IfcPropertySingleValue) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) IfcModelInterface(org.bimserver.emf.IfcModelInterface) IfcAreaMeasure(org.bimserver.models.ifc2x3tc1.IfcAreaMeasure) SProject(org.bimserver.interfaces.objects.SProject) IfcRelDefinesByProperties(org.bimserver.models.ifc2x3tc1.IfcRelDefinesByProperties) URL(java.net.URL) IfcRelDefines(org.bimserver.models.ifc2x3tc1.IfcRelDefines) IfcLabel(org.bimserver.models.ifc2x3tc1.IfcLabel) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) IfcPropertySet(org.bimserver.models.ifc2x3tc1.IfcPropertySet) IfcPropertySetDefinition(org.bimserver.models.ifc2x3tc1.IfcPropertySetDefinition) IfcIdentifier(org.bimserver.models.ifc2x3tc1.IfcIdentifier) Test(org.junit.Test)

Example 15 with UsernamePasswordAuthenticationInfo

use of org.bimserver.shared.UsernamePasswordAuthenticationInfo 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)

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