use of org.hisp.dhis.organisationunit.OrganisationUnitGroupSet in project dhis2-core by dhis2.
the class MergeServiceTest method mergeOrgUnitGroupSet.
@Test
public void mergeOrgUnitGroupSet() {
OrganisationUnit organisationUnitA = createOrganisationUnit('A');
OrganisationUnit organisationUnitB = createOrganisationUnit('B');
OrganisationUnit organisationUnitC = createOrganisationUnit('C');
OrganisationUnit organisationUnitD = createOrganisationUnit('D');
OrganisationUnitGroup organisationUnitGroupA = createOrganisationUnitGroup('A');
organisationUnitGroupA.getMembers().add(organisationUnitA);
organisationUnitGroupA.getMembers().add(organisationUnitB);
organisationUnitGroupA.getMembers().add(organisationUnitC);
organisationUnitGroupA.getMembers().add(organisationUnitD);
OrganisationUnitGroupSet organisationUnitGroupSetA = createOrganisationUnitGroupSet('A');
OrganisationUnitGroupSet organisationUnitGroupSetB = createOrganisationUnitGroupSet('B');
organisationUnitGroupSetA.addOrganisationUnitGroup(organisationUnitGroupA);
mergeService.merge(new MergeParams<>(organisationUnitGroupSetA, organisationUnitGroupSetB).setMergeMode(MergeMode.REPLACE));
assertFalse(organisationUnitGroupSetB.getOrganisationUnitGroups().isEmpty());
assertEquals(organisationUnitGroupSetA.getName(), organisationUnitGroupSetB.getName());
assertEquals(organisationUnitGroupSetA.getDescription(), organisationUnitGroupSetB.getDescription());
assertEquals(organisationUnitGroupSetA.isCompulsory(), organisationUnitGroupSetB.isCompulsory());
assertEquals(organisationUnitGroupSetA.isIncludeSubhierarchyInAnalytics(), organisationUnitGroupSetB.isIncludeSubhierarchyInAnalytics());
assertEquals(1, organisationUnitGroupSetB.getOrganisationUnitGroups().size());
}
use of org.hisp.dhis.organisationunit.OrganisationUnitGroupSet in project dhis2-core by dhis2.
the class DefaultDataIntegrityService method getOrganisationUnitsViolatingExclusiveGroupSets.
@Override
public SortedMap<OrganisationUnit, Collection<OrganisationUnitGroup>> getOrganisationUnitsViolatingExclusiveGroupSets() {
Collection<OrganisationUnitGroupSet> groupSets = organisationUnitGroupService.getAllOrganisationUnitGroupSets();
TreeMap<OrganisationUnit, Collection<OrganisationUnitGroup>> targets = new TreeMap<>();
for (OrganisationUnitGroupSet groupSet : groupSets) {
Collection<OrganisationUnit> duplicates = getDuplicates(new ArrayList<>(groupSet.getOrganisationUnits()));
for (OrganisationUnit duplicate : duplicates) {
targets.put(duplicate, new HashSet<>(duplicate.getGroups()));
}
}
return targets;
}
use of org.hisp.dhis.organisationunit.OrganisationUnitGroupSet in project dhis2-core by dhis2.
the class OrganisationUnitGroupSetResourceTable method getCreateTempTableStatement.
@Override
public String getCreateTempTableStatement() {
String statement = "create table " + getTempTableName() + " (" + "organisationunitid integer not null, " + "organisationunitname varchar(230), ";
for (OrganisationUnitGroupSet groupSet : objects) {
statement += columnQuote + groupSet.getName() + columnQuote + " varchar(230), ";
statement += columnQuote + groupSet.getUid() + columnQuote + " character(11), ";
}
statement += "primary key (organisationunitid))";
return statement;
}
use of org.hisp.dhis.organisationunit.OrganisationUnitGroupSet in project dhis2-core by dhis2.
the class OrganisationUnitGroupSetResourceTable method getPopulateTempTableStatement.
@Override
public Optional<String> getPopulateTempTableStatement() {
String sql = "insert into " + getTempTableName() + " " + "select ou.organisationunitid as organisationunitid, ou.name as organisationunitname, ";
for (OrganisationUnitGroupSet groupSet : objects) {
if (!groupSet.isIncludeSubhierarchyInAnalytics()) {
sql += "(" + "select oug.name from orgunitgroup oug " + "inner join orgunitgroupmembers ougm on ougm.orgunitgroupid = oug.orgunitgroupid " + "inner join orgunitgroupsetmembers ougsm on ougsm.orgunitgroupid = ougm.orgunitgroupid and ougsm.orgunitgroupsetid = " + groupSet.getId() + " " + "where ougm.organisationunitid = ou.organisationunitid " + "limit 1) as " + columnQuote + groupSet.getName() + columnQuote + ", ";
sql += "(" + "select oug.uid from orgunitgroup oug " + "inner join orgunitgroupmembers ougm on ougm.orgunitgroupid = oug.orgunitgroupid " + "inner join orgunitgroupsetmembers ougsm on ougsm.orgunitgroupid = ougm.orgunitgroupid and ougsm.orgunitgroupsetid = " + groupSet.getId() + " " + "where ougm.organisationunitid = ou.organisationunitid " + "limit 1) as " + columnQuote + groupSet.getUid() + columnQuote + ", ";
} else {
sql += "(" + "select oug.name " + "from orgunitgroup oug " + "inner join orgunitgroupmembers ougm on ougm.orgunitgroupid = oug.orgunitgroupid " + "inner join orgunitgroupsetmembers ougsm on ougsm.orgunitgroupid = ougm.orgunitgroupid and ougsm.orgunitgroupsetid = " + groupSet.getId() + " " + "inner join organisationunit ou2 ON ou2.organisationunitid = ougm.organisationunitid AND ou.path LIKE concat(ou2.path, '%') " + "where ougm.orgunitgroupid is not null " + "order by hierarchylevel desc " + "limit 1) as " + columnQuote + groupSet.getName() + columnQuote + ", ";
sql += "(" + "select oug.uid " + "from orgunitgroup oug " + "inner join orgunitgroupmembers ougm on ougm.orgunitgroupid = oug.orgunitgroupid " + "inner join orgunitgroupsetmembers ougsm on ougsm.orgunitgroupid = ougm.orgunitgroupid and ougsm.orgunitgroupsetid = " + groupSet.getId() + " " + "inner join organisationunit ou2 ON ou2.organisationunitid = ougm.organisationunitid AND ou.path LIKE concat(ou2.path, '%') " + "where ougm.orgunitgroupid is not null " + "order by hierarchylevel desc " + "limit 1) as " + columnQuote + groupSet.getName() + columnQuote + ", ";
}
}
sql = TextUtils.removeLastComma(sql) + " ";
sql += "from organisationunit ou";
return Optional.of(sql);
}
use of org.hisp.dhis.organisationunit.OrganisationUnitGroupSet in project dhis2-core by dhis2.
the class OrganisationUnitLocationController method getEntitiesWithinRange.
/**
* Get Organisation Units within a distance from a location
*/
@RequestMapping(value = "/withinRange", method = RequestMethod.GET, produces = { "*/*", "application/json" })
public void getEntitiesWithinRange(@RequestParam Double longitude, @RequestParam Double latitude, @RequestParam Double distance, @RequestParam(required = false) String orgUnitGroupSetId, HttpServletResponse response) throws Exception {
List<OrganisationUnit> entityList = new ArrayList<>(organisationUnitService.getOrganisationUnitWithinDistance(longitude, latitude, distance));
for (OrganisationUnit organisationUnit : entityList) {
Set<AttributeValue> attributeValues = organisationUnit.getAttributeValues();
attributeValues.clear();
if (orgUnitGroupSetId != null) {
for (OrganisationUnitGroup organisationUnitGroup : organisationUnit.getGroups()) {
for (OrganisationUnitGroupSet orgunitGroupSet : organisationUnitGroup.getGroupSets()) {
if (orgunitGroupSet.getUid().compareTo(orgUnitGroupSetId) == 0) {
AttributeValue attributeValue = new AttributeValue();
// attributeValue.setAttribute( new Attribute( ORGUNIGROUP_SYMBOL, ORGUNIGROUP_SYMBOL ) );
attributeValue.setAttribute(new Attribute(ORGUNIGROUP_SYMBOL, ValueType.TEXT));
attributeValue.setValue(organisationUnitGroup.getSymbol());
attributeValues.add(attributeValue);
}
}
}
}
organisationUnit.setAttributeValues(attributeValues);
// Clear out all data not needed for this task
organisationUnit.removeAllDataSets();
organisationUnit.removeAllUsers();
organisationUnit.removeAllOrganisationUnitGroups();
}
renderService.toJson(response.getOutputStream(), entityList);
}
Aggregations