Search in sources :

Example 41 with Project

use of org.bimserver.models.store.Project in project BIMserver by opensourceBIM.

the class RemoveServiceFromProjectDatabaseAction method execute.

@Override
public Boolean execute() throws UserException, BimserverDatabaseException, BimserverLockConflictException {
    Service service = getDatabaseSession().get(soid, OldQuery.getDefault());
    Project project = getDatabaseSession().get(poid, OldQuery.getDefault());
    project.getServices().remove(service);
    getDatabaseSession().store(project);
    return true;
}
Also used : Project(org.bimserver.models.store.Project) Service(org.bimserver.models.store.Service)

Example 42 with Project

use of org.bimserver.models.store.Project 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 43 with Project

use of org.bimserver.models.store.Project 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 44 with Project

use of org.bimserver.models.store.Project in project BIMserver by opensourceBIM.

the class NotificationRegistryServiceImpl method getProgressTopicsOnProject.

@Override
public List<Long> getProgressTopicsOnProject(Long poid) throws ServerException, UserException {
    DatabaseSession session = getBimServer().getDatabase().createSession();
    try {
        List<Long> list = new ArrayList<Long>();
        Project project = session.get(StorePackage.eINSTANCE.getProject(), poid, OldQuery.getDefault());
        List<Long> revisionOids = new ArrayList<Long>();
        for (Revision revision : project.getRevisions()) {
            revisionOids.add(revision.getOid());
        }
        Set<ProgressTopic> progressOnProjectTopics = getBimServer().getNotificationsManager().getProgressOnProjectTopics(poid, revisionOids);
        if (progressOnProjectTopics != null) {
            for (ProgressTopic topic : progressOnProjectTopics) {
                list.add(topic.getKey().getId());
            }
        }
        return list;
    } catch (Exception e) {
        return handleException(e);
    } finally {
        session.close();
    }
}
Also used : Project(org.bimserver.models.store.Project) ProgressTopic(org.bimserver.notifications.ProgressTopic) Revision(org.bimserver.models.store.Revision) DatabaseSession(org.bimserver.database.DatabaseSession) ArrayList(java.util.ArrayList) TopicRegisterException(org.bimserver.notifications.TopicRegisterException) UserException(org.bimserver.shared.exceptions.UserException) ServerException(org.bimserver.shared.exceptions.ServerException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException)

Example 45 with Project

use of org.bimserver.models.store.Project in project BIMserver by opensourceBIM.

the class PluginServiceImpl method getAllDeserializersForProject.

@Override
public List<SDeserializerPluginConfiguration> getAllDeserializersForProject(Boolean onlyEnabled, Long poid) throws ServerException, UserException {
    requireRealUserAuthentication();
    DatabaseSession session = getBimServer().getDatabase().createSession();
    try {
        Project project = session.get(poid, OldQuery.getDefault());
        UserSettings userSettings = getUserSettings(session);
        EList<DeserializerPluginConfiguration> deserializers = userSettings.getDeserializers();
        List<SDeserializerPluginConfiguration> sDeserializers = new ArrayList<SDeserializerPluginConfiguration>();
        for (DeserializerPluginConfiguration deserializerPluginConfiguration : deserializers) {
            DeserializerPlugin plugin = getBimServer().getPluginManager().getDeserializerPlugin(deserializerPluginConfiguration.getPluginDescriptor().getPluginClassName(), true);
            if (plugin == null) {
                StreamingDeserializerPlugin streamingPlugin = getBimServer().getPluginManager().getStreamingDeserializerPlugin(deserializerPluginConfiguration.getPluginDescriptor().getPluginClassName(), true);
                if (streamingPlugin != null) {
                    if (streamingPlugin.getSupportedSchemas().contains(Schema.valueOf(project.getSchema().toUpperCase()))) {
                        if (!onlyEnabled || (deserializerPluginConfiguration.getEnabled() && deserializerPluginConfiguration.getPluginDescriptor().getEnabled())) {
                            sDeserializers.add(getBimServer().getSConverter().convertToSObject(deserializerPluginConfiguration));
                        }
                    }
                }
            } else {
                if (plugin.getSupportedSchemas().contains(Schema.valueOf(project.getSchema().toUpperCase()))) {
                    if (!onlyEnabled || (deserializerPluginConfiguration.getEnabled() && deserializerPluginConfiguration.getPluginDescriptor().getEnabled())) {
                        sDeserializers.add(getBimServer().getSConverter().convertToSObject(deserializerPluginConfiguration));
                    }
                }
            }
        }
        Collections.sort(sDeserializers, new SPluginConfigurationComparator());
        return sDeserializers;
    } catch (Exception e) {
        handleException(e);
    } finally {
        session.close();
    }
    return null;
}
Also used : SPluginConfigurationComparator(org.bimserver.webservices.SPluginConfigurationComparator) Project(org.bimserver.models.store.Project) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) DatabaseSession(org.bimserver.database.DatabaseSession) UserSettings(org.bimserver.models.store.UserSettings) StreamingDeserializerPlugin(org.bimserver.plugins.deserializers.StreamingDeserializerPlugin) ArrayList(java.util.ArrayList) StreamingDeserializerPlugin(org.bimserver.plugins.deserializers.StreamingDeserializerPlugin) DeserializerPlugin(org.bimserver.plugins.deserializers.DeserializerPlugin) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) DeserializerPluginConfiguration(org.bimserver.models.store.DeserializerPluginConfiguration) IOException(java.io.IOException) ServerException(org.bimserver.shared.exceptions.ServerException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) UserException(org.bimserver.shared.exceptions.UserException)

Aggregations

Project (org.bimserver.models.store.Project)80 UserException (org.bimserver.shared.exceptions.UserException)48 User (org.bimserver.models.store.User)46 DatabaseSession (org.bimserver.database.DatabaseSession)25 Revision (org.bimserver.models.store.Revision)23 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)22 ServerException (org.bimserver.shared.exceptions.ServerException)20 Date (java.util.Date)18 ArrayList (java.util.ArrayList)14 SProject (org.bimserver.interfaces.objects.SProject)14 IOException (java.io.IOException)13 PackageMetaData (org.bimserver.emf.PackageMetaData)13 HashSet (java.util.HashSet)12 IfcModelInterface (org.bimserver.emf.IfcModelInterface)12 ConcreteRevision (org.bimserver.models.store.ConcreteRevision)11 OldQuery (org.bimserver.database.OldQuery)10 PostCommitAction (org.bimserver.database.PostCommitAction)10 SConverter (org.bimserver.interfaces.SConverter)9 UnsupportedEncodingException (java.io.UnsupportedEncodingException)8 MalformedURLException (java.net.MalformedURLException)8