Search in sources :

Example 6 with BimserverDatabaseException

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

the class ByteBufferVirtualObject method setListItem.

public void setListItem(EStructuralFeature feature, int index, Object value) throws BimserverDatabaseException {
    if (currentListStart == -1) {
        throw new BimserverDatabaseException("Not currently writing a list");
    }
    if (index + 1 > currentListSize) {
        currentListSize = index + 1;
    }
    if (value instanceof ByteBufferWrappedVirtualObject) {
        ByteBuffer otherBuffer = ((ByteBufferWrappedVirtualObject) value).write();
        ensureCapacity(buffer.position(), otherBuffer.position());
        buffer.put(otherBuffer.array(), 0, otherBuffer.position());
    } else if (value instanceof ByteBufferList) {
        ByteBuffer otherBuffer = ((ByteBufferList) value).write();
        ensureCapacity(buffer.position(), otherBuffer.position());
        buffer.put(otherBuffer.array(), 0, otherBuffer.position());
    } else {
        writePrimitiveValue(feature, value);
    }
}
Also used : BimserverDatabaseException(org.bimserver.BimserverDatabaseException) ByteBuffer(java.nio.ByteBuffer)

Example 7 with BimserverDatabaseException

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

the class HashMapVirtualObject method writePrimitiveValue.

private void writePrimitiveValue(EStructuralFeature feature, Object value, ByteBuffer buffer) throws BimserverDatabaseException {
    EClassifier type = feature.getEType();
    if (type == EcorePackage.eINSTANCE.getEString()) {
        if (value == null) {
            buffer.putInt(-1);
        } else {
            String stringValue = (String) value;
            byte[] bytes = stringValue.getBytes(Charsets.UTF_8);
            if (bytes.length > Integer.MAX_VALUE) {
                throw new BimserverDatabaseException("String value too long (max length is " + Integer.MAX_VALUE + ")");
            }
            buffer.putInt(bytes.length);
            buffer.put(bytes);
        }
    } else if (type == EcorePackage.eINSTANCE.getEInt() || type == EcorePackage.eINSTANCE.getEIntegerObject()) {
        if (value == null) {
            buffer.putInt(0);
        } else {
            buffer.putInt((Integer) value);
        }
    } else if (type == EcorePackage.eINSTANCE.getEDouble() || type == EcorePackage.eINSTANCE.getEDoubleObject()) {
        if (value == null) {
            buffer.putDouble(0D);
        } else {
            buffer.putDouble((Double) value);
        }
    } else if (type == EcorePackage.eINSTANCE.getEFloat() || type == EcorePackage.eINSTANCE.getEFloatObject()) {
        if (value == null) {
            buffer.putFloat(0F);
        } else {
            buffer.putFloat((Float) value);
        }
    } else if (type == EcorePackage.eINSTANCE.getELong() || type == EcorePackage.eINSTANCE.getELongObject()) {
        if (value == null) {
            buffer.putLong(0L);
        } else {
            buffer.putLong((Long) value);
        }
    } else if (type == EcorePackage.eINSTANCE.getEBoolean() || type == EcorePackage.eINSTANCE.getEBooleanObject()) {
        if (value == null) {
            buffer.put((byte) 0);
        } else {
            buffer.put(((Boolean) value) ? (byte) 1 : (byte) 0);
        }
    } else if (type == EcorePackage.eINSTANCE.getEDate()) {
        if (value == null) {
            buffer.putLong(-1L);
        } else {
            buffer.putLong(((Date) value).getTime());
        }
    } else if (type.getName().equals("Tristate")) {
        if (value == null) {
            buffer.putInt(Tristate.UNDEFINED.getValue());
        } else {
            Enumerator eEnumLiteral = (Enumerator) value;
            buffer.putInt(eEnumLiteral.getValue());
        }
    } else if (value instanceof Enumerator) {
        Enumerator eEnumLiteral = (Enumerator) value;
        buffer.putInt(eEnumLiteral.getValue());
    } else if (type == EcorePackage.eINSTANCE.getEByteArray()) {
        if (value == null) {
            buffer.putInt(0);
        } else {
            byte[] bytes = (byte[]) value;
            buffer.putInt(bytes.length);
            buffer.put(bytes);
        }
    } else {
        throw new RuntimeException("Unsupported type " + type.getName());
    }
}
Also used : BimserverDatabaseException(org.bimserver.BimserverDatabaseException) Enumerator(org.eclipse.emf.common.util.Enumerator) EClassifier(org.eclipse.emf.ecore.EClassifier)

