Search in sources :

Example 1 with ProjectDeleted

use of org.bimserver.models.log.ProjectDeleted 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)

Aggregations

Date (java.util.Date)1 PostCommitAction (org.bimserver.database.PostCommitAction)1 SConverter (org.bimserver.interfaces.SConverter)1 ProjectDeleted (org.bimserver.models.log.ProjectDeleted)1 Project (org.bimserver.models.store.Project)1 User (org.bimserver.models.store.User)1 UserException (org.bimserver.shared.exceptions.UserException)1