use of org.bimserver.database.PostCommitAction in project BIMserver by opensourceBIM.
the class RemoveUserFromProjectDatabaseAction method execute.
@Override
public Boolean execute() throws UserException, BimserverDatabaseException, BimserverLockConflictException {
User user = getUserByUoid(uoid);
Project project = getProjectByPoid(poid);
User actingUser = getUserByUoid(authorization.getUoid());
if (authorization.hasRightsOnProject(actingUser, project)) {
if (user.getUserType() == UserType.ADMIN) {
int nrAdmins = 0;
for (User authUser : project.getHasAuthorizedUsers()) {
if (authUser.getUserType() == UserType.ADMIN) {
nrAdmins++;
}
}
if (nrAdmins == 1) {
throw new UserException("User cannot be removed from this project because it is the only admin user with authorization on this project");
}
}
project.getHasAuthorizedUsers().remove(user);
user.getHasRightsOn().remove(project);
final UserRemovedFromProject userRemovedFromProject = getDatabaseSession().create(UserRemovedFromProject.class);
userRemovedFromProject.setDate(new Date());
userRemovedFromProject.setExecutor(actingUser);
userRemovedFromProject.setAccessMethod(getAccessMethod());
userRemovedFromProject.setProject(project);
userRemovedFromProject.setUser(user);
getDatabaseSession().addPostCommitAction(new PostCommitAction() {
@Override
public void execute() throws UserException {
bimServer.getNotificationsManager().notify(new SConverter().convertToSObject(userRemovedFromProject));
}
});
getDatabaseSession().store(user);
getDatabaseSession().store(project);
return true;
} else {
throw new UserException("Insufficient rights to remove user from project");
}
}
use of org.bimserver.database.PostCommitAction in project BIMserver by opensourceBIM.
the class RequestPasswordChangeDatabaseAction method execute.
@Override
public Void execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
final User user = getUserByUserName(username);
if (user == null) {
throw new UserException("User with username \"" + username + "\" not found");
}
final String token = GeneratorUtils.generateToken();
user.setValidationToken(Hashers.getSha256Hash(token));
user.setValidationTokenCreated(new Date());
getDatabaseSession().store(user);
getDatabaseSession().addPostCommitAction(new PostCommitAction() {
@Override
public void execute() throws UserException {
if (MailSystem.isValidEmailAddress(user.getUsername())) {
EmailMessage message = bimServer.getMailSystem().createMessage();
String body = null;
String subject = null;
try {
InternetAddress addressFrom = new InternetAddress(bimServer.getServerSettingsCache().getServerSettings().getEmailSenderAddress());
message.setFrom(addressFrom);
InternetAddress[] addressTo = new InternetAddress[1];
addressTo[0] = new InternetAddress(user.getUsername());
message.setRecipients(Message.RecipientType.TO, addressTo);
Map<String, Object> context = new HashMap<String, Object>();
context.put("name", user.getName());
context.put("username", user.getUsername());
if (includeSiteAddress) {
context.put("siteaddress", bimServer.getServerSettingsCache().getServerSettings().getSiteAddress());
}
context.put("validationlink", resetUrl + "&username=" + user.getUsername() + "&uoid=" + user.getOid() + "&validationtoken=" + token + (includeSiteAddress ? ("&address=" + bimServer.getServerSettingsCache().getServerSettings().getSiteAddress()) : ""));
body = bimServer.getTemplateEngine().process(context, TemplateIdentifier.PASSWORD_RESET_EMAIL_BODY);
subject = bimServer.getTemplateEngine().process(context, TemplateIdentifier.PASSWORD_RESET_EMAIL_SUBJECT);
message.setContent(body, "text/html");
message.setSubject(subject.trim());
message.send();
} catch (Exception e) {
LOGGER.error(body);
throw new UserException(e.getMessage());
}
}
}
});
return null;
}
use of org.bimserver.database.PostCommitAction in project BIMserver by opensourceBIM.
the class SetServerSettingDatabaseAction method execute.
@Override
public Void execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
ServerSettings serverSettings = getDatabaseSession().getSingle(StorePackage.eINSTANCE.getServerSettings(), OldQuery.getDefault());
serverSettingsSetter.set(serverSettings);
getDatabaseSession().store(serverSettings);
getDatabaseSession().addPostCommitAction(new PostCommitAction() {
@Override
public void execute() throws UserException {
bimServer.getServerSettingsCache().updateCache();
}
});
return null;
}
use of org.bimserver.database.PostCommitAction in project BIMserver by opensourceBIM.
the class UpdateGeoTagDatabaseAction method execute.
@Override
public Void execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
User actingUser = getUserByUoid(authorization.getUoid());
GeoTag geoTag = (GeoTag) getDatabaseSession().get(StorePackage.eINSTANCE.getGeoTag(), sGeoTag.getOid(), OldQuery.getDefault());
boolean hasRights = false;
for (Project project : geoTag.getProjects()) {
if (authorization.hasRightsOnProject(actingUser, project)) {
hasRights = true;
continue;
}
}
if (hasRights) {
geoTag.setEnabled(sGeoTag.getEnabled());
geoTag.setX(sGeoTag.getX());
geoTag.setY(sGeoTag.getY());
geoTag.setZ(sGeoTag.getZ());
geoTag.setDirectionAngle(sGeoTag.getDirectionAngle());
geoTag.setEpsg(sGeoTag.getEpsg());
final GeoTagUpdated geoTagUpdated = getDatabaseSession().create(GeoTagUpdated.class);
geoTagUpdated.setGeoTag(geoTag);
geoTagUpdated.setAccessMethod(getAccessMethod());
geoTagUpdated.setDate(new Date());
geoTagUpdated.setExecutor(actingUser);
getDatabaseSession().addPostCommitAction(new PostCommitAction() {
@Override
public void execute() throws UserException {
bimServer.getNotificationsManager().notify(new SConverter().convertToSObject(geoTagUpdated));
}
});
getDatabaseSession().store(geoTag);
} else {
throw new UserException("User has no rights on any projects associated with this geotag");
}
return null;
}
use of org.bimserver.database.PostCommitAction in project BIMserver by opensourceBIM.
the class AddExtendedDataToRevisionDatabaseAction method execute.
@Override
public Long execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
authorization.canWriteExtendedData(roid);
User actingUser = getUserByUoid(authorization.getUoid());
getIdEObject().setUser(actingUser);
getIdEObject().setAdded(new Date());
File file = getIdEObject().getFile();
getIdEObject().setSize(file.getData().length);
super.execute();
Revision revision = getRevisionByRoid(roid);
if (revision == null) {
throw new UserException("Revision with roid " + roid + " not found");
}
revision.getExtendedData().add(getIdEObject());
getDatabaseSession().store(revision);
getIdEObject().setProject(revision.getProject());
getIdEObject().setRevision(revision);
if (getIdEObject().getSchema() != null) {
getDatabaseSession().store(getIdEObject().getSchema());
}
final ExtendedDataAddedToRevision extendedDataAddedToRevision = getDatabaseSession().create(ExtendedDataAddedToRevision.class);
extendedDataAddedToRevision.setAccessMethod(getAccessMethod());
extendedDataAddedToRevision.setDate(new Date());
extendedDataAddedToRevision.setExecutor(actingUser);
extendedDataAddedToRevision.setExtendedData(getIdEObject());
extendedDataAddedToRevision.setRevision(revision);
final long poid = revision.getProject().getOid();
final long roid = revision.getOid();
getDatabaseSession().addPostCommitAction(new PostCommitAction() {
@Override
public void execute() throws UserException {
bimServer.getNotificationsManager().notify(new NewExtendedDataOnRevisionNotification(bimServer, getIdEObject().getOid(), poid, roid, -1));
bimServer.getNotificationsManager().notify(new SConverter().convertToSObject(extendedDataAddedToRevision));
}
});
return null;
}
Aggregations