Example 8 with BimserverDatabaseException

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

the class TestInOut method start.

private void start(String[] args) {
    BimServerConfig config = new BimServerConfig();
    Path homeDir = Paths.get("home");
    try {
        if (Files.isDirectory(homeDir)) {
            PathUtils.removeDirectoryWithContent(homeDir);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    config.setClassPath(System.getProperty("java.class.path"));
    config.setHomeDir(homeDir);
    config.setPort(8080);
    config.setStartEmbeddedWebServer(true);
    config.setResourceFetcher(new LocalDevelopmentResourceFetcher(Paths.get("../")));
    BimServer bimServer = new BimServer(config);
    try {
        LocalDevPluginLoader.loadPlugins(bimServer.getPluginManager(), new OptionsParser(args).getPluginDirectories());
        bimServer.start();
        if (bimServer.getServerInfo().getServerState() == ServerState.NOT_SETUP) {
            AdminInterface adminInterface = bimServer.getServiceFactory().get(new SystemAuthorization(1, TimeUnit.HOURS), AccessMethod.INTERNAL).get(AdminInterface.class);
            adminInterface.setup("http://localhost:8080", "Administrator", "admin@bimserver.org", "admin", null, null, null);
            SettingsInterface settingsInterface = bimServer.getServiceFactory().get(new SystemAuthorization(1, TimeUnit.HOURS), AccessMethod.INTERNAL).get(SettingsInterface.class);
            settingsInterface.setCacheOutputFiles(false);
        }
        BimServerClientInterface client = LocalDevSetup.setupJson("http://localhost:8080");
        SProject project = client.getServiceInterface().addProject("test", "ifc2x3tc1");
        SDeserializerPluginConfiguration deserializer = client.getServiceInterface().getSuggestedDeserializerForExtension("ifc", project.getOid());
        Path inputFile = Paths.get("../TestData/data/AC11-Institute-Var-2-IFC.ifc");
        client.checkin(project.getOid(), "test", deserializer.getOid(), false, Flow.SYNC, inputFile);
        project = client.getServiceInterface().getProjectByPoid(project.getOid());
        SSerializerPluginConfiguration serializer = client.getServiceInterface().getSerializerByContentType("application/ifc");
        Path outputFile = Paths.get("output.ifc");
        client.download(project.getLastRevisionId(), serializer.getOid(), outputFile);
        Diff diff = new Diff(false, false, false, inputFile, outputFile);
        diff.start();
    } catch (ServerException e) {
        e.printStackTrace();
    } catch (DatabaseInitException e) {
        e.printStackTrace();
    } catch (BimserverDatabaseException e) {
        e.printStackTrace();
    } catch (PluginException e) {
        e.printStackTrace();
    } catch (DatabaseRestartRequiredException e) {
        e.printStackTrace();
    } catch (UserException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (PublicInterfaceNotFoundException e) {
        e.printStackTrace();
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (CompareException e) {
        e.printStackTrace();
    } catch (BimServerClientException e) {
        e.printStackTrace();
    }
}
Also used : Path(java.nio.file.Path) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) ServerException(org.bimserver.shared.exceptions.ServerException) Diff(org.bimserver.tests.diff.Diff) BimServer(org.bimserver.BimServer) PluginException(org.bimserver.shared.exceptions.PluginException) IOException(java.io.IOException) SystemAuthorization(org.bimserver.webservices.authorization.SystemAuthorization) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) BimServerConfig(org.bimserver.BimServerConfig) OptionsParser(org.bimserver.plugins.OptionsParser) SProject(org.bimserver.interfaces.objects.SProject) BimServerClientException(org.bimserver.shared.exceptions.BimServerClientException) LocalDevelopmentResourceFetcher(org.bimserver.shared.LocalDevelopmentResourceFetcher) AdminInterface(org.bimserver.shared.interfaces.AdminInterface) DatabaseInitException(org.bimserver.database.berkeley.DatabaseInitException) SettingsInterface(org.bimserver.shared.interfaces.SettingsInterface) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) DatabaseRestartRequiredException(org.bimserver.database.DatabaseRestartRequiredException) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) UserException(org.bimserver.shared.exceptions.UserException) CompareException(org.bimserver.tests.diff.CompareException)

