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();
}
}
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);
}
}
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);
}
}
}
}
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);
}
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();
}
}
}
Aggregations