private void updatePlugins(DatabaseSession session) throws BimserverDatabaseException { Collection<Plugin> allPlugins = pluginManager.getAllPlugins(false); for (Plugin plugin : allPlugins) { Condition pluginCondition = new AttributeCondition( StorePackage.eINSTANCE.getPluginDescriptor_PluginClassName(), new StringLiteral(plugin.getClass().getName())); Map<Long, PluginDescriptor> results = session.query(pluginCondition, PluginDescriptor.class, Query.getDefault()); if (results.size() == 0) { PluginContext pluginContext = pluginManager.getPluginContext(plugin); PluginDescriptor pluginDescriptor = session.create(PluginDescriptor.class); pluginDescriptor.setPluginClassName(plugin.getClass().getName()); pluginDescriptor.setSimpleName(plugin.getClass().getSimpleName()); pluginDescriptor.setDescription(plugin.getDescription() + " " + plugin.getVersion()); pluginDescriptor.setLocation(pluginContext.getLocation().toString()); pluginDescriptor.setPluginInterfaceClassName(getPluginInterfaceClass(plugin).getName()); pluginDescriptor.setEnabled(true); // New plugins are enabled by default } else if (results.size() == 1) { PluginContext pluginContext = pluginManager.getPluginContext(plugin); PluginDescriptor pluginDescriptor = results.values().iterator().next(); pluginDescriptor.setPluginClassName(plugin.getClass().getName()); pluginDescriptor.setSimpleName(plugin.getClass().getSimpleName()); pluginDescriptor.setDescription(plugin.getDescription() + " " + plugin.getVersion()); pluginDescriptor.setLocation(pluginContext.getLocation().toString()); pluginDescriptor.setPluginInterfaceClassName(getPluginInterfaceClass(plugin).getName()); session.store(pluginDescriptor); pluginManager.getPluginContext(plugin).setEnabled(pluginDescriptor.getEnabled(), false); } else { LOGGER.error( "Multiple plugin descriptor objects found with the same name: " + plugin.getClass().getName()); } } }
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 (ObjectIDMPlugin objectIDMPlugin : pluginManager.getAllObjectIDMPlugins(true)) { ObjectIDMPluginConfiguration objectIdmPluginConfiguration = find(userSettings.getObjectIDMs(), objectIDMPlugin.getClass().getName()); if (objectIdmPluginConfiguration == null) { objectIdmPluginConfiguration = session.create(ObjectIDMPluginConfiguration.class); userSettings.getObjectIDMs().add(objectIdmPluginConfiguration); genericPluginConversion( session, objectIDMPlugin, objectIdmPluginConfiguration, getPluginDescriptor(session, objectIDMPlugin.getClass().getName())); } if (userSettings.getDefaultObjectIDM() == null && objectIDMPlugin.getClass() == SchemaFieldObjectIDMPlugin.class) { userSettings.setDefaultObjectIDM(objectIdmPluginConfiguration); } } if (userSettings.getDefaultObjectIDM() == null && !userSettings.getObjectIDMs().isEmpty()) { userSettings.setDefaultObjectIDM(userSettings.getObjectIDMs().get(0)); } for (RenderEnginePlugin ifcEnginePlugin : pluginManager.getAllRenderEnginePlugins(true)) { RenderEnginePluginConfiguration ifcEnginePluginConfiguration = find(userSettings.getRenderEngines(), ifcEnginePlugin.getClass().getName()); if (ifcEnginePluginConfiguration == null) { ifcEnginePluginConfiguration = session.create(RenderEnginePluginConfiguration.class); userSettings.getRenderEngines().add(ifcEnginePluginConfiguration); genericPluginConversion( session, ifcEnginePlugin, ifcEnginePluginConfiguration, getPluginDescriptor(session, ifcEnginePlugin.getClass().getName())); } if (userSettings.getDefaultRenderEngine() != null && userSettings .getDefaultRenderEngine() .getPluginDescriptor() .getPluginClassName() .equals("org.bimserver.ifcengine.TNOJvmRenderEnginePlugin") && ifcEnginePlugin .getClass() .getName() .equals("org.ifcopenshell.IfcOpenShellEnginePlugin")) { userSettings.setDefaultRenderEngine(ifcEnginePluginConfiguration); } if (userSettings.getDefaultRenderEngine() == null && ifcEnginePlugin .getClass() .getName() .equals("org.ifcopenshell.IfcOpenShellEnginePlugin")) { userSettings.setDefaultRenderEngine(ifcEnginePluginConfiguration); } } if (userSettings.getDefaultRenderEngine() == null && !userSettings.getRenderEngines().isEmpty()) { userSettings.setDefaultRenderEngine(userSettings.getRenderEngines().get(0)); } Iterator<RenderEnginePluginConfiguration> iterator = userSettings.getRenderEngines().iterator(); while (iterator.hasNext()) { RenderEnginePluginConfiguration next = iterator.next(); PluginDescriptor pluginDescriptor = next.getPluginDescriptor(); if (pluginDescriptor .getPluginClassName() .equals("org.bimserver.ifcengine.TNOJvmRenderEnginePlugin")) { iterator.remove(); } } for (QueryEnginePlugin queryEnginePlugin : pluginManager.getAllQueryEnginePlugins(true)) { QueryEnginePluginConfiguration queryEnginePluginConfiguration = find(userSettings.getQueryengines(), queryEnginePlugin.getClass().getName()); if (queryEnginePluginConfiguration == null) { queryEnginePluginConfiguration = session.create(QueryEnginePluginConfiguration.class); userSettings.getQueryengines().add(queryEnginePluginConfiguration); genericPluginConversion( session, queryEnginePlugin, queryEnginePluginConfiguration, getPluginDescriptor(session, queryEnginePlugin.getClass().getName())); } if (userSettings.getDefaultQueryEngine() == null && queryEnginePlugin .getClass() .getName() .equals("nl.wietmazairac.bimql.BimQLQueryEnginePlugin")) { userSettings.setDefaultQueryEngine(queryEnginePluginConfiguration); } } if (userSettings.getDefaultQueryEngine() == null && !userSettings.getQueryengines().isEmpty()) { userSettings.setDefaultQueryEngine(userSettings.getQueryengines().get(0)); } for (ModelMergerPlugin modelMergerPlugin : pluginManager.getAllModelMergerPlugins(true)) { ModelMergerPluginConfiguration modelMergerPluginConfiguration = find(userSettings.getModelmergers(), modelMergerPlugin.getClass().getName()); if (modelMergerPluginConfiguration == null) { modelMergerPluginConfiguration = session.create(ModelMergerPluginConfiguration.class); userSettings.getModelmergers().add(modelMergerPluginConfiguration); genericPluginConversion( session, modelMergerPlugin, modelMergerPluginConfiguration, getPluginDescriptor(session, modelMergerPlugin.getClass().getName())); } if (userSettings.getDefaultModelMerger() == null && modelMergerPlugin .getClass() .getName() .equals("org.bimserver.merging.BasicModelMergerPlugin")) { userSettings.setDefaultModelMerger(modelMergerPluginConfiguration); } } if (userSettings.getDefaultModelMerger() == null && !userSettings.getModelmergers().isEmpty()) { userSettings.setDefaultModelMerger(userSettings.getModelmergers().get(0)); } for (ModelComparePlugin modelComparePlugin : pluginManager.getAllModelComparePlugins(true)) { ModelComparePluginConfiguration modelComparePluginConfiguration = find(userSettings.getModelcompares(), modelComparePlugin.getClass().getName()); if (modelComparePluginConfiguration == null) { modelComparePluginConfiguration = session.create(ModelComparePluginConfiguration.class); userSettings.getModelcompares().add(modelComparePluginConfiguration); genericPluginConversion( session, modelComparePlugin, modelComparePluginConfiguration, getPluginDescriptor(session, modelComparePlugin.getClass().getName())); } if (userSettings.getDefaultModelCompare() == null && modelComparePlugin .getClass() .getName() .equals("org.bimserver.ifc.compare.GuidBasedModelComparePlugin")) { userSettings.setDefaultModelCompare(modelComparePluginConfiguration); } } if (userSettings.getDefaultModelCompare() == null && !userSettings.getModelcompares().isEmpty()) { userSettings.setDefaultModelCompare(userSettings.getModelcompares().get(0)); } for (SerializerPlugin serializerPlugin : pluginManager.getAllSerializerPlugins(true)) { SerializerPluginConfiguration serializerPluginConfiguration = find(userSettings.getSerializers(), serializerPlugin.getClass().getName()); if (serializerPluginConfiguration == null) { serializerPluginConfiguration = session.create(SerializerPluginConfiguration.class); userSettings.getSerializers().add(serializerPluginConfiguration); genericPluginConversion( session, serializerPlugin, serializerPluginConfiguration, getPluginDescriptor(session, serializerPlugin.getClass().getName())); serializerPluginConfiguration.setObjectIDM(userSettings.getDefaultObjectIDM()); serializerPluginConfiguration.setRenderEngine(userSettings.getDefaultRenderEngine()); } if (userSettings.getDefaultSerializer() == null && serializerPlugin .getClass() .getName() .equals("org.bimserver.ifc.step.serializer.Ifc2x3tc1StepSerializerPlugin")) { userSettings.setDefaultSerializer(serializerPluginConfiguration); } } for (MessagingSerializerPlugin serializerPlugin : pluginManager.getAllMessagingSerializerPlugins(true)) { MessagingSerializerPluginConfiguration serializerPluginConfiguration = find(userSettings.getMessagingSerializerPlugins(), serializerPlugin.getClass().getName()); if (serializerPluginConfiguration == null) { serializerPluginConfiguration = session.create(MessagingSerializerPluginConfiguration.class); userSettings.getMessagingSerializerPlugins().add(serializerPluginConfiguration); genericPluginConversion( session, serializerPlugin, serializerPluginConfiguration, getPluginDescriptor(session, serializerPlugin.getClass().getName())); } } if (userSettings.getDefaultSerializer() == null && !userSettings.getSerializers().isEmpty()) { userSettings.setDefaultSerializer(userSettings.getSerializers().get(0)); } for (ServicePlugin servicePlugin : pluginManager.getAllServicePlugins(true)) { InternalServicePluginConfiguration internalServicePluginConfiguration = find(userSettings.getServices(), servicePlugin.getClass().getName()); if (internalServicePluginConfiguration == null) { internalServicePluginConfiguration = session.create(InternalServicePluginConfiguration.class); userSettings.getServices().add(internalServicePluginConfiguration); genericPluginConversion( session, servicePlugin, internalServicePluginConfiguration, getPluginDescriptor(session, servicePlugin.getClass().getName())); } ObjectType settings = internalServicePluginConfiguration.getSettings(); SInternalServicePluginConfiguration sInternalService = getSConverter().convertToSObject(internalServicePluginConfiguration); servicePlugin.register( user.getOid(), sInternalService, new org.bimserver.plugins.PluginConfiguration(settings)); } for (DeserializerPlugin deserializerPlugin : pluginManager.getAllDeserializerPlugins(true)) { DeserializerPluginConfiguration deserializerPluginConfiguration = find(userSettings.getDeserializers(), deserializerPlugin.getClass().getName()); if (deserializerPluginConfiguration == null) { deserializerPluginConfiguration = session.create(DeserializerPluginConfiguration.class); userSettings.getDeserializers().add(deserializerPluginConfiguration); genericPluginConversion( session, deserializerPlugin, deserializerPluginConfiguration, getPluginDescriptor(session, deserializerPlugin.getClass().getName())); } } session.store(userSettings); }