use of org.bimserver.interfaces.SConverter 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.interfaces.SConverter 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.interfaces.SConverter 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.interfaces.SConverter 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;
}
use of org.bimserver.interfaces.SConverter in project BIMserver by opensourceBIM.
the class ProgressTopic method updateProgress.
protected synchronized void updateProgress(final LongActionState state) {
try {
// Actually we should be keeping track of when we last sent a message to A SPECIFIC ENDPOINT, this way, new endpoints won't receive the message rights away
boolean sendMessage = lastSent == -1L || (System.nanoTime() - lastSent > RATE_LIMIT_NANO_SECONDS && state.getProgress().intValue() != lastProgress.getProgress().intValue());
sendMessage |= state.getProgress() == 100;
sendMessage |= state.getState() == ActionState.FINISHED;
sendMessage |= state.getState() == ActionState.AS_ERROR;
sendMessage |= lastProgress != null && lastProgress.getStage() != state.getStage();
sendMessage |= lastProgress != null && ((lastProgress.getTitle() == null && state.getTitle() != null) || !lastProgress.getTitle().equals(state.getTitle()));
if (sendMessage) {
try {
// System.out.println("Sending " + state.getProgress() + ", " + state.getState() + ", " + state.getTitle() + " to " + getEndPoints().size());
map(new Mapper() {
@Override
public void map(EndPoint endPoint) throws UserException, ServerException, BimserverDatabaseException {
try {
endPoint.getNotificationInterface().progress(key.getId(), new SConverter().convertToSObject(state));
} catch (Exception e) {
LOGGER.error("", e);
}
}
});
} catch (Exception e) {
LOGGER.error("", e);
}
lastProgress = state;
lastSent = System.nanoTime();
} else {
// System.out.println("Skipping " + state.getProgress() + ", " + state.getState() + ", " + state.getTitle());
}
} catch (Exception e) {
LOGGER.error("", e);
}
}
Aggregations