Search in sources :

Example 91 with UserException

use of org.bimserver.shared.exceptions.UserException in project BIMserver by opensourceBIM.

the class DownloadByNewQueryDatabaseAction method execute.

@Override
public ObjectProvider execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException, ServerException {
    User user = getUserByUoid(authorization.getUoid());
    Project project = null;
    Map<Integer, Long> pidRoidMap = new HashMap<>();
    for (Long roid : roids) {
        Revision virtualRevision = getRevisionByRoid(roid);
        pidRoidMap.put(virtualRevision.getProject().getId(), virtualRevision.getOid());
        project = virtualRevision.getProject();
        try {
            authorization.canDownload(roid);
        } catch (UserException e) {
            if (!authorization.hasRightsOnProjectOrSuperProjectsOrSubProjects(user, project)) {
                throw new UserException("User has insufficient rights to download revisions from this project");
            }
            if (!authorization.hasRightsOnProjectOrSuperProjectsOrSubProjects(user, project)) {
                throw new UserException("User has insufficient rights to download revisions from this project");
            }
        }
    }
    PackageMetaData packageMetaData = bimServer.getMetaDataManager().getPackageMetaData(project.getSchema());
    try {
        return QueryObjectProvider.fromJsonString(getDatabaseSession(), bimServer, json, roids, packageMetaData);
    } catch (Exception e) {
        throw new UserException(e);
    }
}
Also used : Project(org.bimserver.models.store.Project) User(org.bimserver.models.store.User) Revision(org.bimserver.models.store.Revision) HashMap(java.util.HashMap) PackageMetaData(org.bimserver.emf.PackageMetaData) UserException(org.bimserver.shared.exceptions.UserException) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException) UserException(org.bimserver.shared.exceptions.UserException) ServerException(org.bimserver.shared.exceptions.ServerException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException)

Example 92 with UserException

use of org.bimserver.shared.exceptions.UserException in project BIMserver by opensourceBIM.

the class DownloadCompareDatabaseAction method execute.

@Override
public IfcModelInterface execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException, ServerException {
    try {
        Revision revision1 = getRevisionByRoid(roid1);
        Revision revision2 = getRevisionByRoid(roid2);
        Project project = revision1.getProject();
        // bimServer.getCompareCache().getCompareResults(roid1,
        CompareResult compareResults = null;
        // roid2, compareType,
        // compareIdentifier);
        IfcModelInterface model1 = new DownloadDatabaseAction(getBimServer(), getDatabaseSession(), getAccessMethod(), roid1, -1, -1, getAuthorization(), null).execute();
        IfcModelInterface model2 = new DownloadDatabaseAction(getBimServer(), getDatabaseSession(), getAccessMethod(), roid2, -1, -1, getAuthorization(), null).execute();
        try {
            compareResults = getModelCompare().compare(model1, model2, compareType);
        } catch (ModelCompareException e) {
            throw new UserException(e);
        }
        // bimServer.getCompareCache().storeResults(roid1, roid2,
        // compareType, compareIdentifier, compareResults);
        ModelMerger merger = getBimServer().getMergerFactory().createMerger(getDatabaseSession(), getAuthorization().getUoid());
        PackageMetaData packageMetaData = model1.getPackageMetaData();
        IfcModelInterface mergedModel = new ServerIfcModel(packageMetaData, null, getDatabaseSession());
        mergedModel = merger.merge(project, new IfcModelSet(model1, model2), new ModelHelper(getBimServer().getMetaDataManager(), mergedModel));
        mergedModel.getModelMetaData().setName(project.getName() + "." + revision1.getId() + "." + revision2.getId());
        Set<Long> added = new HashSet<Long>();
        Set<Long> modified = new HashSet<Long>();
        Set<Long> deleted = new HashSet<Long>();
        for (CompareContainer compareContainer : compareResults.getItems()) {
            for (CompareItem compareItem : compareContainer.getItems()) {
                DataObject dataObject = compareItem.getDataObject();
                if (compareItem instanceof ObjectAdded) {
                    added.add(dataObject.getOid());
                } else if (compareItem instanceof ObjectModified) {
                    modified.add(dataObject.getOid());
                } else if (compareItem instanceof ObjectRemoved) {
                    deleted.add(dataObject.getOid());
                }
            }
        }
        EClass ifcColourRgbClass = packageMetaData.getEClass("IfcColourRgb");
        EStructuralFeature nameFeature = ifcColourRgbClass.getEStructuralFeature("Name");
        EStructuralFeature redFeature = ifcColourRgbClass.getEStructuralFeature("Red");
        EStructuralFeature greenFeature = ifcColourRgbClass.getEStructuralFeature("Green");
        EStructuralFeature blueFeature = ifcColourRgbClass.getEStructuralFeature("Blue");
        IdEObject red = mergedModel.createAndAdd(ifcColourRgbClass);
        red.eSet(nameFeature, "red");
        red.eSet(redFeature, 0.5D);
        red.eSet(greenFeature, 0.0D);
        red.eSet(blueFeature, 0.0D);
        IdEObject green = mergedModel.createAndAdd(ifcColourRgbClass);
        green.eSet(nameFeature, "green");
        green.eSet(redFeature, 0D);
        green.eSet(greenFeature, 0.5D);
        green.eSet(blueFeature, 0D);
        IdEObject blue = mergedModel.createAndAdd(ifcColourRgbClass);
        blue.eSet(nameFeature, "blue");
        blue.eSet(redFeature, 0D);
        blue.eSet(greenFeature, 0D);
        blue.eSet(blueFeature, 0.5D);
        for (IdEObject product : mergedModel.getAllWithSubTypes(packageMetaData.getEClass("IfcProduct"))) {
            IdEObject color = null;
            if (added.contains(product.getOid())) {
                color = green;
            } else if (deleted.contains(product.getOid())) {
                color = red;
            } else if (modified.contains(product.getOid())) {
                color = blue;
            }
            if (color != null) {
                setColor(mergedModel, product, color);
            }
        }
        mergedModel.fixOidCounter();
        return mergedModel;
    } catch (IfcModelInterfaceException e) {
        throw new UserException(e);
    } catch (MergeException e) {
        throw new UserException(e);
    }
}
Also used : ServerIfcModel(org.bimserver.ServerIfcModel) IfcModelInterface(org.bimserver.emf.IfcModelInterface) CompareResult(org.bimserver.models.store.CompareResult) IfcModelInterfaceException(org.bimserver.emf.IfcModelInterfaceException) EClass(org.eclipse.emf.ecore.EClass) MergeException(org.bimserver.plugins.modelmerger.MergeException) CompareContainer(org.bimserver.models.store.CompareContainer) UserException(org.bimserver.shared.exceptions.UserException) ModelMerger(org.bimserver.plugins.modelmerger.ModelMerger) HashSet(java.util.HashSet) ModelHelper(org.bimserver.plugins.ModelHelper) IdEObject(org.bimserver.emf.IdEObject) PackageMetaData(org.bimserver.emf.PackageMetaData) ObjectRemoved(org.bimserver.models.store.ObjectRemoved) CompareItem(org.bimserver.models.store.CompareItem) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) Project(org.bimserver.models.store.Project) DataObject(org.bimserver.models.store.DataObject) Revision(org.bimserver.models.store.Revision) IfcModelSet(org.bimserver.plugins.IfcModelSet) ObjectAdded(org.bimserver.models.store.ObjectAdded) ModelCompareException(org.bimserver.plugins.modelcompare.ModelCompareException) ObjectModified(org.bimserver.models.store.ObjectModified)

