Search in sources :

Example 1 with SConverter

use of org.bimserver.interfaces.SConverter in project BIMserver by opensourceBIM.

the class AddExtendedDataToProjectDatabaseAction method execute.

@Override
public Long execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    super.execute();
    User actingUser = getUserByUoid(authorization.getUoid());
    Project project = getProjectByPoid(poid);
    if (project == null) {
        throw new UserException("Project with poid " + poid + " not found");
    }
    project.getExtendedData().add(getIdEObject());
    getDatabaseSession().store(project);
    final ExtendedDataAddedToProject extendedDataAddedToProject = getDatabaseSession().create(ExtendedDataAddedToProject.class);
    extendedDataAddedToProject.setAccessMethod(getAccessMethod());
    extendedDataAddedToProject.setDate(new Date());
    extendedDataAddedToProject.setExecutor(actingUser);
    extendedDataAddedToProject.setExtendedData(getIdEObject());
    extendedDataAddedToProject.setProject(project);
    getDatabaseSession().addPostCommitAction(new PostCommitAction() {

        @Override
        public void execute() throws UserException {
            bimServer.getNotificationsManager().notify(new SConverter().convertToSObject(extendedDataAddedToProject));
        }
    });
    return null;
}
Also used : ExtendedDataAddedToProject(org.bimserver.models.log.ExtendedDataAddedToProject) Project(org.bimserver.models.store.Project) User(org.bimserver.models.store.User) ExtendedDataAddedToProject(org.bimserver.models.log.ExtendedDataAddedToProject) SConverter(org.bimserver.interfaces.SConverter) PostCommitAction(org.bimserver.database.PostCommitAction) UserException(org.bimserver.shared.exceptions.UserException) Date(java.util.Date)

Example 2 with SConverter

use of org.bimserver.interfaces.SConverter in project BIMserver by opensourceBIM.

the class ChangeUserTypeDatabaseAction method execute.

@Override
public Void execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    User actingUser = getUserByUoid(authorization.getUoid());
    if (actingUser.getUserType() != UserType.ADMIN) {
        throw new UserException("Only admin users can change other user's types");
    }
    User user = getUserByUoid(uoid);
    if (user.getUserType() == UserType.SYSTEM) {
        throw new UserException("Type of system user cannot be changed");
    }
    user.setUserType(UserType.get(userType.getOrdinal()));
    final UserChanged userChanged = getDatabaseSession().create(UserChanged.class);
    userChanged.setAccessMethod(getAccessMethod());
    userChanged.setDate(new Date());
    userChanged.setExecutor(actingUser);
    userChanged.setUser(user);
    getDatabaseSession().addPostCommitAction(new PostCommitAction() {

        @Override
        public void execute() throws UserException {
            bimServer.getNotificationsManager().notify(new SConverter().convertToSObject(userChanged));
        }
    });
    getDatabaseSession().store(user);
    return null;
}
Also used : User(org.bimserver.models.store.User) SConverter(org.bimserver.interfaces.SConverter) PostCommitAction(org.bimserver.database.PostCommitAction) UserException(org.bimserver.shared.exceptions.UserException) Date(java.util.Date) UserChanged(org.bimserver.models.log.UserChanged)

Example 3 with SConverter

use of org.bimserver.interfaces.SConverter in project BIMserver by opensourceBIM.

the class DeleteProjectDatabaseAction method execute.

@Override
public Boolean execute() throws UserException, BimserverDatabaseException, BimserverLockConflictException {
    User actingUser = getUserByUoid(authorization.getUoid());
    final Project project = getProjectByPoid(poid);
    if (actingUser.getUserType() == UserType.ADMIN || (actingUser.getHasRightsOn().contains(project) && bimServer.getServerSettingsCache().getServerSettings().isAllowUsersToCreateTopLevelProjects())) {
        delete(project);
        final ProjectDeleted projectDeleted = getDatabaseSession().create(ProjectDeleted.class);
        projectDeleted.setAccessMethod(getAccessMethod());
        projectDeleted.setDate(new Date());
        projectDeleted.setExecutor(actingUser);
        projectDeleted.setProject(project);
        getDatabaseSession().addPostCommitAction(new PostCommitAction() {

            @Override
            public void execute() throws UserException {
                bimServer.getNotificationsManager().notify(new SConverter().convertToSObject(projectDeleted));
            }
        });
        getDatabaseSession().store(project);
        return true;
    } else {
        throw new UserException("No rights to delete this project");
    }
}
Also used : Project(org.bimserver.models.store.Project) User(org.bimserver.models.store.User) SConverter(org.bimserver.interfaces.SConverter) PostCommitAction(org.bimserver.database.PostCommitAction) UserException(org.bimserver.shared.exceptions.UserException) ProjectDeleted(org.bimserver.models.log.ProjectDeleted) Date(java.util.Date)

Example 4 with SConverter

use of org.bimserver.interfaces.SConverter in project BIMserver by opensourceBIM.

the class RemoveUserFromProjectDatabaseAction method execute.

