Skip to content

Commit

Permalink
fix: Update code
Browse files Browse the repository at this point in the history
  • Loading branch information
larshelge committed Jan 8, 2025
1 parent c5a6a4c commit ff9e5a1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,10 @@ Map<String, Set<String>> getOrganisationUnitDataSetAssocationMap(
*/
List<OrganisationUnit> getWithinCoordinateArea(double[] box);

/** Updates the <code>path</code> property of all org units. */
void updatePaths();

/** Explicitly updates the <code>path</code> property of all org units. */
void forceUpdatePaths();

/**
Expand All @@ -166,25 +168,10 @@ Map<String, Set<String>> getOrganisationUnitDataSetAssocationMap(
int getMaxLevel();

/**
* Check if the number of orgunits that satisfies the conditions in the queryParams is greater
* than the threshold provided. Note: groups, maxLevels and levels are not supported yet.
* Sets the geometry field for org units to null.
*
* @param params The Org unit query params
* @param threshold the threshold count to check against
* @return true if the org units satisfying the params criteria is above the threshold, false
* otherwise.
* @return then number of affected org units.
*/
boolean isOrgUnitCountAboveThreshold(OrganisationUnitQueryParams params, int threshold);

/**
* Get list of organisation unit uids satisfying the query params. Note: groups, maxLevels and
* levels are not supported yet.
*
* @param params The Org unit query params
* @return the list of org unit uids satisfying the params criteria
*/
List<String> getOrganisationUnitUids(OrganisationUnitQueryParams params);

int updateAllOrganisationUnitsGeometryToNull();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.stream.Collectors.toSet;
import static org.hisp.dhis.system.util.SqlUtils.escape;

import jakarta.persistence.EntityManager;
import java.util.ArrayList;
Expand Down Expand Up @@ -384,26 +383,6 @@ public int getMaxLevel() {
return maxLength != null ? maxLength : 0;
}

@Override
public boolean isOrgUnitCountAboveThreshold(OrganisationUnitQueryParams params, int threshold) {
String sql = buildOrganisationUnitDistinctUidsSql(params);

StringBuilder sb = new StringBuilder();
sb.append("select count(*) from (");
sb.append(sql);
sb.append(" limit ");
sb.append(threshold + 1);
sb.append(") as douid");

return (jdbcTemplate.queryForObject(sb.toString(), Integer.class) > threshold);
}

@Override
public List<String> getOrganisationUnitUids(OrganisationUnitQueryParams params) {
String sql = buildOrganisationUnitDistinctUidsSql(params);
return jdbcTemplate.queryForList(sql, String.class);
}

@Override
public int updateAllOrganisationUnitsGeometryToNull() {
return getQuery("update OrganisationUnit o set o.geometry = null").executeUpdate();
Expand All @@ -423,30 +402,6 @@ public List<OrganisationUnit> getByCategoryOption(@Nonnull Collection<String> ca
.getResultList();
}

private String buildOrganisationUnitDistinctUidsSql(OrganisationUnitQueryParams params) {
SqlHelper hlp = new SqlHelper();

String sql = "select distinct o.uid from organisationunit o ";

if (params.isFetchChildren()) {
sql += " left outer join organisationunit c ON o.organisationunitid = c.parentid ";
}

if (params.hasParents()) {
sql += hlp.whereAnd() + " (";

for (OrganisationUnit parent : params.getParents()) {
sql += "o.path like '" + escape(parent.getPath()) + "%'" + " or ";
}

sql = TextUtils.removeLastOr(sql) + ") ";
}

// TODO: Support Groups + Query + Hierarchy + MaxLevels in this sql

return sql;
}

private void updatePaths(List<OrganisationUnit> organisationUnits) {
Session session = getSession();
int counter = 0;
Expand Down

0 comments on commit ff9e5a1

Please sign in to comment.