Search in sources :

Example 6 with OldQuery

use of org.bimserver.database.OldQuery in project BIMserver by opensourceBIM.

the class BranchToExistingProjectDatabaseAction method execute.

@Override
public ConcreteRevision execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    Revision oldRevision = getDatabaseSession().get(StorePackage.eINSTANCE.getRevision(), roid, OldQuery.getDefault());
    Project oldProject = oldRevision.getProject();
    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());
        IfcModel subModel = new BasicIfcModel(packageMetaData, null);
        getDatabaseSession().getMap(subModel, new OldQuery(packageMetaData, subRevision.getProject().getId(), subRevision.getId(), -1, Deep.YES));
        subModel.getModelMetaData().setDate(subRevision.getDate());
        ifcModelSet.add(subModel);
        lastMetaData = packageMetaData;
    }
    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();
    // TODO
    CheckinDatabaseAction checkinDatabaseAction = new CheckinDatabaseAction(bimServer, getDatabaseSession(), getAccessMethod(), destPoid, authorization, model, comment, comment, false, -1, -1);
    return checkinDatabaseAction.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 7 with OldQuery

use of org.bimserver.database.OldQuery in project BIMserver by opensourceBIM.

the class DownloadDatabaseAction method execute.

@Override
public IfcModelInterface execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException, ServerException {
    Revision revision = getRevisionByRoid(roid);
    PluginConfiguration serializerPluginConfiguration = getDatabaseSession().get(StorePackage.eINSTANCE.getPluginConfiguration(), serializerOid, OldQuery.getDefault());
    getAuthorization().canDownload(roid);
    if (revision == null) {
        throw new UserException("Revision with oid " + roid + " not found");
    }
    Project project = revision.getProject();
    User user = getUserByUoid(getAuthorization().getUoid());
    try {
        getAuthorization().canDownload(roid);
    } catch (UserException e) {
        if (!getAuthorization().hasRightsOnProjectOrSuperProjectsOrSubProjects(user, project)) {
            throw new UserException("User has insufficient rights to download revisions from this project");
        }
    }
    IfcModelSet ifcModelSet = new IfcModelSet();
    long incrSize = 0;
    EList<ConcreteRevision> concreteRevisions = revision.getConcreteRevisions();
    if (concreteRevisions.size() == 0) {
        throw new ServerException("No concrete revisions in revision");
    }
    for (ConcreteRevision subRevision : concreteRevisions) {
        incrSize += subRevision.getSize();
    }
    final long totalSize = incrSize;
    final AtomicLong total = new AtomicLong();
    IfcHeader ifcHeader = null;
    PackageMetaData lastPackageMetaData = null;
    Map<Integer, Long> pidRoidMap = new HashMap<>();
    pidRoidMap.put(project.getId(), roid);
    for (ConcreteRevision concreteRevision : concreteRevisions) {
        if (concreteRevision.getUser().getOid() != ignoreUoid) {
            PackageMetaData packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData(concreteRevision.getProject().getSchema());
            lastPackageMetaData = packageMetaData;
            IfcModel subModel = getDatabaseSession().createServerModel(packageMetaData, pidRoidMap);
            ifcHeader = concreteRevision.getIfcHeader();
            int highestStopId = findHighestStopRid(project, concreteRevision);
            OldQuery query = new OldQuery(packageMetaData, concreteRevision.getProject().getId(), concreteRevision.getId(), concreteRevision.getOid(), Deep.YES, highestStopId);
            subModel.addChangeListener(new IfcModelChangeListener() {

                @Override
                public void objectAdded(IdEObject idEObject) {
                    total.incrementAndGet();
                    if (totalSize == 0) {
                        setProgress("Preparing download...", 0);
                    } else {
                        setProgress("Preparing download...", (int) Math.round(100.0 * total.get() / totalSize));
                    }
                }
            });
            query.updateOidCounters(concreteRevision, getDatabaseSession());
            getDatabaseSession().getMap(subModel, query);
            if (serializerPluginConfiguration != null) {
                try {
                    checkGeometry(serializerPluginConfiguration, getBimServer().getPluginManager(), subModel, project, concreteRevision, revision);
                } catch (GeometryGeneratingException e) {
                    throw new UserException(e);
                }
            }
            subModel.getModelMetaData().setDate(concreteRevision.getDate());
            ifcModelSet.add(subModel);
        }
    }
    IfcModelInterface ifcModel = getDatabaseSession().createServerModel(lastPackageMetaData, pidRoidMap);
    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();
    }
    if (ifcHeader != null) {
        ifcHeader.load();
        ifcModel.getModelMetaData().setIfcHeader(ifcHeader);
    }
    ifcModel.getModelMetaData().setName(project.getName() + "." + revision.getId());
    ifcModel.getModelMetaData().setRevisionId(project.getRevisions().indexOf(revision) + 1);
    if (user != null) {
        ifcModel.getModelMetaData().setAuthorizedUser(user.getName());
    }
    ifcModel.getModelMetaData().setDate(revision.getDate());
    if (revision.getProject().getGeoTag() != null) {
    // ifcModel.setLon(revision.getProject().getGeoTag().getX());
    // ifcModel.setLat(revision.getProject().getGeoTag().getY());
    // ifcModel.setAltitude((int)
    // revision.getProject().getGeoTag().getZ());
    // ifcModel.setDirectionAngle(revision.getProject().getGeoTag().getDirectionAngle());
    // try {
    // CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:" +
    // revision.getProject().getGeoTag().getEpsg());
    // CoordinateReferenceSystem targetCRS =
    // DefaultGeocentricCRS.CARTESIAN;
    // MathTransform transform = CRS.findMathTransform(sourceCRS,
    // targetCRS, true);
    // float[] in = new
    // float[]{revision.getProject().getGeoTag().getX1(),
    // revision.getProject().getGeoTag().getY1(),
    // revision.getProject().getGeoTag().getZ1()};
    // float[] result = new float[3];
    // transform.transform(in, 0, result, 0, 1);
    // IfcModel.setLon(result[0]);
    // IfcModel.setLat(result[1]);
    // } catch (NoSuchAuthorityCodeException e) {
    // LOGGER.error("", e);
    // } catch (FactoryException e) {
    // LOGGER.error("", e);
    // } catch (MismatchedDimensionException e) {
    // LOGGER.error("", e);
    // } catch (TransformException e) {
    // LOGGER.error("", e);
    // }
    }
    return ifcModel;
}
Also used : User(org.bimserver.models.store.User) HashMap(java.util.HashMap) IfcModelInterface(org.bimserver.emf.IfcModelInterface) IfcModelChangeListener(org.bimserver.ifc.IfcModelChangeListener) GeometryGeneratingException(org.bimserver.GeometryGeneratingException) IfcModel(org.bimserver.ifc.IfcModel) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) MergeException(org.bimserver.plugins.modelmerger.MergeException) PluginConfiguration(org.bimserver.models.store.PluginConfiguration) UserException(org.bimserver.shared.exceptions.UserException) ServerException(org.bimserver.shared.exceptions.ServerException) ModelHelper(org.bimserver.plugins.ModelHelper) IdEObject(org.bimserver.emf.IdEObject) PackageMetaData(org.bimserver.emf.PackageMetaData) IfcHeader(org.bimserver.models.store.IfcHeader) OldQuery(org.bimserver.database.OldQuery) Project(org.bimserver.models.store.Project) AtomicLong(java.util.concurrent.atomic.AtomicLong) Revision(org.bimserver.models.store.Revision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) AtomicLong(java.util.concurrent.atomic.AtomicLong) IfcModelSet(org.bimserver.plugins.IfcModelSet)

