001/*
002 *  Copyright 2021 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.tags;
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 tag (used in modules) as a CMS Tag
027 */
028public class ProjectCMSTag extends CMSTag
029{
030    /** The prefix for all tags issue from module tags */
031    public static final String TAG_PREFIX = "WORKSPACES_TAG_";
032    
033    private DefaultTag _tag;
034    
035    /**
036     * Constructor
037     * @param projectTag the project tag
038     * @param parent the parent CMS tag
039     * @param targetType the target type
040     */
041    public ProjectCMSTag(DefaultTag projectTag, CMSTag parent, TagTargetType targetType)
042    {
043        super(TAG_PREFIX + projectTag.getName(), TAG_PREFIX + projectTag.getName(), parent, projectTag.getTitle(), projectTag.getDescription(), TagVisibility.PUBLIC, targetType);
044        _tag = projectTag;
045    }
046    
047    @SuppressWarnings("unchecked")
048    @Override
049    public CMSTag getTag(String tagId)
050    {
051        DefaultTag projectTag = _tag.getTag(tagId);
052        return new ProjectCMSTag(projectTag, this, this.getTarget());
053    }
054    
055    
056    @Override
057    public Map<String, CMSTag> getTags()
058    {
059        return _tag.getTags().values()
060            .stream()
061            .map(projectTag -> new ProjectCMSTag(projectTag, this, this.getTarget()))
062            .collect(Collectors.toMap(tag -> tag.getId(), tag -> tag));
063    }
064}