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.keywords; 017 018import java.util.Map; 019import java.util.stream.Collectors; 020 021import org.ametys.cms.tag.CMSTag; 022import org.ametys.cms.tag.DefaultTag; 023import org.ametys.cms.tag.TagTargetType; 024 025/** 026 * This class represent a project keyword as a CMS Tag 027 */ 028public class KeywordCMSTag extends CMSTag 029{ 030 /** The prefix for all tags issue from keywords */ 031 public static final String TAG_PREFIX = "WORKSPACES_KEYWORD_"; 032 033 private DefaultTag _keyword; 034 035 /** 036 * Constructor 037 * @param keyword the keyword 038 * @param parent the parent CMS tag 039 * @param targetType the target type 040 */ 041 public KeywordCMSTag(DefaultTag keyword, CMSTag parent, TagTargetType targetType) 042 { 043 super(TAG_PREFIX + keyword.getName(), TAG_PREFIX + keyword.getName(), parent, keyword.getTitle(), keyword.getDescription(), TagVisibility.PUBLIC, targetType); 044 _keyword = keyword; 045 } 046 047 @SuppressWarnings("unchecked") 048 @Override 049 public CMSTag getTag(String tagId) 050 { 051 DefaultTag keyword = _keyword.getTag(tagId); 052 return new KeywordCMSTag(keyword, this, this.getTarget()); 053 } 054 055 056 @Override 057 public Map<String, CMSTag> getTags() 058 { 059 return _keyword.getTags().values() 060 .stream() 061 .map(keyword -> new KeywordCMSTag(keyword, this, this.getTarget())) 062 .collect(Collectors.toMap(tag -> tag.getId(), tag -> tag)); 063 } 064}