Example 9 with BimserverDatabaseException

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

the class TestDatabase method checkLists3.

private void checkLists3() {
    DatabaseSession session = database.createSession();
    long xid = -1;
    try {
        User user = session.create(User.class);
        UserSettings userSettings = session.create(UserSettings.class);
        SerializerPluginConfiguration serializerPluginConfiguration1 = session.create(SerializerPluginConfiguration.class);
        SerializerPluginConfiguration serializerPluginConfiguration2 = session.create(SerializerPluginConfiguration.class);
        xid = serializerPluginConfiguration2.getOid();
        user.setUserSettings(userSettings);
        serializerPluginConfiguration1.setUserSettings(userSettings);
        serializerPluginConfiguration2.setUserSettings(userSettings);
        session.commit();
    } catch (BimserverDatabaseException e) {
        e.printStackTrace();
    } catch (ServiceException e) {
        e.printStackTrace();
    } finally {
        session.close();
        session = database.createSession();
        try {
            SerializerPluginConfiguration p1 = session.get(xid, OldQuery.getDefault());
            UserSettings userSettings = p1.getUserSettings();
            for (SerializerPluginConfiguration p2 : userSettings.getSerializers()) {
                System.out.println(p2.getOid() + " - " + p2);
            }
        } catch (BimserverDatabaseException e) {
            e.printStackTrace();
        } finally {
            session.close();
        }
    }
}
Also used : BimserverDatabaseException(org.bimserver.BimserverDatabaseException) User(org.bimserver.models.store.User) ServiceException(org.bimserver.shared.exceptions.ServiceException) DatabaseSession(org.bimserver.database.DatabaseSession) UserSettings(org.bimserver.models.store.UserSettings) SerializerPluginConfiguration(org.bimserver.models.store.SerializerPluginConfiguration)

Example 10 with BimserverDatabaseException

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

the class TestDatabase method checkWithAllOfType.

private void checkWithAllOfType() {
    DatabaseSession session = database.createSession();
    try {
        List<User> users = session.getAllOfType(StorePackage.eINSTANCE.getUser(), User.class, OldQuery.getDefault());
        for (User user : users) {
            if (user.getName().equals("testuser")) {
                System.out.println(user.getName() + ": " + user.getHasRightsOn());
            }
        }
        List<Project> projects = session.getAllOfType(StorePackage.eINSTANCE.getProject(), Project.class, OldQuery.getDefault());
        for (Project project : projects) {
            if (project.getName().equals("testproject")) {
                System.out.println(project.getName() + ": " + project.getHasAuthorizedUsers());
            }
        }
        session.commit();
    } catch (BimserverDatabaseException e) {
        e.printStackTrace();
    } catch (ServiceException e) {
        e.printStackTrace();
    } finally {
        session.close();
    }
}
Also used : Project(org.bimserver.models.store.Project) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) User(org.bimserver.models.store.User) ServiceException(org.bimserver.shared.exceptions.ServiceException) DatabaseSession(org.bimserver.database.DatabaseSession)

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