public List<CategoryOption> getCategoryOptions() { final List<CategoryOption> categoryOptions = new ArrayList<>(); for ( Category category : categories ) { categoryOptions.addAll( category.getCategoryOptions() ); } return categoryOptions; }
public CategoryOption[][] getCategoryOptionsAsArray() { CategoryOption[][] arrays = new CategoryOption[categories.size()][]; int i = 0; for ( Category category : categories ) { arrays[i++] = new ArrayList<>( category.getCategoryOptions() ).toArray( new CategoryOption[0] ); } return arrays; }
/** * Indicates whether this category combo has at least one category, has at * least one category option combo and that all categories have at least one * category option. */ public boolean isValid() { if ( categories == null || categories.isEmpty() ) { return false; } for ( Category category : categories ) { if ( category == null || category.getCategoryOptions() == null || category.getCategoryOptions().isEmpty() ) { return false; } } return true; }
@Override public void deleteCategory( Category category ) { for ( CategoryOption categoryOption : category.getCategoryOptions() ) { categoryOption.getCategories().remove( category ); idObjectManager.updateNoAcl( categoryOption ); } } }
/** * Returns a set of category option group sets which are linked to this data * set through its category combination. */ public Set<CategoryOptionGroupSet> getCategoryOptionGroupSets() { Set<CategoryOptionGroupSet> groupSets = new HashSet<>(); if ( categoryCombo != null ) { for ( Category category : categoryCombo.getCategories() ) { for ( CategoryOption categoryOption : category.getCategoryOptions() ) { groupSets.addAll( categoryOption.getGroupSets() ); } } } return groupSets; }
@Override public String getName() { if ( name != null ) { return name; } StringBuilder builder = new StringBuilder(); if ( categoryCombo == null || categoryCombo.getCategories().isEmpty() ) { return uid; } List<Category> categories = categoryCombo.getCategories(); for ( Category category : categories ) { List<CategoryOption> options = category.getCategoryOptions(); optionLoop: for ( CategoryOption option : categoryOptions ) { if ( options.contains( option ) ) { builder.append( option.getDisplayName() ).append( ", " ); continue optionLoop; } } } builder.delete( Math.max( builder.length() - 2, 0 ), builder.length() ); return StringUtils.substring( builder.toString(), 0, 255 ); }
private SetMap<Class<? extends IdentifiableObject>, IdentifiableObject> handleCategory( SetMap<Class<? extends IdentifiableObject>, IdentifiableObject> metadata, Category category ) { if ( category == null ) return metadata; metadata.putValue( Category.class, category ); handleAttributes( metadata, category ); category.getCategoryOptions().forEach( categoryOption -> handleCategoryOption( metadata, categoryOption ) ); return metadata; }
@Override public String validateCategoryCombo( CategoryCombo 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<CategoryOption> categoryOptions = new HashSet<CategoryOption>(); for ( Category 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; }