Search in sources :

Example 11 with SerializerPluginConfiguration

use of org.bimserver.models.store.SerializerPluginConfiguration in project BIMserver by opensourceBIM.

the class PluginServiceImpl method updateSerializer.

@Override
public void updateSerializer(SSerializerPluginConfiguration serializer) throws ServerException, UserException {
    requireRealUserAuthentication();
    DatabaseSession session = getBimServer().getDatabase().createSession();
    try {
        SerializerPluginConfiguration convert = session.get(serializer.getOid(), OldQuery.getDefault());
        getBimServer().getSConverter().convertFromSObject(serializer, convert, session);
        session.executeAndCommitAction(new UpdateSerializerDatabaseAction(session, getInternalAccessMethod(), convert));
    } catch (Exception e) {
        handleException(e);
    } finally {
        session.close();
    }
}
Also used : UpdateSerializerDatabaseAction(org.bimserver.database.actions.UpdateSerializerDatabaseAction) DatabaseSession(org.bimserver.database.DatabaseSession) SerializerPluginConfiguration(org.bimserver.models.store.SerializerPluginConfiguration) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) IOException(java.io.IOException) ServerException(org.bimserver.shared.exceptions.ServerException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) UserException(org.bimserver.shared.exceptions.UserException)

Example 12 with SerializerPluginConfiguration

use of org.bimserver.models.store.SerializerPluginConfiguration in project BIMserver by opensourceBIM.

the class PluginServiceImpl method getAllSerializersForPoids.

@Override
public List<SSerializerPluginConfiguration> getAllSerializersForPoids(Boolean onlyEnabled, Set<Long> poids) throws ServerException, UserException {
    requireRealUserAuthentication();
    DatabaseSession session = getBimServer().getDatabase().createSession();
    try {
        Set<Schema> uniqueSchemas = new HashSet<>();
        for (Long poid : poids) {
            Project project = session.get(poid, OldQuery.getDefault());
            uniqueSchemas.add(Schema.valueOf(project.getSchema().toUpperCase()));
        }
        Set<Schema> schemaOr = new HashSet<>();
        if (uniqueSchemas.size() == 0) {
        // Weird, no schemas
        } else if (uniqueSchemas.size() == 1) {
            // Easy, just add it, and see if there are converter targets and add those too
            Schema schema = uniqueSchemas.iterator().next();
            schemaOr.add(schema);
            // TODO make recursive
            for (Schema target : getBimServer().getSchemaConverterManager().getSchemaTargets(schema)) {
                schemaOr.add(target);
            }
        } else if (uniqueSchemas.size() == 2) {
            // This is harder, if we have 2 schema, we must figure out a way to convert to 1 schema, and then filter the allowed source schemas
            Iterator<Schema> iterator = uniqueSchemas.iterator();
            Schema schema1 = iterator.next();
            Schema schema2 = iterator.next();
            SchemaConverterFactory converter1 = getBimServer().getSchemaConverterManager().getSchemaConverterFactory(schema1, schema2);
            SchemaConverterFactory converter2 = getBimServer().getSchemaConverterManager().getSchemaConverterFactory(schema2, schema1);
            if (converter1 != null) {
                schemaOr.add(schema1);
            }
            if (converter2 != null) {
                schemaOr.add(schema2);
            }
        } else {
            throw new ServerException("Unimplemented, no support for > 2 schemas");
        }
        UserSettings userSettings = getUserSettings(session);
        List<SSerializerPluginConfiguration> sSerializers = new ArrayList<SSerializerPluginConfiguration>();
        for (SerializerPluginConfiguration serializerPluginConfiguration : userSettings.getSerializers()) {
            Plugin plugin = getBimServer().getPluginManager().getPlugin(serializerPluginConfiguration.getPluginDescriptor().getPluginClassName(), true);
            if (plugin instanceof SerializerPlugin) {
                SerializerPlugin serializerPlugin = getBimServer().getPluginManager().getSerializerPlugin(serializerPluginConfiguration.getPluginDescriptor().getPluginClassName(), true);
                for (Schema schema : serializerPlugin.getSupportedSchemas()) {
                    if (schemaOr.contains(schema)) {
                        if (!onlyEnabled || (serializerPluginConfiguration.getEnabled() && serializerPluginConfiguration.getPluginDescriptor().getEnabled())) {
                            sSerializers.add(getBimServer().getSConverter().convertToSObject(serializerPluginConfiguration));
                            break;
                        }
                    }
                }
            } else if (plugin instanceof StreamingSerializerPlugin) {
                StreamingSerializerPlugin streamingSerializerPlugin = (StreamingSerializerPlugin) plugin;
                for (Schema schema : streamingSerializerPlugin.getSupportedSchemas()) {
                    if (schemaOr.contains(schema)) {
                        if (!onlyEnabled || (serializerPluginConfiguration.getEnabled() && serializerPluginConfiguration.getPluginDescriptor().getEnabled())) {
                            sSerializers.add(getBimServer().getSConverter().convertToSObject(serializerPluginConfiguration));
                            break;
                        }
                    }
                }
            }
        }
        Collections.sort(sSerializers, new SPluginConfigurationComparator());
        return sSerializers;
    } catch (Exception e) {
        handleException(e);
    } finally {
        session.close();
    }
    return null;
}
Also used : ServerException(org.bimserver.shared.exceptions.ServerException) DatabaseSession(org.bimserver.database.DatabaseSession) UserSettings(org.bimserver.models.store.UserSettings) Schema(org.bimserver.emf.Schema) ArrayList(java.util.ArrayList) StreamingSerializerPlugin(org.bimserver.plugins.serializers.StreamingSerializerPlugin) SerializerPlugin(org.bimserver.plugins.serializers.SerializerPlugin) StreamingSerializerPlugin(org.bimserver.plugins.serializers.StreamingSerializerPlugin) IOException(java.io.IOException) ServerException(org.bimserver.shared.exceptions.ServerException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) UserException(org.bimserver.shared.exceptions.UserException) SPluginConfigurationComparator(org.bimserver.webservices.SPluginConfigurationComparator) Project(org.bimserver.models.store.Project) SerializerPluginConfiguration(org.bimserver.models.store.SerializerPluginConfiguration) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) HashSet(java.util.HashSet) SchemaConverterFactory(org.bimserver.schemaconverter.SchemaConverterFactory) ModelCheckerPlugin(org.bimserver.plugins.modelchecker.ModelCheckerPlugin) StreamingDeserializerPlugin(org.bimserver.plugins.deserializers.StreamingDeserializerPlugin) ModelComparePlugin(org.bimserver.plugins.modelcompare.ModelComparePlugin) ObjectIDMPlugin(org.bimserver.plugins.objectidms.ObjectIDMPlugin) DeserializerPlugin(org.bimserver.plugins.deserializers.DeserializerPlugin) ServicePlugin(org.bimserver.plugins.services.ServicePlugin) WebModulePlugin(org.bimserver.plugins.web.WebModulePlugin) RenderEnginePlugin(org.bimserver.plugins.renderengine.RenderEnginePlugin) StreamingSerializerPlugin(org.bimserver.plugins.serializers.StreamingSerializerPlugin) SerializerPlugin(org.bimserver.plugins.serializers.SerializerPlugin) QueryEnginePlugin(org.bimserver.plugins.queryengine.QueryEnginePlugin) ModelMergerPlugin(org.bimserver.plugins.modelmerger.ModelMergerPlugin) Plugin(org.bimserver.plugins.Plugin)

