Search in sources :

Example 16 with SSerializerPluginConfiguration

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

the class PluginServiceImpl method getAllSerializersForPoids.

@Override
public List<SSerializerPluginConfiguration> getAllSerializersForPoids(Boolean onlyEnabled, Set<Long> poids) throws ServerException, UserException {
    requireRealUserAuthentication();
    DatabaseSession session = getBimServer().getDatabase().createSession();
    try {
        Set<Schema> uniqueSchemas = new HashSet<>();
        for (Long poid : poids) {
            Project project = session.get(poid, OldQuery.getDefault());
            uniqueSchemas.add(Schema.valueOf(project.getSchema().toUpperCase()));
        }
        Set<Schema> schemaOr = new HashSet<>();
        if (uniqueSchemas.size() == 0) {
        // Weird, no schemas
        } else if (uniqueSchemas.size() == 1) {
            // Easy, just add it, and see if there are converter targets and add those too
            Schema schema = uniqueSchemas.iterator().next();
            schemaOr.add(schema);
            // TODO make recursive
            for (Schema target : getBimServer().getSchemaConverterManager().getSchemaTargets(schema)) {
                schemaOr.add(target);
            }
        } else if (uniqueSchemas.size() == 2) {
            // This is harder, if we have 2 schema, we must figure out a way to convert to 1 schema, and then filter the allowed source schemas
            Iterator<Schema> iterator = uniqueSchemas.iterator();
            Schema schema1 = iterator.next();
            Schema schema2 = iterator.next();
            SchemaConverterFactory converter1 = getBimServer().getSchemaConverterManager().getSchemaConverterFactory(schema1, schema2);
            SchemaConverterFactory converter2 = getBimServer().getSchemaConverterManager().getSchemaConverterFactory(schema2, schema1);
            if (converter1 != null) {
                schemaOr.add(schema1);
            }
            if (converter2 != null) {
                schemaOr.add(schema2);
            }
        } else {
            throw new ServerException("Unimplemented, no support for > 2 schemas");
        }
        UserSettings userSettings = getUserSettings(session);
        List<SSerializerPluginConfiguration> sSerializers = new ArrayList<SSerializerPluginConfiguration>();
        for (SerializerPluginConfiguration serializerPluginConfiguration : userSettings.getSerializers()) {
            Plugin plugin = getBimServer().getPluginManager().getPlugin(serializerPluginConfiguration.getPluginDescriptor().getPluginClassName(), true);
            if (plugin instanceof SerializerPlugin) {
                SerializerPlugin serializerPlugin = getBimServer().getPluginManager().getSerializerPlugin(serializerPluginConfiguration.getPluginDescriptor().getPluginClassName(), true);
                for (Schema schema : serializerPlugin.getSupportedSchemas()) {
                    if (schemaOr.contains(schema)) {
                        if (!onlyEnabled || (serializerPluginConfiguration.getEnabled() && serializerPluginConfiguration.getPluginDescriptor().getEnabled())) {
                            sSerializers.add(getBimServer().getSConverter().convertToSObject(serializerPluginConfiguration));
                            break;
                        }
                    }
                }
            } else if (plugin instanceof StreamingSerializerPlugin) {
                StreamingSerializerPlugin streamingSerializerPlugin = (StreamingSerializerPlugin) plugin;
                for (Schema schema : streamingSerializerPlugin.getSupportedSchemas()) {
                    if (schemaOr.contains(schema)) {
                        if (!onlyEnabled || (serializerPluginConfiguration.getEnabled() && serializerPluginConfiguration.getPluginDescriptor().getEnabled())) {
                            sSerializers.add(getBimServer().getSConverter().convertToSObject(serializerPluginConfiguration));
                            break;
                        }
                    }
                }
            }
        }
        Collections.sort(sSerializers, new SPluginConfigurationComparator());
        return sSerializers;
    } catch (Exception e) {
        handleException(e);
    } finally {
        session.close();
    }
    return null;
}
Also used : ServerException(org.bimserver.shared.exceptions.ServerException) DatabaseSession(org.bimserver.database.DatabaseSession) UserSettings(org.bimserver.models.store.UserSettings) Schema(org.bimserver.emf.Schema) ArrayList(java.util.ArrayList) StreamingSerializerPlugin(org.bimserver.plugins.serializers.StreamingSerializerPlugin) SerializerPlugin(org.bimserver.plugins.serializers.SerializerPlugin) StreamingSerializerPlugin(org.bimserver.plugins.serializers.StreamingSerializerPlugin) IOException(java.io.IOException) ServerException(org.bimserver.shared.exceptions.ServerException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) UserException(org.bimserver.shared.exceptions.UserException) SPluginConfigurationComparator(org.bimserver.webservices.SPluginConfigurationComparator) Project(org.bimserver.models.store.Project) SerializerPluginConfiguration(org.bimserver.models.store.SerializerPluginConfiguration) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) HashSet(java.util.HashSet) SchemaConverterFactory(org.bimserver.schemaconverter.SchemaConverterFactory) ModelCheckerPlugin(org.bimserver.plugins.modelchecker.ModelCheckerPlugin) StreamingDeserializerPlugin(org.bimserver.plugins.deserializers.StreamingDeserializerPlugin) ModelComparePlugin(org.bimserver.plugins.modelcompare.ModelComparePlugin) ObjectIDMPlugin(org.bimserver.plugins.objectidms.ObjectIDMPlugin) DeserializerPlugin(org.bimserver.plugins.deserializers.DeserializerPlugin) ServicePlugin(org.bimserver.plugins.services.ServicePlugin) WebModulePlugin(org.bimserver.plugins.web.WebModulePlugin) RenderEnginePlugin(org.bimserver.plugins.renderengine.RenderEnginePlugin) StreamingSerializerPlugin(org.bimserver.plugins.serializers.StreamingSerializerPlugin) SerializerPlugin(org.bimserver.plugins.serializers.SerializerPlugin) QueryEnginePlugin(org.bimserver.plugins.queryengine.QueryEnginePlugin) ModelMergerPlugin(org.bimserver.plugins.modelmerger.ModelMergerPlugin) Plugin(org.bimserver.plugins.Plugin)

