Search in sources :

Example 6 with ConcreteRevision

use of org.bimserver.models.store.ConcreteRevision 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 7 with ConcreteRevision

use of org.bimserver.models.store.ConcreteRevision in project BIMserver by opensourceBIM.

the class PluginServiceImpl method getAllSerializersForRoids.

@Override
public List<SSerializerPluginConfiguration> getAllSerializersForRoids(Boolean onlyEnabled, Set<Long> roids) throws ServerException, UserException {
    requireRealUserAuthentication();
    DatabaseSession session = getBimServer().getDatabase().createSession();
    try {
        Set<Long> poids = new HashSet<>();
        for (Long roid : roids) {
            Revision revision = session.get(roid, OldQuery.getDefault());
            for (ConcreteRevision concreteRevision : revision.getConcreteRevisions()) {
                poids.add(concreteRevision.getProject().getOid());
            }
        }
        return getAllSerializersForPoids(onlyEnabled, poids);
    } catch (Exception e) {
        handleException(e);
    } finally {
        session.close();
    }
    return null;
}
Also used : Revision(org.bimserver.models.store.Revision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) DatabaseSession(org.bimserver.database.DatabaseSession) IOException(java.io.IOException) ServerException(org.bimserver.shared.exceptions.ServerException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) UserException(org.bimserver.shared.exceptions.UserException) HashSet(java.util.HashSet)

Example 8 with ConcreteRevision

use of org.bimserver.models.store.ConcreteRevision in project BIMserver by opensourceBIM.

the class GetDataObjectByGuidDatabaseAction method execute.

@Override
public DataObject execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    Revision virtualRevision = getRevisionByRoid(roid);
    ObjectIdentifier objectIdentifier = null;
    for (ConcreteRevision concreteRevision : virtualRevision.getConcreteRevisions()) {
        objectIdentifier = getDatabaseSession().getOidOfGuid(concreteRevision.getProject().getSchema(), guid, concreteRevision.getProject().getId(), concreteRevision.getId());
        if (objectIdentifier != null) {
            long oidOfGuid = objectIdentifier.getOid();
            if (oidOfGuid != -1) {
                break;
            }
        }
    }
    if (objectIdentifier == null) {
        throw new UserException("Guid " + guid + " not found in this revision/project");
    }
    return new GetDataObjectByOidDatabaseAction(bimServer, getDatabaseSession(), getAccessMethod(), roid, objectIdentifier.getOid(), authorization).execute();
}
Also used : Revision(org.bimserver.models.store.Revision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) UserException(org.bimserver.shared.exceptions.UserException) ObjectIdentifier(org.bimserver.database.ObjectIdentifier)

Example 9 with ConcreteRevision

use of org.bimserver.models.store.ConcreteRevision in project BIMserver by opensourceBIM.

the class GetOidByGuidDatabaseAction method execute.

@Override
public Long execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    Revision virtualRevision = getRevisionByRoid(roid);
    ObjectIdentifier objectIdentifier = null;
    for (ConcreteRevision concreteRevision : virtualRevision.getConcreteRevisions()) {
        objectIdentifier = getDatabaseSession().getOidOfGuid(concreteRevision.getProject().getSchema(), guid, concreteRevision.getProject().getId(), concreteRevision.getId());
        if (objectIdentifier != null) {
            long oidOfGuid = objectIdentifier.getOid();
            if (oidOfGuid != -1) {
                break;
            }
        }
    }
    if (objectIdentifier == null) {
        throw new UserException("Guid " + guid + " not found in this revision/project");
    }
    return objectIdentifier.getOid();
}
Also used : Revision(org.bimserver.models.store.Revision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) UserException(org.bimserver.shared.exceptions.UserException) ObjectIdentifier(org.bimserver.database.ObjectIdentifier)

Example 10 with ConcreteRevision

use of org.bimserver.models.store.ConcreteRevision in project BIMserver by opensourceBIM.

the class BranchToNewProjectDatabaseAction method execute.

