Search in sources :

Example 1 with CheckinDatabaseAction

use of org.bimserver.database.actions.CheckinDatabaseAction in project BIMserver by opensourceBIM.

the class ServiceImpl method checkinInternal.

private SLongCheckinActionState checkinInternal(Long topicId, final Long poid, final String comment, Long deserializerOid, Long fileSize, String fileName, InputStream originalInputStream, Boolean merge, Boolean sync, final DatabaseSession readOnlySession, String username, String userUsername, Project project, Path file, long newServiceId) throws BimserverDatabaseException, IOException, DeserializeException, CannotBeScheduledException, ServiceException {
    DeserializerPluginConfiguration deserializerPluginConfiguration = readOnlySession.get(StorePackage.eINSTANCE.getDeserializerPluginConfiguration(), deserializerOid, OldQuery.getDefault());
    if (deserializerPluginConfiguration == null) {
        throw new UserException("Deserializer with oid " + deserializerOid + " not found");
    } else {
        PluginBundleVersion pluginBundleVersion = deserializerPluginConfiguration.getPluginDescriptor().getPluginBundleVersion();
        Plugin plugin = getBimServer().getPluginManager().getPlugin(deserializerPluginConfiguration.getPluginDescriptor().getPluginClassName(), true);
        if (plugin != null) {
            if (plugin instanceof DeserializerPlugin) {
                DeserializerPlugin deserializerPlugin = (DeserializerPlugin) plugin;
                Deserializer deserializer = deserializerPlugin.createDeserializer(getBimServer().getPluginSettingsCache().getPluginSettings(deserializerOid));
                OutputStream outputStream = Files.newOutputStream(file);
                InputStream inputStream = new MultiplexingInputStream(originalInputStream, outputStream);
                deserializer.init(getBimServer().getDatabase().getMetaDataManager().getPackageMetaData(project.getSchema()));
                IfcModelInterface model = null;
                try {
                    model = deserializer.read(inputStream, fileName, fileSize, null);
                } finally {
                    inputStream.close();
                }
                CheckinDatabaseAction checkinDatabaseAction = new CheckinDatabaseAction(getBimServer(), null, getInternalAccessMethod(), poid, getAuthorization(), model, comment, fileName, merge, newServiceId, topicId);
                LongCheckinAction longAction = new LongCheckinAction(topicId, getBimServer(), username, userUsername, getAuthorization(), checkinDatabaseAction);
                getBimServer().getLongActionManager().start(longAction);
                if (sync) {
                    longAction.waitForCompletion();
                    clearCheckinInProgress(poid);
                }
                ProgressTopic progressTopic = getBimServer().getNotificationsManager().getProgressTopic(topicId);
                return (SLongCheckinActionState) getBimServer().getSConverter().convertToSObject(progressTopic.getLastProgress());
            } else if (plugin instanceof StreamingDeserializerPlugin) {
                StreamingDeserializerPlugin streaminDeserializerPlugin = (StreamingDeserializerPlugin) plugin;
                StreamingDeserializer streamingDeserializer = streaminDeserializerPlugin.createDeserializer(getBimServer().getPluginSettingsCache().getPluginSettings(deserializerPluginConfiguration.getOid()));
                streamingDeserializer.init(getBimServer().getDatabase().getMetaDataManager().getPackageMetaData(project.getSchema()));
                RestartableInputStream restartableInputStream = new RestartableInputStream(originalInputStream, file);
                StreamingCheckinDatabaseAction checkinDatabaseAction = new StreamingCheckinDatabaseAction(getBimServer(), null, getInternalAccessMethod(), poid, getAuthorization(), comment, fileName, restartableInputStream, streamingDeserializer, fileSize, newServiceId, pluginBundleVersion, topicId);
                LongStreamingCheckinAction longAction = new LongStreamingCheckinAction(topicId, getBimServer(), username, userUsername, getAuthorization(), checkinDatabaseAction);
                getBimServer().getLongActionManager().start(longAction);
                ProgressTopic progressTopic = null;
                if (sync) {
                    longAction.waitForCompletion();
                    progressTopic = longAction.getProgressTopic();
                    clearCheckinInProgress(poid);
                    SLongCheckinActionState convertToSObject = (SLongCheckinActionState) getBimServer().getSConverter().convertToSObject(progressTopic.getLastProgress());
                    getBimServer().getLongActionManager().remove(progressTopic.getKey().getId());
                    return convertToSObject;
                } else {
                    return (SLongCheckinActionState) getBimServer().getSConverter().convertToSObject(longAction.getState());
                }
            } else {
                throw new UserException("No (enabled) (streaming) deserializer found with oid " + deserializerOid);
            }
        } else {
            throw new UserException("No (enabled) (streaming) deserializer found with oid " + deserializerOid);
        }
    }
}
Also used : MultiplexingInputStream(org.bimserver.utils.MultiplexingInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) MultiplexingInputStream(org.bimserver.utils.MultiplexingInputStream) InputStream(java.io.InputStream) IfcModelInterface(org.bimserver.emf.IfcModelInterface) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) StreamingDeserializerPlugin(org.bimserver.plugins.deserializers.StreamingDeserializerPlugin) DeserializerPlugin(org.bimserver.plugins.deserializers.DeserializerPlugin) SLongCheckinActionState(org.bimserver.interfaces.objects.SLongCheckinActionState) CheckinDatabaseAction(org.bimserver.database.actions.CheckinDatabaseAction) StreamingCheckinDatabaseAction(org.bimserver.database.actions.StreamingCheckinDatabaseAction) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) DeserializerPluginConfiguration(org.bimserver.models.store.DeserializerPluginConfiguration) StreamingDeserializer(org.bimserver.plugins.deserializers.StreamingDeserializer) ProgressTopic(org.bimserver.notifications.ProgressTopic) Deserializer(org.bimserver.plugins.deserializers.Deserializer) StreamingDeserializer(org.bimserver.plugins.deserializers.StreamingDeserializer) LongStreamingCheckinAction(org.bimserver.longaction.LongStreamingCheckinAction) StreamingDeserializerPlugin(org.bimserver.plugins.deserializers.StreamingDeserializerPlugin) LongCheckinAction(org.bimserver.longaction.LongCheckinAction) UserException(org.bimserver.shared.exceptions.UserException) PluginBundleVersion(org.bimserver.models.store.PluginBundleVersion) StreamingCheckinDatabaseAction(org.bimserver.database.actions.StreamingCheckinDatabaseAction) 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)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 CheckinDatabaseAction (org.bimserver.database.actions.CheckinDatabaseAction)1 StreamingCheckinDatabaseAction (org.bimserver.database.actions.StreamingCheckinDatabaseAction)1 IfcModelInterface (org.bimserver.emf.IfcModelInterface)1 SDeserializerPluginConfiguration (org.bimserver.interfaces.objects.SDeserializerPluginConfiguration)1 SLongCheckinActionState (org.bimserver.interfaces.objects.SLongCheckinActionState)1 LongCheckinAction (org.bimserver.longaction.LongCheckinAction)1 LongStreamingCheckinAction (org.bimserver.longaction.LongStreamingCheckinAction)1 DeserializerPluginConfiguration (org.bimserver.models.store.DeserializerPluginConfiguration)1 PluginBundleVersion (org.bimserver.models.store.PluginBundleVersion)1 ProgressTopic (org.bimserver.notifications.ProgressTopic)1 Plugin (org.bimserver.plugins.Plugin)1 Deserializer (org.bimserver.plugins.deserializers.Deserializer)1 DeserializerPlugin (org.bimserver.plugins.deserializers.DeserializerPlugin)1 StreamingDeserializer (org.bimserver.plugins.deserializers.StreamingDeserializer)1 StreamingDeserializerPlugin (org.bimserver.plugins.deserializers.StreamingDeserializerPlugin)1 QueryEnginePlugin (org.bimserver.plugins.queryengine.QueryEnginePlugin)1