Example 17 with SSerializerPluginConfiguration

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

the class TestGuid method main.

public static void main(String[] args) {
    BimServerClientInterface client = LocalDevSetup.setupJson("http://localhost:8080");
    try {
        SProject project = client.getServiceInterface().addProject("testProject2", "ifc2x3tc1");
        Long tid = client.getLowLevelInterface().startTransaction(project.getOid());
        client.getLowLevelInterface().createObject(tid, "IfcWall", false);
        Long roid = client.getLowLevelInterface().commitTransaction(tid, "test commit");
        SSerializerPluginConfiguration serializer = client.getServiceInterface().getSerializerByContentType("application/ifc");
        client.download(roid, serializer.getOid(), Paths.get("test2.ifc"));
    } catch (ServerException | UserException | PublicInterfaceNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (BimServerClientException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : ServerException(org.bimserver.shared.exceptions.ServerException) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) UserException(org.bimserver.shared.exceptions.UserException) IOException(java.io.IOException) SProject(org.bimserver.interfaces.objects.SProject) BimServerClientException(org.bimserver.shared.exceptions.BimServerClientException)

Example 18 with SSerializerPluginConfiguration

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

the class TestJsonSerializerMultipleRevisions method main.

public static void main(String[] args) {
    try {
        BimServerClientInterface client = LocalDevSetup.setupJson("http://localhost:8080");
        SSerializerPluginConfiguration jsonSerializer = client.getServiceInterface().getSerializerByContentType("application/json");
        long roid1 = 65539;
        long roid2 = 131075;
        Long download1 = client.getServiceInterface().download(Collections.singleton(roid1), DefaultQueries.allAsString(), jsonSerializer.getOid(), true);
        InputStream downloadData1 = client.getDownloadData(download1);
        IOUtils.copy(downloadData1, new FileOutputStream(Paths.get("roid1.json").toFile()));
        Long download2 = client.getServiceInterface().download(Collections.singleton(roid2), DefaultQueries.allAsString(), jsonSerializer.getOid(), true);
        InputStream downloadData2 = client.getDownloadData(download2);
        IOUtils.copy(downloadData2, new FileOutputStream(Paths.get("roid2.json").toFile()));
    } catch (ServiceException e) {
        e.printStackTrace();
    } catch (PublicInterfaceNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : ServiceException(org.bimserver.shared.exceptions.ServiceException) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) IOException(java.io.IOException)

Example 19 with SSerializerPluginConfiguration

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

the class TestSceneJsDownload method start.

private void start() {
    try {
        BimServerClientInterface bimServerClient = LocalDevSetup.setupJson("http://localhost:8080");
        bimServerClient.getAuthInterface().login("admin@bimserver.org", "admin");
        SSerializerPluginConfiguration serializerByContentType = bimServerClient.getServiceInterface().getSerializerByContentType("application/json");
        List<SProject> projects = bimServerClient.getServiceInterface().getProjectsByName("test");
        if (!projects.isEmpty()) {
            SProject project = projects.get(0);
            if (project.getLastRevisionId() != -1) {
                long start = System.nanoTime();
                Long download = bimServerClient.getServiceInterface().download(Collections.singleton(project.getLastRevisionId()), DefaultQueries.allAsString(), serializerByContentType.getOid(), true);
                System.out.println(((System.nanoTime() - start) / 1000000) + " ms");
                start = System.nanoTime();
                InputStream inputStream = bimServerClient.getDownloadData(download);
                FileOutputStream fileOutputStream = new FileOutputStream(Paths.get("test.json").toFile());
                IOUtils.copy(inputStream, fileOutputStream);
                fileOutputStream.close();
                System.out.println(((System.nanoTime() - start) / 1000000) + " ms");
            }
        }
    } catch (ServerException e) {
        e.printStackTrace();
    } catch (UserException e) {
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (PublicInterfaceNotFoundException e) {
        e.printStackTrace();
    }
}
Also used : ServerException(org.bimserver.shared.exceptions.ServerException) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) SProject(org.bimserver.interfaces.objects.SProject) FileOutputStream(java.io.FileOutputStream) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) UserException(org.bimserver.shared.exceptions.UserException)

Example 20 with SSerializerPluginConfiguration

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

the class TestSimultaniousDownloadWithCaching method start.

private void start() {
    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("../")));
    final BimServer bimServer = new BimServer(config);
    try {
        LocalDevPluginLoader.loadPlugins(bimServer.getPluginManager(), null);
        bimServer.start();
        if (bimServer.getServerInfo().getServerState() == ServerState.NOT_SETUP) {
            bimServer.getService(AdminInterface.class).setup("http://localhost", "Administrator", "admin@bimserver.org", "admin", null, null, null);
        }
    } catch (PluginException e2) {
        e2.printStackTrace();
    } catch (ServerException e) {
        e.printStackTrace();
    } catch (DatabaseInitException e) {
        e.printStackTrace();
    } catch (BimserverDatabaseException e) {
        e.printStackTrace();
    } catch (DatabaseRestartRequiredException e) {
        e.printStackTrace();
    } catch (UserException e) {
        e.printStackTrace();
    }
    try {
        final ServiceMap serviceMap = bimServer.getServiceFactory().get(AccessMethod.INTERNAL);
        ServiceInterface serviceInterface = serviceMap.get(ServiceInterface.class);
        SettingsInterface settingsInterface = serviceMap.get(SettingsInterface.class);
        final AuthInterface authInterface = serviceMap.get(AuthInterface.class);
        serviceInterface = bimServer.getServiceFactory().get(authInterface.login("admin@bimserver.org", "admin"), AccessMethod.INTERNAL).get(ServiceInterface.class);
        settingsInterface.setCacheOutputFiles(true);
        settingsInterface.setGenerateGeometryOnCheckin(false);
        final SProject project = serviceMap.getServiceInterface().addProject("test", "ifc2x3tc1");
        SDeserializerPluginConfiguration deserializerByName = serviceMap.getServiceInterface().getDeserializerByName("IfcStepDeserializer");
        Path file = Paths.get("../TestData/data/AC11-Institute-Var-2-IFC.ifc");
        serviceInterface.checkin(project.getOid(), "test", deserializerByName.getOid(), file.toFile().length(), file.getFileName().toString(), new DataHandler(new FileDataSource(file.toFile())), false, true);
        final SProject projectUpdate = serviceMap.getServiceInterface().getProjectByPoid(project.getOid());
        ThreadPoolExecutor executor = new ThreadPoolExecutor(20, 20, 1, TimeUnit.HOURS, new ArrayBlockingQueue<Runnable>(1000));
        for (int i = 0; i < 20; i++) {
            executor.execute(new Runnable() {

                @Override
                public void run() {
                    try {
                        ServiceMap serviceMap2 = bimServer.getServiceFactory().get(authInterface.login("admin@bimserver.org", "admin"), AccessMethod.INTERNAL);
                        SSerializerPluginConfiguration serializerPluginConfiguration = serviceMap.getServiceInterface().getSerializerByName("Ifc2x3");
                        Long download = serviceMap2.getServiceInterface().download(Collections.singleton(projectUpdate.getLastRevisionId()), DefaultQueries.allAsString(), serializerPluginConfiguration.getOid(), true);
                        SDownloadResult downloadData = serviceMap2.getServiceInterface().getDownloadData(download);
                        if (downloadData.getFile().getDataSource() instanceof CacheStoringEmfSerializerDataSource) {
                            CacheStoringEmfSerializerDataSource c = (CacheStoringEmfSerializerDataSource) downloadData.getFile().getDataSource();
                            try {
                                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                                c.writeToOutputStream(baos, null);
                                System.out.println(baos.size());
                            } catch (SerializerException e) {
                                e.printStackTrace();
                            }
                        } else {
                            ByteArrayOutputStream baos = new ByteArrayOutputStream();
                            IOUtils.copy(downloadData.getFile().getInputStream(), baos);
                            System.out.println(baos.size());
                        }
                        serviceMap2.getServiceInterface().cleanupLongAction(download);
                    } catch (ServerException e) {
                        e.printStackTrace();
                    } catch (UserException e) {
                        e.printStackTrace();
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    } catch (PublicInterfaceNotFoundException e1) {
                        e1.printStackTrace();
                    }
                }
            });
        }
        executor.shutdown();
        executor.awaitTermination(1, TimeUnit.HOURS);
        bimServer.stop();
    } catch (ServerException e1) {
        e1.printStackTrace();
    } catch (UserException e1) {
        e1.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (PublicInterfaceNotFoundException e2) {
        e2.printStackTrace();
    }
}
Also used : AuthInterface(org.bimserver.shared.interfaces.AuthInterface) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) ServiceMap(org.bimserver.webservices.ServiceMap) CacheStoringEmfSerializerDataSource(org.bimserver.plugins.serializers.CacheStoringEmfSerializerDataSource) FileNotFoundException(java.io.FileNotFoundException) DataHandler(javax.activation.DataHandler) BimServerConfig(org.bimserver.BimServerConfig) SProject(org.bimserver.interfaces.objects.SProject) LocalDevelopmentResourceFetcher(org.bimserver.shared.LocalDevelopmentResourceFetcher) DatabaseInitException(org.bimserver.database.berkeley.DatabaseInitException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) ServiceInterface(org.bimserver.shared.interfaces.ServiceInterface) FileDataSource(javax.activation.FileDataSource) UserException(org.bimserver.shared.exceptions.UserException) Path(java.nio.file.Path) ServerException(org.bimserver.shared.exceptions.ServerException) BimServer(org.bimserver.BimServer) PluginException(org.bimserver.shared.exceptions.PluginException) SDownloadResult(org.bimserver.interfaces.objects.SDownloadResult) IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SerializerException(org.bimserver.plugins.serializers.SerializerException) AdminInterface(org.bimserver.shared.interfaces.AdminInterface) SettingsInterface(org.bimserver.shared.interfaces.SettingsInterface) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) DatabaseRestartRequiredException(org.bimserver.database.DatabaseRestartRequiredException) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Aggregations

