use of org.bimserver.models.store.PluginDescriptor in project BIMserver by opensourceBIM.
the class BimServer method start.
public void start() throws DatabaseInitException, BimserverDatabaseException, PluginException, DatabaseRestartRequiredException, ServerException {
try {
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");
}
if (config.getHomeDir() != null) {
LOGGER.info("Using \"" + config.getHomeDir().toString() + "\" as homedir");
} else {
LOGGER.info("Not using a homedir");
}
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(OperationType.POSSIBLY_WRITE);
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(OperationType.POSSIBLY_WRITE)) {
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(OperationType.POSSIBLY_WRITE)) {
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(OperationType.POSSIBLY_WRITE)) {
ServerSettings serverSettings = getServerSettingsCache().getServerSettings();
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;
ObjectType settings = null;
if (pluginsFound.size() > 0) {
pluginDescriptor = pluginsFound.values().iterator().next();
settings = pluginDescriptor.getSettings();
} else {
pluginDescriptor = session.create(PluginDescriptor.class);
settings = convertSettings(session, pluginContext.getPlugin().getSystemSettingsDefinition());
pluginDescriptor.setSettings(settings);
}
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()));
try {
pluginContext.initialize(new org.bimserver.plugins.PluginConfiguration(settings));
} catch (PluginException e) {
LOGGER.error("", e);
}
if (pluginDescriptor.getPluginClassName().contentEquals("org.ifcopenshell.IfcOpenShellEnginePlugin")) {
if (serverSettings.getDefaultRenderEnginePlugin() == null) {
serverSettings.setDefaultRenderEnginePlugin(pluginDescriptor);
session.store(serverSettings);
}
}
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) {
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(OperationType.POSSIBLY_WRITE);
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(OperationType.POSSIBLY_WRITE)) {
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(true);
pluginManager.initAllLoadedPlugins();
} catch (PluginException e) {
LOGGER.error("", e);
}
serverStartTime = new GregorianCalendar();
longActionManager = new LongActionManager(this);
Set<EPackage> packages = new LinkedHashSet<>();
packages.add(Ifc2x3tc1Package.eINSTANCE);
packages.add(Ifc4Package.eINSTANCE);
templateEngine = new TemplateEngine();
ResourceFetcher resourceFetcher = config.getResourceFetcher();
if (resourceFetcher.isDirectory("emailtemplates")) {
templateEngine.init(resourceFetcher.getURL("emailtemplates"));
} else {
LOGGER.info("No email templates found");
}
Path databaseDir = config.getHomeDir().resolve("database");
BerkeleyKeyValueStore keyValueStore = new BerkeleyKeyValueStore(databaseDir, config.getBdbEnvironmentProperties());
geometryAccellerator = new GeometryAccellerator(this);
schemaConverterManager.registerConverter(new Ifc2x3tc1ToIfc4SchemaConverterFactory());
schemaConverterManager.registerConverter(new Ifc4ToIfc2x3tc1SchemaConverterFactory());
authCache = new AuthCache(this);
pluginSettingsCache = new PluginSettingsCache(this);
metricsRegistry = new MetricsRegistry();
Path mavenPath = config.getHomeDir().resolve("maven");
if (!Files.exists(mavenPath)) {
Files.createDirectories(mavenPath);
}
OldQuery.setPackageMetaDataForDefaultQuery(metaDataManager.getPackageMetaData("store"));
bimDatabase = new Database(this, packages, keyValueStore, metaDataManager);
try {
bimDatabase.init();
} catch (DatabaseRestartRequiredException e) {
bimDatabase.close();
keyValueStore = new BerkeleyKeyValueStore(databaseDir, config.getBdbEnvironmentProperties());
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(OperationType.POSSIBLY_WRITE)) {
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();
serverInfoManager.init(this);
webModuleManager = new WebModuleManager(this);
jsonHandler = new JsonHandler(this);
serializerFactory = new SerializerFactory();
serverSettingsCache = new ServerSettingsCache(bimDatabase);
for (String schema : new String[] { "ifc2x3tc1", "ifc4" }) {
for (String type : new String[] { "geometry", "stdlib" }) {
try {
PackageMetaData packageMetaData = getMetaDataManager().getPackageMetaData(schema);
JsonQueryObjectModelConverter jsonQueryObjectModelConverter = new JsonQueryObjectModelConverter(packageMetaData);
String queryNameSpace = schema + "-" + type;
if (type.contentEquals("stdlib")) {
Include objectPlacement = jsonQueryObjectModelConverter.getDefineFromFile(queryNameSpace + ":ObjectPlacement", true);
// The sole reason is to make sure this is done once, and then cached
objectPlacement.makeDirectRecursive(new HashSet<>());
}
} catch (QueryException e) {
LOGGER.error(schema + " " + type, e);
}
}
}
serverInfoManager.update();
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());
}
}
use of org.bimserver.models.store.PluginDescriptor 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.PluginDescriptor 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 && pluginInterfaceName.contentEquals("RenderEngine")) {
PluginDescriptor defaultRenderEnginePlugin = getServerSettingsCache().getServerSettings().getDefaultRenderEnginePlugin();
if (defaultRenderEnginePlugin != null && pluginDescriptor.getOid() == defaultRenderEnginePlugin.getOid()) {
LOGGER.info("Setting default render engine for user " + user.getUsername() + " to " + defaultRenderEnginePlugin.getName());
userSettings.eSet(defaultReference, pluginConfiguration);
}
}
}
session.store(userSettings);
}
}
use of org.bimserver.models.store.PluginDescriptor in project BIMserver by opensourceBIM.
the class BimServer method updatePlugins.
private void updatePlugins(DatabaseSession session) throws BimserverDatabaseException {
Map<PluginContext, Plugin> allPlugins = pluginManager.getAllPlugins(false);
for (PluginContext pluginContext : allPlugins.keySet()) {
Plugin plugin = pluginContext.getPlugin();
Condition pluginCondition = new AttributeCondition(StorePackage.eINSTANCE.getPluginDescriptor_Identifier(), new StringLiteral(pluginContext.getIdentifier()));
Map<Long, PluginDescriptor> results = session.query(pluginCondition, PluginDescriptor.class, OldQuery.getDefault());
if (results.size() == 0) {
PluginDescriptor pluginDescriptor = session.create(PluginDescriptor.class);
pluginDescriptor.setIdentifier(pluginContext.getIdentifier());
pluginDescriptor.setPluginClassName(plugin.getClass().getName());
pluginDescriptor.setName(plugin.getClass().getSimpleName());
pluginDescriptor.setDescription(pluginContext.getDescription());
pluginDescriptor.setLocation(pluginContext.getLocation().toString());
pluginDescriptor.setPluginInterfaceClassName(getPluginInterface(plugin.getClass()).getName());
pluginDescriptor.setEnabled(true);
} else if (results.size() == 1) {
PluginDescriptor pluginDescriptor = results.values().iterator().next();
pluginDescriptor.setIdentifier(pluginContext.getIdentifier());
pluginDescriptor.setPluginClassName(plugin.getClass().getName());
pluginDescriptor.setName(plugin.getClass().getSimpleName());
pluginDescriptor.setDescription(pluginContext.getDescription());
pluginDescriptor.setLocation(pluginContext.getLocation().toString());
pluginDescriptor.setPluginInterfaceClassName(getPluginInterface(plugin.getClass()).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());
}
}
}
use of org.bimserver.models.store.PluginDescriptor in project BIMserver by opensourceBIM.
the class NewServicesImpl method listAvailableOutputFormats.
@Override
public List<SFormatSerializerMap> listAvailableOutputFormats(Long poid) throws ServerException, UserException {
Map<String, SFormatSerializerMap> outputs = new HashMap<>();
try (DatabaseSession session = getBimServer().getDatabase().createSession(OperationType.READ_ONLY)) {
Project project = session.get(poid, OldQuery.getDefault());
try {
List<SSerializerPluginConfiguration> allSerializersForPoids = getServiceMap().get(PluginInterface.class).getAllSerializersForPoids(true, Collections.singleton(poid));
for (SSerializerPluginConfiguration pluginConfiguration : allSerializersForPoids) {
PluginDescriptor pluginDescriptor = session.get(pluginConfiguration.getPluginDescriptorId(), OldQuery.getDefault());
Plugin plugin = getBimServer().getPluginManager().getPlugin(pluginDescriptor.getIdentifier(), true);
String outputFormat = null;
// TODO For now only streaming serializers
if (plugin instanceof StreamingSerializerPlugin) {
outputFormat = ((StreamingSerializerPlugin) plugin).getOutputFormat(Schema.valueOf(project.getSchema().toUpperCase()));
}
if (outputFormat != null) {
SFormatSerializerMap map = outputs.get(outputFormat);
if (map == null) {
map = new SFormatSerializerMap();
map.setFormat(outputFormat);
outputs.put(outputFormat, map);
}
map.getSerializers().add(pluginConfiguration);
}
}
} catch (ServerException e) {
e.printStackTrace();
} catch (UserException e) {
e.printStackTrace();
}
return new ArrayList<>(outputs.values());
} catch (BimserverDatabaseException e) {
return handleException(e);
}
}
Aggregations