Example 13 with SerializerPluginConfiguration

use of org.bimserver.models.store.SerializerPluginConfiguration in project BIMserver by opensourceBIM.

the class DownloadQueryDatabaseAction method execute.

@Override
public IfcModelInterface execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException, ServerException {
    DatabaseSession session = getBimServer().getDatabase().createSession();
    try {
        SerializerPluginConfiguration serializerPluginConfiguration = getDatabaseSession().get(StorePackage.eINSTANCE.getSerializerPluginConfiguration(), serializerOid, OldQuery.getDefault());
        BimDatabaseAction<IfcModelInterface> action = new DownloadDatabaseAction(getBimServer(), session, AccessMethod.INTERNAL, roid, -1, serializerPluginConfiguration.getOid(), getAuthorization(), null);
        IfcModelInterface ifcModel = session.executeAndCommitAction(action);
        QueryEnginePluginConfiguration queryEngineObject = session.get(StorePackage.eINSTANCE.getQueryEnginePluginConfiguration(), qeid, OldQuery.getDefault());
        Revision revision = session.get(roid, OldQuery.getDefault());
        PackageMetaData packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData(revision.getProject().getSchema());
        if (objectIDM == null) {
            objectIDM = new HideAllInversesObjectIDM(CollectionUtils.singleSet(Ifc2x3tc1Package.eINSTANCE), packageMetaData);
        }
        if (queryEngineObject != null) {
            QueryEnginePlugin queryEnginePlugin = getBimServer().getPluginManager().getQueryEngine(queryEngineObject.getPluginDescriptor().getPluginClassName(), true);
            if (queryEnginePlugin != null) {
                QueryEngine queryEngine = queryEnginePlugin.getQueryEngine(new PluginConfiguration(queryEngineObject.getSettings()));
                final IfcModelInterface result = new ServerIfcModel(packageMetaData, null, getDatabaseSession());
                ModelHelper modelHelper = new ModelHelper(getBimServer().getMetaDataManager(), objectIDM, result);
                modelHelper.setOidProvider(new OidProvider() {

                    private long oid = 1000000;

                    @Override
                    public long newOid(EClass eClass) {
                        return oid++;
                    }
                });
                IfcModelInterface finalResult = queryEngine.query(ifcModel, code, new Reporter() {

                    @Override
                    public void error(Throwable error) {
                    }

                    @Override
                    public void warning(String warning) {
                    }

                    @Override
                    public void info(String info) {
                    }
                }, modelHelper);
                return finalResult;
            } else {
                throw new UserException("No Query Engine found " + queryEngineObject.getPluginDescriptor().getPluginClassName());
            }
        } else {
            throw new UserException("No configured query engine found with qeid " + qeid);
        }
    } catch (BimserverDatabaseException e) {
        throw new UserException(e);
    } catch (QueryEngineException e) {
        throw new UserException(e);
    } catch (PluginException e) {
        throw new UserException(e);
    } finally {
        session.close();
    }
}
Also used : ServerIfcModel(org.bimserver.ServerIfcModel) DatabaseSession(org.bimserver.database.DatabaseSession) IfcModelInterface(org.bimserver.emf.IfcModelInterface) QueryEngine(org.bimserver.plugins.queryengine.QueryEngine) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) EClass(org.eclipse.emf.ecore.EClass) OidProvider(org.bimserver.emf.OidProvider) QueryEngineException(org.bimserver.plugins.queryengine.QueryEngineException) SerializerPluginConfiguration(org.bimserver.models.store.SerializerPluginConfiguration) QueryEnginePluginConfiguration(org.bimserver.models.store.QueryEnginePluginConfiguration) PluginConfiguration(org.bimserver.plugins.PluginConfiguration) UserException(org.bimserver.shared.exceptions.UserException) QueryEnginePluginConfiguration(org.bimserver.models.store.QueryEnginePluginConfiguration) ModelHelper(org.bimserver.plugins.ModelHelper) PackageMetaData(org.bimserver.emf.PackageMetaData) Reporter(org.bimserver.plugins.Reporter) PluginException(org.bimserver.shared.exceptions.PluginException) QueryEnginePlugin(org.bimserver.plugins.queryengine.QueryEnginePlugin) Revision(org.bimserver.models.store.Revision) HideAllInversesObjectIDM(org.bimserver.plugins.objectidms.HideAllInversesObjectIDM) SerializerPluginConfiguration(org.bimserver.models.store.SerializerPluginConfiguration)

