Search in sources :

Example 1 with IfcModelInterface

use of org.bimserver.emf.IfcModelInterface in project BIMserver by opensourceBIM.

the class DatabaseSession method get.

public <T extends IdEObject> T get(EClass eClass, long oid, QueryInterface query) throws BimserverDatabaseException {
    checkOpen();
    if (oid == -1) {
        return null;
    }
    TodoList todoList = new TodoList();
    IfcModelInterface model = createModel(query);
    T t = get(null, oid, model, query, todoList);
    processTodoList(model, todoList, query);
    return t;
}
Also used : IfcModelInterface(org.bimserver.emf.IfcModelInterface)

Example 2 with IfcModelInterface

use of org.bimserver.emf.IfcModelInterface in project BIMserver by opensourceBIM.

the class BimServer method activateServices.

/**
 * Load all users from the database and their configured services. Registers each service.
 *
 * @param session
 * @throws BimserverDatabaseException
 * @throws BimserverLockConflictException
 */
public void activateServices() throws BimserverDatabaseException, BimserverLockConflictException {
    try (DatabaseSession session = bimDatabase.createSession()) {
        IfcModelInterface allOfType = session.getAllOfType(StorePackage.eINSTANCE.getUser(), OldQuery.getDefault());
        for (User user : allOfType.getAll(User.class)) {
            updateUserSettings(session, user);
            UserSettings userSettings = user.getUserSettings();
            for (InternalServicePluginConfiguration internalServicePluginConfiguration : userSettings.getServices()) {
                activateService(user.getOid(), internalServicePluginConfiguration);
            }
        }
    }
}
Also used : User(org.bimserver.models.store.User) DatabaseSession(org.bimserver.database.DatabaseSession) IfcModelInterface(org.bimserver.emf.IfcModelInterface) UserSettings(org.bimserver.models.store.UserSettings) InternalServicePluginConfiguration(org.bimserver.models.store.InternalServicePluginConfiguration) SInternalServicePluginConfiguration(org.bimserver.interfaces.objects.SInternalServicePluginConfiguration)

Example 3 with IfcModelInterface

use of org.bimserver.emf.IfcModelInterface in project BIMserver by opensourceBIM.

the class BimServer method start.

