Search in sources :

Example 21 with Project

use of org.bimserver.models.store.Project 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 = new ServerIfcModel(packageMetaData, pidRoidMap, getDatabaseSession());
            ifcHeader = concreteRevision.getIfcHeader();
            int highestStopId = findHighestStopRid(project, concreteRevision);
            OldQuery query = new OldQuery(packageMetaData, concreteRevision.getProject().getId(), concreteRevision.getId(), concreteRevision.getOid(), objectIDM, 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 = new ServerIfcModel(lastPackageMetaData, pidRoidMap, getDatabaseSession());
    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) ServerIfcModel(org.bimserver.ServerIfcModel) HashMap(java.util.HashMap) IfcModelInterface(org.bimserver.emf.IfcModelInterface) IfcModelChangeListener(org.bimserver.ifc.IfcModelChangeListener) GeometryGeneratingException(org.bimserver.GeometryGeneratingException) ServerIfcModel(org.bimserver.ServerIfcModel) 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 22 with Project

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

the class DownloadProjectsDatabaseAction method execute.

@Override
public IfcModelInterface execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    User user = getUserByUoid(getAuthorization().getUoid());
    Project project = null;
    String projectName = "";
    IfcModelSet ifcModelSet = new IfcModelSet();
    long incrSize = 0;
    for (long roid : roids) {
        Revision revision = getRevisionByRoid(roid);
        for (ConcreteRevision subRevision : revision.getConcreteRevisions()) {
            incrSize += subRevision.getSize();
        }
    }
    final long totalSize = incrSize;
    final AtomicLong total = new AtomicLong();
    PluginConfiguration serializerPluginConfiguration = getDatabaseSession().get(StorePackage.eINSTANCE.getPluginConfiguration(), serializerOid, OldQuery.getDefault());
    PackageMetaData lastPackageMetaData = null;
    IfcHeader ifcHeader = null;
    Map<Integer, Long> pidRoidMap = new HashMap<>();
    for (long roid : roids) {
        Revision revision = getRevisionByRoid(roid);
        project = revision.getProject();
        pidRoidMap.put(project.getId(), roid);
        if (getAuthorization().hasRightsOnProjectOrSuperProjectsOrSubProjects(user, project)) {
            for (ConcreteRevision concreteRevision : revision.getConcreteRevisions()) {
                ifcHeader = concreteRevision.getIfcHeader();
                PackageMetaData packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData(concreteRevision.getProject().getSchema());
                lastPackageMetaData = packageMetaData;
                IfcModel subModel = new ServerIfcModel(packageMetaData, pidRoidMap, getDatabaseSession());
                int highestStopId = findHighestStopRid(project, concreteRevision);
                OldQuery query = new OldQuery(packageMetaData, concreteRevision.getProject().getId(), concreteRevision.getId(), revision.getOid(), objectIDM, 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);
                projectName += concreteRevision.getProject().getName() + "-";
                subModel.getModelMetaData().setDate(concreteRevision.getDate());
                try {
                    checkGeometry(serializerPluginConfiguration, getBimServer().getPluginManager(), subModel, project, concreteRevision, revision);
                } catch (GeometryGeneratingException e) {
                    throw new UserException(e);
                }
                ifcModelSet.add(subModel);
            }
        } else {
            throw new UserException("User has no rights on project " + project.getOid());
        }
    }
    IfcModelInterface ifcModel = new ServerIfcModel(lastPackageMetaData, pidRoidMap, getDatabaseSession());
    if (ifcModelSet.size() == 1) {
        ifcModel = ifcModelSet.iterator().next();
    } else {
        try {
            ifcModel = getBimServer().getMergerFactory().createMerger(getDatabaseSession(), getAuthorization().getUoid()).merge(project, ifcModelSet, new ModelHelper(getBimServer().getMetaDataManager(), ifcModel));
        } catch (MergeException e) {
            throw new UserException(e);
        }
    }
    if (ifcHeader != null) {
        ifcHeader.load();
        ifcModel.getModelMetaData().setIfcHeader(ifcHeader);
    }
    if (projectName.endsWith("-")) {
        projectName = projectName.substring(0, projectName.length() - 1);
    }
    ifcModel.getModelMetaData().setName(projectName);
    return ifcModel;
}
Also used : User(org.bimserver.models.store.User) ServerIfcModel(org.bimserver.ServerIfcModel) HashMap(java.util.HashMap) IfcModelInterface(org.bimserver.emf.IfcModelInterface) IfcModelChangeListener(org.bimserver.ifc.IfcModelChangeListener) GeometryGeneratingException(org.bimserver.GeometryGeneratingException) ServerIfcModel(org.bimserver.ServerIfcModel) 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) 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 23 with Project

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

