=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryService.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryService.java 2015-01-17 07:41:26 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryService.java 2015-01-24 11:12:45 +0000 @@ -342,6 +342,22 @@ * @return a collection of DataElementCategoryCombos. */ Collection getAttributeCategoryCombos(); + + /** + * Validates the category combo. Possible return values are: + * + * + * + * @param categoryCombo the category combo to validate. + * @return null if valid, non-empty string if invalid. + */ + String validateCategoryCombo( DataElementCategoryCombo categoryCombo ); // ------------------------------------------------------------------------- // CategoryOptionCombo === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java 2015-01-17 07:41:26 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java 2015-01-24 11:12:45 +0000 @@ -47,6 +47,8 @@ import org.hisp.dhis.system.util.FilterUtils; import org.springframework.transaction.annotation.Transactional; +import com.google.common.collect.Sets; + /** * @author Abyot Asalefew */ @@ -488,6 +490,42 @@ categoryComboStore.getCategoryCombosByDimensionType( DataElementCategoryCombo.DIMENSION_TYPE_ATTTRIBUTE ) ); } + @Override + public String validateCategoryCombo( DataElementCategoryCombo categoryCombo ) + { + if ( categoryCombo == null ) + { + return "category_combo_is_null"; + } + + if ( categoryCombo.getCategories() == null || categoryCombo.getCategories().isEmpty() ) + { + return "category_combo_must_have_at_least_one_category"; + } + + if ( Sets.newHashSet( categoryCombo.getCategories() ).size() < categoryCombo.getCategories().size() ) + { + return "category_combo_cannot_have_duplicate_categories"; + } + + Set categoryOptions = new HashSet(); + + for ( DataElementCategory category: categoryCombo.getCategories() ) + { + if ( category == null || category.getCategoryOptions().isEmpty() ) + { + return "categories_must_have_at_least_one_category_option"; + } + + if ( !Sets.intersection( categoryOptions, Sets.newHashSet( category.getCategoryOptions() ) ).isEmpty() ) + { + return "categories_cannot_share_category_options"; + } + } + + return null; + } + // ------------------------------------------------------------------------- // CategoryOptionCombo // ------------------------------------------------------------------------- === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/categorycombo/ValidateDataElementCategoryComboAction.java' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/categorycombo/ValidateDataElementCategoryComboAction.java 2015-01-17 07:41:26 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/categorycombo/ValidateDataElementCategoryComboAction.java 2015-01-24 11:12:45 +0000 @@ -130,6 +130,8 @@ } } + //TODO validateCategoryCombo + return SUCCESS; } }