Search in sources :

Example 1 with SerializerPluginConfiguration

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);
    }
}
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 2 with SerializerPluginConfiguration

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

Example 3 with SerializerPluginConfiguration

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;
}
Also used : MessagingSerializerPlugin(org.bimserver.plugins.serializers.MessagingSerializerPlugin) MessagingSerializer(org.bimserver.plugins.serializers.MessagingSerializer) ObjectType(org.bimserver.models.store.ObjectType) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) DatabaseSession(org.bimserver.database.DatabaseSession) MessagingSerializerPluginConfiguration(org.bimserver.models.store.MessagingSerializerPluginConfiguration) SerializerPluginConfiguration(org.bimserver.models.store.SerializerPluginConfiguration) PluginConfiguration(org.bimserver.plugins.PluginConfiguration) MessagingSerializerPluginConfiguration(org.bimserver.models.store.MessagingSerializerPluginConfiguration)

Example 4 with SerializerPluginConfiguration

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();
    }
}
Also used : LongCheckoutAction(org.bimserver.longaction.LongCheckoutAction) CannotBeScheduledException(org.bimserver.longaction.CannotBeScheduledException) LongDownloadOrCheckoutAction(org.bimserver.longaction.LongDownloadOrCheckoutAction) SUser(org.bimserver.interfaces.objects.SUser) User(org.bimserver.models.store.User) DatabaseSession(org.bimserver.database.DatabaseSession) SerializerPluginConfiguration(org.bimserver.models.store.SerializerPluginConfiguration) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) UserException(org.bimserver.shared.exceptions.UserException) IOException(java.io.IOException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) SerializerException(org.bimserver.plugins.serializers.SerializerException) BcfException(org.opensourcebim.bcf.BcfException) UserException(org.bimserver.shared.exceptions.UserException) CannotBeScheduledException(org.bimserver.longaction.CannotBeScheduledException) DeserializeException(org.bimserver.plugins.deserializers.DeserializeException) ServerException(org.bimserver.shared.exceptions.ServerException) MessagingException(javax.mail.MessagingException) AddressException(javax.mail.internet.AddressException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MalformedURLException(java.net.MalformedURLException) DownloadParameters(org.bimserver.longaction.DownloadParameters)

Example 5 with SerializerPluginConfiguration

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();
}
Also used : UserSettings(org.bimserver.models.store.UserSettings) SerializerPluginConfiguration(org.bimserver.models.store.SerializerPluginConfiguration)

Aggregations

SerializerPluginConfiguration (org.bimserver.models.store.SerializerPluginConfiguration)19 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)14 DatabaseSession (org.bimserver.database.DatabaseSession)13 UserException (org.bimserver.shared.exceptions.UserException)10 IOException (java.io.IOException)7 SSerializerPluginConfiguration (org.bimserver.interfaces.objects.SSerializerPluginConfiguration)7 UserSettings (org.bimserver.models.store.UserSettings)7 ServerException (org.bimserver.shared.exceptions.ServerException)7 User (org.bimserver.models.store.User)5 PluginConfiguration (org.bimserver.plugins.PluginConfiguration)5 SerializerException (org.bimserver.plugins.serializers.SerializerException)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 MalformedURLException (java.net.MalformedURLException)3 ArrayList (java.util.ArrayList)3 MessagingException (javax.mail.MessagingException)3 AddressException (javax.mail.internet.AddressException)3 CannotBeScheduledException (org.bimserver.longaction.CannotBeScheduledException)3 Revision (org.bimserver.models.store.Revision)3 DeserializeException (org.bimserver.plugins.deserializers.DeserializeException)3 QueryEnginePlugin (org.bimserver.plugins.queryengine.QueryEnginePlugin)3