Search in sources :

Example 1 with PluginConfiguration

use of org.bimserver.models.store.PluginConfiguration in project BIMserver by opensourceBIM.

the class BimServer method updateUserPlugin.

@SuppressWarnings("unchecked")
public void updateUserPlugin(DatabaseSession session, User user, PluginDescriptor pluginDescriptor, PluginContext pluginContext) throws BimserverDatabaseException {
    if (pluginDescriptor.isInstallForNewUsers()) {
        UserSettings userSettings = user.getUserSettings();
        if (userSettings == null) {
            userSettings = session.create(UserSettings.class);
            user.setUserSettings(userSettings);
            session.store(user);
        }
        Class<?> pluginInterface = getPluginInterface(pluginContext.getPlugin().getClass());
        String originalPluginInterfaceName = pluginInterface.getSimpleName();
        String pluginInterfaceName = pluginInterface.getSimpleName();
        if (pluginInterfaceName.endsWith("Plugin")) {
            pluginInterfaceName = pluginInterfaceName.substring(0, pluginInterfaceName.length() - 6);
        }
        if (pluginInterfaceName.equals("StreamingSerializer")) {
            pluginInterfaceName = "Serializer";
        } else if (pluginInterfaceName.equals("MessagingStreamingSerializer")) {
            pluginInterfaceName = "MessagingSerializer";
        }
        if (pluginInterfaceName.equals("StreamingDeserializer")) {
            pluginInterfaceName = "Deserializer";
        }
        if (pluginInterfaceName.equals("ModelChecker") || pluginInterfaceName.equals("WebModule")) {
            // ServerSettings
            return;
        }
        EClass userSettingsClass = StorePackage.eINSTANCE.getUserSettings();
        String listRefName = StringUtils.firstLowerCase(pluginInterfaceName) + "s";
        if (listRefName.equals("messagingSerializers")) {
            listRefName = "serializers";
        }
        EReference listReference = (EReference) userSettingsClass.getEStructuralFeature(listRefName);
        if (listReference == null) {
            LOGGER.warn(listRefName + " not found");
            return;
        }
        EReference defaultReference = (EReference) userSettingsClass.getEStructuralFeature("default" + pluginInterfaceName);
        EClass pluginConfigurationClass = (EClass) StorePackage.eINSTANCE.getEClassifier((pluginInterfaceName.equals("Service") ? "Internal" : "") + pluginInterfaceName + "PluginConfiguration");
        List<PluginConfiguration> list = (List<PluginConfiguration>) userSettings.eGet(listReference);
        PluginConfiguration pluginConfiguration = find(list, pluginContext.getIdentifier());
        if (pluginConfiguration == null) {
            pluginConfiguration = (PluginConfiguration) session.create(pluginConfigurationClass);
            if (pluginConfiguration instanceof SerializerPluginConfiguration) {
                boolean streaming = originalPluginInterfaceName.equals("StreamingSerializerPlugin") || originalPluginInterfaceName.equals("MessagingStreamingSerializerPlugin");
                ((SerializerPluginConfiguration) pluginConfiguration).setStreaming(streaming);
            } else if (pluginConfiguration instanceof InternalServicePluginConfiguration) {
                ((InternalServicePluginConfiguration) pluginConfiguration).setUserSettings(userSettings);
            }
            list.add(pluginConfiguration);
            genericPluginConversion(pluginContext, session, pluginConfiguration, pluginDescriptor);
        }
        if (pluginInterfaceName.equals("Service")) {
            activateService(user.getOid(), (InternalServicePluginConfiguration) pluginConfiguration);
        }
        if (defaultReference != null) {
            if (userSettings.eGet(defaultReference) == null || pluginConfiguration.getName().equals("IfcOpenShell")) {
                userSettings.eSet(defaultReference, pluginConfiguration);
            }
        }
        session.store(userSettings);
    }
}
Also used : EClass(org.eclipse.emf.ecore.EClass) UserSettings(org.bimserver.models.store.UserSettings) InternalServicePluginConfiguration(org.bimserver.models.store.InternalServicePluginConfiguration) SInternalServicePluginConfiguration(org.bimserver.interfaces.objects.SInternalServicePluginConfiguration) 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) SerializerPluginConfiguration(org.bimserver.models.store.SerializerPluginConfiguration) ArrayList(java.util.ArrayList) InterfaceList(org.bimserver.shared.InterfaceList) List(java.util.List) EReference(org.eclipse.emf.ecore.EReference)

