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");
}
}
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;
}
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;
}
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;
}
Aggregations