Search in sources :

Example 6 with AttributeCondition

use of org.bimserver.database.query.conditions.AttributeCondition in project BIMserver by opensourceBIM.

the class BimServer method initDatabaseDependantItems.

private void initDatabaseDependantItems() throws BimserverDatabaseException {
    LOGGER.info("Initializing database dependant logic...");
    long start = System.nanoTime();
    notificationsManager.init();
    getSerializerFactory().init(pluginManager, bimDatabase, this);
    try {
        DatabaseSession session = bimDatabase.createSession(OperationType.POSSIBLY_WRITE);
        try {
            updatePlugins(session);
            session.commit();
        } catch (ServiceException e) {
            LOGGER.error("", e);
        } finally {
            session.close();
        }
        int renderEngineProcesses = getServerSettingsCache().getServerSettings().getRenderEngineProcesses();
        RenderEnginePoolFactory renderEnginePoolFactory = new CommonsPoolingRenderEnginePoolFactory(renderEngineProcesses);
        renderEnginePools = new RenderEnginePools(this, renderEnginePoolFactory);
        session = bimDatabase.createSession(OperationType.POSSIBLY_WRITE);
        // createDatabaseObjects(session);
        ServerSettings serverSettings = serverSettingsCache.getServerSettings();
        for (Entry<PluginContext, WebModulePlugin> entry : pluginManager.getAllWebPlugins(true).entrySet()) {
            WebModulePluginConfiguration webPluginConfiguration = find(serverSettings.getWebModules(), entry.getKey().getIdentifier());
            if (webPluginConfiguration == null) {
                webPluginConfiguration = session.create(WebModulePluginConfiguration.class);
                serverSettings.getWebModules().add(webPluginConfiguration);
                PluginDescriptor pluginDescriptor = getPluginDescriptor(session, entry.getKey().getIdentifier());
                if (pluginDescriptor == null) {
                    throw new BimserverDatabaseException("No plugin descriptor found: " + entry.getKey().getIdentifier());
                }
                genericPluginConversion(entry.getKey(), session, webPluginConfiguration, pluginDescriptor);
            } else {
                if (webPluginConfiguration == serverSettings.getWebModule()) {
                    setDefaultWebModule(entry.getValue());
                }
            }
        }
        // Set the default
        // if (serverSettings.getWebModule() == null) {
        // WebModulePluginConfiguration bimviewsWebModule = findWebModule(serverSettings, "BIM Views");
        // if (bimviewsWebModule != null) {
        // serverSettings.setWebModule(bimviewsWebModule);
        // setDefaultWebModule(pluginManager.getWebModulePlugin(bimviewsWebModule.getPluginDescriptor().getPluginClassName(), true));
        // } else {
        // WebModulePluginConfiguration defaultWebModule = findWebModule(serverSettings, "org.bimserver.defaultwebmodule.DefaultWebModulePlugin");
        // if (defaultWebModule != null) {
        // serverSettings.setWebModule(defaultWebModule);
        // setDefaultWebModule(pluginManager.getWebModulePlugin(defaultWebModule.getPluginDescriptor().getPluginClassName(), true));
        // }
        // }
        // }
        session.store(serverSettings);
        Condition condition = new AttributeCondition(StorePackage.eINSTANCE.getUser_Username(), new StringLiteral("system"));
        User systemUser = session.querySingle(condition, User.class, OldQuery.getDefault());
        ServerStarted serverStarted = session.create(ServerStarted.class);
        serverStarted.setDate(new Date());
        serverStarted.setAccessMethod(AccessMethod.INTERNAL);
        serverStarted.setExecutor(systemUser);
        try {
            session.store(serverStarted);
            session.commit();
        } catch (BimserverLockConflictException e) {
            throw new BimserverDatabaseException(e);
        } catch (ServiceException e) {
            throw new BimserverDatabaseException(e);
        } finally {
            session.close();
        }
        webModules = new HashMap<String, WebModulePlugin>();
        List<WebModulePluginConfiguration> webModuleConfigurations = serverSettingsCache.getServerSettings().getWebModules();
        for (WebModulePluginConfiguration webModulePluginConfiguration : webModuleConfigurations) {
            String contextPath = "";
            for (Parameter parameter : webModulePluginConfiguration.getSettings().getParameters()) {
                if (parameter.getName().equals("contextPath")) {
                    contextPath = ((StringType) parameter.getValue()).getValue();
                }
            }
            String identifier = webModulePluginConfiguration.getPluginDescriptor().getIdentifier();
            webModules.put(contextPath, (WebModulePlugin) pluginManager.getPlugin(identifier, true));
        }
        try (DatabaseSession databaseSession = getDatabase().createSession(OperationType.POSSIBLY_WRITE)) {
            ExtendedDataSchema htmlSchema = (ExtendedDataSchema) databaseSession.querySingle(StorePackage.eINSTANCE.getExtendedDataSchema_Name(), "GEOMETRY_GENERATION_REPORT_HTML_1_1");
            ExtendedDataSchema jsonSchema = (ExtendedDataSchema) databaseSession.querySingle(StorePackage.eINSTANCE.getExtendedDataSchema_Name(), "GEOMETRY_GENERATION_REPORT_JSON_1_1");
            if (htmlSchema == null) {
                htmlSchema = createExtendedDataSchema(databaseSession, "GEOMETRY_GENERATION_REPORT_HTML_1_1", "text/html");
            }
            if (jsonSchema == null) {
                jsonSchema = createExtendedDataSchema(databaseSession, "GEOMETRY_GENERATION_REPORT_JSON_1_1", "application/json");
            }
            databaseSession.commit();
        } catch (ServiceException e) {
            LOGGER.error("", e);
        }
        Integer protocolBuffersPort = getServerSettingsCache().getServerSettings().getProtocolBuffersPort();
        if (protocolBuffersPort >= 1 && protocolBuffersPort <= 65535) {
            try {
                protocolBuffersMetaData = new ProtocolBuffersMetaData();
                protocolBuffersMetaData.load(servicesMap, ProtocolBuffersBimServerClientFactory.class);
                protocolBuffersServer = new ProtocolBuffersServer(protocolBuffersMetaData, serviceFactory, servicesMap, protocolBuffersPort);
                protocolBuffersServer.start();
            } catch (Exception e) {
                LOGGER.error("", e);
            }
        }
        bimServerClientFactory = new DirectBimServerClientFactory<ServiceInterface>(serverSettingsCache.getServerSettings().getSiteAddress(), serviceFactory, servicesMap, pluginManager, metaDataManager);
        pluginManager.setBimServerClientFactory(bimServerClientFactory);
        try (DatabaseSession session2 = bimDatabase.createSession(OperationType.READ_ONLY)) {
            IfcModelInterface pluginBundleVersions = session2.getAllOfType(StorePackage.eINSTANCE.getPluginBundleVersion(), OldQuery.getDefault());
            for (PluginBundleVersion pluginBundleVersion : pluginBundleVersions.getAll(PluginBundleVersion.class)) {
                if (pluginBundleVersion.getType() == PluginBundleType.MAVEN || pluginBundleVersion.getType() == PluginBundleType.LOCAL) {
                    PluginBundleVersionIdentifier pluginBundleVersionIdentifier = new PluginBundleVersionIdentifier(pluginBundleVersion.getGroupId(), pluginBundleVersion.getArtifactId(), pluginBundleVersion.getVersion());
                    IfcModelInterface pluginDescriptors = session2.getAllOfType(StorePackage.eINSTANCE.getPluginDescriptor(), OldQuery.getDefault());
                    List<SPluginInformation> plugins = new ArrayList<>();
                    for (PluginDescriptor pluginDescriptor : pluginDescriptors.getAll(PluginDescriptor.class)) {
                        if (pluginDescriptor.getPluginBundleVersion() == pluginBundleVersion && pluginDescriptor.getEnabled()) {
                            SPluginInformation sPluginInformation = new SPluginInformation();
                            sPluginInformation.setEnabled(true);
                            sPluginInformation.setDescription(pluginDescriptor.getDescription());
                            sPluginInformation.setIdentifier(pluginDescriptor.getIdentifier());
                            sPluginInformation.setInstallForAllUsers(pluginDescriptor.isInstallForNewUsers());
                            sPluginInformation.setInstallForNewUsers(pluginDescriptor.isInstallForNewUsers());
                            sPluginInformation.setName(pluginDescriptor.getName());
                            sPluginInformation.setType(pluginManager.getPluginTypeFromClass(pluginDescriptor.getPluginClassName()));
                            plugins.add(sPluginInformation);
                        }
                    }
                    try {
                        pluginBundleManager.loadFromPluginDir(pluginBundleVersionIdentifier, getSConverter().convertToSObject(pluginBundleVersion), plugins, serverSettingsCache.getServerSettings().isPluginStrictVersionChecking());
                    } catch (Exception e) {
                        LOGGER.error("", e);
                    }
                }
            }
        } catch (Exception e) {
            throw new BimserverDatabaseException(e);
        }
    } catch (BimserverLockConflictException e) {
        throw new BimserverDatabaseException(e);
    // } catch (PluginException e) {
    // throw new BimserverDatabaseException(e);
    } catch (RenderEngineException e) {
        throw new BimserverDatabaseException(e);
    }
    long end = System.nanoTime();
    LOGGER.info("Done initializing database dependant logic (" + ((end - start) / 1000000) + "ms)");
}
Also used : User(org.bimserver.models.store.User) DatabaseSession(org.bimserver.database.DatabaseSession) IfcModelInterface(org.bimserver.emf.IfcModelInterface) ArrayList(java.util.ArrayList) ProtocolBuffersMetaData(org.bimserver.shared.pb.ProtocolBuffersMetaData) PluginBundleVersionIdentifier(org.bimserver.plugins.PluginBundleVersionIdentifier) ServerSettings(org.bimserver.models.store.ServerSettings) CommonsPoolingRenderEnginePoolFactory(org.bimserver.renderengine.pooled.CommonsPoolingRenderEnginePoolFactory) ServiceInterface(org.bimserver.shared.interfaces.ServiceInterface) ExtendedDataSchema(org.bimserver.models.store.ExtendedDataSchema) WebModulePlugin(org.bimserver.plugins.web.WebModulePlugin) PluginBundleVersion(org.bimserver.models.store.PluginBundleVersion) SPluginBundleVersion(org.bimserver.interfaces.objects.SPluginBundleVersion) RenderEngineException(org.bimserver.plugins.renderengine.RenderEngineException) Condition(org.bimserver.database.query.conditions.Condition) AttributeCondition(org.bimserver.database.query.conditions.AttributeCondition) PluginContext(org.bimserver.plugins.PluginContext) WebModulePluginConfiguration(org.bimserver.models.store.WebModulePluginConfiguration) SPluginInformation(org.bimserver.interfaces.objects.SPluginInformation) AttributeCondition(org.bimserver.database.query.conditions.AttributeCondition) RenderEnginePoolFactory(org.bimserver.renderengine.RenderEnginePoolFactory) CommonsPoolingRenderEnginePoolFactory(org.bimserver.renderengine.pooled.CommonsPoolingRenderEnginePoolFactory) Date(java.util.Date) ServiceException(org.bimserver.shared.exceptions.ServiceException) IOException(java.io.IOException) ServerException(org.bimserver.shared.exceptions.ServerException) PluginException(org.bimserver.shared.exceptions.PluginException) QueryException(org.bimserver.database.queries.om.QueryException) InconsistentModelsException(org.bimserver.database.migrations.InconsistentModelsException) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException) DatabaseRestartRequiredException(org.bimserver.database.DatabaseRestartRequiredException) DatabaseInitException(org.bimserver.database.berkeley.DatabaseInitException) RenderEngineException(org.bimserver.plugins.renderengine.RenderEngineException) ProtocolBuffersServer(org.bimserver.pb.server.ProtocolBuffersServer) PluginDescriptor(org.bimserver.models.store.PluginDescriptor) ServerStarted(org.bimserver.models.log.ServerStarted) ServiceException(org.bimserver.shared.exceptions.ServiceException) StringLiteral(org.bimserver.database.query.literals.StringLiteral) RenderEnginePools(org.bimserver.renderengine.RenderEnginePools) Parameter(org.bimserver.models.store.Parameter) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException)

