Search in sources :

Example 11 with ConcreteRevision

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

the class CheckoutDatabaseAction method realCheckout.

private IfcModel realCheckout(Project project, Revision revision, DatabaseSession databaseSession, User user) throws BimserverLockConflictException, BimserverDatabaseException, UserException {
    PluginConfiguration serializerPluginConfiguration = getDatabaseSession().get(StorePackage.eINSTANCE.getPluginConfiguration(), serializerOid, OldQuery.getDefault());
    final long totalSize = revision.getSize();
    final AtomicLong total = new AtomicLong();
    IfcModelSet ifcModelSet = new IfcModelSet();
    PackageMetaData lastPackageMetaData = null;
    for (ConcreteRevision subRevision : revision.getConcreteRevisions()) {
        PackageMetaData packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData(subRevision.getProject().getSchema());
        lastPackageMetaData = packageMetaData;
        IfcModel subModel = new BasicIfcModel(packageMetaData, null);
        int highestStopId = findHighestStopRid(project, subRevision);
        OldQuery query = new OldQuery(packageMetaData, subRevision.getProject().getId(), subRevision.getId(), revision.getOid(), null, Deep.YES, highestStopId);
        subModel.addChangeListener(new IfcModelChangeListener() {

            @Override
            public void objectAdded(IdEObject idEObject) {
                total.incrementAndGet();
                if (totalSize == 0) {
                    setProgress("Preparing checkout...", 0);
                } else {
                    setProgress("Preparing checkout...", (int) Math.round(100.0 * total.get() / totalSize));
                }
            }
        });
        getDatabaseSession().getMap(subModel, query);
        try {
            checkGeometry(serializerPluginConfiguration, getBimServer().getPluginManager(), subModel, project, subRevision, revision);
        } catch (GeometryGeneratingException e) {
            throw new UserException(e);
        }
        subModel.getModelMetaData().setDate(subRevision.getDate());
        ifcModelSet.add(subModel);
    }
    IfcModelInterface ifcModel = new BasicIfcModel(lastPackageMetaData, null);
    if (ifcModelSet.size() > 1) {
        try {
            ifcModel = getBimServer().getMergerFactory().createMerger(getDatabaseSession(), getAuthorization().getUoid()).merge(revision.getProject(), ifcModelSet, new ModelHelper(getBimServer().getMetaDataManager(), ifcModel));
        } catch (MergeException e) {
            throw new UserException(e);
        }
    } else {
        ifcModel = ifcModelSet.iterator().next();
    }
    ifcModel.getModelMetaData().setName(project.getName() + "." + revision.getId());
    ifcModel.getModelMetaData().setRevisionId(project.getRevisions().indexOf(revision) + 1);
    ifcModel.getModelMetaData().setAuthorizedUser(user.getName());
    ifcModel.getModelMetaData().setDate(new Date());
    return (IfcModel) ifcModel;
}
Also used : ModelHelper(org.bimserver.plugins.ModelHelper) IdEObject(org.bimserver.emf.IdEObject) PackageMetaData(org.bimserver.emf.PackageMetaData) IfcModelInterface(org.bimserver.emf.IfcModelInterface) IfcModelChangeListener(org.bimserver.ifc.IfcModelChangeListener) GeometryGeneratingException(org.bimserver.GeometryGeneratingException) BasicIfcModel(org.bimserver.ifc.BasicIfcModel) Date(java.util.Date) OldQuery(org.bimserver.database.OldQuery) BasicIfcModel(org.bimserver.ifc.BasicIfcModel) IfcModel(org.bimserver.ifc.IfcModel) AtomicLong(java.util.concurrent.atomic.AtomicLong) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) MergeException(org.bimserver.plugins.modelmerger.MergeException) PluginConfiguration(org.bimserver.models.store.PluginConfiguration) IfcModelSet(org.bimserver.plugins.IfcModelSet) UserException(org.bimserver.shared.exceptions.UserException)

Example 12 with ConcreteRevision

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

Example 13 with ConcreteRevision

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

the class GenericCheckinDatabaseAction method createNewVirtualRevision.

private Revision createNewVirtualRevision(DatabaseSession session, Project project, ConcreteRevision concreteRevision, String comment, Date date, User user, long size) throws BimserverLockConflictException, BimserverDatabaseException {
    Revision revision = session.create(Revision.class);
    revision.setLastConcreteRevision(concreteRevision);
    revision.setComment(comment);
    revision.setDate(date);
    revision.setUser(user);
    user.getRevisions().add(revision);
    revision.setSize(size);
    revision.setId(project.getRevisions().size() + 1);
    revision.getConcreteRevisions().add(concreteRevision);
    revision.setProject(project);
    return revision;
}
Also used : Revision(org.bimserver.models.store.Revision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision)

Example 14 with ConcreteRevision

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

the class GenericCheckinDatabaseAction method createNewConcreteRevision.