Example 14 with SerializerPluginConfiguration

use of org.bimserver.models.store.SerializerPluginConfiguration in project BIMserver by opensourceBIM.

the class GetAllSerializersDatabaseAction method execute.

@Override
public List<SerializerPluginConfiguration> execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    Condition condition = new IsOfTypeCondition(StorePackage.eINSTANCE.getSerializerPluginConfiguration());
    Map<Long, SerializerPluginConfiguration> result = getDatabaseSession().query(condition, SerializerPluginConfiguration.class, OldQuery.getDefault());
    List<SerializerPluginConfiguration> mapToList = CollectionUtils.mapToList(result);
    if (onlyEnabled) {
        Iterator<SerializerPluginConfiguration> iterator = mapToList.iterator();
        while (iterator.hasNext()) {
            SerializerPluginConfiguration serializer = iterator.next();
            if (!bimServer.getPluginManager().isEnabled(serializer.getPluginDescriptor().getPluginClassName()) || !serializer.getEnabled()) {
                iterator.remove();
            }
        }
    }
    return mapToList;
}
Also used : IsOfTypeCondition(org.bimserver.database.query.conditions.IsOfTypeCondition) Condition(org.bimserver.database.query.conditions.Condition) IsOfTypeCondition(org.bimserver.database.query.conditions.IsOfTypeCondition) SerializerPluginConfiguration(org.bimserver.models.store.SerializerPluginConfiguration)

Example 15 with SerializerPluginConfiguration

use of org.bimserver.models.store.SerializerPluginConfiguration 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

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