001/* 002 * Copyright 2020 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.ametys.plugins.workspaces.categories; 017 018import java.util.Map; 019import java.util.stream.Collectors; 020 021import org.ametys.cms.tag.CMSTag; 022import org.ametys.cms.tag.TagTargetType; 023 024/** 025 * This class represent a project category as a CMS Tag 026 */ 027public class CategoryCMSTag extends CMSTag 028{ 029 /** The prefix for all tags issue from categories */ 030 public static final String TAG_PREFIX = "WORKSPACES_CATEGORY_"; 031 032 private Category _category; 033 034 /** 035 * Constructor 036 * @param category the category 037 * @param parent the parent CMS tag 038 * @param targetType the target type 039 */ 040 public CategoryCMSTag(Category category, CMSTag parent, TagTargetType targetType) 041 { 042 super(TAG_PREFIX + category.getName(), TAG_PREFIX + category.getName(), parent, category.getTitle(), category.getDescription(), TagVisibility.PUBLIC, targetType); 043 _category = category; 044 } 045 046 @SuppressWarnings("unchecked") 047 @Override 048 public CMSTag getTag(String tagId) 049 { 050 Category category = _category.getTag(tagId); 051 return new CategoryCMSTag(category, this, this.getTarget()); 052 } 053 054 055 @Override 056 public Map<String, CMSTag> getTags() 057 { 058 return _category.getTags().values() 059 .stream() 060 .map(category -> new CategoryCMSTag(category, this, this.getTarget())) 061 .collect(Collectors.toMap(tag -> tag.getId(), tag -> tag)); 062 } 063}