Search in sources :

Example 16 with DatabaseSession

use of org.bimserver.database.DatabaseSession 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 DatabaseSession

use of org.bimserver.database.DatabaseSession in project BIMserver by opensourceBIM.

the class AuthServiceImpl method setHash.

@Override
public void setHash(Long uoid, byte[] hash, byte[] salt) throws ServerException, UserException {
    requireAdminAuthentication();
    DatabaseSession session = getBimServer().getDatabase().createSession();
    try {
        User user = session.get(uoid, OldQuery.getDefault());
        user.setPasswordHash(hash);
        user.setPasswordSalt(salt);
        session.commit();
    } catch (Exception e) {
        handleException(e);
    } finally {
        session.close();
    }
}
Also used : User(org.bimserver.models.store.User) SUser(org.bimserver.interfaces.objects.SUser) DatabaseSession(org.bimserver.database.DatabaseSession) UserException(org.bimserver.shared.exceptions.UserException) ServerException(org.bimserver.shared.exceptions.ServerException)

Example 18 with DatabaseSession

use of org.bimserver.database.DatabaseSession in project BIMserver by opensourceBIM.

the class LowLevelServiceImpl method getDataObjectByGuid.

@Override
public SDataObject getDataObjectByGuid(Long roid, String guid) throws ServerException, UserException {
    requireAuthenticationAndRunningServer();
    DatabaseSession session = getBimServer().getDatabase().createSession();
    try {
        BimDatabaseAction<DataObject> action = new GetDataObjectByGuidDatabaseAction(getBimServer(), session, getInternalAccessMethod(), roid, guid, getAuthorization());
        SDataObject dataObject = getBimServer().getSConverter().convertToSObject(session.executeAndCommitAction(action));
        return dataObject;
    } catch (Exception e) {
        return handleException(e);
    } finally {
        session.close();
    }
}
Also used : SDataObject(org.bimserver.interfaces.objects.SDataObject) DataObject(org.bimserver.models.store.DataObject) DatabaseSession(org.bimserver.database.DatabaseSession) GetDataObjectByGuidDatabaseAction(org.bimserver.database.actions.GetDataObjectByGuidDatabaseAction) SDataObject(org.bimserver.interfaces.objects.SDataObject) UserException(org.bimserver.shared.exceptions.UserException) NoTransactionException(org.bimserver.webservices.NoTransactionException) ServerException(org.bimserver.shared.exceptions.ServerException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException)

Example 19 with DatabaseSession

use of org.bimserver.database.DatabaseSession in project BIMserver by opensourceBIM.

the class LowLevelServiceImpl method getDataObjectByOid.

@Override
public SDataObject getDataObjectByOid(Long roid, Long oid) throws ServerException, UserException {
    requireAuthenticationAndRunningServer();
    DatabaseSession session = getBimServer().getDatabase().createSession();
    try {
        BimDatabaseAction<DataObject> action = new GetDataObjectByOidDatabaseAction(getBimServer(), session, getInternalAccessMethod(), roid, oid, getAuthorization());
        SDataObject dataObject = getBimServer().getSConverter().convertToSObject(session.executeAndCommitAction(action));
        return dataObject;
    } catch (Exception e) {
        return handleException(e);
    } finally {
        session.close();
    }
}
Also used : GetDataObjectByOidDatabaseAction(org.bimserver.database.actions.GetDataObjectByOidDatabaseAction) SDataObject(org.bimserver.interfaces.objects.SDataObject) DataObject(org.bimserver.models.store.DataObject) DatabaseSession(org.bimserver.database.DatabaseSession) SDataObject(org.bimserver.interfaces.objects.SDataObject) UserException(org.bimserver.shared.exceptions.UserException) NoTransactionException(org.bimserver.webservices.NoTransactionException) ServerException(org.bimserver.shared.exceptions.ServerException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException)

Example 20 with DatabaseSession

use of org.bimserver.database.DatabaseSession in project BIMserver by opensourceBIM.

the class LowLevelServiceImpl method getReferences.

@SuppressWarnings("unchecked")
@Override
public List<Long> getReferences(Long tid, Long oid, String referenceName) throws ServerException, UserException {
    DatabaseSession session = getBimServer().getDatabase().createSession();
    try {
        LongTransaction transaction = getBimServer().getLongTransactionManager().get(tid);
        EClass eClass = session.getEClassForOid(oid);
        IdEObject object = session.get(eClass, oid, new OldQuery(transaction.getPackageMetaData(), transaction.getPid(), transaction.getRid(), transaction.getRoid(), null, Deep.NO));
        if (object == null) {
            throw new UserException("No object of type " + eClass.getName() + " with oid " + oid + " found");
        }
        List<IdEObject> list = (List<IdEObject>) object.eGet(object.eClass().getEStructuralFeature(referenceName));
        List<Long> oidList = new ArrayList<Long>();
        for (IdEObject idEObject : list) {
            oidList.add(idEObject.getOid());
        }
        return oidList;
    } catch (Exception e) {
        return handleException(e);
    } finally {
        session.close();
    }
}
Also used : EClass(org.eclipse.emf.ecore.EClass) DatabaseSession(org.bimserver.database.DatabaseSession) IdEObject(org.bimserver.emf.IdEObject) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) 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) OldQuery(org.bimserver.database.OldQuery)

Aggregations

DatabaseSession (org.bimserver.database.DatabaseSession)279 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)258 UserException (org.bimserver.shared.exceptions.UserException)228 ServerException (org.bimserver.shared.exceptions.ServerException)217 IOException (java.io.IOException)194 DeserializeException (org.bimserver.plugins.deserializers.DeserializeException)105 SerializerException (org.bimserver.plugins.serializers.SerializerException)105 UnsupportedEncodingException (java.io.UnsupportedEncodingException)103 MalformedURLException (java.net.MalformedURLException)103 MessagingException (javax.mail.MessagingException)103 AddressException (javax.mail.internet.AddressException)103 CannotBeScheduledException (org.bimserver.longaction.CannotBeScheduledException)103 BcfException (org.opensourcebim.bcf.BcfException)103 User (org.bimserver.models.store.User)34 ArrayList (java.util.ArrayList)29 UserSettings (org.bimserver.models.store.UserSettings)29 Project (org.bimserver.models.store.Project)25 ServerSettings (org.bimserver.models.store.ServerSettings)21 ServerSettingsSetter (org.bimserver.database.actions.ServerSettingsSetter)18 SetServerSettingDatabaseAction (org.bimserver.database.actions.SetServerSettingDatabaseAction)18