Example 93 with UserException

use of org.bimserver.shared.exceptions.UserException 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 94 with UserException

use of org.bimserver.shared.exceptions.UserException 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 95 with UserException

use of org.bimserver.shared.exceptions.UserException in project BIMserver by opensourceBIM.

the class GenericCheckinDatabaseAction method checkCheckSum.

protected void checkCheckSum(Project project, IfcModelInterface model) throws UserException {
    ConcreteRevision lastConcreteRevision = project.getLastConcreteRevision();
    if (lastConcreteRevision != null) {
        int revisionId = -1;
        for (Revision revision : lastConcreteRevision.getRevisions()) {
            if (revision.getProject() == project) {
                revisionId = revision.getId();
            }
        }
        byte[] revisionChecksum = lastConcreteRevision.getChecksum();
        if (revisionChecksum != null && model.getModelMetaData().getChecksum() != null) {
            if (Arrays.equals(revisionChecksum, model.getModelMetaData().getChecksum())) {
                throw new UserException("Uploaded model is the same as last revision (" + revisionId + "), duplicate model not stored");
            }
        }
    }
}
Also used : ConcreteRevision(org.bimserver.models.store.ConcreteRevision) Revision(org.bimserver.models.store.Revision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) UserException(org.bimserver.shared.exceptions.UserException)

Aggregations

UserException (org.bimserver.shared.exceptions.UserException)362 ServerException (org.bimserver.shared.exceptions.ServerException)253 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)241 DatabaseSession (org.bimserver.database.DatabaseSession)227 IOException (java.io.IOException)220 SerializerException (org.bimserver.plugins.serializers.SerializerException)113 DeserializeException (org.bimserver.plugins.deserializers.DeserializeException)112 MalformedURLException (java.net.MalformedURLException)109 MessagingException (javax.mail.MessagingException)109 BcfException (org.opensourcebim.bcf.BcfException)109 UnsupportedEncodingException (java.io.UnsupportedEncodingException)108 AddressException (javax.mail.internet.AddressException)108 CannotBeScheduledException (org.bimserver.longaction.CannotBeScheduledException)108 User (org.bimserver.models.store.User)65 Project (org.bimserver.models.store.Project)48 Revision (org.bimserver.models.store.Revision)39 ArrayList (java.util.ArrayList)35 Date (java.util.Date)34 SProject (org.bimserver.interfaces.objects.SProject)31 PackageMetaData (org.bimserver.emf.PackageMetaData)30