public CreateRevisionResult createNewConcreteRevision(DatabaseSession session, long size, Project project, User user, String comment) throws BimserverDatabaseException, BimserverLockConflictException {
    CreateRevisionResult result = new CreateRevisionResult();
    ConcreteRevision concreteRevision = getDatabaseSession().create(ConcreteRevision.class);
    concreteRevision.setSize(size);
    Date date = new Date();
    concreteRevision.setDate(date);
    concreteRevision.setId(project.getConcreteRevisions().size() + 1);
    concreteRevision.setUser(user);
    concreteRevision.setProject(project);
    project.setLastConcreteRevision(concreteRevision);
    Revision newRevision = createNewVirtualRevision(session, project, concreteRevision, comment, date, user, size);
    for (Checkout checkout : project.getCheckouts()) {
        if (checkout.getUser() == user) {
            checkout.setActive(false);
            session.store(checkout);
        }
    }
    project.setLastRevision(newRevision);
    Project parent = project.getParent();
    result.addRevision(newRevision);
    while (parent != null) {
        Revision revision = getDatabaseSession().create(Revision.class);
        result.addRevision(revision);
        revision.setComment("generated for subproject " + project.getName() + ", revision " + concreteRevision.getId() + ", by " + user.getName());
        revision.setDate(date);
        revision.setUser(getSystemUser());
        revision.setProject(parent);
        if (parent.getLastRevision() != null) {
            Revision lastRevision = parent.getLastRevision();
            for (ConcreteRevision oldRevision : lastRevision.getConcreteRevisions()) {
                if (oldRevision.getProject() != project && oldRevision.getProject() != parent) {
                    revision.getConcreteRevisions().add(oldRevision);
                    revision.setSize((revision.getSize() == null ? 0 : revision.getSize()) + oldRevision.getSize());
                    session.store(revision);
                    session.store(oldRevision);
                }
            }
        }
        revision.getConcreteRevisions().add(concreteRevision);
        revision.setSize((revision.getSize() == null ? 0 : revision.getSize()) + concreteRevision.getSize());
        revision.setLastConcreteRevision(concreteRevision);
        if (parent.getLastRevision() == null) {
            revision.setId(1);
        } else {
            revision.setId(parent.getLastRevision().getId() + 1);
        }
        parent.setLastRevision(revision);
        session.store(revision);
        session.store(parent);
        parent = parent.getParent();
    }
    session.store(project);
    session.store(user);
    session.store(concreteRevision);
    result.setConcreteRevision(concreteRevision);
    return result;
}
Also used : Project(org.bimserver.models.store.Project) Checkout(org.bimserver.models.store.Checkout) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) Revision(org.bimserver.models.store.Revision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) Date(java.util.Date)

Example 15 with ConcreteRevision

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

the class GetDataObjectByOidDatabaseAction method execute.

@Override
public DataObject execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    Revision virtualRevision = getRevisionByRoid(roid);
    EObject eObject = null;
    IfcModelSet ifcModelSet = new IfcModelSet();
    PackageMetaData lastPackageMetaData = null;
    Map<Integer, Long> pidRoidMap = new HashMap<>();
    pidRoidMap.put(virtualRevision.getProject().getId(), virtualRevision.getOid());
    for (ConcreteRevision concreteRevision : virtualRevision.getConcreteRevisions()) {
        PackageMetaData packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData(concreteRevision.getProject().getSchema());
        lastPackageMetaData = packageMetaData;
        IfcModel subModel = new BasicIfcModel(packageMetaData, pidRoidMap);
        int highestStopId = findHighestStopRid(concreteRevision.getProject(), concreteRevision);
        OldQuery query = new OldQuery(packageMetaData, concreteRevision.getProject().getId(), concreteRevision.getId(), virtualRevision.getOid(), null, Deep.NO, highestStopId);
        eObject = getDatabaseSession().get(null, oid, subModel, query);
        subModel.getModelMetaData().setDate(concreteRevision.getDate());
        ifcModelSet.add(subModel);
        if (eObject != null) {
            break;
        }
    }
    IfcModelInterface ifcModel = new BasicIfcModel(lastPackageMetaData, pidRoidMap);
    if (ifcModelSet.size() > 1) {
        try {
            ifcModel = getBimServer().getMergerFactory().createMerger(getDatabaseSession(), getAuthorization().getUoid()).merge(virtualRevision.getProject(), ifcModelSet, new ModelHelper(getBimServer().getMetaDataManager(), ifcModel));
        } catch (MergeException e) {
            throw new UserException(e);
        }
    } else {
        ifcModel = ifcModelSet.iterator().next();
    }
    if (eObject == null) {
        throw new UserException("Object not found in this project/revision");
    }
    DataObject dataObject = null;
    if (eObject instanceof IfcRoot) {
        IfcRoot ifcRoot = (IfcRoot) eObject;
        String guid = ifcRoot.getGlobalId() != null ? ifcRoot.getGlobalId() : "";
        String name = ifcRoot.getName() != null ? ifcRoot.getName() : "";
        dataObject = StoreFactory.eINSTANCE.createDataObject();
        dataObject.setType(eObject.eClass().getName());
        ((IdEObjectImpl) dataObject).setOid(oid);
        dataObject.setGuid(guid);
        dataObject.setName(name);
    } else {
        dataObject = StoreFactory.eINSTANCE.createDataObject();
        dataObject.setType(eObject.eClass().getName());
        ((IdEObjectImpl) dataObject).setOid(oid);
        dataObject.setName("");
        dataObject.setGuid("");
    }
    fillDataObject(ifcModel.getObjects(), eObject, dataObject);
    return dataObject;
}
Also used : IdEObjectImpl(org.bimserver.emf.IdEObjectImpl) ModelHelper(org.bimserver.plugins.ModelHelper) HashMap(java.util.HashMap) PackageMetaData(org.bimserver.emf.PackageMetaData) IfcModelInterface(org.bimserver.emf.IfcModelInterface) IfcRoot(org.bimserver.models.ifc2x3tc1.IfcRoot) BasicIfcModel(org.bimserver.ifc.BasicIfcModel) OldQuery(org.bimserver.database.OldQuery) BasicIfcModel(org.bimserver.ifc.BasicIfcModel) IfcModel(org.bimserver.ifc.IfcModel) DataObject(org.bimserver.models.store.DataObject) Revision(org.bimserver.models.store.Revision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) MergeException(org.bimserver.plugins.modelmerger.MergeException) IdEObject(org.bimserver.emf.IdEObject) EObject(org.eclipse.emf.ecore.EObject) 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