Search in sources :

Example 21 with UsernamePasswordAuthenticationInfo

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

the class TriggerImportDataRemote method main.

public static void main(String[] args) {
    /*
		 * Args:
		 * 	0: Address of new server
		 *  1: Username
		 *  2: Password
		 *  3: Address of old server
		 *  4: Local path to incoming folder of old server, this local path has to be available on the new server, so you have to copy it from the old server
		 */
    try {
        Path home = Paths.get("home");
        Path tmp = home.resolve("tmp");
        PluginManager pluginManager = LocalDevPluginLoader.createPluginManager(home);
        MetaDataManager metaDataManager = new MetaDataManager(tmp);
        pluginManager.setMetaDataManager(metaDataManager);
        try (JsonBimServerClientFactory factory = new JsonBimServerClientFactory(metaDataManager, args[0])) {
            BimServerClient client = factory.create(new UsernamePasswordAuthenticationInfo(args[1], args[2]));
            client.getServiceInterface().importData(args[3], args[1], args[2], args[4]);
        } catch (Exception e) {
            e.printStackTrace();
        }
    } catch (PluginException e) {
        e.printStackTrace();
    } catch (PublicInterfaceNotFoundException e) {
        e.printStackTrace();
    }
}
Also used : Path(java.nio.file.Path) PluginManager(org.bimserver.plugins.PluginManager) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) PluginException(org.bimserver.shared.exceptions.PluginException) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) MetaDataManager(org.bimserver.emf.MetaDataManager) BimServerClient(org.bimserver.client.BimServerClient) PluginException(org.bimserver.shared.exceptions.PluginException) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException)

Example 22 with UsernamePasswordAuthenticationInfo

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

the class TestIfcEngineEmbedded method main.

public static void main(String[] args) {
    // Create a config
    BimServerConfig config = new BimServerConfig();
    Path home = Paths.get("home");
    // Remove the home dir if it's there
    if (WIPE_HOMEDIR) {
        try {
            PathUtils.removeDirectoryWithContent(home);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    config.setHomeDir(home);
    config.setStartEmbeddedWebServer(true);
    config.setPort(8080);
    config.setResourceFetcher(new LocalDevelopmentResourceFetcher(Paths.get("../")));
    config.setClassPath(System.getProperty("java.class.path"));
    // Create a BIMserver
    BimServer bimServer = new BimServer(config);
    BimServerClientInterface client = null;
    try {
        // Load plugins
        Path[] pluginDirs = new Path[] {// TODO: Set these up yourself...
        };
        LocalDevPluginLoader.loadPlugins(bimServer.getPluginManager(), pluginDirs);
        // Start it
        bimServer.start();
        // Get a client, not using any protocol (direct connection)
        client = bimServer.getBimServerClientFactory().create();
        // Setup the server
        if (bimServer.getServerInfo().getServerState() == ServerState.NOT_SETUP) {
            client.getAdminInterface().setup("http://localhost:8080", "Administrator", "admin@bimserver.org", "admin", null, null, null);
        }
        // Authenticate
        client.setAuthentication(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
        // Iterate over the IfcEngines and see if there is one matching the classname specified above
        boolean engineFound = false;
        for (SRenderEnginePluginConfiguration conf : client.getPluginInterface().getAllRenderEngines(false)) {
            SPluginDescriptor pluginDescriptor = client.getPluginInterface().getPluginDescriptor(conf.getPluginDescriptorId());
            if (RENDER_ENGINE.equals(pluginDescriptor.getPluginClassName())) {
                client.getPluginInterface().setDefaultRenderEngine(conf.getOid());
                engineFound = true;
                LOGGER.info("Using " + conf.getName());
                break;
            }
        }
        if (!engineFound) {
            throw new RenderEngineException("No IfcEnginePlugin found with name " + RENDER_ENGINE);
        }
        // Get a deserializer
        SDeserializerPluginConfiguration deserializer = client.getServiceInterface().getSuggestedDeserializerForExtension("ifc", -1L);
        if (deserializer == null) {
            throw new Exception("No deserializer found for IFC-SPF. Make sure plugin directories are correctly configured");
        }
        Thread[] threads = new Thread[TEST_FILES.length];
        AddProjectCheckinDownloadAction[] contexts = new AddProjectCheckinDownloadAction[TEST_FILES.length];
        for (int i = 0; i < TEST_FILES.length; ++i) {
            (threads[i] = new Thread(contexts[i] = new AddProjectCheckinDownloadAction(bimServer, TEST_FILES[i]))).start();
        }
        for (int i = 0; i < TEST_FILES.length; ++i) {
            threads[i].join();
        }
        for (int i = 0; i < TEST_FILES.length; ++i) {
            contexts[i].verify();
        }
        System.exit(0);
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    } finally {
        try {
            client.disconnect();
        } catch (Throwable t) {
        }
        try {
            bimServer.stop();
        } catch (Throwable t) {
        }
    }
}
Also used : Path(java.nio.file.Path) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) SRenderEnginePluginConfiguration(org.bimserver.interfaces.objects.SRenderEnginePluginConfiguration) BimServer(org.bimserver.BimServer) IOException(java.io.IOException) BimServerConfig(org.bimserver.BimServerConfig) LocalDevelopmentResourceFetcher(org.bimserver.shared.LocalDevelopmentResourceFetcher) IOException(java.io.IOException) RenderEngineException(org.bimserver.plugins.renderengine.RenderEngineException) SPluginDescriptor(org.bimserver.interfaces.objects.SPluginDescriptor) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) RenderEngineException(org.bimserver.plugins.renderengine.RenderEngineException)

Example 23 with UsernamePasswordAuthenticationInfo

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

the class TestListWalls 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/Jesse.1.ifc"));
        // Refresh project info
        newProject = bimServerClient.getServiceInterface().getProjectByPoid(newProject.getOid());
        IfcModelInterface model = bimServerClient.getModel(newProject, newProject.getLastRevisionId(), true, false);
        model.getAllWithSubTypes(IfcWallStandardCase.class);
    } 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) SProject(org.bimserver.interfaces.objects.SProject) URL(java.net.URL) Test(org.junit.Test)