Example 8 with OldQuery

use of org.bimserver.database.OldQuery in project BIMserver by opensourceBIM.

the class LowLevelServiceImpl method getAttribute.

private Object getAttribute(Long tid, Long oid, String attributeName) throws ServerException, UserException {
    requireAuthenticationAndRunningServer();
    DatabaseSession session = getBimServer().getDatabase().createSession(OperationType.READ_ONLY);
    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(), Deep.NO));
        if (object == null) {
            throw new UserException("No object of type " + eClass.getName() + " with oid " + oid + " found");
        }
        EStructuralFeature eStructuralFeature = object.eClass().getEStructuralFeature(attributeName);
        if (eStructuralFeature == null) {
            throw new UserException(eClass.getName() + " does not have a field called " + attributeName);
        }
        Object eGet = object.eGet(eStructuralFeature);
        if (eGet instanceof IdEObject) {
            IdEObject refObject = (IdEObject) eGet;
            return refObject.eGet(refObject.eClass().getEStructuralFeature("wrappedValue"));
        }
        return eGet;
    } 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) IdEObject(org.bimserver.emf.IdEObject) SDataObject(org.bimserver.interfaces.objects.SDataObject) DataObject(org.bimserver.models.store.DataObject) 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 9 with OldQuery

use of org.bimserver.database.OldQuery in project BIMserver by opensourceBIM.

the class LowLevelServiceImpl method getAttributeAtIndex.