public void start() throws DatabaseInitException, BimserverDatabaseException, PluginException, DatabaseRestartRequiredException, ServerException {
    try {
        LOGGER.debug("Starting BIMserver");
        if (versionChecker != null) {
            SVersion localVersion = versionChecker.getLocalVersion();
            if (localVersion != null) {
                LOGGER.info("Version: " + localVersion.getFullString());
            } else {
                LOGGER.info("Unknown version");
            }
        } else {
            LOGGER.info("Unknown version");
        }
        try {
            pluginManager.setPluginChangeListener(new PluginChangeListener() {

                @Override
                public void pluginStateChanged(PluginContext pluginContext, boolean enabled) {
                    // Reflect this change also in the database
                    Condition pluginCondition = new AttributeCondition(StorePackage.eINSTANCE.getPluginDescriptor_PluginClassName(), new StringLiteral(pluginContext.getPlugin().getClass().getName()));
                    DatabaseSession session = bimDatabase.createSession();
                    try {
                        Map<Long, PluginDescriptor> pluginsFound = session.query(pluginCondition, PluginDescriptor.class, OldQuery.getDefault());
                        if (pluginsFound.size() == 0) {
                            LOGGER.error("Error changing plugin-state in database, plugin " + pluginContext.getPlugin().getClass().getName() + " not found");
                        } else if (pluginsFound.size() == 1) {
                            PluginDescriptor pluginConfiguration = pluginsFound.values().iterator().next();
                            pluginConfiguration.setEnabled(pluginContext.isEnabled());
                            session.store(pluginConfiguration);
                        } else {
                            LOGGER.error("Error, too many plugin-objects found in database for name " + pluginContext.getPlugin().getClass().getName());
                        }
                        session.commit();
                    } catch (BimserverDatabaseException e) {
                        LOGGER.error("", e);
                    } catch (ServiceException e) {
                        LOGGER.error("", e);
                    } finally {
                        session.close();
                    }
                }

                @Override
                public long pluginBundleUpdated(PluginBundle pluginBundle) {
                    SPluginBundleVersion sPluginBundleVersion = pluginBundle.getPluginBundleVersion();
                    try (DatabaseSession session = bimDatabase.createSession()) {
                        PluginBundleVersion current = null;
                        IfcModelInterface allOfType = session.getAllOfType(StorePackage.eINSTANCE.getPluginBundleVersion(), OldQuery.getDefault());
                        for (PluginBundleVersion pbv : allOfType.getAll(PluginBundleVersion.class)) {
                            if (pbv.getGroupId().equals(pluginBundle.getPluginBundleVersion().getGroupId()) && pbv.getArtifactId().equals(pluginBundle.getPluginBundleVersion().getArtifactId())) {
                                // Current pluginBundle found
                                current = pbv;
                            }
                        }
                        if (current != null) {
                            current.setDescription(sPluginBundleVersion.getArtifactId());
                            current.setIcon(sPluginBundleVersion.getIcon());
                            current.setMismatch(sPluginBundleVersion.isMismatch());
                            current.setRepository(sPluginBundleVersion.getRepository());
                            current.setType(getSConverter().convertFromSObject(sPluginBundleVersion.getType()));
                            current.setVersion(sPluginBundleVersion.getVersion());
                            current.setOrganization(sPluginBundleVersion.getOrganization());
                            current.setName(sPluginBundleVersion.getName());
                            current.setDate(sPluginBundleVersion.getDate());
                            session.store(current);
                            session.commit();
                        }
                        return current.getOid();
                    } catch (BimserverDatabaseException e) {
                        LOGGER.error("", e);
                    } catch (ServiceException e) {
                        LOGGER.error("", e);
                    }
                    return -1;
                }

                @Override
                public void pluginUpdated(long pluginBundleVersionId, PluginContext newPluginContext, SPluginInformation sPluginInformation) throws BimserverDatabaseException {
                    try (DatabaseSession session = bimDatabase.createSession()) {
                        Plugin plugin = newPluginContext.getPlugin();
                        Condition pluginCondition = new AttributeCondition(StorePackage.eINSTANCE.getPluginDescriptor_Identifier(), new StringLiteral(newPluginContext.getIdentifier()));
                        Map<Long, PluginDescriptor> pluginsFound = session.query(pluginCondition, PluginDescriptor.class, OldQuery.getDefault());
                        for (PluginDescriptor pluginDescriptor : pluginsFound.values()) {
                            pluginDescriptor.setIdentifier(newPluginContext.getIdentifier());
                            pluginDescriptor.setPluginClassName(plugin.getClass().getName());
                            pluginDescriptor.setDescription(newPluginContext.getDescription());
                            pluginDescriptor.setName(sPluginInformation.getName());
                            pluginDescriptor.setLocation(newPluginContext.getLocation().toString());
                            pluginDescriptor.setPluginInterfaceClassName(getPluginInterface(plugin.getClass()).getName());
                            pluginDescriptor.setEnabled(sPluginInformation.isEnabled());
                            pluginDescriptor.setInstallForNewUsers(sPluginInformation.isInstallForNewUsers());
                            PluginBundleVersion value = session.get(pluginBundleVersionId, OldQuery.getDefault());
                            pluginDescriptor.setPluginBundleVersion(value);
                            session.store(pluginDescriptor);
                            if (sPluginInformation.isInstallForAllUsers()) {
                                IfcModelInterface allOfType = session.getAllOfType(StorePackage.eINSTANCE.getUser(), OldQuery.getDefault());
                                for (User user : allOfType.getAll(User.class)) {
                                    if (user.getState() == ObjectState.ACTIVE) {
                                        updateUserPlugin(session, user, pluginDescriptor, newPluginContext);
                                    }
                                }
                            }
                            if (newPluginContext.getPlugin() instanceof WebModulePlugin) {
                                ServerSettings serverSettings = getServerSettingsCache().getServerSettings();
                                WebModulePluginConfiguration webPluginConfiguration = find(serverSettings.getWebModules(), newPluginContext.getIdentifier());
                                if (webPluginConfiguration == null) {
                                    webPluginConfiguration = session.create(WebModulePluginConfiguration.class);
                                    serverSettings.getWebModules().add(webPluginConfiguration);
                                }
                                genericPluginConversion(newPluginContext, session, webPluginConfiguration, pluginDescriptor);
                                String contextPath = "";
                                for (Parameter parameter : webPluginConfiguration.getSettings().getParameters()) {
                                    if (parameter.getName().equals("contextPath")) {
                                        contextPath = ((StringType) parameter.getValue()).getValue();
                                    }
                                }
                                String identifier = webPluginConfiguration.getPluginDescriptor().getIdentifier();
                                webModules.put(contextPath, (WebModulePlugin) pluginManager.getPlugin(identifier, true));
                            } else if (newPluginContext.getPlugin() instanceof ServicePlugin) {
                                IfcModelInterface allOfType = session.getAllOfType(StorePackage.eINSTANCE.getInternalServicePluginConfiguration(), OldQuery.getDefault());
                                List<InternalServicePluginConfiguration> all = new ArrayList<>(allOfType.getAll(InternalServicePluginConfiguration.class));
                                for (InternalServicePluginConfiguration internalServicePluginConfiguration : all) {
                                    if (internalServicePluginConfiguration.getPluginDescriptor().getIdentifier().equals(newPluginContext.getIdentifier())) {
                                        activateService(internalServicePluginConfiguration.getUserSettings().getOid(), internalServicePluginConfiguration);
                                    }
                                }
                            }
                        }
                        try {
                            session.commit();
                        } catch (ServiceException e) {
                            LOGGER.error("", e);
                        }
                    }
                }

                @Override
                public void pluginInstalled(long pluginBundleVersionId, PluginContext pluginContext, SPluginInformation sPluginInformation) throws BimserverDatabaseException {
                    try (DatabaseSession session = bimDatabase.createSession()) {
                        Plugin plugin = pluginContext.getPlugin();
                        Condition pluginCondition = new AttributeCondition(StorePackage.eINSTANCE.getPluginDescriptor_Identifier(), new StringLiteral(pluginContext.getIdentifier()));
                        Map<Long, PluginDescriptor> pluginsFound = session.query(pluginCondition, PluginDescriptor.class, OldQuery.getDefault());
                        PluginDescriptor pluginDescriptor = null;
                        if (pluginsFound.size() > 0) {
                            pluginDescriptor = pluginsFound.values().iterator().next();
                        } else {
                            pluginDescriptor = session.create(PluginDescriptor.class);
                        }
                        pluginDescriptor.setIdentifier(pluginContext.getIdentifier());
                        pluginDescriptor.setPluginClassName(plugin.getClass().getName());
                        pluginDescriptor.setDescription(pluginContext.getDescription());
                        pluginDescriptor.setName(sPluginInformation.getName());
                        pluginDescriptor.setLocation(pluginContext.getLocation().toString());
                        pluginDescriptor.setPluginInterfaceClassName(getPluginInterface(plugin.getClass()).getName());
                        pluginDescriptor.setEnabled(sPluginInformation.isEnabled());
                        pluginDescriptor.setInstallForNewUsers(sPluginInformation.isInstallForNewUsers());
                        pluginDescriptor.setPluginBundleVersion(session.get(pluginBundleVersionId, OldQuery.getDefault()));
                        if (sPluginInformation.isInstallForAllUsers()) {
                            IfcModelInterface allOfType = session.getAllOfType(StorePackage.eINSTANCE.getUser(), OldQuery.getDefault());
                            for (User user : allOfType.getAll(User.class)) {
                                if (user.getState() == ObjectState.ACTIVE) {
                                    updateUserPlugin(session, user, pluginDescriptor, pluginContext);
                                }
                            }
                        }
                        if (pluginContext.getPlugin() instanceof WebModulePlugin) {
                            ServerSettings serverSettings = getServerSettingsCache().getServerSettings();
                            WebModulePluginConfiguration webPluginConfiguration = find(serverSettings.getWebModules(), pluginContext.getIdentifier());
                            if (webPluginConfiguration == null) {
                                webPluginConfiguration = session.create(WebModulePluginConfiguration.class);
                                serverSettings.getWebModules().add(webPluginConfiguration);
                                genericPluginConversion(pluginContext, session, webPluginConfiguration, pluginDescriptor);
                                session.store(serverSettings);
                            }
                            String contextPath = "";
                            for (Parameter parameter : webPluginConfiguration.getSettings().getParameters()) {
                                if (parameter.getName().equals("contextPath")) {
                                    contextPath = ((StringType) parameter.getValue()).getValue();
                                }
                            }
                            webModules.put(contextPath, (WebModulePlugin) pluginManager.getPlugin(pluginContext.getIdentifier(), true));
                        }
                        try {
                            session.commit();
                        } catch (ServiceException e) {
                            LOGGER.error("", e);
                        }
                    }
                }

                @Override
                public void pluginUninstalled(PluginContext pluginContext) {
                    // Reflect this change also in the database
                    Condition pluginCondition = new AttributeCondition(StorePackage.eINSTANCE.getPluginDescriptor_Identifier(), new StringLiteral(pluginContext.getIdentifier()));
                    DatabaseSession session = bimDatabase.createSession();
                    try {
                        Map<Long, PluginDescriptor> pluginsFound = session.query(pluginCondition, PluginDescriptor.class, OldQuery.getDefault());
                        if (pluginsFound.size() == 0) {
                            LOGGER.error("Error removing plugin-state in database, plugin " + pluginContext.getPlugin().getClass().getName() + " not found");
                        } else if (pluginsFound.size() == 1) {
                            PluginDescriptor pluginDescriptor = pluginsFound.values().iterator().next();
                            for (PluginConfiguration pluginConfiguration : pluginDescriptor.getConfigurations()) {
                                session.delete(pluginConfiguration, -1);
                            }
                            if (pluginContext.getPlugin() instanceof WebModulePlugin) {
                                ServerSettings serverSettings = getServerSettingsCache().getServerSettings();
                                WebModulePluginConfiguration webPluginConfiguration = find(serverSettings.getWebModules(), pluginContext.getIdentifier());
                                serverSettings.getWebModules().remove(webPluginConfiguration);
                                session.store(serverSettings);
                                String contextPath = "";
                                for (Parameter parameter : webPluginConfiguration.getSettings().getParameters()) {
                                    if (parameter.getName().equals("contextPath")) {
                                        contextPath = ((StringType) parameter.getValue()).getValue();
                                    }
                                }
                                webModules.remove(contextPath);
                            }
                            session.delete(pluginDescriptor, -1);
                        } else {
                            LOGGER.error("Error, too many plugin-objects found in database for name " + pluginContext.getPlugin().getClass().getName());
                        }
                        session.commit();
                    } catch (BimserverDatabaseException e) {
                        LOGGER.error("", e);
                    } catch (ServiceException e) {
                        LOGGER.error("", e);
                    } finally {
                        session.close();
                    }
                }

                @Override
                public long pluginBundleInstalled(PluginBundle pluginBundle) {
                    try (DatabaseSession session = bimDatabase.createSession()) {
                        PluginBundleVersion current = null;
                        IfcModelInterface allOfType = session.getAllOfType(StorePackage.eINSTANCE.getPluginBundleVersion(), OldQuery.getDefault());
                        for (PluginBundleVersion pbv : allOfType.getAll(PluginBundleVersion.class)) {
                            if (pbv.getGroupId().equals(pluginBundle.getPluginBundleVersion().getGroupId()) && pbv.getArtifactId().equals(pluginBundle.getPluginBundleVersion().getArtifactId())) {
                                // Current pluginBundle found
                                current = pbv;
                            }
                        }
                        PluginBundleVersion pluginBundleVersion = null;
                        if (current != null) {
                            pluginBundleVersion = current;
                            session.store(pluginBundleVersion);
                        } else {
                            pluginBundleVersion = session.create(PluginBundleVersion.class);
                        }
                        SPluginBundleVersion sPluginBundleVersion = pluginBundle.getPluginBundleVersion();
                        // SConverter should be used here, but it does not seem to trigger the database session in the rights way, just copying over field for now
                        pluginBundleVersion.setArtifactId(sPluginBundleVersion.getArtifactId());
                        pluginBundleVersion.setDescription(sPluginBundleVersion.getArtifactId());
                        pluginBundleVersion.setGroupId(sPluginBundleVersion.getGroupId());
                        pluginBundleVersion.setIcon(sPluginBundleVersion.getIcon());
                        pluginBundleVersion.setMismatch(sPluginBundleVersion.isMismatch());
                        pluginBundleVersion.setRepository(sPluginBundleVersion.getRepository());
                        pluginBundleVersion.setType(getSConverter().convertFromSObject(sPluginBundleVersion.getType()));
                        pluginBundleVersion.setVersion(sPluginBundleVersion.getVersion());
                        pluginBundleVersion.setOrganization(sPluginBundleVersion.getOrganization());
                        pluginBundleVersion.setName(sPluginBundleVersion.getName());
                        pluginBundleVersion.setDate(sPluginBundleVersion.getDate());
                        session.commit();
                        return pluginBundleVersion.getOid();
                    } catch (BimserverDatabaseException e) {
                        LOGGER.error("", e);
                    } catch (ServiceException e) {
                        LOGGER.error("", e);
                    }
                    return -1;
                }

                @Override
                public void pluginBundleUninstalled(PluginBundle pluginBundle) {
                }
            });
        } catch (Exception e) {
            LOGGER.error("", e);
        }
        try {
            metaDataManager.init();
            pluginManager.initAllLoadedPlugins();
        } catch (PluginException e) {
            LOGGER.error("", e);
        }
        serverStartTime = new GregorianCalendar();
        longActionManager = new LongActionManager();
        Set<EPackage> packages = new LinkedHashSet<>();
        packages.add(Ifc2x3tc1Package.eINSTANCE);
        packages.add(Ifc4Package.eINSTANCE);
        templateEngine = new TemplateEngine();
        URL emailTemplates = config.getResourceFetcher().getResource("emailtemplates/");
        if (emailTemplates != null) {
            templateEngine.init(emailTemplates);
        } else {
            LOGGER.info("No email templates found");
        }
        Path databaseDir = config.getHomeDir().resolve("database");
        BerkeleyKeyValueStore keyValueStore = new BerkeleyKeyValueStore(databaseDir);
        schemaConverterManager.registerConverter(new Ifc2x3tc1ToIfc4SchemaConverterFactory());
        schemaConverterManager.registerConverter(new Ifc4ToIfc2x3tc1SchemaConverterFactory());
        metricsRegistry = new MetricsRegistry();
        Path mavenPath = config.getHomeDir().resolve("maven");
        if (!Files.exists(mavenPath)) {
            Files.createDirectories(mavenPath);
        }
        mavenPluginRepository = new MavenPluginRepository(mavenPath, "http://central.maven.org/maven2", "~/.m2/repository");
        OldQuery.setPackageMetaDataForDefaultQuery(metaDataManager.getPackageMetaData("store"));
        bimDatabase = new Database(this, packages, keyValueStore, metaDataManager);
        try {
            bimDatabase.init();
        } catch (DatabaseRestartRequiredException e) {
            bimDatabase.close();
            keyValueStore = new BerkeleyKeyValueStore(databaseDir);
            bimDatabase = new Database(this, packages, keyValueStore, metaDataManager);
            try {
                bimDatabase.init();
            } catch (InconsistentModelsException e1) {
                LOGGER.error("", e);
                serverInfoManager.setServerState(ServerState.FATAL_ERROR);
                serverInfoManager.setErrorMessage("Inconsistent models");
            }
        } catch (InconsistentModelsException e) {
            LOGGER.error("", e);
            serverInfoManager.setServerState(ServerState.FATAL_ERROR);
            serverInfoManager.setErrorMessage("Inconsistent models");
        }
        try (DatabaseSession encsession = bimDatabase.createSession()) {
            byte[] encryptionkeyBytes = null;
            if (!bimDatabase.getRegistry().has(ENCRYPTIONKEY, encsession)) {
                encryptionkeyBytes = new byte[16];
                new SecureRandom().nextBytes(encryptionkeyBytes);
                bimDatabase.getRegistry().save(ENCRYPTIONKEY, encryptionkeyBytes, encsession);
                encsession.commit();
            } else {
                encryptionkeyBytes = bimDatabase.getRegistry().readByteArray(ENCRYPTIONKEY, encsession);
            }
            encryptionkey = new SecretKeySpec(encryptionkeyBytes, "AES");
        }
        cleanupStaleData();
        protocolBuffersMetaData = new ProtocolBuffersMetaData();
        protocolBuffersMetaData.load(servicesMap, ProtocolBuffersBimServerClientFactory.class);
        serverInfoManager.init(this);
        webModuleManager = new WebModuleManager(this);
        jsonHandler = new JsonHandler(this);
        serializerFactory = new SerializerFactory();
        serverSettingsCache = new ServerSettingsCache(bimDatabase);
        serverInfoManager.update();
        // int renderEngineProcesses = getServerSettingsCache().getServerSettings().getRenderEngineProcesses();
        // RenderEnginePoolFactory renderEnginePoolFactory = new CommonsPoolingRenderEnginePoolFactory(renderEngineProcesses);
        RenderEnginePoolFactory renderEnginePoolFactory = new NoPoolingRenderEnginePoolFactory();
        renderEnginePools = new RenderEnginePools(this, renderEnginePoolFactory);
        if (serverInfoManager.getServerState() == ServerState.MIGRATION_REQUIRED) {
            serverInfoManager.registerStateChangeListener(new StateChangeListener() {

                @Override
                public void stateChanged(ServerState oldState, ServerState newState) {
                    if (oldState == ServerState.MIGRATION_REQUIRED && newState == ServerState.RUNNING) {
                        try {
                            initDatabaseDependantItems();
                        } catch (BimserverDatabaseException e) {
                            LOGGER.error("", e);
                        }
                    }
                }
            });
        } else {
            initDatabaseDependantItems();
        }
        mailSystem = new MailSystem(this);
        diskCacheManager = new DiskCacheManager(this, config.getHomeDir().resolve("cache"));
        newDiskCacheManager = new NewDiskCacheManager(this, config.getHomeDir().resolve("cache"));
        mergerFactory = new MergerFactory(this);
        RealtimeReflectorFactoryBuilder factoryBuilder = new RealtimeReflectorFactoryBuilder(servicesMap);
        reflectorFactory = factoryBuilder.newReflectorFactory();
        if (reflectorFactory == null) {
            throw new RuntimeException("No reflector factory!");
        }
        servicesMap.setReflectorFactory(reflectorFactory);
        bimScheduler = new JobScheduler(this);
        bimScheduler.start();
        if (config.isStartEmbeddedWebServer()) {
            embeddedWebServer.start();
        }
        if (config.isStartCommandLine()) {
            commandLine = new CommandLine(this);
            commandLine.start();
        }
        if (getServerInfoManager().getServerState() == ServerState.SETUP) {
            getServerInfoManager().setServerState(ServerState.RUNNING);
        }
    } catch (Throwable e) {
        LOGGER.error("", e);
        serverInfoManager.setErrorMessage(e.getMessage());
    }
}
Also used : SPluginBundleVersion(org.bimserver.interfaces.objects.SPluginBundleVersion) LinkedHashSet(java.util.LinkedHashSet) DatabaseSession(org.bimserver.database.DatabaseSession) StringType(org.bimserver.models.store.StringType) IfcModelInterface(org.bimserver.emf.IfcModelInterface) ArrayList(java.util.ArrayList) ProtocolBuffersMetaData(org.bimserver.shared.pb.ProtocolBuffersMetaData) LongActionManager(org.bimserver.longaction.LongActionManager) EPackage(org.eclipse.emf.ecore.EPackage) PluginBundle(org.bimserver.plugins.PluginBundle) TemplateEngine(org.bimserver.templating.TemplateEngine) Ifc4ToIfc2x3tc1SchemaConverterFactory(org.bimserver.schemaconverter.Ifc4ToIfc2x3tc1SchemaConverterFactory) SecretKeySpec(javax.crypto.spec.SecretKeySpec) Database(org.bimserver.database.Database) BimDatabase(org.bimserver.database.BimDatabase) Ifc2x3tc1ToIfc4SchemaConverterFactory(org.bimserver.schemaconverter.Ifc2x3tc1ToIfc4SchemaConverterFactory) PluginChangeListener(org.bimserver.plugins.PluginChangeListener) SPluginInformation(org.bimserver.interfaces.objects.SPluginInformation) WebModulePluginConfiguration(org.bimserver.models.store.WebModulePluginConfiguration) PluginException(org.bimserver.shared.exceptions.PluginException) AttributeCondition(org.bimserver.database.query.conditions.AttributeCondition) GregorianCalendar(java.util.GregorianCalendar) SecureRandom(java.security.SecureRandom) SVersion(org.bimserver.interfaces.objects.SVersion) PluginDescriptor(org.bimserver.models.store.PluginDescriptor) StringLiteral(org.bimserver.database.query.literals.StringLiteral) ServiceException(org.bimserver.shared.exceptions.ServiceException) MavenPluginRepository(org.bimserver.plugins.MavenPluginRepository) DatabaseRestartRequiredException(org.bimserver.database.DatabaseRestartRequiredException) RenderEnginePools(org.bimserver.renderengine.RenderEnginePools) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) SServicesMap(org.bimserver.shared.meta.SServicesMap) InconsistentModelsException(org.bimserver.database.migrations.InconsistentModelsException) ServicePlugin(org.bimserver.plugins.services.ServicePlugin) NoPoolingRenderEnginePoolFactory(org.bimserver.renderengine.NoPoolingRenderEnginePoolFactory) User(org.bimserver.models.store.User) URL(java.net.URL) ServerSettings(org.bimserver.models.store.ServerSettings) PluginConfiguration(org.bimserver.models.store.PluginConfiguration) SerializerPluginConfiguration(org.bimserver.models.store.SerializerPluginConfiguration) WebModulePluginConfiguration(org.bimserver.models.store.WebModulePluginConfiguration) InternalServicePluginConfiguration(org.bimserver.models.store.InternalServicePluginConfiguration) SInternalServicePluginConfiguration(org.bimserver.interfaces.objects.SInternalServicePluginConfiguration) WebModulePlugin(org.bimserver.plugins.web.WebModulePlugin) PluginBundleVersion(org.bimserver.models.store.PluginBundleVersion) SPluginBundleVersion(org.bimserver.interfaces.objects.SPluginBundleVersion) RealtimeReflectorFactoryBuilder(org.bimserver.shared.reflector.RealtimeReflectorFactoryBuilder) Condition(org.bimserver.database.query.conditions.Condition) AttributeCondition(org.bimserver.database.query.conditions.AttributeCondition) Path(java.nio.file.Path) BerkeleyKeyValueStore(org.bimserver.database.berkeley.BerkeleyKeyValueStore) SerializerFactory(org.bimserver.serializers.SerializerFactory) PluginContext(org.bimserver.plugins.PluginContext) MailSystem(org.bimserver.mail.MailSystem) ServerState(org.bimserver.models.store.ServerState) RenderEnginePoolFactory(org.bimserver.renderengine.RenderEnginePoolFactory) NoPoolingRenderEnginePoolFactory(org.bimserver.renderengine.NoPoolingRenderEnginePoolFactory) NewDiskCacheManager(org.bimserver.cache.NewDiskCacheManager) ServiceException(org.bimserver.shared.exceptions.ServiceException) IOException(java.io.IOException) ServerException(org.bimserver.shared.exceptions.ServerException) PluginException(org.bimserver.shared.exceptions.PluginException) InconsistentModelsException(org.bimserver.database.migrations.InconsistentModelsException) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException) DatabaseRestartRequiredException(org.bimserver.database.DatabaseRestartRequiredException) DatabaseInitException(org.bimserver.database.berkeley.DatabaseInitException) InternalServicePluginConfiguration(org.bimserver.models.store.InternalServicePluginConfiguration) SInternalServicePluginConfiguration(org.bimserver.interfaces.objects.SInternalServicePluginConfiguration) Parameter(org.bimserver.models.store.Parameter) NewDiskCacheManager(org.bimserver.cache.NewDiskCacheManager) DiskCacheManager(org.bimserver.cache.DiskCacheManager) ModelCheckerPlugin(org.bimserver.plugins.modelchecker.ModelCheckerPlugin) ServicePlugin(org.bimserver.plugins.services.ServicePlugin) WebModulePlugin(org.bimserver.plugins.web.WebModulePlugin) Plugin(org.bimserver.plugins.Plugin)

