001/*
002 *  Copyright 2010 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.web.workflow;
017
018import java.util.HashMap;
019import java.util.Iterator;
020import java.util.Map;
021import java.util.Optional;
022
023import org.apache.commons.lang3.StringUtils;
024
025import org.ametys.cms.workflow.DefaultWorkflowStepEnumerator;
026import org.ametys.runtime.i18n.I18nizableText;
027import org.ametys.runtime.model.Enumerator;
028
029/**
030 * {@link Enumerator} for the default workflow steps excluding steps of id greater than 9000
031 *
032 */
033public class WorkflowStepsEnumerator extends DefaultWorkflowStepEnumerator
034{
035    @Override
036    public Map<String, I18nizableText> getTypedEntries() throws Exception
037    {
038        Map<String, I18nizableText> allEntries = super.getTypedEntries();
039        
040        Map<String, I18nizableText> entries = new HashMap<>(allEntries);
041        
042        Iterator<String> itSteps = allEntries.keySet().iterator();
043        while (itSteps.hasNext())
044        {
045            Optional.of(itSteps.next())
046                    .filter(StringUtils::isNumeric)
047                    .map(Integer::parseInt)
048                    .filter(stepId -> stepId >= 9000)
049                    .map(String::valueOf)
050                    .ifPresent(entries::remove);
051        }
052        
053        return entries;
054    }
055}