Search in sources :

Example 16 with PostCommitAction

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

the class UndeleteProjectDatabaseAction method execute.

@Override
public Boolean execute() throws UserException, BimserverDatabaseException, BimserverLockConflictException {
    User actingUser = getUserByUoid(authorization.getUoid());
    final Project project = getProjectByPoid(poid);
    if (project == null) {
        throw new UserException("No Project with oid " + poid + " found");
    }
    if (actingUser.getUserType() == UserType.ADMIN || actingUser.getHasRightsOn().contains(project)) {
        project.setState(ObjectState.ACTIVE);
        final ProjectUndeleted projectUndeleted = getDatabaseSession().create(ProjectUndeleted.class);
        projectUndeleted.setAccessMethod(getAccessMethod());
        projectUndeleted.setDate(new Date());
        projectUndeleted.setExecutor(actingUser);
        projectUndeleted.setProject(project);
        getDatabaseSession().addPostCommitAction(new PostCommitAction() {

            @Override
            public void execute() throws UserException {
                bimServer.getNotificationsManager().notify(new SConverter().convertToSObject(projectUndeleted));
            }
        });
        getDatabaseSession().store(project);
        return true;
    } else {
        throw new UserException("No rights to undelete 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) Date(java.util.Date) ProjectUndeleted(org.bimserver.models.log.ProjectUndeleted)

Example 17 with PostCommitAction

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

the class UndeleteUserDatabaseAction method execute.

@Override
public Boolean execute() throws UserException, BimserverDatabaseException, BimserverLockConflictException {
    User actingUser = getUserByUoid(authorization.getUoid());
    if (actingUser.getUserType() != UserType.ADMIN) {
        throw new UserException("Only administrators can undelete users");
    }
    final User user = getUserByUoid(uoid);
    if (user == null) {
        throw new UserException("No User with oid " + uoid + " found");
    }
    final UserUndeleted userUndeleted = getDatabaseSession().create(UserUndeleted.class);
    userUndeleted.setAccessMethod(getAccessMethod());
    userUndeleted.setDate(new Date());
    userUndeleted.setExecutor(actingUser);
    userUndeleted.setUser(user);
    getDatabaseSession().addPostCommitAction(new PostCommitAction() {

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

Example 18 with PostCommitAction

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

the class UpdateProjectDatabaseAction method execute.

@Override
public Void execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    User actingUser = getUserByUoid(authorization.getUoid());
    final Project project = getProjectByPoid(sProject.getOid());
    if (project == null) {
        throw new UserException("Project with pid " + sProject.getOid() + " not found");
    }
    if (sProject.getName().trim().equals("")) {
        throw new UserException("Project name cannot be empty");
    }
    if (!authorization.hasRightsOnProjectOrSuperProjects(actingUser, project)) {
        throw new UserException("User has no rights to update project properties");
    }
    if (project.getParent() == null) {
        if (!sProject.getName().equals(project.getName())) {
            for (Project p : getProjectsByName(sProject.getName())) {
                if (p.getParent() == null) {
                    throw new UserException("Project name must be unique");
                }
            }
        }
    } else {
        Project parent = project.getParent();
        for (Project subProject : parent.getSubProjects()) {
            if (subProject.getName().equals(sProject.getName()) && subProject != project) {
                throw new UserException("Project name must be unique within parent project (" + parent.getName() + ")");
            }
        }
    }
    project.setSendEmailOnNewRevision(sProject.isSendEmailOnNewRevision());
    project.setName(sProject.getName());
    project.setDescription(sProject.getDescription());
    project.setExportLengthMeasurePrefix(SIPrefix.get(sProject.getExportLengthMeasurePrefix().getOrdinal()));
    final ProjectUpdated projectUpdated = getDatabaseSession().create(ProjectUpdated.class);
    projectUpdated.setAccessMethod(getAccessMethod());
    projectUpdated.setDate(new Date());
    projectUpdated.setExecutor(actingUser);
    projectUpdated.setProject(project);
    getDatabaseSession().addPostCommitAction(new PostCommitAction() {

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

Example 19 with PostCommitAction

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

the class UpdateRevisionDatabaseAction method execute.

@Override
public Void execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    User actingUser = getUserByUoid(authorization.getUoid());
    final Revision revision = getRevisionByRoid(sRevision.getOid());
    if (revision == null) {
        throw new UserException("Revision with pid " + sRevision.getOid() + " not found");
    }
    Project project = revision.getProject();
    if (!authorization.hasRightsOnProjectOrSuperProjects(actingUser, project)) {
        throw new UserException("User has no rights to update project properties");
    }
    final RevisionUpdated revisionUpdated = getDatabaseSession().create(RevisionUpdated.class);
    revisionUpdated.setRevision(revision);
    revisionUpdated.setDate(new Date());
    revisionUpdated.setExecutor(actingUser);
    revisionUpdated.setAccessMethod(getAccessMethod());
    getDatabaseSession().addPostCommitAction(new PostCommitAction() {

        @Override
        public void execute() throws UserException {
            bimServer.getNotificationsManager().notify(new SConverter().convertToSObject(revisionUpdated));
        }
    });
    revision.setTag(sRevision.getTag());
    getDatabaseSession().store(revision);
    return null;
}
Also used : Project(org.bimserver.models.store.Project) RevisionUpdated(org.bimserver.models.log.RevisionUpdated) User(org.bimserver.models.store.User) SRevision(org.bimserver.interfaces.objects.SRevision) Revision(org.bimserver.models.store.Revision) SConverter(org.bimserver.interfaces.SConverter) PostCommitAction(org.bimserver.database.PostCommitAction) UserException(org.bimserver.shared.exceptions.UserException) Date(java.util.Date)

Aggregations

PostCommitAction (org.bimserver.database.PostCommitAction)19 UserException (org.bimserver.shared.exceptions.UserException)19 Date (java.util.Date)18 User (org.bimserver.models.store.User)18 SConverter (org.bimserver.interfaces.SConverter)13 Project (org.bimserver.models.store.Project)10 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)5 Revision (org.bimserver.models.store.Revision)5 HashMap (java.util.HashMap)4 GenerateGeometryResult (org.bimserver.GenerateGeometryResult)3 SummaryMap (org.bimserver.SummaryMap)3 NewRevisionAdded (org.bimserver.models.log.NewRevisionAdded)3 ConcreteRevision (org.bimserver.models.store.ConcreteRevision)3 ByteBuffer (java.nio.ByteBuffer)2 Map (java.util.Map)2 InternetAddress (javax.mail.internet.InternetAddress)2 Authenticator (org.bimserver.Authenticator)2 BimserverLockConflictException (org.bimserver.database.BimserverLockConflictException)2 GeometryGenerationReport (org.bimserver.geometry.GeometryGenerationReport)2 StreamingGeometryGenerator (org.bimserver.geometry.StreamingGeometryGenerator)2