Example 4 with IfcModelInterface

use of org.bimserver.emf.IfcModelInterface in project BIMserver by opensourceBIM.

the class CommandLine method run.

@Override
public void run() {
    reader = new BufferedReader(new InputStreamReader(System.in));
    running = true;
    try {
        while (running) {
            try {
                String line = reader.readLine();
                if (line == null) {
                    Thread.sleep(50);
                    continue;
                }
                if (line.equalsIgnoreCase("exit")) {
                    bimServer.stop();
                    return;
                } else if (line.startsWith("dumpmodel")) {
                    try {
                        long roid = Long.parseLong(line.substring(9).trim());
                        DatabaseSession databaseSession = bimServer.getDatabase().createSession();
                        try {
                            DownloadDatabaseAction downloadDatabaseAction = new DownloadDatabaseAction(bimServer, databaseSession, AccessMethod.INTERNAL, roid, -1, -1, new SystemAuthorization(1, TimeUnit.HOURS), null);
                            IfcModelInterface model = downloadDatabaseAction.execute();
                            LOGGER.info("Model size: " + model.size());
                            List<IfcWall> walls = model.getAll(IfcWall.class);
                            List<IfcProject> projects = model.getAll(IfcProject.class);
                            List<IfcSlab> slabs = model.getAll(IfcSlab.class);
                            List<IfcWindow> windows = model.getAll(IfcWindow.class);
                            LOGGER.info("Walls: " + walls.size());
                            LOGGER.info("Windows: " + windows.size());
                            LOGGER.info("Projects: " + projects.size());
                            LOGGER.info("Slabs: " + slabs.size());
                        } catch (UserException e) {
                            LOGGER.error("", e);
                        } catch (BimserverLockConflictException e) {
                            LOGGER.error("", e);
                        } catch (BimserverDatabaseException e) {
                            LOGGER.error("", e);
                        } finally {
                            databaseSession.close();
                        }
                    } catch (Exception e) {
                        LOGGER.error("", e);
                    }
                } else if (line.equalsIgnoreCase("dump")) {
                    LOGGER.info("Dumping all thread's track traces...");
                    LOGGER.info("");
                    Map<Thread, StackTraceElement[]> allStackTraces = Thread.getAllStackTraces();
                    for (Thread t : allStackTraces.keySet()) {
                        LOGGER.info(t.getName());
                        StackTraceElement[] stackTraceElements = allStackTraces.get(t);
                        for (StackTraceElement stackTraceElement : stackTraceElements) {
                            LOGGER.info("\t" + stackTraceElement.getClassName() + ":" + stackTraceElement.getLineNumber() + "." + stackTraceElement.getMethodName());
                        }
                        LOGGER.info("");
                    }
                    LOGGER.info("Done printing stack traces");
                    LOGGER.info("");
                    Thread.sleep(10000);
                } else if (line.equals("migrate")) {
                    try {
                        bimServer.getDatabase().getMigrator().migrate();
                        bimServer.getServerInfoManager().update();
                    } catch (MigrationException e) {
                        LOGGER.error("", e);
                    } catch (InconsistentModelsException e) {
                        LOGGER.error("", e);
                    }
                } else if (line.equals("clearendpoints")) {
                    bimServer.getEndPointManager().clear();
                } else if (line.startsWith("showall")) {
                    KeyValueStore keyValueStore = ((Database) bimServer.getDatabase()).getKeyValueStore();
                    Set<String> allTableNames = keyValueStore.getAllTableNames();
                    long total = 0;
                    for (String tableName : allTableNames) {
                        long size = keyValueStore.count(tableName);
                        total += size;
                        if (size != 0) {
                            LOGGER.info(tableName + " " + size);
                        }
                    }
                    LOGGER.info("total: " + total);
                } else {
                    LOGGER.info("Unknown command");
                }
            } catch (IOException e) {
                LOGGER.error("", e);
            }
        }
    } catch (InterruptedException e) {
    }
}
Also used : InconsistentModelsException(org.bimserver.database.migrations.InconsistentModelsException) Set(java.util.Set) DatabaseSession(org.bimserver.database.DatabaseSession) IfcModelInterface(org.bimserver.emf.IfcModelInterface) KeyValueStore(org.bimserver.database.KeyValueStore) SystemAuthorization(org.bimserver.webservices.authorization.SystemAuthorization) List(java.util.List) UserException(org.bimserver.shared.exceptions.UserException) DownloadDatabaseAction(org.bimserver.database.actions.DownloadDatabaseAction) IfcWall(org.bimserver.models.ifc2x3tc1.IfcWall) IfcProject(org.bimserver.models.ifc2x3tc1.IfcProject) IfcWindow(org.bimserver.models.ifc2x3tc1.IfcWindow) InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException) IOException(java.io.IOException) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException) MigrationException(org.bimserver.database.migrations.MigrationException) UserException(org.bimserver.shared.exceptions.UserException) InconsistentModelsException(org.bimserver.database.migrations.InconsistentModelsException) IfcSlab(org.bimserver.models.ifc2x3tc1.IfcSlab) MigrationException(org.bimserver.database.migrations.MigrationException) BufferedReader(java.io.BufferedReader) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException)

