Search in sources :

Example 1 with CategoryComboMap

use of org.hisp.dhis.category.CategoryComboMap 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;
}
Also used : CategoryComboMap(org.hisp.dhis.category.CategoryComboMap) CategoryComboMapException(org.hisp.dhis.category.CategoryComboMap.CategoryComboMapException) Category(org.hisp.dhis.category.Category) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Aggregations

Category (org.hisp.dhis.category.Category)1 CategoryComboMap (org.hisp.dhis.category.CategoryComboMap)1 CategoryComboMapException (org.hisp.dhis.category.CategoryComboMap.CategoryComboMapException)1 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)1