the class GetAllCheckoutsOfProjectDatabaseAction method getSubProjects.

private void getSubProjects(Project project, Set<Project> projects) {
    projects.add(project);
    Iterator<Project> iterator = project.getSubProjects().iterator();
    while (iterator.hasNext()) {
        Project subProject = iterator.next();
        getSubProjects(subProject, projects);
    }
}
Also used : Project(org.bimserver.models.store.Project)

Example 24 with Project

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

the class GetAllCheckoutsOfProjectDatabaseAction method execute.

@Override
public List<Checkout> execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    Project project = getProjectByPoid(poid);
    Set<Project> projects = new HashSet<Project>();
    if (checkSubProjects) {
        getSubProjects(project, projects);
    } else {
        projects.add(project);
    }
    Condition condition = new HasReferenceToInCondition(StorePackage.eINSTANCE.getCheckout_Project(), projects);
    Map<Long, Checkout> query = getDatabaseSession().query(condition, Checkout.class, OldQuery.getDefault());
    return CollectionUtils.mapToList(query);
}
Also used : Condition(org.bimserver.database.query.conditions.Condition) HasReferenceToInCondition(org.bimserver.database.query.conditions.HasReferenceToInCondition) Project(org.bimserver.models.store.Project) Checkout(org.bimserver.models.store.Checkout) HasReferenceToInCondition(org.bimserver.database.query.conditions.HasReferenceToInCondition) HashSet(java.util.HashSet)

Example 25 with Project

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

the class GetAllNonAuthorizedUsersOfProjectDatabaseAction method execute.

@Override
public Set<User> execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    Project project = getProjectByPoid(poid);
    if (project == null) {
        throw new UserException("No Project with oid " + poid + " found");
    }
    Condition condition = new AndCondition(new AndCondition(new Not(new HasReferenceToCondition(StorePackage.eINSTANCE.getUser_HasRightsOn(), project)), new AttributeCondition(StorePackage.eINSTANCE.getUser_State(), new EnumLiteral(ObjectState.ACTIVE))), new Not(new AttributeCondition(StorePackage.eINSTANCE.getUser_UserType(), new EnumLiteral(UserType.SYSTEM))));
    return CollectionUtils.mapToSet(getDatabaseSession().query(condition, User.class, OldQuery.getDefault()));
}
Also used : AttributeCondition(org.bimserver.database.query.conditions.AttributeCondition) Condition(org.bimserver.database.query.conditions.Condition) AndCondition(org.bimserver.database.query.conditions.AndCondition) HasReferenceToCondition(org.bimserver.database.query.conditions.HasReferenceToCondition) Project(org.bimserver.models.store.Project) Not(org.bimserver.database.query.conditions.Not) User(org.bimserver.models.store.User) HasReferenceToCondition(org.bimserver.database.query.conditions.HasReferenceToCondition) AttributeCondition(org.bimserver.database.query.conditions.AttributeCondition) UserException(org.bimserver.shared.exceptions.UserException) EnumLiteral(org.bimserver.database.query.literals.EnumLiteral) AndCondition(org.bimserver.database.query.conditions.AndCondition)

Aggregations

Project (org.bimserver.models.store.Project)80 UserException (org.bimserver.shared.exceptions.UserException)48 User (org.bimserver.models.store.User)46 DatabaseSession (org.bimserver.database.DatabaseSession)25 Revision (org.bimserver.models.store.Revision)23 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)22 ServerException (org.bimserver.shared.exceptions.ServerException)20 Date (java.util.Date)18 ArrayList (java.util.ArrayList)14 SProject (org.bimserver.interfaces.objects.SProject)14 IOException (java.io.IOException)13 PackageMetaData (org.bimserver.emf.PackageMetaData)13 HashSet (java.util.HashSet)12 IfcModelInterface (org.bimserver.emf.IfcModelInterface)12 ConcreteRevision (org.bimserver.models.store.ConcreteRevision)11 OldQuery (org.bimserver.database.OldQuery)10 PostCommitAction (org.bimserver.database.PostCommitAction)10 SConverter (org.bimserver.interfaces.SConverter)9 UnsupportedEncodingException (java.io.UnsupportedEncodingException)8 MalformedURLException (java.net.MalformedURLException)8