SSerializerPluginConfiguration (org.bimserver.interfaces.objects.SSerializerPluginConfiguration)31 SProject (org.bimserver.interfaces.objects.SProject)24 BimServerClientInterface (org.bimserver.plugins.services.BimServerClientInterface)23 SDeserializerPluginConfiguration (org.bimserver.interfaces.objects.SDeserializerPluginConfiguration)17 UsernamePasswordAuthenticationInfo (org.bimserver.shared.UsernamePasswordAuthenticationInfo)15 Test (org.junit.Test)15 IOException (java.io.IOException)11 URL (java.net.URL)11 PublicInterfaceNotFoundException (org.bimserver.shared.exceptions.PublicInterfaceNotFoundException)10 ServerException (org.bimserver.shared.exceptions.ServerException)10 UserException (org.bimserver.shared.exceptions.UserException)10 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)7 IfcModelInterface (org.bimserver.emf.IfcModelInterface)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 DatabaseSession (org.bimserver.database.DatabaseSession)5 ServiceException (org.bimserver.shared.exceptions.ServiceException)5 FileOutputStream (java.io.FileOutputStream)4 InputStream (java.io.InputStream)4 Path (java.nio.file.Path)4 SModelComparePluginConfiguration (org.bimserver.interfaces.objects.SModelComparePluginConfiguration)4