use of org.hisp.dhis.organisationunit.OrganisationUnit in project dhis2-core by dhis2.
the class HibernateOrganisationUnitStore method getOrganisationUnits.
@Override
@SuppressWarnings("unchecked")
public List<OrganisationUnit> getOrganisationUnits(OrganisationUnitQueryParams params) {
SqlHelper hlp = new SqlHelper();
String hql = "select distinct o from OrganisationUnit o ";
if (params.hasGroups()) {
hql += "join o.groups og ";
}
if (params.hasQuery()) {
hql += hlp.whereAnd() + " (lower(o.name) like :queryLower or o.code = :query or o.uid = :query) ";
}
if (params.hasParents()) {
hql += hlp.whereAnd() + " (";
for (OrganisationUnit parent : params.getParents()) {
hql += "o.path like :" + parent.getUid() + " or ";
}
hql = TextUtils.removeLastOr(hql) + ") ";
}
if (params.hasGroups()) {
hql += hlp.whereAnd() + " og.id in (:groupIds) ";
}
if (params.hasLevels()) {
hql += hlp.whereAnd() + " o.hierarchyLevel in (:levels) ";
}
if (params.getMaxLevels() != null) {
hql += hlp.whereAnd() + " o.hierarchyLevel <= :maxLevels ";
}
hql += "order by o.name";
Query query = getQuery(hql);
if (params.hasQuery()) {
query.setString("queryLower", "%" + params.getQuery().toLowerCase() + "%");
query.setString("query", params.getQuery());
}
if (params.hasParents()) {
for (OrganisationUnit parent : params.getParents()) {
query.setString(parent.getUid(), parent.getPath() + "%");
}
}
if (params.hasGroups()) {
query.setParameterList("groupIds", IdentifiableObjectUtils.getIdentifiers(params.getGroups()));
}
if (params.hasLevels()) {
query.setParameterList("levels", params.getLevels());
}
if (params.getMaxLevels() != null) {
query.setInteger("maxLevels", params.getMaxLevels());
}
if (params.getFirst() != null) {
query.setFirstResult(params.getFirst());
}
if (params.getMax() != null) {
query.setMaxResults(params.getMax()).list();
}
return query.list();
}
use of org.hisp.dhis.organisationunit.OrganisationUnit in project dhis2-core by dhis2.
the class HibernateOrganisationUnitStore method updatePaths.
private void updatePaths(List<OrganisationUnit> organisationUnits) {
Session session = getSession();
int counter = 0;
for (OrganisationUnit organisationUnit : organisationUnits) {
session.update(organisationUnit);
if ((counter % 400) == 0) {
dbmsManager.clearSession();
}
counter++;
}
}
use of org.hisp.dhis.organisationunit.OrganisationUnit in project dhis2-core by dhis2.
the class IdentifiableObjectManagerTest method getAllEqualToName.
@Test
public void getAllEqualToName() {
OrganisationUnit organisationUnitA1 = createOrganisationUnit('A');
organisationUnitA1.setCode(null);
identifiableObjectManager.save(organisationUnitA1);
OrganisationUnit organisationUnitA2 = createOrganisationUnit('B');
organisationUnitA2.setName("OrganisationUnitA");
organisationUnitA2.setCode(null);
identifiableObjectManager.save(organisationUnitA2);
assertEquals(2, identifiableObjectManager.getAllByName(OrganisationUnit.class, "OrganisationUnitA").size());
assertEquals(0, identifiableObjectManager.getAllByName(OrganisationUnit.class, "organisationunita").size());
}
use of org.hisp.dhis.organisationunit.OrganisationUnit in project dhis2-core by dhis2.
the class DefaultValidationNotificationService method resolveRecipients.
/**
* Resolve all distinct recipients for the given MessagePair.
*/
private static Set<User> resolveRecipients(MessagePair pair) {
ValidationResult validationResult = pair.result;
ValidationNotificationTemplate template = pair.template;
// Limit recipients to be withing org unit hierarchy only, effectively
// producing a cross-cut of all users in the configured user groups.
final boolean limitToHierarchy = template.getNotifyUsersInHierarchyOnly();
Set<OrganisationUnit> orgUnitsToInclude = Sets.newHashSet();
if (limitToHierarchy) {
// Include self
orgUnitsToInclude.add(validationResult.getOrganisationUnit());
orgUnitsToInclude.addAll(validationResult.getOrganisationUnit().getAncestors());
}
return template.getRecipientUserGroups().stream().flatMap(ug -> ug.getMembers().stream()).distinct().filter(user -> !limitToHierarchy || orgUnitsToInclude.contains(user.getOrganisationUnit())).collect(Collectors.toSet());
}
use of org.hisp.dhis.organisationunit.OrganisationUnit in project dhis2-core by dhis2.
the class AbstractTrackedEntityInstanceService method getTrackedEntityInstance.
public org.hisp.dhis.trackedentity.TrackedEntityInstance getTrackedEntityInstance(TrackedEntityInstance trackedEntityInstance, ImportOptions importOptions, ImportSummary importSummary) {
if (StringUtils.isEmpty(trackedEntityInstance.getOrgUnit())) {
importSummary.getConflicts().add(new ImportConflict(trackedEntityInstance.getTrackedEntityInstance(), "No org unit ID in tracked entity instance object."));
return null;
}
org.hisp.dhis.trackedentity.TrackedEntityInstance entityInstance = new org.hisp.dhis.trackedentity.TrackedEntityInstance();
OrganisationUnit organisationUnit = getOrganisationUnit(importOptions.getIdSchemes(), trackedEntityInstance.getOrgUnit());
if (organisationUnit == null) {
importSummary.getConflicts().add(new ImportConflict(trackedEntityInstance.getTrackedEntityInstance(), "Invalid org unit ID: " + trackedEntityInstance.getOrgUnit()));
return null;
}
entityInstance.setOrganisationUnit(organisationUnit);
TrackedEntity trackedEntity = getTrackedEntity(importOptions.getIdSchemes(), trackedEntityInstance.getTrackedEntity());
if (trackedEntity == null) {
importSummary.getConflicts().add(new ImportConflict(trackedEntityInstance.getTrackedEntityInstance(), "Invalid tracked entity ID: " + trackedEntityInstance.getTrackedEntity()));
return null;
}
entityInstance.setTrackedEntity(trackedEntity);
entityInstance.setUid(CodeGenerator.isValidUid(trackedEntityInstance.getTrackedEntityInstance()) ? trackedEntityInstance.getTrackedEntityInstance() : CodeGenerator.generateUid());
return entityInstance;
}
Aggregations