Search in sources :

Example 41 with QueryBuilder

use of com.j256.ormlite.stmt.QueryBuilder in project SORMAS-Project by hzi-braunschweig.

the class UserDao method getAllInJurisdiction.

public List<User> getAllInJurisdiction() {
    try {
        QueryBuilder builder = queryBuilder();
        Where where = builder.where();
        where.eq(AbstractDomainObject.SNAPSHOT, false);
        User currentUser = ConfigProvider.getUser();
        // create role filters for national and regional users
        List<UserRole> nationalOrRegionalRoles = UserRole.getWithJurisdictionLevels(JurisdictionLevel.NATION, JurisdictionLevel.REGION);
        for (int i = 0; i < nationalOrRegionalRoles.size(); i++) {
            UserRole role = nationalOrRegionalRoles.get(i);
            createRoleFilter(role, where);
        }
        where.or(nationalOrRegionalRoles.size());
        // conjunction by default, jurisdiction filter should not be empty because of combining role and jurisdiction filters by OR
        // if the current user is a national one than it should see all users
        Where jurisdictionFilter = where.raw("1=1");
        if (currentUser.getHealthFacility() != null) {
            where.and(jurisdictionFilter, where.eq(User.HEALTH_FACILITY + "_id", currentUser.getHealthFacility()));
        } else if (currentUser.getPointOfEntry() != null) {
            where.and(jurisdictionFilter, where.eq(User.POINT_OF_ENTRY + "_id", currentUser.getPointOfEntry()));
        } else if (currentUser.getCommunity() != null) {
            where.and(jurisdictionFilter, where.eq(User.COMMUNITY + "_id", currentUser.getCommunity()));
        } else if (currentUser.getDistrict() != null) {
            where.and(jurisdictionFilter, where.eq(User.DISTRICT + "_id", currentUser.getDistrict()));
        } else if (currentUser.getRegion() != null) {
            where.and(jurisdictionFilter, where.eq(User.REGION + "_id", currentUser.getRegion()));
        }
        // combine role filters and jurisdiction filter with OR(=> roleFilter OR jurisdictionFilter)
        where.or(2);
        // combine snapshot filter with AND (=> snapshot AND (role OR jurisdiction))
        where.and(2);
        return builder.query();
    } catch (SQLException e) {
        Log.e(getTableName(), "Could not perform getAllInJurisdiction");
        throw new RuntimeException(e);
    }
}
Also used : SQLException(java.sql.SQLException) UserRole(de.symeda.sormas.api.user.UserRole) QueryBuilder(com.j256.ormlite.stmt.QueryBuilder) Where(com.j256.ormlite.stmt.Where)

Example 42 with QueryBuilder

use of com.j256.ormlite.stmt.QueryBuilder in project SORMAS-Project by hzi-braunschweig.

the class UserDao method getByDistrictAndRole.

public List<User> getByDistrictAndRole(District district, UserRole role) {
    try {
        QueryBuilder builder = queryBuilder();
        Where where = builder.where();
        where.and(where.eq(User.DISTRICT + "_id", district.getId()), createRoleFilter(role, where));
        return (List<User>) builder.query();
    } catch (SQLException e) {
        Log.e(getTableName(), "Could not perform getByDistrictAndRole");
        throw new RuntimeException(e);
    }
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) List(java.util.List) QueryBuilder(com.j256.ormlite.stmt.QueryBuilder) Where(com.j256.ormlite.stmt.Where)

Example 43 with QueryBuilder

use of com.j256.ormlite.stmt.QueryBuilder in project SORMAS-Project by hzi-braunschweig.

the class PointOfEntryDao method getActiveByDistrict.

public List<PointOfEntry> getActiveByDistrict(District district, boolean includeOthers) {
    try {
        QueryBuilder builder = queryBuilder();
        Where where = builder.where();
        where.and(where.eq(PointOfEntry.DISTRICT + "_id", district.getId()), where.eq(InfrastructureAdo.ARCHIVED, false), where.eq(AbstractDomainObject.SNAPSHOT, false), where.ne(PointOfEntry.ACTIVE, false));
        List<PointOfEntry> pointsOfEntry = builder.orderBy(PointOfEntry.NAME, true).query();
        if (includeOthers) {
            pointsOfEntry.add(queryUuid(PointOfEntryDto.OTHER_AIRPORT_UUID));
            pointsOfEntry.add(queryUuid(PointOfEntryDto.OTHER_SEAPORT_UUID));
            pointsOfEntry.add(queryUuid(PointOfEntryDto.OTHER_GROUND_CROSSING_UUID));
            pointsOfEntry.add(queryUuid(PointOfEntryDto.OTHER_POE_UUID));
        }
        return pointsOfEntry;
    } catch (SQLException | IllegalArgumentException e) {
        Log.e(getTableName(), "Could not perform getActiveByDistrict");
        throw new RuntimeException(e);
    }
}
Also used : SQLException(java.sql.SQLException) QueryBuilder(com.j256.ormlite.stmt.QueryBuilder) Where(com.j256.ormlite.stmt.Where)

