Search in sources :

Example 1 with MessagingSerializerPlugin

use of org.bimserver.plugins.serializers.MessagingSerializerPlugin 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 2 with MessagingSerializerPlugin

use of org.bimserver.plugins.serializers.MessagingSerializerPlugin in project BIMserver by opensourceBIM.

the class ServiceImpl method download.

@Override
public Long download(Set<Long> roids, String jsonQuery, Long serializerOid, Boolean sync) throws ServerException, UserException {
    try {
        User user = null;
        DatabaseSession session = getBimServer().getDatabase().createSession();
        Plugin plugin = null;
        try {
            SerializerPluginConfiguration serializerPluginConfiguration = session.get(StorePackage.eINSTANCE.getSerializerPluginConfiguration(), serializerOid, OldQuery.getDefault());
            plugin = getBimServer().getPluginManager().getPlugin(serializerPluginConfiguration.getPluginDescriptor().getPluginClassName(), true);
            user = (User) session.get(StorePackage.eINSTANCE.getUser(), getAuthorization().getUoid(), OldQuery.getDefault());
        } catch (BimserverDatabaseException e) {
            throw new UserException(e);
        } finally {
            session.close();
        }
        if (plugin instanceof StreamingSerializerPlugin || plugin instanceof MessagingStreamingSerializerPlugin) {
            LongStreamingDownloadAction longDownloadAction = new LongStreamingDownloadAction(getBimServer(), user == null ? "Unknown" : user.getName(), user == null ? "Unknown" : user.getUsername(), getAuthorization(), serializerOid, jsonQuery, roids);
            try {
                getBimServer().getLongActionManager().start(longDownloadAction);
            } catch (Exception e) {
                LOGGER.error("", e);
            }
            if (sync) {
                longDownloadAction.waitForCompletion();
            }
            return longDownloadAction.getProgressTopic().getKey().getId();
        } else if (plugin instanceof MessagingSerializerPlugin) {
            requireAuthenticationAndRunningServer();
            DownloadParameters downloadParameters = new DownloadParameters(getBimServer(), DownloadType.DOWNLOAD_BY_NEW_JSON_QUERY);
            downloadParameters.setRoids(roids);
            downloadParameters.setJsonQuery(jsonQuery);
            downloadParameters.setSerializerOid(serializerOid);
            return download(downloadParameters, sync);
        } else if (plugin instanceof SerializerPlugin) {
            requireAuthenticationAndRunningServer();
            DownloadParameters downloadParameters = new DownloadParameters(getBimServer(), DownloadType.DOWNLOAD_BY_NEW_JSON_QUERY);
            downloadParameters.setRoids(roids);
            downloadParameters.setJsonQuery(jsonQuery);
            downloadParameters.setSerializerOid(serializerOid);
            return download(downloadParameters, sync);
        } else {
            throw new UserException("Unimplemented");
        }
    } catch (Exception e) {
        return handleException(e);
    }
}
Also used : MessagingSerializerPlugin(org.bimserver.plugins.serializers.MessagingSerializerPlugin) SUser(org.bimserver.interfaces.objects.SUser) User(org.bimserver.models.store.User) DatabaseSession(org.bimserver.database.DatabaseSession) MessagingStreamingSerializerPlugin(org.bimserver.plugins.serializers.MessagingStreamingSerializerPlugin) LongStreamingDownloadAction(org.bimserver.longaction.LongStreamingDownloadAction) StreamingSerializerPlugin(org.bimserver.plugins.serializers.StreamingSerializerPlugin) MessagingSerializerPlugin(org.bimserver.plugins.serializers.MessagingSerializerPlugin) MessagingStreamingSerializerPlugin(org.bimserver.plugins.serializers.MessagingStreamingSerializerPlugin) SerializerPlugin(org.bimserver.plugins.serializers.SerializerPlugin) StreamingSerializerPlugin(org.bimserver.plugins.serializers.StreamingSerializerPlugin) MessagingStreamingSerializerPlugin(org.bimserver.plugins.serializers.MessagingStreamingSerializerPlugin) 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) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) SerializerPluginConfiguration(org.bimserver.models.store.SerializerPluginConfiguration) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) UserException(org.bimserver.shared.exceptions.UserException) StreamingSerializerPlugin(org.bimserver.plugins.serializers.StreamingSerializerPlugin) QueryEnginePlugin(org.bimserver.plugins.queryengine.QueryEnginePlugin) MessagingSerializerPlugin(org.bimserver.plugins.serializers.MessagingSerializerPlugin) StreamingDeserializerPlugin(org.bimserver.plugins.deserializers.StreamingDeserializerPlugin) DeserializerPlugin(org.bimserver.plugins.deserializers.DeserializerPlugin) MessagingStreamingSerializerPlugin(org.bimserver.plugins.serializers.MessagingStreamingSerializerPlugin) SerializerPlugin(org.bimserver.plugins.serializers.SerializerPlugin) Plugin(org.bimserver.plugins.Plugin) DownloadParameters(org.bimserver.longaction.DownloadParameters)

Aggregations

BimserverDatabaseException (org.bimserver.BimserverDatabaseException)2 DatabaseSession (org.bimserver.database.DatabaseSession)2 SerializerPluginConfiguration (org.bimserver.models.store.SerializerPluginConfiguration)2 MessagingSerializerPlugin (org.bimserver.plugins.serializers.MessagingSerializerPlugin)2 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1 MessagingException (javax.mail.MessagingException)1 AddressException (javax.mail.internet.AddressException)1 SSerializerPluginConfiguration (org.bimserver.interfaces.objects.SSerializerPluginConfiguration)1 SUser (org.bimserver.interfaces.objects.SUser)1 CannotBeScheduledException (org.bimserver.longaction.CannotBeScheduledException)1 DownloadParameters (org.bimserver.longaction.DownloadParameters)1 LongStreamingDownloadAction (org.bimserver.longaction.LongStreamingDownloadAction)1 MessagingSerializerPluginConfiguration (org.bimserver.models.store.MessagingSerializerPluginConfiguration)1 ObjectType (org.bimserver.models.store.ObjectType)1 User (org.bimserver.models.store.User)1 Plugin (org.bimserver.plugins.Plugin)1 PluginConfiguration (org.bimserver.plugins.PluginConfiguration)1 DeserializeException (org.bimserver.plugins.deserializers.DeserializeException)1