Search in sources :

Example 1 with ProjectUndeleted

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

Aggregations

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