Example 7 with AttributeCondition

use of org.bimserver.database.query.conditions.AttributeCondition in project BIMserver by opensourceBIM.

the class GetAllUsersDatabaseAction method execute.

@Override
public Set<User> execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    User actingUser = getUserByUoid(authorization.getUoid());
    Condition condition = new IsOfTypeCondition(StorePackage.eINSTANCE.getUser());
    condition = condition.and(new Not(new AttributeCondition(StorePackage.eINSTANCE.getUser_UserType(), new EnumLiteral(UserType.SYSTEM))));
    if (actingUser.getUserType() != UserType.ADMIN) {
        condition = condition.and(new AttributeCondition(StorePackage.eINSTANCE.getUser_State(), new EnumLiteral(ObjectState.ACTIVE)));
    }
    return CollectionUtils.mapToSet(getDatabaseSession().query(condition, User.class, OldQuery.getDefault()));
}
Also used : IsOfTypeCondition(org.bimserver.database.query.conditions.IsOfTypeCondition) AttributeCondition(org.bimserver.database.query.conditions.AttributeCondition) Condition(org.bimserver.database.query.conditions.Condition) Not(org.bimserver.database.query.conditions.Not) User(org.bimserver.models.store.User) IsOfTypeCondition(org.bimserver.database.query.conditions.IsOfTypeCondition) AttributeCondition(org.bimserver.database.query.conditions.AttributeCondition) EnumLiteral(org.bimserver.database.query.literals.EnumLiteral)

