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.odf.workflow; 017 018import java.util.Map; 019 020import org.apache.avalon.framework.service.ServiceException; 021import org.apache.avalon.framework.service.ServiceManager; 022import org.apache.commons.lang3.StringUtils; 023 024import org.ametys.cms.repository.ModifiableContent; 025import org.ametys.core.user.UserIdentity; 026import org.ametys.odf.course.Course; 027import org.ametys.odf.course.CourseFactory; 028import org.ametys.odf.course.ShareableCourseHelper; 029import org.ametys.odf.courselist.CourseList; 030 031import com.opensymphony.workflow.WorkflowException; 032 033/** 034 * OSWorkflow function for creating a {@link Course} content 035 */ 036public class CreateCourseFunction extends AbstractCreateODFProgramItemFunction 037{ 038 /** Constant for storing the parent course list id to use into the transient variables map. */ 039 public static final String COURSE_LIST_ID_KEY = AbstractCreateODFContentFunction.class.getName() + "$courseListContentId"; 040 041 /** Content name prefix for programs */ 042 public static final String CONTENT_NAME_PREFIX = "course-"; 043 044 /** The shareable course helper */ 045 protected ShareableCourseHelper _shareableCourseHelper; 046 047 @Override 048 public void service(ServiceManager manager) throws ServiceException 049 { 050 super.service(manager); 051 _shareableCourseHelper = (ShareableCourseHelper) manager.lookup(ShareableCourseHelper.ROLE); 052 } 053 054 @Override 055 protected String _getContentNamePrefix() 056 { 057 return CONTENT_NAME_PREFIX; 058 } 059 060 @Override 061 protected String _getNodeType() 062 { 063 return CourseFactory.COURSE_NODETYPE; 064 } 065 066 @Override 067 protected void _populateAdditionalData(Map transientVars, ModifiableContent content) throws WorkflowException 068 { 069 super._populateAdditionalData(transientVars, content); 070 071 String courseListContentId = (String) transientVars.get(COURSE_LIST_ID_KEY); 072 CourseList courseListContent = StringUtils.isNotBlank(courseListContentId) ? _resolver.resolveById(courseListContentId) : null; 073 074 UserIdentity user = getUser(transientVars); 075 _shareableCourseHelper.initializeShareableFields((Course) content, courseListContent, user, false); 076 } 077}