Search in sources :

Example 1 with LongTransaction

use of org.bimserver.webservices.LongTransaction 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)

Example 2 with LongTransaction

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

the class LowLevelServiceImpl method startTransaction.

@Override
public Long startTransaction(Long poid) throws UserException, ServerException {
    requireAuthenticationAndRunningServer();
    DatabaseSession session = getBimServer().getDatabase().createSession();
    int pid = -1;
    int rid = -1;
    long roid = -1;
    try {
        Project project = (Project) session.get(poid, OldQuery.getDefault());
        if (project == null) {
            throw new UserException("No project found with poid " + poid);
        }
        pid = project.getId();
        if (project.getLastRevision() != null) {
            Revision revision = project.getLastRevision();
            ConcreteRevision lastConcreteRevision = revision.getLastConcreteRevision();
            rid = lastConcreteRevision.getId();
            roid = revision.getOid();
        }
        LongTransaction longTransaction = getBimServer().getLongTransactionManager().newLongTransaction(getBimServer().getMetaDataManager().getPackageMetaData(project.getSchema()), poid, pid, rid, roid);
        return longTransaction.getTid();
    } catch (Exception e) {
        return handleException(e);
    } finally {
        session.close();
    }
}
Also used : Project(org.bimserver.models.store.Project) Revision(org.bimserver.models.store.Revision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) DatabaseSession(org.bimserver.database.DatabaseSession) 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 3 with LongTransaction

use of org.bimserver.webservices.LongTransaction 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 4 with LongTransaction

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

the class LowLevelServiceImpl method getReference.

@Override
public Long getReference(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");
        }
        EStructuralFeature eStructuralFeature = object.eClass().getEStructuralFeature(referenceName);
        if (eStructuralFeature == null) {
            throw new UserException("No feature with name " + referenceName + " found on class " + object.eClass().getName());
        }
        IdEObject ref = (IdEObject) object.eGet(eStructuralFeature);
        if (ref == null) {
            return -1L;
        }
        return ref.getOid();
    } 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) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) 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 5 with LongTransaction

use of org.bimserver.webservices.LongTransaction 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)

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