@Override
public ConcreteRevision execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    Revision oldRevision = getDatabaseSession().get(StorePackage.eINSTANCE.getRevision(), roid, OldQuery.getDefault());
    Project oldProject = oldRevision.getProject();
    final User user = getDatabaseSession().get(StorePackage.eINSTANCE.getUser(), authorization.getUoid(), OldQuery.getDefault());
    if (!authorization.hasRightsOnProjectOrSuperProjectsOrSubProjects(user, oldProject)) {
        throw new UserException("User has insufficient rights to download revisions from this project");
    }
    IfcModelSet ifcModelSet = new IfcModelSet();
    PackageMetaData lastMetaData = null;
    for (ConcreteRevision subRevision : oldRevision.getConcreteRevisions()) {
        PackageMetaData packageMetaData = bimServer.getMetaDataManager().getPackageMetaData(subRevision.getProject().getSchema());
        if (lastMetaData != null && lastMetaData != packageMetaData) {
            throw new UserException("Branching not possible for revision with multiple schemas");
        }
        IfcModel subModel = new BasicIfcModel(packageMetaData, null);
        getDatabaseSession().getMap(subModel, new OldQuery(packageMetaData, subRevision.getProject().getId(), subRevision.getId(), -1, Deep.NO));
        subModel.getModelMetaData().setDate(subRevision.getDate());
        ifcModelSet.add(subModel);
    }
    IfcModelInterface model = new BasicIfcModel(lastMetaData, null);
    try {
        model = bimServer.getMergerFactory().createMerger(getDatabaseSession(), authorization.getUoid()).merge(oldRevision.getProject(), ifcModelSet, new ModelHelper(bimServer.getMetaDataManager(), model));
    } catch (MergeException e) {
        throw new UserException(e);
    }
    model.resetOids();
    final Project newProject = new AddProjectDatabaseAction(bimServer, getDatabaseSession(), getAccessMethod(), projectName, "ifc2x3tc1", authorization).execute();
    CheckinDatabaseAction createCheckinAction = new CheckinDatabaseAction(bimServer, getDatabaseSession(), getAccessMethod(), newProject.getOid(), authorization, model, comment, comment, false, -1);
    return createCheckinAction.execute();
}
Also used : User(org.bimserver.models.store.User) ModelHelper(org.bimserver.plugins.ModelHelper) PackageMetaData(org.bimserver.emf.PackageMetaData) IfcModelInterface(org.bimserver.emf.IfcModelInterface) BasicIfcModel(org.bimserver.ifc.BasicIfcModel) OldQuery(org.bimserver.database.OldQuery) Project(org.bimserver.models.store.Project) IfcModel(org.bimserver.ifc.IfcModel) BasicIfcModel(org.bimserver.ifc.BasicIfcModel) Revision(org.bimserver.models.store.Revision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) MergeException(org.bimserver.plugins.modelmerger.MergeException) IfcModelSet(org.bimserver.plugins.IfcModelSet) UserException(org.bimserver.shared.exceptions.UserException)

Aggregations

ConcreteRevision (org.bimserver.models.store.ConcreteRevision)22 Revision (org.bimserver.models.store.Revision)19 UserException (org.bimserver.shared.exceptions.UserException)18 PackageMetaData (org.bimserver.emf.PackageMetaData)11 OldQuery (org.bimserver.database.OldQuery)10 IfcModelInterface (org.bimserver.emf.IfcModelInterface)10 Project (org.bimserver.models.store.Project)10 User (org.bimserver.models.store.User)9 IfcModelSet (org.bimserver.plugins.IfcModelSet)8 ModelHelper (org.bimserver.plugins.ModelHelper)8 MergeException (org.bimserver.plugins.modelmerger.MergeException)8 HashMap (java.util.HashMap)7 IfcModel (org.bimserver.ifc.IfcModel)7 Date (java.util.Date)6 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)6 GeometryGeneratingException (org.bimserver.GeometryGeneratingException)5 IdEObject (org.bimserver.emf.IdEObject)5 BasicIfcModel (org.bimserver.ifc.BasicIfcModel)5 AtomicLong (java.util.concurrent.atomic.AtomicLong)4 GenerateGeometryResult (org.bimserver.GenerateGeometryResult)4