Search in sources :

Example 1 with UserSettings

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

the class MergerFactory method createMerger.

public org.bimserver.plugins.modelmerger.ModelMerger createMerger(DatabaseSession databaseSession, Long currentUoid) throws MergeException, BimserverDatabaseException {
    DatabaseSession session = bimServer.getDatabase().createSession();
    try {
        User user = databaseSession.get(StorePackage.eINSTANCE.getUser(), currentUoid, OldQuery.getDefault());
        UserSettings userSettings = user.getUserSettings();
        ModelMergerPluginConfiguration modelMergerObject = userSettings.getDefaultModelMerger();
        if (modelMergerObject != null) {
            ModelMergerPlugin modelMergerPlugin = bimServer.getPluginManager().getModelMergerPlugin(modelMergerObject.getPluginDescriptor().getPluginClassName(), true);
            if (modelMergerPlugin != null) {
                org.bimserver.plugins.modelmerger.ModelMerger modelMerger = modelMergerPlugin.createModelMerger(new PluginConfiguration(modelMergerObject.getSettings()));
                return modelMerger;
            } else {
                throw new MergeException("No Model Merger found " + modelMergerObject.getPluginDescriptor().getPluginClassName());
            }
        } else {
            throw new MergeException("No configured Model Merger found");
        }
    } finally {
        session.close();
    }
}
Also used : ModelMergerPluginConfiguration(org.bimserver.models.store.ModelMergerPluginConfiguration) User(org.bimserver.models.store.User) DatabaseSession(org.bimserver.database.DatabaseSession) ModelMergerPlugin(org.bimserver.plugins.modelmerger.ModelMergerPlugin) MergeException(org.bimserver.plugins.modelmerger.MergeException) UserSettings(org.bimserver.models.store.UserSettings) ModelMergerPluginConfiguration(org.bimserver.models.store.ModelMergerPluginConfiguration) PluginConfiguration(org.bimserver.plugins.PluginConfiguration)

Example 2 with UserSettings

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

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

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

the class BimServer method updateUserSettings.

public void updateUserSettings(DatabaseSession session, User user) throws BimserverLockConflictException, BimserverDatabaseException {
    UserSettings userSettings = user.getUserSettings();
    if (userSettings == null) {
        userSettings = session.create(UserSettings.class);
        user.setUserSettings(userSettings);
        session.store(user);
    }
    for (Entry<PluginContext, Plugin> pluginEntry : pluginManager.getAllPlugins(true).entrySet()) {
        if (pluginEntry.getValue() instanceof WebModulePlugin || pluginEntry.getValue() instanceof ModelCheckerPlugin) {
            // Non-user related types of plugins
            continue;
        }
        PluginDescriptor pluginDescriptor = getPluginDescriptor(session, pluginEntry.getKey().getIdentifier());
        if (pluginDescriptor == null) {
            LOGGER.error("No plugin descriptor found: " + pluginEntry.getKey().getIdentifier());
        // throw new BimserverDatabaseException("No plugin descriptor found: " + pluginEntry.getKey().getIdentifier());
        } else {
            updateUserPlugin(session, user, pluginDescriptor, pluginEntry.getKey());
        }
    }
    session.store(userSettings);
}
Also used : ModelCheckerPlugin(org.bimserver.plugins.modelchecker.ModelCheckerPlugin) PluginDescriptor(org.bimserver.models.store.PluginDescriptor) PluginContext(org.bimserver.plugins.PluginContext) UserSettings(org.bimserver.models.store.UserSettings) WebModulePlugin(org.bimserver.plugins.web.WebModulePlugin) ModelCheckerPlugin(org.bimserver.plugins.modelchecker.ModelCheckerPlugin) ServicePlugin(org.bimserver.plugins.services.ServicePlugin) WebModulePlugin(org.bimserver.plugins.web.WebModulePlugin) Plugin(org.bimserver.plugins.Plugin)

Example 5 with UserSettings

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

the class TestDatabase method checkLists3.

private void checkLists3() {
    DatabaseSession session = database.createSession();
    long xid = -1;
    try {
        User user = session.create(User.class);
        UserSettings userSettings = session.create(UserSettings.class);
        SerializerPluginConfiguration serializerPluginConfiguration1 = session.create(SerializerPluginConfiguration.class);
        SerializerPluginConfiguration serializerPluginConfiguration2 = session.create(SerializerPluginConfiguration.class);
        xid = serializerPluginConfiguration2.getOid();
        user.setUserSettings(userSettings);
        serializerPluginConfiguration1.setUserSettings(userSettings);
        serializerPluginConfiguration2.setUserSettings(userSettings);
        session.commit();
    } catch (BimserverDatabaseException e) {
        e.printStackTrace();
    } catch (ServiceException e) {
        e.printStackTrace();
    } finally {
        session.close();
        session = database.createSession();
        try {
            SerializerPluginConfiguration p1 = session.get(xid, OldQuery.getDefault());
            UserSettings userSettings = p1.getUserSettings();
            for (SerializerPluginConfiguration p2 : userSettings.getSerializers()) {
                System.out.println(p2.getOid() + " - " + p2);
            }
        } catch (BimserverDatabaseException e) {
            e.printStackTrace();
        } finally {
            session.close();
        }
    }
}
Also used : BimserverDatabaseException(org.bimserver.BimserverDatabaseException) User(org.bimserver.models.store.User) ServiceException(org.bimserver.shared.exceptions.ServiceException) DatabaseSession(org.bimserver.database.DatabaseSession) UserSettings(org.bimserver.models.store.UserSettings) SerializerPluginConfiguration(org.bimserver.models.store.SerializerPluginConfiguration)

Aggregations

UserSettings (org.bimserver.models.store.UserSettings)43 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)29 DatabaseSession (org.bimserver.database.DatabaseSession)29 UserException (org.bimserver.shared.exceptions.UserException)22 IOException (java.io.IOException)18 ServerException (org.bimserver.shared.exceptions.ServerException)18 SPluginConfigurationComparator (org.bimserver.webservices.SPluginConfigurationComparator)10 User (org.bimserver.models.store.User)9 SerializerPluginConfiguration (org.bimserver.models.store.SerializerPluginConfiguration)7 ArrayList (java.util.ArrayList)6 SetUserSettingDatabaseAction (org.bimserver.database.actions.SetUserSettingDatabaseAction)6 UserSettingsSetter (org.bimserver.database.actions.UserSettingsSetter)6 InternalServicePluginConfiguration (org.bimserver.models.store.InternalServicePluginConfiguration)5 PluginConfiguration (org.bimserver.plugins.PluginConfiguration)5 IfcModelInterface (org.bimserver.emf.IfcModelInterface)4 SDeserializerPluginConfiguration (org.bimserver.interfaces.objects.SDeserializerPluginConfiguration)4 DeserializerPluginConfiguration (org.bimserver.models.store.DeserializerPluginConfiguration)4 RenderEnginePluginConfiguration (org.bimserver.models.store.RenderEnginePluginConfiguration)4 List (java.util.List)3 OldQuery (org.bimserver.database.OldQuery)3