001/*
002 *  Copyright 2018 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.userdirectory.synchronize;
017
018import java.util.Collections;
019import java.util.List;
020import java.util.Map;
021import java.util.Set;
022import java.util.stream.Collectors;
023
024import org.apache.cocoon.environment.Request;
025
026/**
027 * This impl cheats on the list on content types by calculating it itself 
028 */
029public class GetCommonMetadataAction extends org.ametys.cms.contenttype.GetCommonMetadataAction
030{
031    @Override
032    protected Set<String> getContentTypes(Request request, boolean withResources)
033    {
034        Map<String, Object> contentTypesList = _contentTypesHelper.getContentTypesList(Collections.singletonList("org.ametys.plugins.userdirectory.Content.user"), 
035                 true /* inherited */, 
036                 false /* checkRights */, 
037                 true /* includePrivate */, 
038                 false /* includeMixins */, 
039                 false /* includeAbstract*/);
040        
041        @SuppressWarnings("unchecked")
042        List<Map<String, Object>> contentTypes = (List<Map<String, Object>>) contentTypesList.get("contentTypes");
043        Set<String> contentTypesIds = contentTypes.stream().map(e -> (String) e.get("id")).collect(Collectors.toSet());
044        return contentTypesIds;
045    }
046}