Example 2 with PluginConfiguration

use of org.bimserver.models.store.PluginConfiguration 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 3 with PluginConfiguration

use of org.bimserver.models.store.PluginConfiguration in project BIMserver by opensourceBIM.

the class DownloadDatabaseAction method execute.

@Override
public IfcModelInterface execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException, ServerException {
    Revision revision = getRevisionByRoid(roid);
    PluginConfiguration serializerPluginConfiguration = getDatabaseSession().get(StorePackage.eINSTANCE.getPluginConfiguration(), serializerOid, OldQuery.getDefault());
    getAuthorization().canDownload(roid);
    if (revision == null) {
        throw new UserException("Revision with oid " + roid + " not found");
    }
    Project project = revision.getProject();
    User user = getUserByUoid(getAuthorization().getUoid());
    try {
        getAuthorization().canDownload(roid);
    } catch (UserException e) {
        if (!getAuthorization().hasRightsOnProjectOrSuperProjectsOrSubProjects(user, project)) {
            throw new UserException("User has insufficient rights to download revisions from this project");
        }
    }
    IfcModelSet ifcModelSet = new IfcModelSet();
    long incrSize = 0;
    EList<ConcreteRevision> concreteRevisions = revision.getConcreteRevisions();
    if (concreteRevisions.size() == 0) {
        throw new ServerException("No concrete revisions in revision");
    }
    for (ConcreteRevision subRevision : concreteRevisions) {
        incrSize += subRevision.getSize();
    }
    final long totalSize = incrSize;
    final AtomicLong total = new AtomicLong();
    IfcHeader ifcHeader = null;
    PackageMetaData lastPackageMetaData = null;
    Map<Integer, Long> pidRoidMap = new HashMap<>();
    pidRoidMap.put(project.getId(), roid);
    for (ConcreteRevision concreteRevision : concreteRevisions) {
        if (concreteRevision.getUser().getOid() != ignoreUoid) {
            PackageMetaData packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData(concreteRevision.getProject().getSchema());
            lastPackageMetaData = packageMetaData;
            IfcModel subModel = new ServerIfcModel(packageMetaData, pidRoidMap, getDatabaseSession());
            ifcHeader = concreteRevision.getIfcHeader();
            int highestStopId = findHighestStopRid(project, concreteRevision);
            OldQuery query = new OldQuery(packageMetaData, concreteRevision.getProject().getId(), concreteRevision.getId(), concreteRevision.getOid(), objectIDM, Deep.YES, highestStopId);
            subModel.addChangeListener(new IfcModelChangeListener() {

                @Override
                public void objectAdded(IdEObject idEObject) {
                    total.incrementAndGet();
                    if (totalSize == 0) {
                        setProgress("Preparing download...", 0);
                    } else {
                        setProgress("Preparing download...", (int) Math.round(100.0 * total.get() / totalSize));
                    }
                }
            });
            query.updateOidCounters(concreteRevision, getDatabaseSession());
            getDatabaseSession().getMap(subModel, query);
            if (serializerPluginConfiguration != null) {
                try {
                    checkGeometry(serializerPluginConfiguration, getBimServer().getPluginManager(), subModel, project, concreteRevision, revision);
                } catch (GeometryGeneratingException e) {
                    throw new UserException(e);
                }
            }
            subModel.getModelMetaData().setDate(concreteRevision.getDate());
            ifcModelSet.add(subModel);
        }
    }
    IfcModelInterface ifcModel = new ServerIfcModel(lastPackageMetaData, pidRoidMap, getDatabaseSession());
    if (ifcModelSet.size() > 1) {
        try {
            ifcModel = getBimServer().getMergerFactory().createMerger(getDatabaseSession(), getAuthorization().getUoid()).merge(revision.getProject(), ifcModelSet, new ModelHelper(getBimServer().getMetaDataManager(), ifcModel));
        } catch (MergeException e) {
            throw new UserException(e);
        }
    } else {
        ifcModel = ifcModelSet.iterator().next();
    }
    if (ifcHeader != null) {
        ifcHeader.load();
        ifcModel.getModelMetaData().setIfcHeader(ifcHeader);
    }
    ifcModel.getModelMetaData().setName(project.getName() + "." + revision.getId());
    ifcModel.getModelMetaData().setRevisionId(project.getRevisions().indexOf(revision) + 1);
    if (user != null) {
        ifcModel.getModelMetaData().setAuthorizedUser(user.getName());
    }
    ifcModel.getModelMetaData().setDate(revision.getDate());
    if (revision.getProject().getGeoTag() != null) {
    // ifcModel.setLon(revision.getProject().getGeoTag().getX());
    // ifcModel.setLat(revision.getProject().getGeoTag().getY());
    // ifcModel.setAltitude((int)
    // revision.getProject().getGeoTag().getZ());
    // ifcModel.setDirectionAngle(revision.getProject().getGeoTag().getDirectionAngle());
    // try {
    // CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:" +
    // revision.getProject().getGeoTag().getEpsg());
    // CoordinateReferenceSystem targetCRS =
    // DefaultGeocentricCRS.CARTESIAN;
    // MathTransform transform = CRS.findMathTransform(sourceCRS,
    // targetCRS, true);
    // float[] in = new
    // float[]{revision.getProject().getGeoTag().getX1(),
    // revision.getProject().getGeoTag().getY1(),
    // revision.getProject().getGeoTag().getZ1()};
    // float[] result = new float[3];
    // transform.transform(in, 0, result, 0, 1);
    // IfcModel.setLon(result[0]);
    // IfcModel.setLat(result[1]);
    // } catch (NoSuchAuthorityCodeException e) {
    // LOGGER.error("", e);
    // } catch (FactoryException e) {
    // LOGGER.error("", e);
    // } catch (MismatchedDimensionException e) {
    // LOGGER.error("", e);
    // } catch (TransformException e) {
    // LOGGER.error("", e);
    // }
    }
    return ifcModel;
}
Also used : User(org.bimserver.models.store.User) ServerIfcModel(org.bimserver.ServerIfcModel) HashMap(java.util.HashMap) IfcModelInterface(org.bimserver.emf.IfcModelInterface) IfcModelChangeListener(org.bimserver.ifc.IfcModelChangeListener) GeometryGeneratingException(org.bimserver.GeometryGeneratingException) ServerIfcModel(org.bimserver.ServerIfcModel) IfcModel(org.bimserver.ifc.IfcModel) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) MergeException(org.bimserver.plugins.modelmerger.MergeException) PluginConfiguration(org.bimserver.models.store.PluginConfiguration) UserException(org.bimserver.shared.exceptions.UserException) ServerException(org.bimserver.shared.exceptions.ServerException) ModelHelper(org.bimserver.plugins.ModelHelper) IdEObject(org.bimserver.emf.IdEObject) PackageMetaData(org.bimserver.emf.PackageMetaData) IfcHeader(org.bimserver.models.store.IfcHeader) OldQuery(org.bimserver.database.OldQuery) Project(org.bimserver.models.store.Project) AtomicLong(java.util.concurrent.atomic.AtomicLong) Revision(org.bimserver.models.store.Revision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) AtomicLong(java.util.concurrent.atomic.AtomicLong) IfcModelSet(org.bimserver.plugins.IfcModelSet)

