001/*
002 *  Copyright 2017 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.odf.workflow.copy;
017
018import java.util.Map;
019import java.util.Set;
020
021import org.ametys.cms.repository.Content;
022import org.ametys.odf.program.ProgramPart;
023import org.ametys.odf.program.SubProgramFactory;
024import org.ametys.odf.program.TraversableProgramPart;
025import org.ametys.odf.workflow.CreateSubProgramFunction;
026import org.ametys.runtime.i18n.I18nizableText;
027
028/**
029 * OSWorkflow function to create a subprogram by copy of another
030 */
031public class CreateSubProgramByCopyFunction extends AbstractCreateProgramItemByCopyFunction
032{
033    @Override
034    protected String _getContentNamePrefix()
035    {
036        return CreateSubProgramFunction.CONTENT_NAME_PREFIX;
037    }
038    
039    @Override
040    protected String _getObjectType(Map transientVars, Map args)
041    {
042        return SubProgramFactory.SUBPROGRAM_NODETYPE;
043    }
044    
045    @Override
046    protected Set<String> _getChildrenReferencesName()
047    {
048        return Set.of(TraversableProgramPart.CHILD_PROGRAM_PARTS);
049    }
050
051    @Override
052    protected boolean _isCompatibleParent(Content parent)
053    {
054        return parent instanceof ProgramPart;
055    }
056
057    @Override
058    protected String _getParentAttributeName(Content parent)
059    {
060        return ProgramPart.PARENT_PROGRAM_PARTS;
061    }
062    
063    @Override
064    public I18nizableText getLabel()
065    {
066        return new I18nizableText("plugin.odf", "PLUGINS_ODF_CREATE_SUB_PROGRAM_BY_COPY_FUNCTION_LABEL");
067    }
068}