use of org.openmrs.module.metadatadeploy.descriptor.LocationDescriptor in project openmrs-module-pihcore by PIH.
the class LocationTagSetup method setLocationTagsFor.
private static void setLocationTagsFor(LocationService service, LocationTagDescriptor locationTag, Collection<LocationDescriptor> locationsThatGetTag) {
LocationTag tag = service.getLocationTagByUuid(locationTag.uuid());
for (Location candidate : service.getAllLocations()) {
boolean expected = false;
if (locationsThatGetTag != null) {
for (LocationDescriptor d : locationsThatGetTag) {
if (d != null && d.uuid().equals(candidate.getUuid())) {
expected = true;
}
}
}
boolean actual = candidate.hasTag(tag.getName());
if (actual && !expected) {
candidate.removeTag(tag);
service.saveLocation(candidate);
} else if (!actual && expected) {
candidate.addTag(tag);
service.saveLocation(candidate);
}
}
}
Aggregations