Search in sources :

Example 1 with ProjectInfo

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

the class SerializerFactory method create.

public Serializer create(Project project, String username, IfcModelInterface model, RenderEnginePlugin renderEnginePlugin, DownloadParameters downloadParameters) throws SerializerException {
    DatabaseSession session = bimDatabase.createSession();
    try {
        SerializerPluginConfiguration serializerPluginConfiguration = session.get(StorePackage.eINSTANCE.getSerializerPluginConfiguration(), downloadParameters.getSerializerOid(), OldQuery.getDefault());
        if (serializerPluginConfiguration != null) {
            SerializerPlugin serializerPlugin = (SerializerPlugin) pluginManager.getPlugin(serializerPluginConfiguration.getPluginDescriptor().getPluginClassName(), true);
            if (serializerPlugin != null) {
                ObjectType settings = serializerPluginConfiguration.getSettings();
                Serializer serializer = serializerPlugin.createSerializer(new PluginConfiguration(settings));
                if (!serializerPlugin.getSupportedSchemas().contains(model.getPackageMetaData().getSchema())) {
                    SchemaConverterFactory converterFactory = null;
                    for (Schema schema : serializerPlugin.getSupportedSchemas()) {
                        converterFactory = bimServer.getSchemaConverterManager().getSchemaConverterFactory(model.getPackageMetaData().getSchema(), schema);
                        if (converterFactory != null) {
                            break;
                        }
                    }
                    if (converterFactory == null) {
                        throw new SerializerException("No usable converter found for schema " + model.getPackageMetaData().getSchema() + " for serializer " + serializerPlugin.getClass().getName());
                    }
                    try {
                        IfcModel targetModel = new BasicIfcModel(bimServer.getMetaDataManager().getPackageMetaData(converterFactory.getTargetSchema().getEPackageName()), new HashMap<Integer, Long>(), (int) model.size());
                        SchemaConverter converter = converterFactory.create(model, targetModel);
                        converter.convert();
                        model = targetModel;
                    } catch (SchemaConverterException e) {
                        throw new SerializerException(e);
                    } catch (IfcModelInterfaceException e) {
                        throw new SerializerException(e);
                    }
                }
                if (serializer != null) {
                    try {
                        ProjectInfo projectInfo = new ProjectInfo();
                        projectInfo.setName(project.getName());
                        projectInfo.setDescription(project.getDescription());
                        GeoTag geoTag = project.getGeoTag();
                        if (geoTag != null && geoTag.getEnabled()) {
                            projectInfo.setX(geoTag.getX());
                            projectInfo.setY(geoTag.getY());
                            projectInfo.setZ(geoTag.getZ());
                            projectInfo.setDirectionAngle(geoTag.getDirectionAngle());
                        } else {
                            projectInfo.setX(4.8900);
                            projectInfo.setY(52.3700);
                        }
                        projectInfo.setAuthorName(username);
                        serializer.init(model, projectInfo, true);
                        return serializer;
                    } catch (NullPointerException e) {
                        LOGGER.error("", e);
                    }
                }
            }
        }
    } catch (BimserverDatabaseException e) {
        LOGGER.error("", e);
    } finally {
        session.close();
    }
    return null;
}
Also used : GeoTag(org.bimserver.models.store.GeoTag) DatabaseSession(org.bimserver.database.DatabaseSession) Schema(org.bimserver.emf.Schema) SerializerPlugin(org.bimserver.plugins.serializers.SerializerPlugin) MessagingSerializerPlugin(org.bimserver.plugins.serializers.MessagingSerializerPlugin) SerializerException(org.bimserver.plugins.serializers.SerializerException) BasicIfcModel(org.bimserver.ifc.BasicIfcModel) ObjectType(org.bimserver.models.store.ObjectType) BasicIfcModel(org.bimserver.ifc.BasicIfcModel) IfcModel(org.bimserver.ifc.IfcModel) IfcModelInterfaceException(org.bimserver.emf.IfcModelInterfaceException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) SchemaConverterException(org.bimserver.schemaconverter.SchemaConverterException) ProjectInfo(org.bimserver.plugins.serializers.ProjectInfo) SerializerPluginConfiguration(org.bimserver.models.store.SerializerPluginConfiguration) MessagingSerializerPluginConfiguration(org.bimserver.models.store.MessagingSerializerPluginConfiguration) SerializerPluginConfiguration(org.bimserver.models.store.SerializerPluginConfiguration) PluginConfiguration(org.bimserver.plugins.PluginConfiguration) MessagingSerializerPluginConfiguration(org.bimserver.models.store.MessagingSerializerPluginConfiguration) SchemaConverter(org.bimserver.schemaconverter.SchemaConverter) MessagingSerializer(org.bimserver.plugins.serializers.MessagingSerializer) Serializer(org.bimserver.plugins.serializers.Serializer) SchemaConverterFactory(org.bimserver.schemaconverter.SchemaConverterFactory)

Aggregations

BimserverDatabaseException (org.bimserver.BimserverDatabaseException)1 DatabaseSession (org.bimserver.database.DatabaseSession)1 IfcModelInterfaceException (org.bimserver.emf.IfcModelInterfaceException)1 Schema (org.bimserver.emf.Schema)1 BasicIfcModel (org.bimserver.ifc.BasicIfcModel)1 IfcModel (org.bimserver.ifc.IfcModel)1 GeoTag (org.bimserver.models.store.GeoTag)1 MessagingSerializerPluginConfiguration (org.bimserver.models.store.MessagingSerializerPluginConfiguration)1 ObjectType (org.bimserver.models.store.ObjectType)1 SerializerPluginConfiguration (org.bimserver.models.store.SerializerPluginConfiguration)1 PluginConfiguration (org.bimserver.plugins.PluginConfiguration)1 MessagingSerializer (org.bimserver.plugins.serializers.MessagingSerializer)1 MessagingSerializerPlugin (org.bimserver.plugins.serializers.MessagingSerializerPlugin)1 ProjectInfo (org.bimserver.plugins.serializers.ProjectInfo)1 Serializer (org.bimserver.plugins.serializers.Serializer)1 SerializerException (org.bimserver.plugins.serializers.SerializerException)1 SerializerPlugin (org.bimserver.plugins.serializers.SerializerPlugin)1 SchemaConverter (org.bimserver.schemaconverter.SchemaConverter)1 SchemaConverterException (org.bimserver.schemaconverter.SchemaConverterException)1 SchemaConverterFactory (org.bimserver.schemaconverter.SchemaConverterFactory)1