Search in sources :

Example 26 with BimserverDatabaseException

use of org.bimserver.BimserverDatabaseException in project BIMserver by opensourceBIM.

the class LowLevelServiceImpl method createObject.

@Override
public Long createObject(Long tid, String className, Boolean generateGuid) throws UserException, ServerException {
    requireAuthenticationAndRunningServer();
    try {
        LongTransaction longTransaction = getBimServer().getLongTransactionManager().get(tid);
        if (longTransaction == null) {
            throw new UserException("No transaction with tid " + tid + " was found");
        }
        try {
            EClass eClass = ((Database) getBimServer().getDatabase()).getEClass(longTransaction.getPackageMetaData().getEPackage().getName(), className);
            Long oid = getBimServer().getDatabase().newOid(eClass);
            CreateObjectChange createObject = new CreateObjectChange(className, oid, eClass, generateGuid);
            longTransaction.add(createObject);
            return oid;
        } catch (BimserverDatabaseException e) {
            throw new UserException("Unknown type: \"" + className + "\"");
        }
    } catch (Exception e) {
        return handleException(e);
    }
}
Also used : BimserverDatabaseException(org.bimserver.BimserverDatabaseException) EClass(org.eclipse.emf.ecore.EClass) CreateObjectChange(org.bimserver.changes.CreateObjectChange) Database(org.bimserver.database.Database) UserException(org.bimserver.shared.exceptions.UserException) LongTransaction(org.bimserver.webservices.LongTransaction) UserException(org.bimserver.shared.exceptions.UserException) NoTransactionException(org.bimserver.webservices.NoTransactionException) ServerException(org.bimserver.shared.exceptions.ServerException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException)

Example 27 with BimserverDatabaseException

use of org.bimserver.BimserverDatabaseException in project BIMserver by opensourceBIM.

the class LowLevelServiceImpl method commitTransaction.

@Override
public Long commitTransaction(Long tid, String comment) throws UserException, ServerException {
    requireAuthenticationAndRunningServer();
    DatabaseSession session = getBimServer().getDatabase().createSession();
    try {
        LongTransaction longTransaction = getBimServer().getLongTransactionManager().get(tid);
        if (longTransaction == null) {
            throw new UserException("No transaction with tid " + tid + " was found");
        }
        CommitTransactionDatabaseAction action = new CommitTransactionDatabaseAction(getBimServer(), session, getInternalAccessMethod(), getAuthorization(), longTransaction, comment);
        try {
            session.executeAndCommitAction(action);
            return action.getRevision().getOid();
        } catch (BimserverDatabaseException e) {
            LOGGER.error("", e);
        } finally {
            session.close();
        }
    } catch (NoTransactionException e) {
        LOGGER.error("", e);
    }
    return -1L;
}
Also used : BimserverDatabaseException(org.bimserver.BimserverDatabaseException) NoTransactionException(org.bimserver.webservices.NoTransactionException) DatabaseSession(org.bimserver.database.DatabaseSession) CommitTransactionDatabaseAction(org.bimserver.database.actions.CommitTransactionDatabaseAction) UserException(org.bimserver.shared.exceptions.UserException) LongTransaction(org.bimserver.webservices.LongTransaction)

Example 28 with BimserverDatabaseException

use of org.bimserver.BimserverDatabaseException in project BIMserver by opensourceBIM.

the class NewServicesImpl method listAvailableOutputFormats.

@Override
public List<SFormatSerializerMap> listAvailableOutputFormats(Long poid) throws ServerException, UserException {
    Map<String, SFormatSerializerMap> outputs = new HashMap<>();
    try (DatabaseSession session = getBimServer().getDatabase().createSession()) {
        Project project = session.get(poid, OldQuery.getDefault());
        try {
            List<SSerializerPluginConfiguration> allSerializersForPoids = getServiceMap().get(PluginInterface.class).getAllSerializersForPoids(true, Collections.singleton(poid));
            for (SSerializerPluginConfiguration pluginConfiguration : allSerializersForPoids) {
                PluginDescriptor pluginDescriptor = session.get(pluginConfiguration.getPluginDescriptorId(), OldQuery.getDefault());
                Plugin plugin = getBimServer().getPluginManager().getPlugin(pluginDescriptor.getIdentifier(), true);
                String outputFormat = null;
                // TODO For now only streaming serializers
                if (plugin instanceof StreamingSerializerPlugin) {
                    outputFormat = ((StreamingSerializerPlugin) plugin).getOutputFormat(Schema.valueOf(project.getSchema().toUpperCase()));
                }
                if (outputFormat != null) {
                    SFormatSerializerMap map = outputs.get(outputFormat);
                    if (map == null) {
                        map = new SFormatSerializerMap();
                        map.setFormat(outputFormat);
                        outputs.put(outputFormat, map);
                    }
                    map.getSerializers().add(pluginConfiguration);
                }
            }
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (UserException e) {
            e.printStackTrace();
        }
        return new ArrayList<>(outputs.values());
    } catch (BimserverDatabaseException e) {
        return handleException(e);
    }
}
Also used : ServerException(org.bimserver.shared.exceptions.ServerException) HashMap(java.util.HashMap) DatabaseSession(org.bimserver.database.DatabaseSession) PluginInterface(org.bimserver.shared.interfaces.PluginInterface) ArrayList(java.util.ArrayList) SFormatSerializerMap(org.bimserver.interfaces.objects.SFormatSerializerMap) StreamingSerializerPlugin(org.bimserver.plugins.serializers.StreamingSerializerPlugin) Project(org.bimserver.models.store.Project) PluginDescriptor(org.bimserver.models.store.PluginDescriptor) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) UserException(org.bimserver.shared.exceptions.UserException) StreamingSerializerPlugin(org.bimserver.plugins.serializers.StreamingSerializerPlugin) Plugin(org.bimserver.plugins.Plugin)

