Search in sources :

Example 6 with LongTransaction

use of org.bimserver.webservices.LongTransaction in project BIMserver by opensourceBIM.

the class LowLevelServiceImpl method getAttributeAtIndex.

private Object getAttributeAtIndex(Long tid, Long oid, String attributeName, int index) throws ServerException, UserException {
    requireAuthenticationAndRunningServer();
    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");
        }
        Object eGet = object.eGet(object.eClass().getEStructuralFeature(attributeName));
        if (eGet instanceof List) {
            List<?> list = (List<?>) eGet;
            return list.get(index);
        }
        return eGet;
    } 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) IdEObject(org.bimserver.emf.IdEObject) SDataObject(org.bimserver.interfaces.objects.SDataObject) DataObject(org.bimserver.models.store.DataObject) 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)

Example 7 with LongTransaction

use of org.bimserver.webservices.LongTransaction in project BIMserver by opensourceBIM.

the class LowLevelServiceImpl method getAttribute.

private Object getAttribute(Long tid, Long oid, String attributeName) throws ServerException, UserException {
    requireAuthenticationAndRunningServer();
    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");
        }
        Object eGet = object.eGet(object.eClass().getEStructuralFeature(attributeName));
        if (eGet instanceof IdEObject) {
            IdEObject refObject = (IdEObject) eGet;
            return refObject.eGet(refObject.eClass().getEStructuralFeature("wrappedValue"));
        }
        return eGet;
    } 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) IdEObject(org.bimserver.emf.IdEObject) SDataObject(org.bimserver.interfaces.objects.SDataObject) DataObject(org.bimserver.models.store.DataObject) 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

BimserverDatabaseException (org.bimserver.BimserverDatabaseException)7 UserException (org.bimserver.shared.exceptions.UserException)7 LongTransaction (org.bimserver.webservices.LongTransaction)7 NoTransactionException (org.bimserver.webservices.NoTransactionException)7 DatabaseSession (org.bimserver.database.DatabaseSession)6 ServerException (org.bimserver.shared.exceptions.ServerException)6 EClass (org.eclipse.emf.ecore.EClass)5 OldQuery (org.bimserver.database.OldQuery)4 IdEObject (org.bimserver.emf.IdEObject)4 ArrayList (java.util.ArrayList)2 List (java.util.List)2 SDataObject (org.bimserver.interfaces.objects.SDataObject)2 DataObject (org.bimserver.models.store.DataObject)2 CreateObjectChange (org.bimserver.changes.CreateObjectChange)1 Database (org.bimserver.database.Database)1 CommitTransactionDatabaseAction (org.bimserver.database.actions.CommitTransactionDatabaseAction)1 ConcreteRevision (org.bimserver.models.store.ConcreteRevision)1 Project (org.bimserver.models.store.Project)1 Revision (org.bimserver.models.store.Revision)1 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)1