Search in sources :

Example 31 with Revision

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

the class CompareDatabaseAction method getModelCompare.

public org.bimserver.plugins.modelcompare.ModelCompare getModelCompare() throws ModelCompareException, BimserverDatabaseException {
    Revision revision1 = getDatabaseSession().get(roid1, OldQuery.getDefault());
    Revision revision2 = getDatabaseSession().get(roid2, OldQuery.getDefault());
    PackageMetaData packageMetaData = bimServer.getMetaDataManager().getPackageMetaData(revision1.getProject().getSchema());
    if (revision1.getProject().getSchema().equals(revision2.getProject().getSchema())) {
        ModelComparePluginConfiguration modelCompareObject = getDatabaseSession().get(StorePackage.eINSTANCE.getModelComparePluginConfiguration(), mcid, OldQuery.getDefault());
        if (modelCompareObject != null) {
            ModelComparePlugin modelComparePlugin = bimServer.getPluginManager().getModelComparePlugin(modelCompareObject.getPluginDescriptor().getPluginClassName(), true);
            if (modelComparePlugin != null) {
                org.bimserver.plugins.modelcompare.ModelCompare modelCompare = modelComparePlugin.createModelCompare(new PluginConfiguration(modelCompareObject.getSettings()), packageMetaData);
                return modelCompare;
            } else {
                throw new ModelCompareException("No Model Compare found " + modelCompareObject.getPluginDescriptor().getPluginClassName());
            }
        } else {
            throw new ModelCompareException("No configured Model Compare found");
        }
    } else {
        throw new ModelCompareException("Not the same schema");
    }
}
Also used : ModelComparePlugin(org.bimserver.plugins.modelcompare.ModelComparePlugin) Revision(org.bimserver.models.store.Revision) PackageMetaData(org.bimserver.emf.PackageMetaData) ModelComparePluginConfiguration(org.bimserver.models.store.ModelComparePluginConfiguration) ModelComparePluginConfiguration(org.bimserver.models.store.ModelComparePluginConfiguration) PluginConfiguration(org.bimserver.plugins.PluginConfiguration) ModelCompareException(org.bimserver.plugins.modelcompare.ModelCompareException)

Example 32 with Revision

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

the class DownloadQueryDatabaseAction method execute.

@Override
public IfcModelInterface execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException, ServerException {
    DatabaseSession session = getBimServer().getDatabase().createSession();
    try {
        SerializerPluginConfiguration serializerPluginConfiguration = getDatabaseSession().get(StorePackage.eINSTANCE.getSerializerPluginConfiguration(), serializerOid, OldQuery.getDefault());
        BimDatabaseAction<IfcModelInterface> action = new DownloadDatabaseAction(getBimServer(), session, AccessMethod.INTERNAL, roid, -1, serializerPluginConfiguration.getOid(), getAuthorization(), null);
        IfcModelInterface ifcModel = session.executeAndCommitAction(action);
        QueryEnginePluginConfiguration queryEngineObject = session.get(StorePackage.eINSTANCE.getQueryEnginePluginConfiguration(), qeid, OldQuery.getDefault());
        Revision revision = session.get(roid, OldQuery.getDefault());
        PackageMetaData packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData(revision.getProject().getSchema());
        if (objectIDM == null) {
            objectIDM = new HideAllInversesObjectIDM(CollectionUtils.singleSet(Ifc2x3tc1Package.eINSTANCE), packageMetaData);
        }
        if (queryEngineObject != null) {
            QueryEnginePlugin queryEnginePlugin = getBimServer().getPluginManager().getQueryEngine(queryEngineObject.getPluginDescriptor().getPluginClassName(), true);
            if (queryEnginePlugin != null) {
                QueryEngine queryEngine = queryEnginePlugin.getQueryEngine(new PluginConfiguration(queryEngineObject.getSettings()));
                final IfcModelInterface result = new ServerIfcModel(packageMetaData, null, getDatabaseSession());
                ModelHelper modelHelper = new ModelHelper(getBimServer().getMetaDataManager(), objectIDM, result);
                modelHelper.setOidProvider(new OidProvider() {

                    private long oid = 1000000;

                    @Override
                    public long newOid(EClass eClass) {
                        return oid++;
                    }
                });
                IfcModelInterface finalResult = queryEngine.query(ifcModel, code, new Reporter() {

                    @Override
                    public void error(Throwable error) {
                    }

                    @Override
                    public void warning(String warning) {
                    }

                    @Override
                    public void info(String info) {
                    }
                }, modelHelper);
                return finalResult;
            } else {
                throw new UserException("No Query Engine found " + queryEngineObject.getPluginDescriptor().getPluginClassName());
            }
        } else {
            throw new UserException("No configured query engine found with qeid " + qeid);
        }
    } catch (BimserverDatabaseException e) {
        throw new UserException(e);
    } catch (QueryEngineException e) {
        throw new UserException(e);
    } catch (PluginException e) {
        throw new UserException(e);
    } finally {
        session.close();
    }
}
Also used : ServerIfcModel(org.bimserver.ServerIfcModel) DatabaseSession(org.bimserver.database.DatabaseSession) IfcModelInterface(org.bimserver.emf.IfcModelInterface) QueryEngine(org.bimserver.plugins.queryengine.QueryEngine) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) EClass(org.eclipse.emf.ecore.EClass) OidProvider(org.bimserver.emf.OidProvider) QueryEngineException(org.bimserver.plugins.queryengine.QueryEngineException) SerializerPluginConfiguration(org.bimserver.models.store.SerializerPluginConfiguration) QueryEnginePluginConfiguration(org.bimserver.models.store.QueryEnginePluginConfiguration) PluginConfiguration(org.bimserver.plugins.PluginConfiguration) UserException(org.bimserver.shared.exceptions.UserException) QueryEnginePluginConfiguration(org.bimserver.models.store.QueryEnginePluginConfiguration) ModelHelper(org.bimserver.plugins.ModelHelper) PackageMetaData(org.bimserver.emf.PackageMetaData) Reporter(org.bimserver.plugins.Reporter) PluginException(org.bimserver.shared.exceptions.PluginException) QueryEnginePlugin(org.bimserver.plugins.queryengine.QueryEnginePlugin) Revision(org.bimserver.models.store.Revision) HideAllInversesObjectIDM(org.bimserver.plugins.objectidms.HideAllInversesObjectIDM) SerializerPluginConfiguration(org.bimserver.models.store.SerializerPluginConfiguration)

Example 33 with Revision

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

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

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

the class GetAllCheckoutsOfRevisionDatabaseAction method execute.

@Override
public List<Checkout> execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    Revision revision = getRevisionByRoid(roid);
    Condition condition = new HasReferenceToCondition(StorePackage.eINSTANCE.getCheckout_Revision(), revision);
    return CollectionUtils.mapToList(getDatabaseSession().query(condition, Checkout.class, OldQuery.getDefault()));
}
Also used : Condition(org.bimserver.database.query.conditions.Condition) HasReferenceToCondition(org.bimserver.database.query.conditions.HasReferenceToCondition) Checkout(org.bimserver.models.store.Checkout) Revision(org.bimserver.models.store.Revision) HasReferenceToCondition(org.bimserver.database.query.conditions.HasReferenceToCondition)

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