Example 5 with IfcModelInterface

use of org.bimserver.emf.IfcModelInterface in project BIMserver by opensourceBIM.

the class TestSetWrappedIntegerGeometry method test.

@Test
public void test() {
    try {
        BimServerClientInterface bimServerClient = getFactory().create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
        bimServerClient.getSettingsInterface().setCacheOutputFiles(false);
        LowLevelInterface lowLevelInterface = bimServerClient.getLowLevelInterface();
        SProject newProject = bimServerClient.getServiceInterface().addProject("test" + Math.random(), "ifc2x3tc1");
        SDeserializerPluginConfiguration suggestedDeserializerForExtension = bimServerClient.getServiceInterface().getSuggestedDeserializerForExtension("ifc", newProject.getOid());
        bimServerClient.checkin(newProject.getOid(), "initial", suggestedDeserializerForExtension.getOid(), false, Flow.SYNC, new URL("https://github.com/opensourceBIM/TestFiles/raw/master/TestData/data/revit_quantities.ifc"));
        newProject = bimServerClient.getServiceInterface().getProjectByPoid(newProject.getOid());
        SSerializerPluginConfiguration serializer = bimServerClient.getServiceInterface().getSerializerByName("Ifc2x3tc1 (Streaming)");
        bimServerClient.download(newProject.getLastRevisionId(), serializer.getOid(), Paths.get("test1.ifc"));
        IfcModelInterface model = bimServerClient.getModel(newProject, newProject.getLastRevisionId(), false, false);
        long tid = lowLevelInterface.startTransaction(newProject.getOid());
        IfcPropertySingleValue ifcPropertySingleValue = model.getAll(IfcPropertySingleValue.class).iterator().next();
        bimServerClient.getLowLevelInterface().setWrappedLongAttribute(tid, ifcPropertySingleValue.getOid(), "NominalValue", "IfcInteger", 12345L);
        long roid = lowLevelInterface.commitTransaction(tid, "v2");
        IfcModelInterface newModel = bimServerClient.getModel(newProject, roid, true, false, true);
        SVector3f minBounds = newModel.getModelMetaData().getMinBounds();
        SVector3f maxBounds = newModel.getModelMetaData().getMaxBounds();
        org.junit.Assert.assertNotNull(minBounds);
        org.junit.Assert.assertNotNull(maxBounds);
        bimServerClient.download(newProject.getLastRevisionId(), serializer.getOid(), Paths.get("test2.ifc"));
        bimServerClient.download(roid, serializer.getOid(), Paths.get("test3.ifc"));
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : IfcPropertySingleValue(org.bimserver.models.ifc2x3tc1.IfcPropertySingleValue) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) IfcModelInterface(org.bimserver.emf.IfcModelInterface) SVector3f(org.bimserver.interfaces.objects.SVector3f) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) SProject(org.bimserver.interfaces.objects.SProject) LowLevelInterface(org.bimserver.shared.interfaces.LowLevelInterface) URL(java.net.URL) Test(org.junit.Test)