Example 8 with AttributeCondition

use of org.bimserver.database.query.conditions.AttributeCondition in project BIMserver by opensourceBIM.

the class RemoteServiceImpl method getPrivateProfiles.

@Override
public List<SProfileDescriptor> getPrivateProfiles(String serviceIdentifier, String token) throws UserException, ServerException {
    DatabaseSession session = getServiceMap().getBimServer().getDatabase().createSession(OperationType.READ_ONLY);
    List<SProfileDescriptor> descriptors = new ArrayList<SProfileDescriptor>();
    try {
        Condition condition = new AttributeCondition(StorePackage.eINSTANCE.getUser_Token(), new StringLiteral(token));
        User user = session.querySingle(condition, User.class, OldQuery.getDefault());
        if (user != null) {
            for (InternalServicePluginConfiguration internalServicePluginConfiguration : user.getUserSettings().getServices()) {
                if (internalServicePluginConfiguration.getPluginDescriptor().getPluginClassName().equals(serviceIdentifier)) {
                    SProfileDescriptor sProfileDescriptor = new SProfileDescriptor();
                    descriptors.add(sProfileDescriptor);
                    sProfileDescriptor.setIdentifier("" + internalServicePluginConfiguration.getOid());
                    sProfileDescriptor.setName(internalServicePluginConfiguration.getName());
                    sProfileDescriptor.setDescription(internalServicePluginConfiguration.getDescription());
                    sProfileDescriptor.setPublicProfile(false);
                }
            }
        }
    } catch (BimserverDatabaseException e) {
        handleException(e);
    } finally {
        session.close();
    }
    return descriptors;
}
Also used : AttributeCondition(org.bimserver.database.query.conditions.AttributeCondition) Condition(org.bimserver.database.query.conditions.Condition) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) User(org.bimserver.models.store.User) StringLiteral(org.bimserver.database.query.literals.StringLiteral) DatabaseSession(org.bimserver.database.DatabaseSession) InternalServicePluginConfiguration(org.bimserver.models.store.InternalServicePluginConfiguration) ArrayList(java.util.ArrayList) AttributeCondition(org.bimserver.database.query.conditions.AttributeCondition) SProfileDescriptor(org.bimserver.interfaces.objects.SProfileDescriptor)

