Search in sources :

Example 1 with GeoTagUpdated

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

Aggregations

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