Aggregations

IfcModelInterface (org.bimserver.emf.IfcModelInterface)58 SProject (org.bimserver.interfaces.objects.SProject)22 UserException (org.bimserver.shared.exceptions.UserException)21 BimServerClientInterface (org.bimserver.plugins.services.BimServerClientInterface)20 UsernamePasswordAuthenticationInfo (org.bimserver.shared.UsernamePasswordAuthenticationInfo)17 Test (org.junit.Test)17 SDeserializerPluginConfiguration (org.bimserver.interfaces.objects.SDeserializerPluginConfiguration)16 PackageMetaData (org.bimserver.emf.PackageMetaData)15 URL (java.net.URL)14 Revision (org.bimserver.models.store.Revision)14 User (org.bimserver.models.store.User)14 ModelHelper (org.bimserver.plugins.ModelHelper)13 OldQuery (org.bimserver.database.OldQuery)12 Project (org.bimserver.models.store.Project)12 IOException (java.io.IOException)11 ArrayList (java.util.ArrayList)11 IdEObject (org.bimserver.emf.IdEObject)11 DatabaseSession (org.bimserver.database.DatabaseSession)10 ConcreteRevision (org.bimserver.models.store.ConcreteRevision)10 IfcModelSet (org.bimserver.plugins.IfcModelSet)10