Aggregations

AttributeCondition (org.bimserver.database.query.conditions.AttributeCondition)8 Condition (org.bimserver.database.query.conditions.Condition)8 User (org.bimserver.models.store.User)7 StringLiteral (org.bimserver.database.query.literals.StringLiteral)6 ArrayList (java.util.ArrayList)4 DatabaseSession (org.bimserver.database.DatabaseSession)4 IOException (java.io.IOException)3 Not (org.bimserver.database.query.conditions.Not)3 EnumLiteral (org.bimserver.database.query.literals.EnumLiteral)3 InternalServicePluginConfiguration (org.bimserver.models.store.InternalServicePluginConfiguration)3 PluginDescriptor (org.bimserver.models.store.PluginDescriptor)3 PluginContext (org.bimserver.plugins.PluginContext)3 WebModulePlugin (org.bimserver.plugins.web.WebModulePlugin)3 PluginException (org.bimserver.shared.exceptions.PluginException)3 ServerException (org.bimserver.shared.exceptions.ServerException)3 ServiceException (org.bimserver.shared.exceptions.ServiceException)3 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)2 AndCondition (org.bimserver.database.query.conditions.AndCondition)2 HasReferenceToCondition (org.bimserver.database.query.conditions.HasReferenceToCondition)2 Project (org.bimserver.models.store.Project)2