Search in sources :

Example 1 with CategoryComboMapException

use of org.hisp.dhis.dataelement.CategoryComboMap.CategoryComboMapException in project dhis2-core by dhis2.

the class DefaultAdxDataService method getCatOptComboFromAttributes.

private DataElementCategoryOptionCombo getCatOptComboFromAttributes(Map<String, String> attributes, DataElementCategoryCombo catcombo, IdentifiableProperty scheme) throws AdxException {
    CategoryComboMap catcomboMap;
    try {
        catcomboMap = new CategoryComboMap(catcombo, scheme);
    } catch (CategoryComboMapException ex) {
        log.info("Failed to create category combo map from: " + catcombo);
        throw new AdxException(ex.getMessage());
    }
    String compositeIdentifier = StringUtils.EMPTY;
    for (DataElementCategory category : catcomboMap.getCategories()) {
        String categoryCode = category.getCode();
        if (categoryCode == null) {
            throw new AdxException("No category matching: " + categoryCode);
        }
        String catAttribute = attributes.get(categoryCode);
        if (catAttribute == null) {
            throw new AdxException("Missing required attribute from category combo: " + categoryCode);
        }
        compositeIdentifier += "\"" + catAttribute + "\"";
    }
    DataElementCategoryOptionCombo catOptionCombo = catcomboMap.getCategoryOptionCombo(compositeIdentifier);
    if (catOptionCombo == null) {
        throw new AdxException("Invalid attributes:" + attributes);
    }
    return catOptionCombo;
}
Also used : CategoryComboMap(org.hisp.dhis.dataelement.CategoryComboMap) CategoryComboMapException(org.hisp.dhis.dataelement.CategoryComboMap.CategoryComboMapException) DataElementCategory(org.hisp.dhis.dataelement.DataElementCategory) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Aggregations

CategoryComboMap (org.hisp.dhis.dataelement.CategoryComboMap)1 CategoryComboMapException (org.hisp.dhis.dataelement.CategoryComboMap.CategoryComboMapException)1 DataElementCategory (org.hisp.dhis.dataelement.DataElementCategory)1 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)1