use of org.bimserver.models.store.SerializerPluginConfiguration 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.SerializerPluginConfiguration 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();
}
}
}
use of org.bimserver.models.store.SerializerPluginConfiguration in project BIMserver by opensourceBIM.
the class SerializerFactory method createMessagingSerializer.
public MessagingSerializer createMessagingSerializer(String username, IfcModelInterface model, DownloadParameters downloadParameters) throws SerializerException {
DatabaseSession session = bimDatabase.createSession();
try {
MessagingSerializerPluginConfiguration serializerPluginConfiguration = session.get(StorePackage.eINSTANCE.getMessagingSerializerPluginConfiguration(), downloadParameters.getSerializerOid(), OldQuery.getDefault());
if (serializerPluginConfiguration != null) {
MessagingSerializerPlugin serializerPlugin = (MessagingSerializerPlugin) pluginManager.getPlugin(serializerPluginConfiguration.getPluginDescriptor().getPluginClassName(), true);
if (serializerPlugin != null) {
ObjectType settings = serializerPluginConfiguration.getSettings();
MessagingSerializer serializer = serializerPlugin.createSerializer(new PluginConfiguration(settings));
if (serializer != null) {
try {
serializer.init(model, null, pluginManager, model.getPackageMetaData(), true);
return serializer;
} catch (NullPointerException e) {
LOGGER.error("", e);
}
}
}
}
} catch (BimserverDatabaseException e) {
LOGGER.error("", e);
} finally {
session.close();
}
return null;
}
use of org.bimserver.models.store.SerializerPluginConfiguration in project BIMserver by opensourceBIM.
the class ServiceImpl method checkout.
@Override
public Long checkout(Long roid, Long serializerOid, Boolean sync) throws ServerException, UserException {
requireAuthenticationAndRunningServer();
getAuthorization().canDownload(roid);
DatabaseSession session = getBimServer().getDatabase().createSession();
User user = null;
try {
SerializerPluginConfiguration serializerPluginConfiguration = (SerializerPluginConfiguration) session.get(serializerOid, OldQuery.getDefault());
// org.bimserver.plugins.serializers.Serializer serializer = getBimServer().getEmfSerializerFactory().get(serializerOid).createSerializer(new org.bimserver.plugins.serializers.PluginConfiguration());
if (serializerPluginConfiguration == null) {
throw new UserException("No serializer with id " + serializerOid + " could be found");
}
if (!serializerPluginConfiguration.getPluginDescriptor().getPluginClassName().equals("org.bimserver.ifc.step.serializer.IfcStepSerializerPlugin") && !serializerPluginConfiguration.getPluginDescriptor().getPluginClassName().equals("org.bimserver.ifc.xml.serializer.IfcXmlSerializerPlugin")) {
throw new UserException("Only IFC or IFCXML allowed when checking out");
}
DownloadParameters downloadParameters = new DownloadParameters(getBimServer(), DownloadType.DOWNLOAD_PROJECTS);
downloadParameters.setRoid(roid);
downloadParameters.setSerializerOid(serializerOid);
user = (User) session.get(StorePackage.eINSTANCE.getUser(), getAuthorization().getUoid(), OldQuery.getDefault());
LongDownloadOrCheckoutAction longDownloadAction = new LongCheckoutAction(getBimServer(), user.getName(), user.getUsername(), downloadParameters, getAuthorization(), getInternalAccessMethod());
try {
getBimServer().getLongActionManager().start(longDownloadAction);
} catch (CannotBeScheduledException e) {
LOGGER.error("", e);
}
if (sync) {
longDownloadAction.waitForCompletion();
}
return longDownloadAction.getProgressTopic().getKey().getId();
} catch (Exception e) {
return handleException(e);
} finally {
session.close();
}
}
use of org.bimserver.models.store.SerializerPluginConfiguration in project BIMserver by opensourceBIM.
the class DeleteSerializerDatabaseAction method execute.
@Override
public Void execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
SerializerPluginConfiguration object = getDatabaseSession().get(geteClass(), getOid(), OldQuery.getDefault());
UserSettings settings = object.getUserSettings();
settings.getSerializers().remove(object);
getDatabaseSession().store(settings);
return super.execute();
}
Aggregations