Search in sources :

Example 26 with Revision

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

the class NotificationRegistryServiceImpl method getProgressTopicsOnProject.

@Override
public List<Long> getProgressTopicsOnProject(Long poid) throws ServerException, UserException {
    DatabaseSession session = getBimServer().getDatabase().createSession();
    try {
        List<Long> list = new ArrayList<Long>();
        Project project = session.get(StorePackage.eINSTANCE.getProject(), poid, OldQuery.getDefault());
        List<Long> revisionOids = new ArrayList<Long>();
        for (Revision revision : project.getRevisions()) {
            revisionOids.add(revision.getOid());
        }
        Set<ProgressTopic> progressOnProjectTopics = getBimServer().getNotificationsManager().getProgressOnProjectTopics(poid, revisionOids);
        if (progressOnProjectTopics != null) {
            for (ProgressTopic topic : progressOnProjectTopics) {
                list.add(topic.getKey().getId());
            }
        }
        return list;
    } catch (Exception e) {
        return handleException(e);
    } finally {
        session.close();
    }
}
Also used : Project(org.bimserver.models.store.Project) ProgressTopic(org.bimserver.notifications.ProgressTopic) Revision(org.bimserver.models.store.Revision) DatabaseSession(org.bimserver.database.DatabaseSession) ArrayList(java.util.ArrayList) TopicRegisterException(org.bimserver.notifications.TopicRegisterException) UserException(org.bimserver.shared.exceptions.UserException) ServerException(org.bimserver.shared.exceptions.ServerException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException)

Example 27 with Revision

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

the class AddExtendedDataToRevisionDatabaseAction method execute.

@Override
public Long execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    authorization.canWriteExtendedData(roid);
    User actingUser = getUserByUoid(authorization.getUoid());
    getIdEObject().setUser(actingUser);
    getIdEObject().setAdded(new Date());
    File file = getIdEObject().getFile();
    getIdEObject().setSize(file.getData().length);
    super.execute();
    Revision revision = getRevisionByRoid(roid);
    if (revision == null) {
        throw new UserException("Revision with roid " + roid + " not found");
    }
    revision.getExtendedData().add(getIdEObject());
    getDatabaseSession().store(revision);
    getIdEObject().setProject(revision.getProject());
    getIdEObject().setRevision(revision);
    if (getIdEObject().getSchema() != null) {
        getDatabaseSession().store(getIdEObject().getSchema());
    }
    final ExtendedDataAddedToRevision extendedDataAddedToRevision = getDatabaseSession().create(ExtendedDataAddedToRevision.class);
    extendedDataAddedToRevision.setAccessMethod(getAccessMethod());
    extendedDataAddedToRevision.setDate(new Date());
    extendedDataAddedToRevision.setExecutor(actingUser);
    extendedDataAddedToRevision.setExtendedData(getIdEObject());
    extendedDataAddedToRevision.setRevision(revision);
    final long poid = revision.getProject().getOid();
    final long roid = revision.getOid();
    getDatabaseSession().addPostCommitAction(new PostCommitAction() {

        @Override
        public void execute() throws UserException {
            bimServer.getNotificationsManager().notify(new NewExtendedDataOnRevisionNotification(bimServer, getIdEObject().getOid(), poid, roid, -1));
            bimServer.getNotificationsManager().notify(new SConverter().convertToSObject(extendedDataAddedToRevision));
        }
    });
    return null;
}
Also used : User(org.bimserver.models.store.User) ExtendedDataAddedToRevision(org.bimserver.models.log.ExtendedDataAddedToRevision) Revision(org.bimserver.models.store.Revision) SConverter(org.bimserver.interfaces.SConverter) PostCommitAction(org.bimserver.database.PostCommitAction) ExtendedDataAddedToRevision(org.bimserver.models.log.ExtendedDataAddedToRevision) UserException(org.bimserver.shared.exceptions.UserException) NewExtendedDataOnRevisionNotification(org.bimserver.notifications.NewExtendedDataOnRevisionNotification) File(org.bimserver.models.store.File) Date(java.util.Date)

