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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations