Search in sources :

Example 16 with BimserverDatabaseException

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

the class AdminServiceImpl method setup.

@Override
public void setup(String siteAddress, String serverName, String serverDescription, String serverIcon, String adminName, String adminUsername, String adminPassword) throws ServerException, UserException {
    SettingsInterface settingsInterface = getServiceMap().get(SettingsInterface.class);
    if (!siteAddress.startsWith("http://") && !siteAddress.startsWith("https://")) {
        throw new UserException("Site address should start with \"http://\" or \"https://\"");
    }
    if (siteAddress.startsWith("http://http://") || siteAddress.startsWith("https://https://")) {
        throw new UserException("Site address should not have duplicate protocols");
    }
    settingsInterface.setSiteAddress(siteAddress);
    settingsInterface.setServerName(serverName);
    settingsInterface.setServerDescription(serverDescription);
    settingsInterface.setServerIcon(serverIcon);
    if (adminUsername.trim().isEmpty()) {
        throw new UserException("Admin Username cannot be empty");
    }
    if (adminPassword.trim().isEmpty()) {
        throw new UserException("Admin Password cannot be empty");
    }
    DatabaseSession session = getBimServer().getDatabase().createSession();
    try {
        AddUserDatabaseAction addUserDatabaseAction = new AddUserDatabaseAction(getBimServer(), session, AccessMethod.INTERNAL, adminUsername, adminPassword, adminName, UserType.ADMIN, getAuthorization(), false, "");
        session.executeAndCommitAction(addUserDatabaseAction);
    } catch (BimserverDatabaseException e) {
        LOGGER.error("", e);
    } finally {
        session.close();
    }
    getBimServer().getServerInfoManager().update();
}
Also used : SettingsInterface(org.bimserver.shared.interfaces.SettingsInterface) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) AddUserDatabaseAction(org.bimserver.database.actions.AddUserDatabaseAction) DatabaseSession(org.bimserver.database.DatabaseSession) UserException(org.bimserver.shared.exceptions.UserException)

Example 17 with BimserverDatabaseException

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

the class ServiceImpl method getAvailableClassesInRevision.

@Override
public List<String> getAvailableClassesInRevision(Long roid) throws ServerException, UserException {
    requireRealUserAuthentication();
    DatabaseSession session = getBimServer().getDatabase().createSession();
    try {
        BimDatabaseAction<List<String>> action = new GetAvailableClassesInRevisionDatabaseAction(getBimServer(), session, getInternalAccessMethod(), roid);
        return session.executeAndCommitAction(action);
    } catch (BimserverDatabaseException e) {
        handleException(e);
    } finally {
        session.close();
    }
    return null;
}
Also used : BimserverDatabaseException(org.bimserver.BimserverDatabaseException) DatabaseSession(org.bimserver.database.DatabaseSession) GetAvailableClassesInRevisionDatabaseAction(org.bimserver.database.actions.GetAvailableClassesInRevisionDatabaseAction) ArrayList(java.util.ArrayList) List(java.util.List) EList(org.eclipse.emf.common.util.EList)

Example 18 with BimserverDatabaseException

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

the class SettingsServiceImpl method setAllowUsersToCreateTopLevelProjects.

@Override
public void setAllowUsersToCreateTopLevelProjects(final Boolean allowUsersToCreateTopLevelProjects) throws ServerException, UserException {
    requireAdminAuthenticationAndRunningServer();
    DatabaseSession session = getBimServer().getDatabase().createSession();
    try {
        SetServerSettingDatabaseAction action = new SetServerSettingDatabaseAction(getBimServer(), session, getInternalAccessMethod(), new ServerSettingsSetter() {

            @Override
            public void set(ServerSettings serverSettings) {
                serverSettings.setAllowUsersToCreateTopLevelProjects(allowUsersToCreateTopLevelProjects);
            }
        });
        session.executeAndCommitAction(action);
    } catch (BimserverDatabaseException e) {
        handleException(e);
    } finally {
        session.close();
    }
}
Also used : ServerSettingsSetter(org.bimserver.database.actions.ServerSettingsSetter) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) DatabaseSession(org.bimserver.database.DatabaseSession) SetServerSettingDatabaseAction(org.bimserver.database.actions.SetServerSettingDatabaseAction) SServerSettings(org.bimserver.interfaces.objects.SServerSettings) ServerSettings(org.bimserver.models.store.ServerSettings)

Example 19 with BimserverDatabaseException

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

the class SettingsServiceImpl method setEmailSenderAddress.

@Override
public void setEmailSenderAddress(final String emailSenderAddress) throws ServerException, UserException {
    if (getBimServer().getServerInfo().getServerState() != ServerState.NOT_SETUP) {
        requireAdminAuthentication();
    }
    if (emailSenderAddress.trim().isEmpty()) {
        throw new UserException("Email sender address cannot be empty");
    }
    DatabaseSession session = getBimServer().getDatabase().createSession();
    try {
        SetServerSettingDatabaseAction action = new SetServerSettingDatabaseAction(getBimServer(), session, getInternalAccessMethod(), new ServerSettingsSetter() {

            @Override
            public void set(ServerSettings serverSettings) {
                serverSettings.setEmailSenderAddress(emailSenderAddress);
            }
        });
        session.executeAndCommitAction(action);
    } catch (BimserverDatabaseException e) {
        handleException(e);
    } finally {
        session.close();
    }
}
Also used : ServerSettingsSetter(org.bimserver.database.actions.ServerSettingsSetter) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) DatabaseSession(org.bimserver.database.DatabaseSession) SetServerSettingDatabaseAction(org.bimserver.database.actions.SetServerSettingDatabaseAction) SServerSettings(org.bimserver.interfaces.objects.SServerSettings) ServerSettings(org.bimserver.models.store.ServerSettings) UserException(org.bimserver.shared.exceptions.UserException)

Example 20 with BimserverDatabaseException

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

the class SettingsServiceImpl method setAllowSelfRegistration.

@Override
public void setAllowSelfRegistration(final Boolean allowSelfRegistration) throws ServerException, UserException {
    requireAdminAuthenticationAndRunningServer();
    DatabaseSession session = getBimServer().getDatabase().createSession();
    try {
        SetServerSettingDatabaseAction action = new SetServerSettingDatabaseAction(getBimServer(), session, getInternalAccessMethod(), new ServerSettingsSetter() {

            @Override
            public void set(ServerSettings serverSettings) {
                serverSettings.setAllowSelfRegistration(allowSelfRegistration);
            }
        });
        session.executeAndCommitAction(action);
    } catch (BimserverDatabaseException e) {
        handleException(e);
    } finally {
        session.close();
    }
}
Also used : ServerSettingsSetter(org.bimserver.database.actions.ServerSettingsSetter) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) DatabaseSession(org.bimserver.database.DatabaseSession) SetServerSettingDatabaseAction(org.bimserver.database.actions.SetServerSettingDatabaseAction) SServerSettings(org.bimserver.interfaces.objects.SServerSettings) ServerSettings(org.bimserver.models.store.ServerSettings)

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