Example 4 with PluginConfiguration

use of org.bimserver.models.store.PluginConfiguration in project BIMserver by opensourceBIM.

the class DownloadProjectsDatabaseAction method execute.

@Override
public IfcModelInterface execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    User user = getUserByUoid(getAuthorization().getUoid());
    Project project = null;
    String projectName = "";
    IfcModelSet ifcModelSet = new IfcModelSet();
    long incrSize = 0;
    for (long roid : roids) {
        Revision revision = getRevisionByRoid(roid);
        for (ConcreteRevision subRevision : revision.getConcreteRevisions()) {
            incrSize += subRevision.getSize();
        }
    }
    final long totalSize = incrSize;
    final AtomicLong total = new AtomicLong();
    PluginConfiguration serializerPluginConfiguration = getDatabaseSession().get(StorePackage.eINSTANCE.getPluginConfiguration(), serializerOid, OldQuery.getDefault());
    PackageMetaData lastPackageMetaData = null;
    IfcHeader ifcHeader = null;
    Map<Integer, Long> pidRoidMap = new HashMap<>();
    for (long roid : roids) {
        Revision revision = getRevisionByRoid(roid);
        project = revision.getProject();
        pidRoidMap.put(project.getId(), roid);
        if (getAuthorization().hasRightsOnProjectOrSuperProjectsOrSubProjects(user, project)) {
            for (ConcreteRevision concreteRevision : revision.getConcreteRevisions()) {
                ifcHeader = concreteRevision.getIfcHeader();
                PackageMetaData packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData(concreteRevision.getProject().getSchema());
                lastPackageMetaData = packageMetaData;
                IfcModel subModel = new ServerIfcModel(packageMetaData, pidRoidMap, getDatabaseSession());
                int highestStopId = findHighestStopRid(project, concreteRevision);
                OldQuery query = new OldQuery(packageMetaData, concreteRevision.getProject().getId(), concreteRevision.getId(), revision.getOid(), objectIDM, Deep.YES, highestStopId);
                subModel.addChangeListener(new IfcModelChangeListener() {

                    @Override
                    public void objectAdded(IdEObject idEObject) {
                        total.incrementAndGet();
                        if (totalSize == 0) {
                            setProgress("Preparing download...", 0);
                        } else {
                            setProgress("Preparing download...", (int) Math.round(100.0 * total.get() / totalSize));
                        }
                    }
                });
                query.updateOidCounters(concreteRevision, getDatabaseSession());
                getDatabaseSession().getMap(subModel, query);
                projectName += concreteRevision.getProject().getName() + "-";
                subModel.getModelMetaData().setDate(concreteRevision.getDate());
                try {
                    checkGeometry(serializerPluginConfiguration, getBimServer().getPluginManager(), subModel, project, concreteRevision, revision);
                } catch (GeometryGeneratingException e) {
                    throw new UserException(e);
                }
                ifcModelSet.add(subModel);
            }
        } else {
            throw new UserException("User has no rights on project " + project.getOid());
        }
    }
    IfcModelInterface ifcModel = new ServerIfcModel(lastPackageMetaData, pidRoidMap, getDatabaseSession());
    if (ifcModelSet.size() == 1) {
        ifcModel = ifcModelSet.iterator().next();
    } else {
        try {
            ifcModel = getBimServer().getMergerFactory().createMerger(getDatabaseSession(), getAuthorization().getUoid()).merge(project, ifcModelSet, new ModelHelper(getBimServer().getMetaDataManager(), ifcModel));
        } catch (MergeException e) {
            throw new UserException(e);
        }
    }
    if (ifcHeader != null) {
        ifcHeader.load();
        ifcModel.getModelMetaData().setIfcHeader(ifcHeader);
    }
    if (projectName.endsWith("-")) {
        projectName = projectName.substring(0, projectName.length() - 1);
    }
    ifcModel.getModelMetaData().setName(projectName);
    return ifcModel;
}
Also used : User(org.bimserver.models.store.User) ServerIfcModel(org.bimserver.ServerIfcModel) HashMap(java.util.HashMap) IfcModelInterface(org.bimserver.emf.IfcModelInterface) IfcModelChangeListener(org.bimserver.ifc.IfcModelChangeListener) GeometryGeneratingException(org.bimserver.GeometryGeneratingException) ServerIfcModel(org.bimserver.ServerIfcModel) IfcModel(org.bimserver.ifc.IfcModel) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) MergeException(org.bimserver.plugins.modelmerger.MergeException) PluginConfiguration(org.bimserver.models.store.PluginConfiguration) UserException(org.bimserver.shared.exceptions.UserException) ModelHelper(org.bimserver.plugins.ModelHelper) IdEObject(org.bimserver.emf.IdEObject) PackageMetaData(org.bimserver.emf.PackageMetaData) IfcHeader(org.bimserver.models.store.IfcHeader) OldQuery(org.bimserver.database.OldQuery) Project(org.bimserver.models.store.Project) AtomicLong(java.util.concurrent.atomic.AtomicLong) Revision(org.bimserver.models.store.Revision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) AtomicLong(java.util.concurrent.atomic.AtomicLong) IfcModelSet(org.bimserver.plugins.IfcModelSet)

