Search in sources :

Example 31 with OrganisationUnit

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();
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Query(org.hibernate.Query) SqlHelper(org.hisp.dhis.commons.util.SqlHelper)

Example 32 with OrganisationUnit

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++;
    }
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Session(org.hibernate.Session)

Example 33 with OrganisationUnit

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());
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 34 with OrganisationUnit

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());
}
Also used : NotificationMessageRenderer(org.hisp.dhis.notification.NotificationMessageRenderer) java.util(java.util) LN(org.hisp.dhis.commons.util.TextUtils.LN) Importance(org.hisp.dhis.validation.Importance) ValidationResultService(org.hisp.dhis.validation.ValidationResultService) Predicate(java.util.function.Predicate) SendStrategy(org.hisp.dhis.notification.SendStrategy) DateUtils(org.hisp.dhis.system.util.DateUtils) MessageService(org.hisp.dhis.message.MessageService) NotNull(javax.validation.constraints.NotNull) CompareToBuilder(org.apache.commons.lang3.builder.CompareToBuilder) ValidationResult(org.hisp.dhis.validation.ValidationResult) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Clock(org.hisp.dhis.system.util.Clock) HashCodeBuilder(org.apache.commons.lang3.builder.HashCodeBuilder) User(org.hisp.dhis.user.User) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) com.google.common.collect(com.google.common.collect) NotificationMessage(org.hisp.dhis.notification.NotificationMessage) EqualsBuilder(org.apache.commons.lang3.builder.EqualsBuilder) Transactional(org.springframework.transaction.annotation.Transactional) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) ValidationResult(org.hisp.dhis.validation.ValidationResult)

Example 35 with OrganisationUnit

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;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) TrackedEntity(org.hisp.dhis.trackedentity.TrackedEntity) ImportConflict(org.hisp.dhis.dxf2.importsummary.ImportConflict)

Aggregations

OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)321 Period (org.hisp.dhis.period.Period)74 Test (org.junit.Test)63 ArrayList (java.util.ArrayList)62 User (org.hisp.dhis.user.User)57 Date (java.util.Date)53 HashSet (java.util.HashSet)53 DataSet (org.hisp.dhis.dataset.DataSet)53 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)51 DataElement (org.hisp.dhis.dataelement.DataElement)50 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)39 DhisSpringTest (org.hisp.dhis.DhisSpringTest)37 List (java.util.List)36 CurrentUserService (org.hisp.dhis.user.CurrentUserService)29 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)28 MockCurrentUserService (org.hisp.dhis.mock.MockCurrentUserService)28 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)23 DataElementCategory (org.hisp.dhis.dataelement.DataElementCategory)23 Program (org.hisp.dhis.program.Program)22 ClassPathResource (org.springframework.core.io.ClassPathResource)20