Example 28 with Revision

use of org.bimserver.models.store.Revision 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)

Example 29 with Revision

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

the class CheckoutDatabaseAction method execute.

@Override
public IfcModel execute() throws UserException, BimserverDatabaseException, BimserverLockConflictException {
    DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm");
    User user = getUserByUoid(getAuthorization().getUoid());
    Revision revision = getRevisionByRoid(roid);
    Project project = revision.getProject();
    if (user.getHasRightsOn().contains(project)) {
        for (Checkout checkout : revision.getCheckouts()) {
            if (checkout.getRevision() == revision && checkout.getUser() == user && checkout.getActive()) {
                throw new UserException("This revision has already been checked out by you on " + dateFormat.format(checkout.getDate()));
            }
        }
        for (Checkout checkout : project.getCheckouts()) {
            if (checkout.getUser() == user && checkout.getActive()) {
                checkout.setActive(false);
                Checkout newCheckout = getDatabaseSession().create(Checkout.class);
                newCheckout.setActive(true);
                newCheckout.setDate(new Date());
                newCheckout.setUser(user);
                newCheckout.setProject(project);
                newCheckout.setRevision(revision);
                getDatabaseSession().store(checkout);
                getDatabaseSession().store(newCheckout);
                getDatabaseSession().store(project);
                return realCheckout(project, revision, getDatabaseSession(), user);
            }
        }
        Checkout checkout = getDatabaseSession().create(Checkout.class);
        checkout.setActive(true);
        checkout.setDate(new Date());
        checkout.setUser(user);
        checkout.setProject(project);
        checkout.setRevision(revision);
        getDatabaseSession().store(checkout);
        getDatabaseSession().store(project);
        return realCheckout(project, revision, getDatabaseSession(), user);
    } else {
        throw new UserException("Insufficient rights to checkout this project");
    }
}
Also used : Project(org.bimserver.models.store.Project) User(org.bimserver.models.store.User) Checkout(org.bimserver.models.store.Checkout) Revision(org.bimserver.models.store.Revision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) UserException(org.bimserver.shared.exceptions.UserException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 30 with Revision

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

the class CommitTransactionDatabaseAction method execute.

@Override
public ConcreteRevision execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    Project project = getProjectByPoid(longTransaction.getPoid());
    User user = getUserByUoid(authorization.getUoid());
    if (project == null) {
        throw new UserException("Project with poid " + longTransaction.getPoid() + " not found");
    }
    if (!authorization.hasRightsOnProjectOrSuperProjects(user, project)) {
        throw new UserException("User has no rights to checkin models to this project");
    }
    if (!MailSystem.isValidEmailAddress(user.getUsername())) {
        throw new UserException("Users must have a valid e-mail address to checkin");
    }
    long size = 0;
    Revision previousRevision = project.getLastRevision();
    if (project.getLastRevision() != null) {
        size += project.getLastRevision().getSize();
    // for (ConcreteRevision concreteRevision : project.getLastRevision().getConcreteRevisions()) {
    // size += concreteRevision.getSize();
    // }
    }
    for (Change change : longTransaction.getChanges()) {
        if (change instanceof CreateObjectChange) {
            size++;
        } else if (change instanceof RemoveObjectChange) {
            size--;
        }
    }
    Revision oldLastRevision = project.getLastRevision();
    CreateRevisionResult result = createNewConcreteRevision(getDatabaseSession(), size, project, user, comment.trim());
    ConcreteRevision concreteRevision = result.getConcreteRevision();
    revision = concreteRevision.getRevisions().get(0);
    project.setLastRevision(revision);
    final NewRevisionAdded newRevisionAdded = getDatabaseSession().create(NewRevisionAdded.class);
    newRevisionAdded.setDate(new Date());
    newRevisionAdded.setExecutor(user);
    newRevisionAdded.setRevision(concreteRevision.getRevisions().get(0));
    newRevisionAdded.setProject(project);
    newRevisionAdded.setAccessMethod(getAccessMethod());
    PackageMetaData packageMetaData = bimServer.getMetaDataManager().getPackageMetaData(project.getSchema());
    // IfcModelInterface ifcModel = new BasicIfcModel(packageMetaData, null);
    if (oldLastRevision != null) {
        int highestStopId = AbstractDownloadDatabaseAction.findHighestStopRid(project, oldLastRevision.getLastConcreteRevision());
        OldQuery query = new OldQuery(longTransaction.getPackageMetaData(), project.getId(), oldLastRevision.getId(), -1, null, Deep.YES, highestStopId);
        query.updateOidCounters(oldLastRevision.getLastConcreteRevision(), getDatabaseSession());
    // getDatabaseSession().getMap(ifcModel, query);
    }
    getDatabaseSession().addPostCommitAction(new PostCommitAction() {

        @Override
        public void execute() throws UserException {
            bimServer.getNotificationsManager().notify(new SConverter().convertToSObject(newRevisionAdded));
            try {
                bimServer.getLongTransactionManager().remove(longTransaction.getTid());
            } catch (NoTransactionException e) {
                LOGGER.error("", e);
            }
        }
    });
    SummaryMap summaryMap = null;
    if (oldLastRevision != null && oldLastRevision.getConcreteRevisions().size() == 1 && oldLastRevision.getConcreteRevisions().get(0).getSummary() != null) {
        summaryMap = new SummaryMap(packageMetaData, oldLastRevision.getConcreteRevisions().get(0).getSummary());
    } else {
        summaryMap = new SummaryMap(packageMetaData);
    }
    boolean geometryChanged = true;
    // TODO actually change this variable...
    // First create all new objects
    Transaction transaction = new Transaction(bimServer, previousRevision, project, concreteRevision, getDatabaseSession());
    for (Change change : longTransaction.getChanges()) {
        if (change instanceof CreateObjectChange) {
            try {
                change.execute(transaction);
            } catch (IOException | QueryException e) {
                e.printStackTrace();
            }
            summaryMap.add(((CreateObjectChange) change).geteClass(), 1);
        }
    }
    // Then do the rest
    for (Change change : longTransaction.getChanges()) {
        if (!(change instanceof CreateObjectChange)) {
            if (change instanceof RemoveObjectChange) {
                summaryMap.remove(((RemoveObjectChange) change).geteClass(), 1);
            }
            try {
                change.execute(transaction);
            } catch (IOException e) {
                e.printStackTrace();
            } catch (QueryException e) {
                e.printStackTrace();
            }
        }
    }
    for (HashMapVirtualObject object : transaction.getCreated()) {
        getDatabaseSession().save(object);
    }
    for (HashMapVirtualObject object : transaction.getUpdated()) {
        getDatabaseSession().save(object, concreteRevision.getId());
    }
    for (HashMapVirtualObject object : transaction.getDeleted()) {
        getDatabaseSession().delete(object, concreteRevision.getId());
    }
    if (bimServer.getServerSettingsCache().getServerSettings().isGenerateGeometryOnCheckin() && geometryChanged) {
        setProgress("Generating Geometry...", -1);
        try {
            GeometryGenerationReport report = new GeometryGenerationReport();
            report.setOriginalDeserializer("No deserializer, low level call");
            report.setOriginalIfcFileName("No file, low level call");
            report.setOriginalIfcFileSize(-1);
            StreamingGeometryGenerator streamingGeometryGenerator = new StreamingGeometryGenerator(bimServer, null, -1L, report);
            int highestStopId = AbstractDownloadDatabaseAction.findHighestStopRid(concreteRevision.getProject(), concreteRevision);
            QueryContext queryContext = new QueryContext(getDatabaseSession(), packageMetaData, project.getId(), concreteRevision.getId(), concreteRevision.getRevisions().get(0).getOid(), highestStopId);
            Map<EClass, Long> startOids = getDatabaseSession().getStartOids();
            if (startOids == null) {
                throw new BimserverDatabaseException("No objects changed");
            }
            Map<EClass, Long> oidCounters = new HashMap<>();
            // buffer.order(ByteOrder.LITTLE_ENDIAN);
            for (EClass eClass : packageMetaData.getEClasses()) {
                if (startOids.containsKey(eClass)) {
                    long oid = startOids.get(eClass);
                    if (!DatabaseSession.perRecordVersioning(eClass)) {
                        oidCounters.put(eClass, oid);
                    // buffer.putLong(oid);
                    }
                }
            }
            queryContext.setOidCounters(oidCounters);
            GenerateGeometryResult generateGeometry = streamingGeometryGenerator.generateGeometry(authorization.getUoid(), getDatabaseSession(), queryContext);
            concreteRevision.setMinBounds(generateGeometry.getMinBoundsAsVector3f());
            concreteRevision.setMaxBounds(generateGeometry.getMaxBoundsAsVector3f());
        } catch (GeometryGeneratingException e) {
            throw new UserException(e);
        }
        revision.setHasGeometry(true);
    }
    if (oldLastRevision != null) {
        concreteRevision.setOidCounters(oldLastRevision.getConcreteRevisions().get(0).getOidCounters());
    }
    concreteRevision.setSummary(summaryMap.toRevisionSummary(getDatabaseSession()));
    getDatabaseSession().store(concreteRevision);
    getDatabaseSession().store(project);
    return concreteRevision;
}
Also used : User(org.bimserver.models.store.User) HashMap(java.util.HashMap) RemoveObjectChange(org.bimserver.changes.RemoveObjectChange) GeometryGeneratingException(org.bimserver.GeometryGeneratingException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) GeometryGenerationReport(org.bimserver.geometry.GeometryGenerationReport) EClass(org.eclipse.emf.ecore.EClass) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) CreateObjectChange(org.bimserver.changes.CreateObjectChange) UserException(org.bimserver.shared.exceptions.UserException) NewRevisionAdded(org.bimserver.models.log.NewRevisionAdded) NoTransactionException(org.bimserver.webservices.NoTransactionException) SConverter(org.bimserver.interfaces.SConverter) PackageMetaData(org.bimserver.emf.PackageMetaData) PostCommitAction(org.bimserver.database.PostCommitAction) StreamingGeometryGenerator(org.bimserver.geometry.StreamingGeometryGenerator) RemoveObjectChange(org.bimserver.changes.RemoveObjectChange) CreateObjectChange(org.bimserver.changes.CreateObjectChange) Change(org.bimserver.changes.Change) IOException(java.io.IOException) QueryContext(org.bimserver.shared.QueryContext) Date(java.util.Date) OldQuery(org.bimserver.database.OldQuery) Project(org.bimserver.models.store.Project) QueryException(org.bimserver.database.queries.om.QueryException) Revision(org.bimserver.models.store.Revision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) SummaryMap(org.bimserver.SummaryMap) LongTransaction(org.bimserver.webservices.LongTransaction) Transaction(org.bimserver.changes.Transaction) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) GenerateGeometryResult(org.bimserver.GenerateGeometryResult)

Aggregations

Revision (org.bimserver.models.store.Revision)52 UserException (org.bimserver.shared.exceptions.UserException)39 Project (org.bimserver.models.store.Project)23 PackageMetaData (org.bimserver.emf.PackageMetaData)22 ConcreteRevision (org.bimserver.models.store.ConcreteRevision)20 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)18 OldQuery (org.bimserver.database.OldQuery)17 User (org.bimserver.models.store.User)16 DatabaseSession (org.bimserver.database.DatabaseSession)15 IfcModelInterface (org.bimserver.emf.IfcModelInterface)14 ServerException (org.bimserver.shared.exceptions.ServerException)14 IOException (java.io.IOException)12 Date (java.util.Date)11 ModelHelper (org.bimserver.plugins.ModelHelper)10 HashMap (java.util.HashMap)9 SRevision (org.bimserver.interfaces.objects.SRevision)9 IfcModelSet (org.bimserver.plugins.IfcModelSet)9 DeserializeException (org.bimserver.plugins.deserializers.DeserializeException)9 MergeException (org.bimserver.plugins.modelmerger.MergeException)9 SerializerException (org.bimserver.plugins.serializers.SerializerException)8