private Object getAttributeAtIndex(Long tid, Long oid, String attributeName, int index) throws ServerException, UserException {
    requireAuthenticationAndRunningServer();
    DatabaseSession session = getBimServer().getDatabase().createSession(OperationType.READ_ONLY);
    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(), Deep.NO));
        if (object == null) {
            throw new UserException("No object of type " + eClass.getName() + " with oid " + oid + " found");
        }
        Object eGet = object.eGet(object.eClass().getEStructuralFeature(attributeName));
        if (eGet instanceof List) {
            List<?> list = (List<?>) eGet;
            return list.get(index);
        }
        return eGet;
    } 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) IdEObject(org.bimserver.emf.IdEObject) SDataObject(org.bimserver.interfaces.objects.SDataObject) DataObject(org.bimserver.models.store.DataObject) 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 10 with OldQuery

use of org.bimserver.database.OldQuery in project BIMserver by opensourceBIM.

the class AdminServiceImpl method regenerateGeometry.

@Override
public void regenerateGeometry(Long croid) throws ServerException, UserException {
    LOGGER.info("Regenerating geometry for concrete revision" + croid);
    DatabaseSession session = getBimServer().getDatabase().createSession(OperationType.POSSIBLY_WRITE);
    try {
        // Normally we wouldn't be allowed to change existing data
        session.setOverwriteEnabled(true);
        ConcreteRevision concreteRevision = session.get(StorePackage.eINSTANCE.getConcreteRevision(), croid, OldQuery.getDefault());
        PackageMetaData packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData(concreteRevision.getProject().getSchema());
        IfcModelInterface model = new BasicIfcModel(packageMetaData, null);
        session.getMap(model, new OldQuery(packageMetaData, concreteRevision.getProject().getId(), concreteRevision.getId(), -1));
        User user = session.get(getAuthorization().getUoid(), OldQuery.getDefault());
        UserSettings userSettings = user.getUserSettings();
        RenderEnginePluginConfiguration defaultRenderEngine = userSettings.getDefaultRenderEngine();
        if (defaultRenderEngine == null) {
            throw new BimBotsException("No default render engine has been selected for this user", BimBotDefaultErrorCode.NO_RENDER_ENGINE);
        }
        RenderEnginePool pool = getBimServer().getRenderEnginePools().getRenderEnginePool(model.getPackageMetaData().getSchema(), defaultRenderEngine.getPluginDescriptor().getPluginClassName(), getBimServer().getPluginSettingsCache().getPluginSettings(defaultRenderEngine.getOid()));
        new GeometryGenerator(getBimServer()).generateGeometry(pool, getBimServer().getPluginManager(), session, model, concreteRevision.getProject().getId(), concreteRevision.getId(), true, null);
        session.commit();
    } catch (Exception e) {
        handleException(e);
    } finally {
        session.close();
    }
}
Also used : User(org.bimserver.models.store.User) RenderEnginePool(org.bimserver.renderengine.RenderEnginePool) DatabaseSession(org.bimserver.database.DatabaseSession) PackageMetaData(org.bimserver.emf.PackageMetaData) IfcModelInterface(org.bimserver.emf.IfcModelInterface) UserSettings(org.bimserver.models.store.UserSettings) GeometryGenerator(org.bimserver.GeometryGenerator) BimBotsException(org.bimserver.bimbots.BimBotsException) BasicIfcModel(org.bimserver.ifc.BasicIfcModel) UserException(org.bimserver.shared.exceptions.UserException) BimBotsException(org.bimserver.bimbots.BimBotsException) IOException(java.io.IOException) ServerException(org.bimserver.shared.exceptions.ServerException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) OldQuery(org.bimserver.database.OldQuery) RenderEnginePluginConfiguration(org.bimserver.models.store.RenderEnginePluginConfiguration) ConcreteRevision(org.bimserver.models.store.ConcreteRevision)

Aggregations

OldQuery (org.bimserver.database.OldQuery)21 UserException (org.bimserver.shared.exceptions.UserException)17 PackageMetaData (org.bimserver.emf.PackageMetaData)14 Revision (org.bimserver.models.store.Revision)14 IfcModelInterface (org.bimserver.emf.IfcModelInterface)12 IdEObject (org.bimserver.emf.IdEObject)10 ConcreteRevision (org.bimserver.models.store.ConcreteRevision)10 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)9 Project (org.bimserver.models.store.Project)9 IfcModelSet (org.bimserver.plugins.IfcModelSet)9 ModelHelper (org.bimserver.plugins.ModelHelper)9 MergeException (org.bimserver.plugins.modelmerger.MergeException)9 DatabaseSession (org.bimserver.database.DatabaseSession)8 ServerException (org.bimserver.shared.exceptions.ServerException)8 IfcModel (org.bimserver.ifc.IfcModel)7 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 BasicIfcModel (org.bimserver.ifc.BasicIfcModel)6 User (org.bimserver.models.store.User)6 EClass (org.eclipse.emf.ecore.EClass)6