use of org.hisp.dhis.category.CategoryComboMap.CategoryComboMapException in project dhis2-core by dhis2.
the class DefaultAdxDataService method getCatOptComboFromAttributes.
private CategoryOptionCombo getCatOptComboFromAttributes(Map<String, String> attributes, CategoryCombo catcombo, IdSchemes idSchemes) throws AdxException {
CategoryComboMap catcomboMap;
try {
catcomboMap = new CategoryComboMap(catcombo, idSchemes.getCategoryOptionIdScheme());
} catch (CategoryComboMapException ex) {
log.info("Failed to create category combo map from: " + catcombo);
throw new AdxException(ex.getMessage());
}
String compositeIdentifier = StringUtils.EMPTY;
for (Category category : catcomboMap.getCategories()) {
String categoryId = category.getPropertyValue(idSchemes.getCategoryIdScheme());
if (categoryId == null) {
throw new AdxException("No category " + idSchemes.getCategoryIdScheme().name() + " for: " + category.toString());
}
String catAttribute = attributes.get(categoryId);
if (catAttribute == null) {
throw new AdxException("Missing required attribute from category combo " + catcombo.getName() + ": " + categoryId);
}
compositeIdentifier += "\"" + catAttribute + "\"";
}
CategoryOptionCombo catOptionCombo = catcomboMap.getCategoryOptionCombo(compositeIdentifier);
if (catOptionCombo == null) {
throw new AdxException("Invalid attributes: " + attributes);
}
return catOptionCombo;
}
Aggregations