Search in sources :

Example 1 with EnumLiteral

use of org.bimserver.database.query.literals.EnumLiteral in project BIMserver by opensourceBIM.

the class GetAllNonAuthorizedUsersOfProjectDatabaseAction method execute.

@Override
public Set<User> execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    Project project = getProjectByPoid(poid);
    if (project == null) {
        throw new UserException("No Project with oid " + poid + " found");
    }
    Condition condition = new AndCondition(new AndCondition(new Not(new HasReferenceToCondition(StorePackage.eINSTANCE.getUser_HasRightsOn(), project)), new AttributeCondition(StorePackage.eINSTANCE.getUser_State(), new EnumLiteral(ObjectState.ACTIVE))), new Not(new AttributeCondition(StorePackage.eINSTANCE.getUser_UserType(), new EnumLiteral(UserType.SYSTEM))));
    return CollectionUtils.mapToSet(getDatabaseSession().query(condition, User.class, OldQuery.getDefault()));
}
Also used : AttributeCondition(org.bimserver.database.query.conditions.AttributeCondition) Condition(org.bimserver.database.query.conditions.Condition) AndCondition(org.bimserver.database.query.conditions.AndCondition) HasReferenceToCondition(org.bimserver.database.query.conditions.HasReferenceToCondition) Project(org.bimserver.models.store.Project) Not(org.bimserver.database.query.conditions.Not) User(org.bimserver.models.store.User) HasReferenceToCondition(org.bimserver.database.query.conditions.HasReferenceToCondition) AttributeCondition(org.bimserver.database.query.conditions.AttributeCondition) UserException(org.bimserver.shared.exceptions.UserException) EnumLiteral(org.bimserver.database.query.literals.EnumLiteral) AndCondition(org.bimserver.database.query.conditions.AndCondition)

Example 2 with EnumLiteral

use of org.bimserver.database.query.literals.EnumLiteral in project BIMserver by opensourceBIM.

the class GetAllProjectsDatabaseAction method execute.

@Override
public Set<Project> execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    User user = getUserByUoid(authorization.getUoid());
    Not notStoreProject = new Not(new AttributeCondition(StorePackage.eINSTANCE.getProject_Name(), new StringLiteral(Database.STORE_PROJECT_NAME)));
    HasReferenceToCondition authorized = new HasReferenceToCondition(StorePackage.eINSTANCE.getProject_HasAuthorizedUsers(), user);
    Condition condition = new IsOfTypeCondition(StorePackage.eINSTANCE.getProject()).and(notStoreProject);
    // }
    if (onlyActive) {
        condition = new AndCondition(condition, new AttributeCondition(StorePackage.eINSTANCE.getProject_State(), new EnumLiteral(ObjectState.ACTIVE)));
    }
    if (user.getUserType() != UserType.ADMIN && user.getUserType() != UserType.SYSTEM) {
        condition = condition.and(authorized);
        condition = condition.and(new AttributeCondition(StorePackage.eINSTANCE.getProject_State(), new EnumLiteral(ObjectState.ACTIVE)));
    }
    Map<Long, Project> results = getDatabaseSession().query(condition, Project.class, OldQuery.getDefault());
    Set<Project> resultSet = new HashSet<Project>();
    for (Project p : results.values()) {
        if (p.getParent() == null || !onlyTopLevel) {
            resultSet.add(p);
        }
    }
    for (Project project : results.values()) {
        addParentProjects(resultSet, project);
    }
    return resultSet;
}
Also used : IsOfTypeCondition(org.bimserver.database.query.conditions.IsOfTypeCondition) AttributeCondition(org.bimserver.database.query.conditions.AttributeCondition) Condition(org.bimserver.database.query.conditions.Condition) AndCondition(org.bimserver.database.query.conditions.AndCondition) HasReferenceToCondition(org.bimserver.database.query.conditions.HasReferenceToCondition) User(org.bimserver.models.store.User) IsOfTypeCondition(org.bimserver.database.query.conditions.IsOfTypeCondition) AttributeCondition(org.bimserver.database.query.conditions.AttributeCondition) AndCondition(org.bimserver.database.query.conditions.AndCondition) Project(org.bimserver.models.store.Project) Not(org.bimserver.database.query.conditions.Not) StringLiteral(org.bimserver.database.query.literals.StringLiteral) HasReferenceToCondition(org.bimserver.database.query.conditions.HasReferenceToCondition) EnumLiteral(org.bimserver.database.query.literals.EnumLiteral) HashSet(java.util.HashSet)

Example 3 with EnumLiteral

use of org.bimserver.database.query.literals.EnumLiteral in project BIMserver by opensourceBIM.

the class GetAllUsersDatabaseAction method execute.

@Override
public Set<User> execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    User actingUser = getUserByUoid(authorization.getUoid());
    Condition condition = new IsOfTypeCondition(StorePackage.eINSTANCE.getUser());
    condition = condition.and(new Not(new AttributeCondition(StorePackage.eINSTANCE.getUser_UserType(), new EnumLiteral(UserType.SYSTEM))));
    if (actingUser.getUserType() != UserType.ADMIN) {
        condition = condition.and(new AttributeCondition(StorePackage.eINSTANCE.getUser_State(), new EnumLiteral(ObjectState.ACTIVE)));
    }
    return CollectionUtils.mapToSet(getDatabaseSession().query(condition, User.class, OldQuery.getDefault()));
}
Also used : IsOfTypeCondition(org.bimserver.database.query.conditions.IsOfTypeCondition) AttributeCondition(org.bimserver.database.query.conditions.AttributeCondition) Condition(org.bimserver.database.query.conditions.Condition) Not(org.bimserver.database.query.conditions.Not) User(org.bimserver.models.store.User) IsOfTypeCondition(org.bimserver.database.query.conditions.IsOfTypeCondition) AttributeCondition(org.bimserver.database.query.conditions.AttributeCondition) EnumLiteral(org.bimserver.database.query.literals.EnumLiteral)

Aggregations

AttributeCondition (org.bimserver.database.query.conditions.AttributeCondition)3 Condition (org.bimserver.database.query.conditions.Condition)3 Not (org.bimserver.database.query.conditions.Not)3 EnumLiteral (org.bimserver.database.query.literals.EnumLiteral)3 User (org.bimserver.models.store.User)3 AndCondition (org.bimserver.database.query.conditions.AndCondition)2 HasReferenceToCondition (org.bimserver.database.query.conditions.HasReferenceToCondition)2 IsOfTypeCondition (org.bimserver.database.query.conditions.IsOfTypeCondition)2 Project (org.bimserver.models.store.Project)2 HashSet (java.util.HashSet)1 StringLiteral (org.bimserver.database.query.literals.StringLiteral)1 UserException (org.bimserver.shared.exceptions.UserException)1