Example 29 with BimserverDatabaseException

use of org.bimserver.BimserverDatabaseException in project BIMserver by opensourceBIM.

the class OAuthServiceImpl method listRegisteredServersLocal.

@Override
public List<SOAuthServer> listRegisteredServersLocal() throws ServerException, UserException {
    try (DatabaseSession session = getBimServer().getDatabase().createSession()) {
        List<OAuthServer> allOfType = session.getAllOfType(StorePackage.eINSTANCE.getOAuthServer(), OAuthServer.class, OldQuery.getDefault());
        Iterator<OAuthServer> iterator = allOfType.iterator();
        while (iterator.hasNext()) {
            OAuthServer next = iterator.next();
            if (!next.isIncoming()) {
                iterator.remove();
            }
        }
        return getBimServer().getSConverter().convertToSListOAuthServer(allOfType);
    } catch (BimserverDatabaseException e) {
        return handleException(e);
    }
}
Also used : BimserverDatabaseException(org.bimserver.BimserverDatabaseException) DatabaseSession(org.bimserver.database.DatabaseSession) SOAuthServer(org.bimserver.interfaces.objects.SOAuthServer) OAuthServer(org.bimserver.models.store.OAuthServer)

Example 30 with BimserverDatabaseException

use of org.bimserver.BimserverDatabaseException in project BIMserver by opensourceBIM.

the class OAuthServiceImpl method listRegisteredServers.

@Override
public List<SOAuthServer> listRegisteredServers() throws ServerException, UserException {
    try (DatabaseSession session = getBimServer().getDatabase().createSession()) {
        List<OAuthServer> allOfType = session.getAllOfType(StorePackage.eINSTANCE.getOAuthServer(), OAuthServer.class, OldQuery.getDefault());
        Iterator<OAuthServer> iterator = allOfType.iterator();
        while (iterator.hasNext()) {
            OAuthServer next = iterator.next();
            if (next.isIncoming()) {
                iterator.remove();
            }
        }
        return getBimServer().getSConverter().convertToSListOAuthServer(allOfType);
    } catch (BimserverDatabaseException e) {
        return handleException(e);
    }
}
Also used : BimserverDatabaseException(org.bimserver.BimserverDatabaseException) DatabaseSession(org.bimserver.database.DatabaseSession) SOAuthServer(org.bimserver.interfaces.objects.SOAuthServer) OAuthServer(org.bimserver.models.store.OAuthServer)

Aggregations

BimserverDatabaseException (org.bimserver.BimserverDatabaseException)123 DatabaseSession (org.bimserver.database.DatabaseSession)56 UserException (org.bimserver.shared.exceptions.UserException)30 EClass (org.eclipse.emf.ecore.EClass)24 User (org.bimserver.models.store.User)20 ByteBuffer (java.nio.ByteBuffer)19 BimserverLockConflictException (org.bimserver.database.BimserverLockConflictException)18 ServerSettings (org.bimserver.models.store.ServerSettings)18 IOException (java.io.IOException)16 ServerSettingsSetter (org.bimserver.database.actions.ServerSettingsSetter)16 SetServerSettingDatabaseAction (org.bimserver.database.actions.SetServerSettingDatabaseAction)16 SServerSettings (org.bimserver.interfaces.objects.SServerSettings)16 ServerException (org.bimserver.shared.exceptions.ServerException)15 UserSettings (org.bimserver.models.store.UserSettings)12 ServiceException (org.bimserver.shared.exceptions.ServiceException)11 HashMapVirtualObject (org.bimserver.shared.HashMapVirtualObject)10 ArrayList (java.util.ArrayList)9 IdEObject (org.bimserver.emf.IdEObject)9 Project (org.bimserver.models.store.Project)9 SerializerPluginConfiguration (org.bimserver.models.store.SerializerPluginConfiguration)9