Example 5 with PluginConfiguration

use of org.bimserver.models.store.PluginConfiguration in project BIMserver by opensourceBIM.

the class LongDownloadOrCheckoutAction method executeAction.

protected void executeAction(BimDatabaseAction<? extends IfcModelInterface> action, DownloadParameters downloadParameters, DatabaseSession session, boolean commit) throws BimserverDatabaseException, UserException, NoSerializerFoundException, ServerException {
    try {
        if (action == null) {
            checkoutResult = new SCheckoutResult();
            checkoutResult.setFile(new CachingDataHandler(getBimServer().getDiskCacheManager(), downloadParameters));
            checkoutResult.setSerializerOid(downloadParameters.getSerializerOid());
        } else {
            Revision revision = session.get(StorePackage.eINSTANCE.getRevision(), downloadParameters.getRoid(), OldQuery.getDefault());
            if (revision == null) {
                throw new UserException("Revision with roid " + downloadParameters.getRoid() + " not found");
            }
            // Little hack to make
            revision.getProject().getGeoTag().load();
            // sure this is
            // lazily loaded,
            // because after the
            // executeAndCommitAction
            // the session won't
            // be usable
            IfcModelInterface ifcModel = session.executeAndCommitAction(action);
            // Session is closed after this
            DatabaseSession newSession = getBimServer().getDatabase().createSession();
            RenderEnginePlugin renderEnginePlugin = null;
            try {
                PluginConfiguration serializerPluginConfiguration = newSession.get(StorePackage.eINSTANCE.getPluginConfiguration(), downloadParameters.getSerializerOid(), OldQuery.getDefault());
                if (serializerPluginConfiguration != null) {
                    if (serializerPluginConfiguration instanceof MessagingSerializerPluginConfiguration) {
                        try {
                            messagingSerializer = getBimServer().getSerializerFactory().createMessagingSerializer(getUserName(), ifcModel, downloadParameters);
                        } catch (SerializerException e) {
                            e.printStackTrace();
                        }
                    } else if (serializerPluginConfiguration instanceof SerializerPluginConfiguration) {
                        RenderEnginePluginConfiguration renderEngine = ((SerializerPluginConfiguration) serializerPluginConfiguration).getRenderEngine();
                        if (renderEngine != null) {
                            renderEnginePlugin = getBimServer().getPluginManager().getRenderEnginePlugin(renderEngine.getPluginDescriptor().getPluginClassName(), true);
                        }
                        checkoutResult = convertModelToCheckoutResult(revision.getProject(), getUserName(), ifcModel, renderEnginePlugin, downloadParameters);
                    }
                }
            } catch (BimserverDatabaseException e) {
                LOGGER.error("", e);
            } finally {
                newSession.close();
            }
        }
    } finally {
        done();
    }
}
Also used : DatabaseSession(org.bimserver.database.DatabaseSession) IfcModelInterface(org.bimserver.emf.IfcModelInterface) SCheckoutResult(org.bimserver.interfaces.objects.SCheckoutResult) RenderEnginePlugin(org.bimserver.plugins.renderengine.RenderEnginePlugin) SerializerException(org.bimserver.plugins.serializers.SerializerException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) RenderEnginePluginConfiguration(org.bimserver.models.store.RenderEnginePluginConfiguration) Revision(org.bimserver.models.store.Revision) MessagingSerializerPluginConfiguration(org.bimserver.models.store.MessagingSerializerPluginConfiguration) RenderEnginePluginConfiguration(org.bimserver.models.store.RenderEnginePluginConfiguration) SerializerPluginConfiguration(org.bimserver.models.store.SerializerPluginConfiguration) PluginConfiguration(org.bimserver.models.store.PluginConfiguration) MessagingSerializerPluginConfiguration(org.bimserver.models.store.MessagingSerializerPluginConfiguration) SerializerPluginConfiguration(org.bimserver.models.store.SerializerPluginConfiguration) MessagingSerializerPluginConfiguration(org.bimserver.models.store.MessagingSerializerPluginConfiguration) UserException(org.bimserver.shared.exceptions.UserException)

Aggregations

PluginConfiguration (org.bimserver.models.store.PluginConfiguration)10 UserException (org.bimserver.shared.exceptions.UserException)7 IfcModelInterface (org.bimserver.emf.IfcModelInterface)5 SerializerPluginConfiguration (org.bimserver.models.store.SerializerPluginConfiguration)5 DatabaseSession (org.bimserver.database.DatabaseSession)4 SInternalServicePluginConfiguration (org.bimserver.interfaces.objects.SInternalServicePluginConfiguration)4 InternalServicePluginConfiguration (org.bimserver.models.store.InternalServicePluginConfiguration)4 WebModulePluginConfiguration (org.bimserver.models.store.WebModulePluginConfiguration)4 ServerException (org.bimserver.shared.exceptions.ServerException)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)3 GeometryGeneratingException (org.bimserver.GeometryGeneratingException)3 OldQuery (org.bimserver.database.OldQuery)3 IdEObject (org.bimserver.emf.IdEObject)3 PackageMetaData (org.bimserver.emf.PackageMetaData)3 IfcModel (org.bimserver.ifc.IfcModel)3 IfcModelChangeListener (org.bimserver.ifc.IfcModelChangeListener)3 ConcreteRevision (org.bimserver.models.store.ConcreteRevision)3