Example 44 with QueryBuilder

use of com.j256.ormlite.stmt.QueryBuilder in project SORMAS-Project by hzi-braunschweig.

the class FacilityDao method getActiveHealthFacilitiesByCommunityAndType.

public List<Facility> getActiveHealthFacilitiesByCommunityAndType(Community community, FacilityType type, boolean includeOtherFacility, boolean includeOtherPlace) {
    try {
        QueryBuilder builder = queryBuilder();
        Where where = builder.where();
        where.and(where.eq(Facility.COMMUNITY, community), where.eq(InfrastructureAdo.ARCHIVED, false), where.eq(AbstractDomainObject.SNAPSHOT, false));
        if (type != null) {
            where.and().eq(Facility.TYPE, type);
        }
        List<Facility> facilities = builder.orderBy(Facility.NAME, true).query();
        if (includeOtherFacility) {
            facilities.add(queryUuid(FacilityDto.OTHER_FACILITY_UUID));
        }
        if (includeOtherPlace) {
            facilities.add(queryUuid(FacilityDto.NONE_FACILITY_UUID));
        }
        return facilities;
    } catch (SQLException | IllegalArgumentException e) {
        Log.e(getTableName(), "Could not perform getActiveHealthFacilitiesByCommunity");
        throw new RuntimeException(e);
    }
}
Also used : SQLException(java.sql.SQLException) QueryBuilder(com.j256.ormlite.stmt.QueryBuilder) Where(com.j256.ormlite.stmt.Where)

Example 45 with QueryBuilder

use of com.j256.ormlite.stmt.QueryBuilder in project SORMAS-Project by hzi-braunschweig.

the class FacilityDao method getActiveHealthFacilitiesByDistrictAndType.

public List<Facility> getActiveHealthFacilitiesByDistrictAndType(District district, FacilityType type, boolean includeOtherFacility, boolean includeOtherPlace) {
    try {
        QueryBuilder builder = queryBuilder();
        Where where = builder.where();
        where.and(where.eq(Facility.DISTRICT, district), where.eq(InfrastructureAdo.ARCHIVED, false), where.eq(AbstractDomainObject.SNAPSHOT, false));
        if (type != null) {
            where.and().eq(Facility.TYPE, type);
        }
        List<Facility> facilities = builder.orderBy(Facility.NAME, true).query();
        if (includeOtherFacility) {
            Facility otherFacility = queryUuid(FacilityDto.OTHER_FACILITY_UUID);
            if (otherFacility != null) {
                facilities.add(otherFacility);
            }
        }
        if (includeOtherPlace) {
            Facility noneFacility = queryUuid(FacilityDto.NONE_FACILITY_UUID);
            if (noneFacility != null) {
                facilities.add(noneFacility);
            }
        }
        return facilities;
    } catch (SQLException | IllegalArgumentException e) {
        Log.e(getTableName(), "Could not perform getActiveHealthFacilitiesByDistrict");
        throw new RuntimeException(e);
    }
}
Also used : SQLException(java.sql.SQLException) QueryBuilder(com.j256.ormlite.stmt.QueryBuilder) Where(com.j256.ormlite.stmt.Where)

Aggregations

SQLException (java.sql.SQLException)44 QueryBuilder (com.j256.ormlite.stmt.QueryBuilder)43 Where (com.j256.ormlite.stmt.Where)38 SelectArg (com.j256.ormlite.stmt.SelectArg)9 ArrayList (java.util.ArrayList)6 List (java.util.List)4 DatabaseHelper (ca.etsmtl.applets.etsmobile.db.DatabaseHelper)3 ElementEvaluation (ca.etsmtl.applets.etsmobile.model.ElementEvaluation)2 NonNull (androidx.annotation.NonNull)1 AppCompatActivity (androidx.appcompat.app.AppCompatActivity)1 FicheEmploye (ca.etsmtl.applets.etsmobile.model.FicheEmploye)1 ExpandableListAdapter (ca.etsmtl.applets.etsmobile.ui.adapter.ExpandableListAdapter)1 Entry (com.faltenreich.diaguard.shared.data.database.entity.Entry)1 EntryTag (com.faltenreich.diaguard.shared.data.database.entity.EntryTag)1 Food (com.faltenreich.diaguard.shared.data.database.entity.Food)1 Tag (com.faltenreich.diaguard.shared.data.database.entity.Tag)1 Disease (de.symeda.sormas.api.Disease)1 FeatureTypeProperty (de.symeda.sormas.api.feature.FeatureTypeProperty)1 UserRole (de.symeda.sormas.api.user.UserRole)1 Date (java.util.Date)1