Example 24 with UsernamePasswordAuthenticationInfo

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

the class TestLoadCompleteModel method start.

@Test
public void start() {
    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(), false, true);
        // Change the window names
        for (IfcWindow window : model.getAllWithSubTypes(IfcWindow.class)) {
            window.setName(window.getName() + " Changed");
        }
        long newRoid = model.commit("Changed window names");
        IfcModelInterface newModel = bimServerClient.getModel(project, newRoid, true, false);
        List<IfcWindow> windows = newModel.getAllWithSubTypes(Ifc2x3tc1Package.eINSTANCE.getIfcWindow());
        for (IfcWindow window : windows) {
            assertTrue(window.getName().endsWith(" Changed"));
        }
    } catch (Exception e) {
        fail(e.getMessage());
    }
}
Also used : SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) IfcWindow(org.bimserver.models.ifc2x3tc1.IfcWindow) 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 25 with UsernamePasswordAuthenticationInfo

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

the class TestMoveObject 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/AC11-Institute-Var-2-IFC.ifc"));
        // Refresh project info
        newProject = bimServerClient.getServiceInterface().getProjectByPoid(newProject.getOid());
        IfcModelInterface model = bimServerClient.getModel(newProject, newProject.getLastRevisionId(), true, true);
        for (IfcFurnishingElement ifcFurnishingElement : model.getAllWithSubTypes(IfcFurnishingElement.class)) {
            IfcObjectPlacement objectPlacement = ifcFurnishingElement.getObjectPlacement();
            if (objectPlacement != null && objectPlacement instanceof IfcLocalPlacement) {
                IfcLocalPlacement localPlacement = (IfcLocalPlacement) objectPlacement;
                IfcAxis2Placement relativePlacement = localPlacement.getRelativePlacement();
                if (relativePlacement != null) {
                    if (relativePlacement instanceof IfcAxis2Placement3D) {
                        IfcAxis2Placement3D axis2Placement3D = (IfcAxis2Placement3D) relativePlacement;
                        IfcCartesianPoint location = axis2Placement3D.getLocation();
                        double newValue = location.getCoordinates().get(2) + 50;
                        System.out.println("Changing z value of " + ifcFurnishingElement.getName() + " from " + location.getCoordinates().get(2) + " to " + newValue);
                        location.getCoordinates().set(2, newValue);
                    }
                }
            }
        }
        long newRoid = model.commit("Moved all furniture 50 meters up");
        SSerializerPluginConfiguration ifcSerializer = bimServerClient.getServiceInterface().getSerializerByContentType("application/ifc");
        bimServerClient.download(newRoid, ifcSerializer.getOid(), Paths.get("movedf.ifc"));
    } catch (Throwable e) {
        e.printStackTrace();
        if (e instanceof AssertionError) {
            throw (AssertionError) e;
        }
        fail(e.getMessage());
    }
}
Also used : SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) IfcFurnishingElement(org.bimserver.models.ifc2x3tc1.IfcFurnishingElement) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) IfcModelInterface(org.bimserver.emf.IfcModelInterface) SProject(org.bimserver.interfaces.objects.SProject) IfcObjectPlacement(org.bimserver.models.ifc2x3tc1.IfcObjectPlacement) URL(java.net.URL) IfcAxis2Placement3D(org.bimserver.models.ifc2x3tc1.IfcAxis2Placement3D) IfcLocalPlacement(org.bimserver.models.ifc2x3tc1.IfcLocalPlacement) IfcCartesianPoint(org.bimserver.models.ifc2x3tc1.IfcCartesianPoint) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) IfcAxis2Placement(org.bimserver.models.ifc2x3tc1.IfcAxis2Placement) 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