Search in sources :

Example 6 with PostCommitAction

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");
    }
}
Also used : Project(org.bimserver.models.store.Project) UserRemovedFromProject(org.bimserver.models.log.UserRemovedFromProject) User(org.bimserver.models.store.User) SConverter(org.bimserver.interfaces.SConverter) PostCommitAction(org.bimserver.database.PostCommitAction) UserException(org.bimserver.shared.exceptions.UserException) UserRemovedFromProject(org.bimserver.models.log.UserRemovedFromProject) Date(java.util.Date)

Example 7 with PostCommitAction

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;
}
Also used : EmailMessage(org.bimserver.mail.EmailMessage) InternetAddress(javax.mail.internet.InternetAddress) User(org.bimserver.models.store.User) PostCommitAction(org.bimserver.database.PostCommitAction) UserException(org.bimserver.shared.exceptions.UserException) HashMap(java.util.HashMap) Map(java.util.Map) Date(java.util.Date) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException) UserException(org.bimserver.shared.exceptions.UserException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException)

Example 8 with PostCommitAction

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;
}
Also used : ServerSettings(org.bimserver.models.store.ServerSettings) PostCommitAction(org.bimserver.database.PostCommitAction) UserException(org.bimserver.shared.exceptions.UserException)

Example 9 with PostCommitAction

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;
}
Also used : Project(org.bimserver.models.store.Project) SGeoTag(org.bimserver.interfaces.objects.SGeoTag) GeoTag(org.bimserver.models.store.GeoTag) User(org.bimserver.models.store.User) GeoTagUpdated(org.bimserver.models.log.GeoTagUpdated) SConverter(org.bimserver.interfaces.SConverter) PostCommitAction(org.bimserver.database.PostCommitAction) UserException(org.bimserver.shared.exceptions.UserException) Date(java.util.Date)

Example 10 with PostCommitAction

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;
}
Also used : User(org.bimserver.models.store.User) ExtendedDataAddedToRevision(org.bimserver.models.log.ExtendedDataAddedToRevision) Revision(org.bimserver.models.store.Revision) SConverter(org.bimserver.interfaces.SConverter) PostCommitAction(org.bimserver.database.PostCommitAction) ExtendedDataAddedToRevision(org.bimserver.models.log.ExtendedDataAddedToRevision) UserException(org.bimserver.shared.exceptions.UserException) NewExtendedDataOnRevisionNotification(org.bimserver.notifications.NewExtendedDataOnRevisionNotification) File(org.bimserver.models.store.File) Date(java.util.Date)

Aggregations

PostCommitAction (org.bimserver.database.PostCommitAction)19 UserException (org.bimserver.shared.exceptions.UserException)19 Date (java.util.Date)18 User (org.bimserver.models.store.User)18 SConverter (org.bimserver.interfaces.SConverter)13 Project (org.bimserver.models.store.Project)10 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)5 Revision (org.bimserver.models.store.Revision)5 HashMap (java.util.HashMap)4 GenerateGeometryResult (org.bimserver.GenerateGeometryResult)3 SummaryMap (org.bimserver.SummaryMap)3 NewRevisionAdded (org.bimserver.models.log.NewRevisionAdded)3 ConcreteRevision (org.bimserver.models.store.ConcreteRevision)3 ByteBuffer (java.nio.ByteBuffer)2 Map (java.util.Map)2 InternetAddress (javax.mail.internet.InternetAddress)2 Authenticator (org.bimserver.Authenticator)2 BimserverLockConflictException (org.bimserver.database.BimserverLockConflictException)2 GeometryGenerationReport (org.bimserver.geometry.GeometryGenerationReport)2 StreamingGeometryGenerator (org.bimserver.geometry.StreamingGeometryGenerator)2