@Override
public Boolean execute() throws UserException, BimserverDatabaseException, BimserverLockConflictException {
    User user = getUserByUoid(uoid);
    Project project = getProjectByPoid(poid);
    User actingUser = getUserByUoid(authorization.getUoid());
    if (authorization.hasRightsOnProject(actingUser, project)) {
        if (user.getUserType() == UserType.ADMIN) {
            int nrAdmins = 0;
            for (User authUser : project.getHasAuthorizedUsers()) {
                if (authUser.getUserType() == UserType.ADMIN) {
                    nrAdmins++;
                }
            }
            if (nrAdmins == 1) {
                throw new UserException("User cannot be removed from this project because it is the only admin user with authorization on this project");
            }
        }
        project.getHasAuthorizedUsers().remove(user);
        user.getHasRightsOn().remove(project);
        final UserRemovedFromProject userRemovedFromProject = getDatabaseSession().create(UserRemovedFromProject.class);
        userRemovedFromProject.setDate(new Date());
        userRemovedFromProject.setExecutor(actingUser);
        userRemovedFromProject.setAccessMethod(getAccessMethod());
        userRemovedFromProject.setProject(project);
        userRemovedFromProject.setUser(user);
        getDatabaseSession().addPostCommitAction(new PostCommitAction() {

            @Override
            public void execute() throws UserException {
                bimServer.getNotificationsManager().notify(new SConverter().convertToSObject(userRemovedFromProject));
            }
        });
        getDatabaseSession().store(user);
        getDatabaseSession().store(project);
        return true;
    } else {
        throw new UserException("Insufficient rights to remove user from project");
    }
}
Also used : Project(org.bimserver.models.store.Project) UserRemovedFromProject(org.bimserver.models.log.UserRemovedFromProject) User(org.bimserver.models.store.User) SConverter(org.bimserver.interfaces.SConverter) PostCommitAction(org.bimserver.database.PostCommitAction) UserException(org.bimserver.shared.exceptions.UserException) UserRemovedFromProject(org.bimserver.models.log.UserRemovedFromProject) Date(java.util.Date)

Example 5 with SConverter

use of org.bimserver.interfaces.SConverter in project BIMserver by opensourceBIM.

the class UpdateGeoTagDatabaseAction method execute.

@Override
public Void execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    User actingUser = getUserByUoid(authorization.getUoid());
    GeoTag geoTag = (GeoTag) getDatabaseSession().get(StorePackage.eINSTANCE.getGeoTag(), sGeoTag.getOid(), OldQuery.getDefault());
    boolean hasRights = false;
    for (Project project : geoTag.getProjects()) {
        if (authorization.hasRightsOnProject(actingUser, project)) {
            hasRights = true;
            continue;
        }
    }
    if (hasRights) {
        geoTag.setEnabled(sGeoTag.getEnabled());
        geoTag.setX(sGeoTag.getX());
        geoTag.setY(sGeoTag.getY());
        geoTag.setZ(sGeoTag.getZ());
        geoTag.setDirectionAngle(sGeoTag.getDirectionAngle());
        geoTag.setEpsg(sGeoTag.getEpsg());
        final GeoTagUpdated geoTagUpdated = getDatabaseSession().create(GeoTagUpdated.class);
        geoTagUpdated.setGeoTag(geoTag);
        geoTagUpdated.setAccessMethod(getAccessMethod());
        geoTagUpdated.setDate(new Date());
        geoTagUpdated.setExecutor(actingUser);
        getDatabaseSession().addPostCommitAction(new PostCommitAction() {

            @Override
            public void execute() throws UserException {
                bimServer.getNotificationsManager().notify(new SConverter().convertToSObject(geoTagUpdated));
            }
        });
        getDatabaseSession().store(geoTag);
    } else {
        throw new UserException("User has no rights on any projects associated with this geotag");
    }
    return null;
}
Also used : Project(org.bimserver.models.store.Project) SGeoTag(org.bimserver.interfaces.objects.SGeoTag) GeoTag(org.bimserver.models.store.GeoTag) User(org.bimserver.models.store.User) GeoTagUpdated(org.bimserver.models.log.GeoTagUpdated) SConverter(org.bimserver.interfaces.SConverter) PostCommitAction(org.bimserver.database.PostCommitAction) UserException(org.bimserver.shared.exceptions.UserException) Date(java.util.Date)

Aggregations

SConverter (org.bimserver.interfaces.SConverter)15 UserException (org.bimserver.shared.exceptions.UserException)14 Date (java.util.Date)13 PostCommitAction (org.bimserver.database.PostCommitAction)13 User (org.bimserver.models.store.User)13 Project (org.bimserver.models.store.Project)9 Revision (org.bimserver.models.store.Revision)3 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Authenticator (org.bimserver.Authenticator)1 GenerateGeometryResult (org.bimserver.GenerateGeometryResult)1 GeometryGeneratingException (org.bimserver.GeometryGeneratingException)1 SummaryMap (org.bimserver.SummaryMap)1 Change (org.bimserver.changes.Change)1 CreateObjectChange (org.bimserver.changes.CreateObjectChange)1 RemoveObjectChange (org.bimserver.changes.RemoveObjectChange)1 Transaction (org.bimserver.changes.Transaction)1 OldQuery (org.bimserver.database.OldQuery)1 QueryException (org.bimserver.database.queries.om.QueryException)1