Search in sources :

Example 36 with Project

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

the class GetAllWritableProjectsDatabaseAction method execute.

@Override
public Set<Project> execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    User user = getUserByUoid(authorization.getUoid());
    IfcModelInterface projectsModel = getDatabaseSession().getAllOfType(StorePackage.eINSTANCE.getProject(), OldQuery.getDefault());
    Set<Project> result = new HashSet<Project>();
    for (IdEObject idEObject : projectsModel.getValues()) {
        if (idEObject instanceof Project) {
            Project project = (Project) idEObject;
            if (!project.getName().equals("INT-Store")) {
                if ((user.getUserType() == UserType.ADMIN || (project.getState() == ObjectState.ACTIVE) && authorization.hasRightsOnProjectOrSuperProjects(user, project))) {
                    result.add(project);
                }
            }
        }
    }
    return result;
}
Also used : Project(org.bimserver.models.store.Project) User(org.bimserver.models.store.User) IdEObject(org.bimserver.emf.IdEObject) IfcModelInterface(org.bimserver.emf.IfcModelInterface) HashSet(java.util.HashSet)

Example 37 with Project

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

the class GetCheckinWarningsDatabaseAction method checkInterleavingCommits.

private void checkInterleavingCommits(Project project, User user, Set<String> warnings) {
    Checkout lastOwnActiveCheckout = null;
    for (Checkout checkout : project.getCheckouts()) {
        if (checkout.getUser() == user && checkout.getActive()) {
            lastOwnActiveCheckout = checkout;
        }
    }
    if (lastOwnActiveCheckout != null) {
        Project mainProject = project;
        while (mainProject.getParent() != null) {
            mainProject = mainProject.getParent();
        }
        int newRevisionsAfterCheckout = 0;
        for (Revision virtualRevision : mainProject.getRevisions()) {
            if (lastOwnActiveCheckout.getDate().before(virtualRevision.getDate()) && lastOwnActiveCheckout.getRevision() != virtualRevision) {
                newRevisionsAfterCheckout++;
            }
        }
        if (newRevisionsAfterCheckout == 1) {
            warnings.add("Warning, after your last checkout of this project (revision " + lastOwnActiveCheckout.getRevision().getId() + "), a new revision has been checked-in");
        } else if (newRevisionsAfterCheckout > 1) {
            warnings.add("Warning, after your last checkout of this project (revision " + lastOwnActiveCheckout.getRevision().getId() + "), " + newRevisionsAfterCheckout + " new revisions have been checked-in");
        }
    }
}
Also used : Project(org.bimserver.models.store.Project) Checkout(org.bimserver.models.store.Checkout) Revision(org.bimserver.models.store.Revision)

Example 38 with Project

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

the class GetGeometryInfoDatabaseAction method execute.

@Override
public SGeometryInfo execute() throws UserException, BimserverDatabaseException, BimserverLockConflictException {
    Revision revision = getDatabaseSession().get(roid, OldQuery.getDefault());
    Project project = revision.getProject();
    PackageMetaData packageMetaData = bimServer.getMetaDataManager().getPackageMetaData(project.getSchema());
    IdEObject ifcProduct = getDatabaseSession().get(oid, new OldQuery(packageMetaData, project.getId(), revision.getId(), revision.getOid()));
    if (ifcProduct == null) {
        throw new UserException("Object with oid " + oid + " not found");
    }
    EStructuralFeature geometryFeature = packageMetaData.getEClass("IfcProduct").getEStructuralFeature("geometry");
    GeometryInfo geometry = (GeometryInfo) ifcProduct.eGet(geometryFeature);
    SGeometryInfo convertToSObject = bimServer.getSConverter().convertToSObject(geometry);
    return convertToSObject;
}
Also used : SGeometryInfo(org.bimserver.interfaces.objects.SGeometryInfo) Project(org.bimserver.models.store.Project) Revision(org.bimserver.models.store.Revision) IdEObject(org.bimserver.emf.IdEObject) PackageMetaData(org.bimserver.emf.PackageMetaData) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) GeometryInfo(org.bimserver.models.geometry.GeometryInfo) SGeometryInfo(org.bimserver.interfaces.objects.SGeometryInfo) UserException(org.bimserver.shared.exceptions.UserException) OldQuery(org.bimserver.database.OldQuery)

Example 39 with Project

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

the class GetProjectByPoidDatabaseAction method execute.

@Override
public Project execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    Project project = getProjectByPoid(poid);
    if (project == null) {
        throw new UserException("Project with oid " + poid + " does not exist");
    }
    User user = getUserByUoid(authorization.getUoid());
    if (user == null) {
        throw new UserException("Authenticated user required");
    }
    if (project.getState() == ObjectState.DELETED && user.getUserType() != UserType.ADMIN) {
        throw new UserException("Project has been deleted");
    }
    if (authorization.hasRightsOnProjectOrSuperProjectsOrSubProjects(user, project)) {
        return project;
    } else {
        throw new UserException("User '" + user.getUsername() + "' has no rights on this project");
    }
}
Also used : Project(org.bimserver.models.store.Project) User(org.bimserver.models.store.User) UserException(org.bimserver.shared.exceptions.UserException)

Example 40 with Project

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

the class GetSubProjectsDatabaseAction method execute.

@Override
public Set<Project> execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    User user = getUserByUoid(authorization.getUoid());
    Project project = getProjectByPoid(poid);
    if (!authorization.hasRightsOnProjectOrSuperProjectsOrSubProjects(user, project)) {
        throw new UserException("User has no rights on project");
    }
    Set<Project> subProjects = new HashSet<Project>();
    for (Project subProject : project.getSubProjects()) {
        if (subProject.getState() == ObjectState.ACTIVE || authorization instanceof AdminAuthorization) {
            subProjects.add(subProject);
        }
    }
    return subProjects;
}
Also used : Project(org.bimserver.models.store.Project) User(org.bimserver.models.store.User) UserException(org.bimserver.shared.exceptions.UserException) AdminAuthorization(org.bimserver.webservices.authorization.AdminAuthorization) HashSet(java.util.HashSet)

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